Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1 | //===--- SemaOpenMP.cpp - Semantic Analysis for OpenMP constructs ---------===// |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | /// \file |
| 10 | /// \brief This file implements semantic analysis for OpenMP directives and |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 11 | /// clauses. |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 12 | /// |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 15 | #include "TreeTransform.h" |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 16 | #include "clang/AST/ASTContext.h" |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 17 | #include "clang/AST/ASTMutationListener.h" |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 18 | #include "clang/AST/Decl.h" |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 19 | #include "clang/AST/DeclCXX.h" |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 20 | #include "clang/AST/DeclOpenMP.h" |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 21 | #include "clang/AST/StmtCXX.h" |
| 22 | #include "clang/AST/StmtOpenMP.h" |
| 23 | #include "clang/AST/StmtVisitor.h" |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 24 | #include "clang/Basic/OpenMPKinds.h" |
Samuel Antao | f8b5012 | 2015-07-13 22:54:53 +0000 | [diff] [blame] | 25 | #include "clang/Basic/TargetInfo.h" |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 26 | #include "clang/Lex/Preprocessor.h" |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 27 | #include "clang/Sema/Initialization.h" |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 28 | #include "clang/Sema/Lookup.h" |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 29 | #include "clang/Sema/Scope.h" |
| 30 | #include "clang/Sema/ScopeInfo.h" |
Chandler Carruth | 5553d0d | 2014-01-07 11:51:46 +0000 | [diff] [blame] | 31 | #include "clang/Sema/SemaInternal.h" |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 32 | using namespace clang; |
| 33 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 34 | //===----------------------------------------------------------------------===// |
| 35 | // Stack of data-sharing attributes for variables |
| 36 | //===----------------------------------------------------------------------===// |
| 37 | |
| 38 | namespace { |
| 39 | /// \brief Default data sharing attributes, which can be applied to directive. |
| 40 | enum DefaultDataSharingAttributes { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 41 | DSA_unspecified = 0, /// \brief Data sharing attribute not specified. |
| 42 | DSA_none = 1 << 0, /// \brief Default data sharing attribute 'none'. |
| 43 | DSA_shared = 1 << 1 /// \brief Default data sharing attribute 'shared'. |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 44 | }; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 45 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 46 | template <class T> struct MatchesAny { |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 47 | explicit MatchesAny(ArrayRef<T> Arr) : Arr(std::move(Arr)) {} |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 48 | bool operator()(T Kind) { |
| 49 | for (auto KindEl : Arr) |
| 50 | if (KindEl == Kind) |
| 51 | return true; |
| 52 | return false; |
| 53 | } |
| 54 | |
| 55 | private: |
| 56 | ArrayRef<T> Arr; |
| 57 | }; |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 58 | struct MatchesAlways { |
Angel Garcia Gomez | 637d1e6 | 2015-10-20 13:23:58 +0000 | [diff] [blame] | 59 | MatchesAlways() {} |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 60 | template <class T> bool operator()(T) { return true; } |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 61 | }; |
| 62 | |
| 63 | typedef MatchesAny<OpenMPClauseKind> MatchesAnyClause; |
| 64 | typedef MatchesAny<OpenMPDirectiveKind> MatchesAnyDirective; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 65 | |
| 66 | /// \brief Stack for tracking declarations used in OpenMP directives and |
| 67 | /// clauses and their data-sharing attributes. |
| 68 | class DSAStackTy { |
| 69 | public: |
| 70 | struct DSAVarData { |
| 71 | OpenMPDirectiveKind DKind; |
| 72 | OpenMPClauseKind CKind; |
| 73 | DeclRefExpr *RefExpr; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 74 | SourceLocation ImplicitDSALoc; |
| 75 | DSAVarData() |
| 76 | : DKind(OMPD_unknown), CKind(OMPC_unknown), RefExpr(nullptr), |
| 77 | ImplicitDSALoc() {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 78 | }; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 79 | |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 80 | public: |
| 81 | struct MapInfo { |
| 82 | Expr *RefExpr; |
| 83 | }; |
| 84 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 85 | private: |
| 86 | struct DSAInfo { |
| 87 | OpenMPClauseKind Attributes; |
| 88 | DeclRefExpr *RefExpr; |
| 89 | }; |
| 90 | typedef llvm::SmallDenseMap<VarDecl *, DSAInfo, 64> DeclSAMapTy; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 91 | typedef llvm::SmallDenseMap<VarDecl *, DeclRefExpr *, 64> AlignedMapTy; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 92 | typedef llvm::DenseMap<VarDecl *, unsigned> LoopControlVariablesMapTy; |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 93 | typedef llvm::SmallDenseMap<VarDecl *, MapInfo, 64> MappedDeclsTy; |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 94 | typedef llvm::StringMap<std::pair<OMPCriticalDirective *, llvm::APSInt>> |
| 95 | CriticalsWithHintsTy; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 96 | |
| 97 | struct SharingMapTy { |
| 98 | DeclSAMapTy SharingMap; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 99 | AlignedMapTy AlignedMap; |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 100 | MappedDeclsTy MappedDecls; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 101 | LoopControlVariablesMapTy LCVMap; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 102 | DefaultDataSharingAttributes DefaultAttr; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 103 | SourceLocation DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 104 | OpenMPDirectiveKind Directive; |
| 105 | DeclarationNameInfo DirectiveName; |
| 106 | Scope *CurScope; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 107 | SourceLocation ConstructLoc; |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 108 | /// \brief first argument (Expr *) contains optional argument of the |
| 109 | /// 'ordered' clause, the second one is true if the regions has 'ordered' |
| 110 | /// clause, false otherwise. |
| 111 | llvm::PointerIntPair<Expr *, 1, bool> OrderedRegion; |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 112 | bool NowaitRegion; |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 113 | bool CancelRegion; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 114 | unsigned AssociatedLoops; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 115 | SourceLocation InnerTeamsRegionLoc; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 116 | SharingMapTy(OpenMPDirectiveKind DKind, DeclarationNameInfo Name, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 117 | Scope *CurScope, SourceLocation Loc) |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 118 | : SharingMap(), AlignedMap(), LCVMap(), DefaultAttr(DSA_unspecified), |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 119 | Directive(DKind), DirectiveName(std::move(Name)), CurScope(CurScope), |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 120 | ConstructLoc(Loc), OrderedRegion(), NowaitRegion(false), |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 121 | CancelRegion(false), AssociatedLoops(1), InnerTeamsRegionLoc() {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 122 | SharingMapTy() |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 123 | : SharingMap(), AlignedMap(), LCVMap(), DefaultAttr(DSA_unspecified), |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 124 | Directive(OMPD_unknown), DirectiveName(), CurScope(nullptr), |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 125 | ConstructLoc(), OrderedRegion(), NowaitRegion(false), |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 126 | CancelRegion(false), AssociatedLoops(1), InnerTeamsRegionLoc() {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 127 | }; |
| 128 | |
| 129 | typedef SmallVector<SharingMapTy, 64> StackTy; |
| 130 | |
| 131 | /// \brief Stack of used declaration and their data-sharing attributes. |
| 132 | StackTy Stack; |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 133 | /// \brief true, if check for DSA must be from parent directive, false, if |
| 134 | /// from current directive. |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 135 | OpenMPClauseKind ClauseKindMode; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 136 | Sema &SemaRef; |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 137 | bool ForceCapturing; |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 138 | CriticalsWithHintsTy Criticals; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 139 | |
| 140 | typedef SmallVector<SharingMapTy, 8>::reverse_iterator reverse_iterator; |
| 141 | |
| 142 | DSAVarData getDSA(StackTy::reverse_iterator Iter, VarDecl *D); |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 143 | |
| 144 | /// \brief Checks if the variable is a local for OpenMP region. |
| 145 | bool isOpenMPLocal(VarDecl *D, StackTy::reverse_iterator Iter); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 146 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 147 | public: |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 148 | explicit DSAStackTy(Sema &S) |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 149 | : Stack(1), ClauseKindMode(OMPC_unknown), SemaRef(S), |
| 150 | ForceCapturing(false) {} |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 151 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 152 | bool isClauseParsingMode() const { return ClauseKindMode != OMPC_unknown; } |
| 153 | void setClauseParsingMode(OpenMPClauseKind K) { ClauseKindMode = K; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 154 | |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 155 | bool isForceVarCapturing() const { return ForceCapturing; } |
| 156 | void setForceVarCapturing(bool V) { ForceCapturing = V; } |
| 157 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 158 | void push(OpenMPDirectiveKind DKind, const DeclarationNameInfo &DirName, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 159 | Scope *CurScope, SourceLocation Loc) { |
| 160 | Stack.push_back(SharingMapTy(DKind, DirName, CurScope, Loc)); |
| 161 | Stack.back().DefaultAttrLoc = Loc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | void pop() { |
| 165 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty!"); |
| 166 | Stack.pop_back(); |
| 167 | } |
| 168 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 169 | void addCriticalWithHint(OMPCriticalDirective *D, llvm::APSInt Hint) { |
| 170 | Criticals[D->getDirectiveName().getAsString()] = std::make_pair(D, Hint); |
| 171 | } |
| 172 | const std::pair<OMPCriticalDirective *, llvm::APSInt> |
| 173 | getCriticalWithHint(const DeclarationNameInfo &Name) const { |
| 174 | auto I = Criticals.find(Name.getAsString()); |
| 175 | if (I != Criticals.end()) |
| 176 | return I->second; |
| 177 | return std::make_pair(nullptr, llvm::APSInt()); |
| 178 | } |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 179 | /// \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] | 180 | /// add it and return NULL; otherwise return previous occurrence's expression |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 181 | /// for diagnostics. |
| 182 | DeclRefExpr *addUniqueAligned(VarDecl *D, DeclRefExpr *NewDE); |
| 183 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 184 | /// \brief Register specified variable as loop control variable. |
| 185 | void addLoopControlVariable(VarDecl *D); |
| 186 | /// \brief Check if the specified variable is a loop control variable for |
| 187 | /// current region. |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 188 | /// \return The index of the loop control variable in the list of associated |
| 189 | /// for-loops (from outer to inner). |
| 190 | unsigned isLoopControlVariable(VarDecl *D); |
| 191 | /// \brief Check if the specified variable is a loop control variable for |
| 192 | /// parent region. |
| 193 | /// \return The index of the loop control variable in the list of associated |
| 194 | /// for-loops (from outer to inner). |
| 195 | unsigned isParentLoopControlVariable(VarDecl *D); |
| 196 | /// \brief Get the loop control variable for the I-th loop (or nullptr) in |
| 197 | /// parent directive. |
| 198 | VarDecl *getParentLoopControlVariable(unsigned I); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 199 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 200 | /// \brief Adds explicit data sharing attribute to the specified declaration. |
| 201 | void addDSA(VarDecl *D, DeclRefExpr *E, OpenMPClauseKind A); |
| 202 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 203 | /// \brief Returns data sharing attributes from top of the stack for the |
| 204 | /// specified declaration. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 205 | DSAVarData getTopDSA(VarDecl *D, bool FromParent); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 206 | /// \brief Returns data-sharing attributes for the specified declaration. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 207 | DSAVarData getImplicitDSA(VarDecl *D, bool FromParent); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 208 | /// \brief Checks if the specified variables has data-sharing attributes which |
| 209 | /// match specified \a CPred predicate in any directive which matches \a DPred |
| 210 | /// predicate. |
| 211 | template <class ClausesPredicate, class DirectivesPredicate> |
| 212 | DSAVarData hasDSA(VarDecl *D, ClausesPredicate CPred, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 213 | DirectivesPredicate DPred, bool FromParent); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 214 | /// \brief Checks if the specified variables has data-sharing attributes which |
| 215 | /// match specified \a CPred predicate in any innermost directive which |
| 216 | /// matches \a DPred predicate. |
| 217 | template <class ClausesPredicate, class DirectivesPredicate> |
| 218 | DSAVarData hasInnermostDSA(VarDecl *D, ClausesPredicate CPred, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 219 | DirectivesPredicate DPred, |
| 220 | bool FromParent); |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 221 | /// \brief Checks if the specified variables has explicit data-sharing |
| 222 | /// attributes which match specified \a CPred predicate at the specified |
| 223 | /// OpenMP region. |
| 224 | bool hasExplicitDSA(VarDecl *D, |
| 225 | const llvm::function_ref<bool(OpenMPClauseKind)> &CPred, |
| 226 | unsigned Level); |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 227 | |
| 228 | /// \brief Returns true if the directive at level \Level matches in the |
| 229 | /// specified \a DPred predicate. |
| 230 | bool hasExplicitDirective( |
| 231 | const llvm::function_ref<bool(OpenMPDirectiveKind)> &DPred, |
| 232 | unsigned Level); |
| 233 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 234 | /// \brief Finds a directive which matches specified \a DPred predicate. |
| 235 | template <class NamedDirectivesPredicate> |
| 236 | bool hasDirective(NamedDirectivesPredicate DPred, bool FromParent); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 237 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 238 | /// \brief Returns currently analyzed directive. |
| 239 | OpenMPDirectiveKind getCurrentDirective() const { |
| 240 | return Stack.back().Directive; |
| 241 | } |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 242 | /// \brief Returns parent directive. |
| 243 | OpenMPDirectiveKind getParentDirective() const { |
| 244 | if (Stack.size() > 2) |
| 245 | return Stack[Stack.size() - 2].Directive; |
| 246 | return OMPD_unknown; |
| 247 | } |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 248 | /// \brief Return the directive associated with the provided scope. |
| 249 | OpenMPDirectiveKind getDirectiveForScope(const Scope *S) const; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 250 | |
| 251 | /// \brief Set default data sharing attribute to none. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 252 | void setDefaultDSANone(SourceLocation Loc) { |
| 253 | Stack.back().DefaultAttr = DSA_none; |
| 254 | Stack.back().DefaultAttrLoc = Loc; |
| 255 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 256 | /// \brief Set default data sharing attribute to shared. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 257 | void setDefaultDSAShared(SourceLocation Loc) { |
| 258 | Stack.back().DefaultAttr = DSA_shared; |
| 259 | Stack.back().DefaultAttrLoc = Loc; |
| 260 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 261 | |
| 262 | DefaultDataSharingAttributes getDefaultDSA() const { |
| 263 | return Stack.back().DefaultAttr; |
| 264 | } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 265 | SourceLocation getDefaultDSALocation() const { |
| 266 | return Stack.back().DefaultAttrLoc; |
| 267 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 268 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 269 | /// \brief Checks if the specified variable is a threadprivate. |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 270 | bool isThreadPrivate(VarDecl *D) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 271 | DSAVarData DVar = getTopDSA(D, false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 272 | return isOpenMPThreadPrivate(DVar.CKind); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 273 | } |
| 274 | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 275 | /// \brief Marks current region as ordered (it has an 'ordered' clause). |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 276 | void setOrderedRegion(bool IsOrdered, Expr *Param) { |
| 277 | Stack.back().OrderedRegion.setInt(IsOrdered); |
| 278 | Stack.back().OrderedRegion.setPointer(Param); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 279 | } |
| 280 | /// \brief Returns true, if parent region is ordered (has associated |
| 281 | /// 'ordered' clause), false - otherwise. |
| 282 | bool isParentOrderedRegion() const { |
| 283 | if (Stack.size() > 2) |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 284 | return Stack[Stack.size() - 2].OrderedRegion.getInt(); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 285 | return false; |
| 286 | } |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 287 | /// \brief Returns optional parameter for the ordered region. |
| 288 | Expr *getParentOrderedRegionParam() const { |
| 289 | if (Stack.size() > 2) |
| 290 | return Stack[Stack.size() - 2].OrderedRegion.getPointer(); |
| 291 | return nullptr; |
| 292 | } |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 293 | /// \brief Marks current region as nowait (it has a 'nowait' clause). |
| 294 | void setNowaitRegion(bool IsNowait = true) { |
| 295 | Stack.back().NowaitRegion = IsNowait; |
| 296 | } |
| 297 | /// \brief Returns true, if parent region is nowait (has associated |
| 298 | /// 'nowait' clause), false - otherwise. |
| 299 | bool isParentNowaitRegion() const { |
| 300 | if (Stack.size() > 2) |
| 301 | return Stack[Stack.size() - 2].NowaitRegion; |
| 302 | return false; |
| 303 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 304 | /// \brief Marks parent region as cancel region. |
| 305 | void setParentCancelRegion(bool Cancel = true) { |
| 306 | if (Stack.size() > 2) |
| 307 | Stack[Stack.size() - 2].CancelRegion = |
| 308 | Stack[Stack.size() - 2].CancelRegion || Cancel; |
| 309 | } |
| 310 | /// \brief Return true if current region has inner cancel construct. |
| 311 | bool isCancelRegion() const { |
| 312 | return Stack.back().CancelRegion; |
| 313 | } |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 314 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 315 | /// \brief Set collapse value for the region. |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 316 | void setAssociatedLoops(unsigned Val) { Stack.back().AssociatedLoops = Val; } |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 317 | /// \brief Return collapse value for region. |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 318 | unsigned getAssociatedLoops() const { return Stack.back().AssociatedLoops; } |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 319 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 320 | /// \brief Marks current target region as one with closely nested teams |
| 321 | /// region. |
| 322 | void setParentTeamsRegionLoc(SourceLocation TeamsRegionLoc) { |
| 323 | if (Stack.size() > 2) |
| 324 | Stack[Stack.size() - 2].InnerTeamsRegionLoc = TeamsRegionLoc; |
| 325 | } |
| 326 | /// \brief Returns true, if current region has closely nested teams region. |
| 327 | bool hasInnerTeamsRegion() const { |
| 328 | return getInnerTeamsRegionLoc().isValid(); |
| 329 | } |
| 330 | /// \brief Returns location of the nested teams region (if any). |
| 331 | SourceLocation getInnerTeamsRegionLoc() const { |
| 332 | if (Stack.size() > 1) |
| 333 | return Stack.back().InnerTeamsRegionLoc; |
| 334 | return SourceLocation(); |
| 335 | } |
| 336 | |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 337 | Scope *getCurScope() const { return Stack.back().CurScope; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 338 | Scope *getCurScope() { return Stack.back().CurScope; } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 339 | SourceLocation getConstructLoc() { return Stack.back().ConstructLoc; } |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 340 | |
| 341 | MapInfo getMapInfoForVar(VarDecl *VD) { |
| 342 | MapInfo VarMI = {0}; |
| 343 | for (auto Cnt = Stack.size() - 1; Cnt > 0; --Cnt) { |
| 344 | if (Stack[Cnt].MappedDecls.count(VD)) { |
| 345 | VarMI = Stack[Cnt].MappedDecls[VD]; |
| 346 | break; |
| 347 | } |
| 348 | } |
| 349 | return VarMI; |
| 350 | } |
| 351 | |
| 352 | void addMapInfoForVar(VarDecl *VD, MapInfo MI) { |
| 353 | if (Stack.size() > 1) { |
| 354 | Stack.back().MappedDecls[VD] = MI; |
| 355 | } |
| 356 | } |
| 357 | |
| 358 | MapInfo IsMappedInCurrentRegion(VarDecl *VD) { |
| 359 | assert(Stack.size() > 1 && "Target level is 0"); |
| 360 | MapInfo VarMI = {0}; |
| 361 | if (Stack.size() > 1 && Stack.back().MappedDecls.count(VD)) { |
| 362 | VarMI = Stack.back().MappedDecls[VD]; |
| 363 | } |
| 364 | return VarMI; |
| 365 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 366 | }; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 367 | bool isParallelOrTaskRegion(OpenMPDirectiveKind DKind) { |
| 368 | return isOpenMPParallelDirective(DKind) || DKind == OMPD_task || |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 369 | isOpenMPTeamsDirective(DKind) || DKind == OMPD_unknown || |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 370 | isOpenMPTaskLoopDirective(DKind); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 371 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 372 | } // namespace |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 373 | |
| 374 | DSAStackTy::DSAVarData DSAStackTy::getDSA(StackTy::reverse_iterator Iter, |
| 375 | VarDecl *D) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 376 | D = D->getCanonicalDecl(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 377 | DSAVarData DVar; |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 378 | if (Iter == std::prev(Stack.rend())) { |
Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 379 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 380 | // in a region but not in construct] |
| 381 | // File-scope or namespace-scope variables referenced in called routines |
| 382 | // in the region are shared unless they appear in a threadprivate |
| 383 | // directive. |
Alexey Bataev | 8b9cb98 | 2014-07-24 02:33:58 +0000 | [diff] [blame] | 384 | if (!D->isFunctionOrMethodVarDecl() && !isa<ParmVarDecl>(D)) |
Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 385 | DVar.CKind = OMPC_shared; |
| 386 | |
| 387 | // OpenMP [2.9.1.2, Data-sharing Attribute Rules for Variables Referenced |
| 388 | // in a region but not in construct] |
| 389 | // Variables with static storage duration that are declared in called |
| 390 | // routines in the region are shared. |
| 391 | if (D->hasGlobalStorage()) |
| 392 | DVar.CKind = OMPC_shared; |
| 393 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 394 | return DVar; |
| 395 | } |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 396 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 397 | DVar.DKind = Iter->Directive; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 398 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 399 | // in a Construct, C/C++, predetermined, p.1] |
| 400 | // Variables with automatic storage duration that are declared in a scope |
| 401 | // inside the construct are private. |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 402 | if (isOpenMPLocal(D, Iter) && D->isLocalVarDecl() && |
| 403 | (D->getStorageClass() == SC_Auto || D->getStorageClass() == SC_None)) { |
| 404 | DVar.CKind = OMPC_private; |
| 405 | return DVar; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 406 | } |
| 407 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 408 | // Explicitly specified attributes and local variables with predetermined |
| 409 | // attributes. |
| 410 | if (Iter->SharingMap.count(D)) { |
| 411 | DVar.RefExpr = Iter->SharingMap[D].RefExpr; |
| 412 | DVar.CKind = Iter->SharingMap[D].Attributes; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 413 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 414 | return DVar; |
| 415 | } |
| 416 | |
| 417 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 418 | // in a Construct, C/C++, implicitly determined, p.1] |
| 419 | // In a parallel or task construct, the data-sharing attributes of these |
| 420 | // variables are determined by the default clause, if present. |
| 421 | switch (Iter->DefaultAttr) { |
| 422 | case DSA_shared: |
| 423 | DVar.CKind = OMPC_shared; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 424 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 425 | return DVar; |
| 426 | case DSA_none: |
| 427 | return DVar; |
| 428 | case DSA_unspecified: |
| 429 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 430 | // in a Construct, implicitly determined, p.2] |
| 431 | // In a parallel construct, if no default clause is present, these |
| 432 | // variables are shared. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 433 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 434 | if (isOpenMPParallelDirective(DVar.DKind) || |
| 435 | isOpenMPTeamsDirective(DVar.DKind)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 436 | DVar.CKind = OMPC_shared; |
| 437 | return DVar; |
| 438 | } |
| 439 | |
| 440 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 441 | // in a Construct, implicitly determined, p.4] |
| 442 | // In a task construct, if no default clause is present, a variable that in |
| 443 | // the enclosing context is determined to be shared by all implicit tasks |
| 444 | // bound to the current team is shared. |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 445 | if (DVar.DKind == OMPD_task) { |
| 446 | DSAVarData DVarTemp; |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 447 | for (StackTy::reverse_iterator I = std::next(Iter), EE = Stack.rend(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 448 | I != EE; ++I) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 449 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables |
| 450 | // Referenced |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 451 | // in a Construct, implicitly determined, p.6] |
| 452 | // In a task construct, if no default clause is present, a variable |
| 453 | // whose data-sharing attribute is not determined by the rules above is |
| 454 | // firstprivate. |
| 455 | DVarTemp = getDSA(I, D); |
| 456 | if (DVarTemp.CKind != OMPC_shared) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 457 | DVar.RefExpr = nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 458 | DVar.DKind = OMPD_task; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 459 | DVar.CKind = OMPC_firstprivate; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 460 | return DVar; |
| 461 | } |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 462 | if (isParallelOrTaskRegion(I->Directive)) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 463 | break; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 464 | } |
| 465 | DVar.DKind = OMPD_task; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 466 | DVar.CKind = |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 467 | (DVarTemp.CKind == OMPC_unknown) ? OMPC_firstprivate : OMPC_shared; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 468 | return DVar; |
| 469 | } |
| 470 | } |
| 471 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 472 | // in a Construct, implicitly determined, p.3] |
| 473 | // For constructs other than task, if no default clause is present, these |
| 474 | // variables inherit their data-sharing attributes from the enclosing |
| 475 | // context. |
Benjamin Kramer | 167e999 | 2014-03-02 12:20:24 +0000 | [diff] [blame] | 476 | return getDSA(std::next(Iter), D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 477 | } |
| 478 | |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 479 | DeclRefExpr *DSAStackTy::addUniqueAligned(VarDecl *D, DeclRefExpr *NewDE) { |
| 480 | assert(Stack.size() > 1 && "Data sharing attributes stack is empty"); |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 481 | D = D->getCanonicalDecl(); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 482 | auto It = Stack.back().AlignedMap.find(D); |
| 483 | if (It == Stack.back().AlignedMap.end()) { |
| 484 | assert(NewDE && "Unexpected nullptr expr to be added into aligned map"); |
| 485 | Stack.back().AlignedMap[D] = NewDE; |
| 486 | return nullptr; |
| 487 | } else { |
| 488 | assert(It->second && "Unexpected nullptr expr in the aligned map"); |
| 489 | return It->second; |
| 490 | } |
| 491 | return nullptr; |
| 492 | } |
| 493 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 494 | void DSAStackTy::addLoopControlVariable(VarDecl *D) { |
| 495 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); |
| 496 | D = D->getCanonicalDecl(); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 497 | Stack.back().LCVMap.insert(std::make_pair(D, Stack.back().LCVMap.size() + 1)); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 498 | } |
| 499 | |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 500 | unsigned DSAStackTy::isLoopControlVariable(VarDecl *D) { |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 501 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); |
| 502 | D = D->getCanonicalDecl(); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 503 | return Stack.back().LCVMap.count(D) > 0 ? Stack.back().LCVMap[D] : 0; |
| 504 | } |
| 505 | |
| 506 | unsigned DSAStackTy::isParentLoopControlVariable(VarDecl *D) { |
| 507 | assert(Stack.size() > 2 && "Data-sharing attributes stack is empty"); |
| 508 | D = D->getCanonicalDecl(); |
| 509 | return Stack[Stack.size() - 2].LCVMap.count(D) > 0 |
| 510 | ? Stack[Stack.size() - 2].LCVMap[D] |
| 511 | : 0; |
| 512 | } |
| 513 | |
| 514 | VarDecl *DSAStackTy::getParentLoopControlVariable(unsigned I) { |
| 515 | assert(Stack.size() > 2 && "Data-sharing attributes stack is empty"); |
| 516 | if (Stack[Stack.size() - 2].LCVMap.size() < I) |
| 517 | return nullptr; |
| 518 | for (auto &Pair : Stack[Stack.size() - 2].LCVMap) { |
| 519 | if (Pair.second == I) |
| 520 | return Pair.first; |
| 521 | } |
| 522 | return nullptr; |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 523 | } |
| 524 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 525 | void DSAStackTy::addDSA(VarDecl *D, DeclRefExpr *E, OpenMPClauseKind A) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 526 | D = D->getCanonicalDecl(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 527 | if (A == OMPC_threadprivate) { |
| 528 | Stack[0].SharingMap[D].Attributes = A; |
| 529 | Stack[0].SharingMap[D].RefExpr = E; |
| 530 | } else { |
| 531 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); |
| 532 | Stack.back().SharingMap[D].Attributes = A; |
| 533 | Stack.back().SharingMap[D].RefExpr = E; |
| 534 | } |
| 535 | } |
| 536 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 537 | bool DSAStackTy::isOpenMPLocal(VarDecl *D, StackTy::reverse_iterator Iter) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 538 | D = D->getCanonicalDecl(); |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 539 | if (Stack.size() > 2) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 540 | reverse_iterator I = Iter, E = std::prev(Stack.rend()); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 541 | Scope *TopScope = nullptr; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 542 | while (I != E && !isParallelOrTaskRegion(I->Directive)) { |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 543 | ++I; |
| 544 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 545 | if (I == E) |
| 546 | return false; |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 547 | TopScope = I->CurScope ? I->CurScope->getParent() : nullptr; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 548 | Scope *CurScope = getCurScope(); |
| 549 | while (CurScope != TopScope && !CurScope->isDeclScope(D)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 550 | CurScope = CurScope->getParent(); |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 551 | } |
| 552 | return CurScope != TopScope; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 553 | } |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 554 | return false; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 555 | } |
| 556 | |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 557 | /// \brief Build a variable declaration for OpenMP loop iteration variable. |
| 558 | static VarDecl *buildVarDecl(Sema &SemaRef, SourceLocation Loc, QualType Type, |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 559 | StringRef Name, const AttrVec *Attrs = nullptr) { |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 560 | DeclContext *DC = SemaRef.CurContext; |
| 561 | IdentifierInfo *II = &SemaRef.PP.getIdentifierTable().get(Name); |
| 562 | TypeSourceInfo *TInfo = SemaRef.Context.getTrivialTypeSourceInfo(Type, Loc); |
| 563 | VarDecl *Decl = |
| 564 | VarDecl::Create(SemaRef.Context, DC, Loc, Loc, II, Type, TInfo, SC_None); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 565 | if (Attrs) { |
| 566 | for (specific_attr_iterator<AlignedAttr> I(Attrs->begin()), E(Attrs->end()); |
| 567 | I != E; ++I) |
| 568 | Decl->addAttr(*I); |
| 569 | } |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 570 | Decl->setImplicit(); |
| 571 | return Decl; |
| 572 | } |
| 573 | |
| 574 | static DeclRefExpr *buildDeclRefExpr(Sema &S, VarDecl *D, QualType Ty, |
| 575 | SourceLocation Loc, |
| 576 | bool RefersToCapture = false) { |
| 577 | D->setReferenced(); |
| 578 | D->markUsed(S.Context); |
| 579 | return DeclRefExpr::Create(S.getASTContext(), NestedNameSpecifierLoc(), |
| 580 | SourceLocation(), D, RefersToCapture, Loc, Ty, |
| 581 | VK_LValue); |
| 582 | } |
| 583 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 584 | DSAStackTy::DSAVarData DSAStackTy::getTopDSA(VarDecl *D, bool FromParent) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 585 | D = D->getCanonicalDecl(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 586 | DSAVarData DVar; |
| 587 | |
| 588 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 589 | // in a Construct, C/C++, predetermined, p.1] |
| 590 | // Variables appearing in threadprivate directives are threadprivate. |
Samuel Antao | f8b5012 | 2015-07-13 22:54:53 +0000 | [diff] [blame] | 591 | if ((D->getTLSKind() != VarDecl::TLS_None && |
| 592 | !(D->hasAttr<OMPThreadPrivateDeclAttr>() && |
| 593 | SemaRef.getLangOpts().OpenMPUseTLS && |
| 594 | SemaRef.getASTContext().getTargetInfo().isTLSSupported())) || |
Alexey Bataev | 1a8b3f1 | 2015-05-06 06:34:55 +0000 | [diff] [blame] | 595 | (D->getStorageClass() == SC_Register && D->hasAttr<AsmLabelAttr>() && |
| 596 | !D->isLocalVarDecl())) { |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 597 | addDSA(D, buildDeclRefExpr(SemaRef, D, D->getType().getNonReferenceType(), |
| 598 | D->getLocation()), |
Alexey Bataev | f2453a0 | 2015-05-06 07:25:08 +0000 | [diff] [blame] | 599 | OMPC_threadprivate); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 600 | } |
| 601 | if (Stack[0].SharingMap.count(D)) { |
| 602 | DVar.RefExpr = Stack[0].SharingMap[D].RefExpr; |
| 603 | DVar.CKind = OMPC_threadprivate; |
| 604 | return DVar; |
| 605 | } |
| 606 | |
| 607 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
Alexey Bataev | dffa93a | 2015-12-10 08:20:58 +0000 | [diff] [blame] | 608 | // in a Construct, C/C++, predetermined, p.4] |
| 609 | // Static data members are shared. |
| 610 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 611 | // in a Construct, C/C++, predetermined, p.7] |
| 612 | // Variables with static storage duration that are declared in a scope |
| 613 | // inside the construct are shared. |
| 614 | if (D->isStaticDataMember()) { |
| 615 | DSAVarData DVarTemp = |
| 616 | hasDSA(D, isOpenMPPrivate, MatchesAlways(), FromParent); |
| 617 | if (DVarTemp.CKind != OMPC_unknown && DVarTemp.RefExpr) |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 618 | return DVar; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 619 | |
Alexey Bataev | dffa93a | 2015-12-10 08:20:58 +0000 | [diff] [blame] | 620 | DVar.CKind = OMPC_shared; |
| 621 | return DVar; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 622 | } |
| 623 | |
| 624 | QualType Type = D->getType().getNonReferenceType().getCanonicalType(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 625 | bool IsConstant = Type.isConstant(SemaRef.getASTContext()); |
| 626 | Type = SemaRef.getASTContext().getBaseElementType(Type); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 627 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 628 | // in a Construct, C/C++, predetermined, p.6] |
| 629 | // Variables with const qualified type having no mutable member are |
| 630 | // shared. |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 631 | CXXRecordDecl *RD = |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 632 | SemaRef.getLangOpts().CPlusPlus ? Type->getAsCXXRecordDecl() : nullptr; |
Alexey Bataev | c9bd03d | 2015-12-17 06:55:08 +0000 | [diff] [blame] | 633 | if (auto *CTSD = dyn_cast_or_null<ClassTemplateSpecializationDecl>(RD)) |
| 634 | if (auto *CTD = CTSD->getSpecializedTemplate()) |
| 635 | RD = CTD->getTemplatedDecl(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 636 | if (IsConstant && |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 637 | !(SemaRef.getLangOpts().CPlusPlus && RD && RD->hasMutableFields())) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 638 | // Variables with const-qualified type having no mutable member may be |
| 639 | // listed in a firstprivate clause, even if they are static data members. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 640 | DSAVarData DVarTemp = hasDSA(D, MatchesAnyClause(OMPC_firstprivate), |
| 641 | MatchesAlways(), FromParent); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 642 | if (DVarTemp.CKind == OMPC_firstprivate && DVarTemp.RefExpr) |
| 643 | return DVar; |
| 644 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 645 | DVar.CKind = OMPC_shared; |
| 646 | return DVar; |
| 647 | } |
| 648 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 649 | // Explicitly specified attributes and local variables with predetermined |
| 650 | // attributes. |
Alexey Bataev | dffa93a | 2015-12-10 08:20:58 +0000 | [diff] [blame] | 651 | auto StartI = std::next(Stack.rbegin()); |
| 652 | auto EndI = std::prev(Stack.rend()); |
| 653 | if (FromParent && StartI != EndI) { |
| 654 | StartI = std::next(StartI); |
| 655 | } |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 656 | auto I = std::prev(StartI); |
| 657 | if (I->SharingMap.count(D)) { |
| 658 | DVar.RefExpr = I->SharingMap[D].RefExpr; |
| 659 | DVar.CKind = I->SharingMap[D].Attributes; |
| 660 | DVar.ImplicitDSALoc = I->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 661 | } |
| 662 | |
| 663 | return DVar; |
| 664 | } |
| 665 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 666 | DSAStackTy::DSAVarData DSAStackTy::getImplicitDSA(VarDecl *D, bool FromParent) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 667 | D = D->getCanonicalDecl(); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 668 | auto StartI = Stack.rbegin(); |
| 669 | auto EndI = std::prev(Stack.rend()); |
| 670 | if (FromParent && StartI != EndI) { |
| 671 | StartI = std::next(StartI); |
| 672 | } |
| 673 | return getDSA(StartI, D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 674 | } |
| 675 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 676 | template <class ClausesPredicate, class DirectivesPredicate> |
| 677 | DSAStackTy::DSAVarData DSAStackTy::hasDSA(VarDecl *D, ClausesPredicate CPred, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 678 | DirectivesPredicate DPred, |
| 679 | bool FromParent) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 680 | D = D->getCanonicalDecl(); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 681 | auto StartI = std::next(Stack.rbegin()); |
| 682 | auto EndI = std::prev(Stack.rend()); |
| 683 | if (FromParent && StartI != EndI) { |
| 684 | StartI = std::next(StartI); |
| 685 | } |
| 686 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
| 687 | if (!DPred(I->Directive) && !isParallelOrTaskRegion(I->Directive)) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 688 | continue; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 689 | DSAVarData DVar = getDSA(I, D); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 690 | if (CPred(DVar.CKind)) |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 691 | return DVar; |
| 692 | } |
| 693 | return DSAVarData(); |
| 694 | } |
| 695 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 696 | template <class ClausesPredicate, class DirectivesPredicate> |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 697 | DSAStackTy::DSAVarData |
| 698 | DSAStackTy::hasInnermostDSA(VarDecl *D, ClausesPredicate CPred, |
| 699 | DirectivesPredicate DPred, bool FromParent) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 700 | D = D->getCanonicalDecl(); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 701 | auto StartI = std::next(Stack.rbegin()); |
| 702 | auto EndI = std::prev(Stack.rend()); |
| 703 | if (FromParent && StartI != EndI) { |
| 704 | StartI = std::next(StartI); |
| 705 | } |
| 706 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 707 | if (!DPred(I->Directive)) |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 708 | break; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 709 | DSAVarData DVar = getDSA(I, D); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 710 | if (CPred(DVar.CKind)) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 711 | return DVar; |
| 712 | return DSAVarData(); |
| 713 | } |
| 714 | return DSAVarData(); |
| 715 | } |
| 716 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 717 | bool DSAStackTy::hasExplicitDSA( |
| 718 | VarDecl *D, const llvm::function_ref<bool(OpenMPClauseKind)> &CPred, |
| 719 | unsigned Level) { |
| 720 | if (CPred(ClauseKindMode)) |
| 721 | return true; |
| 722 | if (isClauseParsingMode()) |
| 723 | ++Level; |
| 724 | D = D->getCanonicalDecl(); |
| 725 | auto StartI = Stack.rbegin(); |
| 726 | auto EndI = std::prev(Stack.rend()); |
NAKAMURA Takumi | 0332eda | 2015-06-23 10:01:20 +0000 | [diff] [blame] | 727 | if (std::distance(StartI, EndI) <= (int)Level) |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 728 | return false; |
| 729 | std::advance(StartI, Level); |
| 730 | return (StartI->SharingMap.count(D) > 0) && StartI->SharingMap[D].RefExpr && |
| 731 | CPred(StartI->SharingMap[D].Attributes); |
| 732 | } |
| 733 | |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 734 | bool DSAStackTy::hasExplicitDirective( |
| 735 | const llvm::function_ref<bool(OpenMPDirectiveKind)> &DPred, |
| 736 | unsigned Level) { |
| 737 | if (isClauseParsingMode()) |
| 738 | ++Level; |
| 739 | auto StartI = Stack.rbegin(); |
| 740 | auto EndI = std::prev(Stack.rend()); |
| 741 | if (std::distance(StartI, EndI) <= (int)Level) |
| 742 | return false; |
| 743 | std::advance(StartI, Level); |
| 744 | return DPred(StartI->Directive); |
| 745 | } |
| 746 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 747 | template <class NamedDirectivesPredicate> |
| 748 | bool DSAStackTy::hasDirective(NamedDirectivesPredicate DPred, bool FromParent) { |
| 749 | auto StartI = std::next(Stack.rbegin()); |
| 750 | auto EndI = std::prev(Stack.rend()); |
| 751 | if (FromParent && StartI != EndI) { |
| 752 | StartI = std::next(StartI); |
| 753 | } |
| 754 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
| 755 | if (DPred(I->Directive, I->DirectiveName, I->ConstructLoc)) |
| 756 | return true; |
| 757 | } |
| 758 | return false; |
| 759 | } |
| 760 | |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 761 | OpenMPDirectiveKind DSAStackTy::getDirectiveForScope(const Scope *S) const { |
| 762 | for (auto I = Stack.rbegin(), EE = Stack.rend(); I != EE; ++I) |
| 763 | if (I->CurScope == S) |
| 764 | return I->Directive; |
| 765 | return OMPD_unknown; |
| 766 | } |
| 767 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 768 | void Sema::InitDataSharingAttributesStack() { |
| 769 | VarDataSharingAttributesStack = new DSAStackTy(*this); |
| 770 | } |
| 771 | |
| 772 | #define DSAStack static_cast<DSAStackTy *>(VarDataSharingAttributesStack) |
| 773 | |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 774 | bool Sema::IsOpenMPCapturedByRef(VarDecl *VD, |
| 775 | const CapturedRegionScopeInfo *RSI) { |
| 776 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| 777 | |
| 778 | auto &Ctx = getASTContext(); |
| 779 | bool IsByRef = true; |
| 780 | |
| 781 | // Find the directive that is associated with the provided scope. |
| 782 | auto DKind = DSAStack->getDirectiveForScope(RSI->TheScope); |
| 783 | auto Ty = VD->getType(); |
| 784 | |
| 785 | if (isOpenMPTargetDirective(DKind)) { |
| 786 | // This table summarizes how a given variable should be passed to the device |
| 787 | // given its type and the clauses where it appears. This table is based on |
| 788 | // the description in OpenMP 4.5 [2.10.4, target Construct] and |
| 789 | // OpenMP 4.5 [2.15.5, Data-mapping Attribute Rules and Clauses]. |
| 790 | // |
| 791 | // ========================================================================= |
| 792 | // | type | defaultmap | pvt | first | is_device_ptr | map | res. | |
| 793 | // | |(tofrom:scalar)| | pvt | | | | |
| 794 | // ========================================================================= |
| 795 | // | scl | | | | - | | bycopy| |
| 796 | // | scl | | - | x | - | - | bycopy| |
| 797 | // | scl | | x | - | - | - | null | |
| 798 | // | scl | x | | | - | | byref | |
| 799 | // | scl | x | - | x | - | - | bycopy| |
| 800 | // | scl | x | x | - | - | - | null | |
| 801 | // | scl | | - | - | - | x | byref | |
| 802 | // | scl | x | - | - | - | x | byref | |
| 803 | // |
| 804 | // | agg | n.a. | | | - | | byref | |
| 805 | // | agg | n.a. | - | x | - | - | byref | |
| 806 | // | agg | n.a. | x | - | - | - | null | |
| 807 | // | agg | n.a. | - | - | - | x | byref | |
| 808 | // | agg | n.a. | - | - | - | x[] | byref | |
| 809 | // |
| 810 | // | ptr | n.a. | | | - | | bycopy| |
| 811 | // | ptr | n.a. | - | x | - | - | bycopy| |
| 812 | // | ptr | n.a. | x | - | - | - | null | |
| 813 | // | ptr | n.a. | - | - | - | x | byref | |
| 814 | // | ptr | n.a. | - | - | - | x[] | bycopy| |
| 815 | // | ptr | n.a. | - | - | x | | bycopy| |
| 816 | // | ptr | n.a. | - | - | x | x | bycopy| |
| 817 | // | ptr | n.a. | - | - | x | x[] | bycopy| |
| 818 | // ========================================================================= |
| 819 | // Legend: |
| 820 | // scl - scalar |
| 821 | // ptr - pointer |
| 822 | // agg - aggregate |
| 823 | // x - applies |
| 824 | // - - invalid in this combination |
| 825 | // [] - mapped with an array section |
| 826 | // byref - should be mapped by reference |
| 827 | // byval - should be mapped by value |
| 828 | // null - initialize a local variable to null on the device |
| 829 | // |
| 830 | // Observations: |
| 831 | // - All scalar declarations that show up in a map clause have to be passed |
| 832 | // by reference, because they may have been mapped in the enclosing data |
| 833 | // environment. |
| 834 | // - If the scalar value does not fit the size of uintptr, it has to be |
| 835 | // passed by reference, regardless the result in the table above. |
| 836 | // - For pointers mapped by value that have either an implicit map or an |
| 837 | // array section, the runtime library may pass the NULL value to the |
| 838 | // device instead of the value passed to it by the compiler. |
| 839 | |
| 840 | // FIXME: Right now, only implicit maps are implemented. Properly mapping |
| 841 | // values requires having the map, private, and firstprivate clauses SEMA |
| 842 | // and parsing in place, which we don't yet. |
| 843 | |
| 844 | if (Ty->isReferenceType()) |
| 845 | Ty = Ty->castAs<ReferenceType>()->getPointeeType(); |
| 846 | IsByRef = !Ty->isScalarType(); |
| 847 | } |
| 848 | |
| 849 | // When passing data by value, we need to make sure it fits the uintptr size |
| 850 | // and alignment, because the runtime library only deals with uintptr types. |
| 851 | // If it does not fit the uintptr size, we need to pass the data by reference |
| 852 | // instead. |
| 853 | if (!IsByRef && |
| 854 | (Ctx.getTypeSizeInChars(Ty) > |
| 855 | Ctx.getTypeSizeInChars(Ctx.getUIntPtrType()) || |
| 856 | Ctx.getDeclAlign(VD) > Ctx.getTypeAlignInChars(Ctx.getUIntPtrType()))) |
| 857 | IsByRef = true; |
| 858 | |
| 859 | return IsByRef; |
| 860 | } |
| 861 | |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 862 | bool Sema::IsOpenMPCapturedVar(VarDecl *VD) { |
| 863 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 864 | VD = VD->getCanonicalDecl(); |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 865 | |
| 866 | // If we are attempting to capture a global variable in a directive with |
| 867 | // 'target' we return true so that this global is also mapped to the device. |
| 868 | // |
| 869 | // FIXME: If the declaration is enclosed in a 'declare target' directive, |
| 870 | // then it should not be captured. Therefore, an extra check has to be |
| 871 | // inserted here once support for 'declare target' is added. |
| 872 | // |
| 873 | if (!VD->hasLocalStorage()) { |
| 874 | if (DSAStack->getCurrentDirective() == OMPD_target && |
| 875 | !DSAStack->isClauseParsingMode()) { |
| 876 | return true; |
| 877 | } |
| 878 | if (DSAStack->getCurScope() && |
| 879 | DSAStack->hasDirective( |
| 880 | [](OpenMPDirectiveKind K, const DeclarationNameInfo &DNI, |
| 881 | SourceLocation Loc) -> bool { |
| 882 | return isOpenMPTargetDirective(K); |
| 883 | }, |
| 884 | false)) { |
| 885 | return true; |
| 886 | } |
| 887 | } |
| 888 | |
Alexey Bataev | 48977c3 | 2015-08-04 08:10:48 +0000 | [diff] [blame] | 889 | if (DSAStack->getCurrentDirective() != OMPD_unknown && |
| 890 | (!DSAStack->isClauseParsingMode() || |
| 891 | DSAStack->getParentDirective() != OMPD_unknown)) { |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 892 | if (DSAStack->isLoopControlVariable(VD) || |
| 893 | (VD->hasLocalStorage() && |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 894 | isParallelOrTaskRegion(DSAStack->getCurrentDirective())) || |
| 895 | DSAStack->isForceVarCapturing()) |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 896 | return true; |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 897 | auto DVarPrivate = DSAStack->getTopDSA(VD, DSAStack->isClauseParsingMode()); |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 898 | if (DVarPrivate.CKind != OMPC_unknown && isOpenMPPrivate(DVarPrivate.CKind)) |
| 899 | return true; |
| 900 | DVarPrivate = DSAStack->hasDSA(VD, isOpenMPPrivate, MatchesAlways(), |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 901 | DSAStack->isClauseParsingMode()); |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 902 | return DVarPrivate.CKind != OMPC_unknown; |
| 903 | } |
| 904 | return false; |
| 905 | } |
| 906 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 907 | bool Sema::isOpenMPPrivateVar(VarDecl *VD, unsigned Level) { |
| 908 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| 909 | return DSAStack->hasExplicitDSA( |
| 910 | VD, [](OpenMPClauseKind K) -> bool { return K == OMPC_private; }, Level); |
| 911 | } |
| 912 | |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 913 | bool Sema::isOpenMPTargetCapturedVar(VarDecl *VD, unsigned Level) { |
| 914 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| 915 | // Return true if the current level is no longer enclosed in a target region. |
| 916 | |
| 917 | return !VD->hasLocalStorage() && |
| 918 | DSAStack->hasExplicitDirective(isOpenMPTargetDirective, Level); |
| 919 | } |
| 920 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 921 | void Sema::DestroyDataSharingAttributesStack() { delete DSAStack; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 922 | |
| 923 | void Sema::StartOpenMPDSABlock(OpenMPDirectiveKind DKind, |
| 924 | const DeclarationNameInfo &DirName, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 925 | Scope *CurScope, SourceLocation Loc) { |
| 926 | DSAStack->push(DKind, DirName, CurScope, Loc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 927 | PushExpressionEvaluationContext(PotentiallyEvaluated); |
| 928 | } |
| 929 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 930 | void Sema::StartOpenMPClause(OpenMPClauseKind K) { |
| 931 | DSAStack->setClauseParsingMode(K); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 932 | } |
| 933 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 934 | void Sema::EndOpenMPClause() { |
| 935 | DSAStack->setClauseParsingMode(/*K=*/OMPC_unknown); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 936 | } |
| 937 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 938 | void Sema::EndOpenMPDSABlock(Stmt *CurDirective) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 939 | // OpenMP [2.14.3.5, Restrictions, C/C++, p.1] |
| 940 | // A variable of class type (or array thereof) that appears in a lastprivate |
| 941 | // clause requires an accessible, unambiguous default constructor for the |
| 942 | // class type, unless the list item is also specified in a firstprivate |
| 943 | // clause. |
| 944 | if (auto D = dyn_cast_or_null<OMPExecutableDirective>(CurDirective)) { |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 945 | for (auto *C : D->clauses()) { |
| 946 | if (auto *Clause = dyn_cast<OMPLastprivateClause>(C)) { |
| 947 | SmallVector<Expr *, 8> PrivateCopies; |
| 948 | for (auto *DE : Clause->varlists()) { |
| 949 | if (DE->isValueDependent() || DE->isTypeDependent()) { |
| 950 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 951 | continue; |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 952 | } |
| 953 | auto *VD = cast<VarDecl>(cast<DeclRefExpr>(DE)->getDecl()); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 954 | QualType Type = VD->getType().getNonReferenceType(); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 955 | auto DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 956 | if (DVar.CKind == OMPC_lastprivate) { |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 957 | // Generate helper private variable and initialize it with the |
| 958 | // default value. The address of the original variable is replaced |
| 959 | // by the address of the new private variable in CodeGen. This new |
| 960 | // variable is not added to IdResolver, so the code in the OpenMP |
| 961 | // region uses original variable for proper diagnostics. |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 962 | auto *VDPrivate = buildVarDecl( |
| 963 | *this, DE->getExprLoc(), Type.getUnqualifiedType(), |
| 964 | VD->getName(), VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 965 | ActOnUninitializedDecl(VDPrivate, /*TypeMayContainAuto=*/false); |
| 966 | if (VDPrivate->isInvalidDecl()) |
| 967 | continue; |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 968 | PrivateCopies.push_back(buildDeclRefExpr( |
| 969 | *this, VDPrivate, DE->getType(), DE->getExprLoc())); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 970 | } else { |
| 971 | // The variable is also a firstprivate, so initialization sequence |
| 972 | // for private copy is generated already. |
| 973 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 974 | } |
| 975 | } |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 976 | // Set initializers to private copies if no errors were found. |
| 977 | if (PrivateCopies.size() == Clause->varlist_size()) { |
| 978 | Clause->setPrivateCopies(PrivateCopies); |
| 979 | } |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 980 | } |
| 981 | } |
| 982 | } |
| 983 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 984 | DSAStack->pop(); |
| 985 | DiscardCleanupsInEvaluationContext(); |
| 986 | PopExpressionEvaluationContext(); |
| 987 | } |
| 988 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 989 | static bool FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV, |
| 990 | Expr *NumIterations, Sema &SemaRef, |
| 991 | Scope *S); |
| 992 | |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 993 | namespace { |
| 994 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 995 | class VarDeclFilterCCC : public CorrectionCandidateCallback { |
| 996 | private: |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 997 | Sema &SemaRef; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 998 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 999 | public: |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1000 | explicit VarDeclFilterCCC(Sema &S) : SemaRef(S) {} |
Craig Topper | e14c0f8 | 2014-03-12 04:55:44 +0000 | [diff] [blame] | 1001 | bool ValidateCandidate(const TypoCorrection &Candidate) override { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1002 | NamedDecl *ND = Candidate.getCorrectionDecl(); |
| 1003 | if (VarDecl *VD = dyn_cast_or_null<VarDecl>(ND)) { |
| 1004 | return VD->hasGlobalStorage() && |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1005 | SemaRef.isDeclInScope(ND, SemaRef.getCurLexicalContext(), |
| 1006 | SemaRef.getCurScope()); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1007 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1008 | return false; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1009 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1010 | }; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1011 | } // namespace |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1012 | |
| 1013 | ExprResult Sema::ActOnOpenMPIdExpression(Scope *CurScope, |
| 1014 | CXXScopeSpec &ScopeSpec, |
| 1015 | const DeclarationNameInfo &Id) { |
| 1016 | LookupResult Lookup(*this, Id, LookupOrdinaryName); |
| 1017 | LookupParsedName(Lookup, CurScope, &ScopeSpec, true); |
| 1018 | |
| 1019 | if (Lookup.isAmbiguous()) |
| 1020 | return ExprError(); |
| 1021 | |
| 1022 | VarDecl *VD; |
| 1023 | if (!Lookup.isSingleResult()) { |
Kaelyn Takata | 89c881b | 2014-10-27 18:07:29 +0000 | [diff] [blame] | 1024 | if (TypoCorrection Corrected = CorrectTypo( |
| 1025 | Id, LookupOrdinaryName, CurScope, nullptr, |
| 1026 | llvm::make_unique<VarDeclFilterCCC>(*this), CTK_ErrorRecovery)) { |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 1027 | diagnoseTypo(Corrected, |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 1028 | PDiag(Lookup.empty() |
| 1029 | ? diag::err_undeclared_var_use_suggest |
| 1030 | : diag::err_omp_expected_var_arg_suggest) |
| 1031 | << Id.getName()); |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 1032 | VD = Corrected.getCorrectionDeclAs<VarDecl>(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1033 | } else { |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 1034 | Diag(Id.getLoc(), Lookup.empty() ? diag::err_undeclared_var_use |
| 1035 | : diag::err_omp_expected_var_arg) |
| 1036 | << Id.getName(); |
| 1037 | return ExprError(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1038 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1039 | } else { |
| 1040 | if (!(VD = Lookup.getAsSingle<VarDecl>())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1041 | Diag(Id.getLoc(), diag::err_omp_expected_var_arg) << Id.getName(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1042 | Diag(Lookup.getFoundDecl()->getLocation(), diag::note_declared_at); |
| 1043 | return ExprError(); |
| 1044 | } |
| 1045 | } |
| 1046 | Lookup.suppressDiagnostics(); |
| 1047 | |
| 1048 | // OpenMP [2.9.2, Syntax, C/C++] |
| 1049 | // Variables must be file-scope, namespace-scope, or static block-scope. |
| 1050 | if (!VD->hasGlobalStorage()) { |
| 1051 | Diag(Id.getLoc(), diag::err_omp_global_var_arg) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1052 | << getOpenMPDirectiveName(OMPD_threadprivate) << !VD->isStaticLocal(); |
| 1053 | bool IsDecl = |
| 1054 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1055 | Diag(VD->getLocation(), |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1056 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1057 | << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1058 | return ExprError(); |
| 1059 | } |
| 1060 | |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1061 | VarDecl *CanonicalVD = VD->getCanonicalDecl(); |
| 1062 | NamedDecl *ND = cast<NamedDecl>(CanonicalVD); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1063 | // OpenMP [2.9.2, Restrictions, C/C++, p.2] |
| 1064 | // A threadprivate directive for file-scope variables must appear outside |
| 1065 | // any definition or declaration. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1066 | if (CanonicalVD->getDeclContext()->isTranslationUnit() && |
| 1067 | !getCurLexicalContext()->isTranslationUnit()) { |
| 1068 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1069 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1070 | bool IsDecl = |
| 1071 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1072 | Diag(VD->getLocation(), |
| 1073 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1074 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1075 | return ExprError(); |
| 1076 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1077 | // OpenMP [2.9.2, Restrictions, C/C++, p.3] |
| 1078 | // A threadprivate directive for static class member variables must appear |
| 1079 | // in the class definition, in the same scope in which the member |
| 1080 | // variables are declared. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1081 | if (CanonicalVD->isStaticDataMember() && |
| 1082 | !CanonicalVD->getDeclContext()->Equals(getCurLexicalContext())) { |
| 1083 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1084 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1085 | bool IsDecl = |
| 1086 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1087 | Diag(VD->getLocation(), |
| 1088 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1089 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1090 | return ExprError(); |
| 1091 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1092 | // OpenMP [2.9.2, Restrictions, C/C++, p.4] |
| 1093 | // A threadprivate directive for namespace-scope variables must appear |
| 1094 | // outside any definition or declaration other than the namespace |
| 1095 | // definition itself. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1096 | if (CanonicalVD->getDeclContext()->isNamespace() && |
| 1097 | (!getCurLexicalContext()->isFileContext() || |
| 1098 | !getCurLexicalContext()->Encloses(CanonicalVD->getDeclContext()))) { |
| 1099 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1100 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1101 | bool IsDecl = |
| 1102 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1103 | Diag(VD->getLocation(), |
| 1104 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1105 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1106 | return ExprError(); |
| 1107 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1108 | // OpenMP [2.9.2, Restrictions, C/C++, p.6] |
| 1109 | // A threadprivate directive for static block-scope variables must appear |
| 1110 | // in the scope of the variable and not in a nested scope. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1111 | if (CanonicalVD->isStaticLocal() && CurScope && |
| 1112 | !isDeclInScope(ND, getCurLexicalContext(), CurScope)) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1113 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1114 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1115 | bool IsDecl = |
| 1116 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1117 | Diag(VD->getLocation(), |
| 1118 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1119 | << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1120 | return ExprError(); |
| 1121 | } |
| 1122 | |
| 1123 | // OpenMP [2.9.2, Restrictions, C/C++, p.2-6] |
| 1124 | // A threadprivate directive must lexically precede all references to any |
| 1125 | // of the variables in its list. |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 1126 | if (VD->isUsed() && !DSAStack->isThreadPrivate(VD)) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1127 | Diag(Id.getLoc(), diag::err_omp_var_used) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1128 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1129 | return ExprError(); |
| 1130 | } |
| 1131 | |
| 1132 | QualType ExprType = VD->getType().getNonReferenceType(); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 1133 | ExprResult DE = buildDeclRefExpr(*this, VD, ExprType, Id.getLoc()); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1134 | return DE; |
| 1135 | } |
| 1136 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1137 | Sema::DeclGroupPtrTy |
| 1138 | Sema::ActOnOpenMPThreadprivateDirective(SourceLocation Loc, |
| 1139 | ArrayRef<Expr *> VarList) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1140 | if (OMPThreadPrivateDecl *D = CheckOMPThreadPrivateDecl(Loc, VarList)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1141 | CurContext->addDecl(D); |
| 1142 | return DeclGroupPtrTy::make(DeclGroupRef(D)); |
| 1143 | } |
David Blaikie | 0403cb1 | 2016-01-15 23:43:25 +0000 | [diff] [blame] | 1144 | return nullptr; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1145 | } |
| 1146 | |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1147 | namespace { |
| 1148 | class LocalVarRefChecker : public ConstStmtVisitor<LocalVarRefChecker, bool> { |
| 1149 | Sema &SemaRef; |
| 1150 | |
| 1151 | public: |
| 1152 | bool VisitDeclRefExpr(const DeclRefExpr *E) { |
| 1153 | if (auto VD = dyn_cast<VarDecl>(E->getDecl())) { |
| 1154 | if (VD->hasLocalStorage()) { |
| 1155 | SemaRef.Diag(E->getLocStart(), |
| 1156 | diag::err_omp_local_var_in_threadprivate_init) |
| 1157 | << E->getSourceRange(); |
| 1158 | SemaRef.Diag(VD->getLocation(), diag::note_defined_here) |
| 1159 | << VD << VD->getSourceRange(); |
| 1160 | return true; |
| 1161 | } |
| 1162 | } |
| 1163 | return false; |
| 1164 | } |
| 1165 | bool VisitStmt(const Stmt *S) { |
| 1166 | for (auto Child : S->children()) { |
| 1167 | if (Child && Visit(Child)) |
| 1168 | return true; |
| 1169 | } |
| 1170 | return false; |
| 1171 | } |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 1172 | explicit LocalVarRefChecker(Sema &SemaRef) : SemaRef(SemaRef) {} |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1173 | }; |
| 1174 | } // namespace |
| 1175 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1176 | OMPThreadPrivateDecl * |
| 1177 | Sema::CheckOMPThreadPrivateDecl(SourceLocation Loc, ArrayRef<Expr *> VarList) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1178 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1179 | for (auto &RefExpr : VarList) { |
| 1180 | DeclRefExpr *DE = cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1181 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); |
| 1182 | SourceLocation ILoc = DE->getExprLoc(); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1183 | |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 1184 | QualType QType = VD->getType(); |
| 1185 | if (QType->isDependentType() || QType->isInstantiationDependentType()) { |
| 1186 | // It will be analyzed later. |
| 1187 | Vars.push_back(DE); |
| 1188 | continue; |
| 1189 | } |
| 1190 | |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1191 | // OpenMP [2.9.2, Restrictions, C/C++, p.10] |
| 1192 | // A threadprivate variable must not have an incomplete type. |
| 1193 | if (RequireCompleteType(ILoc, VD->getType(), |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1194 | diag::err_omp_threadprivate_incomplete_type)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1195 | continue; |
| 1196 | } |
| 1197 | |
| 1198 | // OpenMP [2.9.2, Restrictions, C/C++, p.10] |
| 1199 | // A threadprivate variable must not have a reference type. |
| 1200 | if (VD->getType()->isReferenceType()) { |
| 1201 | Diag(ILoc, diag::err_omp_ref_type_arg) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1202 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD->getType(); |
| 1203 | bool IsDecl = |
| 1204 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1205 | Diag(VD->getLocation(), |
| 1206 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1207 | << VD; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1208 | continue; |
| 1209 | } |
| 1210 | |
Samuel Antao | f8b5012 | 2015-07-13 22:54:53 +0000 | [diff] [blame] | 1211 | // Check if this is a TLS variable. If TLS is not being supported, produce |
| 1212 | // the corresponding diagnostic. |
| 1213 | if ((VD->getTLSKind() != VarDecl::TLS_None && |
| 1214 | !(VD->hasAttr<OMPThreadPrivateDeclAttr>() && |
| 1215 | getLangOpts().OpenMPUseTLS && |
| 1216 | getASTContext().getTargetInfo().isTLSSupported())) || |
Alexey Bataev | 1a8b3f1 | 2015-05-06 06:34:55 +0000 | [diff] [blame] | 1217 | (VD->getStorageClass() == SC_Register && VD->hasAttr<AsmLabelAttr>() && |
| 1218 | !VD->isLocalVarDecl())) { |
Alexey Bataev | 26a3924 | 2015-01-13 03:35:30 +0000 | [diff] [blame] | 1219 | Diag(ILoc, diag::err_omp_var_thread_local) |
| 1220 | << VD << ((VD->getTLSKind() != VarDecl::TLS_None) ? 0 : 1); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1221 | bool IsDecl = |
| 1222 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1223 | Diag(VD->getLocation(), |
| 1224 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1225 | << VD; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1226 | continue; |
| 1227 | } |
| 1228 | |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1229 | // Check if initial value of threadprivate variable reference variable with |
| 1230 | // local storage (it is not supported by runtime). |
| 1231 | if (auto Init = VD->getAnyInitializer()) { |
| 1232 | LocalVarRefChecker Checker(*this); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1233 | if (Checker.Visit(Init)) |
| 1234 | continue; |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1235 | } |
| 1236 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1237 | Vars.push_back(RefExpr); |
Alexey Bataev | d178ad4 | 2014-03-07 08:03:37 +0000 | [diff] [blame] | 1238 | DSAStack->addDSA(VD, DE, OMPC_threadprivate); |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 1239 | VD->addAttr(OMPThreadPrivateDeclAttr::CreateImplicit( |
| 1240 | Context, SourceRange(Loc, Loc))); |
| 1241 | if (auto *ML = Context.getASTMutationListener()) |
| 1242 | ML->DeclarationMarkedOpenMPThreadPrivate(VD); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1243 | } |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 1244 | OMPThreadPrivateDecl *D = nullptr; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 1245 | if (!Vars.empty()) { |
| 1246 | D = OMPThreadPrivateDecl::Create(Context, getCurLexicalContext(), Loc, |
| 1247 | Vars); |
| 1248 | D->setAccess(AS_public); |
| 1249 | } |
| 1250 | return D; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1251 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1252 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1253 | static void ReportOriginalDSA(Sema &SemaRef, DSAStackTy *Stack, |
| 1254 | const VarDecl *VD, DSAStackTy::DSAVarData DVar, |
| 1255 | bool IsLoopIterVar = false) { |
| 1256 | if (DVar.RefExpr) { |
| 1257 | SemaRef.Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_explicit_dsa) |
| 1258 | << getOpenMPClauseName(DVar.CKind); |
| 1259 | return; |
| 1260 | } |
| 1261 | enum { |
| 1262 | PDSA_StaticMemberShared, |
| 1263 | PDSA_StaticLocalVarShared, |
| 1264 | PDSA_LoopIterVarPrivate, |
| 1265 | PDSA_LoopIterVarLinear, |
| 1266 | PDSA_LoopIterVarLastprivate, |
| 1267 | PDSA_ConstVarShared, |
| 1268 | PDSA_GlobalVarShared, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1269 | PDSA_TaskVarFirstprivate, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1270 | PDSA_LocalVarPrivate, |
| 1271 | PDSA_Implicit |
| 1272 | } Reason = PDSA_Implicit; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1273 | bool ReportHint = false; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1274 | auto ReportLoc = VD->getLocation(); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1275 | if (IsLoopIterVar) { |
| 1276 | if (DVar.CKind == OMPC_private) |
| 1277 | Reason = PDSA_LoopIterVarPrivate; |
| 1278 | else if (DVar.CKind == OMPC_lastprivate) |
| 1279 | Reason = PDSA_LoopIterVarLastprivate; |
| 1280 | else |
| 1281 | Reason = PDSA_LoopIterVarLinear; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1282 | } else if (DVar.DKind == OMPD_task && DVar.CKind == OMPC_firstprivate) { |
| 1283 | Reason = PDSA_TaskVarFirstprivate; |
| 1284 | ReportLoc = DVar.ImplicitDSALoc; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1285 | } else if (VD->isStaticLocal()) |
| 1286 | Reason = PDSA_StaticLocalVarShared; |
| 1287 | else if (VD->isStaticDataMember()) |
| 1288 | Reason = PDSA_StaticMemberShared; |
| 1289 | else if (VD->isFileVarDecl()) |
| 1290 | Reason = PDSA_GlobalVarShared; |
| 1291 | else if (VD->getType().isConstant(SemaRef.getASTContext())) |
| 1292 | Reason = PDSA_ConstVarShared; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1293 | else if (VD->isLocalVarDecl() && DVar.CKind == OMPC_private) { |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1294 | ReportHint = true; |
| 1295 | Reason = PDSA_LocalVarPrivate; |
| 1296 | } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1297 | if (Reason != PDSA_Implicit) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1298 | SemaRef.Diag(ReportLoc, diag::note_omp_predetermined_dsa) |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1299 | << Reason << ReportHint |
| 1300 | << getOpenMPDirectiveName(Stack->getCurrentDirective()); |
| 1301 | } else if (DVar.ImplicitDSALoc.isValid()) { |
| 1302 | SemaRef.Diag(DVar.ImplicitDSALoc, diag::note_omp_implicit_dsa) |
| 1303 | << getOpenMPClauseName(DVar.CKind); |
| 1304 | } |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1305 | } |
| 1306 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1307 | namespace { |
| 1308 | class DSAAttrChecker : public StmtVisitor<DSAAttrChecker, void> { |
| 1309 | DSAStackTy *Stack; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1310 | Sema &SemaRef; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1311 | bool ErrorFound; |
| 1312 | CapturedStmt *CS; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1313 | llvm::SmallVector<Expr *, 8> ImplicitFirstprivate; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1314 | llvm::DenseMap<VarDecl *, Expr *> VarsWithInheritedDSA; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1315 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1316 | public: |
| 1317 | void VisitDeclRefExpr(DeclRefExpr *E) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1318 | if (auto *VD = dyn_cast<VarDecl>(E->getDecl())) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1319 | // Skip internally declared variables. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1320 | if (VD->isLocalVarDecl() && !CS->capturesVariable(VD)) |
| 1321 | return; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1322 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1323 | auto DVar = Stack->getTopDSA(VD, false); |
| 1324 | // Check if the variable has explicit DSA set and stop analysis if it so. |
| 1325 | if (DVar.RefExpr) return; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1326 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1327 | auto ELoc = E->getExprLoc(); |
| 1328 | auto DKind = Stack->getCurrentDirective(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1329 | // The default(none) clause requires that each variable that is referenced |
| 1330 | // in the construct, and does not have a predetermined data-sharing |
| 1331 | // attribute, must have its data-sharing attribute explicitly determined |
| 1332 | // by being listed in a data-sharing attribute clause. |
| 1333 | if (DVar.CKind == OMPC_unknown && Stack->getDefaultDSA() == DSA_none && |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1334 | isParallelOrTaskRegion(DKind) && |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1335 | VarsWithInheritedDSA.count(VD) == 0) { |
| 1336 | VarsWithInheritedDSA[VD] = E; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1337 | return; |
| 1338 | } |
| 1339 | |
| 1340 | // OpenMP [2.9.3.6, Restrictions, p.2] |
| 1341 | // A list item that appears in a reduction clause of the innermost |
| 1342 | // enclosing worksharing or parallel construct may not be accessed in an |
| 1343 | // explicit task. |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1344 | DVar = Stack->hasInnermostDSA(VD, MatchesAnyClause(OMPC_reduction), |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1345 | [](OpenMPDirectiveKind K) -> bool { |
| 1346 | return isOpenMPParallelDirective(K) || |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1347 | isOpenMPWorksharingDirective(K) || |
| 1348 | isOpenMPTeamsDirective(K); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1349 | }, |
| 1350 | false); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1351 | if (DKind == OMPD_task && DVar.CKind == OMPC_reduction) { |
| 1352 | ErrorFound = true; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1353 | SemaRef.Diag(ELoc, diag::err_omp_reduction_in_task); |
| 1354 | ReportOriginalDSA(SemaRef, Stack, VD, DVar); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1355 | return; |
| 1356 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1357 | |
| 1358 | // Define implicit data-sharing attributes for task. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1359 | DVar = Stack->getImplicitDSA(VD, false); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1360 | if (DKind == OMPD_task && DVar.CKind != OMPC_shared) |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1361 | ImplicitFirstprivate.push_back(E); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1362 | } |
| 1363 | } |
| 1364 | void VisitOMPExecutableDirective(OMPExecutableDirective *S) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1365 | for (auto *C : S->clauses()) { |
| 1366 | // Skip analysis of arguments of implicitly defined firstprivate clause |
| 1367 | // for task directives. |
| 1368 | if (C && (!isa<OMPFirstprivateClause>(C) || C->getLocStart().isValid())) |
| 1369 | for (auto *CC : C->children()) { |
| 1370 | if (CC) |
| 1371 | Visit(CC); |
| 1372 | } |
| 1373 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1374 | } |
| 1375 | void VisitStmt(Stmt *S) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1376 | for (auto *C : S->children()) { |
| 1377 | if (C && !isa<OMPExecutableDirective>(C)) |
| 1378 | Visit(C); |
| 1379 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1380 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1381 | |
| 1382 | bool isErrorFound() { return ErrorFound; } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1383 | ArrayRef<Expr *> getImplicitFirstprivate() { return ImplicitFirstprivate; } |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1384 | llvm::DenseMap<VarDecl *, Expr *> &getVarsWithInheritedDSA() { |
| 1385 | return VarsWithInheritedDSA; |
| 1386 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1387 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1388 | DSAAttrChecker(DSAStackTy *S, Sema &SemaRef, CapturedStmt *CS) |
| 1389 | : Stack(S), SemaRef(SemaRef), ErrorFound(false), CS(CS) {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1390 | }; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1391 | } // namespace |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1392 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1393 | void Sema::ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, Scope *CurScope) { |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1394 | switch (DKind) { |
| 1395 | case OMPD_parallel: { |
| 1396 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1397 | QualType KmpInt32PtrTy = |
| 1398 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1399 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1400 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1401 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1402 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1403 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1404 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1405 | Params); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1406 | break; |
| 1407 | } |
| 1408 | case OMPD_simd: { |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1409 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1410 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1411 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1412 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1413 | Params); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1414 | break; |
| 1415 | } |
| 1416 | case OMPD_for: { |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1417 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1418 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1419 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1420 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1421 | Params); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1422 | break; |
| 1423 | } |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1424 | case OMPD_for_simd: { |
| 1425 | Sema::CapturedParamNameType Params[] = { |
| 1426 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1427 | }; |
| 1428 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1429 | Params); |
| 1430 | break; |
| 1431 | } |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 1432 | case OMPD_sections: { |
| 1433 | Sema::CapturedParamNameType Params[] = { |
| 1434 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1435 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1436 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1437 | Params); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 1438 | break; |
| 1439 | } |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1440 | case OMPD_section: { |
| 1441 | Sema::CapturedParamNameType Params[] = { |
| 1442 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1443 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1444 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1445 | Params); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1446 | break; |
| 1447 | } |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 1448 | case OMPD_single: { |
| 1449 | Sema::CapturedParamNameType Params[] = { |
| 1450 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1451 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1452 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1453 | Params); |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 1454 | break; |
| 1455 | } |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1456 | case OMPD_master: { |
| 1457 | Sema::CapturedParamNameType Params[] = { |
| 1458 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1459 | }; |
| 1460 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1461 | Params); |
| 1462 | break; |
| 1463 | } |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1464 | case OMPD_critical: { |
| 1465 | Sema::CapturedParamNameType Params[] = { |
| 1466 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1467 | }; |
| 1468 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1469 | Params); |
| 1470 | break; |
| 1471 | } |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1472 | case OMPD_parallel_for: { |
| 1473 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1474 | QualType KmpInt32PtrTy = |
| 1475 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1476 | Sema::CapturedParamNameType Params[] = { |
| 1477 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1478 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1479 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1480 | }; |
| 1481 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1482 | Params); |
| 1483 | break; |
| 1484 | } |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1485 | case OMPD_parallel_for_simd: { |
| 1486 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1487 | QualType KmpInt32PtrTy = |
| 1488 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1489 | Sema::CapturedParamNameType Params[] = { |
| 1490 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1491 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1492 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1493 | }; |
| 1494 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1495 | Params); |
| 1496 | break; |
| 1497 | } |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1498 | case OMPD_parallel_sections: { |
Alexey Bataev | 68adb7d | 2015-04-14 03:29:22 +0000 | [diff] [blame] | 1499 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1500 | QualType KmpInt32PtrTy = |
| 1501 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1502 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | 68adb7d | 2015-04-14 03:29:22 +0000 | [diff] [blame] | 1503 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1504 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1505 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1506 | }; |
| 1507 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1508 | Params); |
| 1509 | break; |
| 1510 | } |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1511 | case OMPD_task: { |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1512 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 3ae88e2 | 2015-05-22 08:56:35 +0000 | [diff] [blame] | 1513 | QualType Args[] = {Context.VoidPtrTy.withConst().withRestrict()}; |
| 1514 | FunctionProtoType::ExtProtoInfo EPI; |
| 1515 | EPI.Variadic = true; |
| 1516 | QualType CopyFnType = Context.getFunctionType(Context.VoidTy, Args, EPI); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1517 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1518 | std::make_pair(".global_tid.", KmpInt32Ty), |
| 1519 | std::make_pair(".part_id.", KmpInt32Ty), |
Alexey Bataev | 3ae88e2 | 2015-05-22 08:56:35 +0000 | [diff] [blame] | 1520 | std::make_pair(".privates.", |
| 1521 | Context.VoidPtrTy.withConst().withRestrict()), |
| 1522 | std::make_pair( |
| 1523 | ".copy_fn.", |
| 1524 | Context.getPointerType(CopyFnType).withConst().withRestrict()), |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1525 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1526 | }; |
| 1527 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1528 | Params); |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1529 | // Mark this captured region as inlined, because we don't use outlined |
| 1530 | // function directly. |
| 1531 | getCurCapturedRegion()->TheCapturedDecl->addAttr( |
| 1532 | AlwaysInlineAttr::CreateImplicit( |
| 1533 | Context, AlwaysInlineAttr::Keyword_forceinline, SourceRange())); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1534 | break; |
| 1535 | } |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1536 | case OMPD_ordered: { |
| 1537 | Sema::CapturedParamNameType Params[] = { |
| 1538 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1539 | }; |
| 1540 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1541 | Params); |
| 1542 | break; |
| 1543 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1544 | case OMPD_atomic: { |
| 1545 | Sema::CapturedParamNameType Params[] = { |
| 1546 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1547 | }; |
| 1548 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1549 | Params); |
| 1550 | break; |
| 1551 | } |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 1552 | case OMPD_target_data: |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1553 | case OMPD_target: { |
| 1554 | Sema::CapturedParamNameType Params[] = { |
| 1555 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1556 | }; |
| 1557 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1558 | Params); |
| 1559 | break; |
| 1560 | } |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1561 | case OMPD_teams: { |
| 1562 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1563 | QualType KmpInt32PtrTy = |
| 1564 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1565 | Sema::CapturedParamNameType Params[] = { |
| 1566 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1567 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1568 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1569 | }; |
| 1570 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1571 | Params); |
| 1572 | break; |
| 1573 | } |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1574 | case OMPD_taskgroup: { |
| 1575 | Sema::CapturedParamNameType Params[] = { |
| 1576 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1577 | }; |
| 1578 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1579 | Params); |
| 1580 | break; |
| 1581 | } |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1582 | case OMPD_taskloop: { |
| 1583 | Sema::CapturedParamNameType Params[] = { |
| 1584 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1585 | }; |
| 1586 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1587 | Params); |
| 1588 | break; |
| 1589 | } |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1590 | case OMPD_taskloop_simd: { |
| 1591 | Sema::CapturedParamNameType Params[] = { |
| 1592 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1593 | }; |
| 1594 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1595 | Params); |
| 1596 | break; |
| 1597 | } |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1598 | case OMPD_distribute: { |
| 1599 | Sema::CapturedParamNameType Params[] = { |
| 1600 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1601 | }; |
| 1602 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1603 | Params); |
| 1604 | break; |
| 1605 | } |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1606 | case OMPD_threadprivate: |
Alexey Bataev | ee9af45 | 2014-11-21 11:33:46 +0000 | [diff] [blame] | 1607 | case OMPD_taskyield: |
| 1608 | case OMPD_barrier: |
| 1609 | case OMPD_taskwait: |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1610 | case OMPD_cancellation_point: |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1611 | case OMPD_cancel: |
Alexey Bataev | ee9af45 | 2014-11-21 11:33:46 +0000 | [diff] [blame] | 1612 | case OMPD_flush: |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1613 | case OMPD_target_enter_data: |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1614 | case OMPD_target_exit_data: |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1615 | llvm_unreachable("OpenMP Directive is not allowed"); |
| 1616 | case OMPD_unknown: |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1617 | llvm_unreachable("Unknown OpenMP directive"); |
| 1618 | } |
| 1619 | } |
| 1620 | |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1621 | StmtResult Sema::ActOnOpenMPRegionEnd(StmtResult S, |
| 1622 | ArrayRef<OMPClause *> Clauses) { |
| 1623 | if (!S.isUsable()) { |
| 1624 | ActOnCapturedRegionError(); |
| 1625 | return StmtError(); |
| 1626 | } |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1627 | |
| 1628 | OMPOrderedClause *OC = nullptr; |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1629 | OMPScheduleClause *SC = nullptr; |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1630 | SmallVector<OMPLinearClause *, 4> LCs; |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1631 | // This is required for proper codegen. |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1632 | for (auto *Clause : Clauses) { |
Alexey Bataev | 16dc7b6 | 2015-05-20 03:46:04 +0000 | [diff] [blame] | 1633 | if (isOpenMPPrivate(Clause->getClauseKind()) || |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 1634 | Clause->getClauseKind() == OMPC_copyprivate || |
| 1635 | (getLangOpts().OpenMPUseTLS && |
| 1636 | getASTContext().getTargetInfo().isTLSSupported() && |
| 1637 | Clause->getClauseKind() == OMPC_copyin)) { |
| 1638 | DSAStack->setForceVarCapturing(Clause->getClauseKind() == OMPC_copyin); |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1639 | // Mark all variables in private list clauses as used in inner region. |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1640 | for (auto *VarRef : Clause->children()) { |
| 1641 | if (auto *E = cast_or_null<Expr>(VarRef)) { |
Alexey Bataev | 8bf6b3e | 2015-04-02 13:07:08 +0000 | [diff] [blame] | 1642 | MarkDeclarationsReferencedInExpr(E); |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1643 | } |
| 1644 | } |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 1645 | DSAStack->setForceVarCapturing(/*V=*/false); |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1646 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective()) && |
| 1647 | Clause->getClauseKind() == OMPC_schedule) { |
| 1648 | // Mark all variables in private list clauses as used in inner region. |
| 1649 | // Required for proper codegen of combined directives. |
| 1650 | // TODO: add processing for other clauses. |
| 1651 | if (auto *E = cast_or_null<Expr>( |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1652 | cast<OMPScheduleClause>(Clause)->getHelperChunkSize())) |
| 1653 | MarkDeclarationsReferencedInExpr(E); |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1654 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1655 | if (Clause->getClauseKind() == OMPC_schedule) |
| 1656 | SC = cast<OMPScheduleClause>(Clause); |
| 1657 | else if (Clause->getClauseKind() == OMPC_ordered) |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1658 | OC = cast<OMPOrderedClause>(Clause); |
| 1659 | else if (Clause->getClauseKind() == OMPC_linear) |
| 1660 | LCs.push_back(cast<OMPLinearClause>(Clause)); |
| 1661 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1662 | bool ErrorFound = false; |
| 1663 | // OpenMP, 2.7.1 Loop Construct, Restrictions |
| 1664 | // The nonmonotonic modifier cannot be specified if an ordered clause is |
| 1665 | // specified. |
| 1666 | if (SC && |
| 1667 | (SC->getFirstScheduleModifier() == OMPC_SCHEDULE_MODIFIER_nonmonotonic || |
| 1668 | SC->getSecondScheduleModifier() == |
| 1669 | OMPC_SCHEDULE_MODIFIER_nonmonotonic) && |
| 1670 | OC) { |
| 1671 | Diag(SC->getFirstScheduleModifier() == OMPC_SCHEDULE_MODIFIER_nonmonotonic |
| 1672 | ? SC->getFirstScheduleModifierLoc() |
| 1673 | : SC->getSecondScheduleModifierLoc(), |
| 1674 | diag::err_omp_schedule_nonmonotonic_ordered) |
| 1675 | << SourceRange(OC->getLocStart(), OC->getLocEnd()); |
| 1676 | ErrorFound = true; |
| 1677 | } |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1678 | if (!LCs.empty() && OC && OC->getNumForLoops()) { |
| 1679 | for (auto *C : LCs) { |
| 1680 | Diag(C->getLocStart(), diag::err_omp_linear_ordered) |
| 1681 | << SourceRange(OC->getLocStart(), OC->getLocEnd()); |
| 1682 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1683 | ErrorFound = true; |
| 1684 | } |
Alexey Bataev | 113438c | 2015-12-30 12:06:23 +0000 | [diff] [blame] | 1685 | if (isOpenMPWorksharingDirective(DSAStack->getCurrentDirective()) && |
| 1686 | isOpenMPSimdDirective(DSAStack->getCurrentDirective()) && OC && |
| 1687 | OC->getNumForLoops()) { |
| 1688 | Diag(OC->getLocStart(), diag::err_omp_ordered_simd) |
| 1689 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 1690 | ErrorFound = true; |
| 1691 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1692 | if (ErrorFound) { |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1693 | ActOnCapturedRegionError(); |
| 1694 | return StmtError(); |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1695 | } |
| 1696 | return ActOnCapturedRegionEnd(S.get()); |
| 1697 | } |
| 1698 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1699 | static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, |
| 1700 | OpenMPDirectiveKind CurrentRegion, |
| 1701 | const DeclarationNameInfo &CurrentName, |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1702 | OpenMPDirectiveKind CancelRegion, |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1703 | SourceLocation StartLoc) { |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1704 | // Allowed nesting of constructs |
| 1705 | // +------------------+-----------------+------------------------------------+ |
| 1706 | // | Parent directive | Child directive | Closely (!), No-Closely(+), Both(*)| |
| 1707 | // +------------------+-----------------+------------------------------------+ |
| 1708 | // | parallel | parallel | * | |
| 1709 | // | parallel | for | * | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1710 | // | parallel | for simd | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1711 | // | parallel | master | * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1712 | // | parallel | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1713 | // | parallel | simd | * | |
| 1714 | // | parallel | sections | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1715 | // | parallel | section | + | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1716 | // | parallel | single | * | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1717 | // | parallel | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1718 | // | parallel |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1719 | // | parallel |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1720 | // | parallel | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1721 | // | parallel | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1722 | // | parallel | barrier | * | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1723 | // | parallel | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1724 | // | parallel | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1725 | // | parallel | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1726 | // | parallel | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1727 | // | parallel | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1728 | // | parallel | target | * | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1729 | // | parallel | target enter | * | |
| 1730 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1731 | // | parallel | target exit | * | |
| 1732 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1733 | // | parallel | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1734 | // | parallel | cancellation | | |
| 1735 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1736 | // | parallel | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1737 | // | parallel | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1738 | // | parallel | taskloop simd | * | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1739 | // | parallel | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1740 | // +------------------+-----------------+------------------------------------+ |
| 1741 | // | for | parallel | * | |
| 1742 | // | for | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1743 | // | for | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1744 | // | for | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1745 | // | for | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1746 | // | for | simd | * | |
| 1747 | // | for | sections | + | |
| 1748 | // | for | section | + | |
| 1749 | // | for | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1750 | // | for | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1751 | // | for |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1752 | // | for |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1753 | // | for | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1754 | // | for | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1755 | // | for | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1756 | // | for | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1757 | // | for | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1758 | // | for | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1759 | // | for | ordered | * (if construct is ordered) | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1760 | // | for | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1761 | // | for | target | * | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1762 | // | for | target enter | * | |
| 1763 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1764 | // | for | target exit | * | |
| 1765 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1766 | // | for | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1767 | // | for | cancellation | | |
| 1768 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1769 | // | for | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1770 | // | for | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1771 | // | for | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1772 | // | for | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1773 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1774 | // | master | parallel | * | |
| 1775 | // | master | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1776 | // | master | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1777 | // | master | master | * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1778 | // | master | critical | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1779 | // | master | simd | * | |
| 1780 | // | master | sections | + | |
| 1781 | // | master | section | + | |
| 1782 | // | master | single | + | |
| 1783 | // | master | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1784 | // | master |parallel for simd| * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1785 | // | master |parallel sections| * | |
| 1786 | // | master | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1787 | // | master | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1788 | // | master | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1789 | // | master | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1790 | // | master | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1791 | // | master | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1792 | // | master | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1793 | // | master | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1794 | // | master | target | * | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1795 | // | master | target enter | * | |
| 1796 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1797 | // | master | target exit | * | |
| 1798 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1799 | // | master | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1800 | // | master | cancellation | | |
| 1801 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1802 | // | master | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1803 | // | master | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1804 | // | master | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1805 | // | master | distribute | | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1806 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1807 | // | critical | parallel | * | |
| 1808 | // | critical | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1809 | // | critical | for simd | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1810 | // | critical | master | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1811 | // | critical | critical | * (should have different names) | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1812 | // | critical | simd | * | |
| 1813 | // | critical | sections | + | |
| 1814 | // | critical | section | + | |
| 1815 | // | critical | single | + | |
| 1816 | // | critical | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1817 | // | critical |parallel for simd| * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1818 | // | critical |parallel sections| * | |
| 1819 | // | critical | task | * | |
| 1820 | // | critical | taskyield | * | |
| 1821 | // | critical | barrier | + | |
| 1822 | // | critical | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1823 | // | critical | taskgroup | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1824 | // | critical | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1825 | // | critical | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1826 | // | critical | target | * | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1827 | // | critical | target enter | * | |
| 1828 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1829 | // | critical | target exit | * | |
| 1830 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1831 | // | critical | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1832 | // | critical | cancellation | | |
| 1833 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1834 | // | critical | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1835 | // | critical | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1836 | // | critical | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1837 | // | critical | distribute | | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1838 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1839 | // | simd | parallel | | |
| 1840 | // | simd | for | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1841 | // | simd | for simd | | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1842 | // | simd | master | | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1843 | // | simd | critical | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1844 | // | simd | simd | | |
| 1845 | // | simd | sections | | |
| 1846 | // | simd | section | | |
| 1847 | // | simd | single | | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1848 | // | simd | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1849 | // | simd |parallel for simd| | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1850 | // | simd |parallel sections| | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1851 | // | simd | task | | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1852 | // | simd | taskyield | | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1853 | // | simd | barrier | | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1854 | // | simd | taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1855 | // | simd | taskgroup | | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1856 | // | simd | flush | | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 1857 | // | simd | ordered | + (with simd clause) | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1858 | // | simd | atomic | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1859 | // | simd | target | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1860 | // | simd | target enter | | |
| 1861 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1862 | // | simd | target exit | | |
| 1863 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1864 | // | simd | teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1865 | // | simd | cancellation | | |
| 1866 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1867 | // | simd | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1868 | // | simd | taskloop | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1869 | // | simd | taskloop simd | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1870 | // | simd | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1871 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1872 | // | for simd | parallel | | |
| 1873 | // | for simd | for | | |
| 1874 | // | for simd | for simd | | |
| 1875 | // | for simd | master | | |
| 1876 | // | for simd | critical | | |
| 1877 | // | for simd | simd | | |
| 1878 | // | for simd | sections | | |
| 1879 | // | for simd | section | | |
| 1880 | // | for simd | single | | |
| 1881 | // | for simd | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1882 | // | for simd |parallel for simd| | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1883 | // | for simd |parallel sections| | |
| 1884 | // | for simd | task | | |
| 1885 | // | for simd | taskyield | | |
| 1886 | // | for simd | barrier | | |
| 1887 | // | for simd | taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1888 | // | for simd | taskgroup | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1889 | // | for simd | flush | | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 1890 | // | for simd | ordered | + (with simd clause) | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1891 | // | for simd | atomic | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1892 | // | for simd | target | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1893 | // | for simd | target enter | | |
| 1894 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1895 | // | for simd | target exit | | |
| 1896 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1897 | // | for simd | teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1898 | // | for simd | cancellation | | |
| 1899 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1900 | // | for simd | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1901 | // | for simd | taskloop | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1902 | // | for simd | taskloop simd | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1903 | // | for simd | distribute | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1904 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1905 | // | parallel for simd| parallel | | |
| 1906 | // | parallel for simd| for | | |
| 1907 | // | parallel for simd| for simd | | |
| 1908 | // | parallel for simd| master | | |
| 1909 | // | parallel for simd| critical | | |
| 1910 | // | parallel for simd| simd | | |
| 1911 | // | parallel for simd| sections | | |
| 1912 | // | parallel for simd| section | | |
| 1913 | // | parallel for simd| single | | |
| 1914 | // | parallel for simd| parallel for | | |
| 1915 | // | parallel for simd|parallel for simd| | |
| 1916 | // | parallel for simd|parallel sections| | |
| 1917 | // | parallel for simd| task | | |
| 1918 | // | parallel for simd| taskyield | | |
| 1919 | // | parallel for simd| barrier | | |
| 1920 | // | parallel for simd| taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1921 | // | parallel for simd| taskgroup | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1922 | // | parallel for simd| flush | | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 1923 | // | parallel for simd| ordered | + (with simd clause) | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1924 | // | parallel for simd| atomic | | |
| 1925 | // | parallel for simd| target | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1926 | // | parallel for simd| target enter | | |
| 1927 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1928 | // | parallel for simd| target exit | | |
| 1929 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1930 | // | parallel for simd| teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1931 | // | parallel for simd| cancellation | | |
| 1932 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1933 | // | parallel for simd| cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1934 | // | parallel for simd| taskloop | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1935 | // | parallel for simd| taskloop simd | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1936 | // | parallel for simd| distribute | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1937 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1938 | // | sections | parallel | * | |
| 1939 | // | sections | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1940 | // | sections | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1941 | // | sections | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1942 | // | sections | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1943 | // | sections | simd | * | |
| 1944 | // | sections | sections | + | |
| 1945 | // | sections | section | * | |
| 1946 | // | sections | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1947 | // | sections | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1948 | // | sections |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1949 | // | sections |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1950 | // | sections | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1951 | // | sections | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1952 | // | sections | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1953 | // | sections | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1954 | // | sections | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1955 | // | sections | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1956 | // | sections | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1957 | // | sections | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1958 | // | sections | target | * | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1959 | // | sections | target enter | * | |
| 1960 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1961 | // | sections | target exit | * | |
| 1962 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1963 | // | sections | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1964 | // | sections | cancellation | | |
| 1965 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1966 | // | sections | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1967 | // | sections | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1968 | // | sections | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1969 | // | sections | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1970 | // +------------------+-----------------+------------------------------------+ |
| 1971 | // | section | parallel | * | |
| 1972 | // | section | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1973 | // | section | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1974 | // | section | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1975 | // | section | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1976 | // | section | simd | * | |
| 1977 | // | section | sections | + | |
| 1978 | // | section | section | + | |
| 1979 | // | section | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1980 | // | section | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1981 | // | section |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1982 | // | section |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1983 | // | section | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1984 | // | section | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1985 | // | section | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1986 | // | section | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1987 | // | section | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1988 | // | section | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1989 | // | section | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1990 | // | section | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1991 | // | section | target | * | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1992 | // | section | target enter | * | |
| 1993 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1994 | // | section | target exit | * | |
| 1995 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1996 | // | section | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1997 | // | section | cancellation | | |
| 1998 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1999 | // | section | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2000 | // | section | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2001 | // | section | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2002 | // | section | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2003 | // +------------------+-----------------+------------------------------------+ |
| 2004 | // | single | parallel | * | |
| 2005 | // | single | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2006 | // | single | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2007 | // | single | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2008 | // | single | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2009 | // | single | simd | * | |
| 2010 | // | single | sections | + | |
| 2011 | // | single | section | + | |
| 2012 | // | single | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2013 | // | single | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2014 | // | single |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2015 | // | single |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2016 | // | single | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2017 | // | single | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2018 | // | single | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2019 | // | single | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2020 | // | single | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2021 | // | single | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2022 | // | single | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2023 | // | single | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2024 | // | single | target | * | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2025 | // | single | target enter | * | |
| 2026 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2027 | // | single | target exit | * | |
| 2028 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2029 | // | single | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2030 | // | single | cancellation | | |
| 2031 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2032 | // | single | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2033 | // | single | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2034 | // | single | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2035 | // | single | distribute | | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2036 | // +------------------+-----------------+------------------------------------+ |
| 2037 | // | parallel for | parallel | * | |
| 2038 | // | parallel for | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2039 | // | parallel for | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2040 | // | parallel for | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2041 | // | parallel for | critical | * | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2042 | // | parallel for | simd | * | |
| 2043 | // | parallel for | sections | + | |
| 2044 | // | parallel for | section | + | |
| 2045 | // | parallel for | single | + | |
| 2046 | // | parallel for | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2047 | // | parallel for |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2048 | // | parallel for |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2049 | // | parallel for | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2050 | // | parallel for | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2051 | // | parallel for | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2052 | // | parallel for | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2053 | // | parallel for | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2054 | // | parallel for | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2055 | // | parallel for | ordered | * (if construct is ordered) | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2056 | // | parallel for | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2057 | // | parallel for | target | * | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2058 | // | parallel for | target enter | * | |
| 2059 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2060 | // | parallel for | target exit | * | |
| 2061 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2062 | // | parallel for | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2063 | // | parallel for | cancellation | | |
| 2064 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2065 | // | parallel for | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2066 | // | parallel for | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2067 | // | parallel for | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2068 | // | parallel for | distribute | | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2069 | // +------------------+-----------------+------------------------------------+ |
| 2070 | // | parallel sections| parallel | * | |
| 2071 | // | parallel sections| for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2072 | // | parallel sections| for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2073 | // | parallel sections| master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2074 | // | parallel sections| critical | + | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2075 | // | parallel sections| simd | * | |
| 2076 | // | parallel sections| sections | + | |
| 2077 | // | parallel sections| section | * | |
| 2078 | // | parallel sections| single | + | |
| 2079 | // | parallel sections| parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2080 | // | parallel sections|parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2081 | // | parallel sections|parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2082 | // | parallel sections| task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2083 | // | parallel sections| taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2084 | // | parallel sections| barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2085 | // | parallel sections| taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2086 | // | parallel sections| taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2087 | // | parallel sections| flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2088 | // | parallel sections| ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2089 | // | parallel sections| atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2090 | // | parallel sections| target | * | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2091 | // | parallel sections| target enter | * | |
| 2092 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2093 | // | parallel sections| target exit | * | |
| 2094 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2095 | // | parallel sections| teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2096 | // | parallel sections| cancellation | | |
| 2097 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2098 | // | parallel sections| cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2099 | // | parallel sections| taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2100 | // | parallel sections| taskloop simd | * | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2101 | // | parallel sections| distribute | | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2102 | // +------------------+-----------------+------------------------------------+ |
| 2103 | // | task | parallel | * | |
| 2104 | // | task | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2105 | // | task | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2106 | // | task | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2107 | // | task | critical | * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2108 | // | task | simd | * | |
| 2109 | // | task | sections | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2110 | // | task | section | + | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2111 | // | task | single | + | |
| 2112 | // | task | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2113 | // | task |parallel for simd| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2114 | // | task |parallel sections| * | |
| 2115 | // | task | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2116 | // | task | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2117 | // | task | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2118 | // | task | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2119 | // | task | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2120 | // | task | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2121 | // | task | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2122 | // | task | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2123 | // | task | target | * | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2124 | // | task | target enter | * | |
| 2125 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2126 | // | task | target exit | * | |
| 2127 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2128 | // | task | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2129 | // | task | cancellation | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2130 | // | | point | ! | |
| 2131 | // | task | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2132 | // | task | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2133 | // | task | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2134 | // | task | distribute | | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2135 | // +------------------+-----------------+------------------------------------+ |
| 2136 | // | ordered | parallel | * | |
| 2137 | // | ordered | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2138 | // | ordered | for simd | + | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2139 | // | ordered | master | * | |
| 2140 | // | ordered | critical | * | |
| 2141 | // | ordered | simd | * | |
| 2142 | // | ordered | sections | + | |
| 2143 | // | ordered | section | + | |
| 2144 | // | ordered | single | + | |
| 2145 | // | ordered | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2146 | // | ordered |parallel for simd| * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2147 | // | ordered |parallel sections| * | |
| 2148 | // | ordered | task | * | |
| 2149 | // | ordered | taskyield | * | |
| 2150 | // | ordered | barrier | + | |
| 2151 | // | ordered | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2152 | // | ordered | taskgroup | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2153 | // | ordered | flush | * | |
| 2154 | // | ordered | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2155 | // | ordered | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2156 | // | ordered | target | * | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2157 | // | ordered | target enter | * | |
| 2158 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2159 | // | ordered | target exit | * | |
| 2160 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2161 | // | ordered | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2162 | // | ordered | cancellation | | |
| 2163 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2164 | // | ordered | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2165 | // | ordered | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2166 | // | ordered | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2167 | // | ordered | distribute | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2168 | // +------------------+-----------------+------------------------------------+ |
| 2169 | // | atomic | parallel | | |
| 2170 | // | atomic | for | | |
| 2171 | // | atomic | for simd | | |
| 2172 | // | atomic | master | | |
| 2173 | // | atomic | critical | | |
| 2174 | // | atomic | simd | | |
| 2175 | // | atomic | sections | | |
| 2176 | // | atomic | section | | |
| 2177 | // | atomic | single | | |
| 2178 | // | atomic | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2179 | // | atomic |parallel for simd| | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2180 | // | atomic |parallel sections| | |
| 2181 | // | atomic | task | | |
| 2182 | // | atomic | taskyield | | |
| 2183 | // | atomic | barrier | | |
| 2184 | // | atomic | taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2185 | // | atomic | taskgroup | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2186 | // | atomic | flush | | |
| 2187 | // | atomic | ordered | | |
| 2188 | // | atomic | atomic | | |
| 2189 | // | atomic | target | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2190 | // | atomic | target enter | | |
| 2191 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2192 | // | atomic | target exit | | |
| 2193 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2194 | // | atomic | teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2195 | // | atomic | cancellation | | |
| 2196 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2197 | // | atomic | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2198 | // | atomic | taskloop | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2199 | // | atomic | taskloop simd | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2200 | // | atomic | distribute | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2201 | // +------------------+-----------------+------------------------------------+ |
| 2202 | // | target | parallel | * | |
| 2203 | // | target | for | * | |
| 2204 | // | target | for simd | * | |
| 2205 | // | target | master | * | |
| 2206 | // | target | critical | * | |
| 2207 | // | target | simd | * | |
| 2208 | // | target | sections | * | |
| 2209 | // | target | section | * | |
| 2210 | // | target | single | * | |
| 2211 | // | target | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2212 | // | target |parallel for simd| * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2213 | // | target |parallel sections| * | |
| 2214 | // | target | task | * | |
| 2215 | // | target | taskyield | * | |
| 2216 | // | target | barrier | * | |
| 2217 | // | target | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2218 | // | target | taskgroup | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2219 | // | target | flush | * | |
| 2220 | // | target | ordered | * | |
| 2221 | // | target | atomic | * | |
| 2222 | // | target | target | * | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2223 | // | target | target enter | * | |
| 2224 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2225 | // | target | target exit | * | |
| 2226 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2227 | // | target | teams | * | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2228 | // | target | cancellation | | |
| 2229 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2230 | // | target | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2231 | // | target | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2232 | // | target | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2233 | // | target | distribute | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2234 | // +------------------+-----------------+------------------------------------+ |
| 2235 | // | teams | parallel | * | |
| 2236 | // | teams | for | + | |
| 2237 | // | teams | for simd | + | |
| 2238 | // | teams | master | + | |
| 2239 | // | teams | critical | + | |
| 2240 | // | teams | simd | + | |
| 2241 | // | teams | sections | + | |
| 2242 | // | teams | section | + | |
| 2243 | // | teams | single | + | |
| 2244 | // | teams | parallel for | * | |
| 2245 | // | teams |parallel for simd| * | |
| 2246 | // | teams |parallel sections| * | |
| 2247 | // | teams | task | + | |
| 2248 | // | teams | taskyield | + | |
| 2249 | // | teams | barrier | + | |
| 2250 | // | teams | taskwait | + | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2251 | // | teams | taskgroup | + | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2252 | // | teams | flush | + | |
| 2253 | // | teams | ordered | + | |
| 2254 | // | teams | atomic | + | |
| 2255 | // | teams | target | + | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2256 | // | teams | target enter | + | |
| 2257 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2258 | // | teams | target exit | + | |
| 2259 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2260 | // | teams | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2261 | // | teams | cancellation | | |
| 2262 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2263 | // | teams | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2264 | // | teams | taskloop | + | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2265 | // | teams | taskloop simd | + | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2266 | // | teams | distribute | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2267 | // +------------------+-----------------+------------------------------------+ |
| 2268 | // | taskloop | parallel | * | |
| 2269 | // | taskloop | for | + | |
| 2270 | // | taskloop | for simd | + | |
| 2271 | // | taskloop | master | + | |
| 2272 | // | taskloop | critical | * | |
| 2273 | // | taskloop | simd | * | |
| 2274 | // | taskloop | sections | + | |
| 2275 | // | taskloop | section | + | |
| 2276 | // | taskloop | single | + | |
| 2277 | // | taskloop | parallel for | * | |
| 2278 | // | taskloop |parallel for simd| * | |
| 2279 | // | taskloop |parallel sections| * | |
| 2280 | // | taskloop | task | * | |
| 2281 | // | taskloop | taskyield | * | |
| 2282 | // | taskloop | barrier | + | |
| 2283 | // | taskloop | taskwait | * | |
| 2284 | // | taskloop | taskgroup | * | |
| 2285 | // | taskloop | flush | * | |
| 2286 | // | taskloop | ordered | + | |
| 2287 | // | taskloop | atomic | * | |
| 2288 | // | taskloop | target | * | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2289 | // | taskloop | target enter | * | |
| 2290 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2291 | // | taskloop | target exit | * | |
| 2292 | // | | data | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2293 | // | taskloop | teams | + | |
| 2294 | // | taskloop | cancellation | | |
| 2295 | // | | point | | |
| 2296 | // | taskloop | cancel | | |
| 2297 | // | taskloop | taskloop | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2298 | // | taskloop | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2299 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2300 | // | taskloop simd | parallel | | |
| 2301 | // | taskloop simd | for | | |
| 2302 | // | taskloop simd | for simd | | |
| 2303 | // | taskloop simd | master | | |
| 2304 | // | taskloop simd | critical | | |
| 2305 | // | taskloop simd | simd | | |
| 2306 | // | taskloop simd | sections | | |
| 2307 | // | taskloop simd | section | | |
| 2308 | // | taskloop simd | single | | |
| 2309 | // | taskloop simd | parallel for | | |
| 2310 | // | taskloop simd |parallel for simd| | |
| 2311 | // | taskloop simd |parallel sections| | |
| 2312 | // | taskloop simd | task | | |
| 2313 | // | taskloop simd | taskyield | | |
| 2314 | // | taskloop simd | barrier | | |
| 2315 | // | taskloop simd | taskwait | | |
| 2316 | // | taskloop simd | taskgroup | | |
| 2317 | // | taskloop simd | flush | | |
| 2318 | // | taskloop simd | ordered | + (with simd clause) | |
| 2319 | // | taskloop simd | atomic | | |
| 2320 | // | taskloop simd | target | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2321 | // | taskloop simd | target enter | | |
| 2322 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2323 | // | taskloop simd | target exit | | |
| 2324 | // | | data | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2325 | // | taskloop simd | teams | | |
| 2326 | // | taskloop simd | cancellation | | |
| 2327 | // | | point | | |
| 2328 | // | taskloop simd | cancel | | |
| 2329 | // | taskloop simd | taskloop | | |
| 2330 | // | taskloop simd | taskloop simd | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2331 | // | taskloop simd | distribute | | |
| 2332 | // +------------------+-----------------+------------------------------------+ |
| 2333 | // | distribute | parallel | * | |
| 2334 | // | distribute | for | * | |
| 2335 | // | distribute | for simd | * | |
| 2336 | // | distribute | master | * | |
| 2337 | // | distribute | critical | * | |
| 2338 | // | distribute | simd | * | |
| 2339 | // | distribute | sections | * | |
| 2340 | // | distribute | section | * | |
| 2341 | // | distribute | single | * | |
| 2342 | // | distribute | parallel for | * | |
| 2343 | // | distribute |parallel for simd| * | |
| 2344 | // | distribute |parallel sections| * | |
| 2345 | // | distribute | task | * | |
| 2346 | // | distribute | taskyield | * | |
| 2347 | // | distribute | barrier | * | |
| 2348 | // | distribute | taskwait | * | |
| 2349 | // | distribute | taskgroup | * | |
| 2350 | // | distribute | flush | * | |
| 2351 | // | distribute | ordered | + | |
| 2352 | // | distribute | atomic | * | |
| 2353 | // | distribute | target | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2354 | // | distribute | target enter | | |
| 2355 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2356 | // | distribute | target exit | | |
| 2357 | // | | data | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2358 | // | distribute | teams | | |
| 2359 | // | distribute | cancellation | + | |
| 2360 | // | | point | | |
| 2361 | // | distribute | cancel | + | |
| 2362 | // | distribute | taskloop | * | |
| 2363 | // | distribute | taskloop simd | * | |
| 2364 | // | distribute | distribute | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2365 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2366 | if (Stack->getCurScope()) { |
| 2367 | auto ParentRegion = Stack->getParentDirective(); |
| 2368 | bool NestingProhibited = false; |
| 2369 | bool CloseNesting = true; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2370 | enum { |
| 2371 | NoRecommend, |
| 2372 | ShouldBeInParallelRegion, |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2373 | ShouldBeInOrderedRegion, |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2374 | ShouldBeInTargetRegion, |
| 2375 | ShouldBeInTeamsRegion |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2376 | } Recommend = NoRecommend; |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2377 | if (isOpenMPSimdDirective(ParentRegion) && CurrentRegion != OMPD_ordered) { |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2378 | // OpenMP [2.16, Nesting of Regions] |
| 2379 | // OpenMP constructs may not be nested inside a simd region. |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2380 | // OpenMP [2.8.1,simd Construct, Restrictions] |
| 2381 | // An ordered construct with the simd clause is the only OpenMP construct |
| 2382 | // that can appear in the simd region. |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2383 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region_simd); |
| 2384 | return true; |
| 2385 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2386 | if (ParentRegion == OMPD_atomic) { |
| 2387 | // OpenMP [2.16, Nesting of Regions] |
| 2388 | // OpenMP constructs may not be nested inside an atomic region. |
| 2389 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region_atomic); |
| 2390 | return true; |
| 2391 | } |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2392 | if (CurrentRegion == OMPD_section) { |
| 2393 | // OpenMP [2.7.2, sections Construct, Restrictions] |
| 2394 | // Orphaned section directives are prohibited. That is, the section |
| 2395 | // directives must appear within the sections construct and must not be |
| 2396 | // encountered elsewhere in the sections region. |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2397 | if (ParentRegion != OMPD_sections && |
| 2398 | ParentRegion != OMPD_parallel_sections) { |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2399 | SemaRef.Diag(StartLoc, diag::err_omp_orphaned_section_directive) |
| 2400 | << (ParentRegion != OMPD_unknown) |
| 2401 | << getOpenMPDirectiveName(ParentRegion); |
| 2402 | return true; |
| 2403 | } |
| 2404 | return false; |
| 2405 | } |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2406 | // Allow some constructs to be orphaned (they could be used in functions, |
| 2407 | // called from OpenMP regions with the required preconditions). |
| 2408 | if (ParentRegion == OMPD_unknown) |
| 2409 | return false; |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2410 | if (CurrentRegion == OMPD_cancellation_point || |
| 2411 | CurrentRegion == OMPD_cancel) { |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2412 | // OpenMP [2.16, Nesting of Regions] |
| 2413 | // A cancellation point construct for which construct-type-clause is |
| 2414 | // taskgroup must be nested inside a task construct. A cancellation |
| 2415 | // point construct for which construct-type-clause is not taskgroup must |
| 2416 | // be closely nested inside an OpenMP construct that matches the type |
| 2417 | // specified in construct-type-clause. |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2418 | // A cancel construct for which construct-type-clause is taskgroup must be |
| 2419 | // nested inside a task construct. A cancel construct for which |
| 2420 | // construct-type-clause is not taskgroup must be closely nested inside an |
| 2421 | // OpenMP construct that matches the type specified in |
| 2422 | // construct-type-clause. |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2423 | NestingProhibited = |
| 2424 | !((CancelRegion == OMPD_parallel && ParentRegion == OMPD_parallel) || |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 2425 | (CancelRegion == OMPD_for && |
| 2426 | (ParentRegion == OMPD_for || ParentRegion == OMPD_parallel_for)) || |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2427 | (CancelRegion == OMPD_taskgroup && ParentRegion == OMPD_task) || |
| 2428 | (CancelRegion == OMPD_sections && |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 2429 | (ParentRegion == OMPD_section || ParentRegion == OMPD_sections || |
| 2430 | ParentRegion == OMPD_parallel_sections))); |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2431 | } else if (CurrentRegion == OMPD_master) { |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2432 | // OpenMP [2.16, Nesting of Regions] |
| 2433 | // A master region may not be closely nested inside a worksharing, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2434 | // atomic, or explicit task region. |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2435 | NestingProhibited = isOpenMPWorksharingDirective(ParentRegion) || |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2436 | ParentRegion == OMPD_task || |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2437 | isOpenMPTaskLoopDirective(ParentRegion); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2438 | } else if (CurrentRegion == OMPD_critical && CurrentName.getName()) { |
| 2439 | // OpenMP [2.16, Nesting of Regions] |
| 2440 | // A critical region may not be nested (closely or otherwise) inside a |
| 2441 | // critical region with the same name. Note that this restriction is not |
| 2442 | // sufficient to prevent deadlock. |
| 2443 | SourceLocation PreviousCriticalLoc; |
| 2444 | bool DeadLock = |
| 2445 | Stack->hasDirective([CurrentName, &PreviousCriticalLoc]( |
| 2446 | OpenMPDirectiveKind K, |
| 2447 | const DeclarationNameInfo &DNI, |
| 2448 | SourceLocation Loc) |
| 2449 | ->bool { |
| 2450 | if (K == OMPD_critical && |
| 2451 | DNI.getName() == CurrentName.getName()) { |
| 2452 | PreviousCriticalLoc = Loc; |
| 2453 | return true; |
| 2454 | } else |
| 2455 | return false; |
| 2456 | }, |
| 2457 | false /* skip top directive */); |
| 2458 | if (DeadLock) { |
| 2459 | SemaRef.Diag(StartLoc, |
| 2460 | diag::err_omp_prohibited_region_critical_same_name) |
| 2461 | << CurrentName.getName(); |
| 2462 | if (PreviousCriticalLoc.isValid()) |
| 2463 | SemaRef.Diag(PreviousCriticalLoc, |
| 2464 | diag::note_omp_previous_critical_region); |
| 2465 | return true; |
| 2466 | } |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2467 | } else if (CurrentRegion == OMPD_barrier) { |
| 2468 | // OpenMP [2.16, Nesting of Regions] |
| 2469 | // A barrier region may not be closely nested inside a worksharing, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2470 | // explicit task, critical, ordered, atomic, or master region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2471 | NestingProhibited = |
| 2472 | isOpenMPWorksharingDirective(ParentRegion) || |
| 2473 | ParentRegion == OMPD_task || ParentRegion == OMPD_master || |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2474 | ParentRegion == OMPD_critical || ParentRegion == OMPD_ordered || |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2475 | isOpenMPTaskLoopDirective(ParentRegion); |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2476 | } else if (isOpenMPWorksharingDirective(CurrentRegion) && |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2477 | !isOpenMPParallelDirective(CurrentRegion)) { |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2478 | // OpenMP [2.16, Nesting of Regions] |
| 2479 | // A worksharing region may not be closely nested inside a worksharing, |
| 2480 | // explicit task, critical, ordered, atomic, or master region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2481 | NestingProhibited = |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2482 | isOpenMPWorksharingDirective(ParentRegion) || |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2483 | ParentRegion == OMPD_task || ParentRegion == OMPD_master || |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2484 | ParentRegion == OMPD_critical || ParentRegion == OMPD_ordered || |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2485 | isOpenMPTaskLoopDirective(ParentRegion); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2486 | Recommend = ShouldBeInParallelRegion; |
| 2487 | } else if (CurrentRegion == OMPD_ordered) { |
| 2488 | // OpenMP [2.16, Nesting of Regions] |
| 2489 | // An ordered region may not be closely nested inside a critical, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2490 | // atomic, or explicit task region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2491 | // An ordered region must be closely nested inside a loop region (or |
| 2492 | // parallel loop region) with an ordered clause. |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2493 | // OpenMP [2.8.1,simd Construct, Restrictions] |
| 2494 | // An ordered construct with the simd clause is the only OpenMP construct |
| 2495 | // that can appear in the simd region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2496 | NestingProhibited = ParentRegion == OMPD_critical || |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2497 | ParentRegion == OMPD_task || |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2498 | isOpenMPTaskLoopDirective(ParentRegion) || |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2499 | !(isOpenMPSimdDirective(ParentRegion) || |
| 2500 | Stack->isParentOrderedRegion()); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2501 | Recommend = ShouldBeInOrderedRegion; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2502 | } else if (isOpenMPTeamsDirective(CurrentRegion)) { |
| 2503 | // OpenMP [2.16, Nesting of Regions] |
| 2504 | // If specified, a teams construct must be contained within a target |
| 2505 | // construct. |
| 2506 | NestingProhibited = ParentRegion != OMPD_target; |
| 2507 | Recommend = ShouldBeInTargetRegion; |
| 2508 | Stack->setParentTeamsRegionLoc(Stack->getConstructLoc()); |
| 2509 | } |
| 2510 | if (!NestingProhibited && isOpenMPTeamsDirective(ParentRegion)) { |
| 2511 | // OpenMP [2.16, Nesting of Regions] |
| 2512 | // distribute, parallel, parallel sections, parallel workshare, and the |
| 2513 | // parallel loop and parallel loop SIMD constructs are the only OpenMP |
| 2514 | // constructs that can be closely nested in the teams region. |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2515 | NestingProhibited = !isOpenMPParallelDirective(CurrentRegion) && |
| 2516 | !isOpenMPDistributeDirective(CurrentRegion); |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2517 | Recommend = ShouldBeInParallelRegion; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2518 | } |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2519 | if (!NestingProhibited && isOpenMPDistributeDirective(CurrentRegion)) { |
| 2520 | // OpenMP 4.5 [2.17 Nesting of Regions] |
| 2521 | // The region associated with the distribute construct must be strictly |
| 2522 | // nested inside a teams region |
| 2523 | NestingProhibited = !isOpenMPTeamsDirective(ParentRegion); |
| 2524 | Recommend = ShouldBeInTeamsRegion; |
| 2525 | } |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2526 | if (NestingProhibited) { |
| 2527 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region) |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2528 | << CloseNesting << getOpenMPDirectiveName(ParentRegion) << Recommend |
| 2529 | << getOpenMPDirectiveName(CurrentRegion); |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2530 | return true; |
| 2531 | } |
| 2532 | } |
| 2533 | return false; |
| 2534 | } |
| 2535 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2536 | static bool checkIfClauses(Sema &S, OpenMPDirectiveKind Kind, |
| 2537 | ArrayRef<OMPClause *> Clauses, |
| 2538 | ArrayRef<OpenMPDirectiveKind> AllowedNameModifiers) { |
| 2539 | bool ErrorFound = false; |
| 2540 | unsigned NamedModifiersNumber = 0; |
| 2541 | SmallVector<const OMPIfClause *, OMPC_unknown + 1> FoundNameModifiers( |
| 2542 | OMPD_unknown + 1); |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2543 | SmallVector<SourceLocation, 4> NameModifierLoc; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2544 | for (const auto *C : Clauses) { |
| 2545 | if (const auto *IC = dyn_cast_or_null<OMPIfClause>(C)) { |
| 2546 | // At most one if clause without a directive-name-modifier can appear on |
| 2547 | // the directive. |
| 2548 | OpenMPDirectiveKind CurNM = IC->getNameModifier(); |
| 2549 | if (FoundNameModifiers[CurNM]) { |
| 2550 | S.Diag(C->getLocStart(), diag::err_omp_more_one_clause) |
| 2551 | << getOpenMPDirectiveName(Kind) << getOpenMPClauseName(OMPC_if) |
| 2552 | << (CurNM != OMPD_unknown) << getOpenMPDirectiveName(CurNM); |
| 2553 | ErrorFound = true; |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2554 | } else if (CurNM != OMPD_unknown) { |
| 2555 | NameModifierLoc.push_back(IC->getNameModifierLoc()); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2556 | ++NamedModifiersNumber; |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2557 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2558 | FoundNameModifiers[CurNM] = IC; |
| 2559 | if (CurNM == OMPD_unknown) |
| 2560 | continue; |
| 2561 | // Check if the specified name modifier is allowed for the current |
| 2562 | // directive. |
| 2563 | // At most one if clause with the particular directive-name-modifier can |
| 2564 | // appear on the directive. |
| 2565 | bool MatchFound = false; |
| 2566 | for (auto NM : AllowedNameModifiers) { |
| 2567 | if (CurNM == NM) { |
| 2568 | MatchFound = true; |
| 2569 | break; |
| 2570 | } |
| 2571 | } |
| 2572 | if (!MatchFound) { |
| 2573 | S.Diag(IC->getNameModifierLoc(), |
| 2574 | diag::err_omp_wrong_if_directive_name_modifier) |
| 2575 | << getOpenMPDirectiveName(CurNM) << getOpenMPDirectiveName(Kind); |
| 2576 | ErrorFound = true; |
| 2577 | } |
| 2578 | } |
| 2579 | } |
| 2580 | // If any if clause on the directive includes a directive-name-modifier then |
| 2581 | // all if clauses on the directive must include a directive-name-modifier. |
| 2582 | if (FoundNameModifiers[OMPD_unknown] && NamedModifiersNumber > 0) { |
| 2583 | if (NamedModifiersNumber == AllowedNameModifiers.size()) { |
| 2584 | S.Diag(FoundNameModifiers[OMPD_unknown]->getLocStart(), |
| 2585 | diag::err_omp_no_more_if_clause); |
| 2586 | } else { |
| 2587 | std::string Values; |
| 2588 | std::string Sep(", "); |
| 2589 | unsigned AllowedCnt = 0; |
| 2590 | unsigned TotalAllowedNum = |
| 2591 | AllowedNameModifiers.size() - NamedModifiersNumber; |
| 2592 | for (unsigned Cnt = 0, End = AllowedNameModifiers.size(); Cnt < End; |
| 2593 | ++Cnt) { |
| 2594 | OpenMPDirectiveKind NM = AllowedNameModifiers[Cnt]; |
| 2595 | if (!FoundNameModifiers[NM]) { |
| 2596 | Values += "'"; |
| 2597 | Values += getOpenMPDirectiveName(NM); |
| 2598 | Values += "'"; |
| 2599 | if (AllowedCnt + 2 == TotalAllowedNum) |
| 2600 | Values += " or "; |
| 2601 | else if (AllowedCnt + 1 != TotalAllowedNum) |
| 2602 | Values += Sep; |
| 2603 | ++AllowedCnt; |
| 2604 | } |
| 2605 | } |
| 2606 | S.Diag(FoundNameModifiers[OMPD_unknown]->getCondition()->getLocStart(), |
| 2607 | diag::err_omp_unnamed_if_clause) |
| 2608 | << (TotalAllowedNum > 1) << Values; |
| 2609 | } |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2610 | for (auto Loc : NameModifierLoc) { |
| 2611 | S.Diag(Loc, diag::note_omp_previous_named_if_clause); |
| 2612 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2613 | ErrorFound = true; |
| 2614 | } |
| 2615 | return ErrorFound; |
| 2616 | } |
| 2617 | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2618 | StmtResult Sema::ActOnOpenMPExecutableDirective( |
| 2619 | OpenMPDirectiveKind Kind, const DeclarationNameInfo &DirName, |
| 2620 | OpenMPDirectiveKind CancelRegion, ArrayRef<OMPClause *> Clauses, |
| 2621 | Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2622 | StmtResult Res = StmtError(); |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2623 | if (CheckNestingOfRegions(*this, DSAStack, Kind, DirName, CancelRegion, |
| 2624 | StartLoc)) |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2625 | return StmtError(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2626 | |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2627 | llvm::SmallVector<OMPClause *, 8> ClausesWithImplicit; |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2628 | llvm::DenseMap<VarDecl *, Expr *> VarsWithInheritedDSA; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2629 | bool ErrorFound = false; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2630 | ClausesWithImplicit.append(Clauses.begin(), Clauses.end()); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2631 | if (AStmt) { |
| 2632 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 2633 | |
| 2634 | // Check default data sharing attributes for referenced variables. |
| 2635 | DSAAttrChecker DSAChecker(DSAStack, *this, cast<CapturedStmt>(AStmt)); |
| 2636 | DSAChecker.Visit(cast<CapturedStmt>(AStmt)->getCapturedStmt()); |
| 2637 | if (DSAChecker.isErrorFound()) |
| 2638 | return StmtError(); |
| 2639 | // Generate list of implicitly defined firstprivate variables. |
| 2640 | VarsWithInheritedDSA = DSAChecker.getVarsWithInheritedDSA(); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2641 | |
| 2642 | if (!DSAChecker.getImplicitFirstprivate().empty()) { |
| 2643 | if (OMPClause *Implicit = ActOnOpenMPFirstprivateClause( |
| 2644 | DSAChecker.getImplicitFirstprivate(), SourceLocation(), |
| 2645 | SourceLocation(), SourceLocation())) { |
| 2646 | ClausesWithImplicit.push_back(Implicit); |
| 2647 | ErrorFound = cast<OMPFirstprivateClause>(Implicit)->varlist_size() != |
| 2648 | DSAChecker.getImplicitFirstprivate().size(); |
| 2649 | } else |
| 2650 | ErrorFound = true; |
| 2651 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2652 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2653 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2654 | llvm::SmallVector<OpenMPDirectiveKind, 4> AllowedNameModifiers; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2655 | switch (Kind) { |
| 2656 | case OMPD_parallel: |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2657 | Res = ActOnOpenMPParallelDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2658 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2659 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2660 | break; |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 2661 | case OMPD_simd: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2662 | Res = ActOnOpenMPSimdDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc, |
| 2663 | VarsWithInheritedDSA); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 2664 | break; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2665 | case OMPD_for: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2666 | Res = ActOnOpenMPForDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc, |
| 2667 | VarsWithInheritedDSA); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2668 | break; |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2669 | case OMPD_for_simd: |
| 2670 | Res = ActOnOpenMPForSimdDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2671 | EndLoc, VarsWithInheritedDSA); |
| 2672 | break; |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 2673 | case OMPD_sections: |
| 2674 | Res = ActOnOpenMPSectionsDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2675 | EndLoc); |
| 2676 | break; |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2677 | case OMPD_section: |
| 2678 | assert(ClausesWithImplicit.empty() && |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2679 | "No clauses are allowed for 'omp section' directive"); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2680 | Res = ActOnOpenMPSectionDirective(AStmt, StartLoc, EndLoc); |
| 2681 | break; |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 2682 | case OMPD_single: |
| 2683 | Res = ActOnOpenMPSingleDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2684 | EndLoc); |
| 2685 | break; |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2686 | case OMPD_master: |
| 2687 | assert(ClausesWithImplicit.empty() && |
| 2688 | "No clauses are allowed for 'omp master' directive"); |
| 2689 | Res = ActOnOpenMPMasterDirective(AStmt, StartLoc, EndLoc); |
| 2690 | break; |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2691 | case OMPD_critical: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 2692 | Res = ActOnOpenMPCriticalDirective(DirName, ClausesWithImplicit, AStmt, |
| 2693 | StartLoc, EndLoc); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2694 | break; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2695 | case OMPD_parallel_for: |
| 2696 | Res = ActOnOpenMPParallelForDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2697 | EndLoc, VarsWithInheritedDSA); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2698 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2699 | break; |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2700 | case OMPD_parallel_for_simd: |
| 2701 | Res = ActOnOpenMPParallelForSimdDirective( |
| 2702 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2703 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2704 | break; |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2705 | case OMPD_parallel_sections: |
| 2706 | Res = ActOnOpenMPParallelSectionsDirective(ClausesWithImplicit, AStmt, |
| 2707 | StartLoc, EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2708 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2709 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2710 | case OMPD_task: |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2711 | Res = |
| 2712 | ActOnOpenMPTaskDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2713 | AllowedNameModifiers.push_back(OMPD_task); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2714 | break; |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2715 | case OMPD_taskyield: |
| 2716 | assert(ClausesWithImplicit.empty() && |
| 2717 | "No clauses are allowed for 'omp taskyield' directive"); |
| 2718 | assert(AStmt == nullptr && |
| 2719 | "No associated statement allowed for 'omp taskyield' directive"); |
| 2720 | Res = ActOnOpenMPTaskyieldDirective(StartLoc, EndLoc); |
| 2721 | break; |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2722 | case OMPD_barrier: |
| 2723 | assert(ClausesWithImplicit.empty() && |
| 2724 | "No clauses are allowed for 'omp barrier' directive"); |
| 2725 | assert(AStmt == nullptr && |
| 2726 | "No associated statement allowed for 'omp barrier' directive"); |
| 2727 | Res = ActOnOpenMPBarrierDirective(StartLoc, EndLoc); |
| 2728 | break; |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2729 | case OMPD_taskwait: |
| 2730 | assert(ClausesWithImplicit.empty() && |
| 2731 | "No clauses are allowed for 'omp taskwait' directive"); |
| 2732 | assert(AStmt == nullptr && |
| 2733 | "No associated statement allowed for 'omp taskwait' directive"); |
| 2734 | Res = ActOnOpenMPTaskwaitDirective(StartLoc, EndLoc); |
| 2735 | break; |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2736 | case OMPD_taskgroup: |
| 2737 | assert(ClausesWithImplicit.empty() && |
| 2738 | "No clauses are allowed for 'omp taskgroup' directive"); |
| 2739 | Res = ActOnOpenMPTaskgroupDirective(AStmt, StartLoc, EndLoc); |
| 2740 | break; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2741 | case OMPD_flush: |
| 2742 | assert(AStmt == nullptr && |
| 2743 | "No associated statement allowed for 'omp flush' directive"); |
| 2744 | Res = ActOnOpenMPFlushDirective(ClausesWithImplicit, StartLoc, EndLoc); |
| 2745 | break; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2746 | case OMPD_ordered: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 2747 | Res = ActOnOpenMPOrderedDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2748 | EndLoc); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2749 | break; |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2750 | case OMPD_atomic: |
| 2751 | Res = ActOnOpenMPAtomicDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2752 | EndLoc); |
| 2753 | break; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2754 | case OMPD_teams: |
| 2755 | Res = |
| 2756 | ActOnOpenMPTeamsDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); |
| 2757 | break; |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2758 | case OMPD_target: |
| 2759 | Res = ActOnOpenMPTargetDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2760 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2761 | AllowedNameModifiers.push_back(OMPD_target); |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2762 | break; |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2763 | case OMPD_cancellation_point: |
| 2764 | assert(ClausesWithImplicit.empty() && |
| 2765 | "No clauses are allowed for 'omp cancellation point' directive"); |
| 2766 | assert(AStmt == nullptr && "No associated statement allowed for 'omp " |
| 2767 | "cancellation point' directive"); |
| 2768 | Res = ActOnOpenMPCancellationPointDirective(StartLoc, EndLoc, CancelRegion); |
| 2769 | break; |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2770 | case OMPD_cancel: |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2771 | assert(AStmt == nullptr && |
| 2772 | "No associated statement allowed for 'omp cancel' directive"); |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 2773 | Res = ActOnOpenMPCancelDirective(ClausesWithImplicit, StartLoc, EndLoc, |
| 2774 | CancelRegion); |
| 2775 | AllowedNameModifiers.push_back(OMPD_cancel); |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2776 | break; |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 2777 | case OMPD_target_data: |
| 2778 | Res = ActOnOpenMPTargetDataDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2779 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2780 | AllowedNameModifiers.push_back(OMPD_target_data); |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 2781 | break; |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2782 | case OMPD_target_enter_data: |
| 2783 | Res = ActOnOpenMPTargetEnterDataDirective(ClausesWithImplicit, StartLoc, |
| 2784 | EndLoc); |
| 2785 | AllowedNameModifiers.push_back(OMPD_target_enter_data); |
| 2786 | break; |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2787 | case OMPD_target_exit_data: |
| 2788 | Res = ActOnOpenMPTargetExitDataDirective(ClausesWithImplicit, StartLoc, |
| 2789 | EndLoc); |
| 2790 | AllowedNameModifiers.push_back(OMPD_target_exit_data); |
| 2791 | break; |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2792 | case OMPD_taskloop: |
| 2793 | Res = ActOnOpenMPTaskLoopDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2794 | EndLoc, VarsWithInheritedDSA); |
| 2795 | AllowedNameModifiers.push_back(OMPD_taskloop); |
| 2796 | break; |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2797 | case OMPD_taskloop_simd: |
| 2798 | Res = ActOnOpenMPTaskLoopSimdDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2799 | EndLoc, VarsWithInheritedDSA); |
| 2800 | AllowedNameModifiers.push_back(OMPD_taskloop); |
| 2801 | break; |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2802 | case OMPD_distribute: |
| 2803 | Res = ActOnOpenMPDistributeDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2804 | EndLoc, VarsWithInheritedDSA); |
| 2805 | break; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2806 | case OMPD_threadprivate: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2807 | llvm_unreachable("OpenMP Directive is not allowed"); |
| 2808 | case OMPD_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2809 | llvm_unreachable("Unknown OpenMP directive"); |
| 2810 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2811 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2812 | for (auto P : VarsWithInheritedDSA) { |
| 2813 | Diag(P.second->getExprLoc(), diag::err_omp_no_dsa_for_variable) |
| 2814 | << P.first << P.second->getSourceRange(); |
| 2815 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2816 | ErrorFound = !VarsWithInheritedDSA.empty() || ErrorFound; |
| 2817 | |
| 2818 | if (!AllowedNameModifiers.empty()) |
| 2819 | ErrorFound = checkIfClauses(*this, Kind, Clauses, AllowedNameModifiers) || |
| 2820 | ErrorFound; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2821 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2822 | if (ErrorFound) |
| 2823 | return StmtError(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2824 | return Res; |
| 2825 | } |
| 2826 | |
| 2827 | StmtResult Sema::ActOnOpenMPParallelDirective(ArrayRef<OMPClause *> Clauses, |
| 2828 | Stmt *AStmt, |
| 2829 | SourceLocation StartLoc, |
| 2830 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2831 | if (!AStmt) |
| 2832 | return StmtError(); |
| 2833 | |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 2834 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 2835 | // 1.2.2 OpenMP Language Terminology |
| 2836 | // Structured block - An executable statement with a single entry at the |
| 2837 | // top and a single exit at the bottom. |
| 2838 | // The point of exit cannot be a branch out of the structured block. |
| 2839 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 2840 | CS->getCapturedDecl()->setNothrow(); |
| 2841 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2842 | getCurFunction()->setHasBranchProtectedScope(); |
| 2843 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 2844 | return OMPParallelDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 2845 | DSAStack->isCancelRegion()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2846 | } |
| 2847 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2848 | namespace { |
| 2849 | /// \brief Helper class for checking canonical form of the OpenMP loops and |
| 2850 | /// extracting iteration space of each loop in the loop nest, that will be used |
| 2851 | /// for IR generation. |
| 2852 | class OpenMPIterationSpaceChecker { |
| 2853 | /// \brief Reference to Sema. |
| 2854 | Sema &SemaRef; |
| 2855 | /// \brief A location for diagnostics (when there is no some better location). |
| 2856 | SourceLocation DefaultLoc; |
| 2857 | /// \brief A location for diagnostics (when increment is not compatible). |
| 2858 | SourceLocation ConditionLoc; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2859 | /// \brief A source location for referring to loop init later. |
| 2860 | SourceRange InitSrcRange; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2861 | /// \brief A source location for referring to condition later. |
| 2862 | SourceRange ConditionSrcRange; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2863 | /// \brief A source location for referring to increment later. |
| 2864 | SourceRange IncrementSrcRange; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2865 | /// \brief Loop variable. |
| 2866 | VarDecl *Var; |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2867 | /// \brief Reference to loop variable. |
| 2868 | DeclRefExpr *VarRef; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2869 | /// \brief Lower bound (initializer for the var). |
| 2870 | Expr *LB; |
| 2871 | /// \brief Upper bound. |
| 2872 | Expr *UB; |
| 2873 | /// \brief Loop step (increment). |
| 2874 | Expr *Step; |
| 2875 | /// \brief This flag is true when condition is one of: |
| 2876 | /// Var < UB |
| 2877 | /// Var <= UB |
| 2878 | /// UB > Var |
| 2879 | /// UB >= Var |
| 2880 | bool TestIsLessOp; |
| 2881 | /// \brief This flag is true when condition is strict ( < or > ). |
| 2882 | bool TestIsStrictOp; |
| 2883 | /// \brief This flag is true when step is subtracted on each iteration. |
| 2884 | bool SubtractStep; |
| 2885 | |
| 2886 | public: |
| 2887 | OpenMPIterationSpaceChecker(Sema &SemaRef, SourceLocation DefaultLoc) |
| 2888 | : SemaRef(SemaRef), DefaultLoc(DefaultLoc), ConditionLoc(DefaultLoc), |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2889 | InitSrcRange(SourceRange()), ConditionSrcRange(SourceRange()), |
| 2890 | IncrementSrcRange(SourceRange()), Var(nullptr), VarRef(nullptr), |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2891 | LB(nullptr), UB(nullptr), Step(nullptr), TestIsLessOp(false), |
| 2892 | TestIsStrictOp(false), SubtractStep(false) {} |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2893 | /// \brief Check init-expr for canonical loop form and save loop counter |
| 2894 | /// variable - #Var and its initialization value - #LB. |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2895 | bool CheckInit(Stmt *S, bool EmitDiags = true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2896 | /// \brief Check test-expr for canonical form, save upper-bound (#UB), flags |
| 2897 | /// for less/greater and for strict/non-strict comparison. |
| 2898 | bool CheckCond(Expr *S); |
| 2899 | /// \brief Check incr-expr for canonical loop form and return true if it |
| 2900 | /// does not conform, otherwise save loop step (#Step). |
| 2901 | bool CheckInc(Expr *S); |
| 2902 | /// \brief Return the loop counter variable. |
| 2903 | VarDecl *GetLoopVar() const { return Var; } |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2904 | /// \brief Return the reference expression to loop counter variable. |
| 2905 | DeclRefExpr *GetLoopVarRefExpr() const { return VarRef; } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2906 | /// \brief Source range of the loop init. |
| 2907 | SourceRange GetInitSrcRange() const { return InitSrcRange; } |
| 2908 | /// \brief Source range of the loop condition. |
| 2909 | SourceRange GetConditionSrcRange() const { return ConditionSrcRange; } |
| 2910 | /// \brief Source range of the loop increment. |
| 2911 | SourceRange GetIncrementSrcRange() const { return IncrementSrcRange; } |
| 2912 | /// \brief True if the step should be subtracted. |
| 2913 | bool ShouldSubtractStep() const { return SubtractStep; } |
| 2914 | /// \brief Build the expression to calculate the number of iterations. |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 2915 | Expr *BuildNumIterations(Scope *S, const bool LimitedType) const; |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 2916 | /// \brief Build the precondition expression for the loops. |
| 2917 | Expr *BuildPreCond(Scope *S, Expr *Cond) const; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2918 | /// \brief Build reference expression to the counter be used for codegen. |
| 2919 | Expr *BuildCounterVar() const; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 2920 | /// \brief Build reference expression to the private counter be used for |
| 2921 | /// codegen. |
| 2922 | Expr *BuildPrivateCounterVar() const; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2923 | /// \brief Build initization of the counter be used for codegen. |
| 2924 | Expr *BuildCounterInit() const; |
| 2925 | /// \brief Build step of the counter be used for codegen. |
| 2926 | Expr *BuildCounterStep() const; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2927 | /// \brief Return true if any expression is dependent. |
| 2928 | bool Dependent() const; |
| 2929 | |
| 2930 | private: |
| 2931 | /// \brief Check the right-hand side of an assignment in the increment |
| 2932 | /// expression. |
| 2933 | bool CheckIncRHS(Expr *RHS); |
| 2934 | /// \brief Helper to set loop counter variable and its initializer. |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2935 | bool SetVarAndLB(VarDecl *NewVar, DeclRefExpr *NewVarRefExpr, Expr *NewLB); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2936 | /// \brief Helper to set upper bound. |
Craig Topper | e335f25 | 2015-10-04 04:53:55 +0000 | [diff] [blame] | 2937 | bool SetUB(Expr *NewUB, bool LessOp, bool StrictOp, SourceRange SR, |
Craig Topper | 9cd5e4f | 2015-09-21 01:23:32 +0000 | [diff] [blame] | 2938 | SourceLocation SL); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2939 | /// \brief Helper to set loop increment. |
| 2940 | bool SetStep(Expr *NewStep, bool Subtract); |
| 2941 | }; |
| 2942 | |
| 2943 | bool OpenMPIterationSpaceChecker::Dependent() const { |
| 2944 | if (!Var) { |
| 2945 | assert(!LB && !UB && !Step); |
| 2946 | return false; |
| 2947 | } |
| 2948 | return Var->getType()->isDependentType() || (LB && LB->isValueDependent()) || |
| 2949 | (UB && UB->isValueDependent()) || (Step && Step->isValueDependent()); |
| 2950 | } |
| 2951 | |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 2952 | template <typename T> |
| 2953 | static T *getExprAsWritten(T *E) { |
| 2954 | if (auto *ExprTemp = dyn_cast<ExprWithCleanups>(E)) |
| 2955 | E = ExprTemp->getSubExpr(); |
| 2956 | |
| 2957 | if (auto *MTE = dyn_cast<MaterializeTemporaryExpr>(E)) |
| 2958 | E = MTE->GetTemporaryExpr(); |
| 2959 | |
| 2960 | while (auto *Binder = dyn_cast<CXXBindTemporaryExpr>(E)) |
| 2961 | E = Binder->getSubExpr(); |
| 2962 | |
| 2963 | if (auto *ICE = dyn_cast<ImplicitCastExpr>(E)) |
| 2964 | E = ICE->getSubExprAsWritten(); |
| 2965 | return E->IgnoreParens(); |
| 2966 | } |
| 2967 | |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2968 | bool OpenMPIterationSpaceChecker::SetVarAndLB(VarDecl *NewVar, |
| 2969 | DeclRefExpr *NewVarRefExpr, |
| 2970 | Expr *NewLB) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2971 | // State consistency checking to ensure correct usage. |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2972 | assert(Var == nullptr && LB == nullptr && VarRef == nullptr && |
| 2973 | UB == nullptr && Step == nullptr && !TestIsLessOp && !TestIsStrictOp); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2974 | if (!NewVar || !NewLB) |
| 2975 | return true; |
| 2976 | Var = NewVar; |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2977 | VarRef = NewVarRefExpr; |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 2978 | if (auto *CE = dyn_cast_or_null<CXXConstructExpr>(NewLB)) |
| 2979 | if (const CXXConstructorDecl *Ctor = CE->getConstructor()) |
Alexey Bataev | 0d08a7f | 2015-07-16 04:19:43 +0000 | [diff] [blame] | 2980 | if ((Ctor->isCopyOrMoveConstructor() || |
| 2981 | Ctor->isConvertingConstructor(/*AllowExplicit=*/false)) && |
| 2982 | CE->getNumArgs() > 0 && CE->getArg(0) != nullptr) |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 2983 | NewLB = CE->getArg(0)->IgnoreParenImpCasts(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2984 | LB = NewLB; |
| 2985 | return false; |
| 2986 | } |
| 2987 | |
| 2988 | bool OpenMPIterationSpaceChecker::SetUB(Expr *NewUB, bool LessOp, bool StrictOp, |
Craig Topper | e335f25 | 2015-10-04 04:53:55 +0000 | [diff] [blame] | 2989 | SourceRange SR, SourceLocation SL) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2990 | // State consistency checking to ensure correct usage. |
| 2991 | assert(Var != nullptr && LB != nullptr && UB == nullptr && Step == nullptr && |
| 2992 | !TestIsLessOp && !TestIsStrictOp); |
| 2993 | if (!NewUB) |
| 2994 | return true; |
| 2995 | UB = NewUB; |
| 2996 | TestIsLessOp = LessOp; |
| 2997 | TestIsStrictOp = StrictOp; |
| 2998 | ConditionSrcRange = SR; |
| 2999 | ConditionLoc = SL; |
| 3000 | return false; |
| 3001 | } |
| 3002 | |
| 3003 | bool OpenMPIterationSpaceChecker::SetStep(Expr *NewStep, bool Subtract) { |
| 3004 | // State consistency checking to ensure correct usage. |
| 3005 | assert(Var != nullptr && LB != nullptr && Step == nullptr); |
| 3006 | if (!NewStep) |
| 3007 | return true; |
| 3008 | if (!NewStep->isValueDependent()) { |
| 3009 | // Check that the step is integer expression. |
| 3010 | SourceLocation StepLoc = NewStep->getLocStart(); |
| 3011 | ExprResult Val = |
| 3012 | SemaRef.PerformOpenMPImplicitIntegerConversion(StepLoc, NewStep); |
| 3013 | if (Val.isInvalid()) |
| 3014 | return true; |
| 3015 | NewStep = Val.get(); |
| 3016 | |
| 3017 | // OpenMP [2.6, Canonical Loop Form, Restrictions] |
| 3018 | // If test-expr is of form var relational-op b and relational-op is < or |
| 3019 | // <= then incr-expr must cause var to increase on each iteration of the |
| 3020 | // loop. If test-expr is of form var relational-op b and relational-op is |
| 3021 | // > or >= then incr-expr must cause var to decrease on each iteration of |
| 3022 | // the loop. |
| 3023 | // If test-expr is of form b relational-op var and relational-op is < or |
| 3024 | // <= then incr-expr must cause var to decrease on each iteration of the |
| 3025 | // loop. If test-expr is of form b relational-op var and relational-op is |
| 3026 | // > or >= then incr-expr must cause var to increase on each iteration of |
| 3027 | // the loop. |
| 3028 | llvm::APSInt Result; |
| 3029 | bool IsConstant = NewStep->isIntegerConstantExpr(Result, SemaRef.Context); |
| 3030 | bool IsUnsigned = !NewStep->getType()->hasSignedIntegerRepresentation(); |
| 3031 | bool IsConstNeg = |
| 3032 | IsConstant && Result.isSigned() && (Subtract != Result.isNegative()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3033 | bool IsConstPos = |
| 3034 | IsConstant && Result.isSigned() && (Subtract == Result.isNegative()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3035 | bool IsConstZero = IsConstant && !Result.getBoolValue(); |
| 3036 | if (UB && (IsConstZero || |
| 3037 | (TestIsLessOp ? (IsConstNeg || (IsUnsigned && Subtract)) |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3038 | : (IsConstPos || (IsUnsigned && !Subtract))))) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3039 | SemaRef.Diag(NewStep->getExprLoc(), |
| 3040 | diag::err_omp_loop_incr_not_compatible) |
| 3041 | << Var << TestIsLessOp << NewStep->getSourceRange(); |
| 3042 | SemaRef.Diag(ConditionLoc, |
| 3043 | diag::note_omp_loop_cond_requres_compatible_incr) |
| 3044 | << TestIsLessOp << ConditionSrcRange; |
| 3045 | return true; |
| 3046 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3047 | if (TestIsLessOp == Subtract) { |
| 3048 | NewStep = SemaRef.CreateBuiltinUnaryOp(NewStep->getExprLoc(), UO_Minus, |
| 3049 | NewStep).get(); |
| 3050 | Subtract = !Subtract; |
| 3051 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3052 | } |
| 3053 | |
| 3054 | Step = NewStep; |
| 3055 | SubtractStep = Subtract; |
| 3056 | return false; |
| 3057 | } |
| 3058 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3059 | bool OpenMPIterationSpaceChecker::CheckInit(Stmt *S, bool EmitDiags) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3060 | // Check init-expr for canonical loop form and save loop counter |
| 3061 | // variable - #Var and its initialization value - #LB. |
| 3062 | // OpenMP [2.6] Canonical loop form. init-expr may be one of the following: |
| 3063 | // var = lb |
| 3064 | // integer-type var = lb |
| 3065 | // random-access-iterator-type var = lb |
| 3066 | // pointer-type var = lb |
| 3067 | // |
| 3068 | if (!S) { |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3069 | if (EmitDiags) { |
| 3070 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_init); |
| 3071 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3072 | return true; |
| 3073 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3074 | InitSrcRange = S->getSourceRange(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3075 | if (Expr *E = dyn_cast<Expr>(S)) |
| 3076 | S = E->IgnoreParens(); |
| 3077 | if (auto BO = dyn_cast<BinaryOperator>(S)) { |
| 3078 | if (BO->getOpcode() == BO_Assign) |
| 3079 | if (auto DRE = dyn_cast<DeclRefExpr>(BO->getLHS()->IgnoreParens())) |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3080 | return SetVarAndLB(dyn_cast<VarDecl>(DRE->getDecl()), DRE, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3081 | BO->getRHS()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3082 | } else if (auto DS = dyn_cast<DeclStmt>(S)) { |
| 3083 | if (DS->isSingleDecl()) { |
| 3084 | if (auto Var = dyn_cast_or_null<VarDecl>(DS->getSingleDecl())) { |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3085 | if (Var->hasInit() && !Var->getType()->isReferenceType()) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3086 | // Accept non-canonical init form here but emit ext. warning. |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3087 | if (Var->getInitStyle() != VarDecl::CInit && EmitDiags) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3088 | SemaRef.Diag(S->getLocStart(), |
| 3089 | diag::ext_omp_loop_not_canonical_init) |
| 3090 | << S->getSourceRange(); |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3091 | return SetVarAndLB(Var, nullptr, Var->getInit()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3092 | } |
| 3093 | } |
| 3094 | } |
| 3095 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) |
| 3096 | if (CE->getOperator() == OO_Equal) |
| 3097 | if (auto DRE = dyn_cast<DeclRefExpr>(CE->getArg(0))) |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3098 | return SetVarAndLB(dyn_cast<VarDecl>(DRE->getDecl()), DRE, |
| 3099 | CE->getArg(1)); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3100 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3101 | if (EmitDiags) { |
| 3102 | SemaRef.Diag(S->getLocStart(), diag::err_omp_loop_not_canonical_init) |
| 3103 | << S->getSourceRange(); |
| 3104 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3105 | return true; |
| 3106 | } |
| 3107 | |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 3108 | /// \brief Ignore parenthesizes, implicit casts, copy constructor and return the |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3109 | /// variable (which may be the loop variable) if possible. |
| 3110 | static const VarDecl *GetInitVarDecl(const Expr *E) { |
| 3111 | if (!E) |
Craig Topper | 4b56692 | 2014-06-09 02:04:02 +0000 | [diff] [blame] | 3112 | return nullptr; |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3113 | E = getExprAsWritten(E); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3114 | if (auto *CE = dyn_cast_or_null<CXXConstructExpr>(E)) |
| 3115 | if (const CXXConstructorDecl *Ctor = CE->getConstructor()) |
Alexey Bataev | 0d08a7f | 2015-07-16 04:19:43 +0000 | [diff] [blame] | 3116 | if ((Ctor->isCopyOrMoveConstructor() || |
| 3117 | Ctor->isConvertingConstructor(/*AllowExplicit=*/false)) && |
| 3118 | CE->getNumArgs() > 0 && CE->getArg(0) != nullptr) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3119 | E = CE->getArg(0)->IgnoreParenImpCasts(); |
| 3120 | auto DRE = dyn_cast_or_null<DeclRefExpr>(E); |
| 3121 | if (!DRE) |
| 3122 | return nullptr; |
| 3123 | return dyn_cast<VarDecl>(DRE->getDecl()); |
| 3124 | } |
| 3125 | |
| 3126 | bool OpenMPIterationSpaceChecker::CheckCond(Expr *S) { |
| 3127 | // Check test-expr for canonical form, save upper-bound UB, flags for |
| 3128 | // less/greater and for strict/non-strict comparison. |
| 3129 | // OpenMP [2.6] Canonical loop form. Test-expr may be one of the following: |
| 3130 | // var relational-op b |
| 3131 | // b relational-op var |
| 3132 | // |
| 3133 | if (!S) { |
| 3134 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_cond) << Var; |
| 3135 | return true; |
| 3136 | } |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3137 | S = getExprAsWritten(S); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3138 | SourceLocation CondLoc = S->getLocStart(); |
| 3139 | if (auto BO = dyn_cast<BinaryOperator>(S)) { |
| 3140 | if (BO->isRelationalOp()) { |
| 3141 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 3142 | return SetUB(BO->getRHS(), |
| 3143 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_LE), |
| 3144 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_GT), |
| 3145 | BO->getSourceRange(), BO->getOperatorLoc()); |
| 3146 | if (GetInitVarDecl(BO->getRHS()) == Var) |
| 3147 | return SetUB(BO->getLHS(), |
| 3148 | (BO->getOpcode() == BO_GT || BO->getOpcode() == BO_GE), |
| 3149 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_GT), |
| 3150 | BO->getSourceRange(), BO->getOperatorLoc()); |
| 3151 | } |
| 3152 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
| 3153 | if (CE->getNumArgs() == 2) { |
| 3154 | auto Op = CE->getOperator(); |
| 3155 | switch (Op) { |
| 3156 | case OO_Greater: |
| 3157 | case OO_GreaterEqual: |
| 3158 | case OO_Less: |
| 3159 | case OO_LessEqual: |
| 3160 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 3161 | return SetUB(CE->getArg(1), Op == OO_Less || Op == OO_LessEqual, |
| 3162 | Op == OO_Less || Op == OO_Greater, CE->getSourceRange(), |
| 3163 | CE->getOperatorLoc()); |
| 3164 | if (GetInitVarDecl(CE->getArg(1)) == Var) |
| 3165 | return SetUB(CE->getArg(0), Op == OO_Greater || Op == OO_GreaterEqual, |
| 3166 | Op == OO_Less || Op == OO_Greater, CE->getSourceRange(), |
| 3167 | CE->getOperatorLoc()); |
| 3168 | break; |
| 3169 | default: |
| 3170 | break; |
| 3171 | } |
| 3172 | } |
| 3173 | } |
| 3174 | SemaRef.Diag(CondLoc, diag::err_omp_loop_not_canonical_cond) |
| 3175 | << S->getSourceRange() << Var; |
| 3176 | return true; |
| 3177 | } |
| 3178 | |
| 3179 | bool OpenMPIterationSpaceChecker::CheckIncRHS(Expr *RHS) { |
| 3180 | // RHS of canonical loop form increment can be: |
| 3181 | // var + incr |
| 3182 | // incr + var |
| 3183 | // var - incr |
| 3184 | // |
| 3185 | RHS = RHS->IgnoreParenImpCasts(); |
| 3186 | if (auto BO = dyn_cast<BinaryOperator>(RHS)) { |
| 3187 | if (BO->isAdditiveOp()) { |
| 3188 | bool IsAdd = BO->getOpcode() == BO_Add; |
| 3189 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 3190 | return SetStep(BO->getRHS(), !IsAdd); |
| 3191 | if (IsAdd && GetInitVarDecl(BO->getRHS()) == Var) |
| 3192 | return SetStep(BO->getLHS(), false); |
| 3193 | } |
| 3194 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(RHS)) { |
| 3195 | bool IsAdd = CE->getOperator() == OO_Plus; |
| 3196 | if ((IsAdd || CE->getOperator() == OO_Minus) && CE->getNumArgs() == 2) { |
| 3197 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 3198 | return SetStep(CE->getArg(1), !IsAdd); |
| 3199 | if (IsAdd && GetInitVarDecl(CE->getArg(1)) == Var) |
| 3200 | return SetStep(CE->getArg(0), false); |
| 3201 | } |
| 3202 | } |
| 3203 | SemaRef.Diag(RHS->getLocStart(), diag::err_omp_loop_not_canonical_incr) |
| 3204 | << RHS->getSourceRange() << Var; |
| 3205 | return true; |
| 3206 | } |
| 3207 | |
| 3208 | bool OpenMPIterationSpaceChecker::CheckInc(Expr *S) { |
| 3209 | // Check incr-expr for canonical loop form and return true if it |
| 3210 | // does not conform. |
| 3211 | // OpenMP [2.6] Canonical loop form. Test-expr may be one of the following: |
| 3212 | // ++var |
| 3213 | // var++ |
| 3214 | // --var |
| 3215 | // var-- |
| 3216 | // var += incr |
| 3217 | // var -= incr |
| 3218 | // var = var + incr |
| 3219 | // var = incr + var |
| 3220 | // var = var - incr |
| 3221 | // |
| 3222 | if (!S) { |
| 3223 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_incr) << Var; |
| 3224 | return true; |
| 3225 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3226 | IncrementSrcRange = S->getSourceRange(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3227 | S = S->IgnoreParens(); |
| 3228 | if (auto UO = dyn_cast<UnaryOperator>(S)) { |
| 3229 | if (UO->isIncrementDecrementOp() && GetInitVarDecl(UO->getSubExpr()) == Var) |
| 3230 | return SetStep( |
| 3231 | SemaRef.ActOnIntegerConstant(UO->getLocStart(), |
| 3232 | (UO->isDecrementOp() ? -1 : 1)).get(), |
| 3233 | false); |
| 3234 | } else if (auto BO = dyn_cast<BinaryOperator>(S)) { |
| 3235 | switch (BO->getOpcode()) { |
| 3236 | case BO_AddAssign: |
| 3237 | case BO_SubAssign: |
| 3238 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 3239 | return SetStep(BO->getRHS(), BO->getOpcode() == BO_SubAssign); |
| 3240 | break; |
| 3241 | case BO_Assign: |
| 3242 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 3243 | return CheckIncRHS(BO->getRHS()); |
| 3244 | break; |
| 3245 | default: |
| 3246 | break; |
| 3247 | } |
| 3248 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
| 3249 | switch (CE->getOperator()) { |
| 3250 | case OO_PlusPlus: |
| 3251 | case OO_MinusMinus: |
| 3252 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 3253 | return SetStep( |
| 3254 | SemaRef.ActOnIntegerConstant( |
| 3255 | CE->getLocStart(), |
| 3256 | ((CE->getOperator() == OO_MinusMinus) ? -1 : 1)).get(), |
| 3257 | false); |
| 3258 | break; |
| 3259 | case OO_PlusEqual: |
| 3260 | case OO_MinusEqual: |
| 3261 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 3262 | return SetStep(CE->getArg(1), CE->getOperator() == OO_MinusEqual); |
| 3263 | break; |
| 3264 | case OO_Equal: |
| 3265 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 3266 | return CheckIncRHS(CE->getArg(1)); |
| 3267 | break; |
| 3268 | default: |
| 3269 | break; |
| 3270 | } |
| 3271 | } |
| 3272 | SemaRef.Diag(S->getLocStart(), diag::err_omp_loop_not_canonical_incr) |
| 3273 | << S->getSourceRange() << Var; |
| 3274 | return true; |
| 3275 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3276 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3277 | namespace { |
| 3278 | // Transform variables declared in GNU statement expressions to new ones to |
| 3279 | // avoid crash on codegen. |
| 3280 | class TransformToNewDefs : public TreeTransform<TransformToNewDefs> { |
| 3281 | typedef TreeTransform<TransformToNewDefs> BaseTransform; |
| 3282 | |
| 3283 | public: |
| 3284 | TransformToNewDefs(Sema &SemaRef) : BaseTransform(SemaRef) {} |
| 3285 | |
| 3286 | Decl *TransformDefinition(SourceLocation Loc, Decl *D) { |
| 3287 | if (auto *VD = cast<VarDecl>(D)) |
| 3288 | if (!isa<ParmVarDecl>(D) && !isa<VarTemplateSpecializationDecl>(D) && |
| 3289 | !isa<ImplicitParamDecl>(D)) { |
| 3290 | auto *NewVD = VarDecl::Create( |
| 3291 | SemaRef.Context, VD->getDeclContext(), VD->getLocStart(), |
| 3292 | VD->getLocation(), VD->getIdentifier(), VD->getType(), |
| 3293 | VD->getTypeSourceInfo(), VD->getStorageClass()); |
| 3294 | NewVD->setTSCSpec(VD->getTSCSpec()); |
| 3295 | NewVD->setInit(VD->getInit()); |
| 3296 | NewVD->setInitStyle(VD->getInitStyle()); |
| 3297 | NewVD->setExceptionVariable(VD->isExceptionVariable()); |
| 3298 | NewVD->setNRVOVariable(VD->isNRVOVariable()); |
| 3299 | NewVD->setCXXForRangeDecl(VD->isInExternCXXContext()); |
| 3300 | NewVD->setConstexpr(VD->isConstexpr()); |
| 3301 | NewVD->setInitCapture(VD->isInitCapture()); |
| 3302 | NewVD->setPreviousDeclInSameBlockScope( |
| 3303 | VD->isPreviousDeclInSameBlockScope()); |
| 3304 | VD->getDeclContext()->addHiddenDecl(NewVD); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 3305 | if (VD->hasAttrs()) |
| 3306 | NewVD->setAttrs(VD->getAttrs()); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3307 | transformedLocalDecl(VD, NewVD); |
| 3308 | return NewVD; |
| 3309 | } |
| 3310 | return BaseTransform::TransformDefinition(Loc, D); |
| 3311 | } |
| 3312 | |
| 3313 | ExprResult TransformDeclRefExpr(DeclRefExpr *E) { |
| 3314 | if (auto *NewD = TransformDecl(E->getExprLoc(), E->getDecl())) |
| 3315 | if (E->getDecl() != NewD) { |
| 3316 | NewD->setReferenced(); |
| 3317 | NewD->markUsed(SemaRef.Context); |
| 3318 | return DeclRefExpr::Create( |
| 3319 | SemaRef.Context, E->getQualifierLoc(), E->getTemplateKeywordLoc(), |
| 3320 | cast<ValueDecl>(NewD), E->refersToEnclosingVariableOrCapture(), |
| 3321 | E->getNameInfo(), E->getType(), E->getValueKind()); |
| 3322 | } |
| 3323 | return BaseTransform::TransformDeclRefExpr(E); |
| 3324 | } |
| 3325 | }; |
| 3326 | } |
| 3327 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3328 | /// \brief Build the expression to calculate the number of iterations. |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3329 | Expr * |
| 3330 | OpenMPIterationSpaceChecker::BuildNumIterations(Scope *S, |
| 3331 | const bool LimitedType) const { |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3332 | TransformToNewDefs Transform(SemaRef); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3333 | ExprResult Diff; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3334 | auto VarType = Var->getType().getNonReferenceType(); |
| 3335 | if (VarType->isIntegerType() || VarType->isPointerType() || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3336 | SemaRef.getLangOpts().CPlusPlus) { |
| 3337 | // Upper - Lower |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3338 | auto *UBExpr = TestIsLessOp ? UB : LB; |
| 3339 | auto *LBExpr = TestIsLessOp ? LB : UB; |
| 3340 | Expr *Upper = Transform.TransformExpr(UBExpr).get(); |
| 3341 | Expr *Lower = Transform.TransformExpr(LBExpr).get(); |
| 3342 | if (!Upper || !Lower) |
| 3343 | return nullptr; |
| 3344 | Upper = SemaRef.PerformImplicitConversion(Upper, UBExpr->getType(), |
| 3345 | Sema::AA_Converting, |
| 3346 | /*AllowExplicit=*/true) |
| 3347 | .get(); |
| 3348 | Lower = SemaRef.PerformImplicitConversion(Lower, LBExpr->getType(), |
| 3349 | Sema::AA_Converting, |
| 3350 | /*AllowExplicit=*/true) |
| 3351 | .get(); |
| 3352 | if (!Upper || !Lower) |
| 3353 | return nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3354 | |
| 3355 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Sub, Upper, Lower); |
| 3356 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3357 | if (!Diff.isUsable() && VarType->getAsCXXRecordDecl()) { |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3358 | // BuildBinOp already emitted error, this one is to point user to upper |
| 3359 | // and lower bound, and to tell what is passed to 'operator-'. |
| 3360 | SemaRef.Diag(Upper->getLocStart(), diag::err_omp_loop_diff_cxx) |
| 3361 | << Upper->getSourceRange() << Lower->getSourceRange(); |
| 3362 | return nullptr; |
| 3363 | } |
| 3364 | } |
| 3365 | |
| 3366 | if (!Diff.isUsable()) |
| 3367 | return nullptr; |
| 3368 | |
| 3369 | // Upper - Lower [- 1] |
| 3370 | if (TestIsStrictOp) |
| 3371 | Diff = SemaRef.BuildBinOp( |
| 3372 | S, DefaultLoc, BO_Sub, Diff.get(), |
| 3373 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 3374 | if (!Diff.isUsable()) |
| 3375 | return nullptr; |
| 3376 | |
| 3377 | // Upper - Lower [- 1] + Step |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3378 | auto NewStep = Transform.TransformExpr(Step->IgnoreImplicit()); |
| 3379 | if (NewStep.isInvalid()) |
| 3380 | return nullptr; |
| 3381 | NewStep = SemaRef.PerformImplicitConversion( |
| 3382 | NewStep.get(), Step->IgnoreImplicit()->getType(), Sema::AA_Converting, |
| 3383 | /*AllowExplicit=*/true); |
| 3384 | if (NewStep.isInvalid()) |
| 3385 | return nullptr; |
| 3386 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Add, Diff.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3387 | if (!Diff.isUsable()) |
| 3388 | return nullptr; |
| 3389 | |
| 3390 | // Parentheses (for dumping/debugging purposes only). |
| 3391 | Diff = SemaRef.ActOnParenExpr(DefaultLoc, DefaultLoc, Diff.get()); |
| 3392 | if (!Diff.isUsable()) |
| 3393 | return nullptr; |
| 3394 | |
| 3395 | // (Upper - Lower [- 1] + Step) / Step |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3396 | NewStep = Transform.TransformExpr(Step->IgnoreImplicit()); |
| 3397 | if (NewStep.isInvalid()) |
| 3398 | return nullptr; |
| 3399 | NewStep = SemaRef.PerformImplicitConversion( |
| 3400 | NewStep.get(), Step->IgnoreImplicit()->getType(), Sema::AA_Converting, |
| 3401 | /*AllowExplicit=*/true); |
| 3402 | if (NewStep.isInvalid()) |
| 3403 | return nullptr; |
| 3404 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Div, Diff.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3405 | if (!Diff.isUsable()) |
| 3406 | return nullptr; |
| 3407 | |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3408 | // OpenMP runtime requires 32-bit or 64-bit loop variables. |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3409 | QualType Type = Diff.get()->getType(); |
| 3410 | auto &C = SemaRef.Context; |
| 3411 | bool UseVarType = VarType->hasIntegerRepresentation() && |
| 3412 | C.getTypeSize(Type) > C.getTypeSize(VarType); |
| 3413 | if (!Type->isIntegerType() || UseVarType) { |
| 3414 | unsigned NewSize = |
| 3415 | UseVarType ? C.getTypeSize(VarType) : C.getTypeSize(Type); |
| 3416 | bool IsSigned = UseVarType ? VarType->hasSignedIntegerRepresentation() |
| 3417 | : Type->hasSignedIntegerRepresentation(); |
| 3418 | Type = C.getIntTypeForBitwidth(NewSize, IsSigned); |
| 3419 | Diff = SemaRef.PerformImplicitConversion( |
| 3420 | Diff.get(), Type, Sema::AA_Converting, /*AllowExplicit=*/true); |
| 3421 | if (!Diff.isUsable()) |
| 3422 | return nullptr; |
| 3423 | } |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3424 | if (LimitedType) { |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3425 | unsigned NewSize = (C.getTypeSize(Type) > 32) ? 64 : 32; |
| 3426 | if (NewSize != C.getTypeSize(Type)) { |
| 3427 | if (NewSize < C.getTypeSize(Type)) { |
| 3428 | assert(NewSize == 64 && "incorrect loop var size"); |
| 3429 | SemaRef.Diag(DefaultLoc, diag::warn_omp_loop_64_bit_var) |
| 3430 | << InitSrcRange << ConditionSrcRange; |
| 3431 | } |
| 3432 | QualType NewType = C.getIntTypeForBitwidth( |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3433 | NewSize, Type->hasSignedIntegerRepresentation() || |
| 3434 | C.getTypeSize(Type) < NewSize); |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3435 | Diff = SemaRef.PerformImplicitConversion(Diff.get(), NewType, |
| 3436 | Sema::AA_Converting, true); |
| 3437 | if (!Diff.isUsable()) |
| 3438 | return nullptr; |
| 3439 | } |
| 3440 | } |
| 3441 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3442 | return Diff.get(); |
| 3443 | } |
| 3444 | |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3445 | Expr *OpenMPIterationSpaceChecker::BuildPreCond(Scope *S, Expr *Cond) const { |
| 3446 | // Try to build LB <op> UB, where <op> is <, >, <=, or >=. |
| 3447 | bool Suppress = SemaRef.getDiagnostics().getSuppressAllDiagnostics(); |
| 3448 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(/*Val=*/true); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3449 | TransformToNewDefs Transform(SemaRef); |
| 3450 | |
| 3451 | auto NewLB = Transform.TransformExpr(LB); |
| 3452 | auto NewUB = Transform.TransformExpr(UB); |
| 3453 | if (NewLB.isInvalid() || NewUB.isInvalid()) |
| 3454 | return Cond; |
| 3455 | NewLB = SemaRef.PerformImplicitConversion(NewLB.get(), LB->getType(), |
| 3456 | Sema::AA_Converting, |
| 3457 | /*AllowExplicit=*/true); |
| 3458 | NewUB = SemaRef.PerformImplicitConversion(NewUB.get(), UB->getType(), |
| 3459 | Sema::AA_Converting, |
| 3460 | /*AllowExplicit=*/true); |
| 3461 | if (NewLB.isInvalid() || NewUB.isInvalid()) |
| 3462 | return Cond; |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3463 | auto CondExpr = SemaRef.BuildBinOp( |
| 3464 | S, DefaultLoc, TestIsLessOp ? (TestIsStrictOp ? BO_LT : BO_LE) |
| 3465 | : (TestIsStrictOp ? BO_GT : BO_GE), |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3466 | NewLB.get(), NewUB.get()); |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3467 | if (CondExpr.isUsable()) { |
| 3468 | CondExpr = SemaRef.PerformImplicitConversion( |
| 3469 | CondExpr.get(), SemaRef.Context.BoolTy, /*Action=*/Sema::AA_Casting, |
| 3470 | /*AllowExplicit=*/true); |
| 3471 | } |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3472 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(Suppress); |
| 3473 | // Otherwise use original loop conditon and evaluate it in runtime. |
| 3474 | return CondExpr.isUsable() ? CondExpr.get() : Cond; |
| 3475 | } |
| 3476 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3477 | /// \brief Build reference expression to the counter be used for codegen. |
| 3478 | Expr *OpenMPIterationSpaceChecker::BuildCounterVar() const { |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3479 | return buildDeclRefExpr(SemaRef, Var, Var->getType().getNonReferenceType(), |
| 3480 | DefaultLoc); |
| 3481 | } |
| 3482 | |
| 3483 | Expr *OpenMPIterationSpaceChecker::BuildPrivateCounterVar() const { |
| 3484 | if (Var && !Var->isInvalidDecl()) { |
| 3485 | auto Type = Var->getType().getNonReferenceType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 3486 | auto *PrivateVar = |
| 3487 | buildVarDecl(SemaRef, DefaultLoc, Type, Var->getName(), |
| 3488 | Var->hasAttrs() ? &Var->getAttrs() : nullptr); |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3489 | if (PrivateVar->isInvalidDecl()) |
| 3490 | return nullptr; |
| 3491 | return buildDeclRefExpr(SemaRef, PrivateVar, Type, DefaultLoc); |
| 3492 | } |
| 3493 | return nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3494 | } |
| 3495 | |
| 3496 | /// \brief Build initization of the counter be used for codegen. |
| 3497 | Expr *OpenMPIterationSpaceChecker::BuildCounterInit() const { return LB; } |
| 3498 | |
| 3499 | /// \brief Build step of the counter be used for codegen. |
| 3500 | Expr *OpenMPIterationSpaceChecker::BuildCounterStep() const { return Step; } |
| 3501 | |
| 3502 | /// \brief Iteration space of a single for loop. |
| 3503 | struct LoopIterationSpace { |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3504 | /// \brief Condition of the loop. |
| 3505 | Expr *PreCond; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3506 | /// \brief This expression calculates the number of iterations in the loop. |
| 3507 | /// It is always possible to calculate it before starting the loop. |
| 3508 | Expr *NumIterations; |
| 3509 | /// \brief The loop counter variable. |
| 3510 | Expr *CounterVar; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3511 | /// \brief Private loop counter variable. |
| 3512 | Expr *PrivateCounterVar; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3513 | /// \brief This is initializer for the initial value of #CounterVar. |
| 3514 | Expr *CounterInit; |
| 3515 | /// \brief This is step for the #CounterVar used to generate its update: |
| 3516 | /// #CounterVar = #CounterInit + #CounterStep * CurrentIteration. |
| 3517 | Expr *CounterStep; |
| 3518 | /// \brief Should step be subtracted? |
| 3519 | bool Subtract; |
| 3520 | /// \brief Source range of the loop init. |
| 3521 | SourceRange InitSrcRange; |
| 3522 | /// \brief Source range of the loop condition. |
| 3523 | SourceRange CondSrcRange; |
| 3524 | /// \brief Source range of the loop increment. |
| 3525 | SourceRange IncSrcRange; |
| 3526 | }; |
| 3527 | |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 3528 | } // namespace |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3529 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3530 | void Sema::ActOnOpenMPLoopInitialization(SourceLocation ForLoc, Stmt *Init) { |
| 3531 | assert(getLangOpts().OpenMP && "OpenMP is not active."); |
| 3532 | assert(Init && "Expected loop in canonical form."); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 3533 | unsigned AssociatedLoops = DSAStack->getAssociatedLoops(); |
| 3534 | if (AssociatedLoops > 0 && |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3535 | isOpenMPLoopDirective(DSAStack->getCurrentDirective())) { |
| 3536 | OpenMPIterationSpaceChecker ISC(*this, ForLoc); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 3537 | if (!ISC.CheckInit(Init, /*EmitDiags=*/false)) |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3538 | DSAStack->addLoopControlVariable(ISC.GetLoopVar()); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 3539 | DSAStack->setAssociatedLoops(AssociatedLoops - 1); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3540 | } |
| 3541 | } |
| 3542 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3543 | /// \brief Called on a for stmt to check and extract its iteration space |
| 3544 | /// for further processing (such as collapsing). |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3545 | static bool CheckOpenMPIterationSpace( |
| 3546 | OpenMPDirectiveKind DKind, Stmt *S, Sema &SemaRef, DSAStackTy &DSA, |
| 3547 | unsigned CurrentNestedLoopCount, unsigned NestedLoopCount, |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3548 | Expr *CollapseLoopCountExpr, Expr *OrderedLoopCountExpr, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3549 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA, |
| 3550 | LoopIterationSpace &ResultIterSpace) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3551 | // OpenMP [2.6, Canonical Loop Form] |
| 3552 | // for (init-expr; test-expr; incr-expr) structured-block |
| 3553 | auto For = dyn_cast_or_null<ForStmt>(S); |
| 3554 | if (!For) { |
| 3555 | SemaRef.Diag(S->getLocStart(), diag::err_omp_not_for) |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3556 | << (CollapseLoopCountExpr != nullptr || OrderedLoopCountExpr != nullptr) |
| 3557 | << getOpenMPDirectiveName(DKind) << NestedLoopCount |
| 3558 | << (CurrentNestedLoopCount > 0) << CurrentNestedLoopCount; |
| 3559 | if (NestedLoopCount > 1) { |
| 3560 | if (CollapseLoopCountExpr && OrderedLoopCountExpr) |
| 3561 | SemaRef.Diag(DSA.getConstructLoc(), |
| 3562 | diag::note_omp_collapse_ordered_expr) |
| 3563 | << 2 << CollapseLoopCountExpr->getSourceRange() |
| 3564 | << OrderedLoopCountExpr->getSourceRange(); |
| 3565 | else if (CollapseLoopCountExpr) |
| 3566 | SemaRef.Diag(CollapseLoopCountExpr->getExprLoc(), |
| 3567 | diag::note_omp_collapse_ordered_expr) |
| 3568 | << 0 << CollapseLoopCountExpr->getSourceRange(); |
| 3569 | else |
| 3570 | SemaRef.Diag(OrderedLoopCountExpr->getExprLoc(), |
| 3571 | diag::note_omp_collapse_ordered_expr) |
| 3572 | << 1 << OrderedLoopCountExpr->getSourceRange(); |
| 3573 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3574 | return true; |
| 3575 | } |
| 3576 | assert(For->getBody()); |
| 3577 | |
| 3578 | OpenMPIterationSpaceChecker ISC(SemaRef, For->getForLoc()); |
| 3579 | |
| 3580 | // Check init. |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 3581 | auto Init = For->getInit(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3582 | if (ISC.CheckInit(Init)) { |
| 3583 | return true; |
| 3584 | } |
| 3585 | |
| 3586 | bool HasErrors = false; |
| 3587 | |
| 3588 | // Check loop variable's type. |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 3589 | auto Var = ISC.GetLoopVar(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3590 | |
| 3591 | // OpenMP [2.6, Canonical Loop Form] |
| 3592 | // Var is one of the following: |
| 3593 | // A variable of signed or unsigned integer type. |
| 3594 | // For C++, a variable of a random access iterator type. |
| 3595 | // For C, a variable of a pointer type. |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3596 | auto VarType = Var->getType().getNonReferenceType(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3597 | if (!VarType->isDependentType() && !VarType->isIntegerType() && |
| 3598 | !VarType->isPointerType() && |
| 3599 | !(SemaRef.getLangOpts().CPlusPlus && VarType->isOverloadableType())) { |
| 3600 | SemaRef.Diag(Init->getLocStart(), diag::err_omp_loop_variable_type) |
| 3601 | << SemaRef.getLangOpts().CPlusPlus; |
| 3602 | HasErrors = true; |
| 3603 | } |
| 3604 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3605 | // OpenMP, 2.14.1.1 Data-sharing Attribute Rules for Variables Referenced in a |
| 3606 | // Construct |
| 3607 | // The loop iteration variable(s) in the associated for-loop(s) of a for or |
| 3608 | // parallel for construct is (are) private. |
| 3609 | // The loop iteration variable in the associated for-loop of a simd construct |
| 3610 | // with just one associated for-loop is linear with a constant-linear-step |
| 3611 | // that is the increment of the associated for-loop. |
| 3612 | // Exclude loop var from the list of variables with implicitly defined data |
| 3613 | // sharing attributes. |
Benjamin Kramer | ad8e079 | 2014-10-10 15:32:48 +0000 | [diff] [blame] | 3614 | VarsWithImplicitDSA.erase(Var); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3615 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3616 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced in |
| 3617 | // a Construct, C/C++]. |
Alexey Bataev | cefffae | 2014-06-23 08:21:53 +0000 | [diff] [blame] | 3618 | // The loop iteration variable in the associated for-loop of a simd construct |
| 3619 | // with just one associated for-loop may be listed in a linear clause with a |
| 3620 | // constant-linear-step that is the increment of the associated for-loop. |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3621 | // The loop iteration variable(s) in the associated for-loop(s) of a for or |
| 3622 | // parallel for construct may be listed in a private or lastprivate clause. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 3623 | DSAStackTy::DSAVarData DVar = DSA.getTopDSA(Var, false); |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3624 | auto LoopVarRefExpr = ISC.GetLoopVarRefExpr(); |
| 3625 | // If LoopVarRefExpr is nullptr it means the corresponding loop variable is |
| 3626 | // declared in the loop and it is predetermined as a private. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3627 | auto PredeterminedCKind = |
| 3628 | isOpenMPSimdDirective(DKind) |
| 3629 | ? ((NestedLoopCount == 1) ? OMPC_linear : OMPC_lastprivate) |
| 3630 | : OMPC_private; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3631 | if (((isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown && |
Alexey Bataev | e648e80 | 2015-12-25 13:38:08 +0000 | [diff] [blame] | 3632 | DVar.CKind != PredeterminedCKind) || |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 3633 | ((isOpenMPWorksharingDirective(DKind) || DKind == OMPD_taskloop || |
Alexey Bataev | e648e80 | 2015-12-25 13:38:08 +0000 | [diff] [blame] | 3634 | isOpenMPDistributeDirective(DKind)) && |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 3635 | !isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown && |
Alexey Bataev | e648e80 | 2015-12-25 13:38:08 +0000 | [diff] [blame] | 3636 | DVar.CKind != OMPC_private && DVar.CKind != OMPC_lastprivate)) && |
| 3637 | (DVar.CKind != OMPC_private || DVar.RefExpr != nullptr)) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3638 | SemaRef.Diag(Init->getLocStart(), diag::err_omp_loop_var_dsa) |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3639 | << getOpenMPClauseName(DVar.CKind) << getOpenMPDirectiveName(DKind) |
| 3640 | << getOpenMPClauseName(PredeterminedCKind); |
Alexey Bataev | f2453a0 | 2015-05-06 07:25:08 +0000 | [diff] [blame] | 3641 | if (DVar.RefExpr == nullptr) |
| 3642 | DVar.CKind = PredeterminedCKind; |
| 3643 | ReportOriginalDSA(SemaRef, &DSA, Var, DVar, /*IsLoopIterVar=*/true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3644 | HasErrors = true; |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3645 | } else if (LoopVarRefExpr != nullptr) { |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3646 | // Make the loop iteration variable private (for worksharing constructs), |
| 3647 | // linear (for simd directives with the only one associated loop) or |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3648 | // lastprivate (for simd directives with several collapsed or ordered |
| 3649 | // loops). |
Alexey Bataev | 9aba41c | 2014-11-14 04:08:45 +0000 | [diff] [blame] | 3650 | if (DVar.CKind == OMPC_unknown) |
| 3651 | DVar = DSA.hasDSA(Var, isOpenMPPrivate, MatchesAlways(), |
| 3652 | /*FromParent=*/false); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3653 | DSA.addDSA(Var, LoopVarRefExpr, PredeterminedCKind); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3654 | } |
| 3655 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 3656 | assert(isOpenMPLoopDirective(DKind) && "DSA for non-loop vars"); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 3657 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3658 | // Check test-expr. |
| 3659 | HasErrors |= ISC.CheckCond(For->getCond()); |
| 3660 | |
| 3661 | // Check incr-expr. |
| 3662 | HasErrors |= ISC.CheckInc(For->getInc()); |
| 3663 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3664 | if (ISC.Dependent() || SemaRef.CurContext->isDependentContext() || HasErrors) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3665 | return HasErrors; |
| 3666 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3667 | // Build the loop's iteration space representation. |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3668 | ResultIterSpace.PreCond = ISC.BuildPreCond(DSA.getCurScope(), For->getCond()); |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3669 | ResultIterSpace.NumIterations = ISC.BuildNumIterations( |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 3670 | DSA.getCurScope(), (isOpenMPWorksharingDirective(DKind) || |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 3671 | isOpenMPTaskLoopDirective(DKind) || |
| 3672 | isOpenMPDistributeDirective(DKind))); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3673 | ResultIterSpace.CounterVar = ISC.BuildCounterVar(); |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3674 | ResultIterSpace.PrivateCounterVar = ISC.BuildPrivateCounterVar(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3675 | ResultIterSpace.CounterInit = ISC.BuildCounterInit(); |
| 3676 | ResultIterSpace.CounterStep = ISC.BuildCounterStep(); |
| 3677 | ResultIterSpace.InitSrcRange = ISC.GetInitSrcRange(); |
| 3678 | ResultIterSpace.CondSrcRange = ISC.GetConditionSrcRange(); |
| 3679 | ResultIterSpace.IncSrcRange = ISC.GetIncrementSrcRange(); |
| 3680 | ResultIterSpace.Subtract = ISC.ShouldSubtractStep(); |
| 3681 | |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3682 | HasErrors |= (ResultIterSpace.PreCond == nullptr || |
| 3683 | ResultIterSpace.NumIterations == nullptr || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3684 | ResultIterSpace.CounterVar == nullptr || |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3685 | ResultIterSpace.PrivateCounterVar == nullptr || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3686 | ResultIterSpace.CounterInit == nullptr || |
| 3687 | ResultIterSpace.CounterStep == nullptr); |
| 3688 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3689 | return HasErrors; |
| 3690 | } |
| 3691 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3692 | /// \brief Build 'VarRef = Start. |
| 3693 | static ExprResult BuildCounterInit(Sema &SemaRef, Scope *S, SourceLocation Loc, |
| 3694 | ExprResult VarRef, ExprResult Start) { |
| 3695 | TransformToNewDefs Transform(SemaRef); |
| 3696 | // Build 'VarRef = Start. |
| 3697 | auto NewStart = Transform.TransformExpr(Start.get()->IgnoreImplicit()); |
| 3698 | if (NewStart.isInvalid()) |
| 3699 | return ExprError(); |
| 3700 | NewStart = SemaRef.PerformImplicitConversion( |
| 3701 | NewStart.get(), Start.get()->IgnoreImplicit()->getType(), |
| 3702 | Sema::AA_Converting, |
| 3703 | /*AllowExplicit=*/true); |
| 3704 | if (NewStart.isInvalid()) |
| 3705 | return ExprError(); |
| 3706 | NewStart = SemaRef.PerformImplicitConversion( |
| 3707 | NewStart.get(), VarRef.get()->getType(), Sema::AA_Converting, |
| 3708 | /*AllowExplicit=*/true); |
| 3709 | if (!NewStart.isUsable()) |
| 3710 | return ExprError(); |
| 3711 | |
| 3712 | auto Init = |
| 3713 | SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), NewStart.get()); |
| 3714 | return Init; |
| 3715 | } |
| 3716 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3717 | /// \brief Build 'VarRef = Start + Iter * Step'. |
| 3718 | static ExprResult BuildCounterUpdate(Sema &SemaRef, Scope *S, |
| 3719 | SourceLocation Loc, ExprResult VarRef, |
| 3720 | ExprResult Start, ExprResult Iter, |
| 3721 | ExprResult Step, bool Subtract) { |
| 3722 | // Add parentheses (for debugging purposes only). |
| 3723 | Iter = SemaRef.ActOnParenExpr(Loc, Loc, Iter.get()); |
| 3724 | if (!VarRef.isUsable() || !Start.isUsable() || !Iter.isUsable() || |
| 3725 | !Step.isUsable()) |
| 3726 | return ExprError(); |
| 3727 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3728 | TransformToNewDefs Transform(SemaRef); |
| 3729 | auto NewStep = Transform.TransformExpr(Step.get()->IgnoreImplicit()); |
| 3730 | if (NewStep.isInvalid()) |
| 3731 | return ExprError(); |
| 3732 | NewStep = SemaRef.PerformImplicitConversion( |
| 3733 | NewStep.get(), Step.get()->IgnoreImplicit()->getType(), |
| 3734 | Sema::AA_Converting, |
| 3735 | /*AllowExplicit=*/true); |
| 3736 | if (NewStep.isInvalid()) |
| 3737 | return ExprError(); |
| 3738 | ExprResult Update = |
| 3739 | SemaRef.BuildBinOp(S, Loc, BO_Mul, Iter.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3740 | if (!Update.isUsable()) |
| 3741 | return ExprError(); |
| 3742 | |
| 3743 | // Build 'VarRef = Start + Iter * Step'. |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3744 | auto NewStart = Transform.TransformExpr(Start.get()->IgnoreImplicit()); |
| 3745 | if (NewStart.isInvalid()) |
| 3746 | return ExprError(); |
| 3747 | NewStart = SemaRef.PerformImplicitConversion( |
| 3748 | NewStart.get(), Start.get()->IgnoreImplicit()->getType(), |
| 3749 | Sema::AA_Converting, |
| 3750 | /*AllowExplicit=*/true); |
| 3751 | if (NewStart.isInvalid()) |
| 3752 | return ExprError(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3753 | Update = SemaRef.BuildBinOp(S, Loc, (Subtract ? BO_Sub : BO_Add), |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3754 | NewStart.get(), Update.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3755 | if (!Update.isUsable()) |
| 3756 | return ExprError(); |
| 3757 | |
| 3758 | Update = SemaRef.PerformImplicitConversion( |
| 3759 | Update.get(), VarRef.get()->getType(), Sema::AA_Converting, true); |
| 3760 | if (!Update.isUsable()) |
| 3761 | return ExprError(); |
| 3762 | |
| 3763 | Update = SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), Update.get()); |
| 3764 | return Update; |
| 3765 | } |
| 3766 | |
| 3767 | /// \brief Convert integer expression \a E to make it have at least \a Bits |
| 3768 | /// bits. |
| 3769 | static ExprResult WidenIterationCount(unsigned Bits, Expr *E, |
| 3770 | Sema &SemaRef) { |
| 3771 | if (E == nullptr) |
| 3772 | return ExprError(); |
| 3773 | auto &C = SemaRef.Context; |
| 3774 | QualType OldType = E->getType(); |
| 3775 | unsigned HasBits = C.getTypeSize(OldType); |
| 3776 | if (HasBits >= Bits) |
| 3777 | return ExprResult(E); |
| 3778 | // OK to convert to signed, because new type has more bits than old. |
| 3779 | QualType NewType = C.getIntTypeForBitwidth(Bits, /* Signed */ true); |
| 3780 | return SemaRef.PerformImplicitConversion(E, NewType, Sema::AA_Converting, |
| 3781 | true); |
| 3782 | } |
| 3783 | |
| 3784 | /// \brief Check if the given expression \a E is a constant integer that fits |
| 3785 | /// into \a Bits bits. |
| 3786 | static bool FitsInto(unsigned Bits, bool Signed, Expr *E, Sema &SemaRef) { |
| 3787 | if (E == nullptr) |
| 3788 | return false; |
| 3789 | llvm::APSInt Result; |
| 3790 | if (E->isIntegerConstantExpr(Result, SemaRef.Context)) |
| 3791 | return Signed ? Result.isSignedIntN(Bits) : Result.isIntN(Bits); |
| 3792 | return false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3793 | } |
| 3794 | |
| 3795 | /// \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] | 3796 | /// \return Returns 0 if one of the collapsed stmts is not canonical for loop, |
| 3797 | /// number of collapsed loops otherwise. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3798 | static unsigned |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3799 | CheckOpenMPLoop(OpenMPDirectiveKind DKind, Expr *CollapseLoopCountExpr, |
| 3800 | Expr *OrderedLoopCountExpr, Stmt *AStmt, Sema &SemaRef, |
| 3801 | DSAStackTy &DSA, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3802 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA, |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3803 | OMPLoopDirective::HelperExprs &Built) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3804 | unsigned NestedLoopCount = 1; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3805 | if (CollapseLoopCountExpr) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3806 | // Found 'collapse' clause - calculate collapse number. |
| 3807 | llvm::APSInt Result; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3808 | if (CollapseLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext())) |
Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 3809 | NestedLoopCount = Result.getLimitedValue(); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3810 | } |
| 3811 | if (OrderedLoopCountExpr) { |
| 3812 | // Found 'ordered' clause - calculate collapse number. |
| 3813 | llvm::APSInt Result; |
Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 3814 | if (OrderedLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext())) { |
| 3815 | if (Result.getLimitedValue() < NestedLoopCount) { |
| 3816 | SemaRef.Diag(OrderedLoopCountExpr->getExprLoc(), |
| 3817 | diag::err_omp_wrong_ordered_loop_count) |
| 3818 | << OrderedLoopCountExpr->getSourceRange(); |
| 3819 | SemaRef.Diag(CollapseLoopCountExpr->getExprLoc(), |
| 3820 | diag::note_collapse_loop_count) |
| 3821 | << CollapseLoopCountExpr->getSourceRange(); |
| 3822 | } |
| 3823 | NestedLoopCount = Result.getLimitedValue(); |
| 3824 | } |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3825 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3826 | // This is helper routine for loop directives (e.g., 'for', 'simd', |
| 3827 | // 'for simd', etc.). |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3828 | SmallVector<LoopIterationSpace, 4> IterSpaces; |
| 3829 | IterSpaces.resize(NestedLoopCount); |
| 3830 | Stmt *CurStmt = AStmt->IgnoreContainers(/* IgnoreCaptured */ true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3831 | for (unsigned Cnt = 0; Cnt < NestedLoopCount; ++Cnt) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3832 | if (CheckOpenMPIterationSpace(DKind, CurStmt, SemaRef, DSA, Cnt, |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3833 | NestedLoopCount, CollapseLoopCountExpr, |
| 3834 | OrderedLoopCountExpr, VarsWithImplicitDSA, |
| 3835 | IterSpaces[Cnt])) |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 3836 | return 0; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3837 | // 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] | 3838 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 3839 | // All loops associated with the construct must be perfectly nested; that |
| 3840 | // is, there must be no intervening code nor any OpenMP directive between |
| 3841 | // any two loops. |
| 3842 | CurStmt = cast<ForStmt>(CurStmt)->getBody()->IgnoreContainers(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3843 | } |
| 3844 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3845 | Built.clear(/* size */ NestedLoopCount); |
| 3846 | |
| 3847 | if (SemaRef.CurContext->isDependentContext()) |
| 3848 | return NestedLoopCount; |
| 3849 | |
| 3850 | // An example of what is generated for the following code: |
| 3851 | // |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3852 | // #pragma omp simd collapse(2) ordered(2) |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3853 | // for (i = 0; i < NI; ++i) |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3854 | // for (k = 0; k < NK; ++k) |
| 3855 | // for (j = J0; j < NJ; j+=2) { |
| 3856 | // <loop body> |
| 3857 | // } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3858 | // |
| 3859 | // We generate the code below. |
| 3860 | // Note: the loop body may be outlined in CodeGen. |
| 3861 | // Note: some counters may be C++ classes, operator- is used to find number of |
| 3862 | // iterations and operator+= to calculate counter value. |
| 3863 | // Note: decltype(NumIterations) must be integer type (in 'omp for', only i32 |
| 3864 | // or i64 is currently supported). |
| 3865 | // |
| 3866 | // #define NumIterations (NI * ((NJ - J0 - 1 + 2) / 2)) |
| 3867 | // for (int[32|64]_t IV = 0; IV < NumIterations; ++IV ) { |
| 3868 | // .local.i = IV / ((NJ - J0 - 1 + 2) / 2); |
| 3869 | // .local.j = J0 + (IV % ((NJ - J0 - 1 + 2) / 2)) * 2; |
| 3870 | // // similar updates for vars in clauses (e.g. 'linear') |
| 3871 | // <loop body (using local i and j)> |
| 3872 | // } |
| 3873 | // i = NI; // assign final values of counters |
| 3874 | // j = NJ; |
| 3875 | // |
| 3876 | |
| 3877 | // Last iteration number is (I1 * I2 * ... In) - 1, where I1, I2 ... In are |
| 3878 | // the iteration counts of the collapsed for loops. |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3879 | // Precondition tests if there is at least one iteration (all conditions are |
| 3880 | // true). |
| 3881 | auto PreCond = ExprResult(IterSpaces[0].PreCond); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3882 | auto N0 = IterSpaces[0].NumIterations; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3883 | ExprResult LastIteration32 = WidenIterationCount( |
| 3884 | 32 /* Bits */, SemaRef.PerformImplicitConversion( |
| 3885 | N0->IgnoreImpCasts(), N0->getType(), |
| 3886 | Sema::AA_Converting, /*AllowExplicit=*/true) |
| 3887 | .get(), |
| 3888 | SemaRef); |
| 3889 | ExprResult LastIteration64 = WidenIterationCount( |
| 3890 | 64 /* Bits */, SemaRef.PerformImplicitConversion( |
| 3891 | N0->IgnoreImpCasts(), N0->getType(), |
| 3892 | Sema::AA_Converting, /*AllowExplicit=*/true) |
| 3893 | .get(), |
| 3894 | SemaRef); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3895 | |
| 3896 | if (!LastIteration32.isUsable() || !LastIteration64.isUsable()) |
| 3897 | return NestedLoopCount; |
| 3898 | |
| 3899 | auto &C = SemaRef.Context; |
| 3900 | bool AllCountsNeedLessThan32Bits = C.getTypeSize(N0->getType()) < 32; |
| 3901 | |
| 3902 | Scope *CurScope = DSA.getCurScope(); |
| 3903 | for (unsigned Cnt = 1; Cnt < NestedLoopCount; ++Cnt) { |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3904 | if (PreCond.isUsable()) { |
| 3905 | PreCond = SemaRef.BuildBinOp(CurScope, SourceLocation(), BO_LAnd, |
| 3906 | PreCond.get(), IterSpaces[Cnt].PreCond); |
| 3907 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3908 | auto N = IterSpaces[Cnt].NumIterations; |
| 3909 | AllCountsNeedLessThan32Bits &= C.getTypeSize(N->getType()) < 32; |
| 3910 | if (LastIteration32.isUsable()) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3911 | LastIteration32 = SemaRef.BuildBinOp( |
| 3912 | CurScope, SourceLocation(), BO_Mul, LastIteration32.get(), |
| 3913 | SemaRef.PerformImplicitConversion(N->IgnoreImpCasts(), N->getType(), |
| 3914 | Sema::AA_Converting, |
| 3915 | /*AllowExplicit=*/true) |
| 3916 | .get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3917 | if (LastIteration64.isUsable()) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3918 | LastIteration64 = SemaRef.BuildBinOp( |
| 3919 | CurScope, SourceLocation(), BO_Mul, LastIteration64.get(), |
| 3920 | SemaRef.PerformImplicitConversion(N->IgnoreImpCasts(), N->getType(), |
| 3921 | Sema::AA_Converting, |
| 3922 | /*AllowExplicit=*/true) |
| 3923 | .get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3924 | } |
| 3925 | |
| 3926 | // Choose either the 32-bit or 64-bit version. |
| 3927 | ExprResult LastIteration = LastIteration64; |
| 3928 | if (LastIteration32.isUsable() && |
| 3929 | C.getTypeSize(LastIteration32.get()->getType()) == 32 && |
| 3930 | (AllCountsNeedLessThan32Bits || NestedLoopCount == 1 || |
| 3931 | FitsInto( |
| 3932 | 32 /* Bits */, |
| 3933 | LastIteration32.get()->getType()->hasSignedIntegerRepresentation(), |
| 3934 | LastIteration64.get(), SemaRef))) |
| 3935 | LastIteration = LastIteration32; |
| 3936 | |
| 3937 | if (!LastIteration.isUsable()) |
| 3938 | return 0; |
| 3939 | |
| 3940 | // Save the number of iterations. |
| 3941 | ExprResult NumIterations = LastIteration; |
| 3942 | { |
| 3943 | LastIteration = SemaRef.BuildBinOp( |
| 3944 | CurScope, SourceLocation(), BO_Sub, LastIteration.get(), |
| 3945 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 3946 | if (!LastIteration.isUsable()) |
| 3947 | return 0; |
| 3948 | } |
| 3949 | |
| 3950 | // Calculate the last iteration number beforehand instead of doing this on |
| 3951 | // each iteration. Do not do this if the number of iterations may be kfold-ed. |
| 3952 | llvm::APSInt Result; |
| 3953 | bool IsConstant = |
| 3954 | LastIteration.get()->isIntegerConstantExpr(Result, SemaRef.Context); |
| 3955 | ExprResult CalcLastIteration; |
| 3956 | if (!IsConstant) { |
| 3957 | SourceLocation SaveLoc; |
| 3958 | VarDecl *SaveVar = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3959 | buildVarDecl(SemaRef, SaveLoc, LastIteration.get()->getType(), |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3960 | ".omp.last.iteration"); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3961 | ExprResult SaveRef = buildDeclRefExpr( |
| 3962 | SemaRef, SaveVar, LastIteration.get()->getType(), SaveLoc); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3963 | CalcLastIteration = SemaRef.BuildBinOp(CurScope, SaveLoc, BO_Assign, |
| 3964 | SaveRef.get(), LastIteration.get()); |
| 3965 | LastIteration = SaveRef; |
| 3966 | |
| 3967 | // Prepare SaveRef + 1. |
| 3968 | NumIterations = SemaRef.BuildBinOp( |
| 3969 | CurScope, SaveLoc, BO_Add, SaveRef.get(), |
| 3970 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 3971 | if (!NumIterations.isUsable()) |
| 3972 | return 0; |
| 3973 | } |
| 3974 | |
| 3975 | SourceLocation InitLoc = IterSpaces[0].InitSrcRange.getBegin(); |
| 3976 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3977 | QualType VType = LastIteration.get()->getType(); |
| 3978 | // Build variables passed into runtime, nesessary for worksharing directives. |
| 3979 | ExprResult LB, UB, IL, ST, EUB; |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 3980 | if (isOpenMPWorksharingDirective(DKind) || isOpenMPTaskLoopDirective(DKind) || |
| 3981 | isOpenMPDistributeDirective(DKind)) { |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3982 | // Lower bound variable, initialized with zero. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3983 | VarDecl *LBDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.lb"); |
| 3984 | LB = buildDeclRefExpr(SemaRef, LBDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3985 | SemaRef.AddInitializerToDecl( |
| 3986 | LBDecl, SemaRef.ActOnIntegerConstant(InitLoc, 0).get(), |
| 3987 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 3988 | |
| 3989 | // Upper bound variable, initialized with last iteration number. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3990 | VarDecl *UBDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.ub"); |
| 3991 | UB = buildDeclRefExpr(SemaRef, UBDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3992 | SemaRef.AddInitializerToDecl(UBDecl, LastIteration.get(), |
| 3993 | /*DirectInit*/ false, |
| 3994 | /*TypeMayContainAuto*/ false); |
| 3995 | |
| 3996 | // A 32-bit variable-flag where runtime returns 1 for the last iteration. |
| 3997 | // This will be used to implement clause 'lastprivate'. |
| 3998 | QualType Int32Ty = SemaRef.Context.getIntTypeForBitwidth(32, true); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3999 | VarDecl *ILDecl = buildVarDecl(SemaRef, InitLoc, Int32Ty, ".omp.is_last"); |
| 4000 | IL = buildDeclRefExpr(SemaRef, ILDecl, Int32Ty, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4001 | SemaRef.AddInitializerToDecl( |
| 4002 | ILDecl, SemaRef.ActOnIntegerConstant(InitLoc, 0).get(), |
| 4003 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 4004 | |
| 4005 | // Stride variable returned by runtime (we initialize it to 1 by default). |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4006 | VarDecl *STDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.stride"); |
| 4007 | ST = buildDeclRefExpr(SemaRef, STDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4008 | SemaRef.AddInitializerToDecl( |
| 4009 | STDecl, SemaRef.ActOnIntegerConstant(InitLoc, 1).get(), |
| 4010 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 4011 | |
| 4012 | // Build expression: UB = min(UB, LastIteration) |
| 4013 | // It is nesessary for CodeGen of directives with static scheduling. |
| 4014 | ExprResult IsUBGreater = SemaRef.BuildBinOp(CurScope, InitLoc, BO_GT, |
| 4015 | UB.get(), LastIteration.get()); |
| 4016 | ExprResult CondOp = SemaRef.ActOnConditionalOp( |
| 4017 | InitLoc, InitLoc, IsUBGreater.get(), LastIteration.get(), UB.get()); |
| 4018 | EUB = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, UB.get(), |
| 4019 | CondOp.get()); |
| 4020 | EUB = SemaRef.ActOnFinishFullExpr(EUB.get()); |
| 4021 | } |
| 4022 | |
| 4023 | // Build the iteration variable and its initialization before loop. |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4024 | ExprResult IV; |
| 4025 | ExprResult Init; |
| 4026 | { |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4027 | VarDecl *IVDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.iv"); |
| 4028 | IV = buildDeclRefExpr(SemaRef, IVDecl, VType, InitLoc); |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 4029 | Expr *RHS = (isOpenMPWorksharingDirective(DKind) || |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 4030 | isOpenMPTaskLoopDirective(DKind) || |
| 4031 | isOpenMPDistributeDirective(DKind)) |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4032 | ? LB.get() |
| 4033 | : SemaRef.ActOnIntegerConstant(SourceLocation(), 0).get(); |
| 4034 | Init = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, IV.get(), RHS); |
| 4035 | Init = SemaRef.ActOnFinishFullExpr(Init.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4036 | } |
| 4037 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4038 | // Loop condition (IV < NumIterations) or (IV <= UB) for worksharing loops. |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4039 | SourceLocation CondLoc; |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4040 | ExprResult Cond = |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 4041 | (isOpenMPWorksharingDirective(DKind) || |
| 4042 | isOpenMPTaskLoopDirective(DKind) || isOpenMPDistributeDirective(DKind)) |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4043 | ? SemaRef.BuildBinOp(CurScope, CondLoc, BO_LE, IV.get(), UB.get()) |
| 4044 | : SemaRef.BuildBinOp(CurScope, CondLoc, BO_LT, IV.get(), |
| 4045 | NumIterations.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4046 | |
| 4047 | // Loop increment (IV = IV + 1) |
| 4048 | SourceLocation IncLoc; |
| 4049 | ExprResult Inc = |
| 4050 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, IV.get(), |
| 4051 | SemaRef.ActOnIntegerConstant(IncLoc, 1).get()); |
| 4052 | if (!Inc.isUsable()) |
| 4053 | return 0; |
| 4054 | Inc = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, IV.get(), Inc.get()); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4055 | Inc = SemaRef.ActOnFinishFullExpr(Inc.get()); |
| 4056 | if (!Inc.isUsable()) |
| 4057 | return 0; |
| 4058 | |
| 4059 | // Increments for worksharing loops (LB = LB + ST; UB = UB + ST). |
| 4060 | // Used for directives with static scheduling. |
| 4061 | ExprResult NextLB, NextUB; |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 4062 | if (isOpenMPWorksharingDirective(DKind) || isOpenMPTaskLoopDirective(DKind) || |
| 4063 | isOpenMPDistributeDirective(DKind)) { |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4064 | // LB + ST |
| 4065 | NextLB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, LB.get(), ST.get()); |
| 4066 | if (!NextLB.isUsable()) |
| 4067 | return 0; |
| 4068 | // LB = LB + ST |
| 4069 | NextLB = |
| 4070 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, LB.get(), NextLB.get()); |
| 4071 | NextLB = SemaRef.ActOnFinishFullExpr(NextLB.get()); |
| 4072 | if (!NextLB.isUsable()) |
| 4073 | return 0; |
| 4074 | // UB + ST |
| 4075 | NextUB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, UB.get(), ST.get()); |
| 4076 | if (!NextUB.isUsable()) |
| 4077 | return 0; |
| 4078 | // UB = UB + ST |
| 4079 | NextUB = |
| 4080 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, UB.get(), NextUB.get()); |
| 4081 | NextUB = SemaRef.ActOnFinishFullExpr(NextUB.get()); |
| 4082 | if (!NextUB.isUsable()) |
| 4083 | return 0; |
| 4084 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4085 | |
| 4086 | // Build updates and final values of the loop counters. |
| 4087 | bool HasErrors = false; |
| 4088 | Built.Counters.resize(NestedLoopCount); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4089 | Built.Inits.resize(NestedLoopCount); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4090 | Built.Updates.resize(NestedLoopCount); |
| 4091 | Built.Finals.resize(NestedLoopCount); |
| 4092 | { |
| 4093 | ExprResult Div; |
| 4094 | // Go from inner nested loop to outer. |
| 4095 | for (int Cnt = NestedLoopCount - 1; Cnt >= 0; --Cnt) { |
| 4096 | LoopIterationSpace &IS = IterSpaces[Cnt]; |
| 4097 | SourceLocation UpdLoc = IS.IncSrcRange.getBegin(); |
| 4098 | // Build: Iter = (IV / Div) % IS.NumIters |
| 4099 | // where Div is product of previous iterations' IS.NumIters. |
| 4100 | ExprResult Iter; |
| 4101 | if (Div.isUsable()) { |
| 4102 | Iter = |
| 4103 | SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Div, IV.get(), Div.get()); |
| 4104 | } else { |
| 4105 | Iter = IV; |
| 4106 | assert((Cnt == (int)NestedLoopCount - 1) && |
| 4107 | "unusable div expected on first iteration only"); |
| 4108 | } |
| 4109 | |
| 4110 | if (Cnt != 0 && Iter.isUsable()) |
| 4111 | Iter = SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Rem, Iter.get(), |
| 4112 | IS.NumIterations); |
| 4113 | if (!Iter.isUsable()) { |
| 4114 | HasErrors = true; |
| 4115 | break; |
| 4116 | } |
| 4117 | |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4118 | // Build update: IS.CounterVar(Private) = IS.Start + Iter * IS.Step |
| 4119 | auto *CounterVar = buildDeclRefExpr( |
| 4120 | SemaRef, cast<VarDecl>(cast<DeclRefExpr>(IS.CounterVar)->getDecl()), |
| 4121 | IS.CounterVar->getType(), IS.CounterVar->getExprLoc(), |
| 4122 | /*RefersToCapture=*/true); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4123 | ExprResult Init = BuildCounterInit(SemaRef, CurScope, UpdLoc, CounterVar, |
| 4124 | IS.CounterInit); |
| 4125 | if (!Init.isUsable()) { |
| 4126 | HasErrors = true; |
| 4127 | break; |
| 4128 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4129 | ExprResult Update = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4130 | BuildCounterUpdate(SemaRef, CurScope, UpdLoc, CounterVar, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4131 | IS.CounterInit, Iter, IS.CounterStep, IS.Subtract); |
| 4132 | if (!Update.isUsable()) { |
| 4133 | HasErrors = true; |
| 4134 | break; |
| 4135 | } |
| 4136 | |
| 4137 | // Build final: IS.CounterVar = IS.Start + IS.NumIters * IS.Step |
| 4138 | ExprResult Final = BuildCounterUpdate( |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4139 | SemaRef, CurScope, UpdLoc, CounterVar, IS.CounterInit, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4140 | IS.NumIterations, IS.CounterStep, IS.Subtract); |
| 4141 | if (!Final.isUsable()) { |
| 4142 | HasErrors = true; |
| 4143 | break; |
| 4144 | } |
| 4145 | |
| 4146 | // Build Div for the next iteration: Div <- Div * IS.NumIters |
| 4147 | if (Cnt != 0) { |
| 4148 | if (Div.isUnset()) |
| 4149 | Div = IS.NumIterations; |
| 4150 | else |
| 4151 | Div = SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Mul, Div.get(), |
| 4152 | IS.NumIterations); |
| 4153 | |
| 4154 | // Add parentheses (for debugging purposes only). |
| 4155 | if (Div.isUsable()) |
| 4156 | Div = SemaRef.ActOnParenExpr(UpdLoc, UpdLoc, Div.get()); |
| 4157 | if (!Div.isUsable()) { |
| 4158 | HasErrors = true; |
| 4159 | break; |
| 4160 | } |
| 4161 | } |
| 4162 | if (!Update.isUsable() || !Final.isUsable()) { |
| 4163 | HasErrors = true; |
| 4164 | break; |
| 4165 | } |
| 4166 | // Save results |
| 4167 | Built.Counters[Cnt] = IS.CounterVar; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 4168 | Built.PrivateCounters[Cnt] = IS.PrivateCounterVar; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4169 | Built.Inits[Cnt] = Init.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4170 | Built.Updates[Cnt] = Update.get(); |
| 4171 | Built.Finals[Cnt] = Final.get(); |
| 4172 | } |
| 4173 | } |
| 4174 | |
| 4175 | if (HasErrors) |
| 4176 | return 0; |
| 4177 | |
| 4178 | // Save results |
| 4179 | Built.IterationVarRef = IV.get(); |
| 4180 | Built.LastIteration = LastIteration.get(); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 4181 | Built.NumIterations = NumIterations.get(); |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 4182 | Built.CalcLastIteration = |
| 4183 | SemaRef.ActOnFinishFullExpr(CalcLastIteration.get()).get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4184 | Built.PreCond = PreCond.get(); |
| 4185 | Built.Cond = Cond.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4186 | Built.Init = Init.get(); |
| 4187 | Built.Inc = Inc.get(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4188 | Built.LB = LB.get(); |
| 4189 | Built.UB = UB.get(); |
| 4190 | Built.IL = IL.get(); |
| 4191 | Built.ST = ST.get(); |
| 4192 | Built.EUB = EUB.get(); |
| 4193 | Built.NLB = NextLB.get(); |
| 4194 | Built.NUB = NextUB.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4195 | |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 4196 | return NestedLoopCount; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4197 | } |
| 4198 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4199 | static Expr *getCollapseNumberExpr(ArrayRef<OMPClause *> Clauses) { |
Benjamin Kramer | fc600dc | 2015-08-30 15:12:28 +0000 | [diff] [blame] | 4200 | auto CollapseClauses = |
| 4201 | OMPExecutableDirective::getClausesOfKind<OMPCollapseClause>(Clauses); |
| 4202 | if (CollapseClauses.begin() != CollapseClauses.end()) |
| 4203 | return (*CollapseClauses.begin())->getNumForLoops(); |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 4204 | return nullptr; |
| 4205 | } |
| 4206 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4207 | static Expr *getOrderedNumberExpr(ArrayRef<OMPClause *> Clauses) { |
Benjamin Kramer | fc600dc | 2015-08-30 15:12:28 +0000 | [diff] [blame] | 4208 | auto OrderedClauses = |
| 4209 | OMPExecutableDirective::getClausesOfKind<OMPOrderedClause>(Clauses); |
| 4210 | if (OrderedClauses.begin() != OrderedClauses.end()) |
| 4211 | return (*OrderedClauses.begin())->getNumForLoops(); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4212 | return nullptr; |
| 4213 | } |
| 4214 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 4215 | static bool checkSimdlenSafelenValues(Sema &S, const Expr *Simdlen, |
| 4216 | const Expr *Safelen) { |
| 4217 | llvm::APSInt SimdlenRes, SafelenRes; |
| 4218 | if (Simdlen->isValueDependent() || Simdlen->isTypeDependent() || |
| 4219 | Simdlen->isInstantiationDependent() || |
| 4220 | Simdlen->containsUnexpandedParameterPack()) |
| 4221 | return false; |
| 4222 | if (Safelen->isValueDependent() || Safelen->isTypeDependent() || |
| 4223 | Safelen->isInstantiationDependent() || |
| 4224 | Safelen->containsUnexpandedParameterPack()) |
| 4225 | return false; |
| 4226 | Simdlen->EvaluateAsInt(SimdlenRes, S.Context); |
| 4227 | Safelen->EvaluateAsInt(SafelenRes, S.Context); |
| 4228 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 4229 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 4230 | // parameter must be less than or equal to the value of the safelen parameter. |
| 4231 | if (SimdlenRes > SafelenRes) { |
| 4232 | S.Diag(Simdlen->getExprLoc(), diag::err_omp_wrong_simdlen_safelen_values) |
| 4233 | << Simdlen->getSourceRange() << Safelen->getSourceRange(); |
| 4234 | return true; |
| 4235 | } |
| 4236 | return false; |
| 4237 | } |
| 4238 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4239 | StmtResult Sema::ActOnOpenMPSimdDirective( |
| 4240 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4241 | SourceLocation EndLoc, |
| 4242 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4243 | if (!AStmt) |
| 4244 | return StmtError(); |
| 4245 | |
| 4246 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4247 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4248 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4249 | // define the nested loops number. |
| 4250 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 4251 | OMPD_simd, getCollapseNumberExpr(Clauses), getOrderedNumberExpr(Clauses), |
| 4252 | AStmt, *this, *DSAStack, VarsWithImplicitDSA, B); |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 4253 | if (NestedLoopCount == 0) |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 4254 | return StmtError(); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 4255 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4256 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 4257 | "omp simd loop exprs were not built"); |
| 4258 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 4259 | if (!CurContext->isDependentContext()) { |
| 4260 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4261 | for (auto C : Clauses) { |
| 4262 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 4263 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 4264 | B.NumIterations, *this, CurScope)) |
| 4265 | return StmtError(); |
| 4266 | } |
| 4267 | } |
| 4268 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 4269 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 4270 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 4271 | // parameter must be less than or equal to the value of the safelen parameter. |
| 4272 | OMPSafelenClause *Safelen = nullptr; |
| 4273 | OMPSimdlenClause *Simdlen = nullptr; |
| 4274 | for (auto *Clause : Clauses) { |
| 4275 | if (Clause->getClauseKind() == OMPC_safelen) |
| 4276 | Safelen = cast<OMPSafelenClause>(Clause); |
| 4277 | else if (Clause->getClauseKind() == OMPC_simdlen) |
| 4278 | Simdlen = cast<OMPSimdlenClause>(Clause); |
| 4279 | if (Safelen && Simdlen) |
| 4280 | break; |
| 4281 | } |
| 4282 | if (Simdlen && Safelen && |
| 4283 | checkSimdlenSafelenValues(*this, Simdlen->getSimdlen(), |
| 4284 | Safelen->getSafelen())) |
| 4285 | return StmtError(); |
| 4286 | |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 4287 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4288 | return OMPSimdDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| 4289 | Clauses, AStmt, B); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 4290 | } |
| 4291 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4292 | StmtResult Sema::ActOnOpenMPForDirective( |
| 4293 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4294 | SourceLocation EndLoc, |
| 4295 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4296 | if (!AStmt) |
| 4297 | return StmtError(); |
| 4298 | |
| 4299 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4300 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4301 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4302 | // define the nested loops number. |
| 4303 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 4304 | OMPD_for, getCollapseNumberExpr(Clauses), getOrderedNumberExpr(Clauses), |
| 4305 | AStmt, *this, *DSAStack, VarsWithImplicitDSA, B); |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 4306 | if (NestedLoopCount == 0) |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4307 | return StmtError(); |
| 4308 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4309 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 4310 | "omp for loop exprs were not built"); |
| 4311 | |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 4312 | if (!CurContext->isDependentContext()) { |
| 4313 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4314 | for (auto C : Clauses) { |
| 4315 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 4316 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 4317 | B.NumIterations, *this, CurScope)) |
| 4318 | return StmtError(); |
| 4319 | } |
| 4320 | } |
| 4321 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4322 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4323 | return OMPForDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4324 | Clauses, AStmt, B, DSAStack->isCancelRegion()); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4325 | } |
| 4326 | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4327 | StmtResult Sema::ActOnOpenMPForSimdDirective( |
| 4328 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4329 | SourceLocation EndLoc, |
| 4330 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4331 | if (!AStmt) |
| 4332 | return StmtError(); |
| 4333 | |
| 4334 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4335 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4336 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4337 | // define the nested loops number. |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4338 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4339 | CheckOpenMPLoop(OMPD_for_simd, getCollapseNumberExpr(Clauses), |
| 4340 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 4341 | VarsWithImplicitDSA, B); |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4342 | if (NestedLoopCount == 0) |
| 4343 | return StmtError(); |
| 4344 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4345 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 4346 | "omp for simd loop exprs were not built"); |
| 4347 | |
Alexey Bataev | 58e5bdb | 2015-06-18 04:45:29 +0000 | [diff] [blame] | 4348 | if (!CurContext->isDependentContext()) { |
| 4349 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4350 | for (auto C : Clauses) { |
| 4351 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 4352 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 4353 | B.NumIterations, *this, CurScope)) |
| 4354 | return StmtError(); |
| 4355 | } |
| 4356 | } |
| 4357 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 4358 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 4359 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 4360 | // parameter must be less than or equal to the value of the safelen parameter. |
| 4361 | OMPSafelenClause *Safelen = nullptr; |
| 4362 | OMPSimdlenClause *Simdlen = nullptr; |
| 4363 | for (auto *Clause : Clauses) { |
| 4364 | if (Clause->getClauseKind() == OMPC_safelen) |
| 4365 | Safelen = cast<OMPSafelenClause>(Clause); |
| 4366 | else if (Clause->getClauseKind() == OMPC_simdlen) |
| 4367 | Simdlen = cast<OMPSimdlenClause>(Clause); |
| 4368 | if (Safelen && Simdlen) |
| 4369 | break; |
| 4370 | } |
| 4371 | if (Simdlen && Safelen && |
| 4372 | checkSimdlenSafelenValues(*this, Simdlen->getSimdlen(), |
| 4373 | Safelen->getSafelen())) |
| 4374 | return StmtError(); |
| 4375 | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4376 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4377 | return OMPForSimdDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| 4378 | Clauses, AStmt, B); |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4379 | } |
| 4380 | |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4381 | StmtResult Sema::ActOnOpenMPSectionsDirective(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 | |
| 4388 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4389 | auto BaseStmt = AStmt; |
| 4390 | while (CapturedStmt *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt)) |
| 4391 | BaseStmt = CS->getCapturedStmt(); |
| 4392 | if (auto C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) { |
| 4393 | auto S = C->children(); |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 4394 | if (S.begin() == S.end()) |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4395 | return StmtError(); |
| 4396 | // All associated statements must be '#pragma omp section' except for |
| 4397 | // the first one. |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 4398 | for (Stmt *SectionStmt : llvm::make_range(std::next(S.begin()), S.end())) { |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4399 | if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) { |
| 4400 | if (SectionStmt) |
| 4401 | Diag(SectionStmt->getLocStart(), |
| 4402 | diag::err_omp_sections_substmt_not_section); |
| 4403 | return StmtError(); |
| 4404 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4405 | cast<OMPSectionDirective>(SectionStmt) |
| 4406 | ->setHasCancel(DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4407 | } |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4408 | } else { |
| 4409 | Diag(AStmt->getLocStart(), diag::err_omp_sections_not_compound_stmt); |
| 4410 | return StmtError(); |
| 4411 | } |
| 4412 | |
| 4413 | getCurFunction()->setHasBranchProtectedScope(); |
| 4414 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4415 | return OMPSectionsDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 4416 | DSAStack->isCancelRegion()); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4417 | } |
| 4418 | |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4419 | StmtResult Sema::ActOnOpenMPSectionDirective(Stmt *AStmt, |
| 4420 | SourceLocation StartLoc, |
| 4421 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4422 | if (!AStmt) |
| 4423 | return StmtError(); |
| 4424 | |
| 4425 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4426 | |
| 4427 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4428 | DSAStack->setParentCancelRegion(DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4429 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4430 | return OMPSectionDirective::Create(Context, StartLoc, EndLoc, AStmt, |
| 4431 | DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4432 | } |
| 4433 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 4434 | StmtResult Sema::ActOnOpenMPSingleDirective(ArrayRef<OMPClause *> Clauses, |
| 4435 | Stmt *AStmt, |
| 4436 | SourceLocation StartLoc, |
| 4437 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4438 | if (!AStmt) |
| 4439 | return StmtError(); |
| 4440 | |
| 4441 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 74a05c9 | 2014-07-15 02:55:09 +0000 | [diff] [blame] | 4442 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 4443 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | 74a05c9 | 2014-07-15 02:55:09 +0000 | [diff] [blame] | 4444 | |
Alexey Bataev | 3255bf3 | 2015-01-19 05:20:46 +0000 | [diff] [blame] | 4445 | // OpenMP [2.7.3, single Construct, Restrictions] |
| 4446 | // The copyprivate clause must not be used with the nowait clause. |
| 4447 | OMPClause *Nowait = nullptr; |
| 4448 | OMPClause *Copyprivate = nullptr; |
| 4449 | for (auto *Clause : Clauses) { |
| 4450 | if (Clause->getClauseKind() == OMPC_nowait) |
| 4451 | Nowait = Clause; |
| 4452 | else if (Clause->getClauseKind() == OMPC_copyprivate) |
| 4453 | Copyprivate = Clause; |
| 4454 | if (Copyprivate && Nowait) { |
| 4455 | Diag(Copyprivate->getLocStart(), |
| 4456 | diag::err_omp_single_copyprivate_with_nowait); |
| 4457 | Diag(Nowait->getLocStart(), diag::note_omp_nowait_clause_here); |
| 4458 | return StmtError(); |
| 4459 | } |
| 4460 | } |
| 4461 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 4462 | return OMPSingleDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 4463 | } |
| 4464 | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 4465 | StmtResult Sema::ActOnOpenMPMasterDirective(Stmt *AStmt, |
| 4466 | SourceLocation StartLoc, |
| 4467 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4468 | if (!AStmt) |
| 4469 | return StmtError(); |
| 4470 | |
| 4471 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 4472 | |
| 4473 | getCurFunction()->setHasBranchProtectedScope(); |
| 4474 | |
| 4475 | return OMPMasterDirective::Create(Context, StartLoc, EndLoc, AStmt); |
| 4476 | } |
| 4477 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 4478 | StmtResult Sema::ActOnOpenMPCriticalDirective( |
| 4479 | const DeclarationNameInfo &DirName, ArrayRef<OMPClause *> Clauses, |
| 4480 | Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4481 | if (!AStmt) |
| 4482 | return StmtError(); |
| 4483 | |
| 4484 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 4485 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 4486 | bool ErrorFound = false; |
| 4487 | llvm::APSInt Hint; |
| 4488 | SourceLocation HintLoc; |
| 4489 | bool DependentHint = false; |
| 4490 | for (auto *C : Clauses) { |
| 4491 | if (C->getClauseKind() == OMPC_hint) { |
| 4492 | if (!DirName.getName()) { |
| 4493 | Diag(C->getLocStart(), diag::err_omp_hint_clause_no_name); |
| 4494 | ErrorFound = true; |
| 4495 | } |
| 4496 | Expr *E = cast<OMPHintClause>(C)->getHint(); |
| 4497 | if (E->isTypeDependent() || E->isValueDependent() || |
| 4498 | E->isInstantiationDependent()) |
| 4499 | DependentHint = true; |
| 4500 | else { |
| 4501 | Hint = E->EvaluateKnownConstInt(Context); |
| 4502 | HintLoc = C->getLocStart(); |
| 4503 | } |
| 4504 | } |
| 4505 | } |
| 4506 | if (ErrorFound) |
| 4507 | return StmtError(); |
| 4508 | auto Pair = DSAStack->getCriticalWithHint(DirName); |
| 4509 | if (Pair.first && DirName.getName() && !DependentHint) { |
| 4510 | if (llvm::APSInt::compareValues(Hint, Pair.second) != 0) { |
| 4511 | Diag(StartLoc, diag::err_omp_critical_with_hint); |
| 4512 | if (HintLoc.isValid()) { |
| 4513 | Diag(HintLoc, diag::note_omp_critical_hint_here) |
| 4514 | << 0 << Hint.toString(/*Radix=*/10, /*Signed=*/false); |
| 4515 | } else |
| 4516 | Diag(StartLoc, diag::note_omp_critical_no_hint) << 0; |
| 4517 | if (auto *C = Pair.first->getSingleClause<OMPHintClause>()) { |
| 4518 | Diag(C->getLocStart(), diag::note_omp_critical_hint_here) |
| 4519 | << 1 |
| 4520 | << C->getHint()->EvaluateKnownConstInt(Context).toString( |
| 4521 | /*Radix=*/10, /*Signed=*/false); |
| 4522 | } else |
| 4523 | Diag(Pair.first->getLocStart(), diag::note_omp_critical_no_hint) << 1; |
| 4524 | } |
| 4525 | } |
| 4526 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 4527 | getCurFunction()->setHasBranchProtectedScope(); |
| 4528 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 4529 | auto *Dir = OMPCriticalDirective::Create(Context, DirName, StartLoc, EndLoc, |
| 4530 | Clauses, AStmt); |
| 4531 | if (!Pair.first && DirName.getName() && !DependentHint) |
| 4532 | DSAStack->addCriticalWithHint(Dir, Hint); |
| 4533 | return Dir; |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 4534 | } |
| 4535 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4536 | StmtResult Sema::ActOnOpenMPParallelForDirective( |
| 4537 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4538 | SourceLocation EndLoc, |
| 4539 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4540 | if (!AStmt) |
| 4541 | return StmtError(); |
| 4542 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4543 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 4544 | // 1.2.2 OpenMP Language Terminology |
| 4545 | // Structured block - An executable statement with a single entry at the |
| 4546 | // top and a single exit at the bottom. |
| 4547 | // The point of exit cannot be a branch out of the structured block. |
| 4548 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 4549 | CS->getCapturedDecl()->setNothrow(); |
| 4550 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4551 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4552 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4553 | // define the nested loops number. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4554 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4555 | CheckOpenMPLoop(OMPD_parallel_for, getCollapseNumberExpr(Clauses), |
| 4556 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 4557 | VarsWithImplicitDSA, B); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4558 | if (NestedLoopCount == 0) |
| 4559 | return StmtError(); |
| 4560 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4561 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 4562 | "omp parallel for loop exprs were not built"); |
| 4563 | |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 4564 | if (!CurContext->isDependentContext()) { |
| 4565 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4566 | for (auto C : Clauses) { |
| 4567 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 4568 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 4569 | B.NumIterations, *this, CurScope)) |
| 4570 | return StmtError(); |
| 4571 | } |
| 4572 | } |
| 4573 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4574 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4575 | return OMPParallelForDirective::Create(Context, StartLoc, EndLoc, |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4576 | NestedLoopCount, Clauses, AStmt, B, |
| 4577 | DSAStack->isCancelRegion()); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4578 | } |
| 4579 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4580 | StmtResult Sema::ActOnOpenMPParallelForSimdDirective( |
| 4581 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4582 | SourceLocation EndLoc, |
| 4583 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4584 | if (!AStmt) |
| 4585 | return StmtError(); |
| 4586 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4587 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 4588 | // 1.2.2 OpenMP Language Terminology |
| 4589 | // Structured block - An executable statement with a single entry at the |
| 4590 | // top and a single exit at the bottom. |
| 4591 | // The point of exit cannot be a branch out of the structured block. |
| 4592 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 4593 | CS->getCapturedDecl()->setNothrow(); |
| 4594 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4595 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4596 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4597 | // define the nested loops number. |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4598 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4599 | CheckOpenMPLoop(OMPD_parallel_for_simd, getCollapseNumberExpr(Clauses), |
| 4600 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 4601 | VarsWithImplicitDSA, B); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4602 | if (NestedLoopCount == 0) |
| 4603 | return StmtError(); |
| 4604 | |
Alexey Bataev | 3b5b5c4 | 2015-06-18 10:10:12 +0000 | [diff] [blame] | 4605 | if (!CurContext->isDependentContext()) { |
| 4606 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4607 | for (auto C : Clauses) { |
| 4608 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 4609 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 4610 | B.NumIterations, *this, CurScope)) |
| 4611 | return StmtError(); |
| 4612 | } |
| 4613 | } |
| 4614 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 4615 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 4616 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 4617 | // parameter must be less than or equal to the value of the safelen parameter. |
| 4618 | OMPSafelenClause *Safelen = nullptr; |
| 4619 | OMPSimdlenClause *Simdlen = nullptr; |
| 4620 | for (auto *Clause : Clauses) { |
| 4621 | if (Clause->getClauseKind() == OMPC_safelen) |
| 4622 | Safelen = cast<OMPSafelenClause>(Clause); |
| 4623 | else if (Clause->getClauseKind() == OMPC_simdlen) |
| 4624 | Simdlen = cast<OMPSimdlenClause>(Clause); |
| 4625 | if (Safelen && Simdlen) |
| 4626 | break; |
| 4627 | } |
| 4628 | if (Simdlen && Safelen && |
| 4629 | checkSimdlenSafelenValues(*this, Simdlen->getSimdlen(), |
| 4630 | Safelen->getSafelen())) |
| 4631 | return StmtError(); |
| 4632 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4633 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4634 | return OMPParallelForSimdDirective::Create( |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4635 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4636 | } |
| 4637 | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4638 | StmtResult |
| 4639 | Sema::ActOnOpenMPParallelSectionsDirective(ArrayRef<OMPClause *> Clauses, |
| 4640 | Stmt *AStmt, SourceLocation StartLoc, |
| 4641 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4642 | if (!AStmt) |
| 4643 | return StmtError(); |
| 4644 | |
| 4645 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4646 | auto BaseStmt = AStmt; |
| 4647 | while (CapturedStmt *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt)) |
| 4648 | BaseStmt = CS->getCapturedStmt(); |
| 4649 | if (auto C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) { |
| 4650 | auto S = C->children(); |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 4651 | if (S.begin() == S.end()) |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4652 | return StmtError(); |
| 4653 | // All associated statements must be '#pragma omp section' except for |
| 4654 | // the first one. |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 4655 | for (Stmt *SectionStmt : llvm::make_range(std::next(S.begin()), S.end())) { |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4656 | if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) { |
| 4657 | if (SectionStmt) |
| 4658 | Diag(SectionStmt->getLocStart(), |
| 4659 | diag::err_omp_parallel_sections_substmt_not_section); |
| 4660 | return StmtError(); |
| 4661 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4662 | cast<OMPSectionDirective>(SectionStmt) |
| 4663 | ->setHasCancel(DSAStack->isCancelRegion()); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4664 | } |
| 4665 | } else { |
| 4666 | Diag(AStmt->getLocStart(), |
| 4667 | diag::err_omp_parallel_sections_not_compound_stmt); |
| 4668 | return StmtError(); |
| 4669 | } |
| 4670 | |
| 4671 | getCurFunction()->setHasBranchProtectedScope(); |
| 4672 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4673 | return OMPParallelSectionsDirective::Create( |
| 4674 | Context, StartLoc, EndLoc, Clauses, AStmt, DSAStack->isCancelRegion()); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4675 | } |
| 4676 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 4677 | StmtResult Sema::ActOnOpenMPTaskDirective(ArrayRef<OMPClause *> Clauses, |
| 4678 | Stmt *AStmt, SourceLocation StartLoc, |
| 4679 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4680 | if (!AStmt) |
| 4681 | return StmtError(); |
| 4682 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 4683 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 4684 | // 1.2.2 OpenMP Language Terminology |
| 4685 | // Structured block - An executable statement with a single entry at the |
| 4686 | // top and a single exit at the bottom. |
| 4687 | // The point of exit cannot be a branch out of the structured block. |
| 4688 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 4689 | CS->getCapturedDecl()->setNothrow(); |
| 4690 | |
| 4691 | getCurFunction()->setHasBranchProtectedScope(); |
| 4692 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4693 | return OMPTaskDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 4694 | DSAStack->isCancelRegion()); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 4695 | } |
| 4696 | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 4697 | StmtResult Sema::ActOnOpenMPTaskyieldDirective(SourceLocation StartLoc, |
| 4698 | SourceLocation EndLoc) { |
| 4699 | return OMPTaskyieldDirective::Create(Context, StartLoc, EndLoc); |
| 4700 | } |
| 4701 | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 4702 | StmtResult Sema::ActOnOpenMPBarrierDirective(SourceLocation StartLoc, |
| 4703 | SourceLocation EndLoc) { |
| 4704 | return OMPBarrierDirective::Create(Context, StartLoc, EndLoc); |
| 4705 | } |
| 4706 | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 4707 | StmtResult Sema::ActOnOpenMPTaskwaitDirective(SourceLocation StartLoc, |
| 4708 | SourceLocation EndLoc) { |
| 4709 | return OMPTaskwaitDirective::Create(Context, StartLoc, EndLoc); |
| 4710 | } |
| 4711 | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 4712 | StmtResult Sema::ActOnOpenMPTaskgroupDirective(Stmt *AStmt, |
| 4713 | SourceLocation StartLoc, |
| 4714 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4715 | if (!AStmt) |
| 4716 | return StmtError(); |
| 4717 | |
| 4718 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 4719 | |
| 4720 | getCurFunction()->setHasBranchProtectedScope(); |
| 4721 | |
| 4722 | return OMPTaskgroupDirective::Create(Context, StartLoc, EndLoc, AStmt); |
| 4723 | } |
| 4724 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 4725 | StmtResult Sema::ActOnOpenMPFlushDirective(ArrayRef<OMPClause *> Clauses, |
| 4726 | SourceLocation StartLoc, |
| 4727 | SourceLocation EndLoc) { |
| 4728 | assert(Clauses.size() <= 1 && "Extra clauses in flush directive"); |
| 4729 | return OMPFlushDirective::Create(Context, StartLoc, EndLoc, Clauses); |
| 4730 | } |
| 4731 | |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 4732 | StmtResult Sema::ActOnOpenMPOrderedDirective(ArrayRef<OMPClause *> Clauses, |
| 4733 | Stmt *AStmt, |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 4734 | SourceLocation StartLoc, |
| 4735 | SourceLocation EndLoc) { |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 4736 | OMPClause *DependFound = nullptr; |
| 4737 | OMPClause *DependSourceClause = nullptr; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 4738 | OMPClause *DependSinkClause = nullptr; |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 4739 | bool ErrorFound = false; |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 4740 | OMPThreadsClause *TC = nullptr; |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 4741 | OMPSIMDClause *SC = nullptr; |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 4742 | for (auto *C : Clauses) { |
| 4743 | if (auto *DC = dyn_cast<OMPDependClause>(C)) { |
| 4744 | DependFound = C; |
| 4745 | if (DC->getDependencyKind() == OMPC_DEPEND_source) { |
| 4746 | if (DependSourceClause) { |
| 4747 | Diag(C->getLocStart(), diag::err_omp_more_one_clause) |
| 4748 | << getOpenMPDirectiveName(OMPD_ordered) |
| 4749 | << getOpenMPClauseName(OMPC_depend) << 2; |
| 4750 | ErrorFound = true; |
| 4751 | } else |
| 4752 | DependSourceClause = C; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 4753 | if (DependSinkClause) { |
| 4754 | Diag(C->getLocStart(), diag::err_omp_depend_sink_source_not_allowed) |
| 4755 | << 0; |
| 4756 | ErrorFound = true; |
| 4757 | } |
| 4758 | } else if (DC->getDependencyKind() == OMPC_DEPEND_sink) { |
| 4759 | if (DependSourceClause) { |
| 4760 | Diag(C->getLocStart(), diag::err_omp_depend_sink_source_not_allowed) |
| 4761 | << 1; |
| 4762 | ErrorFound = true; |
| 4763 | } |
| 4764 | DependSinkClause = C; |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 4765 | } |
| 4766 | } else if (C->getClauseKind() == OMPC_threads) |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 4767 | TC = cast<OMPThreadsClause>(C); |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 4768 | else if (C->getClauseKind() == OMPC_simd) |
| 4769 | SC = cast<OMPSIMDClause>(C); |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 4770 | } |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 4771 | if (!ErrorFound && !SC && |
| 4772 | isOpenMPSimdDirective(DSAStack->getParentDirective())) { |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 4773 | // OpenMP [2.8.1,simd Construct, Restrictions] |
| 4774 | // An ordered construct with the simd clause is the only OpenMP construct |
| 4775 | // that can appear in the simd region. |
| 4776 | Diag(StartLoc, diag::err_omp_prohibited_region_simd); |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 4777 | ErrorFound = true; |
| 4778 | } else if (DependFound && (TC || SC)) { |
| 4779 | Diag(DependFound->getLocStart(), diag::err_omp_depend_clause_thread_simd) |
| 4780 | << getOpenMPClauseName(TC ? TC->getClauseKind() : SC->getClauseKind()); |
| 4781 | ErrorFound = true; |
| 4782 | } else if (DependFound && !DSAStack->getParentOrderedRegionParam()) { |
| 4783 | Diag(DependFound->getLocStart(), |
| 4784 | diag::err_omp_ordered_directive_without_param); |
| 4785 | ErrorFound = true; |
| 4786 | } else if (TC || Clauses.empty()) { |
| 4787 | if (auto *Param = DSAStack->getParentOrderedRegionParam()) { |
| 4788 | SourceLocation ErrLoc = TC ? TC->getLocStart() : StartLoc; |
| 4789 | Diag(ErrLoc, diag::err_omp_ordered_directive_with_param) |
| 4790 | << (TC != nullptr); |
| 4791 | Diag(Param->getLocStart(), diag::note_omp_ordered_param); |
| 4792 | ErrorFound = true; |
| 4793 | } |
| 4794 | } |
| 4795 | if ((!AStmt && !DependFound) || ErrorFound) |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 4796 | return StmtError(); |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 4797 | |
| 4798 | if (AStmt) { |
| 4799 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 4800 | |
| 4801 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 4802 | } |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 4803 | |
| 4804 | return OMPOrderedDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 4805 | } |
| 4806 | |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4807 | namespace { |
| 4808 | /// \brief Helper class for checking expression in 'omp atomic [update]' |
| 4809 | /// construct. |
| 4810 | class OpenMPAtomicUpdateChecker { |
| 4811 | /// \brief Error results for atomic update expressions. |
| 4812 | enum ExprAnalysisErrorCode { |
| 4813 | /// \brief A statement is not an expression statement. |
| 4814 | NotAnExpression, |
| 4815 | /// \brief Expression is not builtin binary or unary operation. |
| 4816 | NotABinaryOrUnaryExpression, |
| 4817 | /// \brief Unary operation is not post-/pre- increment/decrement operation. |
| 4818 | NotAnUnaryIncDecExpression, |
| 4819 | /// \brief An expression is not of scalar type. |
| 4820 | NotAScalarType, |
| 4821 | /// \brief A binary operation is not an assignment operation. |
| 4822 | NotAnAssignmentOp, |
| 4823 | /// \brief RHS part of the binary operation is not a binary expression. |
| 4824 | NotABinaryExpression, |
| 4825 | /// \brief RHS part is not additive/multiplicative/shift/biwise binary |
| 4826 | /// expression. |
| 4827 | NotABinaryOperator, |
| 4828 | /// \brief RHS binary operation does not have reference to the updated LHS |
| 4829 | /// part. |
| 4830 | NotAnUpdateExpression, |
| 4831 | /// \brief No errors is found. |
| 4832 | NoError |
| 4833 | }; |
| 4834 | /// \brief Reference to Sema. |
| 4835 | Sema &SemaRef; |
| 4836 | /// \brief A location for note diagnostics (when error is found). |
| 4837 | SourceLocation NoteLoc; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4838 | /// \brief 'x' lvalue part of the source atomic expression. |
| 4839 | Expr *X; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4840 | /// \brief 'expr' rvalue part of the source atomic expression. |
| 4841 | Expr *E; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4842 | /// \brief Helper expression of the form |
| 4843 | /// 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or |
| 4844 | /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'. |
| 4845 | Expr *UpdateExpr; |
| 4846 | /// \brief Is 'x' a LHS in a RHS part of full update expression. It is |
| 4847 | /// important for non-associative operations. |
| 4848 | bool IsXLHSInRHSPart; |
| 4849 | BinaryOperatorKind Op; |
| 4850 | SourceLocation OpLoc; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4851 | /// \brief true if the source expression is a postfix unary operation, false |
| 4852 | /// if it is a prefix unary operation. |
| 4853 | bool IsPostfixUpdate; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4854 | |
| 4855 | public: |
| 4856 | OpenMPAtomicUpdateChecker(Sema &SemaRef) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4857 | : SemaRef(SemaRef), X(nullptr), E(nullptr), UpdateExpr(nullptr), |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4858 | IsXLHSInRHSPart(false), Op(BO_PtrMemD), IsPostfixUpdate(false) {} |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4859 | /// \brief Check specified statement that it is suitable for 'atomic update' |
| 4860 | /// constructs and extract 'x', 'expr' and Operation from the original |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4861 | /// expression. If DiagId and NoteId == 0, then only check is performed |
| 4862 | /// without error notification. |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4863 | /// \param DiagId Diagnostic which should be emitted if error is found. |
| 4864 | /// \param NoteId Diagnostic note for the main error message. |
| 4865 | /// \return true if statement is not an update expression, false otherwise. |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4866 | bool checkStatement(Stmt *S, unsigned DiagId = 0, unsigned NoteId = 0); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4867 | /// \brief Return the 'x' lvalue part of the source atomic expression. |
| 4868 | Expr *getX() const { return X; } |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4869 | /// \brief Return the 'expr' rvalue part of the source atomic expression. |
| 4870 | Expr *getExpr() const { return E; } |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4871 | /// \brief Return the update expression used in calculation of the updated |
| 4872 | /// value. Always has form 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or |
| 4873 | /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'. |
| 4874 | Expr *getUpdateExpr() const { return UpdateExpr; } |
| 4875 | /// \brief Return true if 'x' is LHS in RHS part of full update expression, |
| 4876 | /// false otherwise. |
| 4877 | bool isXLHSInRHSPart() const { return IsXLHSInRHSPart; } |
| 4878 | |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4879 | /// \brief true if the source expression is a postfix unary operation, false |
| 4880 | /// if it is a prefix unary operation. |
| 4881 | bool isPostfixUpdate() const { return IsPostfixUpdate; } |
| 4882 | |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4883 | private: |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4884 | bool checkBinaryOperation(BinaryOperator *AtomicBinOp, unsigned DiagId = 0, |
| 4885 | unsigned NoteId = 0); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4886 | }; |
| 4887 | } // namespace |
| 4888 | |
| 4889 | bool OpenMPAtomicUpdateChecker::checkBinaryOperation( |
| 4890 | BinaryOperator *AtomicBinOp, unsigned DiagId, unsigned NoteId) { |
| 4891 | ExprAnalysisErrorCode ErrorFound = NoError; |
| 4892 | SourceLocation ErrorLoc, NoteLoc; |
| 4893 | SourceRange ErrorRange, NoteRange; |
| 4894 | // Allowed constructs are: |
| 4895 | // x = x binop expr; |
| 4896 | // x = expr binop x; |
| 4897 | if (AtomicBinOp->getOpcode() == BO_Assign) { |
| 4898 | X = AtomicBinOp->getLHS(); |
| 4899 | if (auto *AtomicInnerBinOp = dyn_cast<BinaryOperator>( |
| 4900 | AtomicBinOp->getRHS()->IgnoreParenImpCasts())) { |
| 4901 | if (AtomicInnerBinOp->isMultiplicativeOp() || |
| 4902 | AtomicInnerBinOp->isAdditiveOp() || AtomicInnerBinOp->isShiftOp() || |
| 4903 | AtomicInnerBinOp->isBitwiseOp()) { |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4904 | Op = AtomicInnerBinOp->getOpcode(); |
| 4905 | OpLoc = AtomicInnerBinOp->getOperatorLoc(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4906 | auto *LHS = AtomicInnerBinOp->getLHS(); |
| 4907 | auto *RHS = AtomicInnerBinOp->getRHS(); |
| 4908 | llvm::FoldingSetNodeID XId, LHSId, RHSId; |
| 4909 | X->IgnoreParenImpCasts()->Profile(XId, SemaRef.getASTContext(), |
| 4910 | /*Canonical=*/true); |
| 4911 | LHS->IgnoreParenImpCasts()->Profile(LHSId, SemaRef.getASTContext(), |
| 4912 | /*Canonical=*/true); |
| 4913 | RHS->IgnoreParenImpCasts()->Profile(RHSId, SemaRef.getASTContext(), |
| 4914 | /*Canonical=*/true); |
| 4915 | if (XId == LHSId) { |
| 4916 | E = RHS; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4917 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4918 | } else if (XId == RHSId) { |
| 4919 | E = LHS; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4920 | IsXLHSInRHSPart = false; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4921 | } else { |
| 4922 | ErrorLoc = AtomicInnerBinOp->getExprLoc(); |
| 4923 | ErrorRange = AtomicInnerBinOp->getSourceRange(); |
| 4924 | NoteLoc = X->getExprLoc(); |
| 4925 | NoteRange = X->getSourceRange(); |
| 4926 | ErrorFound = NotAnUpdateExpression; |
| 4927 | } |
| 4928 | } else { |
| 4929 | ErrorLoc = AtomicInnerBinOp->getExprLoc(); |
| 4930 | ErrorRange = AtomicInnerBinOp->getSourceRange(); |
| 4931 | NoteLoc = AtomicInnerBinOp->getOperatorLoc(); |
| 4932 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 4933 | ErrorFound = NotABinaryOperator; |
| 4934 | } |
| 4935 | } else { |
| 4936 | NoteLoc = ErrorLoc = AtomicBinOp->getRHS()->getExprLoc(); |
| 4937 | NoteRange = ErrorRange = AtomicBinOp->getRHS()->getSourceRange(); |
| 4938 | ErrorFound = NotABinaryExpression; |
| 4939 | } |
| 4940 | } else { |
| 4941 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 4942 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 4943 | NoteLoc = AtomicBinOp->getOperatorLoc(); |
| 4944 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 4945 | ErrorFound = NotAnAssignmentOp; |
| 4946 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4947 | if (ErrorFound != NoError && DiagId != 0 && NoteId != 0) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4948 | SemaRef.Diag(ErrorLoc, DiagId) << ErrorRange; |
| 4949 | SemaRef.Diag(NoteLoc, NoteId) << ErrorFound << NoteRange; |
| 4950 | return true; |
| 4951 | } else if (SemaRef.CurContext->isDependentContext()) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4952 | E = X = UpdateExpr = nullptr; |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 4953 | return ErrorFound != NoError; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4954 | } |
| 4955 | |
| 4956 | bool OpenMPAtomicUpdateChecker::checkStatement(Stmt *S, unsigned DiagId, |
| 4957 | unsigned NoteId) { |
| 4958 | ExprAnalysisErrorCode ErrorFound = NoError; |
| 4959 | SourceLocation ErrorLoc, NoteLoc; |
| 4960 | SourceRange ErrorRange, NoteRange; |
| 4961 | // Allowed constructs are: |
| 4962 | // x++; |
| 4963 | // x--; |
| 4964 | // ++x; |
| 4965 | // --x; |
| 4966 | // x binop= expr; |
| 4967 | // x = x binop expr; |
| 4968 | // x = expr binop x; |
| 4969 | if (auto *AtomicBody = dyn_cast<Expr>(S)) { |
| 4970 | AtomicBody = AtomicBody->IgnoreParenImpCasts(); |
| 4971 | if (AtomicBody->getType()->isScalarType() || |
| 4972 | AtomicBody->isInstantiationDependent()) { |
| 4973 | if (auto *AtomicCompAssignOp = dyn_cast<CompoundAssignOperator>( |
| 4974 | AtomicBody->IgnoreParenImpCasts())) { |
| 4975 | // Check for Compound Assignment Operation |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4976 | Op = BinaryOperator::getOpForCompoundAssignment( |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4977 | AtomicCompAssignOp->getOpcode()); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4978 | OpLoc = AtomicCompAssignOp->getOperatorLoc(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4979 | E = AtomicCompAssignOp->getRHS(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4980 | X = AtomicCompAssignOp->getLHS(); |
| 4981 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4982 | } else if (auto *AtomicBinOp = dyn_cast<BinaryOperator>( |
| 4983 | AtomicBody->IgnoreParenImpCasts())) { |
| 4984 | // Check for Binary Operation |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4985 | if(checkBinaryOperation(AtomicBinOp, DiagId, NoteId)) |
| 4986 | return true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4987 | } else if (auto *AtomicUnaryOp = |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4988 | dyn_cast<UnaryOperator>(AtomicBody->IgnoreParenImpCasts())) { |
| 4989 | // Check for Unary Operation |
| 4990 | if (AtomicUnaryOp->isIncrementDecrementOp()) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4991 | IsPostfixUpdate = AtomicUnaryOp->isPostfix(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4992 | Op = AtomicUnaryOp->isIncrementOp() ? BO_Add : BO_Sub; |
| 4993 | OpLoc = AtomicUnaryOp->getOperatorLoc(); |
| 4994 | X = AtomicUnaryOp->getSubExpr(); |
| 4995 | E = SemaRef.ActOnIntegerConstant(OpLoc, /*uint64_t Val=*/1).get(); |
| 4996 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4997 | } else { |
| 4998 | ErrorFound = NotAnUnaryIncDecExpression; |
| 4999 | ErrorLoc = AtomicUnaryOp->getExprLoc(); |
| 5000 | ErrorRange = AtomicUnaryOp->getSourceRange(); |
| 5001 | NoteLoc = AtomicUnaryOp->getOperatorLoc(); |
| 5002 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 5003 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5004 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5005 | ErrorFound = NotABinaryOrUnaryExpression; |
| 5006 | NoteLoc = ErrorLoc = AtomicBody->getExprLoc(); |
| 5007 | NoteRange = ErrorRange = AtomicBody->getSourceRange(); |
| 5008 | } |
| 5009 | } else { |
| 5010 | ErrorFound = NotAScalarType; |
| 5011 | NoteLoc = ErrorLoc = AtomicBody->getLocStart(); |
| 5012 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
| 5013 | } |
| 5014 | } else { |
| 5015 | ErrorFound = NotAnExpression; |
| 5016 | NoteLoc = ErrorLoc = S->getLocStart(); |
| 5017 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
| 5018 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5019 | if (ErrorFound != NoError && DiagId != 0 && NoteId != 0) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5020 | SemaRef.Diag(ErrorLoc, DiagId) << ErrorRange; |
| 5021 | SemaRef.Diag(NoteLoc, NoteId) << ErrorFound << NoteRange; |
| 5022 | return true; |
| 5023 | } else if (SemaRef.CurContext->isDependentContext()) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5024 | E = X = UpdateExpr = nullptr; |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5025 | if (ErrorFound == NoError && E && X) { |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5026 | // Build an update expression of form 'OpaqueValueExpr(x) binop |
| 5027 | // OpaqueValueExpr(expr)' or 'OpaqueValueExpr(expr) binop |
| 5028 | // OpaqueValueExpr(x)' and then cast it to the type of the 'x' expression. |
| 5029 | auto *OVEX = new (SemaRef.getASTContext()) |
| 5030 | OpaqueValueExpr(X->getExprLoc(), X->getType(), VK_RValue); |
| 5031 | auto *OVEExpr = new (SemaRef.getASTContext()) |
| 5032 | OpaqueValueExpr(E->getExprLoc(), E->getType(), VK_RValue); |
| 5033 | auto Update = |
| 5034 | SemaRef.CreateBuiltinBinOp(OpLoc, Op, IsXLHSInRHSPart ? OVEX : OVEExpr, |
| 5035 | IsXLHSInRHSPart ? OVEExpr : OVEX); |
| 5036 | if (Update.isInvalid()) |
| 5037 | return true; |
| 5038 | Update = SemaRef.PerformImplicitConversion(Update.get(), X->getType(), |
| 5039 | Sema::AA_Casting); |
| 5040 | if (Update.isInvalid()) |
| 5041 | return true; |
| 5042 | UpdateExpr = Update.get(); |
| 5043 | } |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5044 | return ErrorFound != NoError; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5045 | } |
| 5046 | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 5047 | StmtResult Sema::ActOnOpenMPAtomicDirective(ArrayRef<OMPClause *> Clauses, |
| 5048 | Stmt *AStmt, |
| 5049 | SourceLocation StartLoc, |
| 5050 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5051 | if (!AStmt) |
| 5052 | return StmtError(); |
| 5053 | |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5054 | auto CS = cast<CapturedStmt>(AStmt); |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 5055 | // 1.2.2 OpenMP Language Terminology |
| 5056 | // Structured block - An executable statement with a single entry at the |
| 5057 | // top and a single exit at the bottom. |
| 5058 | // The point of exit cannot be a branch out of the structured block. |
| 5059 | // longjmp() and throw() must not violate the entry/exit criteria. |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5060 | OpenMPClauseKind AtomicKind = OMPC_unknown; |
| 5061 | SourceLocation AtomicKindLoc; |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5062 | for (auto *C : Clauses) { |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5063 | if (C->getClauseKind() == OMPC_read || C->getClauseKind() == OMPC_write || |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5064 | C->getClauseKind() == OMPC_update || |
| 5065 | C->getClauseKind() == OMPC_capture) { |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5066 | if (AtomicKind != OMPC_unknown) { |
| 5067 | Diag(C->getLocStart(), diag::err_omp_atomic_several_clauses) |
| 5068 | << SourceRange(C->getLocStart(), C->getLocEnd()); |
| 5069 | Diag(AtomicKindLoc, diag::note_omp_atomic_previous_clause) |
| 5070 | << getOpenMPClauseName(AtomicKind); |
| 5071 | } else { |
| 5072 | AtomicKind = C->getClauseKind(); |
| 5073 | AtomicKindLoc = C->getLocStart(); |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5074 | } |
| 5075 | } |
| 5076 | } |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5077 | |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5078 | auto Body = CS->getCapturedStmt(); |
Alexey Bataev | 10fec57 | 2015-03-11 04:48:56 +0000 | [diff] [blame] | 5079 | if (auto *EWC = dyn_cast<ExprWithCleanups>(Body)) |
| 5080 | Body = EWC->getSubExpr(); |
| 5081 | |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5082 | Expr *X = nullptr; |
| 5083 | Expr *V = nullptr; |
| 5084 | Expr *E = nullptr; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5085 | Expr *UE = nullptr; |
| 5086 | bool IsXLHSInRHSPart = false; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5087 | bool IsPostfixUpdate = false; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5088 | // OpenMP [2.12.6, atomic Construct] |
| 5089 | // In the next expressions: |
| 5090 | // * x and v (as applicable) are both l-value expressions with scalar type. |
| 5091 | // * During the execution of an atomic region, multiple syntactic |
| 5092 | // occurrences of x must designate the same storage location. |
| 5093 | // * Neither of v and expr (as applicable) may access the storage location |
| 5094 | // designated by x. |
| 5095 | // * Neither of x and expr (as applicable) may access the storage location |
| 5096 | // designated by v. |
| 5097 | // * expr is an expression with scalar type. |
| 5098 | // * binop is one of +, *, -, /, &, ^, |, <<, or >>. |
| 5099 | // * binop, binop=, ++, and -- are not overloaded operators. |
| 5100 | // * The expression x binop expr must be numerically equivalent to x binop |
| 5101 | // (expr). This requirement is satisfied if the operators in expr have |
| 5102 | // precedence greater than binop, or by using parentheses around expr or |
| 5103 | // subexpressions of expr. |
| 5104 | // * The expression expr binop x must be numerically equivalent to (expr) |
| 5105 | // binop x. This requirement is satisfied if the operators in expr have |
| 5106 | // precedence equal to or greater than binop, or by using parentheses around |
| 5107 | // expr or subexpressions of expr. |
| 5108 | // * For forms that allow multiple occurrences of x, the number of times |
| 5109 | // that x is evaluated is unspecified. |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5110 | if (AtomicKind == OMPC_read) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5111 | enum { |
| 5112 | NotAnExpression, |
| 5113 | NotAnAssignmentOp, |
| 5114 | NotAScalarType, |
| 5115 | NotAnLValue, |
| 5116 | NoError |
| 5117 | } ErrorFound = NoError; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5118 | SourceLocation ErrorLoc, NoteLoc; |
| 5119 | SourceRange ErrorRange, NoteRange; |
| 5120 | // If clause is read: |
| 5121 | // v = x; |
| 5122 | if (auto AtomicBody = dyn_cast<Expr>(Body)) { |
| 5123 | auto AtomicBinOp = |
| 5124 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 5125 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
| 5126 | X = AtomicBinOp->getRHS()->IgnoreParenImpCasts(); |
| 5127 | V = AtomicBinOp->getLHS()->IgnoreParenImpCasts(); |
| 5128 | if ((X->isInstantiationDependent() || X->getType()->isScalarType()) && |
| 5129 | (V->isInstantiationDependent() || V->getType()->isScalarType())) { |
| 5130 | if (!X->isLValue() || !V->isLValue()) { |
| 5131 | auto NotLValueExpr = X->isLValue() ? V : X; |
| 5132 | ErrorFound = NotAnLValue; |
| 5133 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5134 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5135 | NoteLoc = NotLValueExpr->getExprLoc(); |
| 5136 | NoteRange = NotLValueExpr->getSourceRange(); |
| 5137 | } |
| 5138 | } else if (!X->isInstantiationDependent() || |
| 5139 | !V->isInstantiationDependent()) { |
| 5140 | auto NotScalarExpr = |
| 5141 | (X->isInstantiationDependent() || X->getType()->isScalarType()) |
| 5142 | ? V |
| 5143 | : X; |
| 5144 | ErrorFound = NotAScalarType; |
| 5145 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5146 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5147 | NoteLoc = NotScalarExpr->getExprLoc(); |
| 5148 | NoteRange = NotScalarExpr->getSourceRange(); |
| 5149 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5150 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5151 | ErrorFound = NotAnAssignmentOp; |
| 5152 | ErrorLoc = AtomicBody->getExprLoc(); |
| 5153 | ErrorRange = AtomicBody->getSourceRange(); |
| 5154 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 5155 | : AtomicBody->getExprLoc(); |
| 5156 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 5157 | : AtomicBody->getSourceRange(); |
| 5158 | } |
| 5159 | } else { |
| 5160 | ErrorFound = NotAnExpression; |
| 5161 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 5162 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5163 | } |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5164 | if (ErrorFound != NoError) { |
| 5165 | Diag(ErrorLoc, diag::err_omp_atomic_read_not_expression_statement) |
| 5166 | << ErrorRange; |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5167 | Diag(NoteLoc, diag::note_omp_atomic_read_write) << ErrorFound |
| 5168 | << NoteRange; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5169 | return StmtError(); |
| 5170 | } else if (CurContext->isDependentContext()) |
| 5171 | V = X = nullptr; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5172 | } else if (AtomicKind == OMPC_write) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5173 | enum { |
| 5174 | NotAnExpression, |
| 5175 | NotAnAssignmentOp, |
| 5176 | NotAScalarType, |
| 5177 | NotAnLValue, |
| 5178 | NoError |
| 5179 | } ErrorFound = NoError; |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5180 | SourceLocation ErrorLoc, NoteLoc; |
| 5181 | SourceRange ErrorRange, NoteRange; |
| 5182 | // If clause is write: |
| 5183 | // x = expr; |
| 5184 | if (auto AtomicBody = dyn_cast<Expr>(Body)) { |
| 5185 | auto AtomicBinOp = |
| 5186 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 5187 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
Alexey Bataev | b832926 | 2015-02-27 06:33:30 +0000 | [diff] [blame] | 5188 | X = AtomicBinOp->getLHS(); |
| 5189 | E = AtomicBinOp->getRHS(); |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5190 | if ((X->isInstantiationDependent() || X->getType()->isScalarType()) && |
| 5191 | (E->isInstantiationDependent() || E->getType()->isScalarType())) { |
| 5192 | if (!X->isLValue()) { |
| 5193 | ErrorFound = NotAnLValue; |
| 5194 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5195 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5196 | NoteLoc = X->getExprLoc(); |
| 5197 | NoteRange = X->getSourceRange(); |
| 5198 | } |
| 5199 | } else if (!X->isInstantiationDependent() || |
| 5200 | !E->isInstantiationDependent()) { |
| 5201 | auto NotScalarExpr = |
| 5202 | (X->isInstantiationDependent() || X->getType()->isScalarType()) |
| 5203 | ? E |
| 5204 | : X; |
| 5205 | ErrorFound = NotAScalarType; |
| 5206 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5207 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5208 | NoteLoc = NotScalarExpr->getExprLoc(); |
| 5209 | NoteRange = NotScalarExpr->getSourceRange(); |
| 5210 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5211 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5212 | ErrorFound = NotAnAssignmentOp; |
| 5213 | ErrorLoc = AtomicBody->getExprLoc(); |
| 5214 | ErrorRange = AtomicBody->getSourceRange(); |
| 5215 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 5216 | : AtomicBody->getExprLoc(); |
| 5217 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 5218 | : AtomicBody->getSourceRange(); |
| 5219 | } |
| 5220 | } else { |
| 5221 | ErrorFound = NotAnExpression; |
| 5222 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 5223 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5224 | } |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5225 | if (ErrorFound != NoError) { |
| 5226 | Diag(ErrorLoc, diag::err_omp_atomic_write_not_expression_statement) |
| 5227 | << ErrorRange; |
| 5228 | Diag(NoteLoc, diag::note_omp_atomic_read_write) << ErrorFound |
| 5229 | << NoteRange; |
| 5230 | return StmtError(); |
| 5231 | } else if (CurContext->isDependentContext()) |
| 5232 | E = X = nullptr; |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5233 | } else if (AtomicKind == OMPC_update || AtomicKind == OMPC_unknown) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5234 | // If clause is update: |
| 5235 | // x++; |
| 5236 | // x--; |
| 5237 | // ++x; |
| 5238 | // --x; |
| 5239 | // x binop= expr; |
| 5240 | // x = x binop expr; |
| 5241 | // x = expr binop x; |
| 5242 | OpenMPAtomicUpdateChecker Checker(*this); |
| 5243 | if (Checker.checkStatement( |
| 5244 | Body, (AtomicKind == OMPC_update) |
| 5245 | ? diag::err_omp_atomic_update_not_expression_statement |
| 5246 | : diag::err_omp_atomic_not_expression_statement, |
| 5247 | diag::note_omp_atomic_update)) |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5248 | return StmtError(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5249 | if (!CurContext->isDependentContext()) { |
| 5250 | E = Checker.getExpr(); |
| 5251 | X = Checker.getX(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5252 | UE = Checker.getUpdateExpr(); |
| 5253 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5254 | } |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5255 | } else if (AtomicKind == OMPC_capture) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5256 | enum { |
| 5257 | NotAnAssignmentOp, |
| 5258 | NotACompoundStatement, |
| 5259 | NotTwoSubstatements, |
| 5260 | NotASpecificExpression, |
| 5261 | NoError |
| 5262 | } ErrorFound = NoError; |
| 5263 | SourceLocation ErrorLoc, NoteLoc; |
| 5264 | SourceRange ErrorRange, NoteRange; |
| 5265 | if (auto *AtomicBody = dyn_cast<Expr>(Body)) { |
| 5266 | // If clause is a capture: |
| 5267 | // v = x++; |
| 5268 | // v = x--; |
| 5269 | // v = ++x; |
| 5270 | // v = --x; |
| 5271 | // v = x binop= expr; |
| 5272 | // v = x = x binop expr; |
| 5273 | // v = x = expr binop x; |
| 5274 | auto *AtomicBinOp = |
| 5275 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 5276 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
| 5277 | V = AtomicBinOp->getLHS(); |
| 5278 | Body = AtomicBinOp->getRHS()->IgnoreParenImpCasts(); |
| 5279 | OpenMPAtomicUpdateChecker Checker(*this); |
| 5280 | if (Checker.checkStatement( |
| 5281 | Body, diag::err_omp_atomic_capture_not_expression_statement, |
| 5282 | diag::note_omp_atomic_update)) |
| 5283 | return StmtError(); |
| 5284 | E = Checker.getExpr(); |
| 5285 | X = Checker.getX(); |
| 5286 | UE = Checker.getUpdateExpr(); |
| 5287 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
| 5288 | IsPostfixUpdate = Checker.isPostfixUpdate(); |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5289 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5290 | ErrorLoc = AtomicBody->getExprLoc(); |
| 5291 | ErrorRange = AtomicBody->getSourceRange(); |
| 5292 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 5293 | : AtomicBody->getExprLoc(); |
| 5294 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 5295 | : AtomicBody->getSourceRange(); |
| 5296 | ErrorFound = NotAnAssignmentOp; |
| 5297 | } |
| 5298 | if (ErrorFound != NoError) { |
| 5299 | Diag(ErrorLoc, diag::err_omp_atomic_capture_not_expression_statement) |
| 5300 | << ErrorRange; |
| 5301 | Diag(NoteLoc, diag::note_omp_atomic_capture) << ErrorFound << NoteRange; |
| 5302 | return StmtError(); |
| 5303 | } else if (CurContext->isDependentContext()) { |
| 5304 | UE = V = E = X = nullptr; |
| 5305 | } |
| 5306 | } else { |
| 5307 | // If clause is a capture: |
| 5308 | // { v = x; x = expr; } |
| 5309 | // { v = x; x++; } |
| 5310 | // { v = x; x--; } |
| 5311 | // { v = x; ++x; } |
| 5312 | // { v = x; --x; } |
| 5313 | // { v = x; x binop= expr; } |
| 5314 | // { v = x; x = x binop expr; } |
| 5315 | // { v = x; x = expr binop x; } |
| 5316 | // { x++; v = x; } |
| 5317 | // { x--; v = x; } |
| 5318 | // { ++x; v = x; } |
| 5319 | // { --x; v = x; } |
| 5320 | // { x binop= expr; v = x; } |
| 5321 | // { x = x binop expr; v = x; } |
| 5322 | // { x = expr binop x; v = x; } |
| 5323 | if (auto *CS = dyn_cast<CompoundStmt>(Body)) { |
| 5324 | // Check that this is { expr1; expr2; } |
| 5325 | if (CS->size() == 2) { |
| 5326 | auto *First = CS->body_front(); |
| 5327 | auto *Second = CS->body_back(); |
| 5328 | if (auto *EWC = dyn_cast<ExprWithCleanups>(First)) |
| 5329 | First = EWC->getSubExpr()->IgnoreParenImpCasts(); |
| 5330 | if (auto *EWC = dyn_cast<ExprWithCleanups>(Second)) |
| 5331 | Second = EWC->getSubExpr()->IgnoreParenImpCasts(); |
| 5332 | // Need to find what subexpression is 'v' and what is 'x'. |
| 5333 | OpenMPAtomicUpdateChecker Checker(*this); |
| 5334 | bool IsUpdateExprFound = !Checker.checkStatement(Second); |
| 5335 | BinaryOperator *BinOp = nullptr; |
| 5336 | if (IsUpdateExprFound) { |
| 5337 | BinOp = dyn_cast<BinaryOperator>(First); |
| 5338 | IsUpdateExprFound = BinOp && BinOp->getOpcode() == BO_Assign; |
| 5339 | } |
| 5340 | if (IsUpdateExprFound && !CurContext->isDependentContext()) { |
| 5341 | // { v = x; x++; } |
| 5342 | // { v = x; x--; } |
| 5343 | // { v = x; ++x; } |
| 5344 | // { v = x; --x; } |
| 5345 | // { v = x; x binop= expr; } |
| 5346 | // { v = x; x = x binop expr; } |
| 5347 | // { v = x; x = expr binop x; } |
| 5348 | // Check that the first expression has form v = x. |
| 5349 | auto *PossibleX = BinOp->getRHS()->IgnoreParenImpCasts(); |
| 5350 | llvm::FoldingSetNodeID XId, PossibleXId; |
| 5351 | Checker.getX()->Profile(XId, Context, /*Canonical=*/true); |
| 5352 | PossibleX->Profile(PossibleXId, Context, /*Canonical=*/true); |
| 5353 | IsUpdateExprFound = XId == PossibleXId; |
| 5354 | if (IsUpdateExprFound) { |
| 5355 | V = BinOp->getLHS(); |
| 5356 | X = Checker.getX(); |
| 5357 | E = Checker.getExpr(); |
| 5358 | UE = Checker.getUpdateExpr(); |
| 5359 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5360 | IsPostfixUpdate = true; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5361 | } |
| 5362 | } |
| 5363 | if (!IsUpdateExprFound) { |
| 5364 | IsUpdateExprFound = !Checker.checkStatement(First); |
| 5365 | BinOp = nullptr; |
| 5366 | if (IsUpdateExprFound) { |
| 5367 | BinOp = dyn_cast<BinaryOperator>(Second); |
| 5368 | IsUpdateExprFound = BinOp && BinOp->getOpcode() == BO_Assign; |
| 5369 | } |
| 5370 | if (IsUpdateExprFound && !CurContext->isDependentContext()) { |
| 5371 | // { x++; v = x; } |
| 5372 | // { x--; v = x; } |
| 5373 | // { ++x; v = x; } |
| 5374 | // { --x; v = x; } |
| 5375 | // { x binop= expr; v = x; } |
| 5376 | // { x = x binop expr; v = x; } |
| 5377 | // { x = expr binop x; v = x; } |
| 5378 | // Check that the second expression has form v = x. |
| 5379 | auto *PossibleX = BinOp->getRHS()->IgnoreParenImpCasts(); |
| 5380 | llvm::FoldingSetNodeID XId, PossibleXId; |
| 5381 | Checker.getX()->Profile(XId, Context, /*Canonical=*/true); |
| 5382 | PossibleX->Profile(PossibleXId, Context, /*Canonical=*/true); |
| 5383 | IsUpdateExprFound = XId == PossibleXId; |
| 5384 | if (IsUpdateExprFound) { |
| 5385 | V = BinOp->getLHS(); |
| 5386 | X = Checker.getX(); |
| 5387 | E = Checker.getExpr(); |
| 5388 | UE = Checker.getUpdateExpr(); |
| 5389 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5390 | IsPostfixUpdate = false; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5391 | } |
| 5392 | } |
| 5393 | } |
| 5394 | if (!IsUpdateExprFound) { |
| 5395 | // { v = x; x = expr; } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5396 | auto *FirstExpr = dyn_cast<Expr>(First); |
| 5397 | auto *SecondExpr = dyn_cast<Expr>(Second); |
| 5398 | if (!FirstExpr || !SecondExpr || |
| 5399 | !(FirstExpr->isInstantiationDependent() || |
| 5400 | SecondExpr->isInstantiationDependent())) { |
| 5401 | auto *FirstBinOp = dyn_cast<BinaryOperator>(First); |
| 5402 | if (!FirstBinOp || FirstBinOp->getOpcode() != BO_Assign) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5403 | ErrorFound = NotAnAssignmentOp; |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5404 | NoteLoc = ErrorLoc = FirstBinOp ? FirstBinOp->getOperatorLoc() |
| 5405 | : First->getLocStart(); |
| 5406 | NoteRange = ErrorRange = FirstBinOp |
| 5407 | ? FirstBinOp->getSourceRange() |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5408 | : SourceRange(ErrorLoc, ErrorLoc); |
| 5409 | } else { |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5410 | auto *SecondBinOp = dyn_cast<BinaryOperator>(Second); |
| 5411 | if (!SecondBinOp || SecondBinOp->getOpcode() != BO_Assign) { |
| 5412 | ErrorFound = NotAnAssignmentOp; |
| 5413 | NoteLoc = ErrorLoc = SecondBinOp |
| 5414 | ? SecondBinOp->getOperatorLoc() |
| 5415 | : Second->getLocStart(); |
| 5416 | NoteRange = ErrorRange = |
| 5417 | SecondBinOp ? SecondBinOp->getSourceRange() |
| 5418 | : SourceRange(ErrorLoc, ErrorLoc); |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5419 | } else { |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5420 | auto *PossibleXRHSInFirst = |
| 5421 | FirstBinOp->getRHS()->IgnoreParenImpCasts(); |
| 5422 | auto *PossibleXLHSInSecond = |
| 5423 | SecondBinOp->getLHS()->IgnoreParenImpCasts(); |
| 5424 | llvm::FoldingSetNodeID X1Id, X2Id; |
| 5425 | PossibleXRHSInFirst->Profile(X1Id, Context, |
| 5426 | /*Canonical=*/true); |
| 5427 | PossibleXLHSInSecond->Profile(X2Id, Context, |
| 5428 | /*Canonical=*/true); |
| 5429 | IsUpdateExprFound = X1Id == X2Id; |
| 5430 | if (IsUpdateExprFound) { |
| 5431 | V = FirstBinOp->getLHS(); |
| 5432 | X = SecondBinOp->getLHS(); |
| 5433 | E = SecondBinOp->getRHS(); |
| 5434 | UE = nullptr; |
| 5435 | IsXLHSInRHSPart = false; |
| 5436 | IsPostfixUpdate = true; |
| 5437 | } else { |
| 5438 | ErrorFound = NotASpecificExpression; |
| 5439 | ErrorLoc = FirstBinOp->getExprLoc(); |
| 5440 | ErrorRange = FirstBinOp->getSourceRange(); |
| 5441 | NoteLoc = SecondBinOp->getLHS()->getExprLoc(); |
| 5442 | NoteRange = SecondBinOp->getRHS()->getSourceRange(); |
| 5443 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5444 | } |
| 5445 | } |
| 5446 | } |
| 5447 | } |
| 5448 | } else { |
| 5449 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 5450 | NoteRange = ErrorRange = |
| 5451 | SourceRange(Body->getLocStart(), Body->getLocStart()); |
| 5452 | ErrorFound = NotTwoSubstatements; |
| 5453 | } |
| 5454 | } else { |
| 5455 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 5456 | NoteRange = ErrorRange = |
| 5457 | SourceRange(Body->getLocStart(), Body->getLocStart()); |
| 5458 | ErrorFound = NotACompoundStatement; |
| 5459 | } |
| 5460 | if (ErrorFound != NoError) { |
| 5461 | Diag(ErrorLoc, diag::err_omp_atomic_capture_not_compound_statement) |
| 5462 | << ErrorRange; |
| 5463 | Diag(NoteLoc, diag::note_omp_atomic_capture) << ErrorFound << NoteRange; |
| 5464 | return StmtError(); |
| 5465 | } else if (CurContext->isDependentContext()) { |
| 5466 | UE = V = E = X = nullptr; |
| 5467 | } |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5468 | } |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5469 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 5470 | |
| 5471 | getCurFunction()->setHasBranchProtectedScope(); |
| 5472 | |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5473 | return OMPAtomicDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5474 | X, V, E, UE, IsXLHSInRHSPart, |
| 5475 | IsPostfixUpdate); |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 5476 | } |
| 5477 | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 5478 | StmtResult Sema::ActOnOpenMPTargetDirective(ArrayRef<OMPClause *> Clauses, |
| 5479 | Stmt *AStmt, |
| 5480 | SourceLocation StartLoc, |
| 5481 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5482 | if (!AStmt) |
| 5483 | return StmtError(); |
| 5484 | |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 5485 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 5486 | // 1.2.2 OpenMP Language Terminology |
| 5487 | // Structured block - An executable statement with a single entry at the |
| 5488 | // top and a single exit at the bottom. |
| 5489 | // The point of exit cannot be a branch out of the structured block. |
| 5490 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5491 | CS->getCapturedDecl()->setNothrow(); |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 5492 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 5493 | // OpenMP [2.16, Nesting of Regions] |
| 5494 | // If specified, a teams construct must be contained within a target |
| 5495 | // construct. That target construct must contain no statements or directives |
| 5496 | // outside of the teams construct. |
| 5497 | if (DSAStack->hasInnerTeamsRegion()) { |
| 5498 | auto S = AStmt->IgnoreContainers(/*IgnoreCaptured*/ true); |
| 5499 | bool OMPTeamsFound = true; |
| 5500 | if (auto *CS = dyn_cast<CompoundStmt>(S)) { |
| 5501 | auto I = CS->body_begin(); |
| 5502 | while (I != CS->body_end()) { |
| 5503 | auto OED = dyn_cast<OMPExecutableDirective>(*I); |
| 5504 | if (!OED || !isOpenMPTeamsDirective(OED->getDirectiveKind())) { |
| 5505 | OMPTeamsFound = false; |
| 5506 | break; |
| 5507 | } |
| 5508 | ++I; |
| 5509 | } |
| 5510 | assert(I != CS->body_end() && "Not found statement"); |
| 5511 | S = *I; |
| 5512 | } |
| 5513 | if (!OMPTeamsFound) { |
| 5514 | Diag(StartLoc, diag::err_omp_target_contains_not_only_teams); |
| 5515 | Diag(DSAStack->getInnerTeamsRegionLoc(), |
| 5516 | diag::note_omp_nested_teams_construct_here); |
| 5517 | Diag(S->getLocStart(), diag::note_omp_nested_statement_here) |
| 5518 | << isa<OMPExecutableDirective>(S); |
| 5519 | return StmtError(); |
| 5520 | } |
| 5521 | } |
| 5522 | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 5523 | getCurFunction()->setHasBranchProtectedScope(); |
| 5524 | |
| 5525 | return OMPTargetDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 5526 | } |
| 5527 | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 5528 | /// \brief Check for existence of a map clause in the list of clauses. |
| 5529 | static bool HasMapClause(ArrayRef<OMPClause *> Clauses) { |
| 5530 | for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end(); |
| 5531 | I != E; ++I) { |
| 5532 | if (*I != nullptr && (*I)->getClauseKind() == OMPC_map) { |
| 5533 | return true; |
| 5534 | } |
| 5535 | } |
| 5536 | |
| 5537 | return false; |
| 5538 | } |
| 5539 | |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 5540 | StmtResult Sema::ActOnOpenMPTargetDataDirective(ArrayRef<OMPClause *> Clauses, |
| 5541 | Stmt *AStmt, |
| 5542 | SourceLocation StartLoc, |
| 5543 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5544 | if (!AStmt) |
| 5545 | return StmtError(); |
| 5546 | |
| 5547 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 5548 | |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 5549 | getCurFunction()->setHasBranchProtectedScope(); |
| 5550 | |
| 5551 | return OMPTargetDataDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 5552 | AStmt); |
| 5553 | } |
| 5554 | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 5555 | StmtResult |
| 5556 | Sema::ActOnOpenMPTargetEnterDataDirective(ArrayRef<OMPClause *> Clauses, |
| 5557 | SourceLocation StartLoc, |
| 5558 | SourceLocation EndLoc) { |
| 5559 | // OpenMP [2.10.2, Restrictions, p. 99] |
| 5560 | // At least one map clause must appear on the directive. |
| 5561 | if (!HasMapClause(Clauses)) { |
| 5562 | Diag(StartLoc, diag::err_omp_no_map_for_directive) |
| 5563 | << getOpenMPDirectiveName(OMPD_target_enter_data); |
| 5564 | return StmtError(); |
| 5565 | } |
| 5566 | |
| 5567 | return OMPTargetEnterDataDirective::Create(Context, StartLoc, EndLoc, |
| 5568 | Clauses); |
| 5569 | } |
| 5570 | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 5571 | StmtResult |
| 5572 | Sema::ActOnOpenMPTargetExitDataDirective(ArrayRef<OMPClause *> Clauses, |
| 5573 | SourceLocation StartLoc, |
| 5574 | SourceLocation EndLoc) { |
| 5575 | // OpenMP [2.10.3, Restrictions, p. 102] |
| 5576 | // At least one map clause must appear on the directive. |
| 5577 | if (!HasMapClause(Clauses)) { |
| 5578 | Diag(StartLoc, diag::err_omp_no_map_for_directive) |
| 5579 | << getOpenMPDirectiveName(OMPD_target_exit_data); |
| 5580 | return StmtError(); |
| 5581 | } |
| 5582 | |
| 5583 | return OMPTargetExitDataDirective::Create(Context, StartLoc, EndLoc, Clauses); |
| 5584 | } |
| 5585 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 5586 | StmtResult Sema::ActOnOpenMPTeamsDirective(ArrayRef<OMPClause *> Clauses, |
| 5587 | Stmt *AStmt, SourceLocation StartLoc, |
| 5588 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5589 | if (!AStmt) |
| 5590 | return StmtError(); |
| 5591 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 5592 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 5593 | // 1.2.2 OpenMP Language Terminology |
| 5594 | // Structured block - An executable statement with a single entry at the |
| 5595 | // top and a single exit at the bottom. |
| 5596 | // The point of exit cannot be a branch out of the structured block. |
| 5597 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5598 | CS->getCapturedDecl()->setNothrow(); |
| 5599 | |
| 5600 | getCurFunction()->setHasBranchProtectedScope(); |
| 5601 | |
| 5602 | return OMPTeamsDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 5603 | } |
| 5604 | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 5605 | StmtResult |
| 5606 | Sema::ActOnOpenMPCancellationPointDirective(SourceLocation StartLoc, |
| 5607 | SourceLocation EndLoc, |
| 5608 | OpenMPDirectiveKind CancelRegion) { |
| 5609 | if (CancelRegion != OMPD_parallel && CancelRegion != OMPD_for && |
| 5610 | CancelRegion != OMPD_sections && CancelRegion != OMPD_taskgroup) { |
| 5611 | Diag(StartLoc, diag::err_omp_wrong_cancel_region) |
| 5612 | << getOpenMPDirectiveName(CancelRegion); |
| 5613 | return StmtError(); |
| 5614 | } |
| 5615 | if (DSAStack->isParentNowaitRegion()) { |
| 5616 | Diag(StartLoc, diag::err_omp_parent_cancel_region_nowait) << 0; |
| 5617 | return StmtError(); |
| 5618 | } |
| 5619 | if (DSAStack->isParentOrderedRegion()) { |
| 5620 | Diag(StartLoc, diag::err_omp_parent_cancel_region_ordered) << 0; |
| 5621 | return StmtError(); |
| 5622 | } |
| 5623 | return OMPCancellationPointDirective::Create(Context, StartLoc, EndLoc, |
| 5624 | CancelRegion); |
| 5625 | } |
| 5626 | |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 5627 | StmtResult Sema::ActOnOpenMPCancelDirective(ArrayRef<OMPClause *> Clauses, |
| 5628 | SourceLocation StartLoc, |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 5629 | SourceLocation EndLoc, |
| 5630 | OpenMPDirectiveKind CancelRegion) { |
| 5631 | if (CancelRegion != OMPD_parallel && CancelRegion != OMPD_for && |
| 5632 | CancelRegion != OMPD_sections && CancelRegion != OMPD_taskgroup) { |
| 5633 | Diag(StartLoc, diag::err_omp_wrong_cancel_region) |
| 5634 | << getOpenMPDirectiveName(CancelRegion); |
| 5635 | return StmtError(); |
| 5636 | } |
| 5637 | if (DSAStack->isParentNowaitRegion()) { |
| 5638 | Diag(StartLoc, diag::err_omp_parent_cancel_region_nowait) << 1; |
| 5639 | return StmtError(); |
| 5640 | } |
| 5641 | if (DSAStack->isParentOrderedRegion()) { |
| 5642 | Diag(StartLoc, diag::err_omp_parent_cancel_region_ordered) << 1; |
| 5643 | return StmtError(); |
| 5644 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 5645 | DSAStack->setParentCancelRegion(/*Cancel=*/true); |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 5646 | return OMPCancelDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 5647 | CancelRegion); |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 5648 | } |
| 5649 | |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 5650 | static bool checkGrainsizeNumTasksClauses(Sema &S, |
| 5651 | ArrayRef<OMPClause *> Clauses) { |
| 5652 | OMPClause *PrevClause = nullptr; |
| 5653 | bool ErrorFound = false; |
| 5654 | for (auto *C : Clauses) { |
| 5655 | if (C->getClauseKind() == OMPC_grainsize || |
| 5656 | C->getClauseKind() == OMPC_num_tasks) { |
| 5657 | if (!PrevClause) |
| 5658 | PrevClause = C; |
| 5659 | else if (PrevClause->getClauseKind() != C->getClauseKind()) { |
| 5660 | S.Diag(C->getLocStart(), |
| 5661 | diag::err_omp_grainsize_num_tasks_mutually_exclusive) |
| 5662 | << getOpenMPClauseName(C->getClauseKind()) |
| 5663 | << getOpenMPClauseName(PrevClause->getClauseKind()); |
| 5664 | S.Diag(PrevClause->getLocStart(), |
| 5665 | diag::note_omp_previous_grainsize_num_tasks) |
| 5666 | << getOpenMPClauseName(PrevClause->getClauseKind()); |
| 5667 | ErrorFound = true; |
| 5668 | } |
| 5669 | } |
| 5670 | } |
| 5671 | return ErrorFound; |
| 5672 | } |
| 5673 | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 5674 | StmtResult Sema::ActOnOpenMPTaskLoopDirective( |
| 5675 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 5676 | SourceLocation EndLoc, |
| 5677 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
| 5678 | if (!AStmt) |
| 5679 | return StmtError(); |
| 5680 | |
| 5681 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 5682 | OMPLoopDirective::HelperExprs B; |
| 5683 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 5684 | // define the nested loops number. |
| 5685 | unsigned NestedLoopCount = |
| 5686 | CheckOpenMPLoop(OMPD_taskloop, getCollapseNumberExpr(Clauses), |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 5687 | /*OrderedLoopCountExpr=*/nullptr, AStmt, *this, *DSAStack, |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 5688 | VarsWithImplicitDSA, B); |
| 5689 | if (NestedLoopCount == 0) |
| 5690 | return StmtError(); |
| 5691 | |
| 5692 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 5693 | "omp for loop exprs were not built"); |
| 5694 | |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 5695 | // OpenMP, [2.9.2 taskloop Construct, Restrictions] |
| 5696 | // The grainsize clause and num_tasks clause are mutually exclusive and may |
| 5697 | // not appear on the same taskloop directive. |
| 5698 | if (checkGrainsizeNumTasksClauses(*this, Clauses)) |
| 5699 | return StmtError(); |
| 5700 | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 5701 | getCurFunction()->setHasBranchProtectedScope(); |
| 5702 | return OMPTaskLoopDirective::Create(Context, StartLoc, EndLoc, |
| 5703 | NestedLoopCount, Clauses, AStmt, B); |
| 5704 | } |
| 5705 | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 5706 | StmtResult Sema::ActOnOpenMPTaskLoopSimdDirective( |
| 5707 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 5708 | SourceLocation EndLoc, |
| 5709 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
| 5710 | if (!AStmt) |
| 5711 | return StmtError(); |
| 5712 | |
| 5713 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 5714 | OMPLoopDirective::HelperExprs B; |
| 5715 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 5716 | // define the nested loops number. |
| 5717 | unsigned NestedLoopCount = |
| 5718 | CheckOpenMPLoop(OMPD_taskloop_simd, getCollapseNumberExpr(Clauses), |
| 5719 | /*OrderedLoopCountExpr=*/nullptr, AStmt, *this, *DSAStack, |
| 5720 | VarsWithImplicitDSA, B); |
| 5721 | if (NestedLoopCount == 0) |
| 5722 | return StmtError(); |
| 5723 | |
| 5724 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 5725 | "omp for loop exprs were not built"); |
| 5726 | |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 5727 | // OpenMP, [2.9.2 taskloop Construct, Restrictions] |
| 5728 | // The grainsize clause and num_tasks clause are mutually exclusive and may |
| 5729 | // not appear on the same taskloop directive. |
| 5730 | if (checkGrainsizeNumTasksClauses(*this, Clauses)) |
| 5731 | return StmtError(); |
| 5732 | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 5733 | getCurFunction()->setHasBranchProtectedScope(); |
| 5734 | return OMPTaskLoopSimdDirective::Create(Context, StartLoc, EndLoc, |
| 5735 | NestedLoopCount, Clauses, AStmt, B); |
| 5736 | } |
| 5737 | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 5738 | StmtResult Sema::ActOnOpenMPDistributeDirective( |
| 5739 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 5740 | SourceLocation EndLoc, |
| 5741 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
| 5742 | if (!AStmt) |
| 5743 | return StmtError(); |
| 5744 | |
| 5745 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 5746 | OMPLoopDirective::HelperExprs B; |
| 5747 | // In presence of clause 'collapse' with number of loops, it will |
| 5748 | // define the nested loops number. |
| 5749 | unsigned NestedLoopCount = |
| 5750 | CheckOpenMPLoop(OMPD_distribute, getCollapseNumberExpr(Clauses), |
| 5751 | nullptr /*ordered not a clause on distribute*/, AStmt, |
| 5752 | *this, *DSAStack, VarsWithImplicitDSA, B); |
| 5753 | if (NestedLoopCount == 0) |
| 5754 | return StmtError(); |
| 5755 | |
| 5756 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 5757 | "omp for loop exprs were not built"); |
| 5758 | |
| 5759 | getCurFunction()->setHasBranchProtectedScope(); |
| 5760 | return OMPDistributeDirective::Create(Context, StartLoc, EndLoc, |
| 5761 | NestedLoopCount, Clauses, AStmt, B); |
| 5762 | } |
| 5763 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5764 | OMPClause *Sema::ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, Expr *Expr, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5765 | SourceLocation StartLoc, |
| 5766 | SourceLocation LParenLoc, |
| 5767 | SourceLocation EndLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 5768 | OMPClause *Res = nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5769 | switch (Kind) { |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 5770 | case OMPC_final: |
| 5771 | Res = ActOnOpenMPFinalClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5772 | break; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5773 | case OMPC_num_threads: |
| 5774 | Res = ActOnOpenMPNumThreadsClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5775 | break; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5776 | case OMPC_safelen: |
| 5777 | Res = ActOnOpenMPSafelenClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5778 | break; |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 5779 | case OMPC_simdlen: |
| 5780 | Res = ActOnOpenMPSimdlenClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5781 | break; |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 5782 | case OMPC_collapse: |
| 5783 | Res = ActOnOpenMPCollapseClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5784 | break; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5785 | case OMPC_ordered: |
| 5786 | Res = ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Expr); |
| 5787 | break; |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 5788 | case OMPC_device: |
| 5789 | Res = ActOnOpenMPDeviceClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5790 | break; |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 5791 | case OMPC_num_teams: |
| 5792 | Res = ActOnOpenMPNumTeamsClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5793 | break; |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 5794 | case OMPC_thread_limit: |
| 5795 | Res = ActOnOpenMPThreadLimitClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5796 | break; |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 5797 | case OMPC_priority: |
| 5798 | Res = ActOnOpenMPPriorityClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5799 | break; |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 5800 | case OMPC_grainsize: |
| 5801 | Res = ActOnOpenMPGrainsizeClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5802 | break; |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 5803 | case OMPC_num_tasks: |
| 5804 | Res = ActOnOpenMPNumTasksClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5805 | break; |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 5806 | case OMPC_hint: |
| 5807 | Res = ActOnOpenMPHintClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5808 | break; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5809 | case OMPC_if: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5810 | case OMPC_default: |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 5811 | case OMPC_proc_bind: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5812 | case OMPC_schedule: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5813 | case OMPC_private: |
| 5814 | case OMPC_firstprivate: |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 5815 | case OMPC_lastprivate: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5816 | case OMPC_shared: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5817 | case OMPC_reduction: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 5818 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 5819 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 5820 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 5821 | case OMPC_copyprivate: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 5822 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 5823 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 5824 | case OMPC_mergeable: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5825 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 5826 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5827 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5828 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5829 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5830 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 5831 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 5832 | case OMPC_depend: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5833 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5834 | case OMPC_simd: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 5835 | case OMPC_map: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 5836 | case OMPC_nogroup: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 5837 | case OMPC_dist_schedule: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5838 | case OMPC_unknown: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5839 | llvm_unreachable("Clause is not allowed."); |
| 5840 | } |
| 5841 | return Res; |
| 5842 | } |
| 5843 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5844 | OMPClause *Sema::ActOnOpenMPIfClause(OpenMPDirectiveKind NameModifier, |
| 5845 | Expr *Condition, SourceLocation StartLoc, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5846 | SourceLocation LParenLoc, |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5847 | SourceLocation NameModifierLoc, |
| 5848 | SourceLocation ColonLoc, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5849 | SourceLocation EndLoc) { |
| 5850 | Expr *ValExpr = Condition; |
| 5851 | if (!Condition->isValueDependent() && !Condition->isTypeDependent() && |
| 5852 | !Condition->isInstantiationDependent() && |
| 5853 | !Condition->containsUnexpandedParameterPack()) { |
| 5854 | ExprResult Val = ActOnBooleanCondition(DSAStack->getCurScope(), |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5855 | Condition->getExprLoc(), Condition); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5856 | if (Val.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 5857 | return nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5858 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 5859 | ValExpr = Val.get(); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5860 | } |
| 5861 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5862 | return new (Context) OMPIfClause(NameModifier, ValExpr, StartLoc, LParenLoc, |
| 5863 | NameModifierLoc, ColonLoc, EndLoc); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5864 | } |
| 5865 | |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 5866 | OMPClause *Sema::ActOnOpenMPFinalClause(Expr *Condition, |
| 5867 | SourceLocation StartLoc, |
| 5868 | SourceLocation LParenLoc, |
| 5869 | SourceLocation EndLoc) { |
| 5870 | Expr *ValExpr = Condition; |
| 5871 | if (!Condition->isValueDependent() && !Condition->isTypeDependent() && |
| 5872 | !Condition->isInstantiationDependent() && |
| 5873 | !Condition->containsUnexpandedParameterPack()) { |
| 5874 | ExprResult Val = ActOnBooleanCondition(DSAStack->getCurScope(), |
| 5875 | Condition->getExprLoc(), Condition); |
| 5876 | if (Val.isInvalid()) |
| 5877 | return nullptr; |
| 5878 | |
| 5879 | ValExpr = Val.get(); |
| 5880 | } |
| 5881 | |
| 5882 | return new (Context) OMPFinalClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 5883 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5884 | ExprResult Sema::PerformOpenMPImplicitIntegerConversion(SourceLocation Loc, |
| 5885 | Expr *Op) { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5886 | if (!Op) |
| 5887 | return ExprError(); |
| 5888 | |
| 5889 | class IntConvertDiagnoser : public ICEConvertDiagnoser { |
| 5890 | public: |
| 5891 | IntConvertDiagnoser() |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5892 | : ICEConvertDiagnoser(/*AllowScopedEnumerations*/ false, false, true) {} |
Craig Topper | e14c0f8 | 2014-03-12 04:55:44 +0000 | [diff] [blame] | 5893 | SemaDiagnosticBuilder diagnoseNotInt(Sema &S, SourceLocation Loc, |
| 5894 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5895 | return S.Diag(Loc, diag::err_omp_not_integral) << T; |
| 5896 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5897 | SemaDiagnosticBuilder diagnoseIncomplete(Sema &S, SourceLocation Loc, |
| 5898 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5899 | return S.Diag(Loc, diag::err_omp_incomplete_type) << T; |
| 5900 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5901 | SemaDiagnosticBuilder diagnoseExplicitConv(Sema &S, SourceLocation Loc, |
| 5902 | QualType T, |
| 5903 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5904 | return S.Diag(Loc, diag::err_omp_explicit_conversion) << T << ConvTy; |
| 5905 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5906 | SemaDiagnosticBuilder noteExplicitConv(Sema &S, CXXConversionDecl *Conv, |
| 5907 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5908 | return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5909 | << ConvTy->isEnumeralType() << ConvTy; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5910 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5911 | SemaDiagnosticBuilder diagnoseAmbiguous(Sema &S, SourceLocation Loc, |
| 5912 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5913 | return S.Diag(Loc, diag::err_omp_ambiguous_conversion) << T; |
| 5914 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5915 | SemaDiagnosticBuilder noteAmbiguous(Sema &S, CXXConversionDecl *Conv, |
| 5916 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5917 | return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5918 | << ConvTy->isEnumeralType() << ConvTy; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5919 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5920 | SemaDiagnosticBuilder diagnoseConversion(Sema &, SourceLocation, QualType, |
| 5921 | QualType) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5922 | llvm_unreachable("conversion functions are permitted"); |
| 5923 | } |
| 5924 | } ConvertDiagnoser; |
| 5925 | return PerformContextualImplicitConversion(Loc, Op, ConvertDiagnoser); |
| 5926 | } |
| 5927 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 5928 | static bool IsNonNegativeIntegerValue(Expr *&ValExpr, Sema &SemaRef, |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 5929 | OpenMPClauseKind CKind, |
| 5930 | bool StrictlyPositive) { |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 5931 | if (!ValExpr->isTypeDependent() && !ValExpr->isValueDependent() && |
| 5932 | !ValExpr->isInstantiationDependent()) { |
| 5933 | SourceLocation Loc = ValExpr->getExprLoc(); |
| 5934 | ExprResult Value = |
| 5935 | SemaRef.PerformOpenMPImplicitIntegerConversion(Loc, ValExpr); |
| 5936 | if (Value.isInvalid()) |
| 5937 | return false; |
| 5938 | |
| 5939 | ValExpr = Value.get(); |
| 5940 | // The expression must evaluate to a non-negative integer value. |
| 5941 | llvm::APSInt Result; |
| 5942 | if (ValExpr->isIntegerConstantExpr(Result, SemaRef.Context) && |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 5943 | Result.isSigned() && |
| 5944 | !((!StrictlyPositive && Result.isNonNegative()) || |
| 5945 | (StrictlyPositive && Result.isStrictlyPositive()))) { |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 5946 | SemaRef.Diag(Loc, diag::err_omp_negative_expression_in_clause) |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 5947 | << getOpenMPClauseName(CKind) << (StrictlyPositive ? 1 : 0) |
| 5948 | << ValExpr->getSourceRange(); |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 5949 | return false; |
| 5950 | } |
| 5951 | } |
| 5952 | return true; |
| 5953 | } |
| 5954 | |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5955 | OMPClause *Sema::ActOnOpenMPNumThreadsClause(Expr *NumThreads, |
| 5956 | SourceLocation StartLoc, |
| 5957 | SourceLocation LParenLoc, |
| 5958 | SourceLocation EndLoc) { |
| 5959 | Expr *ValExpr = NumThreads; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5960 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 5961 | // OpenMP [2.5, Restrictions] |
| 5962 | // The num_threads expression must evaluate to a positive integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 5963 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_num_threads, |
| 5964 | /*StrictlyPositive=*/true)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 5965 | return nullptr; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5966 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5967 | return new (Context) |
| 5968 | OMPNumThreadsClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5969 | } |
| 5970 | |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5971 | ExprResult Sema::VerifyPositiveIntegerConstantInClause(Expr *E, |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 5972 | OpenMPClauseKind CKind, |
| 5973 | bool StrictlyPositive) { |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5974 | if (!E) |
| 5975 | return ExprError(); |
| 5976 | if (E->isValueDependent() || E->isTypeDependent() || |
| 5977 | E->isInstantiationDependent() || E->containsUnexpandedParameterPack()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 5978 | return E; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5979 | llvm::APSInt Result; |
| 5980 | ExprResult ICE = VerifyIntegerConstantExpression(E, &Result); |
| 5981 | if (ICE.isInvalid()) |
| 5982 | return ExprError(); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 5983 | if ((StrictlyPositive && !Result.isStrictlyPositive()) || |
| 5984 | (!StrictlyPositive && !Result.isNonNegative())) { |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5985 | Diag(E->getExprLoc(), diag::err_omp_negative_expression_in_clause) |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 5986 | << getOpenMPClauseName(CKind) << (StrictlyPositive ? 1 : 0) |
| 5987 | << E->getSourceRange(); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5988 | return ExprError(); |
| 5989 | } |
Alexander Musman | 09184fe | 2014-09-30 05:29:28 +0000 | [diff] [blame] | 5990 | if (CKind == OMPC_aligned && !Result.isPowerOf2()) { |
| 5991 | Diag(E->getExprLoc(), diag::warn_omp_alignment_not_power_of_two) |
| 5992 | << E->getSourceRange(); |
| 5993 | return ExprError(); |
| 5994 | } |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 5995 | if (CKind == OMPC_collapse && DSAStack->getAssociatedLoops() == 1) |
| 5996 | DSAStack->setAssociatedLoops(Result.getExtValue()); |
Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 5997 | else if (CKind == OMPC_ordered) |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 5998 | DSAStack->setAssociatedLoops(Result.getExtValue()); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5999 | return ICE; |
| 6000 | } |
| 6001 | |
| 6002 | OMPClause *Sema::ActOnOpenMPSafelenClause(Expr *Len, SourceLocation StartLoc, |
| 6003 | SourceLocation LParenLoc, |
| 6004 | SourceLocation EndLoc) { |
| 6005 | // OpenMP [2.8.1, simd construct, Description] |
| 6006 | // The parameter of the safelen clause must be a constant |
| 6007 | // positive integer expression. |
| 6008 | ExprResult Safelen = VerifyPositiveIntegerConstantInClause(Len, OMPC_safelen); |
| 6009 | if (Safelen.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6010 | return nullptr; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6011 | return new (Context) |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6012 | OMPSafelenClause(Safelen.get(), StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6013 | } |
| 6014 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 6015 | OMPClause *Sema::ActOnOpenMPSimdlenClause(Expr *Len, SourceLocation StartLoc, |
| 6016 | SourceLocation LParenLoc, |
| 6017 | SourceLocation EndLoc) { |
| 6018 | // OpenMP [2.8.1, simd construct, Description] |
| 6019 | // The parameter of the simdlen clause must be a constant |
| 6020 | // positive integer expression. |
| 6021 | ExprResult Simdlen = VerifyPositiveIntegerConstantInClause(Len, OMPC_simdlen); |
| 6022 | if (Simdlen.isInvalid()) |
| 6023 | return nullptr; |
| 6024 | return new (Context) |
| 6025 | OMPSimdlenClause(Simdlen.get(), StartLoc, LParenLoc, EndLoc); |
| 6026 | } |
| 6027 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6028 | OMPClause *Sema::ActOnOpenMPCollapseClause(Expr *NumForLoops, |
| 6029 | SourceLocation StartLoc, |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6030 | SourceLocation LParenLoc, |
| 6031 | SourceLocation EndLoc) { |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6032 | // OpenMP [2.7.1, loop construct, Description] |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6033 | // OpenMP [2.8.1, simd construct, Description] |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6034 | // OpenMP [2.9.6, distribute construct, Description] |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6035 | // The parameter of the collapse clause must be a constant |
| 6036 | // positive integer expression. |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6037 | ExprResult NumForLoopsResult = |
| 6038 | VerifyPositiveIntegerConstantInClause(NumForLoops, OMPC_collapse); |
| 6039 | if (NumForLoopsResult.isInvalid()) |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6040 | return nullptr; |
| 6041 | return new (Context) |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6042 | OMPCollapseClause(NumForLoopsResult.get(), StartLoc, LParenLoc, EndLoc); |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6043 | } |
| 6044 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 6045 | OMPClause *Sema::ActOnOpenMPOrderedClause(SourceLocation StartLoc, |
| 6046 | SourceLocation EndLoc, |
| 6047 | SourceLocation LParenLoc, |
| 6048 | Expr *NumForLoops) { |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 6049 | // OpenMP [2.7.1, loop construct, Description] |
| 6050 | // OpenMP [2.8.1, simd construct, Description] |
| 6051 | // OpenMP [2.9.6, distribute construct, Description] |
| 6052 | // The parameter of the ordered clause must be a constant |
| 6053 | // positive integer expression if any. |
| 6054 | if (NumForLoops && LParenLoc.isValid()) { |
| 6055 | ExprResult NumForLoopsResult = |
| 6056 | VerifyPositiveIntegerConstantInClause(NumForLoops, OMPC_ordered); |
| 6057 | if (NumForLoopsResult.isInvalid()) |
| 6058 | return nullptr; |
| 6059 | NumForLoops = NumForLoopsResult.get(); |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6060 | } else |
| 6061 | NumForLoops = nullptr; |
| 6062 | DSAStack->setOrderedRegion(/*IsOrdered=*/true, NumForLoops); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 6063 | return new (Context) |
| 6064 | OMPOrderedClause(NumForLoops, StartLoc, LParenLoc, EndLoc); |
| 6065 | } |
| 6066 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6067 | OMPClause *Sema::ActOnOpenMPSimpleClause( |
| 6068 | OpenMPClauseKind Kind, unsigned Argument, SourceLocation ArgumentLoc, |
| 6069 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6070 | OMPClause *Res = nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6071 | switch (Kind) { |
| 6072 | case OMPC_default: |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6073 | Res = |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6074 | ActOnOpenMPDefaultClause(static_cast<OpenMPDefaultClauseKind>(Argument), |
| 6075 | ArgumentLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6076 | break; |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6077 | case OMPC_proc_bind: |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6078 | Res = ActOnOpenMPProcBindClause( |
| 6079 | static_cast<OpenMPProcBindClauseKind>(Argument), ArgumentLoc, StartLoc, |
| 6080 | LParenLoc, EndLoc); |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6081 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6082 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 6083 | case OMPC_final: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6084 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6085 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 6086 | case OMPC_simdlen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6087 | case OMPC_collapse: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6088 | case OMPC_schedule: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6089 | case OMPC_private: |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6090 | case OMPC_firstprivate: |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6091 | case OMPC_lastprivate: |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6092 | case OMPC_shared: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6093 | case OMPC_reduction: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6094 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 6095 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6096 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6097 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6098 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6099 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 6100 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 6101 | case OMPC_mergeable: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6102 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 6103 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6104 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6105 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6106 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6107 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 6108 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6109 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 6110 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6111 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6112 | case OMPC_simd: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 6113 | case OMPC_map: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 6114 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6115 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6116 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 6117 | case OMPC_grainsize: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 6118 | case OMPC_nogroup: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6119 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 6120 | case OMPC_hint: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 6121 | case OMPC_dist_schedule: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6122 | case OMPC_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6123 | llvm_unreachable("Clause is not allowed."); |
| 6124 | } |
| 6125 | return Res; |
| 6126 | } |
| 6127 | |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6128 | static std::string |
| 6129 | getListOfPossibleValues(OpenMPClauseKind K, unsigned First, unsigned Last, |
| 6130 | ArrayRef<unsigned> Exclude = llvm::None) { |
| 6131 | std::string Values; |
| 6132 | unsigned Bound = Last >= 2 ? Last - 2 : 0; |
| 6133 | unsigned Skipped = Exclude.size(); |
| 6134 | auto S = Exclude.begin(), E = Exclude.end(); |
| 6135 | for (unsigned i = First; i < Last; ++i) { |
| 6136 | if (std::find(S, E, i) != E) { |
| 6137 | --Skipped; |
| 6138 | continue; |
| 6139 | } |
| 6140 | Values += "'"; |
| 6141 | Values += getOpenMPSimpleClauseTypeName(K, i); |
| 6142 | Values += "'"; |
| 6143 | if (i == Bound - Skipped) |
| 6144 | Values += " or "; |
| 6145 | else if (i != Bound + 1 - Skipped) |
| 6146 | Values += ", "; |
| 6147 | } |
| 6148 | return Values; |
| 6149 | } |
| 6150 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6151 | OMPClause *Sema::ActOnOpenMPDefaultClause(OpenMPDefaultClauseKind Kind, |
| 6152 | SourceLocation KindKwLoc, |
| 6153 | SourceLocation StartLoc, |
| 6154 | SourceLocation LParenLoc, |
| 6155 | SourceLocation EndLoc) { |
| 6156 | if (Kind == OMPC_DEFAULT_unknown) { |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 6157 | static_assert(OMPC_DEFAULT_unknown > 0, |
| 6158 | "OMPC_DEFAULT_unknown not greater than 0"); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6159 | Diag(KindKwLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6160 | << getListOfPossibleValues(OMPC_default, /*First=*/0, |
| 6161 | /*Last=*/OMPC_DEFAULT_unknown) |
| 6162 | << getOpenMPClauseName(OMPC_default); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6163 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6164 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6165 | switch (Kind) { |
| 6166 | case OMPC_DEFAULT_none: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6167 | DSAStack->setDefaultDSANone(KindKwLoc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6168 | break; |
| 6169 | case OMPC_DEFAULT_shared: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6170 | DSAStack->setDefaultDSAShared(KindKwLoc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6171 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6172 | case OMPC_DEFAULT_unknown: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6173 | llvm_unreachable("Clause kind is not allowed."); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6174 | break; |
| 6175 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6176 | return new (Context) |
| 6177 | OMPDefaultClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6178 | } |
| 6179 | |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6180 | OMPClause *Sema::ActOnOpenMPProcBindClause(OpenMPProcBindClauseKind Kind, |
| 6181 | SourceLocation KindKwLoc, |
| 6182 | SourceLocation StartLoc, |
| 6183 | SourceLocation LParenLoc, |
| 6184 | SourceLocation EndLoc) { |
| 6185 | if (Kind == OMPC_PROC_BIND_unknown) { |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6186 | Diag(KindKwLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6187 | << getListOfPossibleValues(OMPC_proc_bind, /*First=*/0, |
| 6188 | /*Last=*/OMPC_PROC_BIND_unknown) |
| 6189 | << getOpenMPClauseName(OMPC_proc_bind); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6190 | return nullptr; |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6191 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6192 | return new (Context) |
| 6193 | OMPProcBindClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6194 | } |
| 6195 | |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6196 | OMPClause *Sema::ActOnOpenMPSingleExprWithArgClause( |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6197 | OpenMPClauseKind Kind, ArrayRef<unsigned> Argument, Expr *Expr, |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6198 | SourceLocation StartLoc, SourceLocation LParenLoc, |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6199 | ArrayRef<SourceLocation> ArgumentLoc, SourceLocation DelimLoc, |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6200 | SourceLocation EndLoc) { |
| 6201 | OMPClause *Res = nullptr; |
| 6202 | switch (Kind) { |
| 6203 | case OMPC_schedule: |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6204 | enum { Modifier1, Modifier2, ScheduleKind, NumberOfElements }; |
| 6205 | assert(Argument.size() == NumberOfElements && |
| 6206 | ArgumentLoc.size() == NumberOfElements); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6207 | Res = ActOnOpenMPScheduleClause( |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6208 | static_cast<OpenMPScheduleClauseModifier>(Argument[Modifier1]), |
| 6209 | static_cast<OpenMPScheduleClauseModifier>(Argument[Modifier2]), |
| 6210 | static_cast<OpenMPScheduleClauseKind>(Argument[ScheduleKind]), Expr, |
| 6211 | StartLoc, LParenLoc, ArgumentLoc[Modifier1], ArgumentLoc[Modifier2], |
| 6212 | ArgumentLoc[ScheduleKind], DelimLoc, EndLoc); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6213 | break; |
| 6214 | case OMPC_if: |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6215 | assert(Argument.size() == 1 && ArgumentLoc.size() == 1); |
| 6216 | Res = ActOnOpenMPIfClause(static_cast<OpenMPDirectiveKind>(Argument.back()), |
| 6217 | Expr, StartLoc, LParenLoc, ArgumentLoc.back(), |
| 6218 | DelimLoc, EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6219 | break; |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 6220 | case OMPC_dist_schedule: |
| 6221 | Res = ActOnOpenMPDistScheduleClause( |
| 6222 | static_cast<OpenMPDistScheduleClauseKind>(Argument.back()), Expr, |
| 6223 | StartLoc, LParenLoc, ArgumentLoc.back(), DelimLoc, EndLoc); |
| 6224 | break; |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 6225 | case OMPC_final: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6226 | case OMPC_num_threads: |
| 6227 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 6228 | case OMPC_simdlen: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6229 | case OMPC_collapse: |
| 6230 | case OMPC_default: |
| 6231 | case OMPC_proc_bind: |
| 6232 | case OMPC_private: |
| 6233 | case OMPC_firstprivate: |
| 6234 | case OMPC_lastprivate: |
| 6235 | case OMPC_shared: |
| 6236 | case OMPC_reduction: |
| 6237 | case OMPC_linear: |
| 6238 | case OMPC_aligned: |
| 6239 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6240 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6241 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6242 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 6243 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 6244 | case OMPC_mergeable: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6245 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 6246 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6247 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6248 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6249 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6250 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 6251 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6252 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 6253 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6254 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6255 | case OMPC_simd: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 6256 | case OMPC_map: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 6257 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6258 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6259 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 6260 | case OMPC_grainsize: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 6261 | case OMPC_nogroup: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6262 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 6263 | case OMPC_hint: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6264 | case OMPC_unknown: |
| 6265 | llvm_unreachable("Clause is not allowed."); |
| 6266 | } |
| 6267 | return Res; |
| 6268 | } |
| 6269 | |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6270 | static bool checkScheduleModifiers(Sema &S, OpenMPScheduleClauseModifier M1, |
| 6271 | OpenMPScheduleClauseModifier M2, |
| 6272 | SourceLocation M1Loc, SourceLocation M2Loc) { |
| 6273 | if (M1 == OMPC_SCHEDULE_MODIFIER_unknown && M1Loc.isValid()) { |
| 6274 | SmallVector<unsigned, 2> Excluded; |
| 6275 | if (M2 != OMPC_SCHEDULE_MODIFIER_unknown) |
| 6276 | Excluded.push_back(M2); |
| 6277 | if (M2 == OMPC_SCHEDULE_MODIFIER_nonmonotonic) |
| 6278 | Excluded.push_back(OMPC_SCHEDULE_MODIFIER_monotonic); |
| 6279 | if (M2 == OMPC_SCHEDULE_MODIFIER_monotonic) |
| 6280 | Excluded.push_back(OMPC_SCHEDULE_MODIFIER_nonmonotonic); |
| 6281 | S.Diag(M1Loc, diag::err_omp_unexpected_clause_value) |
| 6282 | << getListOfPossibleValues(OMPC_schedule, |
| 6283 | /*First=*/OMPC_SCHEDULE_MODIFIER_unknown + 1, |
| 6284 | /*Last=*/OMPC_SCHEDULE_MODIFIER_last, |
| 6285 | Excluded) |
| 6286 | << getOpenMPClauseName(OMPC_schedule); |
| 6287 | return true; |
| 6288 | } |
| 6289 | return false; |
| 6290 | } |
| 6291 | |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6292 | OMPClause *Sema::ActOnOpenMPScheduleClause( |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6293 | OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2, |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6294 | OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6295 | SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc, |
| 6296 | SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) { |
| 6297 | if (checkScheduleModifiers(*this, M1, M2, M1Loc, M2Loc) || |
| 6298 | checkScheduleModifiers(*this, M2, M1, M2Loc, M1Loc)) |
| 6299 | return nullptr; |
| 6300 | // OpenMP, 2.7.1, Loop Construct, Restrictions |
| 6301 | // Either the monotonic modifier or the nonmonotonic modifier can be specified |
| 6302 | // but not both. |
| 6303 | if ((M1 == M2 && M1 != OMPC_SCHEDULE_MODIFIER_unknown) || |
| 6304 | (M1 == OMPC_SCHEDULE_MODIFIER_monotonic && |
| 6305 | M2 == OMPC_SCHEDULE_MODIFIER_nonmonotonic) || |
| 6306 | (M1 == OMPC_SCHEDULE_MODIFIER_nonmonotonic && |
| 6307 | M2 == OMPC_SCHEDULE_MODIFIER_monotonic)) { |
| 6308 | Diag(M2Loc, diag::err_omp_unexpected_schedule_modifier) |
| 6309 | << getOpenMPSimpleClauseTypeName(OMPC_schedule, M2) |
| 6310 | << getOpenMPSimpleClauseTypeName(OMPC_schedule, M1); |
| 6311 | return nullptr; |
| 6312 | } |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6313 | if (Kind == OMPC_SCHEDULE_unknown) { |
| 6314 | std::string Values; |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6315 | if (M1Loc.isInvalid() && M2Loc.isInvalid()) { |
| 6316 | unsigned Exclude[] = {OMPC_SCHEDULE_unknown}; |
| 6317 | Values = getListOfPossibleValues(OMPC_schedule, /*First=*/0, |
| 6318 | /*Last=*/OMPC_SCHEDULE_MODIFIER_last, |
| 6319 | Exclude); |
| 6320 | } else { |
| 6321 | Values = getListOfPossibleValues(OMPC_schedule, /*First=*/0, |
| 6322 | /*Last=*/OMPC_SCHEDULE_unknown); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6323 | } |
| 6324 | Diag(KindLoc, diag::err_omp_unexpected_clause_value) |
| 6325 | << Values << getOpenMPClauseName(OMPC_schedule); |
| 6326 | return nullptr; |
| 6327 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6328 | // OpenMP, 2.7.1, Loop Construct, Restrictions |
| 6329 | // The nonmonotonic modifier can only be specified with schedule(dynamic) or |
| 6330 | // schedule(guided). |
| 6331 | if ((M1 == OMPC_SCHEDULE_MODIFIER_nonmonotonic || |
| 6332 | M2 == OMPC_SCHEDULE_MODIFIER_nonmonotonic) && |
| 6333 | Kind != OMPC_SCHEDULE_dynamic && Kind != OMPC_SCHEDULE_guided) { |
| 6334 | Diag(M1 == OMPC_SCHEDULE_MODIFIER_nonmonotonic ? M1Loc : M2Loc, |
| 6335 | diag::err_omp_schedule_nonmonotonic_static); |
| 6336 | return nullptr; |
| 6337 | } |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6338 | Expr *ValExpr = ChunkSize; |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 6339 | Expr *HelperValExpr = nullptr; |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6340 | if (ChunkSize) { |
| 6341 | if (!ChunkSize->isValueDependent() && !ChunkSize->isTypeDependent() && |
| 6342 | !ChunkSize->isInstantiationDependent() && |
| 6343 | !ChunkSize->containsUnexpandedParameterPack()) { |
| 6344 | SourceLocation ChunkSizeLoc = ChunkSize->getLocStart(); |
| 6345 | ExprResult Val = |
| 6346 | PerformOpenMPImplicitIntegerConversion(ChunkSizeLoc, ChunkSize); |
| 6347 | if (Val.isInvalid()) |
| 6348 | return nullptr; |
| 6349 | |
| 6350 | ValExpr = Val.get(); |
| 6351 | |
| 6352 | // OpenMP [2.7.1, Restrictions] |
| 6353 | // chunk_size must be a loop invariant integer expression with a positive |
| 6354 | // value. |
| 6355 | llvm::APSInt Result; |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 6356 | if (ValExpr->isIntegerConstantExpr(Result, Context)) { |
| 6357 | if (Result.isSigned() && !Result.isStrictlyPositive()) { |
| 6358 | Diag(ChunkSizeLoc, diag::err_omp_negative_expression_in_clause) |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6359 | << "schedule" << 1 << ChunkSize->getSourceRange(); |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 6360 | return nullptr; |
| 6361 | } |
| 6362 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective())) { |
| 6363 | auto *ImpVar = buildVarDecl(*this, ChunkSize->getExprLoc(), |
| 6364 | ChunkSize->getType(), ".chunk."); |
| 6365 | auto *ImpVarRef = buildDeclRefExpr(*this, ImpVar, ChunkSize->getType(), |
| 6366 | ChunkSize->getExprLoc(), |
| 6367 | /*RefersToCapture=*/true); |
| 6368 | HelperValExpr = ImpVarRef; |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6369 | } |
| 6370 | } |
| 6371 | } |
| 6372 | |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6373 | return new (Context) |
| 6374 | OMPScheduleClause(StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc, Kind, |
| 6375 | ValExpr, HelperValExpr, M1, M1Loc, M2, M2Loc); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6376 | } |
| 6377 | |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6378 | OMPClause *Sema::ActOnOpenMPClause(OpenMPClauseKind Kind, |
| 6379 | SourceLocation StartLoc, |
| 6380 | SourceLocation EndLoc) { |
| 6381 | OMPClause *Res = nullptr; |
| 6382 | switch (Kind) { |
| 6383 | case OMPC_ordered: |
| 6384 | Res = ActOnOpenMPOrderedClause(StartLoc, EndLoc); |
| 6385 | break; |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6386 | case OMPC_nowait: |
| 6387 | Res = ActOnOpenMPNowaitClause(StartLoc, EndLoc); |
| 6388 | break; |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 6389 | case OMPC_untied: |
| 6390 | Res = ActOnOpenMPUntiedClause(StartLoc, EndLoc); |
| 6391 | break; |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 6392 | case OMPC_mergeable: |
| 6393 | Res = ActOnOpenMPMergeableClause(StartLoc, EndLoc); |
| 6394 | break; |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6395 | case OMPC_read: |
| 6396 | Res = ActOnOpenMPReadClause(StartLoc, EndLoc); |
| 6397 | break; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6398 | case OMPC_write: |
| 6399 | Res = ActOnOpenMPWriteClause(StartLoc, EndLoc); |
| 6400 | break; |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6401 | case OMPC_update: |
| 6402 | Res = ActOnOpenMPUpdateClause(StartLoc, EndLoc); |
| 6403 | break; |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6404 | case OMPC_capture: |
| 6405 | Res = ActOnOpenMPCaptureClause(StartLoc, EndLoc); |
| 6406 | break; |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 6407 | case OMPC_seq_cst: |
| 6408 | Res = ActOnOpenMPSeqCstClause(StartLoc, EndLoc); |
| 6409 | break; |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6410 | case OMPC_threads: |
| 6411 | Res = ActOnOpenMPThreadsClause(StartLoc, EndLoc); |
| 6412 | break; |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6413 | case OMPC_simd: |
| 6414 | Res = ActOnOpenMPSIMDClause(StartLoc, EndLoc); |
| 6415 | break; |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 6416 | case OMPC_nogroup: |
| 6417 | Res = ActOnOpenMPNogroupClause(StartLoc, EndLoc); |
| 6418 | break; |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6419 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 6420 | case OMPC_final: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6421 | case OMPC_num_threads: |
| 6422 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 6423 | case OMPC_simdlen: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6424 | case OMPC_collapse: |
| 6425 | case OMPC_schedule: |
| 6426 | case OMPC_private: |
| 6427 | case OMPC_firstprivate: |
| 6428 | case OMPC_lastprivate: |
| 6429 | case OMPC_shared: |
| 6430 | case OMPC_reduction: |
| 6431 | case OMPC_linear: |
| 6432 | case OMPC_aligned: |
| 6433 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6434 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6435 | case OMPC_default: |
| 6436 | case OMPC_proc_bind: |
| 6437 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 6438 | case OMPC_flush: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6439 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 6440 | case OMPC_device: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 6441 | case OMPC_map: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 6442 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6443 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6444 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 6445 | case OMPC_grainsize: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6446 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 6447 | case OMPC_hint: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 6448 | case OMPC_dist_schedule: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6449 | case OMPC_unknown: |
| 6450 | llvm_unreachable("Clause is not allowed."); |
| 6451 | } |
| 6452 | return Res; |
| 6453 | } |
| 6454 | |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6455 | OMPClause *Sema::ActOnOpenMPNowaitClause(SourceLocation StartLoc, |
| 6456 | SourceLocation EndLoc) { |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 6457 | DSAStack->setNowaitRegion(); |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6458 | return new (Context) OMPNowaitClause(StartLoc, EndLoc); |
| 6459 | } |
| 6460 | |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 6461 | OMPClause *Sema::ActOnOpenMPUntiedClause(SourceLocation StartLoc, |
| 6462 | SourceLocation EndLoc) { |
| 6463 | return new (Context) OMPUntiedClause(StartLoc, EndLoc); |
| 6464 | } |
| 6465 | |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 6466 | OMPClause *Sema::ActOnOpenMPMergeableClause(SourceLocation StartLoc, |
| 6467 | SourceLocation EndLoc) { |
| 6468 | return new (Context) OMPMergeableClause(StartLoc, EndLoc); |
| 6469 | } |
| 6470 | |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6471 | OMPClause *Sema::ActOnOpenMPReadClause(SourceLocation StartLoc, |
| 6472 | SourceLocation EndLoc) { |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6473 | return new (Context) OMPReadClause(StartLoc, EndLoc); |
| 6474 | } |
| 6475 | |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6476 | OMPClause *Sema::ActOnOpenMPWriteClause(SourceLocation StartLoc, |
| 6477 | SourceLocation EndLoc) { |
| 6478 | return new (Context) OMPWriteClause(StartLoc, EndLoc); |
| 6479 | } |
| 6480 | |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6481 | OMPClause *Sema::ActOnOpenMPUpdateClause(SourceLocation StartLoc, |
| 6482 | SourceLocation EndLoc) { |
| 6483 | return new (Context) OMPUpdateClause(StartLoc, EndLoc); |
| 6484 | } |
| 6485 | |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6486 | OMPClause *Sema::ActOnOpenMPCaptureClause(SourceLocation StartLoc, |
| 6487 | SourceLocation EndLoc) { |
| 6488 | return new (Context) OMPCaptureClause(StartLoc, EndLoc); |
| 6489 | } |
| 6490 | |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 6491 | OMPClause *Sema::ActOnOpenMPSeqCstClause(SourceLocation StartLoc, |
| 6492 | SourceLocation EndLoc) { |
| 6493 | return new (Context) OMPSeqCstClause(StartLoc, EndLoc); |
| 6494 | } |
| 6495 | |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6496 | OMPClause *Sema::ActOnOpenMPThreadsClause(SourceLocation StartLoc, |
| 6497 | SourceLocation EndLoc) { |
| 6498 | return new (Context) OMPThreadsClause(StartLoc, EndLoc); |
| 6499 | } |
| 6500 | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6501 | OMPClause *Sema::ActOnOpenMPSIMDClause(SourceLocation StartLoc, |
| 6502 | SourceLocation EndLoc) { |
| 6503 | return new (Context) OMPSIMDClause(StartLoc, EndLoc); |
| 6504 | } |
| 6505 | |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 6506 | OMPClause *Sema::ActOnOpenMPNogroupClause(SourceLocation StartLoc, |
| 6507 | SourceLocation EndLoc) { |
| 6508 | return new (Context) OMPNogroupClause(StartLoc, EndLoc); |
| 6509 | } |
| 6510 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6511 | OMPClause *Sema::ActOnOpenMPVarListClause( |
| 6512 | OpenMPClauseKind Kind, ArrayRef<Expr *> VarList, Expr *TailExpr, |
| 6513 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, |
| 6514 | SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6515 | const DeclarationNameInfo &ReductionId, OpenMPDependClauseKind DepKind, |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame^] | 6516 | OpenMPLinearClauseKind LinKind, OpenMPMapClauseKind MapTypeModifier, |
| 6517 | OpenMPMapClauseKind MapType, bool IsMapTypeImplicit, |
| 6518 | SourceLocation DepLinMapLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6519 | OMPClause *Res = nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6520 | switch (Kind) { |
| 6521 | case OMPC_private: |
| 6522 | Res = ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 6523 | break; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6524 | case OMPC_firstprivate: |
| 6525 | Res = ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 6526 | break; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6527 | case OMPC_lastprivate: |
| 6528 | Res = ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 6529 | break; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6530 | case OMPC_shared: |
| 6531 | Res = ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 6532 | break; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6533 | case OMPC_reduction: |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 6534 | Res = ActOnOpenMPReductionClause(VarList, StartLoc, LParenLoc, ColonLoc, |
| 6535 | EndLoc, ReductionIdScopeSpec, ReductionId); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6536 | break; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6537 | case OMPC_linear: |
| 6538 | Res = ActOnOpenMPLinearClause(VarList, TailExpr, StartLoc, LParenLoc, |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 6539 | LinKind, DepLinMapLoc, ColonLoc, EndLoc); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6540 | break; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 6541 | case OMPC_aligned: |
| 6542 | Res = ActOnOpenMPAlignedClause(VarList, TailExpr, StartLoc, LParenLoc, |
| 6543 | ColonLoc, EndLoc); |
| 6544 | break; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6545 | case OMPC_copyin: |
| 6546 | Res = ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 6547 | break; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6548 | case OMPC_copyprivate: |
| 6549 | Res = ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 6550 | break; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 6551 | case OMPC_flush: |
| 6552 | Res = ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 6553 | break; |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6554 | case OMPC_depend: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 6555 | Res = ActOnOpenMPDependClause(DepKind, DepLinMapLoc, ColonLoc, VarList, |
| 6556 | StartLoc, LParenLoc, EndLoc); |
| 6557 | break; |
| 6558 | case OMPC_map: |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame^] | 6559 | Res = ActOnOpenMPMapClause(MapTypeModifier, MapType, IsMapTypeImplicit, |
| 6560 | DepLinMapLoc, ColonLoc, VarList, StartLoc, |
| 6561 | LParenLoc, EndLoc); |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6562 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6563 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 6564 | case OMPC_final: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6565 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6566 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 6567 | case OMPC_simdlen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6568 | case OMPC_collapse: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6569 | case OMPC_default: |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6570 | case OMPC_proc_bind: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6571 | case OMPC_schedule: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6572 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6573 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 6574 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 6575 | case OMPC_mergeable: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6576 | case OMPC_threadprivate: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6577 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6578 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6579 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6580 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 6581 | case OMPC_seq_cst: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 6582 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6583 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6584 | case OMPC_simd: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 6585 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6586 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6587 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 6588 | case OMPC_grainsize: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 6589 | case OMPC_nogroup: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6590 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 6591 | case OMPC_hint: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 6592 | case OMPC_dist_schedule: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6593 | case OMPC_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6594 | llvm_unreachable("Clause is not allowed."); |
| 6595 | } |
| 6596 | return Res; |
| 6597 | } |
| 6598 | |
| 6599 | OMPClause *Sema::ActOnOpenMPPrivateClause(ArrayRef<Expr *> VarList, |
| 6600 | SourceLocation StartLoc, |
| 6601 | SourceLocation LParenLoc, |
| 6602 | SourceLocation EndLoc) { |
| 6603 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 6604 | SmallVector<Expr *, 8> PrivateCopies; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6605 | for (auto &RefExpr : VarList) { |
| 6606 | assert(RefExpr && "NULL expr in OpenMP private clause."); |
| 6607 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6608 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6609 | Vars.push_back(RefExpr); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 6610 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6611 | continue; |
| 6612 | } |
| 6613 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6614 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Carlo Bertolli | 9e8c6c1 | 2016-01-19 16:53:55 +0000 | [diff] [blame] | 6615 | // OpenMP [3.1, C/C++] |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6616 | // A list item is a variable name. |
| 6617 | // OpenMP [2.9.3.3, Restrictions, p.1] |
| 6618 | // A variable that is part of another variable (as an array or |
| 6619 | // structure element) cannot appear in a private clause. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6620 | DeclRefExpr *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6621 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6622 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6623 | continue; |
| 6624 | } |
| 6625 | Decl *D = DE->getDecl(); |
| 6626 | VarDecl *VD = cast<VarDecl>(D); |
| 6627 | |
| 6628 | QualType Type = VD->getType(); |
| 6629 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 6630 | // It will be analyzed later. |
| 6631 | Vars.push_back(DE); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 6632 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6633 | continue; |
| 6634 | } |
| 6635 | |
| 6636 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 6637 | // A variable that appears in a private clause must not have an incomplete |
| 6638 | // type or a reference type. |
| 6639 | if (RequireCompleteType(ELoc, Type, |
| 6640 | diag::err_omp_private_incomplete_type)) { |
| 6641 | continue; |
| 6642 | } |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 6643 | Type = Type.getNonReferenceType(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6644 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6645 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 6646 | // in a Construct] |
| 6647 | // Variables with the predetermined data-sharing attributes may not be |
| 6648 | // listed in data-sharing attributes clauses, except for the cases |
| 6649 | // listed below. For these exceptions only, listing a predetermined |
| 6650 | // variable in a data-sharing attribute clause is allowed and overrides |
| 6651 | // the variable's predetermined data-sharing attributes. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6652 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6653 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_private) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6654 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 6655 | << getOpenMPClauseName(OMPC_private); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 6656 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6657 | continue; |
| 6658 | } |
| 6659 | |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 6660 | // Variably modified types are not supported for tasks. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 6661 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType() && |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 6662 | DSAStack->getCurrentDirective() == OMPD_task) { |
| 6663 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
| 6664 | << getOpenMPClauseName(OMPC_private) << Type |
| 6665 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 6666 | bool IsDecl = |
| 6667 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 6668 | Diag(VD->getLocation(), |
| 6669 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 6670 | << VD; |
| 6671 | continue; |
| 6672 | } |
| 6673 | |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6674 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.1] |
| 6675 | // A variable of class type (or array thereof) that appears in a private |
| 6676 | // clause requires an accessible, unambiguous default constructor for the |
| 6677 | // class type. |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 6678 | // Generate helper private variable and initialize it with the default |
| 6679 | // value. The address of the original variable is replaced by the address of |
| 6680 | // the new private variable in CodeGen. This new variable is not added to |
| 6681 | // IdResolver, so the code in the OpenMP region uses original variable for |
| 6682 | // proper diagnostics. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6683 | Type = Type.getUnqualifiedType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 6684 | auto VDPrivate = buildVarDecl(*this, DE->getExprLoc(), Type, VD->getName(), |
| 6685 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6686 | ActOnUninitializedDecl(VDPrivate, /*TypeMayContainAuto=*/false); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 6687 | if (VDPrivate->isInvalidDecl()) |
| 6688 | continue; |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6689 | auto VDPrivateRefExpr = buildDeclRefExpr( |
| 6690 | *this, VDPrivate, DE->getType().getUnqualifiedType(), DE->getExprLoc()); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 6691 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6692 | DSAStack->addDSA(VD, DE, OMPC_private); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6693 | Vars.push_back(DE); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 6694 | PrivateCopies.push_back(VDPrivateRefExpr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6695 | } |
| 6696 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6697 | if (Vars.empty()) |
| 6698 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6699 | |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 6700 | return OMPPrivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
| 6701 | PrivateCopies); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6702 | } |
| 6703 | |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6704 | namespace { |
| 6705 | class DiagsUninitializedSeveretyRAII { |
| 6706 | private: |
| 6707 | DiagnosticsEngine &Diags; |
| 6708 | SourceLocation SavedLoc; |
| 6709 | bool IsIgnored; |
| 6710 | |
| 6711 | public: |
| 6712 | DiagsUninitializedSeveretyRAII(DiagnosticsEngine &Diags, SourceLocation Loc, |
| 6713 | bool IsIgnored) |
| 6714 | : Diags(Diags), SavedLoc(Loc), IsIgnored(IsIgnored) { |
| 6715 | if (!IsIgnored) { |
| 6716 | Diags.setSeverity(/*Diag*/ diag::warn_uninit_self_reference_in_init, |
| 6717 | /*Map*/ diag::Severity::Ignored, Loc); |
| 6718 | } |
| 6719 | } |
| 6720 | ~DiagsUninitializedSeveretyRAII() { |
| 6721 | if (!IsIgnored) |
| 6722 | Diags.popMappings(SavedLoc); |
| 6723 | } |
| 6724 | }; |
Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 6725 | } |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6726 | |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6727 | OMPClause *Sema::ActOnOpenMPFirstprivateClause(ArrayRef<Expr *> VarList, |
| 6728 | SourceLocation StartLoc, |
| 6729 | SourceLocation LParenLoc, |
| 6730 | SourceLocation EndLoc) { |
| 6731 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6732 | SmallVector<Expr *, 8> PrivateCopies; |
| 6733 | SmallVector<Expr *, 8> Inits; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6734 | bool IsImplicitClause = |
| 6735 | StartLoc.isInvalid() && LParenLoc.isInvalid() && EndLoc.isInvalid(); |
| 6736 | auto ImplicitClauseLoc = DSAStack->getConstructLoc(); |
| 6737 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6738 | for (auto &RefExpr : VarList) { |
| 6739 | assert(RefExpr && "NULL expr in OpenMP firstprivate clause."); |
| 6740 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6741 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6742 | Vars.push_back(RefExpr); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6743 | PrivateCopies.push_back(nullptr); |
| 6744 | Inits.push_back(nullptr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6745 | continue; |
| 6746 | } |
| 6747 | |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6748 | SourceLocation ELoc = |
| 6749 | IsImplicitClause ? ImplicitClauseLoc : RefExpr->getExprLoc(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6750 | // OpenMP [2.1, C/C++] |
| 6751 | // A list item is a variable name. |
| 6752 | // OpenMP [2.9.3.3, Restrictions, p.1] |
| 6753 | // A variable that is part of another variable (as an array or |
| 6754 | // structure element) cannot appear in a private clause. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6755 | DeclRefExpr *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6756 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6757 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6758 | continue; |
| 6759 | } |
| 6760 | Decl *D = DE->getDecl(); |
| 6761 | VarDecl *VD = cast<VarDecl>(D); |
| 6762 | |
| 6763 | QualType Type = VD->getType(); |
| 6764 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 6765 | // It will be analyzed later. |
| 6766 | Vars.push_back(DE); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6767 | PrivateCopies.push_back(nullptr); |
| 6768 | Inits.push_back(nullptr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6769 | continue; |
| 6770 | } |
| 6771 | |
| 6772 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 6773 | // A variable that appears in a private clause must not have an incomplete |
| 6774 | // type or a reference type. |
| 6775 | if (RequireCompleteType(ELoc, Type, |
| 6776 | diag::err_omp_firstprivate_incomplete_type)) { |
| 6777 | continue; |
| 6778 | } |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 6779 | Type = Type.getNonReferenceType(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6780 | |
| 6781 | // OpenMP [2.9.3.4, Restrictions, C/C++, p.1] |
| 6782 | // 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] | 6783 | // clause requires an accessible, unambiguous copy constructor for the |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6784 | // class type. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6785 | auto ElemType = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6786 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6787 | // If an implicit firstprivate variable found it was checked already. |
| 6788 | if (!IsImplicitClause) { |
| 6789 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6790 | bool IsConstant = ElemType.isConstant(Context); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6791 | // OpenMP [2.4.13, Data-sharing Attribute Clauses] |
| 6792 | // A list item that specifies a given variable may not appear in more |
| 6793 | // than one clause on the same directive, except that a variable may be |
| 6794 | // specified in both firstprivate and lastprivate clauses. |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6795 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_firstprivate && |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6796 | DVar.CKind != OMPC_lastprivate && DVar.RefExpr) { |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6797 | Diag(ELoc, diag::err_omp_wrong_dsa) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6798 | << getOpenMPClauseName(DVar.CKind) |
| 6799 | << getOpenMPClauseName(OMPC_firstprivate); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 6800 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6801 | continue; |
| 6802 | } |
| 6803 | |
| 6804 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 6805 | // in a Construct] |
| 6806 | // Variables with the predetermined data-sharing attributes may not be |
| 6807 | // listed in data-sharing attributes clauses, except for the cases |
| 6808 | // listed below. For these exceptions only, listing a predetermined |
| 6809 | // variable in a data-sharing attribute clause is allowed and overrides |
| 6810 | // the variable's predetermined data-sharing attributes. |
| 6811 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 6812 | // in a Construct, C/C++, p.2] |
| 6813 | // Variables with const-qualified type having no mutable member may be |
| 6814 | // listed in a firstprivate clause, even if they are static data members. |
| 6815 | if (!(IsConstant || VD->isStaticDataMember()) && !DVar.RefExpr && |
| 6816 | DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared) { |
| 6817 | Diag(ELoc, diag::err_omp_wrong_dsa) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6818 | << getOpenMPClauseName(DVar.CKind) |
| 6819 | << getOpenMPClauseName(OMPC_firstprivate); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 6820 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6821 | continue; |
| 6822 | } |
| 6823 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6824 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6825 | // OpenMP [2.9.3.4, Restrictions, p.2] |
| 6826 | // A list item that is private within a parallel region must not appear |
| 6827 | // in a firstprivate clause on a worksharing construct if any of the |
| 6828 | // worksharing regions arising from the worksharing construct ever bind |
| 6829 | // to any of the parallel regions arising from the parallel construct. |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 6830 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 6831 | !isOpenMPParallelDirective(CurrDir)) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6832 | DVar = DSAStack->getImplicitDSA(VD, true); |
| 6833 | if (DVar.CKind != OMPC_shared && |
| 6834 | (isOpenMPParallelDirective(DVar.DKind) || |
| 6835 | DVar.DKind == OMPD_unknown)) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6836 | Diag(ELoc, diag::err_omp_required_access) |
| 6837 | << getOpenMPClauseName(OMPC_firstprivate) |
| 6838 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 6839 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6840 | continue; |
| 6841 | } |
| 6842 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6843 | // OpenMP [2.9.3.4, Restrictions, p.3] |
| 6844 | // A list item that appears in a reduction clause of a parallel construct |
| 6845 | // must not appear in a firstprivate clause on a worksharing or task |
| 6846 | // construct if any of the worksharing or task regions arising from the |
| 6847 | // worksharing or task construct ever bind to any of the parallel regions |
| 6848 | // arising from the parallel construct. |
| 6849 | // OpenMP [2.9.3.4, Restrictions, p.4] |
| 6850 | // A list item that appears in a reduction clause in worksharing |
| 6851 | // construct must not appear in a firstprivate clause in a task construct |
| 6852 | // encountered during execution of any of the worksharing regions arising |
| 6853 | // from the worksharing construct. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6854 | if (CurrDir == OMPD_task) { |
| 6855 | DVar = |
| 6856 | DSAStack->hasInnermostDSA(VD, MatchesAnyClause(OMPC_reduction), |
| 6857 | [](OpenMPDirectiveKind K) -> bool { |
| 6858 | return isOpenMPParallelDirective(K) || |
| 6859 | isOpenMPWorksharingDirective(K); |
| 6860 | }, |
| 6861 | false); |
| 6862 | if (DVar.CKind == OMPC_reduction && |
| 6863 | (isOpenMPParallelDirective(DVar.DKind) || |
| 6864 | isOpenMPWorksharingDirective(DVar.DKind))) { |
| 6865 | Diag(ELoc, diag::err_omp_parallel_reduction_in_task_firstprivate) |
| 6866 | << getOpenMPDirectiveName(DVar.DKind); |
| 6867 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 6868 | continue; |
| 6869 | } |
| 6870 | } |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 6871 | |
| 6872 | // OpenMP 4.5 [2.15.3.4, Restrictions, p.3] |
| 6873 | // A list item that is private within a teams region must not appear in a |
| 6874 | // firstprivate clause on a distribute construct if any of the distribute |
| 6875 | // regions arising from the distribute construct ever bind to any of the |
| 6876 | // teams regions arising from the teams construct. |
| 6877 | // OpenMP 4.5 [2.15.3.4, Restrictions, p.3] |
| 6878 | // A list item that appears in a reduction clause of a teams construct |
| 6879 | // must not appear in a firstprivate clause on a distribute construct if |
| 6880 | // any of the distribute regions arising from the distribute construct |
| 6881 | // ever bind to any of the teams regions arising from the teams construct. |
| 6882 | // OpenMP 4.5 [2.10.8, Distribute Construct, p.3] |
| 6883 | // A list item may appear in a firstprivate or lastprivate clause but not |
| 6884 | // both. |
| 6885 | if (CurrDir == OMPD_distribute) { |
| 6886 | DVar = DSAStack->hasInnermostDSA(VD, MatchesAnyClause(OMPC_private), |
| 6887 | [](OpenMPDirectiveKind K) -> bool { |
| 6888 | return isOpenMPTeamsDirective(K); |
| 6889 | }, |
| 6890 | false); |
| 6891 | if (DVar.CKind == OMPC_private && isOpenMPTeamsDirective(DVar.DKind)) { |
| 6892 | Diag(ELoc, diag::err_omp_firstprivate_distribute_private_teams); |
| 6893 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 6894 | continue; |
| 6895 | } |
| 6896 | DVar = DSAStack->hasInnermostDSA(VD, MatchesAnyClause(OMPC_reduction), |
| 6897 | [](OpenMPDirectiveKind K) -> bool { |
| 6898 | return isOpenMPTeamsDirective(K); |
| 6899 | }, |
| 6900 | false); |
| 6901 | if (DVar.CKind == OMPC_reduction && |
| 6902 | isOpenMPTeamsDirective(DVar.DKind)) { |
| 6903 | Diag(ELoc, diag::err_omp_firstprivate_distribute_in_teams_reduction); |
| 6904 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 6905 | continue; |
| 6906 | } |
| 6907 | DVar = DSAStack->getTopDSA(VD, false); |
| 6908 | if (DVar.CKind == OMPC_lastprivate) { |
| 6909 | Diag(ELoc, diag::err_omp_firstprivate_and_lastprivate_in_distribute); |
| 6910 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 6911 | continue; |
| 6912 | } |
| 6913 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6914 | } |
| 6915 | |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 6916 | // Variably modified types are not supported for tasks. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 6917 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType() && |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 6918 | DSAStack->getCurrentDirective() == OMPD_task) { |
| 6919 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
| 6920 | << getOpenMPClauseName(OMPC_firstprivate) << Type |
| 6921 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 6922 | bool IsDecl = |
| 6923 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 6924 | Diag(VD->getLocation(), |
| 6925 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 6926 | << VD; |
| 6927 | continue; |
| 6928 | } |
| 6929 | |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6930 | Type = Type.getUnqualifiedType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 6931 | auto VDPrivate = buildVarDecl(*this, ELoc, Type, VD->getName(), |
| 6932 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6933 | // Generate helper private variable and initialize it with the value of the |
| 6934 | // original variable. The address of the original variable is replaced by |
| 6935 | // the address of the new private variable in the CodeGen. This new variable |
| 6936 | // is not added to IdResolver, so the code in the OpenMP region uses |
| 6937 | // original variable for proper diagnostics and variable capturing. |
| 6938 | Expr *VDInitRefExpr = nullptr; |
| 6939 | // For arrays generate initializer for single element and replace it by the |
| 6940 | // original array element in CodeGen. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6941 | if (Type->isArrayType()) { |
| 6942 | auto VDInit = |
| 6943 | buildVarDecl(*this, DE->getExprLoc(), ElemType, VD->getName()); |
| 6944 | VDInitRefExpr = buildDeclRefExpr(*this, VDInit, ElemType, ELoc); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6945 | auto Init = DefaultLvalueConversion(VDInitRefExpr).get(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6946 | ElemType = ElemType.getUnqualifiedType(); |
| 6947 | auto *VDInitTemp = buildVarDecl(*this, DE->getLocStart(), ElemType, |
| 6948 | ".firstprivate.temp"); |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 6949 | InitializedEntity Entity = |
| 6950 | InitializedEntity::InitializeVariable(VDInitTemp); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6951 | InitializationKind Kind = InitializationKind::CreateCopy(ELoc, ELoc); |
| 6952 | |
| 6953 | InitializationSequence InitSeq(*this, Entity, Kind, Init); |
| 6954 | ExprResult Result = InitSeq.Perform(*this, Entity, Kind, Init); |
| 6955 | if (Result.isInvalid()) |
| 6956 | VDPrivate->setInvalidDecl(); |
| 6957 | else |
| 6958 | VDPrivate->setInit(Result.getAs<Expr>()); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 6959 | // Remove temp variable declaration. |
| 6960 | Context.Deallocate(VDInitTemp); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6961 | } else { |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 6962 | auto *VDInit = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6963 | buildVarDecl(*this, DE->getLocStart(), Type, ".firstprivate.temp"); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6964 | VDInitRefExpr = |
| 6965 | buildDeclRefExpr(*this, VDInit, DE->getType(), DE->getExprLoc()); |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 6966 | AddInitializerToDecl(VDPrivate, |
| 6967 | DefaultLvalueConversion(VDInitRefExpr).get(), |
| 6968 | /*DirectInit=*/false, /*TypeMayContainAuto=*/false); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6969 | } |
| 6970 | if (VDPrivate->isInvalidDecl()) { |
| 6971 | if (IsImplicitClause) { |
| 6972 | Diag(DE->getExprLoc(), |
| 6973 | diag::note_omp_task_predetermined_firstprivate_here); |
| 6974 | } |
| 6975 | continue; |
| 6976 | } |
| 6977 | CurContext->addDecl(VDPrivate); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6978 | auto VDPrivateRefExpr = buildDeclRefExpr( |
| 6979 | *this, VDPrivate, DE->getType().getUnqualifiedType(), DE->getExprLoc()); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6980 | DSAStack->addDSA(VD, DE, OMPC_firstprivate); |
| 6981 | Vars.push_back(DE); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6982 | PrivateCopies.push_back(VDPrivateRefExpr); |
| 6983 | Inits.push_back(VDInitRefExpr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6984 | } |
| 6985 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6986 | if (Vars.empty()) |
| 6987 | return nullptr; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6988 | |
| 6989 | return OMPFirstprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6990 | Vars, PrivateCopies, Inits); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6991 | } |
| 6992 | |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6993 | OMPClause *Sema::ActOnOpenMPLastprivateClause(ArrayRef<Expr *> VarList, |
| 6994 | SourceLocation StartLoc, |
| 6995 | SourceLocation LParenLoc, |
| 6996 | SourceLocation EndLoc) { |
| 6997 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 6998 | SmallVector<Expr *, 8> SrcExprs; |
| 6999 | SmallVector<Expr *, 8> DstExprs; |
| 7000 | SmallVector<Expr *, 8> AssignmentOps; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7001 | for (auto &RefExpr : VarList) { |
| 7002 | assert(RefExpr && "NULL expr in OpenMP lastprivate clause."); |
| 7003 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 7004 | // It will be analyzed later. |
| 7005 | Vars.push_back(RefExpr); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7006 | SrcExprs.push_back(nullptr); |
| 7007 | DstExprs.push_back(nullptr); |
| 7008 | AssignmentOps.push_back(nullptr); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7009 | continue; |
| 7010 | } |
| 7011 | |
| 7012 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 7013 | // OpenMP [2.1, C/C++] |
| 7014 | // A list item is a variable name. |
| 7015 | // OpenMP [2.14.3.5, Restrictions, p.1] |
| 7016 | // A variable that is part of another variable (as an array or structure |
| 7017 | // element) cannot appear in a lastprivate clause. |
| 7018 | DeclRefExpr *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr); |
| 7019 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
| 7020 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
| 7021 | continue; |
| 7022 | } |
| 7023 | Decl *D = DE->getDecl(); |
| 7024 | VarDecl *VD = cast<VarDecl>(D); |
| 7025 | |
| 7026 | QualType Type = VD->getType(); |
| 7027 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 7028 | // It will be analyzed later. |
| 7029 | Vars.push_back(DE); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7030 | SrcExprs.push_back(nullptr); |
| 7031 | DstExprs.push_back(nullptr); |
| 7032 | AssignmentOps.push_back(nullptr); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7033 | continue; |
| 7034 | } |
| 7035 | |
| 7036 | // OpenMP [2.14.3.5, Restrictions, C/C++, p.2] |
| 7037 | // A variable that appears in a lastprivate clause must not have an |
| 7038 | // incomplete type or a reference type. |
| 7039 | if (RequireCompleteType(ELoc, Type, |
| 7040 | diag::err_omp_lastprivate_incomplete_type)) { |
| 7041 | continue; |
| 7042 | } |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7043 | Type = Type.getNonReferenceType(); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7044 | |
| 7045 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 7046 | // in a Construct] |
| 7047 | // Variables with the predetermined data-sharing attributes may not be |
| 7048 | // listed in data-sharing attributes clauses, except for the cases |
| 7049 | // listed below. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7050 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7051 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_lastprivate && |
| 7052 | DVar.CKind != OMPC_firstprivate && |
| 7053 | (DVar.CKind != OMPC_private || DVar.RefExpr != nullptr)) { |
| 7054 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 7055 | << getOpenMPClauseName(DVar.CKind) |
| 7056 | << getOpenMPClauseName(OMPC_lastprivate); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 7057 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7058 | continue; |
| 7059 | } |
| 7060 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7061 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
| 7062 | // OpenMP [2.14.3.5, Restrictions, p.2] |
| 7063 | // A list item that is private within a parallel region, or that appears in |
| 7064 | // the reduction clause of a parallel construct, must not appear in a |
| 7065 | // lastprivate clause on a worksharing construct if any of the corresponding |
| 7066 | // worksharing regions ever binds to any of the corresponding parallel |
| 7067 | // regions. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7068 | DSAStackTy::DSAVarData TopDVar = DVar; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 7069 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 7070 | !isOpenMPParallelDirective(CurrDir)) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7071 | DVar = DSAStack->getImplicitDSA(VD, true); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7072 | if (DVar.CKind != OMPC_shared) { |
| 7073 | Diag(ELoc, diag::err_omp_required_access) |
| 7074 | << getOpenMPClauseName(OMPC_lastprivate) |
| 7075 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 7076 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7077 | continue; |
| 7078 | } |
| 7079 | } |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7080 | // OpenMP [2.14.3.5, Restrictions, C++, p.1,2] |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7081 | // A variable of class type (or array thereof) that appears in a |
| 7082 | // lastprivate clause requires an accessible, unambiguous default |
| 7083 | // constructor for the class type, unless the list item is also specified |
| 7084 | // in a firstprivate clause. |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7085 | // A variable of class type (or array thereof) that appears in a |
| 7086 | // lastprivate clause requires an accessible, unambiguous copy assignment |
| 7087 | // operator for the class type. |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7088 | Type = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7089 | auto *SrcVD = buildVarDecl(*this, DE->getLocStart(), |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 7090 | Type.getUnqualifiedType(), ".lastprivate.src", |
| 7091 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7092 | auto *PseudoSrcExpr = buildDeclRefExpr( |
| 7093 | *this, SrcVD, Type.getUnqualifiedType(), DE->getExprLoc()); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7094 | auto *DstVD = |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 7095 | buildVarDecl(*this, DE->getLocStart(), Type, ".lastprivate.dst", |
| 7096 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7097 | auto *PseudoDstExpr = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7098 | buildDeclRefExpr(*this, DstVD, Type, DE->getExprLoc()); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7099 | // For arrays generate assignment operation for single element and replace |
| 7100 | // it by the original array element in CodeGen. |
| 7101 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, DE->getExprLoc(), BO_Assign, |
| 7102 | PseudoDstExpr, PseudoSrcExpr); |
| 7103 | if (AssignmentOp.isInvalid()) |
| 7104 | continue; |
| 7105 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), DE->getExprLoc(), |
| 7106 | /*DiscardedValue=*/true); |
| 7107 | if (AssignmentOp.isInvalid()) |
| 7108 | continue; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7109 | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7110 | // OpenMP 4.5 [2.10.8, Distribute Construct, p.3] |
| 7111 | // A list item may appear in a firstprivate or lastprivate clause but not |
| 7112 | // both. |
| 7113 | if (CurrDir == OMPD_distribute) { |
| 7114 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
| 7115 | if (DVar.CKind == OMPC_firstprivate) { |
| 7116 | Diag(ELoc, diag::err_omp_firstprivate_and_lastprivate_in_distribute); |
| 7117 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 7118 | continue; |
| 7119 | } |
| 7120 | } |
| 7121 | |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7122 | if (TopDVar.CKind != OMPC_firstprivate) |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7123 | DSAStack->addDSA(VD, DE, OMPC_lastprivate); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7124 | Vars.push_back(DE); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7125 | SrcExprs.push_back(PseudoSrcExpr); |
| 7126 | DstExprs.push_back(PseudoDstExpr); |
| 7127 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7128 | } |
| 7129 | |
| 7130 | if (Vars.empty()) |
| 7131 | return nullptr; |
| 7132 | |
| 7133 | return OMPLastprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7134 | Vars, SrcExprs, DstExprs, AssignmentOps); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7135 | } |
| 7136 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7137 | OMPClause *Sema::ActOnOpenMPSharedClause(ArrayRef<Expr *> VarList, |
| 7138 | SourceLocation StartLoc, |
| 7139 | SourceLocation LParenLoc, |
| 7140 | SourceLocation EndLoc) { |
| 7141 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7142 | for (auto &RefExpr : VarList) { |
| 7143 | assert(RefExpr && "NULL expr in OpenMP shared clause."); |
| 7144 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7145 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7146 | Vars.push_back(RefExpr); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7147 | continue; |
| 7148 | } |
| 7149 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7150 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7151 | // OpenMP [2.1, C/C++] |
| 7152 | // A list item is a variable name. |
Alexey Bataev | d4dbdf5 | 2014-03-06 12:27:56 +0000 | [diff] [blame] | 7153 | // OpenMP [2.14.3.2, Restrictions, p.1] |
| 7154 | // A variable that is part of another variable (as an array or structure |
| 7155 | // element) cannot appear in a shared unless it is a static data member |
| 7156 | // of a C++ class. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7157 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7158 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7159 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7160 | continue; |
| 7161 | } |
| 7162 | Decl *D = DE->getDecl(); |
| 7163 | VarDecl *VD = cast<VarDecl>(D); |
| 7164 | |
| 7165 | QualType Type = VD->getType(); |
| 7166 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 7167 | // It will be analyzed later. |
| 7168 | Vars.push_back(DE); |
| 7169 | continue; |
| 7170 | } |
| 7171 | |
| 7172 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 7173 | // in a Construct] |
| 7174 | // Variables with the predetermined data-sharing attributes may not be |
| 7175 | // listed in data-sharing attributes clauses, except for the cases |
| 7176 | // listed below. For these exceptions only, listing a predetermined |
| 7177 | // variable in a data-sharing attribute clause is allowed and overrides |
| 7178 | // the variable's predetermined data-sharing attributes. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7179 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7180 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared && |
| 7181 | DVar.RefExpr) { |
| 7182 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 7183 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 7184 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7185 | continue; |
| 7186 | } |
| 7187 | |
| 7188 | DSAStack->addDSA(VD, DE, OMPC_shared); |
| 7189 | Vars.push_back(DE); |
| 7190 | } |
| 7191 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7192 | if (Vars.empty()) |
| 7193 | return nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7194 | |
| 7195 | return OMPSharedClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars); |
| 7196 | } |
| 7197 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7198 | namespace { |
| 7199 | class DSARefChecker : public StmtVisitor<DSARefChecker, bool> { |
| 7200 | DSAStackTy *Stack; |
| 7201 | |
| 7202 | public: |
| 7203 | bool VisitDeclRefExpr(DeclRefExpr *E) { |
| 7204 | if (VarDecl *VD = dyn_cast<VarDecl>(E->getDecl())) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7205 | DSAStackTy::DSAVarData DVar = Stack->getTopDSA(VD, false); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7206 | if (DVar.CKind == OMPC_shared && !DVar.RefExpr) |
| 7207 | return false; |
| 7208 | if (DVar.CKind != OMPC_unknown) |
| 7209 | return true; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7210 | DSAStackTy::DSAVarData DVarPrivate = |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7211 | Stack->hasDSA(VD, isOpenMPPrivate, MatchesAlways(), false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7212 | if (DVarPrivate.CKind != OMPC_unknown) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7213 | return true; |
| 7214 | return false; |
| 7215 | } |
| 7216 | return false; |
| 7217 | } |
| 7218 | bool VisitStmt(Stmt *S) { |
| 7219 | for (auto Child : S->children()) { |
| 7220 | if (Child && Visit(Child)) |
| 7221 | return true; |
| 7222 | } |
| 7223 | return false; |
| 7224 | } |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 7225 | explicit DSARefChecker(DSAStackTy *S) : Stack(S) {} |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7226 | }; |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 7227 | } // namespace |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7228 | |
| 7229 | OMPClause *Sema::ActOnOpenMPReductionClause( |
| 7230 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, SourceLocation LParenLoc, |
| 7231 | SourceLocation ColonLoc, SourceLocation EndLoc, |
| 7232 | CXXScopeSpec &ReductionIdScopeSpec, |
| 7233 | const DeclarationNameInfo &ReductionId) { |
| 7234 | // TODO: Allow scope specification search when 'declare reduction' is |
| 7235 | // supported. |
| 7236 | assert(ReductionIdScopeSpec.isEmpty() && |
| 7237 | "No support for scoped reduction identifiers yet."); |
| 7238 | |
| 7239 | auto DN = ReductionId.getName(); |
| 7240 | auto OOK = DN.getCXXOverloadedOperator(); |
| 7241 | BinaryOperatorKind BOK = BO_Comma; |
| 7242 | |
| 7243 | // OpenMP [2.14.3.6, reduction clause] |
| 7244 | // C |
| 7245 | // reduction-identifier is either an identifier or one of the following |
| 7246 | // operators: +, -, *, &, |, ^, && and || |
| 7247 | // C++ |
| 7248 | // reduction-identifier is either an id-expression or one of the following |
| 7249 | // operators: +, -, *, &, |, ^, && and || |
| 7250 | // FIXME: Only 'min' and 'max' identifiers are supported for now. |
| 7251 | switch (OOK) { |
| 7252 | case OO_Plus: |
| 7253 | case OO_Minus: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7254 | BOK = BO_Add; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7255 | break; |
| 7256 | case OO_Star: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7257 | BOK = BO_Mul; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7258 | break; |
| 7259 | case OO_Amp: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7260 | BOK = BO_And; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7261 | break; |
| 7262 | case OO_Pipe: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7263 | BOK = BO_Or; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7264 | break; |
| 7265 | case OO_Caret: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7266 | BOK = BO_Xor; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7267 | break; |
| 7268 | case OO_AmpAmp: |
| 7269 | BOK = BO_LAnd; |
| 7270 | break; |
| 7271 | case OO_PipePipe: |
| 7272 | BOK = BO_LOr; |
| 7273 | break; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7274 | case OO_New: |
| 7275 | case OO_Delete: |
| 7276 | case OO_Array_New: |
| 7277 | case OO_Array_Delete: |
| 7278 | case OO_Slash: |
| 7279 | case OO_Percent: |
| 7280 | case OO_Tilde: |
| 7281 | case OO_Exclaim: |
| 7282 | case OO_Equal: |
| 7283 | case OO_Less: |
| 7284 | case OO_Greater: |
| 7285 | case OO_LessEqual: |
| 7286 | case OO_GreaterEqual: |
| 7287 | case OO_PlusEqual: |
| 7288 | case OO_MinusEqual: |
| 7289 | case OO_StarEqual: |
| 7290 | case OO_SlashEqual: |
| 7291 | case OO_PercentEqual: |
| 7292 | case OO_CaretEqual: |
| 7293 | case OO_AmpEqual: |
| 7294 | case OO_PipeEqual: |
| 7295 | case OO_LessLess: |
| 7296 | case OO_GreaterGreater: |
| 7297 | case OO_LessLessEqual: |
| 7298 | case OO_GreaterGreaterEqual: |
| 7299 | case OO_EqualEqual: |
| 7300 | case OO_ExclaimEqual: |
| 7301 | case OO_PlusPlus: |
| 7302 | case OO_MinusMinus: |
| 7303 | case OO_Comma: |
| 7304 | case OO_ArrowStar: |
| 7305 | case OO_Arrow: |
| 7306 | case OO_Call: |
| 7307 | case OO_Subscript: |
| 7308 | case OO_Conditional: |
Richard Smith | 9be594e | 2015-10-22 05:12:22 +0000 | [diff] [blame] | 7309 | case OO_Coawait: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7310 | case NUM_OVERLOADED_OPERATORS: |
| 7311 | llvm_unreachable("Unexpected reduction identifier"); |
| 7312 | case OO_None: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7313 | if (auto II = DN.getAsIdentifierInfo()) { |
| 7314 | if (II->isStr("max")) |
| 7315 | BOK = BO_GT; |
| 7316 | else if (II->isStr("min")) |
| 7317 | BOK = BO_LT; |
| 7318 | } |
| 7319 | break; |
| 7320 | } |
| 7321 | SourceRange ReductionIdRange; |
| 7322 | if (ReductionIdScopeSpec.isValid()) { |
| 7323 | ReductionIdRange.setBegin(ReductionIdScopeSpec.getBeginLoc()); |
| 7324 | } |
| 7325 | ReductionIdRange.setEnd(ReductionId.getEndLoc()); |
| 7326 | if (BOK == BO_Comma) { |
| 7327 | // Not allowed reduction identifier is found. |
| 7328 | Diag(ReductionId.getLocStart(), diag::err_omp_unknown_reduction_identifier) |
| 7329 | << ReductionIdRange; |
| 7330 | return nullptr; |
| 7331 | } |
| 7332 | |
| 7333 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7334 | SmallVector<Expr *, 8> Privates; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7335 | SmallVector<Expr *, 8> LHSs; |
| 7336 | SmallVector<Expr *, 8> RHSs; |
| 7337 | SmallVector<Expr *, 8> ReductionOps; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7338 | for (auto RefExpr : VarList) { |
| 7339 | assert(RefExpr && "nullptr expr in OpenMP reduction clause."); |
| 7340 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 7341 | // It will be analyzed later. |
| 7342 | Vars.push_back(RefExpr); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7343 | Privates.push_back(nullptr); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7344 | LHSs.push_back(nullptr); |
| 7345 | RHSs.push_back(nullptr); |
| 7346 | ReductionOps.push_back(nullptr); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7347 | continue; |
| 7348 | } |
| 7349 | |
| 7350 | if (RefExpr->isTypeDependent() || RefExpr->isValueDependent() || |
| 7351 | RefExpr->isInstantiationDependent() || |
| 7352 | RefExpr->containsUnexpandedParameterPack()) { |
| 7353 | // It will be analyzed later. |
| 7354 | Vars.push_back(RefExpr); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7355 | Privates.push_back(nullptr); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7356 | LHSs.push_back(nullptr); |
| 7357 | RHSs.push_back(nullptr); |
| 7358 | ReductionOps.push_back(nullptr); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7359 | continue; |
| 7360 | } |
| 7361 | |
| 7362 | auto ELoc = RefExpr->getExprLoc(); |
| 7363 | auto ERange = RefExpr->getSourceRange(); |
| 7364 | // OpenMP [2.1, C/C++] |
| 7365 | // A list item is a variable or array section, subject to the restrictions |
| 7366 | // specified in Section 2.4 on page 42 and in each of the sections |
| 7367 | // describing clauses and directives for which a list appears. |
| 7368 | // OpenMP [2.14.3.3, Restrictions, p.1] |
| 7369 | // A variable that is part of another variable (as an array or |
| 7370 | // structure element) cannot appear in a private clause. |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7371 | auto *DE = dyn_cast<DeclRefExpr>(RefExpr); |
| 7372 | auto *ASE = dyn_cast<ArraySubscriptExpr>(RefExpr); |
| 7373 | auto *OASE = dyn_cast<OMPArraySectionExpr>(RefExpr); |
| 7374 | if (!ASE && !OASE && (!DE || !isa<VarDecl>(DE->getDecl()))) { |
| 7375 | Diag(ELoc, diag::err_omp_expected_var_name_or_array_item) << ERange; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7376 | continue; |
| 7377 | } |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7378 | QualType Type; |
| 7379 | VarDecl *VD = nullptr; |
| 7380 | if (DE) { |
| 7381 | auto D = DE->getDecl(); |
| 7382 | VD = cast<VarDecl>(D); |
| 7383 | Type = VD->getType(); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7384 | } else if (ASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7385 | Type = ASE->getType(); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7386 | auto *Base = ASE->getBase()->IgnoreParenImpCasts(); |
| 7387 | while (auto *TempASE = dyn_cast<ArraySubscriptExpr>(Base)) |
| 7388 | Base = TempASE->getBase()->IgnoreParenImpCasts(); |
| 7389 | DE = dyn_cast<DeclRefExpr>(Base); |
| 7390 | if (DE) |
| 7391 | VD = dyn_cast<VarDecl>(DE->getDecl()); |
| 7392 | if (!VD) { |
| 7393 | Diag(Base->getExprLoc(), diag::err_omp_expected_base_var_name) |
| 7394 | << 0 << Base->getSourceRange(); |
| 7395 | continue; |
| 7396 | } |
| 7397 | } else if (OASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7398 | auto BaseType = OMPArraySectionExpr::getBaseOriginalType(OASE->getBase()); |
| 7399 | if (auto *ATy = BaseType->getAsArrayTypeUnsafe()) |
| 7400 | Type = ATy->getElementType(); |
| 7401 | else |
| 7402 | Type = BaseType->getPointeeType(); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7403 | auto *Base = OASE->getBase()->IgnoreParenImpCasts(); |
| 7404 | while (auto *TempOASE = dyn_cast<OMPArraySectionExpr>(Base)) |
| 7405 | Base = TempOASE->getBase()->IgnoreParenImpCasts(); |
| 7406 | while (auto *TempASE = dyn_cast<ArraySubscriptExpr>(Base)) |
| 7407 | Base = TempASE->getBase()->IgnoreParenImpCasts(); |
| 7408 | DE = dyn_cast<DeclRefExpr>(Base); |
| 7409 | if (DE) |
| 7410 | VD = dyn_cast<VarDecl>(DE->getDecl()); |
| 7411 | if (!VD) { |
| 7412 | Diag(Base->getExprLoc(), diag::err_omp_expected_base_var_name) |
| 7413 | << 1 << Base->getSourceRange(); |
| 7414 | continue; |
| 7415 | } |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7416 | } |
| 7417 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7418 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 7419 | // A variable that appears in a private clause must not have an incomplete |
| 7420 | // type or a reference type. |
| 7421 | if (RequireCompleteType(ELoc, Type, |
| 7422 | diag::err_omp_reduction_incomplete_type)) |
| 7423 | continue; |
| 7424 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
| 7425 | // Arrays may not appear in a reduction clause. |
| 7426 | if (Type.getNonReferenceType()->isArrayType()) { |
| 7427 | Diag(ELoc, diag::err_omp_reduction_type_array) << Type << ERange; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7428 | if (!ASE && !OASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7429 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 7430 | VarDecl::DeclarationOnly; |
| 7431 | Diag(VD->getLocation(), |
| 7432 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7433 | << VD; |
| 7434 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7435 | continue; |
| 7436 | } |
| 7437 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
| 7438 | // A list item that appears in a reduction clause must not be |
| 7439 | // const-qualified. |
| 7440 | if (Type.getNonReferenceType().isConstant(Context)) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7441 | Diag(ELoc, diag::err_omp_const_reduction_list_item) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7442 | << getOpenMPClauseName(OMPC_reduction) << Type << ERange; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7443 | if (!ASE && !OASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7444 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 7445 | VarDecl::DeclarationOnly; |
| 7446 | Diag(VD->getLocation(), |
| 7447 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7448 | << VD; |
| 7449 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7450 | continue; |
| 7451 | } |
| 7452 | // OpenMP [2.9.3.6, Restrictions, C/C++, p.4] |
| 7453 | // If a list-item is a reference type then it must bind to the same object |
| 7454 | // for all threads of the team. |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7455 | if (!ASE && !OASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7456 | VarDecl *VDDef = VD->getDefinition(); |
| 7457 | if (Type->isReferenceType() && VDDef) { |
| 7458 | DSARefChecker Check(DSAStack); |
| 7459 | if (Check.Visit(VDDef->getInit())) { |
| 7460 | Diag(ELoc, diag::err_omp_reduction_ref_type_arg) << ERange; |
| 7461 | Diag(VDDef->getLocation(), diag::note_defined_here) << VDDef; |
| 7462 | continue; |
| 7463 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7464 | } |
| 7465 | } |
| 7466 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
| 7467 | // The type of a list item that appears in a reduction clause must be valid |
| 7468 | // for the reduction-identifier. For a max or min reduction in C, the type |
| 7469 | // of the list item must be an allowed arithmetic data type: char, int, |
| 7470 | // float, double, or _Bool, possibly modified with long, short, signed, or |
| 7471 | // unsigned. For a max or min reduction in C++, the type of the list item |
| 7472 | // must be an allowed arithmetic data type: char, wchar_t, int, float, |
| 7473 | // double, or bool, possibly modified with long, short, signed, or unsigned. |
| 7474 | if ((BOK == BO_GT || BOK == BO_LT) && |
| 7475 | !(Type->isScalarType() || |
| 7476 | (getLangOpts().CPlusPlus && Type->isArithmeticType()))) { |
| 7477 | Diag(ELoc, diag::err_omp_clause_not_arithmetic_type_arg) |
| 7478 | << getLangOpts().CPlusPlus; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7479 | if (!ASE && !OASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7480 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 7481 | VarDecl::DeclarationOnly; |
| 7482 | Diag(VD->getLocation(), |
| 7483 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7484 | << VD; |
| 7485 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7486 | continue; |
| 7487 | } |
| 7488 | if ((BOK == BO_OrAssign || BOK == BO_AndAssign || BOK == BO_XorAssign) && |
| 7489 | !getLangOpts().CPlusPlus && Type->isFloatingType()) { |
| 7490 | Diag(ELoc, diag::err_omp_clause_floating_type_arg); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7491 | if (!ASE && !OASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7492 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 7493 | VarDecl::DeclarationOnly; |
| 7494 | Diag(VD->getLocation(), |
| 7495 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7496 | << VD; |
| 7497 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7498 | continue; |
| 7499 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7500 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 7501 | // in a Construct] |
| 7502 | // Variables with the predetermined data-sharing attributes may not be |
| 7503 | // listed in data-sharing attributes clauses, except for the cases |
| 7504 | // listed below. For these exceptions only, listing a predetermined |
| 7505 | // variable in a data-sharing attribute clause is allowed and overrides |
| 7506 | // the variable's predetermined data-sharing attributes. |
| 7507 | // OpenMP [2.14.3.6, Restrictions, p.3] |
| 7508 | // Any number of reduction clauses can be specified on the directive, |
| 7509 | // but a list item can appear only once in the reduction clauses for that |
| 7510 | // directive. |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7511 | DSAStackTy::DSAVarData DVar; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7512 | DVar = DSAStack->getTopDSA(VD, false); |
| 7513 | if (DVar.CKind == OMPC_reduction) { |
| 7514 | Diag(ELoc, diag::err_omp_once_referenced) |
| 7515 | << getOpenMPClauseName(OMPC_reduction); |
| 7516 | if (DVar.RefExpr) { |
| 7517 | Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_referenced); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7518 | } |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7519 | } else if (DVar.CKind != OMPC_unknown) { |
| 7520 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 7521 | << getOpenMPClauseName(DVar.CKind) |
| 7522 | << getOpenMPClauseName(OMPC_reduction); |
| 7523 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 7524 | continue; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7525 | } |
| 7526 | |
| 7527 | // OpenMP [2.14.3.6, Restrictions, p.1] |
| 7528 | // A list item that appears in a reduction clause of a worksharing |
| 7529 | // construct must be shared in the parallel regions to which any of the |
| 7530 | // worksharing regions arising from the worksharing construct bind. |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7531 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
| 7532 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 7533 | !isOpenMPParallelDirective(CurrDir)) { |
| 7534 | DVar = DSAStack->getImplicitDSA(VD, true); |
| 7535 | if (DVar.CKind != OMPC_shared) { |
| 7536 | Diag(ELoc, diag::err_omp_required_access) |
| 7537 | << getOpenMPClauseName(OMPC_reduction) |
| 7538 | << getOpenMPClauseName(OMPC_shared); |
| 7539 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 7540 | continue; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7541 | } |
| 7542 | } |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7543 | |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7544 | Type = Type.getNonLValueExprType(Context).getUnqualifiedType(); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7545 | auto *LHSVD = buildVarDecl(*this, ELoc, Type, ".reduction.lhs", |
| 7546 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
| 7547 | auto *RHSVD = buildVarDecl(*this, ELoc, Type, VD->getName(), |
| 7548 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
| 7549 | auto PrivateTy = Type; |
| 7550 | if (OASE) { |
| 7551 | // For array sections only: |
| 7552 | // Create pseudo array type for private copy. The size for this array will |
| 7553 | // be generated during codegen. |
| 7554 | // For array subscripts or single variables Private Ty is the same as Type |
| 7555 | // (type of the variable or single array element). |
| 7556 | PrivateTy = Context.getVariableArrayType( |
| 7557 | Type, new (Context) OpaqueValueExpr(SourceLocation(), |
| 7558 | Context.getSizeType(), VK_RValue), |
| 7559 | ArrayType::Normal, /*IndexTypeQuals=*/0, SourceRange()); |
| 7560 | } |
| 7561 | // Private copy. |
| 7562 | auto *PrivateVD = buildVarDecl(*this, ELoc, PrivateTy, VD->getName(), |
| 7563 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7564 | // Add initializer for private variable. |
| 7565 | Expr *Init = nullptr; |
| 7566 | switch (BOK) { |
| 7567 | case BO_Add: |
| 7568 | case BO_Xor: |
| 7569 | case BO_Or: |
| 7570 | case BO_LOr: |
| 7571 | // '+', '-', '^', '|', '||' reduction ops - initializer is '0'. |
| 7572 | if (Type->isScalarType() || Type->isAnyComplexType()) { |
| 7573 | Init = ActOnIntegerConstant(ELoc, /*Val=*/0).get(); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7574 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7575 | break; |
| 7576 | case BO_Mul: |
| 7577 | case BO_LAnd: |
| 7578 | if (Type->isScalarType() || Type->isAnyComplexType()) { |
| 7579 | // '*' and '&&' reduction ops - initializer is '1'. |
| 7580 | Init = ActOnIntegerConstant(ELoc, /*Val=*/1).get(); |
| 7581 | } |
| 7582 | break; |
| 7583 | case BO_And: { |
| 7584 | // '&' reduction op - initializer is '~0'. |
| 7585 | QualType OrigType = Type; |
| 7586 | if (auto *ComplexTy = OrigType->getAs<ComplexType>()) { |
| 7587 | Type = ComplexTy->getElementType(); |
| 7588 | } |
| 7589 | if (Type->isRealFloatingType()) { |
| 7590 | llvm::APFloat InitValue = |
| 7591 | llvm::APFloat::getAllOnesValue(Context.getTypeSize(Type), |
| 7592 | /*isIEEE=*/true); |
| 7593 | Init = FloatingLiteral::Create(Context, InitValue, /*isexact=*/true, |
| 7594 | Type, ELoc); |
| 7595 | } else if (Type->isScalarType()) { |
| 7596 | auto Size = Context.getTypeSize(Type); |
| 7597 | QualType IntTy = Context.getIntTypeForBitwidth(Size, /*Signed=*/0); |
| 7598 | llvm::APInt InitValue = llvm::APInt::getAllOnesValue(Size); |
| 7599 | Init = IntegerLiteral::Create(Context, InitValue, IntTy, ELoc); |
| 7600 | } |
| 7601 | if (Init && OrigType->isAnyComplexType()) { |
| 7602 | // Init = 0xFFFF + 0xFFFFi; |
| 7603 | auto *Im = new (Context) ImaginaryLiteral(Init, OrigType); |
| 7604 | Init = CreateBuiltinBinOp(ELoc, BO_Add, Init, Im).get(); |
| 7605 | } |
| 7606 | Type = OrigType; |
| 7607 | break; |
| 7608 | } |
| 7609 | case BO_LT: |
| 7610 | case BO_GT: { |
| 7611 | // 'min' reduction op - initializer is 'Largest representable number in |
| 7612 | // the reduction list item type'. |
| 7613 | // 'max' reduction op - initializer is 'Least representable number in |
| 7614 | // the reduction list item type'. |
| 7615 | if (Type->isIntegerType() || Type->isPointerType()) { |
| 7616 | bool IsSigned = Type->hasSignedIntegerRepresentation(); |
| 7617 | auto Size = Context.getTypeSize(Type); |
| 7618 | QualType IntTy = |
| 7619 | Context.getIntTypeForBitwidth(Size, /*Signed=*/IsSigned); |
| 7620 | llvm::APInt InitValue = |
| 7621 | (BOK != BO_LT) |
| 7622 | ? IsSigned ? llvm::APInt::getSignedMinValue(Size) |
| 7623 | : llvm::APInt::getMinValue(Size) |
| 7624 | : IsSigned ? llvm::APInt::getSignedMaxValue(Size) |
| 7625 | : llvm::APInt::getMaxValue(Size); |
| 7626 | Init = IntegerLiteral::Create(Context, InitValue, IntTy, ELoc); |
| 7627 | if (Type->isPointerType()) { |
| 7628 | // Cast to pointer type. |
| 7629 | auto CastExpr = BuildCStyleCastExpr( |
| 7630 | SourceLocation(), Context.getTrivialTypeSourceInfo(Type, ELoc), |
| 7631 | SourceLocation(), Init); |
| 7632 | if (CastExpr.isInvalid()) |
| 7633 | continue; |
| 7634 | Init = CastExpr.get(); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7635 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7636 | } else if (Type->isRealFloatingType()) { |
| 7637 | llvm::APFloat InitValue = llvm::APFloat::getLargest( |
| 7638 | Context.getFloatTypeSemantics(Type), BOK != BO_LT); |
| 7639 | Init = FloatingLiteral::Create(Context, InitValue, /*isexact=*/true, |
| 7640 | Type, ELoc); |
| 7641 | } |
| 7642 | break; |
| 7643 | } |
| 7644 | case BO_PtrMemD: |
| 7645 | case BO_PtrMemI: |
| 7646 | case BO_MulAssign: |
| 7647 | case BO_Div: |
| 7648 | case BO_Rem: |
| 7649 | case BO_Sub: |
| 7650 | case BO_Shl: |
| 7651 | case BO_Shr: |
| 7652 | case BO_LE: |
| 7653 | case BO_GE: |
| 7654 | case BO_EQ: |
| 7655 | case BO_NE: |
| 7656 | case BO_AndAssign: |
| 7657 | case BO_XorAssign: |
| 7658 | case BO_OrAssign: |
| 7659 | case BO_Assign: |
| 7660 | case BO_AddAssign: |
| 7661 | case BO_SubAssign: |
| 7662 | case BO_DivAssign: |
| 7663 | case BO_RemAssign: |
| 7664 | case BO_ShlAssign: |
| 7665 | case BO_ShrAssign: |
| 7666 | case BO_Comma: |
| 7667 | llvm_unreachable("Unexpected reduction operation"); |
| 7668 | } |
| 7669 | if (Init) { |
| 7670 | AddInitializerToDecl(RHSVD, Init, /*DirectInit=*/false, |
| 7671 | /*TypeMayContainAuto=*/false); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7672 | } else |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7673 | ActOnUninitializedDecl(RHSVD, /*TypeMayContainAuto=*/false); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7674 | if (!RHSVD->hasInit()) { |
| 7675 | Diag(ELoc, diag::err_omp_reduction_id_not_compatible) << Type |
| 7676 | << ReductionIdRange; |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7677 | if (VD) { |
| 7678 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 7679 | VarDecl::DeclarationOnly; |
| 7680 | Diag(VD->getLocation(), |
| 7681 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7682 | << VD; |
| 7683 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7684 | continue; |
| 7685 | } |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7686 | // Store initializer for single element in private copy. Will be used during |
| 7687 | // codegen. |
| 7688 | PrivateVD->setInit(RHSVD->getInit()); |
| 7689 | PrivateVD->setInitStyle(RHSVD->getInitStyle()); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7690 | auto *LHSDRE = buildDeclRefExpr(*this, LHSVD, Type, ELoc); |
| 7691 | auto *RHSDRE = buildDeclRefExpr(*this, RHSVD, Type, ELoc); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7692 | auto *PrivateDRE = buildDeclRefExpr(*this, PrivateVD, PrivateTy, ELoc); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7693 | ExprResult ReductionOp = |
| 7694 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), BOK, |
| 7695 | LHSDRE, RHSDRE); |
| 7696 | if (ReductionOp.isUsable()) { |
Alexey Bataev | 69a4779 | 2015-05-07 03:54:03 +0000 | [diff] [blame] | 7697 | if (BOK != BO_LT && BOK != BO_GT) { |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7698 | ReductionOp = |
| 7699 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), |
| 7700 | BO_Assign, LHSDRE, ReductionOp.get()); |
| 7701 | } else { |
| 7702 | auto *ConditionalOp = new (Context) ConditionalOperator( |
| 7703 | ReductionOp.get(), SourceLocation(), LHSDRE, SourceLocation(), |
| 7704 | RHSDRE, Type, VK_LValue, OK_Ordinary); |
| 7705 | ReductionOp = |
| 7706 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), |
| 7707 | BO_Assign, LHSDRE, ConditionalOp); |
| 7708 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 7709 | ReductionOp = ActOnFinishFullExpr(ReductionOp.get()); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7710 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7711 | if (ReductionOp.isInvalid()) |
| 7712 | continue; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7713 | |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7714 | DSAStack->addDSA(VD, DE, OMPC_reduction); |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7715 | Vars.push_back(RefExpr); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7716 | Privates.push_back(PrivateDRE); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7717 | LHSs.push_back(LHSDRE); |
| 7718 | RHSs.push_back(RHSDRE); |
| 7719 | ReductionOps.push_back(ReductionOp.get()); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7720 | } |
| 7721 | |
| 7722 | if (Vars.empty()) |
| 7723 | return nullptr; |
| 7724 | |
| 7725 | return OMPReductionClause::Create( |
| 7726 | Context, StartLoc, LParenLoc, ColonLoc, EndLoc, Vars, |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7727 | ReductionIdScopeSpec.getWithLocInContext(Context), ReductionId, Privates, |
| 7728 | LHSs, RHSs, ReductionOps); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7729 | } |
| 7730 | |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 7731 | OMPClause *Sema::ActOnOpenMPLinearClause( |
| 7732 | ArrayRef<Expr *> VarList, Expr *Step, SourceLocation StartLoc, |
| 7733 | SourceLocation LParenLoc, OpenMPLinearClauseKind LinKind, |
| 7734 | SourceLocation LinLoc, SourceLocation ColonLoc, SourceLocation EndLoc) { |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7735 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7736 | SmallVector<Expr *, 8> Privates; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7737 | SmallVector<Expr *, 8> Inits; |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 7738 | if ((!LangOpts.CPlusPlus && LinKind != OMPC_LINEAR_val) || |
| 7739 | LinKind == OMPC_LINEAR_unknown) { |
| 7740 | Diag(LinLoc, diag::err_omp_wrong_linear_modifier) << LangOpts.CPlusPlus; |
| 7741 | LinKind = OMPC_LINEAR_val; |
| 7742 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7743 | for (auto &RefExpr : VarList) { |
| 7744 | assert(RefExpr && "NULL expr in OpenMP linear clause."); |
| 7745 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7746 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7747 | Vars.push_back(RefExpr); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7748 | Privates.push_back(nullptr); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7749 | Inits.push_back(nullptr); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7750 | continue; |
| 7751 | } |
| 7752 | |
| 7753 | // OpenMP [2.14.3.7, linear clause] |
| 7754 | // A list item that appears in a linear clause is subject to the private |
| 7755 | // clause semantics described in Section 2.14.3.3 on page 159 except as |
| 7756 | // noted. In addition, the value of the new list item on each iteration |
| 7757 | // of the associated loop(s) corresponds to the value of the original |
| 7758 | // list item before entering the construct plus the logical number of |
| 7759 | // the iteration times linear-step. |
| 7760 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7761 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7762 | // OpenMP [2.1, C/C++] |
| 7763 | // A list item is a variable name. |
| 7764 | // OpenMP [2.14.3.3, Restrictions, p.1] |
| 7765 | // A variable that is part of another variable (as an array or |
| 7766 | // structure element) cannot appear in a private clause. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7767 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7768 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7769 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7770 | continue; |
| 7771 | } |
| 7772 | |
| 7773 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); |
| 7774 | |
| 7775 | // OpenMP [2.14.3.7, linear clause] |
| 7776 | // A list-item cannot appear in more than one linear clause. |
| 7777 | // A list-item that appears in a linear clause cannot appear in any |
| 7778 | // other data-sharing attribute clause. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7779 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7780 | if (DVar.RefExpr) { |
| 7781 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 7782 | << getOpenMPClauseName(OMPC_linear); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 7783 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7784 | continue; |
| 7785 | } |
| 7786 | |
| 7787 | QualType QType = VD->getType(); |
| 7788 | if (QType->isDependentType() || QType->isInstantiationDependentType()) { |
| 7789 | // It will be analyzed later. |
| 7790 | Vars.push_back(DE); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7791 | Privates.push_back(nullptr); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7792 | Inits.push_back(nullptr); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7793 | continue; |
| 7794 | } |
| 7795 | |
| 7796 | // A variable must not have an incomplete type or a reference type. |
| 7797 | if (RequireCompleteType(ELoc, QType, |
| 7798 | diag::err_omp_linear_incomplete_type)) { |
| 7799 | continue; |
| 7800 | } |
Alexey Bataev | 1185e19 | 2015-08-20 12:15:57 +0000 | [diff] [blame] | 7801 | if ((LinKind == OMPC_LINEAR_uval || LinKind == OMPC_LINEAR_ref) && |
| 7802 | !QType->isReferenceType()) { |
| 7803 | Diag(ELoc, diag::err_omp_wrong_linear_modifier_non_reference) |
| 7804 | << QType << getOpenMPSimpleClauseTypeName(OMPC_linear, LinKind); |
| 7805 | continue; |
| 7806 | } |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7807 | QType = QType.getNonReferenceType(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7808 | |
| 7809 | // A list item must not be const-qualified. |
| 7810 | if (QType.isConstant(Context)) { |
| 7811 | Diag(ELoc, diag::err_omp_const_variable) |
| 7812 | << getOpenMPClauseName(OMPC_linear); |
| 7813 | bool IsDecl = |
| 7814 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 7815 | Diag(VD->getLocation(), |
| 7816 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7817 | << VD; |
| 7818 | continue; |
| 7819 | } |
| 7820 | |
| 7821 | // A list item must be of integral or pointer type. |
| 7822 | QType = QType.getUnqualifiedType().getCanonicalType(); |
| 7823 | const Type *Ty = QType.getTypePtrOrNull(); |
| 7824 | if (!Ty || (!Ty->isDependentType() && !Ty->isIntegralType(Context) && |
| 7825 | !Ty->isPointerType())) { |
| 7826 | Diag(ELoc, diag::err_omp_linear_expected_int_or_ptr) << QType; |
| 7827 | bool IsDecl = |
| 7828 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 7829 | Diag(VD->getLocation(), |
| 7830 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7831 | << VD; |
| 7832 | continue; |
| 7833 | } |
| 7834 | |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7835 | // Build private copy of original var. |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 7836 | auto *Private = buildVarDecl(*this, ELoc, QType, VD->getName(), |
| 7837 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7838 | auto *PrivateRef = buildDeclRefExpr( |
| 7839 | *this, Private, DE->getType().getUnqualifiedType(), DE->getExprLoc()); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7840 | // Build var to save initial value. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7841 | VarDecl *Init = buildVarDecl(*this, ELoc, QType, ".linear.start"); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 7842 | Expr *InitExpr; |
| 7843 | if (LinKind == OMPC_LINEAR_uval) |
| 7844 | InitExpr = VD->getInit(); |
| 7845 | else |
| 7846 | InitExpr = DE; |
| 7847 | AddInitializerToDecl(Init, DefaultLvalueConversion(InitExpr).get(), |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7848 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7849 | auto InitRef = buildDeclRefExpr( |
| 7850 | *this, Init, DE->getType().getUnqualifiedType(), DE->getExprLoc()); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7851 | DSAStack->addDSA(VD, DE, OMPC_linear); |
| 7852 | Vars.push_back(DE); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7853 | Privates.push_back(PrivateRef); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7854 | Inits.push_back(InitRef); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7855 | } |
| 7856 | |
| 7857 | if (Vars.empty()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 7858 | return nullptr; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7859 | |
| 7860 | Expr *StepExpr = Step; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7861 | Expr *CalcStepExpr = nullptr; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7862 | if (Step && !Step->isValueDependent() && !Step->isTypeDependent() && |
| 7863 | !Step->isInstantiationDependent() && |
| 7864 | !Step->containsUnexpandedParameterPack()) { |
| 7865 | SourceLocation StepLoc = Step->getLocStart(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 7866 | ExprResult Val = PerformOpenMPImplicitIntegerConversion(StepLoc, Step); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7867 | if (Val.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 7868 | return nullptr; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 7869 | StepExpr = Val.get(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7870 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7871 | // Build var to save the step value. |
| 7872 | VarDecl *SaveVar = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7873 | buildVarDecl(*this, StepLoc, StepExpr->getType(), ".linear.step"); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7874 | ExprResult SaveRef = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7875 | buildDeclRefExpr(*this, SaveVar, StepExpr->getType(), StepLoc); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7876 | ExprResult CalcStep = |
| 7877 | BuildBinOp(CurScope, StepLoc, BO_Assign, SaveRef.get(), StepExpr); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 7878 | CalcStep = ActOnFinishFullExpr(CalcStep.get()); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7879 | |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7880 | // Warn about zero linear step (it would be probably better specified as |
| 7881 | // making corresponding variables 'const'). |
| 7882 | llvm::APSInt Result; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7883 | bool IsConstant = StepExpr->isIntegerConstantExpr(Result, Context); |
| 7884 | if (IsConstant && !Result.isNegative() && !Result.isStrictlyPositive()) |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7885 | Diag(StepLoc, diag::warn_omp_linear_step_zero) << Vars[0] |
| 7886 | << (Vars.size() > 1); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7887 | if (!IsConstant && CalcStep.isUsable()) { |
| 7888 | // Calculate the step beforehand instead of doing this on each iteration. |
| 7889 | // (This is not used if the number of iterations may be kfold-ed). |
| 7890 | CalcStepExpr = CalcStep.get(); |
| 7891 | } |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7892 | } |
| 7893 | |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 7894 | return OMPLinearClause::Create(Context, StartLoc, LParenLoc, LinKind, LinLoc, |
| 7895 | ColonLoc, EndLoc, Vars, Privates, Inits, |
| 7896 | StepExpr, CalcStepExpr); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7897 | } |
| 7898 | |
| 7899 | static bool FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV, |
| 7900 | Expr *NumIterations, Sema &SemaRef, |
| 7901 | Scope *S) { |
| 7902 | // Walk the vars and build update/final expressions for the CodeGen. |
| 7903 | SmallVector<Expr *, 8> Updates; |
| 7904 | SmallVector<Expr *, 8> Finals; |
| 7905 | Expr *Step = Clause.getStep(); |
| 7906 | Expr *CalcStep = Clause.getCalcStep(); |
| 7907 | // OpenMP [2.14.3.7, linear clause] |
| 7908 | // If linear-step is not specified it is assumed to be 1. |
| 7909 | if (Step == nullptr) |
| 7910 | Step = SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get(); |
| 7911 | else if (CalcStep) |
| 7912 | Step = cast<BinaryOperator>(CalcStep)->getLHS(); |
| 7913 | bool HasErrors = false; |
| 7914 | auto CurInit = Clause.inits().begin(); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7915 | auto CurPrivate = Clause.privates().begin(); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 7916 | auto LinKind = Clause.getModifier(); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7917 | for (auto &RefExpr : Clause.varlists()) { |
| 7918 | Expr *InitExpr = *CurInit; |
| 7919 | |
| 7920 | // Build privatized reference to the current linear var. |
| 7921 | auto DE = cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 7922 | Expr *CapturedRef; |
| 7923 | if (LinKind == OMPC_LINEAR_uval) |
| 7924 | CapturedRef = cast<VarDecl>(DE->getDecl())->getInit(); |
| 7925 | else |
| 7926 | CapturedRef = |
| 7927 | buildDeclRefExpr(SemaRef, cast<VarDecl>(DE->getDecl()), |
| 7928 | DE->getType().getUnqualifiedType(), DE->getExprLoc(), |
| 7929 | /*RefersToCapture=*/true); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7930 | |
| 7931 | // Build update: Var = InitExpr + IV * Step |
| 7932 | ExprResult Update = |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7933 | BuildCounterUpdate(SemaRef, S, RefExpr->getExprLoc(), *CurPrivate, |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7934 | InitExpr, IV, Step, /* Subtract */ false); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 7935 | Update = SemaRef.ActOnFinishFullExpr(Update.get(), DE->getLocStart(), |
| 7936 | /*DiscardedValue=*/true); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7937 | |
| 7938 | // Build final: Var = InitExpr + NumIterations * Step |
| 7939 | ExprResult Final = |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7940 | BuildCounterUpdate(SemaRef, S, RefExpr->getExprLoc(), CapturedRef, |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7941 | InitExpr, NumIterations, Step, /* Subtract */ false); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 7942 | Final = SemaRef.ActOnFinishFullExpr(Final.get(), DE->getLocStart(), |
| 7943 | /*DiscardedValue=*/true); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7944 | if (!Update.isUsable() || !Final.isUsable()) { |
| 7945 | Updates.push_back(nullptr); |
| 7946 | Finals.push_back(nullptr); |
| 7947 | HasErrors = true; |
| 7948 | } else { |
| 7949 | Updates.push_back(Update.get()); |
| 7950 | Finals.push_back(Final.get()); |
| 7951 | } |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7952 | ++CurInit, ++CurPrivate; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7953 | } |
| 7954 | Clause.setUpdates(Updates); |
| 7955 | Clause.setFinals(Finals); |
| 7956 | return HasErrors; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7957 | } |
| 7958 | |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 7959 | OMPClause *Sema::ActOnOpenMPAlignedClause( |
| 7960 | ArrayRef<Expr *> VarList, Expr *Alignment, SourceLocation StartLoc, |
| 7961 | SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc) { |
| 7962 | |
| 7963 | SmallVector<Expr *, 8> Vars; |
| 7964 | for (auto &RefExpr : VarList) { |
| 7965 | assert(RefExpr && "NULL expr in OpenMP aligned clause."); |
| 7966 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 7967 | // It will be analyzed later. |
| 7968 | Vars.push_back(RefExpr); |
| 7969 | continue; |
| 7970 | } |
| 7971 | |
| 7972 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 7973 | // OpenMP [2.1, C/C++] |
| 7974 | // A list item is a variable name. |
| 7975 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
| 7976 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
| 7977 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
| 7978 | continue; |
| 7979 | } |
| 7980 | |
| 7981 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); |
| 7982 | |
| 7983 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 7984 | // The type of list items appearing in the aligned clause must be |
| 7985 | // array, pointer, reference to array, or reference to pointer. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7986 | QualType QType = VD->getType(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7987 | QType = QType.getNonReferenceType().getUnqualifiedType().getCanonicalType(); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 7988 | const Type *Ty = QType.getTypePtrOrNull(); |
| 7989 | if (!Ty || (!Ty->isDependentType() && !Ty->isArrayType() && |
| 7990 | !Ty->isPointerType())) { |
| 7991 | Diag(ELoc, diag::err_omp_aligned_expected_array_or_ptr) |
| 7992 | << QType << getLangOpts().CPlusPlus << RefExpr->getSourceRange(); |
| 7993 | bool IsDecl = |
| 7994 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 7995 | Diag(VD->getLocation(), |
| 7996 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7997 | << VD; |
| 7998 | continue; |
| 7999 | } |
| 8000 | |
| 8001 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 8002 | // A list-item cannot appear in more than one aligned clause. |
| 8003 | if (DeclRefExpr *PrevRef = DSAStack->addUniqueAligned(VD, DE)) { |
| 8004 | Diag(ELoc, diag::err_omp_aligned_twice) << RefExpr->getSourceRange(); |
| 8005 | Diag(PrevRef->getExprLoc(), diag::note_omp_explicit_dsa) |
| 8006 | << getOpenMPClauseName(OMPC_aligned); |
| 8007 | continue; |
| 8008 | } |
| 8009 | |
| 8010 | Vars.push_back(DE); |
| 8011 | } |
| 8012 | |
| 8013 | // OpenMP [2.8.1, simd construct, Description] |
| 8014 | // The parameter of the aligned clause, alignment, must be a constant |
| 8015 | // positive integer expression. |
| 8016 | // If no optional parameter is specified, implementation-defined default |
| 8017 | // alignments for SIMD instructions on the target platforms are assumed. |
| 8018 | if (Alignment != nullptr) { |
| 8019 | ExprResult AlignResult = |
| 8020 | VerifyPositiveIntegerConstantInClause(Alignment, OMPC_aligned); |
| 8021 | if (AlignResult.isInvalid()) |
| 8022 | return nullptr; |
| 8023 | Alignment = AlignResult.get(); |
| 8024 | } |
| 8025 | if (Vars.empty()) |
| 8026 | return nullptr; |
| 8027 | |
| 8028 | return OMPAlignedClause::Create(Context, StartLoc, LParenLoc, ColonLoc, |
| 8029 | EndLoc, Vars, Alignment); |
| 8030 | } |
| 8031 | |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8032 | OMPClause *Sema::ActOnOpenMPCopyinClause(ArrayRef<Expr *> VarList, |
| 8033 | SourceLocation StartLoc, |
| 8034 | SourceLocation LParenLoc, |
| 8035 | SourceLocation EndLoc) { |
| 8036 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 8037 | SmallVector<Expr *, 8> SrcExprs; |
| 8038 | SmallVector<Expr *, 8> DstExprs; |
| 8039 | SmallVector<Expr *, 8> AssignmentOps; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8040 | for (auto &RefExpr : VarList) { |
| 8041 | assert(RefExpr && "NULL expr in OpenMP copyin clause."); |
| 8042 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8043 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8044 | Vars.push_back(RefExpr); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 8045 | SrcExprs.push_back(nullptr); |
| 8046 | DstExprs.push_back(nullptr); |
| 8047 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8048 | continue; |
| 8049 | } |
| 8050 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8051 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8052 | // OpenMP [2.1, C/C++] |
| 8053 | // A list item is a variable name. |
| 8054 | // OpenMP [2.14.4.1, Restrictions, p.1] |
| 8055 | // A list item that appears in a copyin clause must be threadprivate. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8056 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8057 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8058 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8059 | continue; |
| 8060 | } |
| 8061 | |
| 8062 | Decl *D = DE->getDecl(); |
| 8063 | VarDecl *VD = cast<VarDecl>(D); |
| 8064 | |
| 8065 | QualType Type = VD->getType(); |
| 8066 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 8067 | // It will be analyzed later. |
| 8068 | Vars.push_back(DE); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 8069 | SrcExprs.push_back(nullptr); |
| 8070 | DstExprs.push_back(nullptr); |
| 8071 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8072 | continue; |
| 8073 | } |
| 8074 | |
| 8075 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.1] |
| 8076 | // A list item that appears in a copyin clause must be threadprivate. |
| 8077 | if (!DSAStack->isThreadPrivate(VD)) { |
| 8078 | Diag(ELoc, diag::err_omp_required_access) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8079 | << getOpenMPClauseName(OMPC_copyin) |
| 8080 | << getOpenMPDirectiveName(OMPD_threadprivate); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8081 | continue; |
| 8082 | } |
| 8083 | |
| 8084 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.2] |
| 8085 | // A variable of class type (or array thereof) that appears in a |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 8086 | // copyin clause requires an accessible, unambiguous copy assignment |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8087 | // operator for the class type. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8088 | auto ElemType = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 8089 | auto *SrcVD = |
| 8090 | buildVarDecl(*this, DE->getLocStart(), ElemType.getUnqualifiedType(), |
| 8091 | ".copyin.src", VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 8092 | auto *PseudoSrcExpr = buildDeclRefExpr( |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8093 | *this, SrcVD, ElemType.getUnqualifiedType(), DE->getExprLoc()); |
| 8094 | auto *DstVD = |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 8095 | buildVarDecl(*this, DE->getLocStart(), ElemType, ".copyin.dst", |
| 8096 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 8097 | auto *PseudoDstExpr = |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8098 | buildDeclRefExpr(*this, DstVD, ElemType, DE->getExprLoc()); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 8099 | // For arrays generate assignment operation for single element and replace |
| 8100 | // it by the original array element in CodeGen. |
| 8101 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, DE->getExprLoc(), BO_Assign, |
| 8102 | PseudoDstExpr, PseudoSrcExpr); |
| 8103 | if (AssignmentOp.isInvalid()) |
| 8104 | continue; |
| 8105 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), DE->getExprLoc(), |
| 8106 | /*DiscardedValue=*/true); |
| 8107 | if (AssignmentOp.isInvalid()) |
| 8108 | continue; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8109 | |
| 8110 | DSAStack->addDSA(VD, DE, OMPC_copyin); |
| 8111 | Vars.push_back(DE); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 8112 | SrcExprs.push_back(PseudoSrcExpr); |
| 8113 | DstExprs.push_back(PseudoDstExpr); |
| 8114 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8115 | } |
| 8116 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8117 | if (Vars.empty()) |
| 8118 | return nullptr; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8119 | |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 8120 | return OMPCopyinClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
| 8121 | SrcExprs, DstExprs, AssignmentOps); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8122 | } |
| 8123 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8124 | OMPClause *Sema::ActOnOpenMPCopyprivateClause(ArrayRef<Expr *> VarList, |
| 8125 | SourceLocation StartLoc, |
| 8126 | SourceLocation LParenLoc, |
| 8127 | SourceLocation EndLoc) { |
| 8128 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 8129 | SmallVector<Expr *, 8> SrcExprs; |
| 8130 | SmallVector<Expr *, 8> DstExprs; |
| 8131 | SmallVector<Expr *, 8> AssignmentOps; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8132 | for (auto &RefExpr : VarList) { |
| 8133 | assert(RefExpr && "NULL expr in OpenMP copyprivate clause."); |
| 8134 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 8135 | // It will be analyzed later. |
| 8136 | Vars.push_back(RefExpr); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 8137 | SrcExprs.push_back(nullptr); |
| 8138 | DstExprs.push_back(nullptr); |
| 8139 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8140 | continue; |
| 8141 | } |
| 8142 | |
| 8143 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 8144 | // OpenMP [2.1, C/C++] |
| 8145 | // A list item is a variable name. |
| 8146 | // OpenMP [2.14.4.1, Restrictions, p.1] |
| 8147 | // A list item that appears in a copyin clause must be threadprivate. |
| 8148 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
| 8149 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
| 8150 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
| 8151 | continue; |
| 8152 | } |
| 8153 | |
| 8154 | Decl *D = DE->getDecl(); |
| 8155 | VarDecl *VD = cast<VarDecl>(D); |
| 8156 | |
| 8157 | QualType Type = VD->getType(); |
| 8158 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 8159 | // It will be analyzed later. |
| 8160 | Vars.push_back(DE); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 8161 | SrcExprs.push_back(nullptr); |
| 8162 | DstExprs.push_back(nullptr); |
| 8163 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8164 | continue; |
| 8165 | } |
| 8166 | |
| 8167 | // OpenMP [2.14.4.2, Restrictions, p.2] |
| 8168 | // A list item that appears in a copyprivate clause may not appear in a |
| 8169 | // private or firstprivate clause on the single construct. |
| 8170 | if (!DSAStack->isThreadPrivate(VD)) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 8171 | auto DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 8172 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_copyprivate && |
| 8173 | DVar.RefExpr) { |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8174 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 8175 | << getOpenMPClauseName(DVar.CKind) |
| 8176 | << getOpenMPClauseName(OMPC_copyprivate); |
| 8177 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 8178 | continue; |
| 8179 | } |
| 8180 | |
| 8181 | // OpenMP [2.11.4.2, Restrictions, p.1] |
| 8182 | // All list items that appear in a copyprivate clause must be either |
| 8183 | // threadprivate or private in the enclosing context. |
| 8184 | if (DVar.CKind == OMPC_unknown) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 8185 | DVar = DSAStack->getImplicitDSA(VD, false); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8186 | if (DVar.CKind == OMPC_shared) { |
| 8187 | Diag(ELoc, diag::err_omp_required_access) |
| 8188 | << getOpenMPClauseName(OMPC_copyprivate) |
| 8189 | << "threadprivate or private in the enclosing context"; |
| 8190 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 8191 | continue; |
| 8192 | } |
| 8193 | } |
| 8194 | } |
| 8195 | |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 8196 | // Variably modified types are not supported. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 8197 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType()) { |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 8198 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8199 | << getOpenMPClauseName(OMPC_copyprivate) << Type |
| 8200 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 8201 | bool IsDecl = |
| 8202 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 8203 | Diag(VD->getLocation(), |
| 8204 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 8205 | << VD; |
| 8206 | continue; |
| 8207 | } |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8208 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8209 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.2] |
| 8210 | // A variable of class type (or array thereof) that appears in a |
| 8211 | // copyin clause requires an accessible, unambiguous copy assignment |
| 8212 | // operator for the class type. |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8213 | Type = Context.getBaseElementType(Type.getNonReferenceType()) |
| 8214 | .getUnqualifiedType(); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 8215 | auto *SrcVD = |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 8216 | buildVarDecl(*this, DE->getLocStart(), Type, ".copyprivate.src", |
| 8217 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 8218 | auto *PseudoSrcExpr = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 8219 | buildDeclRefExpr(*this, SrcVD, Type, DE->getExprLoc()); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 8220 | auto *DstVD = |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 8221 | buildVarDecl(*this, DE->getLocStart(), Type, ".copyprivate.dst", |
| 8222 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 8223 | auto *PseudoDstExpr = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 8224 | buildDeclRefExpr(*this, DstVD, Type, DE->getExprLoc()); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 8225 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, DE->getExprLoc(), BO_Assign, |
| 8226 | PseudoDstExpr, PseudoSrcExpr); |
| 8227 | if (AssignmentOp.isInvalid()) |
| 8228 | continue; |
| 8229 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), DE->getExprLoc(), |
| 8230 | /*DiscardedValue=*/true); |
| 8231 | if (AssignmentOp.isInvalid()) |
| 8232 | continue; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8233 | |
| 8234 | // No need to mark vars as copyprivate, they are already threadprivate or |
| 8235 | // implicitly private. |
| 8236 | Vars.push_back(DE); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 8237 | SrcExprs.push_back(PseudoSrcExpr); |
| 8238 | DstExprs.push_back(PseudoDstExpr); |
| 8239 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8240 | } |
| 8241 | |
| 8242 | if (Vars.empty()) |
| 8243 | return nullptr; |
| 8244 | |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 8245 | return OMPCopyprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| 8246 | Vars, SrcExprs, DstExprs, AssignmentOps); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8247 | } |
| 8248 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 8249 | OMPClause *Sema::ActOnOpenMPFlushClause(ArrayRef<Expr *> VarList, |
| 8250 | SourceLocation StartLoc, |
| 8251 | SourceLocation LParenLoc, |
| 8252 | SourceLocation EndLoc) { |
| 8253 | if (VarList.empty()) |
| 8254 | return nullptr; |
| 8255 | |
| 8256 | return OMPFlushClause::Create(Context, StartLoc, LParenLoc, EndLoc, VarList); |
| 8257 | } |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 8258 | |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8259 | OMPClause * |
| 8260 | Sema::ActOnOpenMPDependClause(OpenMPDependClauseKind DepKind, |
| 8261 | SourceLocation DepLoc, SourceLocation ColonLoc, |
| 8262 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
| 8263 | SourceLocation LParenLoc, SourceLocation EndLoc) { |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 8264 | if (DSAStack->getCurrentDirective() == OMPD_ordered && |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 8265 | DepKind != OMPC_DEPEND_source && DepKind != OMPC_DEPEND_sink) { |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 8266 | Diag(DepLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 8267 | << "'source' or 'sink'" << getOpenMPClauseName(OMPC_depend); |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 8268 | return nullptr; |
| 8269 | } |
| 8270 | if (DSAStack->getCurrentDirective() != OMPD_ordered && |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 8271 | (DepKind == OMPC_DEPEND_unknown || DepKind == OMPC_DEPEND_source || |
| 8272 | DepKind == OMPC_DEPEND_sink)) { |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 8273 | unsigned Except[] = {OMPC_DEPEND_source, OMPC_DEPEND_sink}; |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8274 | Diag(DepLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 8275 | << getListOfPossibleValues(OMPC_depend, /*First=*/0, |
| 8276 | /*Last=*/OMPC_DEPEND_unknown, Except) |
| 8277 | << getOpenMPClauseName(OMPC_depend); |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8278 | return nullptr; |
| 8279 | } |
| 8280 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 8281 | llvm::APSInt DepCounter(/*BitWidth=*/32); |
| 8282 | llvm::APSInt TotalDepCount(/*BitWidth=*/32); |
| 8283 | if (DepKind == OMPC_DEPEND_sink) { |
| 8284 | if (auto *OrderedCountExpr = DSAStack->getParentOrderedRegionParam()) { |
| 8285 | TotalDepCount = OrderedCountExpr->EvaluateKnownConstInt(Context); |
| 8286 | TotalDepCount.setIsUnsigned(/*Val=*/true); |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8287 | } |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8288 | } |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 8289 | if ((DepKind != OMPC_DEPEND_sink && DepKind != OMPC_DEPEND_source) || |
| 8290 | DSAStack->getParentOrderedRegionParam()) { |
| 8291 | for (auto &RefExpr : VarList) { |
| 8292 | assert(RefExpr && "NULL expr in OpenMP shared clause."); |
| 8293 | if (isa<DependentScopeDeclRefExpr>(RefExpr) || |
| 8294 | (DepKind == OMPC_DEPEND_sink && CurContext->isDependentContext())) { |
| 8295 | // It will be analyzed later. |
| 8296 | Vars.push_back(RefExpr); |
| 8297 | continue; |
| 8298 | } |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8299 | |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 8300 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 8301 | auto *SimpleExpr = RefExpr->IgnoreParenCasts(); |
| 8302 | if (DepKind == OMPC_DEPEND_sink) { |
| 8303 | if (DepCounter >= TotalDepCount) { |
| 8304 | Diag(ELoc, diag::err_omp_depend_sink_unexpected_expr); |
| 8305 | continue; |
| 8306 | } |
| 8307 | ++DepCounter; |
| 8308 | // OpenMP [2.13.9, Summary] |
| 8309 | // depend(dependence-type : vec), where dependence-type is: |
| 8310 | // 'sink' and where vec is the iteration vector, which has the form: |
| 8311 | // x1 [+- d1], x2 [+- d2 ], . . . , xn [+- dn] |
| 8312 | // where n is the value specified by the ordered clause in the loop |
| 8313 | // directive, xi denotes the loop iteration variable of the i-th nested |
| 8314 | // loop associated with the loop directive, and di is a constant |
| 8315 | // non-negative integer. |
| 8316 | SimpleExpr = SimpleExpr->IgnoreImplicit(); |
| 8317 | auto *DE = dyn_cast<DeclRefExpr>(SimpleExpr); |
| 8318 | if (!DE) { |
| 8319 | OverloadedOperatorKind OOK = OO_None; |
| 8320 | SourceLocation OOLoc; |
| 8321 | Expr *LHS, *RHS; |
| 8322 | if (auto *BO = dyn_cast<BinaryOperator>(SimpleExpr)) { |
| 8323 | OOK = BinaryOperator::getOverloadedOperator(BO->getOpcode()); |
| 8324 | OOLoc = BO->getOperatorLoc(); |
| 8325 | LHS = BO->getLHS()->IgnoreParenImpCasts(); |
| 8326 | RHS = BO->getRHS()->IgnoreParenImpCasts(); |
| 8327 | } else if (auto *OCE = dyn_cast<CXXOperatorCallExpr>(SimpleExpr)) { |
| 8328 | OOK = OCE->getOperator(); |
| 8329 | OOLoc = OCE->getOperatorLoc(); |
| 8330 | LHS = OCE->getArg(/*Arg=*/0)->IgnoreParenImpCasts(); |
| 8331 | RHS = OCE->getArg(/*Arg=*/1)->IgnoreParenImpCasts(); |
| 8332 | } else if (auto *MCE = dyn_cast<CXXMemberCallExpr>(SimpleExpr)) { |
| 8333 | OOK = MCE->getMethodDecl() |
| 8334 | ->getNameInfo() |
| 8335 | .getName() |
| 8336 | .getCXXOverloadedOperator(); |
| 8337 | OOLoc = MCE->getCallee()->getExprLoc(); |
| 8338 | LHS = MCE->getImplicitObjectArgument()->IgnoreParenImpCasts(); |
| 8339 | RHS = MCE->getArg(/*Arg=*/0)->IgnoreParenImpCasts(); |
| 8340 | } else { |
| 8341 | Diag(ELoc, diag::err_omp_depend_sink_wrong_expr); |
| 8342 | continue; |
| 8343 | } |
| 8344 | DE = dyn_cast<DeclRefExpr>(LHS); |
| 8345 | if (!DE) { |
| 8346 | Diag(LHS->getExprLoc(), |
| 8347 | diag::err_omp_depend_sink_expected_loop_iteration) |
| 8348 | << DSAStack->getParentLoopControlVariable( |
| 8349 | DepCounter.getZExtValue()); |
| 8350 | continue; |
| 8351 | } |
| 8352 | if (OOK != OO_Plus && OOK != OO_Minus) { |
| 8353 | Diag(OOLoc, diag::err_omp_depend_sink_expected_plus_minus); |
| 8354 | continue; |
| 8355 | } |
| 8356 | ExprResult Res = VerifyPositiveIntegerConstantInClause( |
| 8357 | RHS, OMPC_depend, /*StrictlyPositive=*/false); |
| 8358 | if (Res.isInvalid()) |
| 8359 | continue; |
| 8360 | } |
| 8361 | auto *VD = dyn_cast<VarDecl>(DE->getDecl()); |
| 8362 | if (!CurContext->isDependentContext() && |
| 8363 | DSAStack->getParentOrderedRegionParam() && |
| 8364 | (!VD || DepCounter != DSAStack->isParentLoopControlVariable(VD))) { |
| 8365 | Diag(DE->getExprLoc(), |
| 8366 | diag::err_omp_depend_sink_expected_loop_iteration) |
| 8367 | << DSAStack->getParentLoopControlVariable( |
| 8368 | DepCounter.getZExtValue()); |
| 8369 | continue; |
| 8370 | } |
| 8371 | } else { |
| 8372 | // OpenMP [2.11.1.1, Restrictions, p.3] |
| 8373 | // A variable that is part of another variable (such as a field of a |
| 8374 | // structure) but is not an array element or an array section cannot |
| 8375 | // appear in a depend clause. |
| 8376 | auto *DE = dyn_cast<DeclRefExpr>(SimpleExpr); |
| 8377 | auto *ASE = dyn_cast<ArraySubscriptExpr>(SimpleExpr); |
| 8378 | auto *OASE = dyn_cast<OMPArraySectionExpr>(SimpleExpr); |
| 8379 | if (!RefExpr->IgnoreParenImpCasts()->isLValue() || |
| 8380 | (!ASE && !DE && !OASE) || (DE && !isa<VarDecl>(DE->getDecl())) || |
| 8381 | (ASE && !ASE->getBase()->getType()->isAnyPointerType() && |
| 8382 | !ASE->getBase()->getType()->isArrayType())) { |
| 8383 | Diag(ELoc, diag::err_omp_expected_var_name_or_array_item) |
| 8384 | << RefExpr->getSourceRange(); |
| 8385 | continue; |
| 8386 | } |
| 8387 | } |
| 8388 | |
| 8389 | Vars.push_back(RefExpr->IgnoreParenImpCasts()); |
| 8390 | } |
| 8391 | |
| 8392 | if (!CurContext->isDependentContext() && DepKind == OMPC_DEPEND_sink && |
| 8393 | TotalDepCount > VarList.size() && |
| 8394 | DSAStack->getParentOrderedRegionParam()) { |
| 8395 | Diag(EndLoc, diag::err_omp_depend_sink_expected_loop_iteration) |
| 8396 | << DSAStack->getParentLoopControlVariable(VarList.size() + 1); |
| 8397 | } |
| 8398 | if (DepKind != OMPC_DEPEND_source && DepKind != OMPC_DEPEND_sink && |
| 8399 | Vars.empty()) |
| 8400 | return nullptr; |
| 8401 | } |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8402 | |
| 8403 | return OMPDependClause::Create(Context, StartLoc, LParenLoc, EndLoc, DepKind, |
| 8404 | DepLoc, ColonLoc, Vars); |
| 8405 | } |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 8406 | |
| 8407 | OMPClause *Sema::ActOnOpenMPDeviceClause(Expr *Device, SourceLocation StartLoc, |
| 8408 | SourceLocation LParenLoc, |
| 8409 | SourceLocation EndLoc) { |
| 8410 | Expr *ValExpr = Device; |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 8411 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 8412 | // OpenMP [2.9.1, Restrictions] |
| 8413 | // The device expression must evaluate to a non-negative integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 8414 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_device, |
| 8415 | /*StrictlyPositive=*/false)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 8416 | return nullptr; |
| 8417 | |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 8418 | return new (Context) OMPDeviceClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 8419 | } |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 8420 | |
| 8421 | static bool IsCXXRecordForMappable(Sema &SemaRef, SourceLocation Loc, |
| 8422 | DSAStackTy *Stack, CXXRecordDecl *RD) { |
| 8423 | if (!RD || RD->isInvalidDecl()) |
| 8424 | return true; |
| 8425 | |
Alexey Bataev | c9bd03d | 2015-12-17 06:55:08 +0000 | [diff] [blame] | 8426 | if (auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(RD)) |
| 8427 | if (auto *CTD = CTSD->getSpecializedTemplate()) |
| 8428 | RD = CTD->getTemplatedDecl(); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 8429 | auto QTy = SemaRef.Context.getRecordType(RD); |
| 8430 | if (RD->isDynamicClass()) { |
| 8431 | SemaRef.Diag(Loc, diag::err_omp_not_mappable_type) << QTy; |
| 8432 | SemaRef.Diag(RD->getLocation(), diag::note_omp_polymorphic_in_target); |
| 8433 | return false; |
| 8434 | } |
| 8435 | auto *DC = RD; |
| 8436 | bool IsCorrect = true; |
| 8437 | for (auto *I : DC->decls()) { |
| 8438 | if (I) { |
| 8439 | if (auto *MD = dyn_cast<CXXMethodDecl>(I)) { |
| 8440 | if (MD->isStatic()) { |
| 8441 | SemaRef.Diag(Loc, diag::err_omp_not_mappable_type) << QTy; |
| 8442 | SemaRef.Diag(MD->getLocation(), |
| 8443 | diag::note_omp_static_member_in_target); |
| 8444 | IsCorrect = false; |
| 8445 | } |
| 8446 | } else if (auto *VD = dyn_cast<VarDecl>(I)) { |
| 8447 | if (VD->isStaticDataMember()) { |
| 8448 | SemaRef.Diag(Loc, diag::err_omp_not_mappable_type) << QTy; |
| 8449 | SemaRef.Diag(VD->getLocation(), |
| 8450 | diag::note_omp_static_member_in_target); |
| 8451 | IsCorrect = false; |
| 8452 | } |
| 8453 | } |
| 8454 | } |
| 8455 | } |
| 8456 | |
| 8457 | for (auto &I : RD->bases()) { |
| 8458 | if (!IsCXXRecordForMappable(SemaRef, I.getLocStart(), Stack, |
| 8459 | I.getType()->getAsCXXRecordDecl())) |
| 8460 | IsCorrect = false; |
| 8461 | } |
| 8462 | return IsCorrect; |
| 8463 | } |
| 8464 | |
| 8465 | static bool CheckTypeMappable(SourceLocation SL, SourceRange SR, Sema &SemaRef, |
| 8466 | DSAStackTy *Stack, QualType QTy) { |
| 8467 | NamedDecl *ND; |
| 8468 | if (QTy->isIncompleteType(&ND)) { |
| 8469 | SemaRef.Diag(SL, diag::err_incomplete_type) << QTy << SR; |
| 8470 | return false; |
| 8471 | } else if (CXXRecordDecl *RD = dyn_cast_or_null<CXXRecordDecl>(ND)) { |
| 8472 | if (!RD->isInvalidDecl() && |
| 8473 | !IsCXXRecordForMappable(SemaRef, SL, Stack, RD)) |
| 8474 | return false; |
| 8475 | } |
| 8476 | return true; |
| 8477 | } |
| 8478 | |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame^] | 8479 | OMPClause * |
| 8480 | Sema::ActOnOpenMPMapClause(OpenMPMapClauseKind MapTypeModifier, |
| 8481 | OpenMPMapClauseKind MapType, bool IsMapTypeImplicit, |
| 8482 | SourceLocation MapLoc, SourceLocation ColonLoc, |
| 8483 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
| 8484 | SourceLocation LParenLoc, SourceLocation EndLoc) { |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 8485 | SmallVector<Expr *, 4> Vars; |
| 8486 | |
| 8487 | for (auto &RE : VarList) { |
| 8488 | assert(RE && "Null expr in omp map"); |
| 8489 | if (isa<DependentScopeDeclRefExpr>(RE)) { |
| 8490 | // It will be analyzed later. |
| 8491 | Vars.push_back(RE); |
| 8492 | continue; |
| 8493 | } |
| 8494 | SourceLocation ELoc = RE->getExprLoc(); |
| 8495 | |
| 8496 | // OpenMP [2.14.5, Restrictions] |
| 8497 | // A variable that is part of another variable (such as field of a |
| 8498 | // structure) but is not an array element or an array section cannot appear |
| 8499 | // in a map clause. |
| 8500 | auto *VE = RE->IgnoreParenLValueCasts(); |
| 8501 | |
| 8502 | if (VE->isValueDependent() || VE->isTypeDependent() || |
| 8503 | VE->isInstantiationDependent() || |
| 8504 | VE->containsUnexpandedParameterPack()) { |
| 8505 | // It will be analyzed later. |
| 8506 | Vars.push_back(RE); |
| 8507 | continue; |
| 8508 | } |
| 8509 | |
| 8510 | auto *SimpleExpr = RE->IgnoreParenCasts(); |
| 8511 | auto *DE = dyn_cast<DeclRefExpr>(SimpleExpr); |
| 8512 | auto *ASE = dyn_cast<ArraySubscriptExpr>(SimpleExpr); |
| 8513 | auto *OASE = dyn_cast<OMPArraySectionExpr>(SimpleExpr); |
| 8514 | |
| 8515 | if (!RE->IgnoreParenImpCasts()->isLValue() || |
| 8516 | (!OASE && !ASE && !DE) || |
| 8517 | (DE && !isa<VarDecl>(DE->getDecl())) || |
| 8518 | (ASE && !ASE->getBase()->getType()->isAnyPointerType() && |
| 8519 | !ASE->getBase()->getType()->isArrayType())) { |
| 8520 | Diag(ELoc, diag::err_omp_expected_var_name_or_array_item) |
| 8521 | << RE->getSourceRange(); |
| 8522 | continue; |
| 8523 | } |
| 8524 | |
| 8525 | Decl *D = nullptr; |
| 8526 | if (DE) { |
| 8527 | D = DE->getDecl(); |
| 8528 | } else if (ASE) { |
| 8529 | auto *B = ASE->getBase()->IgnoreParenCasts(); |
| 8530 | D = dyn_cast<DeclRefExpr>(B)->getDecl(); |
| 8531 | } else if (OASE) { |
| 8532 | auto *B = OASE->getBase(); |
| 8533 | D = dyn_cast<DeclRefExpr>(B)->getDecl(); |
| 8534 | } |
| 8535 | assert(D && "Null decl on map clause."); |
| 8536 | auto *VD = cast<VarDecl>(D); |
| 8537 | |
| 8538 | // OpenMP [2.14.5, Restrictions, p.8] |
| 8539 | // threadprivate variables cannot appear in a map clause. |
| 8540 | if (DSAStack->isThreadPrivate(VD)) { |
| 8541 | auto DVar = DSAStack->getTopDSA(VD, false); |
| 8542 | Diag(ELoc, diag::err_omp_threadprivate_in_map); |
| 8543 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 8544 | continue; |
| 8545 | } |
| 8546 | |
| 8547 | // OpenMP [2.14.5, Restrictions, p.2] |
| 8548 | // At most one list item can be an array item derived from a given variable |
| 8549 | // in map clauses of the same construct. |
| 8550 | // OpenMP [2.14.5, Restrictions, p.3] |
| 8551 | // List items of map clauses in the same construct must not share original |
| 8552 | // storage. |
| 8553 | // OpenMP [2.14.5, Restrictions, C/C++, p.2] |
| 8554 | // A variable for which the type is pointer, reference to array, or |
| 8555 | // reference to pointer and an array section derived from that variable |
| 8556 | // must not appear as list items of map clauses of the same construct. |
| 8557 | DSAStackTy::MapInfo MI = DSAStack->IsMappedInCurrentRegion(VD); |
| 8558 | if (MI.RefExpr) { |
| 8559 | Diag(ELoc, diag::err_omp_map_shared_storage) << ELoc; |
| 8560 | Diag(MI.RefExpr->getExprLoc(), diag::note_used_here) |
| 8561 | << MI.RefExpr->getSourceRange(); |
| 8562 | continue; |
| 8563 | } |
| 8564 | |
| 8565 | // OpenMP [2.14.5, Restrictions, C/C++, p.3,4] |
| 8566 | // A variable for which the type is pointer, reference to array, or |
| 8567 | // reference to pointer must not appear as a list item if the enclosing |
| 8568 | // device data environment already contains an array section derived from |
| 8569 | // that variable. |
| 8570 | // An array section derived from a variable for which the type is pointer, |
| 8571 | // reference to array, or reference to pointer must not appear as a list |
| 8572 | // item if the enclosing device data environment already contains that |
| 8573 | // variable. |
| 8574 | QualType Type = VD->getType(); |
| 8575 | MI = DSAStack->getMapInfoForVar(VD); |
| 8576 | if (MI.RefExpr && (isa<DeclRefExpr>(MI.RefExpr->IgnoreParenLValueCasts()) != |
| 8577 | isa<DeclRefExpr>(VE)) && |
| 8578 | (Type->isPointerType() || Type->isReferenceType())) { |
| 8579 | Diag(ELoc, diag::err_omp_map_shared_storage) << ELoc; |
| 8580 | Diag(MI.RefExpr->getExprLoc(), diag::note_used_here) |
| 8581 | << MI.RefExpr->getSourceRange(); |
| 8582 | continue; |
| 8583 | } |
| 8584 | |
| 8585 | // OpenMP [2.14.5, Restrictions, C/C++, p.7] |
| 8586 | // A list item must have a mappable type. |
| 8587 | if (!CheckTypeMappable(VE->getExprLoc(), VE->getSourceRange(), *this, |
| 8588 | DSAStack, Type)) |
| 8589 | continue; |
| 8590 | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 8591 | // target enter data |
| 8592 | // OpenMP [2.10.2, Restrictions, p. 99] |
| 8593 | // A map-type must be specified in all map clauses and must be either |
| 8594 | // to or alloc. |
| 8595 | OpenMPDirectiveKind DKind = DSAStack->getCurrentDirective(); |
| 8596 | if (DKind == OMPD_target_enter_data && |
| 8597 | !(MapType == OMPC_MAP_to || MapType == OMPC_MAP_alloc)) { |
| 8598 | Diag(StartLoc, diag::err_omp_invalid_map_type_for_directive) |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame^] | 8599 | << (IsMapTypeImplicit ? 1 : 0) |
| 8600 | << getOpenMPSimpleClauseTypeName(OMPC_map, MapType) |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 8601 | << getOpenMPDirectiveName(DKind); |
| 8602 | // Proceed to add the variable in a map clause anyway, to prevent |
| 8603 | // further spurious messages |
| 8604 | } |
| 8605 | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 8606 | // target exit_data |
| 8607 | // OpenMP [2.10.3, Restrictions, p. 102] |
| 8608 | // A map-type must be specified in all map clauses and must be either |
| 8609 | // from, release, or delete. |
| 8610 | DKind = DSAStack->getCurrentDirective(); |
| 8611 | if (DKind == OMPD_target_exit_data && |
| 8612 | !(MapType == OMPC_MAP_from || MapType == OMPC_MAP_release || |
| 8613 | MapType == OMPC_MAP_delete)) { |
| 8614 | Diag(StartLoc, diag::err_omp_invalid_map_type_for_directive) |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame^] | 8615 | << (IsMapTypeImplicit ? 1 : 0) |
| 8616 | << getOpenMPSimpleClauseTypeName(OMPC_map, MapType) |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 8617 | << getOpenMPDirectiveName(DKind); |
| 8618 | // Proceed to add the variable in a map clause anyway, to prevent |
| 8619 | // further spurious messages |
| 8620 | } |
| 8621 | |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 8622 | Vars.push_back(RE); |
| 8623 | MI.RefExpr = RE; |
| 8624 | DSAStack->addMapInfoForVar(VD, MI); |
| 8625 | } |
| 8626 | if (Vars.empty()) |
| 8627 | return nullptr; |
| 8628 | |
| 8629 | return OMPMapClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame^] | 8630 | MapTypeModifier, MapType, IsMapTypeImplicit, |
| 8631 | MapLoc); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 8632 | } |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 8633 | |
| 8634 | OMPClause *Sema::ActOnOpenMPNumTeamsClause(Expr *NumTeams, |
| 8635 | SourceLocation StartLoc, |
| 8636 | SourceLocation LParenLoc, |
| 8637 | SourceLocation EndLoc) { |
| 8638 | Expr *ValExpr = NumTeams; |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 8639 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 8640 | // OpenMP [teams Constrcut, Restrictions] |
| 8641 | // The num_teams expression must evaluate to a positive integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 8642 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_num_teams, |
| 8643 | /*StrictlyPositive=*/true)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 8644 | return nullptr; |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 8645 | |
| 8646 | return new (Context) OMPNumTeamsClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 8647 | } |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 8648 | |
| 8649 | OMPClause *Sema::ActOnOpenMPThreadLimitClause(Expr *ThreadLimit, |
| 8650 | SourceLocation StartLoc, |
| 8651 | SourceLocation LParenLoc, |
| 8652 | SourceLocation EndLoc) { |
| 8653 | Expr *ValExpr = ThreadLimit; |
| 8654 | |
| 8655 | // OpenMP [teams Constrcut, Restrictions] |
| 8656 | // The thread_limit expression must evaluate to a positive integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 8657 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_thread_limit, |
| 8658 | /*StrictlyPositive=*/true)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 8659 | return nullptr; |
| 8660 | |
| 8661 | return new (Context) OMPThreadLimitClause(ValExpr, StartLoc, LParenLoc, |
| 8662 | EndLoc); |
| 8663 | } |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 8664 | |
| 8665 | OMPClause *Sema::ActOnOpenMPPriorityClause(Expr *Priority, |
| 8666 | SourceLocation StartLoc, |
| 8667 | SourceLocation LParenLoc, |
| 8668 | SourceLocation EndLoc) { |
| 8669 | Expr *ValExpr = Priority; |
| 8670 | |
| 8671 | // OpenMP [2.9.1, task Constrcut] |
| 8672 | // The priority-value is a non-negative numerical scalar expression. |
| 8673 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_priority, |
| 8674 | /*StrictlyPositive=*/false)) |
| 8675 | return nullptr; |
| 8676 | |
| 8677 | return new (Context) OMPPriorityClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 8678 | } |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 8679 | |
| 8680 | OMPClause *Sema::ActOnOpenMPGrainsizeClause(Expr *Grainsize, |
| 8681 | SourceLocation StartLoc, |
| 8682 | SourceLocation LParenLoc, |
| 8683 | SourceLocation EndLoc) { |
| 8684 | Expr *ValExpr = Grainsize; |
| 8685 | |
| 8686 | // OpenMP [2.9.2, taskloop Constrcut] |
| 8687 | // The parameter of the grainsize clause must be a positive integer |
| 8688 | // expression. |
| 8689 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_grainsize, |
| 8690 | /*StrictlyPositive=*/true)) |
| 8691 | return nullptr; |
| 8692 | |
| 8693 | return new (Context) OMPGrainsizeClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 8694 | } |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 8695 | |
| 8696 | OMPClause *Sema::ActOnOpenMPNumTasksClause(Expr *NumTasks, |
| 8697 | SourceLocation StartLoc, |
| 8698 | SourceLocation LParenLoc, |
| 8699 | SourceLocation EndLoc) { |
| 8700 | Expr *ValExpr = NumTasks; |
| 8701 | |
| 8702 | // OpenMP [2.9.2, taskloop Constrcut] |
| 8703 | // The parameter of the num_tasks clause must be a positive integer |
| 8704 | // expression. |
| 8705 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_num_tasks, |
| 8706 | /*StrictlyPositive=*/true)) |
| 8707 | return nullptr; |
| 8708 | |
| 8709 | return new (Context) OMPNumTasksClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 8710 | } |
| 8711 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 8712 | OMPClause *Sema::ActOnOpenMPHintClause(Expr *Hint, SourceLocation StartLoc, |
| 8713 | SourceLocation LParenLoc, |
| 8714 | SourceLocation EndLoc) { |
| 8715 | // OpenMP [2.13.2, critical construct, Description] |
| 8716 | // ... where hint-expression is an integer constant expression that evaluates |
| 8717 | // to a valid lock hint. |
| 8718 | ExprResult HintExpr = VerifyPositiveIntegerConstantInClause(Hint, OMPC_hint); |
| 8719 | if (HintExpr.isInvalid()) |
| 8720 | return nullptr; |
| 8721 | return new (Context) |
| 8722 | OMPHintClause(HintExpr.get(), StartLoc, LParenLoc, EndLoc); |
| 8723 | } |
| 8724 | |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 8725 | OMPClause *Sema::ActOnOpenMPDistScheduleClause( |
| 8726 | OpenMPDistScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, |
| 8727 | SourceLocation LParenLoc, SourceLocation KindLoc, SourceLocation CommaLoc, |
| 8728 | SourceLocation EndLoc) { |
| 8729 | if (Kind == OMPC_DIST_SCHEDULE_unknown) { |
| 8730 | std::string Values; |
| 8731 | Values += "'"; |
| 8732 | Values += getOpenMPSimpleClauseTypeName(OMPC_dist_schedule, 0); |
| 8733 | Values += "'"; |
| 8734 | Diag(KindLoc, diag::err_omp_unexpected_clause_value) |
| 8735 | << Values << getOpenMPClauseName(OMPC_dist_schedule); |
| 8736 | return nullptr; |
| 8737 | } |
| 8738 | Expr *ValExpr = ChunkSize; |
| 8739 | Expr *HelperValExpr = nullptr; |
| 8740 | if (ChunkSize) { |
| 8741 | if (!ChunkSize->isValueDependent() && !ChunkSize->isTypeDependent() && |
| 8742 | !ChunkSize->isInstantiationDependent() && |
| 8743 | !ChunkSize->containsUnexpandedParameterPack()) { |
| 8744 | SourceLocation ChunkSizeLoc = ChunkSize->getLocStart(); |
| 8745 | ExprResult Val = |
| 8746 | PerformOpenMPImplicitIntegerConversion(ChunkSizeLoc, ChunkSize); |
| 8747 | if (Val.isInvalid()) |
| 8748 | return nullptr; |
| 8749 | |
| 8750 | ValExpr = Val.get(); |
| 8751 | |
| 8752 | // OpenMP [2.7.1, Restrictions] |
| 8753 | // chunk_size must be a loop invariant integer expression with a positive |
| 8754 | // value. |
| 8755 | llvm::APSInt Result; |
| 8756 | if (ValExpr->isIntegerConstantExpr(Result, Context)) { |
| 8757 | if (Result.isSigned() && !Result.isStrictlyPositive()) { |
| 8758 | Diag(ChunkSizeLoc, diag::err_omp_negative_expression_in_clause) |
| 8759 | << "dist_schedule" << ChunkSize->getSourceRange(); |
| 8760 | return nullptr; |
| 8761 | } |
| 8762 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective())) { |
| 8763 | auto *ImpVar = buildVarDecl(*this, ChunkSize->getExprLoc(), |
| 8764 | ChunkSize->getType(), ".chunk."); |
| 8765 | auto *ImpVarRef = buildDeclRefExpr(*this, ImpVar, ChunkSize->getType(), |
| 8766 | ChunkSize->getExprLoc(), |
| 8767 | /*RefersToCapture=*/true); |
| 8768 | HelperValExpr = ImpVarRef; |
| 8769 | } |
| 8770 | } |
| 8771 | } |
| 8772 | |
| 8773 | return new (Context) |
| 8774 | OMPDistScheduleClause(StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc, |
| 8775 | Kind, ValExpr, HelperValExpr); |
| 8776 | } |