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; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 73 | Expr *RefExpr; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 74 | SourceLocation ImplicitDSALoc; |
| 75 | DSAVarData() |
| 76 | : DKind(OMPD_unknown), CKind(OMPC_unknown), RefExpr(nullptr), |
| 77 | ImplicitDSALoc() {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 78 | }; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 79 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 80 | private: |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 81 | typedef SmallVector<Expr *, 4> MapInfo; |
| 82 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 83 | struct DSAInfo { |
| 84 | OpenMPClauseKind Attributes; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 85 | Expr *RefExpr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 86 | }; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 87 | typedef llvm::SmallDenseMap<ValueDecl *, DSAInfo, 64> DeclSAMapTy; |
| 88 | typedef llvm::SmallDenseMap<ValueDecl *, Expr *, 64> AlignedMapTy; |
| 89 | typedef llvm::DenseMap<ValueDecl *, unsigned> LoopControlVariablesMapTy; |
| 90 | typedef llvm::SmallDenseMap<ValueDecl *, MapInfo, 64> MappedDeclsTy; |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 91 | typedef llvm::StringMap<std::pair<OMPCriticalDirective *, llvm::APSInt>> |
| 92 | CriticalsWithHintsTy; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 93 | |
| 94 | struct SharingMapTy { |
| 95 | DeclSAMapTy SharingMap; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 96 | AlignedMapTy AlignedMap; |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 97 | MappedDeclsTy MappedDecls; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 98 | LoopControlVariablesMapTy LCVMap; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 99 | DefaultDataSharingAttributes DefaultAttr; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 100 | SourceLocation DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 101 | OpenMPDirectiveKind Directive; |
| 102 | DeclarationNameInfo DirectiveName; |
| 103 | Scope *CurScope; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 104 | SourceLocation ConstructLoc; |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 105 | /// \brief first argument (Expr *) contains optional argument of the |
| 106 | /// 'ordered' clause, the second one is true if the regions has 'ordered' |
| 107 | /// clause, false otherwise. |
| 108 | llvm::PointerIntPair<Expr *, 1, bool> OrderedRegion; |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 109 | bool NowaitRegion; |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 110 | bool CancelRegion; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 111 | unsigned AssociatedLoops; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 112 | SourceLocation InnerTeamsRegionLoc; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 113 | SharingMapTy(OpenMPDirectiveKind DKind, DeclarationNameInfo Name, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 114 | Scope *CurScope, SourceLocation Loc) |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 115 | : SharingMap(), AlignedMap(), LCVMap(), DefaultAttr(DSA_unspecified), |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 116 | Directive(DKind), DirectiveName(std::move(Name)), CurScope(CurScope), |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 117 | ConstructLoc(Loc), OrderedRegion(), NowaitRegion(false), |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 118 | CancelRegion(false), AssociatedLoops(1), InnerTeamsRegionLoc() {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 119 | SharingMapTy() |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 120 | : SharingMap(), AlignedMap(), LCVMap(), DefaultAttr(DSA_unspecified), |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 121 | Directive(OMPD_unknown), DirectiveName(), CurScope(nullptr), |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 122 | ConstructLoc(), OrderedRegion(), NowaitRegion(false), |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 123 | CancelRegion(false), AssociatedLoops(1), InnerTeamsRegionLoc() {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 124 | }; |
| 125 | |
| 126 | typedef SmallVector<SharingMapTy, 64> StackTy; |
| 127 | |
| 128 | /// \brief Stack of used declaration and their data-sharing attributes. |
| 129 | StackTy Stack; |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 130 | /// \brief true, if check for DSA must be from parent directive, false, if |
| 131 | /// from current directive. |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 132 | OpenMPClauseKind ClauseKindMode; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 133 | Sema &SemaRef; |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 134 | bool ForceCapturing; |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 135 | CriticalsWithHintsTy Criticals; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 136 | |
| 137 | typedef SmallVector<SharingMapTy, 8>::reverse_iterator reverse_iterator; |
| 138 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 139 | DSAVarData getDSA(StackTy::reverse_iterator Iter, ValueDecl *D); |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 140 | |
| 141 | /// \brief Checks if the variable is a local for OpenMP region. |
| 142 | bool isOpenMPLocal(VarDecl *D, StackTy::reverse_iterator Iter); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 143 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 144 | public: |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 145 | explicit DSAStackTy(Sema &S) |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 146 | : Stack(1), ClauseKindMode(OMPC_unknown), SemaRef(S), |
| 147 | ForceCapturing(false) {} |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 148 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 149 | bool isClauseParsingMode() const { return ClauseKindMode != OMPC_unknown; } |
| 150 | void setClauseParsingMode(OpenMPClauseKind K) { ClauseKindMode = K; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 151 | |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 152 | bool isForceVarCapturing() const { return ForceCapturing; } |
| 153 | void setForceVarCapturing(bool V) { ForceCapturing = V; } |
| 154 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 155 | void push(OpenMPDirectiveKind DKind, const DeclarationNameInfo &DirName, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 156 | Scope *CurScope, SourceLocation Loc) { |
| 157 | Stack.push_back(SharingMapTy(DKind, DirName, CurScope, Loc)); |
| 158 | Stack.back().DefaultAttrLoc = Loc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | void pop() { |
| 162 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty!"); |
| 163 | Stack.pop_back(); |
| 164 | } |
| 165 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 166 | void addCriticalWithHint(OMPCriticalDirective *D, llvm::APSInt Hint) { |
| 167 | Criticals[D->getDirectiveName().getAsString()] = std::make_pair(D, Hint); |
| 168 | } |
| 169 | const std::pair<OMPCriticalDirective *, llvm::APSInt> |
| 170 | getCriticalWithHint(const DeclarationNameInfo &Name) const { |
| 171 | auto I = Criticals.find(Name.getAsString()); |
| 172 | if (I != Criticals.end()) |
| 173 | return I->second; |
| 174 | return std::make_pair(nullptr, llvm::APSInt()); |
| 175 | } |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 176 | /// \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] | 177 | /// add it and return NULL; otherwise return previous occurrence's expression |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 178 | /// for diagnostics. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 179 | Expr *addUniqueAligned(ValueDecl *D, Expr *NewDE); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 180 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 181 | /// \brief Register specified variable as loop control variable. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 182 | void addLoopControlVariable(ValueDecl *D); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 183 | /// \brief Check if the specified variable is a loop control variable for |
| 184 | /// current region. |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 185 | /// \return The index of the loop control variable in the list of associated |
| 186 | /// for-loops (from outer to inner). |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 187 | unsigned isLoopControlVariable(ValueDecl *D); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 188 | /// \brief Check if the specified variable is a loop control variable for |
| 189 | /// parent region. |
| 190 | /// \return The index of the loop control variable in the list of associated |
| 191 | /// for-loops (from outer to inner). |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 192 | unsigned isParentLoopControlVariable(ValueDecl *D); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 193 | /// \brief Get the loop control variable for the I-th loop (or nullptr) in |
| 194 | /// parent directive. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 195 | ValueDecl *getParentLoopControlVariable(unsigned I); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 196 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 197 | /// \brief Adds explicit data sharing attribute to the specified declaration. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 198 | void addDSA(ValueDecl *D, Expr *E, OpenMPClauseKind A); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 199 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 200 | /// \brief Returns data sharing attributes from top of the stack for the |
| 201 | /// specified declaration. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 202 | DSAVarData getTopDSA(ValueDecl *D, bool FromParent); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 203 | /// \brief Returns data-sharing attributes for the specified declaration. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 204 | DSAVarData getImplicitDSA(ValueDecl *D, bool FromParent); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 205 | /// \brief Checks if the specified variables has data-sharing attributes which |
| 206 | /// match specified \a CPred predicate in any directive which matches \a DPred |
| 207 | /// predicate. |
| 208 | template <class ClausesPredicate, class DirectivesPredicate> |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 209 | DSAVarData hasDSA(ValueDecl *D, ClausesPredicate CPred, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 210 | DirectivesPredicate DPred, bool FromParent); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 211 | /// \brief Checks if the specified variables has data-sharing attributes which |
| 212 | /// match specified \a CPred predicate in any innermost directive which |
| 213 | /// matches \a DPred predicate. |
| 214 | template <class ClausesPredicate, class DirectivesPredicate> |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 215 | DSAVarData hasInnermostDSA(ValueDecl *D, ClausesPredicate CPred, |
| 216 | DirectivesPredicate DPred, bool FromParent); |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 217 | /// \brief Checks if the specified variables has explicit data-sharing |
| 218 | /// attributes which match specified \a CPred predicate at the specified |
| 219 | /// OpenMP region. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 220 | bool hasExplicitDSA(ValueDecl *D, |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 221 | const llvm::function_ref<bool(OpenMPClauseKind)> &CPred, |
| 222 | unsigned Level); |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 223 | |
| 224 | /// \brief Returns true if the directive at level \Level matches in the |
| 225 | /// specified \a DPred predicate. |
| 226 | bool hasExplicitDirective( |
| 227 | const llvm::function_ref<bool(OpenMPDirectiveKind)> &DPred, |
| 228 | unsigned Level); |
| 229 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 230 | /// \brief Finds a directive which matches specified \a DPred predicate. |
| 231 | template <class NamedDirectivesPredicate> |
| 232 | bool hasDirective(NamedDirectivesPredicate DPred, bool FromParent); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 233 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 234 | /// \brief Returns currently analyzed directive. |
| 235 | OpenMPDirectiveKind getCurrentDirective() const { |
| 236 | return Stack.back().Directive; |
| 237 | } |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 238 | /// \brief Returns parent directive. |
| 239 | OpenMPDirectiveKind getParentDirective() const { |
| 240 | if (Stack.size() > 2) |
| 241 | return Stack[Stack.size() - 2].Directive; |
| 242 | return OMPD_unknown; |
| 243 | } |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 244 | /// \brief Return the directive associated with the provided scope. |
| 245 | OpenMPDirectiveKind getDirectiveForScope(const Scope *S) const; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 246 | |
| 247 | /// \brief Set default data sharing attribute to none. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 248 | void setDefaultDSANone(SourceLocation Loc) { |
| 249 | Stack.back().DefaultAttr = DSA_none; |
| 250 | Stack.back().DefaultAttrLoc = Loc; |
| 251 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 252 | /// \brief Set default data sharing attribute to shared. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 253 | void setDefaultDSAShared(SourceLocation Loc) { |
| 254 | Stack.back().DefaultAttr = DSA_shared; |
| 255 | Stack.back().DefaultAttrLoc = Loc; |
| 256 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 257 | |
| 258 | DefaultDataSharingAttributes getDefaultDSA() const { |
| 259 | return Stack.back().DefaultAttr; |
| 260 | } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 261 | SourceLocation getDefaultDSALocation() const { |
| 262 | return Stack.back().DefaultAttrLoc; |
| 263 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 264 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 265 | /// \brief Checks if the specified variable is a threadprivate. |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 266 | bool isThreadPrivate(VarDecl *D) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 267 | DSAVarData DVar = getTopDSA(D, false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 268 | return isOpenMPThreadPrivate(DVar.CKind); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 269 | } |
| 270 | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 271 | /// \brief Marks current region as ordered (it has an 'ordered' clause). |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 272 | void setOrderedRegion(bool IsOrdered, Expr *Param) { |
| 273 | Stack.back().OrderedRegion.setInt(IsOrdered); |
| 274 | Stack.back().OrderedRegion.setPointer(Param); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 275 | } |
| 276 | /// \brief Returns true, if parent region is ordered (has associated |
| 277 | /// 'ordered' clause), false - otherwise. |
| 278 | bool isParentOrderedRegion() const { |
| 279 | if (Stack.size() > 2) |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 280 | return Stack[Stack.size() - 2].OrderedRegion.getInt(); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 281 | return false; |
| 282 | } |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 283 | /// \brief Returns optional parameter for the ordered region. |
| 284 | Expr *getParentOrderedRegionParam() const { |
| 285 | if (Stack.size() > 2) |
| 286 | return Stack[Stack.size() - 2].OrderedRegion.getPointer(); |
| 287 | return nullptr; |
| 288 | } |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 289 | /// \brief Marks current region as nowait (it has a 'nowait' clause). |
| 290 | void setNowaitRegion(bool IsNowait = true) { |
| 291 | Stack.back().NowaitRegion = IsNowait; |
| 292 | } |
| 293 | /// \brief Returns true, if parent region is nowait (has associated |
| 294 | /// 'nowait' clause), false - otherwise. |
| 295 | bool isParentNowaitRegion() const { |
| 296 | if (Stack.size() > 2) |
| 297 | return Stack[Stack.size() - 2].NowaitRegion; |
| 298 | return false; |
| 299 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 300 | /// \brief Marks parent region as cancel region. |
| 301 | void setParentCancelRegion(bool Cancel = true) { |
| 302 | if (Stack.size() > 2) |
| 303 | Stack[Stack.size() - 2].CancelRegion = |
| 304 | Stack[Stack.size() - 2].CancelRegion || Cancel; |
| 305 | } |
| 306 | /// \brief Return true if current region has inner cancel construct. |
| 307 | bool isCancelRegion() const { |
| 308 | return Stack.back().CancelRegion; |
| 309 | } |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 310 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 311 | /// \brief Set collapse value for the region. |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 312 | void setAssociatedLoops(unsigned Val) { Stack.back().AssociatedLoops = Val; } |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 313 | /// \brief Return collapse value for region. |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 314 | unsigned getAssociatedLoops() const { return Stack.back().AssociatedLoops; } |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 315 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 316 | /// \brief Marks current target region as one with closely nested teams |
| 317 | /// region. |
| 318 | void setParentTeamsRegionLoc(SourceLocation TeamsRegionLoc) { |
| 319 | if (Stack.size() > 2) |
| 320 | Stack[Stack.size() - 2].InnerTeamsRegionLoc = TeamsRegionLoc; |
| 321 | } |
| 322 | /// \brief Returns true, if current region has closely nested teams region. |
| 323 | bool hasInnerTeamsRegion() const { |
| 324 | return getInnerTeamsRegionLoc().isValid(); |
| 325 | } |
| 326 | /// \brief Returns location of the nested teams region (if any). |
| 327 | SourceLocation getInnerTeamsRegionLoc() const { |
| 328 | if (Stack.size() > 1) |
| 329 | return Stack.back().InnerTeamsRegionLoc; |
| 330 | return SourceLocation(); |
| 331 | } |
| 332 | |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 333 | Scope *getCurScope() const { return Stack.back().CurScope; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 334 | Scope *getCurScope() { return Stack.back().CurScope; } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 335 | SourceLocation getConstructLoc() { return Stack.back().ConstructLoc; } |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 336 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 337 | // Do the check specified in MapInfoCheck and return true if any issue is |
| 338 | // found. |
| 339 | template <class MapInfoCheck> |
| 340 | bool checkMapInfoForVar(ValueDecl *VD, bool CurrentRegionOnly, |
| 341 | MapInfoCheck Check) { |
| 342 | auto SI = Stack.rbegin(); |
| 343 | auto SE = Stack.rend(); |
| 344 | |
| 345 | if (SI == SE) |
| 346 | return false; |
| 347 | |
| 348 | if (CurrentRegionOnly) { |
| 349 | SE = std::next(SI); |
| 350 | } else { |
| 351 | ++SI; |
| 352 | } |
| 353 | |
| 354 | for (; SI != SE; ++SI) { |
| 355 | auto MI = SI->MappedDecls.find(VD); |
| 356 | if (MI != SI->MappedDecls.end()) { |
| 357 | for (Expr *E : MI->second) { |
| 358 | if (Check(E)) |
| 359 | return true; |
| 360 | } |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 361 | } |
| 362 | } |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 363 | return false; |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 364 | } |
| 365 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 366 | void addExprToVarMapInfo(ValueDecl *VD, Expr *E) { |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 367 | if (Stack.size() > 1) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 368 | Stack.back().MappedDecls[VD].push_back(E); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 369 | } |
| 370 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 371 | }; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 372 | bool isParallelOrTaskRegion(OpenMPDirectiveKind DKind) { |
| 373 | return isOpenMPParallelDirective(DKind) || DKind == OMPD_task || |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 374 | isOpenMPTeamsDirective(DKind) || DKind == OMPD_unknown || |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 375 | isOpenMPTaskLoopDirective(DKind); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 376 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 377 | } // namespace |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 378 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 379 | static ValueDecl *getCanonicalDecl(ValueDecl *D) { |
| 380 | auto *VD = dyn_cast<VarDecl>(D); |
| 381 | auto *FD = dyn_cast<FieldDecl>(D); |
| 382 | if (VD != nullptr) { |
| 383 | VD = VD->getCanonicalDecl(); |
| 384 | D = VD; |
| 385 | } else { |
| 386 | assert(FD); |
| 387 | FD = FD->getCanonicalDecl(); |
| 388 | D = FD; |
| 389 | } |
| 390 | return D; |
| 391 | } |
| 392 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 393 | DSAStackTy::DSAVarData DSAStackTy::getDSA(StackTy::reverse_iterator Iter, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 394 | ValueDecl *D) { |
| 395 | D = getCanonicalDecl(D); |
| 396 | auto *VD = dyn_cast<VarDecl>(D); |
| 397 | auto *FD = dyn_cast<FieldDecl>(D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 398 | DSAVarData DVar; |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 399 | if (Iter == std::prev(Stack.rend())) { |
Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 400 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 401 | // in a region but not in construct] |
| 402 | // File-scope or namespace-scope variables referenced in called routines |
| 403 | // in the region are shared unless they appear in a threadprivate |
| 404 | // directive. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 405 | if (VD && !VD->isFunctionOrMethodVarDecl() && !isa<ParmVarDecl>(D)) |
Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 406 | DVar.CKind = OMPC_shared; |
| 407 | |
| 408 | // OpenMP [2.9.1.2, Data-sharing Attribute Rules for Variables Referenced |
| 409 | // in a region but not in construct] |
| 410 | // Variables with static storage duration that are declared in called |
| 411 | // routines in the region are shared. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 412 | if (VD && VD->hasGlobalStorage()) |
| 413 | DVar.CKind = OMPC_shared; |
| 414 | |
| 415 | // Non-static data members are shared by default. |
| 416 | if (FD) |
Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 417 | DVar.CKind = OMPC_shared; |
| 418 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 419 | return DVar; |
| 420 | } |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 421 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 422 | DVar.DKind = Iter->Directive; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 423 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 424 | // in a Construct, C/C++, predetermined, p.1] |
| 425 | // Variables with automatic storage duration that are declared in a scope |
| 426 | // inside the construct are private. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 427 | if (VD && isOpenMPLocal(VD, Iter) && VD->isLocalVarDecl() && |
| 428 | (VD->getStorageClass() == SC_Auto || VD->getStorageClass() == SC_None)) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 429 | DVar.CKind = OMPC_private; |
| 430 | return DVar; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 431 | } |
| 432 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 433 | // Explicitly specified attributes and local variables with predetermined |
| 434 | // attributes. |
| 435 | if (Iter->SharingMap.count(D)) { |
| 436 | DVar.RefExpr = Iter->SharingMap[D].RefExpr; |
| 437 | DVar.CKind = Iter->SharingMap[D].Attributes; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 438 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 439 | return DVar; |
| 440 | } |
| 441 | |
| 442 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 443 | // in a Construct, C/C++, implicitly determined, p.1] |
| 444 | // In a parallel or task construct, the data-sharing attributes of these |
| 445 | // variables are determined by the default clause, if present. |
| 446 | switch (Iter->DefaultAttr) { |
| 447 | case DSA_shared: |
| 448 | DVar.CKind = OMPC_shared; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 449 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 450 | return DVar; |
| 451 | case DSA_none: |
| 452 | return DVar; |
| 453 | case DSA_unspecified: |
| 454 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 455 | // in a Construct, implicitly determined, p.2] |
| 456 | // In a parallel construct, if no default clause is present, these |
| 457 | // variables are shared. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 458 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 459 | if (isOpenMPParallelDirective(DVar.DKind) || |
| 460 | isOpenMPTeamsDirective(DVar.DKind)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 461 | DVar.CKind = OMPC_shared; |
| 462 | return DVar; |
| 463 | } |
| 464 | |
| 465 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 466 | // in a Construct, implicitly determined, p.4] |
| 467 | // In a task construct, if no default clause is present, a variable that in |
| 468 | // the enclosing context is determined to be shared by all implicit tasks |
| 469 | // bound to the current team is shared. |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 470 | if (DVar.DKind == OMPD_task) { |
| 471 | DSAVarData DVarTemp; |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 472 | for (StackTy::reverse_iterator I = std::next(Iter), EE = Stack.rend(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 473 | I != EE; ++I) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 474 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables |
| 475 | // Referenced |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 476 | // in a Construct, implicitly determined, p.6] |
| 477 | // In a task construct, if no default clause is present, a variable |
| 478 | // whose data-sharing attribute is not determined by the rules above is |
| 479 | // firstprivate. |
| 480 | DVarTemp = getDSA(I, D); |
| 481 | if (DVarTemp.CKind != OMPC_shared) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 482 | DVar.RefExpr = nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 483 | DVar.DKind = OMPD_task; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 484 | DVar.CKind = OMPC_firstprivate; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 485 | return DVar; |
| 486 | } |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 487 | if (isParallelOrTaskRegion(I->Directive)) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 488 | break; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 489 | } |
| 490 | DVar.DKind = OMPD_task; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 491 | DVar.CKind = |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 492 | (DVarTemp.CKind == OMPC_unknown) ? OMPC_firstprivate : OMPC_shared; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 493 | return DVar; |
| 494 | } |
| 495 | } |
| 496 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 497 | // in a Construct, implicitly determined, p.3] |
| 498 | // For constructs other than task, if no default clause is present, these |
| 499 | // variables inherit their data-sharing attributes from the enclosing |
| 500 | // context. |
Benjamin Kramer | 167e999 | 2014-03-02 12:20:24 +0000 | [diff] [blame] | 501 | return getDSA(std::next(Iter), D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 502 | } |
| 503 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 504 | Expr *DSAStackTy::addUniqueAligned(ValueDecl *D, Expr *NewDE) { |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 505 | assert(Stack.size() > 1 && "Data sharing attributes stack is empty"); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 506 | D = getCanonicalDecl(D); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 507 | auto It = Stack.back().AlignedMap.find(D); |
| 508 | if (It == Stack.back().AlignedMap.end()) { |
| 509 | assert(NewDE && "Unexpected nullptr expr to be added into aligned map"); |
| 510 | Stack.back().AlignedMap[D] = NewDE; |
| 511 | return nullptr; |
| 512 | } else { |
| 513 | assert(It->second && "Unexpected nullptr expr in the aligned map"); |
| 514 | return It->second; |
| 515 | } |
| 516 | return nullptr; |
| 517 | } |
| 518 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 519 | void DSAStackTy::addLoopControlVariable(ValueDecl *D) { |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 520 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 521 | D = getCanonicalDecl(D); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 522 | 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] | 523 | } |
| 524 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 525 | unsigned DSAStackTy::isLoopControlVariable(ValueDecl *D) { |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 526 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 527 | D = getCanonicalDecl(D); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 528 | return Stack.back().LCVMap.count(D) > 0 ? Stack.back().LCVMap[D] : 0; |
| 529 | } |
| 530 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 531 | unsigned DSAStackTy::isParentLoopControlVariable(ValueDecl *D) { |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 532 | assert(Stack.size() > 2 && "Data-sharing attributes stack is empty"); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 533 | D = getCanonicalDecl(D); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 534 | return Stack[Stack.size() - 2].LCVMap.count(D) > 0 |
| 535 | ? Stack[Stack.size() - 2].LCVMap[D] |
| 536 | : 0; |
| 537 | } |
| 538 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 539 | ValueDecl *DSAStackTy::getParentLoopControlVariable(unsigned I) { |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 540 | assert(Stack.size() > 2 && "Data-sharing attributes stack is empty"); |
| 541 | if (Stack[Stack.size() - 2].LCVMap.size() < I) |
| 542 | return nullptr; |
| 543 | for (auto &Pair : Stack[Stack.size() - 2].LCVMap) { |
| 544 | if (Pair.second == I) |
| 545 | return Pair.first; |
| 546 | } |
| 547 | return nullptr; |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 548 | } |
| 549 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 550 | void DSAStackTy::addDSA(ValueDecl *D, Expr *E, OpenMPClauseKind A) { |
| 551 | D = getCanonicalDecl(D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 552 | if (A == OMPC_threadprivate) { |
| 553 | Stack[0].SharingMap[D].Attributes = A; |
| 554 | Stack[0].SharingMap[D].RefExpr = E; |
| 555 | } else { |
| 556 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); |
| 557 | Stack.back().SharingMap[D].Attributes = A; |
| 558 | Stack.back().SharingMap[D].RefExpr = E; |
| 559 | } |
| 560 | } |
| 561 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 562 | bool DSAStackTy::isOpenMPLocal(VarDecl *D, StackTy::reverse_iterator Iter) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 563 | D = D->getCanonicalDecl(); |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 564 | if (Stack.size() > 2) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 565 | reverse_iterator I = Iter, E = std::prev(Stack.rend()); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 566 | Scope *TopScope = nullptr; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 567 | while (I != E && !isParallelOrTaskRegion(I->Directive)) { |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 568 | ++I; |
| 569 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 570 | if (I == E) |
| 571 | return false; |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 572 | TopScope = I->CurScope ? I->CurScope->getParent() : nullptr; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 573 | Scope *CurScope = getCurScope(); |
| 574 | while (CurScope != TopScope && !CurScope->isDeclScope(D)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 575 | CurScope = CurScope->getParent(); |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 576 | } |
| 577 | return CurScope != TopScope; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 578 | } |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 579 | return false; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 580 | } |
| 581 | |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 582 | /// \brief Build a variable declaration for OpenMP loop iteration variable. |
| 583 | static VarDecl *buildVarDecl(Sema &SemaRef, SourceLocation Loc, QualType Type, |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 584 | StringRef Name, const AttrVec *Attrs = nullptr) { |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 585 | DeclContext *DC = SemaRef.CurContext; |
| 586 | IdentifierInfo *II = &SemaRef.PP.getIdentifierTable().get(Name); |
| 587 | TypeSourceInfo *TInfo = SemaRef.Context.getTrivialTypeSourceInfo(Type, Loc); |
| 588 | VarDecl *Decl = |
| 589 | VarDecl::Create(SemaRef.Context, DC, Loc, Loc, II, Type, TInfo, SC_None); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 590 | if (Attrs) { |
| 591 | for (specific_attr_iterator<AlignedAttr> I(Attrs->begin()), E(Attrs->end()); |
| 592 | I != E; ++I) |
| 593 | Decl->addAttr(*I); |
| 594 | } |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 595 | Decl->setImplicit(); |
| 596 | return Decl; |
| 597 | } |
| 598 | |
| 599 | static DeclRefExpr *buildDeclRefExpr(Sema &S, VarDecl *D, QualType Ty, |
| 600 | SourceLocation Loc, |
| 601 | bool RefersToCapture = false) { |
| 602 | D->setReferenced(); |
| 603 | D->markUsed(S.Context); |
| 604 | return DeclRefExpr::Create(S.getASTContext(), NestedNameSpecifierLoc(), |
| 605 | SourceLocation(), D, RefersToCapture, Loc, Ty, |
| 606 | VK_LValue); |
| 607 | } |
| 608 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 609 | DSAStackTy::DSAVarData DSAStackTy::getTopDSA(ValueDecl *D, bool FromParent) { |
| 610 | D = getCanonicalDecl(D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 611 | DSAVarData DVar; |
| 612 | |
| 613 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 614 | // in a Construct, C/C++, predetermined, p.1] |
| 615 | // Variables appearing in threadprivate directives are threadprivate. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 616 | auto *VD = dyn_cast<VarDecl>(D); |
| 617 | if ((VD && VD->getTLSKind() != VarDecl::TLS_None && |
| 618 | !(VD->hasAttr<OMPThreadPrivateDeclAttr>() && |
Samuel Antao | f8b5012 | 2015-07-13 22:54:53 +0000 | [diff] [blame] | 619 | SemaRef.getLangOpts().OpenMPUseTLS && |
| 620 | SemaRef.getASTContext().getTargetInfo().isTLSSupported())) || |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 621 | (VD && VD->getStorageClass() == SC_Register && |
| 622 | VD->hasAttr<AsmLabelAttr>() && !VD->isLocalVarDecl())) { |
| 623 | addDSA(D, buildDeclRefExpr(SemaRef, VD, D->getType().getNonReferenceType(), |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 624 | D->getLocation()), |
Alexey Bataev | f2453a0 | 2015-05-06 07:25:08 +0000 | [diff] [blame] | 625 | OMPC_threadprivate); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 626 | } |
| 627 | if (Stack[0].SharingMap.count(D)) { |
| 628 | DVar.RefExpr = Stack[0].SharingMap[D].RefExpr; |
| 629 | DVar.CKind = OMPC_threadprivate; |
| 630 | return DVar; |
| 631 | } |
| 632 | |
| 633 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
Alexey Bataev | dffa93a | 2015-12-10 08:20:58 +0000 | [diff] [blame] | 634 | // in a Construct, C/C++, predetermined, p.4] |
| 635 | // Static data members are shared. |
| 636 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 637 | // in a Construct, C/C++, predetermined, p.7] |
| 638 | // Variables with static storage duration that are declared in a scope |
| 639 | // inside the construct are shared. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 640 | if (VD && VD->isStaticDataMember()) { |
Alexey Bataev | dffa93a | 2015-12-10 08:20:58 +0000 | [diff] [blame] | 641 | DSAVarData DVarTemp = |
| 642 | hasDSA(D, isOpenMPPrivate, MatchesAlways(), FromParent); |
| 643 | if (DVarTemp.CKind != OMPC_unknown && DVarTemp.RefExpr) |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 644 | return DVar; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 645 | |
Alexey Bataev | dffa93a | 2015-12-10 08:20:58 +0000 | [diff] [blame] | 646 | DVar.CKind = OMPC_shared; |
| 647 | return DVar; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 648 | } |
| 649 | |
| 650 | QualType Type = D->getType().getNonReferenceType().getCanonicalType(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 651 | bool IsConstant = Type.isConstant(SemaRef.getASTContext()); |
| 652 | Type = SemaRef.getASTContext().getBaseElementType(Type); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 653 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 654 | // in a Construct, C/C++, predetermined, p.6] |
| 655 | // Variables with const qualified type having no mutable member are |
| 656 | // shared. |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 657 | CXXRecordDecl *RD = |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 658 | SemaRef.getLangOpts().CPlusPlus ? Type->getAsCXXRecordDecl() : nullptr; |
Alexey Bataev | c9bd03d | 2015-12-17 06:55:08 +0000 | [diff] [blame] | 659 | if (auto *CTSD = dyn_cast_or_null<ClassTemplateSpecializationDecl>(RD)) |
| 660 | if (auto *CTD = CTSD->getSpecializedTemplate()) |
| 661 | RD = CTD->getTemplatedDecl(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 662 | if (IsConstant && |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 663 | !(SemaRef.getLangOpts().CPlusPlus && RD && RD->hasMutableFields())) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 664 | // Variables with const-qualified type having no mutable member may be |
| 665 | // listed in a firstprivate clause, even if they are static data members. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 666 | DSAVarData DVarTemp = hasDSA(D, MatchesAnyClause(OMPC_firstprivate), |
| 667 | MatchesAlways(), FromParent); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 668 | if (DVarTemp.CKind == OMPC_firstprivate && DVarTemp.RefExpr) |
| 669 | return DVar; |
| 670 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 671 | DVar.CKind = OMPC_shared; |
| 672 | return DVar; |
| 673 | } |
| 674 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 675 | // Explicitly specified attributes and local variables with predetermined |
| 676 | // attributes. |
Alexey Bataev | dffa93a | 2015-12-10 08:20:58 +0000 | [diff] [blame] | 677 | auto StartI = std::next(Stack.rbegin()); |
| 678 | auto EndI = std::prev(Stack.rend()); |
| 679 | if (FromParent && StartI != EndI) { |
| 680 | StartI = std::next(StartI); |
| 681 | } |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 682 | auto I = std::prev(StartI); |
| 683 | if (I->SharingMap.count(D)) { |
| 684 | DVar.RefExpr = I->SharingMap[D].RefExpr; |
| 685 | DVar.CKind = I->SharingMap[D].Attributes; |
| 686 | DVar.ImplicitDSALoc = I->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 687 | } |
| 688 | |
| 689 | return DVar; |
| 690 | } |
| 691 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 692 | DSAStackTy::DSAVarData DSAStackTy::getImplicitDSA(ValueDecl *D, |
| 693 | bool FromParent) { |
| 694 | D = getCanonicalDecl(D); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 695 | auto StartI = Stack.rbegin(); |
| 696 | auto EndI = std::prev(Stack.rend()); |
| 697 | if (FromParent && StartI != EndI) { |
| 698 | StartI = std::next(StartI); |
| 699 | } |
| 700 | return getDSA(StartI, D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 701 | } |
| 702 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 703 | template <class ClausesPredicate, class DirectivesPredicate> |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 704 | DSAStackTy::DSAVarData DSAStackTy::hasDSA(ValueDecl *D, ClausesPredicate CPred, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 705 | DirectivesPredicate DPred, |
| 706 | bool FromParent) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 707 | D = getCanonicalDecl(D); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 708 | auto StartI = std::next(Stack.rbegin()); |
| 709 | auto EndI = std::prev(Stack.rend()); |
| 710 | if (FromParent && StartI != EndI) { |
| 711 | StartI = std::next(StartI); |
| 712 | } |
| 713 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
| 714 | if (!DPred(I->Directive) && !isParallelOrTaskRegion(I->Directive)) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 715 | continue; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 716 | DSAVarData DVar = getDSA(I, D); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 717 | if (CPred(DVar.CKind)) |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 718 | return DVar; |
| 719 | } |
| 720 | return DSAVarData(); |
| 721 | } |
| 722 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 723 | template <class ClausesPredicate, class DirectivesPredicate> |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 724 | DSAStackTy::DSAVarData |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 725 | DSAStackTy::hasInnermostDSA(ValueDecl *D, ClausesPredicate CPred, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 726 | DirectivesPredicate DPred, bool FromParent) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 727 | D = getCanonicalDecl(D); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 728 | auto StartI = std::next(Stack.rbegin()); |
| 729 | auto EndI = std::prev(Stack.rend()); |
| 730 | if (FromParent && StartI != EndI) { |
| 731 | StartI = std::next(StartI); |
| 732 | } |
| 733 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 734 | if (!DPred(I->Directive)) |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 735 | break; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 736 | DSAVarData DVar = getDSA(I, D); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 737 | if (CPred(DVar.CKind)) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 738 | return DVar; |
| 739 | return DSAVarData(); |
| 740 | } |
| 741 | return DSAVarData(); |
| 742 | } |
| 743 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 744 | bool DSAStackTy::hasExplicitDSA( |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 745 | ValueDecl *D, const llvm::function_ref<bool(OpenMPClauseKind)> &CPred, |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 746 | unsigned Level) { |
| 747 | if (CPred(ClauseKindMode)) |
| 748 | return true; |
| 749 | if (isClauseParsingMode()) |
| 750 | ++Level; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 751 | D = getCanonicalDecl(D); |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 752 | auto StartI = Stack.rbegin(); |
| 753 | auto EndI = std::prev(Stack.rend()); |
NAKAMURA Takumi | 0332eda | 2015-06-23 10:01:20 +0000 | [diff] [blame] | 754 | if (std::distance(StartI, EndI) <= (int)Level) |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 755 | return false; |
| 756 | std::advance(StartI, Level); |
| 757 | return (StartI->SharingMap.count(D) > 0) && StartI->SharingMap[D].RefExpr && |
| 758 | CPred(StartI->SharingMap[D].Attributes); |
| 759 | } |
| 760 | |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 761 | bool DSAStackTy::hasExplicitDirective( |
| 762 | const llvm::function_ref<bool(OpenMPDirectiveKind)> &DPred, |
| 763 | unsigned Level) { |
| 764 | if (isClauseParsingMode()) |
| 765 | ++Level; |
| 766 | auto StartI = Stack.rbegin(); |
| 767 | auto EndI = std::prev(Stack.rend()); |
| 768 | if (std::distance(StartI, EndI) <= (int)Level) |
| 769 | return false; |
| 770 | std::advance(StartI, Level); |
| 771 | return DPred(StartI->Directive); |
| 772 | } |
| 773 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 774 | template <class NamedDirectivesPredicate> |
| 775 | bool DSAStackTy::hasDirective(NamedDirectivesPredicate DPred, bool FromParent) { |
| 776 | auto StartI = std::next(Stack.rbegin()); |
| 777 | auto EndI = std::prev(Stack.rend()); |
| 778 | if (FromParent && StartI != EndI) { |
| 779 | StartI = std::next(StartI); |
| 780 | } |
| 781 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
| 782 | if (DPred(I->Directive, I->DirectiveName, I->ConstructLoc)) |
| 783 | return true; |
| 784 | } |
| 785 | return false; |
| 786 | } |
| 787 | |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 788 | OpenMPDirectiveKind DSAStackTy::getDirectiveForScope(const Scope *S) const { |
| 789 | for (auto I = Stack.rbegin(), EE = Stack.rend(); I != EE; ++I) |
| 790 | if (I->CurScope == S) |
| 791 | return I->Directive; |
| 792 | return OMPD_unknown; |
| 793 | } |
| 794 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 795 | void Sema::InitDataSharingAttributesStack() { |
| 796 | VarDataSharingAttributesStack = new DSAStackTy(*this); |
| 797 | } |
| 798 | |
| 799 | #define DSAStack static_cast<DSAStackTy *>(VarDataSharingAttributesStack) |
| 800 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 801 | bool Sema::IsOpenMPCapturedByRef(ValueDecl *D, |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 802 | const CapturedRegionScopeInfo *RSI) { |
| 803 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| 804 | |
| 805 | auto &Ctx = getASTContext(); |
| 806 | bool IsByRef = true; |
| 807 | |
| 808 | // Find the directive that is associated with the provided scope. |
| 809 | auto DKind = DSAStack->getDirectiveForScope(RSI->TheScope); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 810 | auto Ty = D->getType(); |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 811 | |
| 812 | if (isOpenMPTargetDirective(DKind)) { |
| 813 | // This table summarizes how a given variable should be passed to the device |
| 814 | // given its type and the clauses where it appears. This table is based on |
| 815 | // the description in OpenMP 4.5 [2.10.4, target Construct] and |
| 816 | // OpenMP 4.5 [2.15.5, Data-mapping Attribute Rules and Clauses]. |
| 817 | // |
| 818 | // ========================================================================= |
| 819 | // | type | defaultmap | pvt | first | is_device_ptr | map | res. | |
| 820 | // | |(tofrom:scalar)| | pvt | | | | |
| 821 | // ========================================================================= |
| 822 | // | scl | | | | - | | bycopy| |
| 823 | // | scl | | - | x | - | - | bycopy| |
| 824 | // | scl | | x | - | - | - | null | |
| 825 | // | scl | x | | | - | | byref | |
| 826 | // | scl | x | - | x | - | - | bycopy| |
| 827 | // | scl | x | x | - | - | - | null | |
| 828 | // | scl | | - | - | - | x | byref | |
| 829 | // | scl | x | - | - | - | x | byref | |
| 830 | // |
| 831 | // | agg | n.a. | | | - | | byref | |
| 832 | // | agg | n.a. | - | x | - | - | byref | |
| 833 | // | agg | n.a. | x | - | - | - | null | |
| 834 | // | agg | n.a. | - | - | - | x | byref | |
| 835 | // | agg | n.a. | - | - | - | x[] | byref | |
| 836 | // |
| 837 | // | ptr | n.a. | | | - | | bycopy| |
| 838 | // | ptr | n.a. | - | x | - | - | bycopy| |
| 839 | // | ptr | n.a. | x | - | - | - | null | |
| 840 | // | ptr | n.a. | - | - | - | x | byref | |
| 841 | // | ptr | n.a. | - | - | - | x[] | bycopy| |
| 842 | // | ptr | n.a. | - | - | x | | bycopy| |
| 843 | // | ptr | n.a. | - | - | x | x | bycopy| |
| 844 | // | ptr | n.a. | - | - | x | x[] | bycopy| |
| 845 | // ========================================================================= |
| 846 | // Legend: |
| 847 | // scl - scalar |
| 848 | // ptr - pointer |
| 849 | // agg - aggregate |
| 850 | // x - applies |
| 851 | // - - invalid in this combination |
| 852 | // [] - mapped with an array section |
| 853 | // byref - should be mapped by reference |
| 854 | // byval - should be mapped by value |
| 855 | // null - initialize a local variable to null on the device |
| 856 | // |
| 857 | // Observations: |
| 858 | // - All scalar declarations that show up in a map clause have to be passed |
| 859 | // by reference, because they may have been mapped in the enclosing data |
| 860 | // environment. |
| 861 | // - If the scalar value does not fit the size of uintptr, it has to be |
| 862 | // passed by reference, regardless the result in the table above. |
| 863 | // - For pointers mapped by value that have either an implicit map or an |
| 864 | // array section, the runtime library may pass the NULL value to the |
| 865 | // device instead of the value passed to it by the compiler. |
| 866 | |
| 867 | // FIXME: Right now, only implicit maps are implemented. Properly mapping |
| 868 | // values requires having the map, private, and firstprivate clauses SEMA |
| 869 | // and parsing in place, which we don't yet. |
| 870 | |
| 871 | if (Ty->isReferenceType()) |
| 872 | Ty = Ty->castAs<ReferenceType>()->getPointeeType(); |
| 873 | IsByRef = !Ty->isScalarType(); |
| 874 | } |
| 875 | |
| 876 | // When passing data by value, we need to make sure it fits the uintptr size |
| 877 | // and alignment, because the runtime library only deals with uintptr types. |
| 878 | // If it does not fit the uintptr size, we need to pass the data by reference |
| 879 | // instead. |
| 880 | if (!IsByRef && |
| 881 | (Ctx.getTypeSizeInChars(Ty) > |
| 882 | Ctx.getTypeSizeInChars(Ctx.getUIntPtrType()) || |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 883 | Ctx.getDeclAlign(D) > Ctx.getTypeAlignInChars(Ctx.getUIntPtrType()))) |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 884 | IsByRef = true; |
| 885 | |
| 886 | return IsByRef; |
| 887 | } |
| 888 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 889 | bool Sema::IsOpenMPCapturedDecl(ValueDecl *D) { |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 890 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 891 | D = getCanonicalDecl(D); |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 892 | |
| 893 | // If we are attempting to capture a global variable in a directive with |
| 894 | // 'target' we return true so that this global is also mapped to the device. |
| 895 | // |
| 896 | // FIXME: If the declaration is enclosed in a 'declare target' directive, |
| 897 | // then it should not be captured. Therefore, an extra check has to be |
| 898 | // inserted here once support for 'declare target' is added. |
| 899 | // |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 900 | auto *VD = dyn_cast<VarDecl>(D); |
| 901 | if (VD && !VD->hasLocalStorage()) { |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 902 | if (DSAStack->getCurrentDirective() == OMPD_target && |
| 903 | !DSAStack->isClauseParsingMode()) { |
| 904 | return true; |
| 905 | } |
| 906 | if (DSAStack->getCurScope() && |
| 907 | DSAStack->hasDirective( |
| 908 | [](OpenMPDirectiveKind K, const DeclarationNameInfo &DNI, |
| 909 | SourceLocation Loc) -> bool { |
| 910 | return isOpenMPTargetDirective(K); |
| 911 | }, |
| 912 | false)) { |
| 913 | return true; |
| 914 | } |
| 915 | } |
| 916 | |
Alexey Bataev | 48977c3 | 2015-08-04 08:10:48 +0000 | [diff] [blame] | 917 | if (DSAStack->getCurrentDirective() != OMPD_unknown && |
| 918 | (!DSAStack->isClauseParsingMode() || |
| 919 | DSAStack->getParentDirective() != OMPD_unknown)) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 920 | if (DSAStack->isLoopControlVariable(D) || |
| 921 | (VD && VD->hasLocalStorage() && |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 922 | isParallelOrTaskRegion(DSAStack->getCurrentDirective())) || |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 923 | (VD && DSAStack->isForceVarCapturing())) |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 924 | return true; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 925 | auto DVarPrivate = DSAStack->getTopDSA(D, DSAStack->isClauseParsingMode()); |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 926 | if (DVarPrivate.CKind != OMPC_unknown && isOpenMPPrivate(DVarPrivate.CKind)) |
| 927 | return true; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 928 | DVarPrivate = DSAStack->hasDSA(D, isOpenMPPrivate, MatchesAlways(), |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 929 | DSAStack->isClauseParsingMode()); |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 930 | return DVarPrivate.CKind != OMPC_unknown; |
| 931 | } |
| 932 | return false; |
| 933 | } |
| 934 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 935 | bool Sema::isOpenMPPrivateDecl(ValueDecl *D, unsigned Level) { |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 936 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| 937 | return DSAStack->hasExplicitDSA( |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 938 | D, [](OpenMPClauseKind K) -> bool { return K == OMPC_private; }, Level); |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 939 | } |
| 940 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 941 | bool Sema::isOpenMPTargetCapturedDecl(ValueDecl *D, unsigned Level) { |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 942 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| 943 | // Return true if the current level is no longer enclosed in a target region. |
| 944 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 945 | auto *VD = dyn_cast<VarDecl>(D); |
| 946 | return VD && !VD->hasLocalStorage() && |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 947 | DSAStack->hasExplicitDirective(isOpenMPTargetDirective, Level); |
| 948 | } |
| 949 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 950 | void Sema::DestroyDataSharingAttributesStack() { delete DSAStack; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 951 | |
| 952 | void Sema::StartOpenMPDSABlock(OpenMPDirectiveKind DKind, |
| 953 | const DeclarationNameInfo &DirName, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 954 | Scope *CurScope, SourceLocation Loc) { |
| 955 | DSAStack->push(DKind, DirName, CurScope, Loc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 956 | PushExpressionEvaluationContext(PotentiallyEvaluated); |
| 957 | } |
| 958 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 959 | void Sema::StartOpenMPClause(OpenMPClauseKind K) { |
| 960 | DSAStack->setClauseParsingMode(K); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 961 | } |
| 962 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 963 | void Sema::EndOpenMPClause() { |
| 964 | DSAStack->setClauseParsingMode(/*K=*/OMPC_unknown); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 965 | } |
| 966 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 967 | void Sema::EndOpenMPDSABlock(Stmt *CurDirective) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 968 | // OpenMP [2.14.3.5, Restrictions, C/C++, p.1] |
| 969 | // A variable of class type (or array thereof) that appears in a lastprivate |
| 970 | // clause requires an accessible, unambiguous default constructor for the |
| 971 | // class type, unless the list item is also specified in a firstprivate |
| 972 | // clause. |
| 973 | if (auto D = dyn_cast_or_null<OMPExecutableDirective>(CurDirective)) { |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 974 | for (auto *C : D->clauses()) { |
| 975 | if (auto *Clause = dyn_cast<OMPLastprivateClause>(C)) { |
| 976 | SmallVector<Expr *, 8> PrivateCopies; |
| 977 | for (auto *DE : Clause->varlists()) { |
| 978 | if (DE->isValueDependent() || DE->isTypeDependent()) { |
| 979 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 980 | continue; |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 981 | } |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 982 | DE = DE->IgnoreParens(); |
| 983 | VarDecl *VD = nullptr; |
| 984 | FieldDecl *FD = nullptr; |
| 985 | ValueDecl *D; |
| 986 | if (auto *DRE = dyn_cast<DeclRefExpr>(DE)) { |
| 987 | VD = cast<VarDecl>(DRE->getDecl()); |
| 988 | D = VD; |
| 989 | } else { |
| 990 | assert(isa<MemberExpr>(DE)); |
| 991 | FD = cast<FieldDecl>(cast<MemberExpr>(DE)->getMemberDecl()); |
| 992 | D = FD; |
| 993 | } |
| 994 | QualType Type = D->getType().getNonReferenceType(); |
| 995 | auto DVar = DSAStack->getTopDSA(D, false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 996 | if (DVar.CKind == OMPC_lastprivate) { |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 997 | // Generate helper private variable and initialize it with the |
| 998 | // default value. The address of the original variable is replaced |
| 999 | // by the address of the new private variable in CodeGen. This new |
| 1000 | // variable is not added to IdResolver, so the code in the OpenMP |
| 1001 | // region uses original variable for proper diagnostics. |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 1002 | auto *VDPrivate = buildVarDecl( |
| 1003 | *this, DE->getExprLoc(), Type.getUnqualifiedType(), |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1004 | D->getName(), D->hasAttrs() ? &D->getAttrs() : nullptr); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1005 | ActOnUninitializedDecl(VDPrivate, /*TypeMayContainAuto=*/false); |
| 1006 | if (VDPrivate->isInvalidDecl()) |
| 1007 | continue; |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 1008 | PrivateCopies.push_back(buildDeclRefExpr( |
| 1009 | *this, VDPrivate, DE->getType(), DE->getExprLoc())); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1010 | } else { |
| 1011 | // The variable is also a firstprivate, so initialization sequence |
| 1012 | // for private copy is generated already. |
| 1013 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1014 | } |
| 1015 | } |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1016 | // Set initializers to private copies if no errors were found. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1017 | if (PrivateCopies.size() == Clause->varlist_size()) |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1018 | Clause->setPrivateCopies(PrivateCopies); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1019 | } |
| 1020 | } |
| 1021 | } |
| 1022 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1023 | DSAStack->pop(); |
| 1024 | DiscardCleanupsInEvaluationContext(); |
| 1025 | PopExpressionEvaluationContext(); |
| 1026 | } |
| 1027 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 1028 | static bool FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV, |
| 1029 | Expr *NumIterations, Sema &SemaRef, |
| 1030 | Scope *S); |
| 1031 | |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1032 | namespace { |
| 1033 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1034 | class VarDeclFilterCCC : public CorrectionCandidateCallback { |
| 1035 | private: |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1036 | Sema &SemaRef; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1037 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1038 | public: |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1039 | explicit VarDeclFilterCCC(Sema &S) : SemaRef(S) {} |
Craig Topper | e14c0f8 | 2014-03-12 04:55:44 +0000 | [diff] [blame] | 1040 | bool ValidateCandidate(const TypoCorrection &Candidate) override { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1041 | NamedDecl *ND = Candidate.getCorrectionDecl(); |
| 1042 | if (VarDecl *VD = dyn_cast_or_null<VarDecl>(ND)) { |
| 1043 | return VD->hasGlobalStorage() && |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1044 | SemaRef.isDeclInScope(ND, SemaRef.getCurLexicalContext(), |
| 1045 | SemaRef.getCurScope()); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1046 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1047 | return false; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1048 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1049 | }; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1050 | } // namespace |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1051 | |
| 1052 | ExprResult Sema::ActOnOpenMPIdExpression(Scope *CurScope, |
| 1053 | CXXScopeSpec &ScopeSpec, |
| 1054 | const DeclarationNameInfo &Id) { |
| 1055 | LookupResult Lookup(*this, Id, LookupOrdinaryName); |
| 1056 | LookupParsedName(Lookup, CurScope, &ScopeSpec, true); |
| 1057 | |
| 1058 | if (Lookup.isAmbiguous()) |
| 1059 | return ExprError(); |
| 1060 | |
| 1061 | VarDecl *VD; |
| 1062 | if (!Lookup.isSingleResult()) { |
Kaelyn Takata | 89c881b | 2014-10-27 18:07:29 +0000 | [diff] [blame] | 1063 | if (TypoCorrection Corrected = CorrectTypo( |
| 1064 | Id, LookupOrdinaryName, CurScope, nullptr, |
| 1065 | llvm::make_unique<VarDeclFilterCCC>(*this), CTK_ErrorRecovery)) { |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 1066 | diagnoseTypo(Corrected, |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 1067 | PDiag(Lookup.empty() |
| 1068 | ? diag::err_undeclared_var_use_suggest |
| 1069 | : diag::err_omp_expected_var_arg_suggest) |
| 1070 | << Id.getName()); |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 1071 | VD = Corrected.getCorrectionDeclAs<VarDecl>(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1072 | } else { |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 1073 | Diag(Id.getLoc(), Lookup.empty() ? diag::err_undeclared_var_use |
| 1074 | : diag::err_omp_expected_var_arg) |
| 1075 | << Id.getName(); |
| 1076 | return ExprError(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1077 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1078 | } else { |
| 1079 | if (!(VD = Lookup.getAsSingle<VarDecl>())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1080 | Diag(Id.getLoc(), diag::err_omp_expected_var_arg) << Id.getName(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1081 | Diag(Lookup.getFoundDecl()->getLocation(), diag::note_declared_at); |
| 1082 | return ExprError(); |
| 1083 | } |
| 1084 | } |
| 1085 | Lookup.suppressDiagnostics(); |
| 1086 | |
| 1087 | // OpenMP [2.9.2, Syntax, C/C++] |
| 1088 | // Variables must be file-scope, namespace-scope, or static block-scope. |
| 1089 | if (!VD->hasGlobalStorage()) { |
| 1090 | Diag(Id.getLoc(), diag::err_omp_global_var_arg) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1091 | << getOpenMPDirectiveName(OMPD_threadprivate) << !VD->isStaticLocal(); |
| 1092 | bool IsDecl = |
| 1093 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1094 | Diag(VD->getLocation(), |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1095 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1096 | << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1097 | return ExprError(); |
| 1098 | } |
| 1099 | |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1100 | VarDecl *CanonicalVD = VD->getCanonicalDecl(); |
| 1101 | NamedDecl *ND = cast<NamedDecl>(CanonicalVD); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1102 | // OpenMP [2.9.2, Restrictions, C/C++, p.2] |
| 1103 | // A threadprivate directive for file-scope variables must appear outside |
| 1104 | // any definition or declaration. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1105 | if (CanonicalVD->getDeclContext()->isTranslationUnit() && |
| 1106 | !getCurLexicalContext()->isTranslationUnit()) { |
| 1107 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1108 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1109 | bool IsDecl = |
| 1110 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1111 | Diag(VD->getLocation(), |
| 1112 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1113 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1114 | return ExprError(); |
| 1115 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1116 | // OpenMP [2.9.2, Restrictions, C/C++, p.3] |
| 1117 | // A threadprivate directive for static class member variables must appear |
| 1118 | // in the class definition, in the same scope in which the member |
| 1119 | // variables are declared. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1120 | if (CanonicalVD->isStaticDataMember() && |
| 1121 | !CanonicalVD->getDeclContext()->Equals(getCurLexicalContext())) { |
| 1122 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1123 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1124 | bool IsDecl = |
| 1125 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1126 | Diag(VD->getLocation(), |
| 1127 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1128 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1129 | return ExprError(); |
| 1130 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1131 | // OpenMP [2.9.2, Restrictions, C/C++, p.4] |
| 1132 | // A threadprivate directive for namespace-scope variables must appear |
| 1133 | // outside any definition or declaration other than the namespace |
| 1134 | // definition itself. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1135 | if (CanonicalVD->getDeclContext()->isNamespace() && |
| 1136 | (!getCurLexicalContext()->isFileContext() || |
| 1137 | !getCurLexicalContext()->Encloses(CanonicalVD->getDeclContext()))) { |
| 1138 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1139 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1140 | bool IsDecl = |
| 1141 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1142 | Diag(VD->getLocation(), |
| 1143 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1144 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1145 | return ExprError(); |
| 1146 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1147 | // OpenMP [2.9.2, Restrictions, C/C++, p.6] |
| 1148 | // A threadprivate directive for static block-scope variables must appear |
| 1149 | // in the scope of the variable and not in a nested scope. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1150 | if (CanonicalVD->isStaticLocal() && CurScope && |
| 1151 | !isDeclInScope(ND, getCurLexicalContext(), CurScope)) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1152 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1153 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1154 | bool IsDecl = |
| 1155 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1156 | Diag(VD->getLocation(), |
| 1157 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1158 | << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1159 | return ExprError(); |
| 1160 | } |
| 1161 | |
| 1162 | // OpenMP [2.9.2, Restrictions, C/C++, p.2-6] |
| 1163 | // A threadprivate directive must lexically precede all references to any |
| 1164 | // of the variables in its list. |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 1165 | if (VD->isUsed() && !DSAStack->isThreadPrivate(VD)) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1166 | Diag(Id.getLoc(), diag::err_omp_var_used) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1167 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1168 | return ExprError(); |
| 1169 | } |
| 1170 | |
| 1171 | QualType ExprType = VD->getType().getNonReferenceType(); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 1172 | ExprResult DE = buildDeclRefExpr(*this, VD, ExprType, Id.getLoc()); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1173 | return DE; |
| 1174 | } |
| 1175 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1176 | Sema::DeclGroupPtrTy |
| 1177 | Sema::ActOnOpenMPThreadprivateDirective(SourceLocation Loc, |
| 1178 | ArrayRef<Expr *> VarList) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1179 | if (OMPThreadPrivateDecl *D = CheckOMPThreadPrivateDecl(Loc, VarList)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1180 | CurContext->addDecl(D); |
| 1181 | return DeclGroupPtrTy::make(DeclGroupRef(D)); |
| 1182 | } |
David Blaikie | 0403cb1 | 2016-01-15 23:43:25 +0000 | [diff] [blame] | 1183 | return nullptr; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1184 | } |
| 1185 | |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1186 | namespace { |
| 1187 | class LocalVarRefChecker : public ConstStmtVisitor<LocalVarRefChecker, bool> { |
| 1188 | Sema &SemaRef; |
| 1189 | |
| 1190 | public: |
| 1191 | bool VisitDeclRefExpr(const DeclRefExpr *E) { |
| 1192 | if (auto VD = dyn_cast<VarDecl>(E->getDecl())) { |
| 1193 | if (VD->hasLocalStorage()) { |
| 1194 | SemaRef.Diag(E->getLocStart(), |
| 1195 | diag::err_omp_local_var_in_threadprivate_init) |
| 1196 | << E->getSourceRange(); |
| 1197 | SemaRef.Diag(VD->getLocation(), diag::note_defined_here) |
| 1198 | << VD << VD->getSourceRange(); |
| 1199 | return true; |
| 1200 | } |
| 1201 | } |
| 1202 | return false; |
| 1203 | } |
| 1204 | bool VisitStmt(const Stmt *S) { |
| 1205 | for (auto Child : S->children()) { |
| 1206 | if (Child && Visit(Child)) |
| 1207 | return true; |
| 1208 | } |
| 1209 | return false; |
| 1210 | } |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 1211 | explicit LocalVarRefChecker(Sema &SemaRef) : SemaRef(SemaRef) {} |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1212 | }; |
| 1213 | } // namespace |
| 1214 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1215 | OMPThreadPrivateDecl * |
| 1216 | Sema::CheckOMPThreadPrivateDecl(SourceLocation Loc, ArrayRef<Expr *> VarList) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1217 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1218 | for (auto &RefExpr : VarList) { |
| 1219 | DeclRefExpr *DE = cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1220 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); |
| 1221 | SourceLocation ILoc = DE->getExprLoc(); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1222 | |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 1223 | QualType QType = VD->getType(); |
| 1224 | if (QType->isDependentType() || QType->isInstantiationDependentType()) { |
| 1225 | // It will be analyzed later. |
| 1226 | Vars.push_back(DE); |
| 1227 | continue; |
| 1228 | } |
| 1229 | |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1230 | // OpenMP [2.9.2, Restrictions, C/C++, p.10] |
| 1231 | // A threadprivate variable must not have an incomplete type. |
| 1232 | if (RequireCompleteType(ILoc, VD->getType(), |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1233 | diag::err_omp_threadprivate_incomplete_type)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1234 | continue; |
| 1235 | } |
| 1236 | |
| 1237 | // OpenMP [2.9.2, Restrictions, C/C++, p.10] |
| 1238 | // A threadprivate variable must not have a reference type. |
| 1239 | if (VD->getType()->isReferenceType()) { |
| 1240 | Diag(ILoc, diag::err_omp_ref_type_arg) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1241 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD->getType(); |
| 1242 | bool IsDecl = |
| 1243 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1244 | Diag(VD->getLocation(), |
| 1245 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1246 | << VD; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1247 | continue; |
| 1248 | } |
| 1249 | |
Samuel Antao | f8b5012 | 2015-07-13 22:54:53 +0000 | [diff] [blame] | 1250 | // Check if this is a TLS variable. If TLS is not being supported, produce |
| 1251 | // the corresponding diagnostic. |
| 1252 | if ((VD->getTLSKind() != VarDecl::TLS_None && |
| 1253 | !(VD->hasAttr<OMPThreadPrivateDeclAttr>() && |
| 1254 | getLangOpts().OpenMPUseTLS && |
| 1255 | getASTContext().getTargetInfo().isTLSSupported())) || |
Alexey Bataev | 1a8b3f1 | 2015-05-06 06:34:55 +0000 | [diff] [blame] | 1256 | (VD->getStorageClass() == SC_Register && VD->hasAttr<AsmLabelAttr>() && |
| 1257 | !VD->isLocalVarDecl())) { |
Alexey Bataev | 26a3924 | 2015-01-13 03:35:30 +0000 | [diff] [blame] | 1258 | Diag(ILoc, diag::err_omp_var_thread_local) |
| 1259 | << VD << ((VD->getTLSKind() != VarDecl::TLS_None) ? 0 : 1); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1260 | bool IsDecl = |
| 1261 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1262 | Diag(VD->getLocation(), |
| 1263 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1264 | << VD; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1265 | continue; |
| 1266 | } |
| 1267 | |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1268 | // Check if initial value of threadprivate variable reference variable with |
| 1269 | // local storage (it is not supported by runtime). |
| 1270 | if (auto Init = VD->getAnyInitializer()) { |
| 1271 | LocalVarRefChecker Checker(*this); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1272 | if (Checker.Visit(Init)) |
| 1273 | continue; |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1274 | } |
| 1275 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1276 | Vars.push_back(RefExpr); |
Alexey Bataev | d178ad4 | 2014-03-07 08:03:37 +0000 | [diff] [blame] | 1277 | DSAStack->addDSA(VD, DE, OMPC_threadprivate); |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 1278 | VD->addAttr(OMPThreadPrivateDeclAttr::CreateImplicit( |
| 1279 | Context, SourceRange(Loc, Loc))); |
| 1280 | if (auto *ML = Context.getASTMutationListener()) |
| 1281 | ML->DeclarationMarkedOpenMPThreadPrivate(VD); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1282 | } |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 1283 | OMPThreadPrivateDecl *D = nullptr; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 1284 | if (!Vars.empty()) { |
| 1285 | D = OMPThreadPrivateDecl::Create(Context, getCurLexicalContext(), Loc, |
| 1286 | Vars); |
| 1287 | D->setAccess(AS_public); |
| 1288 | } |
| 1289 | return D; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1290 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1291 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1292 | static void ReportOriginalDSA(Sema &SemaRef, DSAStackTy *Stack, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1293 | const ValueDecl *D, DSAStackTy::DSAVarData DVar, |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1294 | bool IsLoopIterVar = false) { |
| 1295 | if (DVar.RefExpr) { |
| 1296 | SemaRef.Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_explicit_dsa) |
| 1297 | << getOpenMPClauseName(DVar.CKind); |
| 1298 | return; |
| 1299 | } |
| 1300 | enum { |
| 1301 | PDSA_StaticMemberShared, |
| 1302 | PDSA_StaticLocalVarShared, |
| 1303 | PDSA_LoopIterVarPrivate, |
| 1304 | PDSA_LoopIterVarLinear, |
| 1305 | PDSA_LoopIterVarLastprivate, |
| 1306 | PDSA_ConstVarShared, |
| 1307 | PDSA_GlobalVarShared, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1308 | PDSA_TaskVarFirstprivate, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1309 | PDSA_LocalVarPrivate, |
| 1310 | PDSA_Implicit |
| 1311 | } Reason = PDSA_Implicit; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1312 | bool ReportHint = false; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1313 | auto ReportLoc = D->getLocation(); |
| 1314 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1315 | if (IsLoopIterVar) { |
| 1316 | if (DVar.CKind == OMPC_private) |
| 1317 | Reason = PDSA_LoopIterVarPrivate; |
| 1318 | else if (DVar.CKind == OMPC_lastprivate) |
| 1319 | Reason = PDSA_LoopIterVarLastprivate; |
| 1320 | else |
| 1321 | Reason = PDSA_LoopIterVarLinear; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1322 | } else if (DVar.DKind == OMPD_task && DVar.CKind == OMPC_firstprivate) { |
| 1323 | Reason = PDSA_TaskVarFirstprivate; |
| 1324 | ReportLoc = DVar.ImplicitDSALoc; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1325 | } else if (VD && VD->isStaticLocal()) |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1326 | Reason = PDSA_StaticLocalVarShared; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1327 | else if (VD && VD->isStaticDataMember()) |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1328 | Reason = PDSA_StaticMemberShared; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1329 | else if (VD && VD->isFileVarDecl()) |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1330 | Reason = PDSA_GlobalVarShared; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1331 | else if (D->getType().isConstant(SemaRef.getASTContext())) |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1332 | Reason = PDSA_ConstVarShared; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1333 | else if (VD && VD->isLocalVarDecl() && DVar.CKind == OMPC_private) { |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1334 | ReportHint = true; |
| 1335 | Reason = PDSA_LocalVarPrivate; |
| 1336 | } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1337 | if (Reason != PDSA_Implicit) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1338 | SemaRef.Diag(ReportLoc, diag::note_omp_predetermined_dsa) |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1339 | << Reason << ReportHint |
| 1340 | << getOpenMPDirectiveName(Stack->getCurrentDirective()); |
| 1341 | } else if (DVar.ImplicitDSALoc.isValid()) { |
| 1342 | SemaRef.Diag(DVar.ImplicitDSALoc, diag::note_omp_implicit_dsa) |
| 1343 | << getOpenMPClauseName(DVar.CKind); |
| 1344 | } |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1345 | } |
| 1346 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1347 | namespace { |
| 1348 | class DSAAttrChecker : public StmtVisitor<DSAAttrChecker, void> { |
| 1349 | DSAStackTy *Stack; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1350 | Sema &SemaRef; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1351 | bool ErrorFound; |
| 1352 | CapturedStmt *CS; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1353 | llvm::SmallVector<Expr *, 8> ImplicitFirstprivate; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1354 | llvm::DenseMap<ValueDecl *, Expr *> VarsWithInheritedDSA; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1355 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1356 | public: |
| 1357 | void VisitDeclRefExpr(DeclRefExpr *E) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1358 | if (auto *VD = dyn_cast<VarDecl>(E->getDecl())) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1359 | // Skip internally declared variables. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1360 | if (VD->isLocalVarDecl() && !CS->capturesVariable(VD)) |
| 1361 | return; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1362 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1363 | auto DVar = Stack->getTopDSA(VD, false); |
| 1364 | // Check if the variable has explicit DSA set and stop analysis if it so. |
| 1365 | if (DVar.RefExpr) return; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1366 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1367 | auto ELoc = E->getExprLoc(); |
| 1368 | auto DKind = Stack->getCurrentDirective(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1369 | // The default(none) clause requires that each variable that is referenced |
| 1370 | // in the construct, and does not have a predetermined data-sharing |
| 1371 | // attribute, must have its data-sharing attribute explicitly determined |
| 1372 | // by being listed in a data-sharing attribute clause. |
| 1373 | if (DVar.CKind == OMPC_unknown && Stack->getDefaultDSA() == DSA_none && |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1374 | isParallelOrTaskRegion(DKind) && |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1375 | VarsWithInheritedDSA.count(VD) == 0) { |
| 1376 | VarsWithInheritedDSA[VD] = E; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1377 | return; |
| 1378 | } |
| 1379 | |
| 1380 | // OpenMP [2.9.3.6, Restrictions, p.2] |
| 1381 | // A list item that appears in a reduction clause of the innermost |
| 1382 | // enclosing worksharing or parallel construct may not be accessed in an |
| 1383 | // explicit task. |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1384 | DVar = Stack->hasInnermostDSA(VD, MatchesAnyClause(OMPC_reduction), |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1385 | [](OpenMPDirectiveKind K) -> bool { |
| 1386 | return isOpenMPParallelDirective(K) || |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1387 | isOpenMPWorksharingDirective(K) || |
| 1388 | isOpenMPTeamsDirective(K); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1389 | }, |
| 1390 | false); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1391 | if (DKind == OMPD_task && DVar.CKind == OMPC_reduction) { |
| 1392 | ErrorFound = true; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1393 | SemaRef.Diag(ELoc, diag::err_omp_reduction_in_task); |
| 1394 | ReportOriginalDSA(SemaRef, Stack, VD, DVar); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1395 | return; |
| 1396 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1397 | |
| 1398 | // Define implicit data-sharing attributes for task. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1399 | DVar = Stack->getImplicitDSA(VD, false); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1400 | if (DKind == OMPD_task && DVar.CKind != OMPC_shared) |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1401 | ImplicitFirstprivate.push_back(E); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1402 | } |
| 1403 | } |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1404 | void VisitMemberExpr(MemberExpr *E) { |
| 1405 | if (isa<CXXThisExpr>(E->getBase()->IgnoreParens())) { |
| 1406 | if (auto *FD = dyn_cast<FieldDecl>(E->getMemberDecl())) { |
| 1407 | auto DVar = Stack->getTopDSA(FD, false); |
| 1408 | // Check if the variable has explicit DSA set and stop analysis if it |
| 1409 | // so. |
| 1410 | if (DVar.RefExpr) |
| 1411 | return; |
| 1412 | |
| 1413 | auto ELoc = E->getExprLoc(); |
| 1414 | auto DKind = Stack->getCurrentDirective(); |
| 1415 | // OpenMP [2.9.3.6, Restrictions, p.2] |
| 1416 | // A list item that appears in a reduction clause of the innermost |
| 1417 | // enclosing worksharing or parallel construct may not be accessed in |
| 1418 | // an |
| 1419 | // explicit task. |
| 1420 | DVar = |
| 1421 | Stack->hasInnermostDSA(FD, MatchesAnyClause(OMPC_reduction), |
| 1422 | [](OpenMPDirectiveKind K) -> bool { |
| 1423 | return isOpenMPParallelDirective(K) || |
| 1424 | isOpenMPWorksharingDirective(K) || |
| 1425 | isOpenMPTeamsDirective(K); |
| 1426 | }, |
| 1427 | false); |
| 1428 | if (DKind == OMPD_task && DVar.CKind == OMPC_reduction) { |
| 1429 | ErrorFound = true; |
| 1430 | SemaRef.Diag(ELoc, diag::err_omp_reduction_in_task); |
| 1431 | ReportOriginalDSA(SemaRef, Stack, FD, DVar); |
| 1432 | return; |
| 1433 | } |
| 1434 | |
| 1435 | // Define implicit data-sharing attributes for task. |
| 1436 | DVar = Stack->getImplicitDSA(FD, false); |
| 1437 | if (DKind == OMPD_task && DVar.CKind != OMPC_shared) |
| 1438 | ImplicitFirstprivate.push_back(E); |
| 1439 | } |
| 1440 | } |
| 1441 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1442 | void VisitOMPExecutableDirective(OMPExecutableDirective *S) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1443 | for (auto *C : S->clauses()) { |
| 1444 | // Skip analysis of arguments of implicitly defined firstprivate clause |
| 1445 | // for task directives. |
| 1446 | if (C && (!isa<OMPFirstprivateClause>(C) || C->getLocStart().isValid())) |
| 1447 | for (auto *CC : C->children()) { |
| 1448 | if (CC) |
| 1449 | Visit(CC); |
| 1450 | } |
| 1451 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1452 | } |
| 1453 | void VisitStmt(Stmt *S) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1454 | for (auto *C : S->children()) { |
| 1455 | if (C && !isa<OMPExecutableDirective>(C)) |
| 1456 | Visit(C); |
| 1457 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1458 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1459 | |
| 1460 | bool isErrorFound() { return ErrorFound; } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1461 | ArrayRef<Expr *> getImplicitFirstprivate() { return ImplicitFirstprivate; } |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1462 | llvm::DenseMap<ValueDecl *, Expr *> &getVarsWithInheritedDSA() { |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1463 | return VarsWithInheritedDSA; |
| 1464 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1465 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1466 | DSAAttrChecker(DSAStackTy *S, Sema &SemaRef, CapturedStmt *CS) |
| 1467 | : Stack(S), SemaRef(SemaRef), ErrorFound(false), CS(CS) {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1468 | }; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1469 | } // namespace |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1470 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1471 | void Sema::ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, Scope *CurScope) { |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1472 | switch (DKind) { |
| 1473 | case OMPD_parallel: { |
| 1474 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1475 | QualType KmpInt32PtrTy = |
| 1476 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1477 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1478 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1479 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1480 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1481 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1482 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1483 | Params); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1484 | break; |
| 1485 | } |
| 1486 | case OMPD_simd: { |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1487 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1488 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1489 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1490 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1491 | Params); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1492 | break; |
| 1493 | } |
| 1494 | case OMPD_for: { |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1495 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1496 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1497 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1498 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1499 | Params); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1500 | break; |
| 1501 | } |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1502 | case OMPD_for_simd: { |
| 1503 | Sema::CapturedParamNameType Params[] = { |
| 1504 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1505 | }; |
| 1506 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1507 | Params); |
| 1508 | break; |
| 1509 | } |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 1510 | case OMPD_sections: { |
| 1511 | Sema::CapturedParamNameType Params[] = { |
| 1512 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1513 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1514 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1515 | Params); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 1516 | break; |
| 1517 | } |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1518 | case OMPD_section: { |
| 1519 | Sema::CapturedParamNameType Params[] = { |
| 1520 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1521 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1522 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1523 | Params); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1524 | break; |
| 1525 | } |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 1526 | case OMPD_single: { |
| 1527 | Sema::CapturedParamNameType Params[] = { |
| 1528 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1529 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1530 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1531 | Params); |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 1532 | break; |
| 1533 | } |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1534 | case OMPD_master: { |
| 1535 | Sema::CapturedParamNameType Params[] = { |
| 1536 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1537 | }; |
| 1538 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1539 | Params); |
| 1540 | break; |
| 1541 | } |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1542 | case OMPD_critical: { |
| 1543 | Sema::CapturedParamNameType Params[] = { |
| 1544 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1545 | }; |
| 1546 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1547 | Params); |
| 1548 | break; |
| 1549 | } |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1550 | case OMPD_parallel_for: { |
| 1551 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1552 | QualType KmpInt32PtrTy = |
| 1553 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1554 | Sema::CapturedParamNameType Params[] = { |
| 1555 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1556 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1557 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1558 | }; |
| 1559 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1560 | Params); |
| 1561 | break; |
| 1562 | } |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1563 | case OMPD_parallel_for_simd: { |
| 1564 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1565 | QualType KmpInt32PtrTy = |
| 1566 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1567 | Sema::CapturedParamNameType Params[] = { |
| 1568 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1569 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1570 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1571 | }; |
| 1572 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1573 | Params); |
| 1574 | break; |
| 1575 | } |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1576 | case OMPD_parallel_sections: { |
Alexey Bataev | 68adb7d | 2015-04-14 03:29:22 +0000 | [diff] [blame] | 1577 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1578 | QualType KmpInt32PtrTy = |
| 1579 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1580 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | 68adb7d | 2015-04-14 03:29:22 +0000 | [diff] [blame] | 1581 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1582 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1583 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1584 | }; |
| 1585 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1586 | Params); |
| 1587 | break; |
| 1588 | } |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1589 | case OMPD_task: { |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1590 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 3ae88e2 | 2015-05-22 08:56:35 +0000 | [diff] [blame] | 1591 | QualType Args[] = {Context.VoidPtrTy.withConst().withRestrict()}; |
| 1592 | FunctionProtoType::ExtProtoInfo EPI; |
| 1593 | EPI.Variadic = true; |
| 1594 | QualType CopyFnType = Context.getFunctionType(Context.VoidTy, Args, EPI); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1595 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1596 | std::make_pair(".global_tid.", KmpInt32Ty), |
| 1597 | std::make_pair(".part_id.", KmpInt32Ty), |
Alexey Bataev | 3ae88e2 | 2015-05-22 08:56:35 +0000 | [diff] [blame] | 1598 | std::make_pair(".privates.", |
| 1599 | Context.VoidPtrTy.withConst().withRestrict()), |
| 1600 | std::make_pair( |
| 1601 | ".copy_fn.", |
| 1602 | Context.getPointerType(CopyFnType).withConst().withRestrict()), |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1603 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1604 | }; |
| 1605 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1606 | Params); |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1607 | // Mark this captured region as inlined, because we don't use outlined |
| 1608 | // function directly. |
| 1609 | getCurCapturedRegion()->TheCapturedDecl->addAttr( |
| 1610 | AlwaysInlineAttr::CreateImplicit( |
| 1611 | Context, AlwaysInlineAttr::Keyword_forceinline, SourceRange())); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1612 | break; |
| 1613 | } |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1614 | case OMPD_ordered: { |
| 1615 | Sema::CapturedParamNameType Params[] = { |
| 1616 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1617 | }; |
| 1618 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1619 | Params); |
| 1620 | break; |
| 1621 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1622 | case OMPD_atomic: { |
| 1623 | Sema::CapturedParamNameType Params[] = { |
| 1624 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1625 | }; |
| 1626 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1627 | Params); |
| 1628 | break; |
| 1629 | } |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 1630 | case OMPD_target_data: |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1631 | case OMPD_target: { |
| 1632 | Sema::CapturedParamNameType Params[] = { |
| 1633 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1634 | }; |
| 1635 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1636 | Params); |
| 1637 | break; |
| 1638 | } |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1639 | case OMPD_teams: { |
| 1640 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1641 | QualType KmpInt32PtrTy = |
| 1642 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1643 | Sema::CapturedParamNameType Params[] = { |
| 1644 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1645 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1646 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1647 | }; |
| 1648 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1649 | Params); |
| 1650 | break; |
| 1651 | } |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1652 | case OMPD_taskgroup: { |
| 1653 | Sema::CapturedParamNameType Params[] = { |
| 1654 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1655 | }; |
| 1656 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1657 | Params); |
| 1658 | break; |
| 1659 | } |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1660 | case OMPD_taskloop: { |
| 1661 | Sema::CapturedParamNameType Params[] = { |
| 1662 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1663 | }; |
| 1664 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1665 | Params); |
| 1666 | break; |
| 1667 | } |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1668 | case OMPD_taskloop_simd: { |
| 1669 | Sema::CapturedParamNameType Params[] = { |
| 1670 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1671 | }; |
| 1672 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1673 | Params); |
| 1674 | break; |
| 1675 | } |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1676 | case OMPD_distribute: { |
| 1677 | Sema::CapturedParamNameType Params[] = { |
| 1678 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1679 | }; |
| 1680 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1681 | Params); |
| 1682 | break; |
| 1683 | } |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1684 | case OMPD_threadprivate: |
Alexey Bataev | ee9af45 | 2014-11-21 11:33:46 +0000 | [diff] [blame] | 1685 | case OMPD_taskyield: |
| 1686 | case OMPD_barrier: |
| 1687 | case OMPD_taskwait: |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1688 | case OMPD_cancellation_point: |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1689 | case OMPD_cancel: |
Alexey Bataev | ee9af45 | 2014-11-21 11:33:46 +0000 | [diff] [blame] | 1690 | case OMPD_flush: |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1691 | case OMPD_target_enter_data: |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1692 | case OMPD_target_exit_data: |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1693 | llvm_unreachable("OpenMP Directive is not allowed"); |
| 1694 | case OMPD_unknown: |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1695 | llvm_unreachable("Unknown OpenMP directive"); |
| 1696 | } |
| 1697 | } |
| 1698 | |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1699 | StmtResult Sema::ActOnOpenMPRegionEnd(StmtResult S, |
| 1700 | ArrayRef<OMPClause *> Clauses) { |
| 1701 | if (!S.isUsable()) { |
| 1702 | ActOnCapturedRegionError(); |
| 1703 | return StmtError(); |
| 1704 | } |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1705 | |
| 1706 | OMPOrderedClause *OC = nullptr; |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1707 | OMPScheduleClause *SC = nullptr; |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1708 | SmallVector<OMPLinearClause *, 4> LCs; |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1709 | // This is required for proper codegen. |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1710 | for (auto *Clause : Clauses) { |
Alexey Bataev | 16dc7b6 | 2015-05-20 03:46:04 +0000 | [diff] [blame] | 1711 | if (isOpenMPPrivate(Clause->getClauseKind()) || |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 1712 | Clause->getClauseKind() == OMPC_copyprivate || |
| 1713 | (getLangOpts().OpenMPUseTLS && |
| 1714 | getASTContext().getTargetInfo().isTLSSupported() && |
| 1715 | Clause->getClauseKind() == OMPC_copyin)) { |
| 1716 | DSAStack->setForceVarCapturing(Clause->getClauseKind() == OMPC_copyin); |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1717 | // Mark all variables in private list clauses as used in inner region. |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1718 | for (auto *VarRef : Clause->children()) { |
| 1719 | if (auto *E = cast_or_null<Expr>(VarRef)) { |
Alexey Bataev | 8bf6b3e | 2015-04-02 13:07:08 +0000 | [diff] [blame] | 1720 | MarkDeclarationsReferencedInExpr(E); |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1721 | } |
| 1722 | } |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 1723 | DSAStack->setForceVarCapturing(/*V=*/false); |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1724 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective()) && |
| 1725 | Clause->getClauseKind() == OMPC_schedule) { |
| 1726 | // Mark all variables in private list clauses as used in inner region. |
| 1727 | // Required for proper codegen of combined directives. |
| 1728 | // TODO: add processing for other clauses. |
| 1729 | if (auto *E = cast_or_null<Expr>( |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1730 | cast<OMPScheduleClause>(Clause)->getHelperChunkSize())) |
| 1731 | MarkDeclarationsReferencedInExpr(E); |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1732 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1733 | if (Clause->getClauseKind() == OMPC_schedule) |
| 1734 | SC = cast<OMPScheduleClause>(Clause); |
| 1735 | else if (Clause->getClauseKind() == OMPC_ordered) |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1736 | OC = cast<OMPOrderedClause>(Clause); |
| 1737 | else if (Clause->getClauseKind() == OMPC_linear) |
| 1738 | LCs.push_back(cast<OMPLinearClause>(Clause)); |
| 1739 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1740 | bool ErrorFound = false; |
| 1741 | // OpenMP, 2.7.1 Loop Construct, Restrictions |
| 1742 | // The nonmonotonic modifier cannot be specified if an ordered clause is |
| 1743 | // specified. |
| 1744 | if (SC && |
| 1745 | (SC->getFirstScheduleModifier() == OMPC_SCHEDULE_MODIFIER_nonmonotonic || |
| 1746 | SC->getSecondScheduleModifier() == |
| 1747 | OMPC_SCHEDULE_MODIFIER_nonmonotonic) && |
| 1748 | OC) { |
| 1749 | Diag(SC->getFirstScheduleModifier() == OMPC_SCHEDULE_MODIFIER_nonmonotonic |
| 1750 | ? SC->getFirstScheduleModifierLoc() |
| 1751 | : SC->getSecondScheduleModifierLoc(), |
| 1752 | diag::err_omp_schedule_nonmonotonic_ordered) |
| 1753 | << SourceRange(OC->getLocStart(), OC->getLocEnd()); |
| 1754 | ErrorFound = true; |
| 1755 | } |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1756 | if (!LCs.empty() && OC && OC->getNumForLoops()) { |
| 1757 | for (auto *C : LCs) { |
| 1758 | Diag(C->getLocStart(), diag::err_omp_linear_ordered) |
| 1759 | << SourceRange(OC->getLocStart(), OC->getLocEnd()); |
| 1760 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1761 | ErrorFound = true; |
| 1762 | } |
Alexey Bataev | 113438c | 2015-12-30 12:06:23 +0000 | [diff] [blame] | 1763 | if (isOpenMPWorksharingDirective(DSAStack->getCurrentDirective()) && |
| 1764 | isOpenMPSimdDirective(DSAStack->getCurrentDirective()) && OC && |
| 1765 | OC->getNumForLoops()) { |
| 1766 | Diag(OC->getLocStart(), diag::err_omp_ordered_simd) |
| 1767 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 1768 | ErrorFound = true; |
| 1769 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1770 | if (ErrorFound) { |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1771 | ActOnCapturedRegionError(); |
| 1772 | return StmtError(); |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1773 | } |
| 1774 | return ActOnCapturedRegionEnd(S.get()); |
| 1775 | } |
| 1776 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1777 | static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, |
| 1778 | OpenMPDirectiveKind CurrentRegion, |
| 1779 | const DeclarationNameInfo &CurrentName, |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1780 | OpenMPDirectiveKind CancelRegion, |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1781 | SourceLocation StartLoc) { |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1782 | // Allowed nesting of constructs |
| 1783 | // +------------------+-----------------+------------------------------------+ |
| 1784 | // | Parent directive | Child directive | Closely (!), No-Closely(+), Both(*)| |
| 1785 | // +------------------+-----------------+------------------------------------+ |
| 1786 | // | parallel | parallel | * | |
| 1787 | // | parallel | for | * | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1788 | // | parallel | for simd | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1789 | // | parallel | master | * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1790 | // | parallel | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1791 | // | parallel | simd | * | |
| 1792 | // | parallel | sections | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1793 | // | parallel | section | + | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1794 | // | parallel | single | * | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1795 | // | parallel | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1796 | // | parallel |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1797 | // | parallel |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1798 | // | parallel | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1799 | // | parallel | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1800 | // | parallel | barrier | * | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1801 | // | parallel | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1802 | // | parallel | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1803 | // | parallel | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1804 | // | parallel | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1805 | // | parallel | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1806 | // | parallel | target | * | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1807 | // | parallel | target enter | * | |
| 1808 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1809 | // | parallel | target exit | * | |
| 1810 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1811 | // | parallel | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1812 | // | parallel | cancellation | | |
| 1813 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1814 | // | parallel | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1815 | // | parallel | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1816 | // | parallel | taskloop simd | * | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1817 | // | parallel | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1818 | // +------------------+-----------------+------------------------------------+ |
| 1819 | // | for | parallel | * | |
| 1820 | // | for | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1821 | // | for | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1822 | // | for | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1823 | // | for | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1824 | // | for | simd | * | |
| 1825 | // | for | sections | + | |
| 1826 | // | for | section | + | |
| 1827 | // | for | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1828 | // | for | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1829 | // | for |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1830 | // | for |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1831 | // | for | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1832 | // | for | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1833 | // | for | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1834 | // | for | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1835 | // | for | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1836 | // | for | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1837 | // | for | ordered | * (if construct is ordered) | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1838 | // | for | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1839 | // | for | target | * | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1840 | // | for | target enter | * | |
| 1841 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1842 | // | for | target exit | * | |
| 1843 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1844 | // | for | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1845 | // | for | cancellation | | |
| 1846 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1847 | // | for | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1848 | // | for | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1849 | // | for | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1850 | // | for | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1851 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1852 | // | master | parallel | * | |
| 1853 | // | master | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1854 | // | master | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1855 | // | master | master | * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1856 | // | master | critical | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1857 | // | master | simd | * | |
| 1858 | // | master | sections | + | |
| 1859 | // | master | section | + | |
| 1860 | // | master | single | + | |
| 1861 | // | master | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1862 | // | master |parallel for simd| * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1863 | // | master |parallel sections| * | |
| 1864 | // | master | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1865 | // | master | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1866 | // | master | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1867 | // | master | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1868 | // | master | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1869 | // | master | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1870 | // | master | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1871 | // | master | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1872 | // | master | target | * | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1873 | // | master | target enter | * | |
| 1874 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1875 | // | master | target exit | * | |
| 1876 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1877 | // | master | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1878 | // | master | cancellation | | |
| 1879 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1880 | // | master | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1881 | // | master | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1882 | // | master | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1883 | // | master | distribute | | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1884 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1885 | // | critical | parallel | * | |
| 1886 | // | critical | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1887 | // | critical | for simd | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1888 | // | critical | master | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1889 | // | critical | critical | * (should have different names) | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1890 | // | critical | simd | * | |
| 1891 | // | critical | sections | + | |
| 1892 | // | critical | section | + | |
| 1893 | // | critical | single | + | |
| 1894 | // | critical | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1895 | // | critical |parallel for simd| * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1896 | // | critical |parallel sections| * | |
| 1897 | // | critical | task | * | |
| 1898 | // | critical | taskyield | * | |
| 1899 | // | critical | barrier | + | |
| 1900 | // | critical | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1901 | // | critical | taskgroup | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1902 | // | critical | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1903 | // | critical | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1904 | // | critical | target | * | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1905 | // | critical | target enter | * | |
| 1906 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1907 | // | critical | target exit | * | |
| 1908 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1909 | // | critical | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1910 | // | critical | cancellation | | |
| 1911 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1912 | // | critical | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1913 | // | critical | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1914 | // | critical | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1915 | // | critical | distribute | | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1916 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1917 | // | simd | parallel | | |
| 1918 | // | simd | for | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1919 | // | simd | for simd | | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1920 | // | simd | master | | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1921 | // | simd | critical | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1922 | // | simd | simd | | |
| 1923 | // | simd | sections | | |
| 1924 | // | simd | section | | |
| 1925 | // | simd | single | | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1926 | // | simd | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1927 | // | simd |parallel for simd| | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1928 | // | simd |parallel sections| | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1929 | // | simd | task | | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1930 | // | simd | taskyield | | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1931 | // | simd | barrier | | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1932 | // | simd | taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1933 | // | simd | taskgroup | | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1934 | // | simd | flush | | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 1935 | // | simd | ordered | + (with simd clause) | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1936 | // | simd | atomic | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1937 | // | simd | target | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1938 | // | simd | target enter | | |
| 1939 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1940 | // | simd | target exit | | |
| 1941 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1942 | // | simd | teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1943 | // | simd | cancellation | | |
| 1944 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1945 | // | simd | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1946 | // | simd | taskloop | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1947 | // | simd | taskloop simd | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1948 | // | simd | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1949 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1950 | // | for simd | parallel | | |
| 1951 | // | for simd | for | | |
| 1952 | // | for simd | for simd | | |
| 1953 | // | for simd | master | | |
| 1954 | // | for simd | critical | | |
| 1955 | // | for simd | simd | | |
| 1956 | // | for simd | sections | | |
| 1957 | // | for simd | section | | |
| 1958 | // | for simd | single | | |
| 1959 | // | for simd | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1960 | // | for simd |parallel for simd| | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1961 | // | for simd |parallel sections| | |
| 1962 | // | for simd | task | | |
| 1963 | // | for simd | taskyield | | |
| 1964 | // | for simd | barrier | | |
| 1965 | // | for simd | taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1966 | // | for simd | taskgroup | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1967 | // | for simd | flush | | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 1968 | // | for simd | ordered | + (with simd clause) | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1969 | // | for simd | atomic | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1970 | // | for simd | target | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1971 | // | for simd | target enter | | |
| 1972 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1973 | // | for simd | target exit | | |
| 1974 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1975 | // | for simd | teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1976 | // | for simd | cancellation | | |
| 1977 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1978 | // | for simd | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1979 | // | for simd | taskloop | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1980 | // | for simd | taskloop simd | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1981 | // | for simd | distribute | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1982 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1983 | // | parallel for simd| parallel | | |
| 1984 | // | parallel for simd| for | | |
| 1985 | // | parallel for simd| for simd | | |
| 1986 | // | parallel for simd| master | | |
| 1987 | // | parallel for simd| critical | | |
| 1988 | // | parallel for simd| simd | | |
| 1989 | // | parallel for simd| sections | | |
| 1990 | // | parallel for simd| section | | |
| 1991 | // | parallel for simd| single | | |
| 1992 | // | parallel for simd| parallel for | | |
| 1993 | // | parallel for simd|parallel for simd| | |
| 1994 | // | parallel for simd|parallel sections| | |
| 1995 | // | parallel for simd| task | | |
| 1996 | // | parallel for simd| taskyield | | |
| 1997 | // | parallel for simd| barrier | | |
| 1998 | // | parallel for simd| taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1999 | // | parallel for simd| taskgroup | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2000 | // | parallel for simd| flush | | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2001 | // | parallel for simd| ordered | + (with simd clause) | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2002 | // | parallel for simd| atomic | | |
| 2003 | // | parallel for simd| target | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2004 | // | parallel for simd| target enter | | |
| 2005 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2006 | // | parallel for simd| target exit | | |
| 2007 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2008 | // | parallel for simd| teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2009 | // | parallel for simd| cancellation | | |
| 2010 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2011 | // | parallel for simd| cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2012 | // | parallel for simd| taskloop | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2013 | // | parallel for simd| taskloop simd | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2014 | // | parallel for simd| distribute | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2015 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2016 | // | sections | parallel | * | |
| 2017 | // | sections | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2018 | // | sections | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2019 | // | sections | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2020 | // | sections | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2021 | // | sections | simd | * | |
| 2022 | // | sections | sections | + | |
| 2023 | // | sections | section | * | |
| 2024 | // | sections | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2025 | // | sections | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2026 | // | sections |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2027 | // | sections |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2028 | // | sections | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2029 | // | sections | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2030 | // | sections | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2031 | // | sections | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2032 | // | sections | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2033 | // | sections | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2034 | // | sections | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2035 | // | sections | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2036 | // | sections | target | * | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2037 | // | sections | target enter | * | |
| 2038 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2039 | // | sections | target exit | * | |
| 2040 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2041 | // | sections | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2042 | // | sections | cancellation | | |
| 2043 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2044 | // | sections | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2045 | // | sections | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2046 | // | sections | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2047 | // | sections | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2048 | // +------------------+-----------------+------------------------------------+ |
| 2049 | // | section | parallel | * | |
| 2050 | // | section | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2051 | // | section | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2052 | // | section | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2053 | // | section | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2054 | // | section | simd | * | |
| 2055 | // | section | sections | + | |
| 2056 | // | section | section | + | |
| 2057 | // | section | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2058 | // | section | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2059 | // | section |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2060 | // | section |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2061 | // | section | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2062 | // | section | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2063 | // | section | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2064 | // | section | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2065 | // | section | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2066 | // | section | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2067 | // | section | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2068 | // | section | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2069 | // | section | target | * | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2070 | // | section | target enter | * | |
| 2071 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2072 | // | section | target exit | * | |
| 2073 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2074 | // | section | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2075 | // | section | cancellation | | |
| 2076 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2077 | // | section | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2078 | // | section | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2079 | // | section | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2080 | // | section | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2081 | // +------------------+-----------------+------------------------------------+ |
| 2082 | // | single | parallel | * | |
| 2083 | // | single | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2084 | // | single | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2085 | // | single | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2086 | // | single | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2087 | // | single | simd | * | |
| 2088 | // | single | sections | + | |
| 2089 | // | single | section | + | |
| 2090 | // | single | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2091 | // | single | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2092 | // | single |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2093 | // | single |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2094 | // | single | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2095 | // | single | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2096 | // | single | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2097 | // | single | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2098 | // | single | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2099 | // | single | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2100 | // | single | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2101 | // | single | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2102 | // | single | target | * | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2103 | // | single | target enter | * | |
| 2104 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2105 | // | single | target exit | * | |
| 2106 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2107 | // | single | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2108 | // | single | cancellation | | |
| 2109 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2110 | // | single | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2111 | // | single | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2112 | // | single | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2113 | // | single | distribute | | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2114 | // +------------------+-----------------+------------------------------------+ |
| 2115 | // | parallel for | parallel | * | |
| 2116 | // | parallel for | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2117 | // | parallel for | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2118 | // | parallel for | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2119 | // | parallel for | critical | * | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2120 | // | parallel for | simd | * | |
| 2121 | // | parallel for | sections | + | |
| 2122 | // | parallel for | section | + | |
| 2123 | // | parallel for | single | + | |
| 2124 | // | parallel for | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2125 | // | parallel for |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2126 | // | parallel for |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2127 | // | parallel for | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2128 | // | parallel for | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2129 | // | parallel for | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2130 | // | parallel for | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2131 | // | parallel for | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2132 | // | parallel for | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2133 | // | parallel for | ordered | * (if construct is ordered) | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2134 | // | parallel for | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2135 | // | parallel for | target | * | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2136 | // | parallel for | target enter | * | |
| 2137 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2138 | // | parallel for | target exit | * | |
| 2139 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2140 | // | parallel for | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2141 | // | parallel for | cancellation | | |
| 2142 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2143 | // | parallel for | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2144 | // | parallel for | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2145 | // | parallel for | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2146 | // | parallel for | distribute | | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2147 | // +------------------+-----------------+------------------------------------+ |
| 2148 | // | parallel sections| parallel | * | |
| 2149 | // | parallel sections| for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2150 | // | parallel sections| for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2151 | // | parallel sections| master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2152 | // | parallel sections| critical | + | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2153 | // | parallel sections| simd | * | |
| 2154 | // | parallel sections| sections | + | |
| 2155 | // | parallel sections| section | * | |
| 2156 | // | parallel sections| single | + | |
| 2157 | // | parallel sections| parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2158 | // | parallel sections|parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2159 | // | parallel sections|parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2160 | // | parallel sections| task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2161 | // | parallel sections| taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2162 | // | parallel sections| barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2163 | // | parallel sections| taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2164 | // | parallel sections| taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2165 | // | parallel sections| flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2166 | // | parallel sections| ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2167 | // | parallel sections| atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2168 | // | parallel sections| target | * | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2169 | // | parallel sections| target enter | * | |
| 2170 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2171 | // | parallel sections| target exit | * | |
| 2172 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2173 | // | parallel sections| teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2174 | // | parallel sections| cancellation | | |
| 2175 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2176 | // | parallel sections| cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2177 | // | parallel sections| taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2178 | // | parallel sections| taskloop simd | * | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2179 | // | parallel sections| distribute | | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2180 | // +------------------+-----------------+------------------------------------+ |
| 2181 | // | task | parallel | * | |
| 2182 | // | task | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2183 | // | task | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2184 | // | task | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2185 | // | task | critical | * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2186 | // | task | simd | * | |
| 2187 | // | task | sections | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2188 | // | task | section | + | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2189 | // | task | single | + | |
| 2190 | // | task | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2191 | // | task |parallel for simd| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2192 | // | task |parallel sections| * | |
| 2193 | // | task | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2194 | // | task | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2195 | // | task | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2196 | // | task | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2197 | // | task | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2198 | // | task | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2199 | // | task | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2200 | // | task | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2201 | // | task | target | * | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2202 | // | task | target enter | * | |
| 2203 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2204 | // | task | target exit | * | |
| 2205 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2206 | // | task | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2207 | // | task | cancellation | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2208 | // | | point | ! | |
| 2209 | // | task | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2210 | // | task | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2211 | // | task | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2212 | // | task | distribute | | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2213 | // +------------------+-----------------+------------------------------------+ |
| 2214 | // | ordered | parallel | * | |
| 2215 | // | ordered | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2216 | // | ordered | for simd | + | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2217 | // | ordered | master | * | |
| 2218 | // | ordered | critical | * | |
| 2219 | // | ordered | simd | * | |
| 2220 | // | ordered | sections | + | |
| 2221 | // | ordered | section | + | |
| 2222 | // | ordered | single | + | |
| 2223 | // | ordered | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2224 | // | ordered |parallel for simd| * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2225 | // | ordered |parallel sections| * | |
| 2226 | // | ordered | task | * | |
| 2227 | // | ordered | taskyield | * | |
| 2228 | // | ordered | barrier | + | |
| 2229 | // | ordered | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2230 | // | ordered | taskgroup | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2231 | // | ordered | flush | * | |
| 2232 | // | ordered | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2233 | // | ordered | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2234 | // | ordered | target | * | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2235 | // | ordered | target enter | * | |
| 2236 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2237 | // | ordered | target exit | * | |
| 2238 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2239 | // | ordered | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2240 | // | ordered | cancellation | | |
| 2241 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2242 | // | ordered | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2243 | // | ordered | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2244 | // | ordered | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2245 | // | ordered | distribute | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2246 | // +------------------+-----------------+------------------------------------+ |
| 2247 | // | atomic | parallel | | |
| 2248 | // | atomic | for | | |
| 2249 | // | atomic | for simd | | |
| 2250 | // | atomic | master | | |
| 2251 | // | atomic | critical | | |
| 2252 | // | atomic | simd | | |
| 2253 | // | atomic | sections | | |
| 2254 | // | atomic | section | | |
| 2255 | // | atomic | single | | |
| 2256 | // | atomic | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2257 | // | atomic |parallel for simd| | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2258 | // | atomic |parallel sections| | |
| 2259 | // | atomic | task | | |
| 2260 | // | atomic | taskyield | | |
| 2261 | // | atomic | barrier | | |
| 2262 | // | atomic | taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2263 | // | atomic | taskgroup | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2264 | // | atomic | flush | | |
| 2265 | // | atomic | ordered | | |
| 2266 | // | atomic | atomic | | |
| 2267 | // | atomic | target | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2268 | // | atomic | target enter | | |
| 2269 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2270 | // | atomic | target exit | | |
| 2271 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2272 | // | atomic | teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2273 | // | atomic | cancellation | | |
| 2274 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2275 | // | atomic | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2276 | // | atomic | taskloop | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2277 | // | atomic | taskloop simd | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2278 | // | atomic | distribute | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2279 | // +------------------+-----------------+------------------------------------+ |
| 2280 | // | target | parallel | * | |
| 2281 | // | target | for | * | |
| 2282 | // | target | for simd | * | |
| 2283 | // | target | master | * | |
| 2284 | // | target | critical | * | |
| 2285 | // | target | simd | * | |
| 2286 | // | target | sections | * | |
| 2287 | // | target | section | * | |
| 2288 | // | target | single | * | |
| 2289 | // | target | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2290 | // | target |parallel for simd| * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2291 | // | target |parallel sections| * | |
| 2292 | // | target | task | * | |
| 2293 | // | target | taskyield | * | |
| 2294 | // | target | barrier | * | |
| 2295 | // | target | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2296 | // | target | taskgroup | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2297 | // | target | flush | * | |
| 2298 | // | target | ordered | * | |
| 2299 | // | target | atomic | * | |
| 2300 | // | target | target | * | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2301 | // | target | target enter | * | |
| 2302 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2303 | // | target | target exit | * | |
| 2304 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2305 | // | target | teams | * | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2306 | // | target | cancellation | | |
| 2307 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2308 | // | target | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2309 | // | target | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2310 | // | target | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2311 | // | target | distribute | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2312 | // +------------------+-----------------+------------------------------------+ |
| 2313 | // | teams | parallel | * | |
| 2314 | // | teams | for | + | |
| 2315 | // | teams | for simd | + | |
| 2316 | // | teams | master | + | |
| 2317 | // | teams | critical | + | |
| 2318 | // | teams | simd | + | |
| 2319 | // | teams | sections | + | |
| 2320 | // | teams | section | + | |
| 2321 | // | teams | single | + | |
| 2322 | // | teams | parallel for | * | |
| 2323 | // | teams |parallel for simd| * | |
| 2324 | // | teams |parallel sections| * | |
| 2325 | // | teams | task | + | |
| 2326 | // | teams | taskyield | + | |
| 2327 | // | teams | barrier | + | |
| 2328 | // | teams | taskwait | + | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2329 | // | teams | taskgroup | + | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2330 | // | teams | flush | + | |
| 2331 | // | teams | ordered | + | |
| 2332 | // | teams | atomic | + | |
| 2333 | // | teams | target | + | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2334 | // | teams | target enter | + | |
| 2335 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2336 | // | teams | target exit | + | |
| 2337 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2338 | // | teams | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2339 | // | teams | cancellation | | |
| 2340 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2341 | // | teams | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2342 | // | teams | taskloop | + | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2343 | // | teams | taskloop simd | + | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2344 | // | teams | distribute | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2345 | // +------------------+-----------------+------------------------------------+ |
| 2346 | // | taskloop | parallel | * | |
| 2347 | // | taskloop | for | + | |
| 2348 | // | taskloop | for simd | + | |
| 2349 | // | taskloop | master | + | |
| 2350 | // | taskloop | critical | * | |
| 2351 | // | taskloop | simd | * | |
| 2352 | // | taskloop | sections | + | |
| 2353 | // | taskloop | section | + | |
| 2354 | // | taskloop | single | + | |
| 2355 | // | taskloop | parallel for | * | |
| 2356 | // | taskloop |parallel for simd| * | |
| 2357 | // | taskloop |parallel sections| * | |
| 2358 | // | taskloop | task | * | |
| 2359 | // | taskloop | taskyield | * | |
| 2360 | // | taskloop | barrier | + | |
| 2361 | // | taskloop | taskwait | * | |
| 2362 | // | taskloop | taskgroup | * | |
| 2363 | // | taskloop | flush | * | |
| 2364 | // | taskloop | ordered | + | |
| 2365 | // | taskloop | atomic | * | |
| 2366 | // | taskloop | target | * | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2367 | // | taskloop | target enter | * | |
| 2368 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2369 | // | taskloop | target exit | * | |
| 2370 | // | | data | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2371 | // | taskloop | teams | + | |
| 2372 | // | taskloop | cancellation | | |
| 2373 | // | | point | | |
| 2374 | // | taskloop | cancel | | |
| 2375 | // | taskloop | taskloop | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2376 | // | taskloop | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2377 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2378 | // | taskloop simd | parallel | | |
| 2379 | // | taskloop simd | for | | |
| 2380 | // | taskloop simd | for simd | | |
| 2381 | // | taskloop simd | master | | |
| 2382 | // | taskloop simd | critical | | |
| 2383 | // | taskloop simd | simd | | |
| 2384 | // | taskloop simd | sections | | |
| 2385 | // | taskloop simd | section | | |
| 2386 | // | taskloop simd | single | | |
| 2387 | // | taskloop simd | parallel for | | |
| 2388 | // | taskloop simd |parallel for simd| | |
| 2389 | // | taskloop simd |parallel sections| | |
| 2390 | // | taskloop simd | task | | |
| 2391 | // | taskloop simd | taskyield | | |
| 2392 | // | taskloop simd | barrier | | |
| 2393 | // | taskloop simd | taskwait | | |
| 2394 | // | taskloop simd | taskgroup | | |
| 2395 | // | taskloop simd | flush | | |
| 2396 | // | taskloop simd | ordered | + (with simd clause) | |
| 2397 | // | taskloop simd | atomic | | |
| 2398 | // | taskloop simd | target | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2399 | // | taskloop simd | target enter | | |
| 2400 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2401 | // | taskloop simd | target exit | | |
| 2402 | // | | data | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2403 | // | taskloop simd | teams | | |
| 2404 | // | taskloop simd | cancellation | | |
| 2405 | // | | point | | |
| 2406 | // | taskloop simd | cancel | | |
| 2407 | // | taskloop simd | taskloop | | |
| 2408 | // | taskloop simd | taskloop simd | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2409 | // | taskloop simd | distribute | | |
| 2410 | // +------------------+-----------------+------------------------------------+ |
| 2411 | // | distribute | parallel | * | |
| 2412 | // | distribute | for | * | |
| 2413 | // | distribute | for simd | * | |
| 2414 | // | distribute | master | * | |
| 2415 | // | distribute | critical | * | |
| 2416 | // | distribute | simd | * | |
| 2417 | // | distribute | sections | * | |
| 2418 | // | distribute | section | * | |
| 2419 | // | distribute | single | * | |
| 2420 | // | distribute | parallel for | * | |
| 2421 | // | distribute |parallel for simd| * | |
| 2422 | // | distribute |parallel sections| * | |
| 2423 | // | distribute | task | * | |
| 2424 | // | distribute | taskyield | * | |
| 2425 | // | distribute | barrier | * | |
| 2426 | // | distribute | taskwait | * | |
| 2427 | // | distribute | taskgroup | * | |
| 2428 | // | distribute | flush | * | |
| 2429 | // | distribute | ordered | + | |
| 2430 | // | distribute | atomic | * | |
| 2431 | // | distribute | target | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2432 | // | distribute | target enter | | |
| 2433 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2434 | // | distribute | target exit | | |
| 2435 | // | | data | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2436 | // | distribute | teams | | |
| 2437 | // | distribute | cancellation | + | |
| 2438 | // | | point | | |
| 2439 | // | distribute | cancel | + | |
| 2440 | // | distribute | taskloop | * | |
| 2441 | // | distribute | taskloop simd | * | |
| 2442 | // | distribute | distribute | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2443 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2444 | if (Stack->getCurScope()) { |
| 2445 | auto ParentRegion = Stack->getParentDirective(); |
| 2446 | bool NestingProhibited = false; |
| 2447 | bool CloseNesting = true; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2448 | enum { |
| 2449 | NoRecommend, |
| 2450 | ShouldBeInParallelRegion, |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2451 | ShouldBeInOrderedRegion, |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2452 | ShouldBeInTargetRegion, |
| 2453 | ShouldBeInTeamsRegion |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2454 | } Recommend = NoRecommend; |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2455 | if (isOpenMPSimdDirective(ParentRegion) && CurrentRegion != OMPD_ordered) { |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2456 | // OpenMP [2.16, Nesting of Regions] |
| 2457 | // OpenMP constructs may not be nested inside a simd region. |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2458 | // OpenMP [2.8.1,simd Construct, Restrictions] |
| 2459 | // An ordered construct with the simd clause is the only OpenMP construct |
| 2460 | // that can appear in the simd region. |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2461 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region_simd); |
| 2462 | return true; |
| 2463 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2464 | if (ParentRegion == OMPD_atomic) { |
| 2465 | // OpenMP [2.16, Nesting of Regions] |
| 2466 | // OpenMP constructs may not be nested inside an atomic region. |
| 2467 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region_atomic); |
| 2468 | return true; |
| 2469 | } |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2470 | if (CurrentRegion == OMPD_section) { |
| 2471 | // OpenMP [2.7.2, sections Construct, Restrictions] |
| 2472 | // Orphaned section directives are prohibited. That is, the section |
| 2473 | // directives must appear within the sections construct and must not be |
| 2474 | // encountered elsewhere in the sections region. |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2475 | if (ParentRegion != OMPD_sections && |
| 2476 | ParentRegion != OMPD_parallel_sections) { |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2477 | SemaRef.Diag(StartLoc, diag::err_omp_orphaned_section_directive) |
| 2478 | << (ParentRegion != OMPD_unknown) |
| 2479 | << getOpenMPDirectiveName(ParentRegion); |
| 2480 | return true; |
| 2481 | } |
| 2482 | return false; |
| 2483 | } |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2484 | // Allow some constructs to be orphaned (they could be used in functions, |
| 2485 | // called from OpenMP regions with the required preconditions). |
| 2486 | if (ParentRegion == OMPD_unknown) |
| 2487 | return false; |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2488 | if (CurrentRegion == OMPD_cancellation_point || |
| 2489 | CurrentRegion == OMPD_cancel) { |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2490 | // OpenMP [2.16, Nesting of Regions] |
| 2491 | // A cancellation point construct for which construct-type-clause is |
| 2492 | // taskgroup must be nested inside a task construct. A cancellation |
| 2493 | // point construct for which construct-type-clause is not taskgroup must |
| 2494 | // be closely nested inside an OpenMP construct that matches the type |
| 2495 | // specified in construct-type-clause. |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2496 | // A cancel construct for which construct-type-clause is taskgroup must be |
| 2497 | // nested inside a task construct. A cancel construct for which |
| 2498 | // construct-type-clause is not taskgroup must be closely nested inside an |
| 2499 | // OpenMP construct that matches the type specified in |
| 2500 | // construct-type-clause. |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2501 | NestingProhibited = |
| 2502 | !((CancelRegion == OMPD_parallel && ParentRegion == OMPD_parallel) || |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 2503 | (CancelRegion == OMPD_for && |
| 2504 | (ParentRegion == OMPD_for || ParentRegion == OMPD_parallel_for)) || |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2505 | (CancelRegion == OMPD_taskgroup && ParentRegion == OMPD_task) || |
| 2506 | (CancelRegion == OMPD_sections && |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 2507 | (ParentRegion == OMPD_section || ParentRegion == OMPD_sections || |
| 2508 | ParentRegion == OMPD_parallel_sections))); |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2509 | } else if (CurrentRegion == OMPD_master) { |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2510 | // OpenMP [2.16, Nesting of Regions] |
| 2511 | // A master region may not be closely nested inside a worksharing, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2512 | // atomic, or explicit task region. |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2513 | NestingProhibited = isOpenMPWorksharingDirective(ParentRegion) || |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2514 | ParentRegion == OMPD_task || |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2515 | isOpenMPTaskLoopDirective(ParentRegion); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2516 | } else if (CurrentRegion == OMPD_critical && CurrentName.getName()) { |
| 2517 | // OpenMP [2.16, Nesting of Regions] |
| 2518 | // A critical region may not be nested (closely or otherwise) inside a |
| 2519 | // critical region with the same name. Note that this restriction is not |
| 2520 | // sufficient to prevent deadlock. |
| 2521 | SourceLocation PreviousCriticalLoc; |
| 2522 | bool DeadLock = |
| 2523 | Stack->hasDirective([CurrentName, &PreviousCriticalLoc]( |
| 2524 | OpenMPDirectiveKind K, |
| 2525 | const DeclarationNameInfo &DNI, |
| 2526 | SourceLocation Loc) |
| 2527 | ->bool { |
| 2528 | if (K == OMPD_critical && |
| 2529 | DNI.getName() == CurrentName.getName()) { |
| 2530 | PreviousCriticalLoc = Loc; |
| 2531 | return true; |
| 2532 | } else |
| 2533 | return false; |
| 2534 | }, |
| 2535 | false /* skip top directive */); |
| 2536 | if (DeadLock) { |
| 2537 | SemaRef.Diag(StartLoc, |
| 2538 | diag::err_omp_prohibited_region_critical_same_name) |
| 2539 | << CurrentName.getName(); |
| 2540 | if (PreviousCriticalLoc.isValid()) |
| 2541 | SemaRef.Diag(PreviousCriticalLoc, |
| 2542 | diag::note_omp_previous_critical_region); |
| 2543 | return true; |
| 2544 | } |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2545 | } else if (CurrentRegion == OMPD_barrier) { |
| 2546 | // OpenMP [2.16, Nesting of Regions] |
| 2547 | // A barrier region may not be closely nested inside a worksharing, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2548 | // explicit task, critical, ordered, atomic, or master region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2549 | NestingProhibited = |
| 2550 | isOpenMPWorksharingDirective(ParentRegion) || |
| 2551 | ParentRegion == OMPD_task || ParentRegion == OMPD_master || |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2552 | ParentRegion == OMPD_critical || ParentRegion == OMPD_ordered || |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2553 | isOpenMPTaskLoopDirective(ParentRegion); |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2554 | } else if (isOpenMPWorksharingDirective(CurrentRegion) && |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2555 | !isOpenMPParallelDirective(CurrentRegion)) { |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2556 | // OpenMP [2.16, Nesting of Regions] |
| 2557 | // A worksharing region may not be closely nested inside a worksharing, |
| 2558 | // explicit task, critical, ordered, atomic, or master region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2559 | NestingProhibited = |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2560 | isOpenMPWorksharingDirective(ParentRegion) || |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2561 | ParentRegion == OMPD_task || ParentRegion == OMPD_master || |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2562 | ParentRegion == OMPD_critical || ParentRegion == OMPD_ordered || |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2563 | isOpenMPTaskLoopDirective(ParentRegion); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2564 | Recommend = ShouldBeInParallelRegion; |
| 2565 | } else if (CurrentRegion == OMPD_ordered) { |
| 2566 | // OpenMP [2.16, Nesting of Regions] |
| 2567 | // An ordered region may not be closely nested inside a critical, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2568 | // atomic, or explicit task region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2569 | // An ordered region must be closely nested inside a loop region (or |
| 2570 | // parallel loop region) with an ordered clause. |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2571 | // OpenMP [2.8.1,simd Construct, Restrictions] |
| 2572 | // An ordered construct with the simd clause is the only OpenMP construct |
| 2573 | // that can appear in the simd region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2574 | NestingProhibited = ParentRegion == OMPD_critical || |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2575 | ParentRegion == OMPD_task || |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2576 | isOpenMPTaskLoopDirective(ParentRegion) || |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2577 | !(isOpenMPSimdDirective(ParentRegion) || |
| 2578 | Stack->isParentOrderedRegion()); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2579 | Recommend = ShouldBeInOrderedRegion; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2580 | } else if (isOpenMPTeamsDirective(CurrentRegion)) { |
| 2581 | // OpenMP [2.16, Nesting of Regions] |
| 2582 | // If specified, a teams construct must be contained within a target |
| 2583 | // construct. |
| 2584 | NestingProhibited = ParentRegion != OMPD_target; |
| 2585 | Recommend = ShouldBeInTargetRegion; |
| 2586 | Stack->setParentTeamsRegionLoc(Stack->getConstructLoc()); |
| 2587 | } |
| 2588 | if (!NestingProhibited && isOpenMPTeamsDirective(ParentRegion)) { |
| 2589 | // OpenMP [2.16, Nesting of Regions] |
| 2590 | // distribute, parallel, parallel sections, parallel workshare, and the |
| 2591 | // parallel loop and parallel loop SIMD constructs are the only OpenMP |
| 2592 | // constructs that can be closely nested in the teams region. |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2593 | NestingProhibited = !isOpenMPParallelDirective(CurrentRegion) && |
| 2594 | !isOpenMPDistributeDirective(CurrentRegion); |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2595 | Recommend = ShouldBeInParallelRegion; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2596 | } |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2597 | if (!NestingProhibited && isOpenMPDistributeDirective(CurrentRegion)) { |
| 2598 | // OpenMP 4.5 [2.17 Nesting of Regions] |
| 2599 | // The region associated with the distribute construct must be strictly |
| 2600 | // nested inside a teams region |
| 2601 | NestingProhibited = !isOpenMPTeamsDirective(ParentRegion); |
| 2602 | Recommend = ShouldBeInTeamsRegion; |
| 2603 | } |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2604 | if (NestingProhibited) { |
| 2605 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region) |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2606 | << CloseNesting << getOpenMPDirectiveName(ParentRegion) << Recommend |
| 2607 | << getOpenMPDirectiveName(CurrentRegion); |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2608 | return true; |
| 2609 | } |
| 2610 | } |
| 2611 | return false; |
| 2612 | } |
| 2613 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2614 | static bool checkIfClauses(Sema &S, OpenMPDirectiveKind Kind, |
| 2615 | ArrayRef<OMPClause *> Clauses, |
| 2616 | ArrayRef<OpenMPDirectiveKind> AllowedNameModifiers) { |
| 2617 | bool ErrorFound = false; |
| 2618 | unsigned NamedModifiersNumber = 0; |
| 2619 | SmallVector<const OMPIfClause *, OMPC_unknown + 1> FoundNameModifiers( |
| 2620 | OMPD_unknown + 1); |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2621 | SmallVector<SourceLocation, 4> NameModifierLoc; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2622 | for (const auto *C : Clauses) { |
| 2623 | if (const auto *IC = dyn_cast_or_null<OMPIfClause>(C)) { |
| 2624 | // At most one if clause without a directive-name-modifier can appear on |
| 2625 | // the directive. |
| 2626 | OpenMPDirectiveKind CurNM = IC->getNameModifier(); |
| 2627 | if (FoundNameModifiers[CurNM]) { |
| 2628 | S.Diag(C->getLocStart(), diag::err_omp_more_one_clause) |
| 2629 | << getOpenMPDirectiveName(Kind) << getOpenMPClauseName(OMPC_if) |
| 2630 | << (CurNM != OMPD_unknown) << getOpenMPDirectiveName(CurNM); |
| 2631 | ErrorFound = true; |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2632 | } else if (CurNM != OMPD_unknown) { |
| 2633 | NameModifierLoc.push_back(IC->getNameModifierLoc()); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2634 | ++NamedModifiersNumber; |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2635 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2636 | FoundNameModifiers[CurNM] = IC; |
| 2637 | if (CurNM == OMPD_unknown) |
| 2638 | continue; |
| 2639 | // Check if the specified name modifier is allowed for the current |
| 2640 | // directive. |
| 2641 | // At most one if clause with the particular directive-name-modifier can |
| 2642 | // appear on the directive. |
| 2643 | bool MatchFound = false; |
| 2644 | for (auto NM : AllowedNameModifiers) { |
| 2645 | if (CurNM == NM) { |
| 2646 | MatchFound = true; |
| 2647 | break; |
| 2648 | } |
| 2649 | } |
| 2650 | if (!MatchFound) { |
| 2651 | S.Diag(IC->getNameModifierLoc(), |
| 2652 | diag::err_omp_wrong_if_directive_name_modifier) |
| 2653 | << getOpenMPDirectiveName(CurNM) << getOpenMPDirectiveName(Kind); |
| 2654 | ErrorFound = true; |
| 2655 | } |
| 2656 | } |
| 2657 | } |
| 2658 | // If any if clause on the directive includes a directive-name-modifier then |
| 2659 | // all if clauses on the directive must include a directive-name-modifier. |
| 2660 | if (FoundNameModifiers[OMPD_unknown] && NamedModifiersNumber > 0) { |
| 2661 | if (NamedModifiersNumber == AllowedNameModifiers.size()) { |
| 2662 | S.Diag(FoundNameModifiers[OMPD_unknown]->getLocStart(), |
| 2663 | diag::err_omp_no_more_if_clause); |
| 2664 | } else { |
| 2665 | std::string Values; |
| 2666 | std::string Sep(", "); |
| 2667 | unsigned AllowedCnt = 0; |
| 2668 | unsigned TotalAllowedNum = |
| 2669 | AllowedNameModifiers.size() - NamedModifiersNumber; |
| 2670 | for (unsigned Cnt = 0, End = AllowedNameModifiers.size(); Cnt < End; |
| 2671 | ++Cnt) { |
| 2672 | OpenMPDirectiveKind NM = AllowedNameModifiers[Cnt]; |
| 2673 | if (!FoundNameModifiers[NM]) { |
| 2674 | Values += "'"; |
| 2675 | Values += getOpenMPDirectiveName(NM); |
| 2676 | Values += "'"; |
| 2677 | if (AllowedCnt + 2 == TotalAllowedNum) |
| 2678 | Values += " or "; |
| 2679 | else if (AllowedCnt + 1 != TotalAllowedNum) |
| 2680 | Values += Sep; |
| 2681 | ++AllowedCnt; |
| 2682 | } |
| 2683 | } |
| 2684 | S.Diag(FoundNameModifiers[OMPD_unknown]->getCondition()->getLocStart(), |
| 2685 | diag::err_omp_unnamed_if_clause) |
| 2686 | << (TotalAllowedNum > 1) << Values; |
| 2687 | } |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2688 | for (auto Loc : NameModifierLoc) { |
| 2689 | S.Diag(Loc, diag::note_omp_previous_named_if_clause); |
| 2690 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2691 | ErrorFound = true; |
| 2692 | } |
| 2693 | return ErrorFound; |
| 2694 | } |
| 2695 | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2696 | StmtResult Sema::ActOnOpenMPExecutableDirective( |
| 2697 | OpenMPDirectiveKind Kind, const DeclarationNameInfo &DirName, |
| 2698 | OpenMPDirectiveKind CancelRegion, ArrayRef<OMPClause *> Clauses, |
| 2699 | Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2700 | StmtResult Res = StmtError(); |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2701 | if (CheckNestingOfRegions(*this, DSAStack, Kind, DirName, CancelRegion, |
| 2702 | StartLoc)) |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2703 | return StmtError(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2704 | |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2705 | llvm::SmallVector<OMPClause *, 8> ClausesWithImplicit; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 2706 | llvm::DenseMap<ValueDecl *, Expr *> VarsWithInheritedDSA; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2707 | bool ErrorFound = false; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2708 | ClausesWithImplicit.append(Clauses.begin(), Clauses.end()); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2709 | if (AStmt) { |
| 2710 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 2711 | |
| 2712 | // Check default data sharing attributes for referenced variables. |
| 2713 | DSAAttrChecker DSAChecker(DSAStack, *this, cast<CapturedStmt>(AStmt)); |
| 2714 | DSAChecker.Visit(cast<CapturedStmt>(AStmt)->getCapturedStmt()); |
| 2715 | if (DSAChecker.isErrorFound()) |
| 2716 | return StmtError(); |
| 2717 | // Generate list of implicitly defined firstprivate variables. |
| 2718 | VarsWithInheritedDSA = DSAChecker.getVarsWithInheritedDSA(); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2719 | |
| 2720 | if (!DSAChecker.getImplicitFirstprivate().empty()) { |
| 2721 | if (OMPClause *Implicit = ActOnOpenMPFirstprivateClause( |
| 2722 | DSAChecker.getImplicitFirstprivate(), SourceLocation(), |
| 2723 | SourceLocation(), SourceLocation())) { |
| 2724 | ClausesWithImplicit.push_back(Implicit); |
| 2725 | ErrorFound = cast<OMPFirstprivateClause>(Implicit)->varlist_size() != |
| 2726 | DSAChecker.getImplicitFirstprivate().size(); |
| 2727 | } else |
| 2728 | ErrorFound = true; |
| 2729 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2730 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2731 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2732 | llvm::SmallVector<OpenMPDirectiveKind, 4> AllowedNameModifiers; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2733 | switch (Kind) { |
| 2734 | case OMPD_parallel: |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2735 | Res = ActOnOpenMPParallelDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2736 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2737 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2738 | break; |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 2739 | case OMPD_simd: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2740 | Res = ActOnOpenMPSimdDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc, |
| 2741 | VarsWithInheritedDSA); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 2742 | break; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2743 | case OMPD_for: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2744 | Res = ActOnOpenMPForDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc, |
| 2745 | VarsWithInheritedDSA); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2746 | break; |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2747 | case OMPD_for_simd: |
| 2748 | Res = ActOnOpenMPForSimdDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2749 | EndLoc, VarsWithInheritedDSA); |
| 2750 | break; |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 2751 | case OMPD_sections: |
| 2752 | Res = ActOnOpenMPSectionsDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2753 | EndLoc); |
| 2754 | break; |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2755 | case OMPD_section: |
| 2756 | assert(ClausesWithImplicit.empty() && |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2757 | "No clauses are allowed for 'omp section' directive"); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2758 | Res = ActOnOpenMPSectionDirective(AStmt, StartLoc, EndLoc); |
| 2759 | break; |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 2760 | case OMPD_single: |
| 2761 | Res = ActOnOpenMPSingleDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2762 | EndLoc); |
| 2763 | break; |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2764 | case OMPD_master: |
| 2765 | assert(ClausesWithImplicit.empty() && |
| 2766 | "No clauses are allowed for 'omp master' directive"); |
| 2767 | Res = ActOnOpenMPMasterDirective(AStmt, StartLoc, EndLoc); |
| 2768 | break; |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2769 | case OMPD_critical: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 2770 | Res = ActOnOpenMPCriticalDirective(DirName, ClausesWithImplicit, AStmt, |
| 2771 | StartLoc, EndLoc); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2772 | break; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2773 | case OMPD_parallel_for: |
| 2774 | Res = ActOnOpenMPParallelForDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2775 | EndLoc, VarsWithInheritedDSA); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2776 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2777 | break; |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2778 | case OMPD_parallel_for_simd: |
| 2779 | Res = ActOnOpenMPParallelForSimdDirective( |
| 2780 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2781 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2782 | break; |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2783 | case OMPD_parallel_sections: |
| 2784 | Res = ActOnOpenMPParallelSectionsDirective(ClausesWithImplicit, AStmt, |
| 2785 | StartLoc, EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2786 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2787 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2788 | case OMPD_task: |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2789 | Res = |
| 2790 | ActOnOpenMPTaskDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2791 | AllowedNameModifiers.push_back(OMPD_task); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2792 | break; |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2793 | case OMPD_taskyield: |
| 2794 | assert(ClausesWithImplicit.empty() && |
| 2795 | "No clauses are allowed for 'omp taskyield' directive"); |
| 2796 | assert(AStmt == nullptr && |
| 2797 | "No associated statement allowed for 'omp taskyield' directive"); |
| 2798 | Res = ActOnOpenMPTaskyieldDirective(StartLoc, EndLoc); |
| 2799 | break; |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2800 | case OMPD_barrier: |
| 2801 | assert(ClausesWithImplicit.empty() && |
| 2802 | "No clauses are allowed for 'omp barrier' directive"); |
| 2803 | assert(AStmt == nullptr && |
| 2804 | "No associated statement allowed for 'omp barrier' directive"); |
| 2805 | Res = ActOnOpenMPBarrierDirective(StartLoc, EndLoc); |
| 2806 | break; |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2807 | case OMPD_taskwait: |
| 2808 | assert(ClausesWithImplicit.empty() && |
| 2809 | "No clauses are allowed for 'omp taskwait' directive"); |
| 2810 | assert(AStmt == nullptr && |
| 2811 | "No associated statement allowed for 'omp taskwait' directive"); |
| 2812 | Res = ActOnOpenMPTaskwaitDirective(StartLoc, EndLoc); |
| 2813 | break; |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2814 | case OMPD_taskgroup: |
| 2815 | assert(ClausesWithImplicit.empty() && |
| 2816 | "No clauses are allowed for 'omp taskgroup' directive"); |
| 2817 | Res = ActOnOpenMPTaskgroupDirective(AStmt, StartLoc, EndLoc); |
| 2818 | break; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2819 | case OMPD_flush: |
| 2820 | assert(AStmt == nullptr && |
| 2821 | "No associated statement allowed for 'omp flush' directive"); |
| 2822 | Res = ActOnOpenMPFlushDirective(ClausesWithImplicit, StartLoc, EndLoc); |
| 2823 | break; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2824 | case OMPD_ordered: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 2825 | Res = ActOnOpenMPOrderedDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2826 | EndLoc); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2827 | break; |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2828 | case OMPD_atomic: |
| 2829 | Res = ActOnOpenMPAtomicDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2830 | EndLoc); |
| 2831 | break; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2832 | case OMPD_teams: |
| 2833 | Res = |
| 2834 | ActOnOpenMPTeamsDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); |
| 2835 | break; |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2836 | case OMPD_target: |
| 2837 | Res = ActOnOpenMPTargetDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2838 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2839 | AllowedNameModifiers.push_back(OMPD_target); |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2840 | break; |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2841 | case OMPD_cancellation_point: |
| 2842 | assert(ClausesWithImplicit.empty() && |
| 2843 | "No clauses are allowed for 'omp cancellation point' directive"); |
| 2844 | assert(AStmt == nullptr && "No associated statement allowed for 'omp " |
| 2845 | "cancellation point' directive"); |
| 2846 | Res = ActOnOpenMPCancellationPointDirective(StartLoc, EndLoc, CancelRegion); |
| 2847 | break; |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2848 | case OMPD_cancel: |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2849 | assert(AStmt == nullptr && |
| 2850 | "No associated statement allowed for 'omp cancel' directive"); |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 2851 | Res = ActOnOpenMPCancelDirective(ClausesWithImplicit, StartLoc, EndLoc, |
| 2852 | CancelRegion); |
| 2853 | AllowedNameModifiers.push_back(OMPD_cancel); |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2854 | break; |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 2855 | case OMPD_target_data: |
| 2856 | Res = ActOnOpenMPTargetDataDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2857 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2858 | AllowedNameModifiers.push_back(OMPD_target_data); |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 2859 | break; |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2860 | case OMPD_target_enter_data: |
| 2861 | Res = ActOnOpenMPTargetEnterDataDirective(ClausesWithImplicit, StartLoc, |
| 2862 | EndLoc); |
| 2863 | AllowedNameModifiers.push_back(OMPD_target_enter_data); |
| 2864 | break; |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2865 | case OMPD_target_exit_data: |
| 2866 | Res = ActOnOpenMPTargetExitDataDirective(ClausesWithImplicit, StartLoc, |
| 2867 | EndLoc); |
| 2868 | AllowedNameModifiers.push_back(OMPD_target_exit_data); |
| 2869 | break; |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2870 | case OMPD_taskloop: |
| 2871 | Res = ActOnOpenMPTaskLoopDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2872 | EndLoc, VarsWithInheritedDSA); |
| 2873 | AllowedNameModifiers.push_back(OMPD_taskloop); |
| 2874 | break; |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2875 | case OMPD_taskloop_simd: |
| 2876 | Res = ActOnOpenMPTaskLoopSimdDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2877 | EndLoc, VarsWithInheritedDSA); |
| 2878 | AllowedNameModifiers.push_back(OMPD_taskloop); |
| 2879 | break; |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2880 | case OMPD_distribute: |
| 2881 | Res = ActOnOpenMPDistributeDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2882 | EndLoc, VarsWithInheritedDSA); |
| 2883 | break; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2884 | case OMPD_threadprivate: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2885 | llvm_unreachable("OpenMP Directive is not allowed"); |
| 2886 | case OMPD_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2887 | llvm_unreachable("Unknown OpenMP directive"); |
| 2888 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2889 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2890 | for (auto P : VarsWithInheritedDSA) { |
| 2891 | Diag(P.second->getExprLoc(), diag::err_omp_no_dsa_for_variable) |
| 2892 | << P.first << P.second->getSourceRange(); |
| 2893 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2894 | ErrorFound = !VarsWithInheritedDSA.empty() || ErrorFound; |
| 2895 | |
| 2896 | if (!AllowedNameModifiers.empty()) |
| 2897 | ErrorFound = checkIfClauses(*this, Kind, Clauses, AllowedNameModifiers) || |
| 2898 | ErrorFound; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2899 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2900 | if (ErrorFound) |
| 2901 | return StmtError(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2902 | return Res; |
| 2903 | } |
| 2904 | |
| 2905 | StmtResult Sema::ActOnOpenMPParallelDirective(ArrayRef<OMPClause *> Clauses, |
| 2906 | Stmt *AStmt, |
| 2907 | SourceLocation StartLoc, |
| 2908 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2909 | if (!AStmt) |
| 2910 | return StmtError(); |
| 2911 | |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 2912 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 2913 | // 1.2.2 OpenMP Language Terminology |
| 2914 | // Structured block - An executable statement with a single entry at the |
| 2915 | // top and a single exit at the bottom. |
| 2916 | // The point of exit cannot be a branch out of the structured block. |
| 2917 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 2918 | CS->getCapturedDecl()->setNothrow(); |
| 2919 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2920 | getCurFunction()->setHasBranchProtectedScope(); |
| 2921 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 2922 | return OMPParallelDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 2923 | DSAStack->isCancelRegion()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2924 | } |
| 2925 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2926 | namespace { |
| 2927 | /// \brief Helper class for checking canonical form of the OpenMP loops and |
| 2928 | /// extracting iteration space of each loop in the loop nest, that will be used |
| 2929 | /// for IR generation. |
| 2930 | class OpenMPIterationSpaceChecker { |
| 2931 | /// \brief Reference to Sema. |
| 2932 | Sema &SemaRef; |
| 2933 | /// \brief A location for diagnostics (when there is no some better location). |
| 2934 | SourceLocation DefaultLoc; |
| 2935 | /// \brief A location for diagnostics (when increment is not compatible). |
| 2936 | SourceLocation ConditionLoc; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2937 | /// \brief A source location for referring to loop init later. |
| 2938 | SourceRange InitSrcRange; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2939 | /// \brief A source location for referring to condition later. |
| 2940 | SourceRange ConditionSrcRange; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2941 | /// \brief A source location for referring to increment later. |
| 2942 | SourceRange IncrementSrcRange; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2943 | /// \brief Loop variable. |
| 2944 | VarDecl *Var; |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2945 | /// \brief Reference to loop variable. |
| 2946 | DeclRefExpr *VarRef; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2947 | /// \brief Lower bound (initializer for the var). |
| 2948 | Expr *LB; |
| 2949 | /// \brief Upper bound. |
| 2950 | Expr *UB; |
| 2951 | /// \brief Loop step (increment). |
| 2952 | Expr *Step; |
| 2953 | /// \brief This flag is true when condition is one of: |
| 2954 | /// Var < UB |
| 2955 | /// Var <= UB |
| 2956 | /// UB > Var |
| 2957 | /// UB >= Var |
| 2958 | bool TestIsLessOp; |
| 2959 | /// \brief This flag is true when condition is strict ( < or > ). |
| 2960 | bool TestIsStrictOp; |
| 2961 | /// \brief This flag is true when step is subtracted on each iteration. |
| 2962 | bool SubtractStep; |
| 2963 | |
| 2964 | public: |
| 2965 | OpenMPIterationSpaceChecker(Sema &SemaRef, SourceLocation DefaultLoc) |
| 2966 | : SemaRef(SemaRef), DefaultLoc(DefaultLoc), ConditionLoc(DefaultLoc), |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2967 | InitSrcRange(SourceRange()), ConditionSrcRange(SourceRange()), |
| 2968 | IncrementSrcRange(SourceRange()), Var(nullptr), VarRef(nullptr), |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2969 | LB(nullptr), UB(nullptr), Step(nullptr), TestIsLessOp(false), |
| 2970 | TestIsStrictOp(false), SubtractStep(false) {} |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2971 | /// \brief Check init-expr for canonical loop form and save loop counter |
| 2972 | /// variable - #Var and its initialization value - #LB. |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2973 | bool CheckInit(Stmt *S, bool EmitDiags = true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2974 | /// \brief Check test-expr for canonical form, save upper-bound (#UB), flags |
| 2975 | /// for less/greater and for strict/non-strict comparison. |
| 2976 | bool CheckCond(Expr *S); |
| 2977 | /// \brief Check incr-expr for canonical loop form and return true if it |
| 2978 | /// does not conform, otherwise save loop step (#Step). |
| 2979 | bool CheckInc(Expr *S); |
| 2980 | /// \brief Return the loop counter variable. |
| 2981 | VarDecl *GetLoopVar() const { return Var; } |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2982 | /// \brief Return the reference expression to loop counter variable. |
| 2983 | DeclRefExpr *GetLoopVarRefExpr() const { return VarRef; } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2984 | /// \brief Source range of the loop init. |
| 2985 | SourceRange GetInitSrcRange() const { return InitSrcRange; } |
| 2986 | /// \brief Source range of the loop condition. |
| 2987 | SourceRange GetConditionSrcRange() const { return ConditionSrcRange; } |
| 2988 | /// \brief Source range of the loop increment. |
| 2989 | SourceRange GetIncrementSrcRange() const { return IncrementSrcRange; } |
| 2990 | /// \brief True if the step should be subtracted. |
| 2991 | bool ShouldSubtractStep() const { return SubtractStep; } |
| 2992 | /// \brief Build the expression to calculate the number of iterations. |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 2993 | Expr *BuildNumIterations(Scope *S, const bool LimitedType) const; |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 2994 | /// \brief Build the precondition expression for the loops. |
| 2995 | Expr *BuildPreCond(Scope *S, Expr *Cond) const; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2996 | /// \brief Build reference expression to the counter be used for codegen. |
| 2997 | Expr *BuildCounterVar() const; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 2998 | /// \brief Build reference expression to the private counter be used for |
| 2999 | /// codegen. |
| 3000 | Expr *BuildPrivateCounterVar() const; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3001 | /// \brief Build initization of the counter be used for codegen. |
| 3002 | Expr *BuildCounterInit() const; |
| 3003 | /// \brief Build step of the counter be used for codegen. |
| 3004 | Expr *BuildCounterStep() const; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3005 | /// \brief Return true if any expression is dependent. |
| 3006 | bool Dependent() const; |
| 3007 | |
| 3008 | private: |
| 3009 | /// \brief Check the right-hand side of an assignment in the increment |
| 3010 | /// expression. |
| 3011 | bool CheckIncRHS(Expr *RHS); |
| 3012 | /// \brief Helper to set loop counter variable and its initializer. |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3013 | bool SetVarAndLB(VarDecl *NewVar, DeclRefExpr *NewVarRefExpr, Expr *NewLB); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3014 | /// \brief Helper to set upper bound. |
Craig Topper | e335f25 | 2015-10-04 04:53:55 +0000 | [diff] [blame] | 3015 | bool SetUB(Expr *NewUB, bool LessOp, bool StrictOp, SourceRange SR, |
Craig Topper | 9cd5e4f | 2015-09-21 01:23:32 +0000 | [diff] [blame] | 3016 | SourceLocation SL); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3017 | /// \brief Helper to set loop increment. |
| 3018 | bool SetStep(Expr *NewStep, bool Subtract); |
| 3019 | }; |
| 3020 | |
| 3021 | bool OpenMPIterationSpaceChecker::Dependent() const { |
| 3022 | if (!Var) { |
| 3023 | assert(!LB && !UB && !Step); |
| 3024 | return false; |
| 3025 | } |
| 3026 | return Var->getType()->isDependentType() || (LB && LB->isValueDependent()) || |
| 3027 | (UB && UB->isValueDependent()) || (Step && Step->isValueDependent()); |
| 3028 | } |
| 3029 | |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3030 | template <typename T> |
| 3031 | static T *getExprAsWritten(T *E) { |
| 3032 | if (auto *ExprTemp = dyn_cast<ExprWithCleanups>(E)) |
| 3033 | E = ExprTemp->getSubExpr(); |
| 3034 | |
| 3035 | if (auto *MTE = dyn_cast<MaterializeTemporaryExpr>(E)) |
| 3036 | E = MTE->GetTemporaryExpr(); |
| 3037 | |
| 3038 | while (auto *Binder = dyn_cast<CXXBindTemporaryExpr>(E)) |
| 3039 | E = Binder->getSubExpr(); |
| 3040 | |
| 3041 | if (auto *ICE = dyn_cast<ImplicitCastExpr>(E)) |
| 3042 | E = ICE->getSubExprAsWritten(); |
| 3043 | return E->IgnoreParens(); |
| 3044 | } |
| 3045 | |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3046 | bool OpenMPIterationSpaceChecker::SetVarAndLB(VarDecl *NewVar, |
| 3047 | DeclRefExpr *NewVarRefExpr, |
| 3048 | Expr *NewLB) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3049 | // State consistency checking to ensure correct usage. |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3050 | assert(Var == nullptr && LB == nullptr && VarRef == nullptr && |
| 3051 | UB == nullptr && Step == nullptr && !TestIsLessOp && !TestIsStrictOp); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3052 | if (!NewVar || !NewLB) |
| 3053 | return true; |
| 3054 | Var = NewVar; |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3055 | VarRef = NewVarRefExpr; |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3056 | if (auto *CE = dyn_cast_or_null<CXXConstructExpr>(NewLB)) |
| 3057 | if (const CXXConstructorDecl *Ctor = CE->getConstructor()) |
Alexey Bataev | 0d08a7f | 2015-07-16 04:19:43 +0000 | [diff] [blame] | 3058 | if ((Ctor->isCopyOrMoveConstructor() || |
| 3059 | Ctor->isConvertingConstructor(/*AllowExplicit=*/false)) && |
| 3060 | CE->getNumArgs() > 0 && CE->getArg(0) != nullptr) |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3061 | NewLB = CE->getArg(0)->IgnoreParenImpCasts(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3062 | LB = NewLB; |
| 3063 | return false; |
| 3064 | } |
| 3065 | |
| 3066 | bool OpenMPIterationSpaceChecker::SetUB(Expr *NewUB, bool LessOp, bool StrictOp, |
Craig Topper | e335f25 | 2015-10-04 04:53:55 +0000 | [diff] [blame] | 3067 | SourceRange SR, SourceLocation SL) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3068 | // State consistency checking to ensure correct usage. |
| 3069 | assert(Var != nullptr && LB != nullptr && UB == nullptr && Step == nullptr && |
| 3070 | !TestIsLessOp && !TestIsStrictOp); |
| 3071 | if (!NewUB) |
| 3072 | return true; |
| 3073 | UB = NewUB; |
| 3074 | TestIsLessOp = LessOp; |
| 3075 | TestIsStrictOp = StrictOp; |
| 3076 | ConditionSrcRange = SR; |
| 3077 | ConditionLoc = SL; |
| 3078 | return false; |
| 3079 | } |
| 3080 | |
| 3081 | bool OpenMPIterationSpaceChecker::SetStep(Expr *NewStep, bool Subtract) { |
| 3082 | // State consistency checking to ensure correct usage. |
| 3083 | assert(Var != nullptr && LB != nullptr && Step == nullptr); |
| 3084 | if (!NewStep) |
| 3085 | return true; |
| 3086 | if (!NewStep->isValueDependent()) { |
| 3087 | // Check that the step is integer expression. |
| 3088 | SourceLocation StepLoc = NewStep->getLocStart(); |
| 3089 | ExprResult Val = |
| 3090 | SemaRef.PerformOpenMPImplicitIntegerConversion(StepLoc, NewStep); |
| 3091 | if (Val.isInvalid()) |
| 3092 | return true; |
| 3093 | NewStep = Val.get(); |
| 3094 | |
| 3095 | // OpenMP [2.6, Canonical Loop Form, Restrictions] |
| 3096 | // If test-expr is of form var relational-op b and relational-op is < or |
| 3097 | // <= then incr-expr must cause var to increase on each iteration of the |
| 3098 | // loop. If test-expr is of form var relational-op b and relational-op is |
| 3099 | // > or >= then incr-expr must cause var to decrease on each iteration of |
| 3100 | // the loop. |
| 3101 | // If test-expr is of form b relational-op var and relational-op is < or |
| 3102 | // <= then incr-expr must cause var to decrease on each iteration of the |
| 3103 | // loop. If test-expr is of form b relational-op var and relational-op is |
| 3104 | // > or >= then incr-expr must cause var to increase on each iteration of |
| 3105 | // the loop. |
| 3106 | llvm::APSInt Result; |
| 3107 | bool IsConstant = NewStep->isIntegerConstantExpr(Result, SemaRef.Context); |
| 3108 | bool IsUnsigned = !NewStep->getType()->hasSignedIntegerRepresentation(); |
| 3109 | bool IsConstNeg = |
| 3110 | IsConstant && Result.isSigned() && (Subtract != Result.isNegative()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3111 | bool IsConstPos = |
| 3112 | IsConstant && Result.isSigned() && (Subtract == Result.isNegative()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3113 | bool IsConstZero = IsConstant && !Result.getBoolValue(); |
| 3114 | if (UB && (IsConstZero || |
| 3115 | (TestIsLessOp ? (IsConstNeg || (IsUnsigned && Subtract)) |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3116 | : (IsConstPos || (IsUnsigned && !Subtract))))) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3117 | SemaRef.Diag(NewStep->getExprLoc(), |
| 3118 | diag::err_omp_loop_incr_not_compatible) |
| 3119 | << Var << TestIsLessOp << NewStep->getSourceRange(); |
| 3120 | SemaRef.Diag(ConditionLoc, |
| 3121 | diag::note_omp_loop_cond_requres_compatible_incr) |
| 3122 | << TestIsLessOp << ConditionSrcRange; |
| 3123 | return true; |
| 3124 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3125 | if (TestIsLessOp == Subtract) { |
| 3126 | NewStep = SemaRef.CreateBuiltinUnaryOp(NewStep->getExprLoc(), UO_Minus, |
| 3127 | NewStep).get(); |
| 3128 | Subtract = !Subtract; |
| 3129 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3130 | } |
| 3131 | |
| 3132 | Step = NewStep; |
| 3133 | SubtractStep = Subtract; |
| 3134 | return false; |
| 3135 | } |
| 3136 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3137 | bool OpenMPIterationSpaceChecker::CheckInit(Stmt *S, bool EmitDiags) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3138 | // Check init-expr for canonical loop form and save loop counter |
| 3139 | // variable - #Var and its initialization value - #LB. |
| 3140 | // OpenMP [2.6] Canonical loop form. init-expr may be one of the following: |
| 3141 | // var = lb |
| 3142 | // integer-type var = lb |
| 3143 | // random-access-iterator-type var = lb |
| 3144 | // pointer-type var = lb |
| 3145 | // |
| 3146 | if (!S) { |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3147 | if (EmitDiags) { |
| 3148 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_init); |
| 3149 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3150 | return true; |
| 3151 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3152 | InitSrcRange = S->getSourceRange(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3153 | if (Expr *E = dyn_cast<Expr>(S)) |
| 3154 | S = E->IgnoreParens(); |
| 3155 | if (auto BO = dyn_cast<BinaryOperator>(S)) { |
| 3156 | if (BO->getOpcode() == BO_Assign) |
| 3157 | if (auto DRE = dyn_cast<DeclRefExpr>(BO->getLHS()->IgnoreParens())) |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3158 | return SetVarAndLB(dyn_cast<VarDecl>(DRE->getDecl()), DRE, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3159 | BO->getRHS()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3160 | } else if (auto DS = dyn_cast<DeclStmt>(S)) { |
| 3161 | if (DS->isSingleDecl()) { |
| 3162 | if (auto Var = dyn_cast_or_null<VarDecl>(DS->getSingleDecl())) { |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3163 | if (Var->hasInit() && !Var->getType()->isReferenceType()) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3164 | // Accept non-canonical init form here but emit ext. warning. |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3165 | if (Var->getInitStyle() != VarDecl::CInit && EmitDiags) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3166 | SemaRef.Diag(S->getLocStart(), |
| 3167 | diag::ext_omp_loop_not_canonical_init) |
| 3168 | << S->getSourceRange(); |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3169 | return SetVarAndLB(Var, nullptr, Var->getInit()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3170 | } |
| 3171 | } |
| 3172 | } |
| 3173 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) |
| 3174 | if (CE->getOperator() == OO_Equal) |
| 3175 | if (auto DRE = dyn_cast<DeclRefExpr>(CE->getArg(0))) |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3176 | return SetVarAndLB(dyn_cast<VarDecl>(DRE->getDecl()), DRE, |
| 3177 | CE->getArg(1)); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3178 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3179 | if (EmitDiags) { |
| 3180 | SemaRef.Diag(S->getLocStart(), diag::err_omp_loop_not_canonical_init) |
| 3181 | << S->getSourceRange(); |
| 3182 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3183 | return true; |
| 3184 | } |
| 3185 | |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 3186 | /// \brief Ignore parenthesizes, implicit casts, copy constructor and return the |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3187 | /// variable (which may be the loop variable) if possible. |
| 3188 | static const VarDecl *GetInitVarDecl(const Expr *E) { |
| 3189 | if (!E) |
Craig Topper | 4b56692 | 2014-06-09 02:04:02 +0000 | [diff] [blame] | 3190 | return nullptr; |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3191 | E = getExprAsWritten(E); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3192 | if (auto *CE = dyn_cast_or_null<CXXConstructExpr>(E)) |
| 3193 | if (const CXXConstructorDecl *Ctor = CE->getConstructor()) |
Alexey Bataev | 0d08a7f | 2015-07-16 04:19:43 +0000 | [diff] [blame] | 3194 | if ((Ctor->isCopyOrMoveConstructor() || |
| 3195 | Ctor->isConvertingConstructor(/*AllowExplicit=*/false)) && |
| 3196 | CE->getNumArgs() > 0 && CE->getArg(0) != nullptr) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3197 | E = CE->getArg(0)->IgnoreParenImpCasts(); |
| 3198 | auto DRE = dyn_cast_or_null<DeclRefExpr>(E); |
| 3199 | if (!DRE) |
| 3200 | return nullptr; |
| 3201 | return dyn_cast<VarDecl>(DRE->getDecl()); |
| 3202 | } |
| 3203 | |
| 3204 | bool OpenMPIterationSpaceChecker::CheckCond(Expr *S) { |
| 3205 | // Check test-expr for canonical form, save upper-bound UB, flags for |
| 3206 | // less/greater and for strict/non-strict comparison. |
| 3207 | // OpenMP [2.6] Canonical loop form. Test-expr may be one of the following: |
| 3208 | // var relational-op b |
| 3209 | // b relational-op var |
| 3210 | // |
| 3211 | if (!S) { |
| 3212 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_cond) << Var; |
| 3213 | return true; |
| 3214 | } |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3215 | S = getExprAsWritten(S); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3216 | SourceLocation CondLoc = S->getLocStart(); |
| 3217 | if (auto BO = dyn_cast<BinaryOperator>(S)) { |
| 3218 | if (BO->isRelationalOp()) { |
| 3219 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 3220 | return SetUB(BO->getRHS(), |
| 3221 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_LE), |
| 3222 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_GT), |
| 3223 | BO->getSourceRange(), BO->getOperatorLoc()); |
| 3224 | if (GetInitVarDecl(BO->getRHS()) == Var) |
| 3225 | return SetUB(BO->getLHS(), |
| 3226 | (BO->getOpcode() == BO_GT || BO->getOpcode() == BO_GE), |
| 3227 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_GT), |
| 3228 | BO->getSourceRange(), BO->getOperatorLoc()); |
| 3229 | } |
| 3230 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
| 3231 | if (CE->getNumArgs() == 2) { |
| 3232 | auto Op = CE->getOperator(); |
| 3233 | switch (Op) { |
| 3234 | case OO_Greater: |
| 3235 | case OO_GreaterEqual: |
| 3236 | case OO_Less: |
| 3237 | case OO_LessEqual: |
| 3238 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 3239 | return SetUB(CE->getArg(1), Op == OO_Less || Op == OO_LessEqual, |
| 3240 | Op == OO_Less || Op == OO_Greater, CE->getSourceRange(), |
| 3241 | CE->getOperatorLoc()); |
| 3242 | if (GetInitVarDecl(CE->getArg(1)) == Var) |
| 3243 | return SetUB(CE->getArg(0), Op == OO_Greater || Op == OO_GreaterEqual, |
| 3244 | Op == OO_Less || Op == OO_Greater, CE->getSourceRange(), |
| 3245 | CE->getOperatorLoc()); |
| 3246 | break; |
| 3247 | default: |
| 3248 | break; |
| 3249 | } |
| 3250 | } |
| 3251 | } |
| 3252 | SemaRef.Diag(CondLoc, diag::err_omp_loop_not_canonical_cond) |
| 3253 | << S->getSourceRange() << Var; |
| 3254 | return true; |
| 3255 | } |
| 3256 | |
| 3257 | bool OpenMPIterationSpaceChecker::CheckIncRHS(Expr *RHS) { |
| 3258 | // RHS of canonical loop form increment can be: |
| 3259 | // var + incr |
| 3260 | // incr + var |
| 3261 | // var - incr |
| 3262 | // |
| 3263 | RHS = RHS->IgnoreParenImpCasts(); |
| 3264 | if (auto BO = dyn_cast<BinaryOperator>(RHS)) { |
| 3265 | if (BO->isAdditiveOp()) { |
| 3266 | bool IsAdd = BO->getOpcode() == BO_Add; |
| 3267 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 3268 | return SetStep(BO->getRHS(), !IsAdd); |
| 3269 | if (IsAdd && GetInitVarDecl(BO->getRHS()) == Var) |
| 3270 | return SetStep(BO->getLHS(), false); |
| 3271 | } |
| 3272 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(RHS)) { |
| 3273 | bool IsAdd = CE->getOperator() == OO_Plus; |
| 3274 | if ((IsAdd || CE->getOperator() == OO_Minus) && CE->getNumArgs() == 2) { |
| 3275 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 3276 | return SetStep(CE->getArg(1), !IsAdd); |
| 3277 | if (IsAdd && GetInitVarDecl(CE->getArg(1)) == Var) |
| 3278 | return SetStep(CE->getArg(0), false); |
| 3279 | } |
| 3280 | } |
| 3281 | SemaRef.Diag(RHS->getLocStart(), diag::err_omp_loop_not_canonical_incr) |
| 3282 | << RHS->getSourceRange() << Var; |
| 3283 | return true; |
| 3284 | } |
| 3285 | |
| 3286 | bool OpenMPIterationSpaceChecker::CheckInc(Expr *S) { |
| 3287 | // Check incr-expr for canonical loop form and return true if it |
| 3288 | // does not conform. |
| 3289 | // OpenMP [2.6] Canonical loop form. Test-expr may be one of the following: |
| 3290 | // ++var |
| 3291 | // var++ |
| 3292 | // --var |
| 3293 | // var-- |
| 3294 | // var += incr |
| 3295 | // var -= incr |
| 3296 | // var = var + incr |
| 3297 | // var = incr + var |
| 3298 | // var = var - incr |
| 3299 | // |
| 3300 | if (!S) { |
| 3301 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_incr) << Var; |
| 3302 | return true; |
| 3303 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3304 | IncrementSrcRange = S->getSourceRange(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3305 | S = S->IgnoreParens(); |
| 3306 | if (auto UO = dyn_cast<UnaryOperator>(S)) { |
| 3307 | if (UO->isIncrementDecrementOp() && GetInitVarDecl(UO->getSubExpr()) == Var) |
| 3308 | return SetStep( |
| 3309 | SemaRef.ActOnIntegerConstant(UO->getLocStart(), |
| 3310 | (UO->isDecrementOp() ? -1 : 1)).get(), |
| 3311 | false); |
| 3312 | } else if (auto BO = dyn_cast<BinaryOperator>(S)) { |
| 3313 | switch (BO->getOpcode()) { |
| 3314 | case BO_AddAssign: |
| 3315 | case BO_SubAssign: |
| 3316 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 3317 | return SetStep(BO->getRHS(), BO->getOpcode() == BO_SubAssign); |
| 3318 | break; |
| 3319 | case BO_Assign: |
| 3320 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 3321 | return CheckIncRHS(BO->getRHS()); |
| 3322 | break; |
| 3323 | default: |
| 3324 | break; |
| 3325 | } |
| 3326 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
| 3327 | switch (CE->getOperator()) { |
| 3328 | case OO_PlusPlus: |
| 3329 | case OO_MinusMinus: |
| 3330 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 3331 | return SetStep( |
| 3332 | SemaRef.ActOnIntegerConstant( |
| 3333 | CE->getLocStart(), |
| 3334 | ((CE->getOperator() == OO_MinusMinus) ? -1 : 1)).get(), |
| 3335 | false); |
| 3336 | break; |
| 3337 | case OO_PlusEqual: |
| 3338 | case OO_MinusEqual: |
| 3339 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 3340 | return SetStep(CE->getArg(1), CE->getOperator() == OO_MinusEqual); |
| 3341 | break; |
| 3342 | case OO_Equal: |
| 3343 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 3344 | return CheckIncRHS(CE->getArg(1)); |
| 3345 | break; |
| 3346 | default: |
| 3347 | break; |
| 3348 | } |
| 3349 | } |
| 3350 | SemaRef.Diag(S->getLocStart(), diag::err_omp_loop_not_canonical_incr) |
| 3351 | << S->getSourceRange() << Var; |
| 3352 | return true; |
| 3353 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3354 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3355 | namespace { |
| 3356 | // Transform variables declared in GNU statement expressions to new ones to |
| 3357 | // avoid crash on codegen. |
| 3358 | class TransformToNewDefs : public TreeTransform<TransformToNewDefs> { |
| 3359 | typedef TreeTransform<TransformToNewDefs> BaseTransform; |
| 3360 | |
| 3361 | public: |
| 3362 | TransformToNewDefs(Sema &SemaRef) : BaseTransform(SemaRef) {} |
| 3363 | |
| 3364 | Decl *TransformDefinition(SourceLocation Loc, Decl *D) { |
| 3365 | if (auto *VD = cast<VarDecl>(D)) |
| 3366 | if (!isa<ParmVarDecl>(D) && !isa<VarTemplateSpecializationDecl>(D) && |
| 3367 | !isa<ImplicitParamDecl>(D)) { |
| 3368 | auto *NewVD = VarDecl::Create( |
| 3369 | SemaRef.Context, VD->getDeclContext(), VD->getLocStart(), |
| 3370 | VD->getLocation(), VD->getIdentifier(), VD->getType(), |
| 3371 | VD->getTypeSourceInfo(), VD->getStorageClass()); |
| 3372 | NewVD->setTSCSpec(VD->getTSCSpec()); |
| 3373 | NewVD->setInit(VD->getInit()); |
| 3374 | NewVD->setInitStyle(VD->getInitStyle()); |
| 3375 | NewVD->setExceptionVariable(VD->isExceptionVariable()); |
| 3376 | NewVD->setNRVOVariable(VD->isNRVOVariable()); |
| 3377 | NewVD->setCXXForRangeDecl(VD->isInExternCXXContext()); |
| 3378 | NewVD->setConstexpr(VD->isConstexpr()); |
| 3379 | NewVD->setInitCapture(VD->isInitCapture()); |
| 3380 | NewVD->setPreviousDeclInSameBlockScope( |
| 3381 | VD->isPreviousDeclInSameBlockScope()); |
| 3382 | VD->getDeclContext()->addHiddenDecl(NewVD); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 3383 | if (VD->hasAttrs()) |
| 3384 | NewVD->setAttrs(VD->getAttrs()); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3385 | transformedLocalDecl(VD, NewVD); |
| 3386 | return NewVD; |
| 3387 | } |
| 3388 | return BaseTransform::TransformDefinition(Loc, D); |
| 3389 | } |
| 3390 | |
| 3391 | ExprResult TransformDeclRefExpr(DeclRefExpr *E) { |
| 3392 | if (auto *NewD = TransformDecl(E->getExprLoc(), E->getDecl())) |
| 3393 | if (E->getDecl() != NewD) { |
| 3394 | NewD->setReferenced(); |
| 3395 | NewD->markUsed(SemaRef.Context); |
| 3396 | return DeclRefExpr::Create( |
| 3397 | SemaRef.Context, E->getQualifierLoc(), E->getTemplateKeywordLoc(), |
| 3398 | cast<ValueDecl>(NewD), E->refersToEnclosingVariableOrCapture(), |
| 3399 | E->getNameInfo(), E->getType(), E->getValueKind()); |
| 3400 | } |
| 3401 | return BaseTransform::TransformDeclRefExpr(E); |
| 3402 | } |
| 3403 | }; |
| 3404 | } |
| 3405 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3406 | /// \brief Build the expression to calculate the number of iterations. |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3407 | Expr * |
| 3408 | OpenMPIterationSpaceChecker::BuildNumIterations(Scope *S, |
| 3409 | const bool LimitedType) const { |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3410 | TransformToNewDefs Transform(SemaRef); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3411 | ExprResult Diff; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3412 | auto VarType = Var->getType().getNonReferenceType(); |
| 3413 | if (VarType->isIntegerType() || VarType->isPointerType() || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3414 | SemaRef.getLangOpts().CPlusPlus) { |
| 3415 | // Upper - Lower |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3416 | auto *UBExpr = TestIsLessOp ? UB : LB; |
| 3417 | auto *LBExpr = TestIsLessOp ? LB : UB; |
| 3418 | Expr *Upper = Transform.TransformExpr(UBExpr).get(); |
| 3419 | Expr *Lower = Transform.TransformExpr(LBExpr).get(); |
| 3420 | if (!Upper || !Lower) |
| 3421 | return nullptr; |
| 3422 | Upper = SemaRef.PerformImplicitConversion(Upper, UBExpr->getType(), |
| 3423 | Sema::AA_Converting, |
| 3424 | /*AllowExplicit=*/true) |
| 3425 | .get(); |
| 3426 | Lower = SemaRef.PerformImplicitConversion(Lower, LBExpr->getType(), |
| 3427 | Sema::AA_Converting, |
| 3428 | /*AllowExplicit=*/true) |
| 3429 | .get(); |
| 3430 | if (!Upper || !Lower) |
| 3431 | return nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3432 | |
| 3433 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Sub, Upper, Lower); |
| 3434 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3435 | if (!Diff.isUsable() && VarType->getAsCXXRecordDecl()) { |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3436 | // BuildBinOp already emitted error, this one is to point user to upper |
| 3437 | // and lower bound, and to tell what is passed to 'operator-'. |
| 3438 | SemaRef.Diag(Upper->getLocStart(), diag::err_omp_loop_diff_cxx) |
| 3439 | << Upper->getSourceRange() << Lower->getSourceRange(); |
| 3440 | return nullptr; |
| 3441 | } |
| 3442 | } |
| 3443 | |
| 3444 | if (!Diff.isUsable()) |
| 3445 | return nullptr; |
| 3446 | |
| 3447 | // Upper - Lower [- 1] |
| 3448 | if (TestIsStrictOp) |
| 3449 | Diff = SemaRef.BuildBinOp( |
| 3450 | S, DefaultLoc, BO_Sub, Diff.get(), |
| 3451 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 3452 | if (!Diff.isUsable()) |
| 3453 | return nullptr; |
| 3454 | |
| 3455 | // Upper - Lower [- 1] + Step |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3456 | auto NewStep = Transform.TransformExpr(Step->IgnoreImplicit()); |
| 3457 | if (NewStep.isInvalid()) |
| 3458 | return nullptr; |
| 3459 | NewStep = SemaRef.PerformImplicitConversion( |
| 3460 | NewStep.get(), Step->IgnoreImplicit()->getType(), Sema::AA_Converting, |
| 3461 | /*AllowExplicit=*/true); |
| 3462 | if (NewStep.isInvalid()) |
| 3463 | return nullptr; |
| 3464 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Add, Diff.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3465 | if (!Diff.isUsable()) |
| 3466 | return nullptr; |
| 3467 | |
| 3468 | // Parentheses (for dumping/debugging purposes only). |
| 3469 | Diff = SemaRef.ActOnParenExpr(DefaultLoc, DefaultLoc, Diff.get()); |
| 3470 | if (!Diff.isUsable()) |
| 3471 | return nullptr; |
| 3472 | |
| 3473 | // (Upper - Lower [- 1] + Step) / Step |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3474 | NewStep = Transform.TransformExpr(Step->IgnoreImplicit()); |
| 3475 | if (NewStep.isInvalid()) |
| 3476 | return nullptr; |
| 3477 | NewStep = SemaRef.PerformImplicitConversion( |
| 3478 | NewStep.get(), Step->IgnoreImplicit()->getType(), Sema::AA_Converting, |
| 3479 | /*AllowExplicit=*/true); |
| 3480 | if (NewStep.isInvalid()) |
| 3481 | return nullptr; |
| 3482 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Div, Diff.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3483 | if (!Diff.isUsable()) |
| 3484 | return nullptr; |
| 3485 | |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3486 | // OpenMP runtime requires 32-bit or 64-bit loop variables. |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3487 | QualType Type = Diff.get()->getType(); |
| 3488 | auto &C = SemaRef.Context; |
| 3489 | bool UseVarType = VarType->hasIntegerRepresentation() && |
| 3490 | C.getTypeSize(Type) > C.getTypeSize(VarType); |
| 3491 | if (!Type->isIntegerType() || UseVarType) { |
| 3492 | unsigned NewSize = |
| 3493 | UseVarType ? C.getTypeSize(VarType) : C.getTypeSize(Type); |
| 3494 | bool IsSigned = UseVarType ? VarType->hasSignedIntegerRepresentation() |
| 3495 | : Type->hasSignedIntegerRepresentation(); |
| 3496 | Type = C.getIntTypeForBitwidth(NewSize, IsSigned); |
| 3497 | Diff = SemaRef.PerformImplicitConversion( |
| 3498 | Diff.get(), Type, Sema::AA_Converting, /*AllowExplicit=*/true); |
| 3499 | if (!Diff.isUsable()) |
| 3500 | return nullptr; |
| 3501 | } |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3502 | if (LimitedType) { |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3503 | unsigned NewSize = (C.getTypeSize(Type) > 32) ? 64 : 32; |
| 3504 | if (NewSize != C.getTypeSize(Type)) { |
| 3505 | if (NewSize < C.getTypeSize(Type)) { |
| 3506 | assert(NewSize == 64 && "incorrect loop var size"); |
| 3507 | SemaRef.Diag(DefaultLoc, diag::warn_omp_loop_64_bit_var) |
| 3508 | << InitSrcRange << ConditionSrcRange; |
| 3509 | } |
| 3510 | QualType NewType = C.getIntTypeForBitwidth( |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3511 | NewSize, Type->hasSignedIntegerRepresentation() || |
| 3512 | C.getTypeSize(Type) < NewSize); |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3513 | Diff = SemaRef.PerformImplicitConversion(Diff.get(), NewType, |
| 3514 | Sema::AA_Converting, true); |
| 3515 | if (!Diff.isUsable()) |
| 3516 | return nullptr; |
| 3517 | } |
| 3518 | } |
| 3519 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3520 | return Diff.get(); |
| 3521 | } |
| 3522 | |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3523 | Expr *OpenMPIterationSpaceChecker::BuildPreCond(Scope *S, Expr *Cond) const { |
| 3524 | // Try to build LB <op> UB, where <op> is <, >, <=, or >=. |
| 3525 | bool Suppress = SemaRef.getDiagnostics().getSuppressAllDiagnostics(); |
| 3526 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(/*Val=*/true); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3527 | TransformToNewDefs Transform(SemaRef); |
| 3528 | |
| 3529 | auto NewLB = Transform.TransformExpr(LB); |
| 3530 | auto NewUB = Transform.TransformExpr(UB); |
| 3531 | if (NewLB.isInvalid() || NewUB.isInvalid()) |
| 3532 | return Cond; |
| 3533 | NewLB = SemaRef.PerformImplicitConversion(NewLB.get(), LB->getType(), |
| 3534 | Sema::AA_Converting, |
| 3535 | /*AllowExplicit=*/true); |
| 3536 | NewUB = SemaRef.PerformImplicitConversion(NewUB.get(), UB->getType(), |
| 3537 | Sema::AA_Converting, |
| 3538 | /*AllowExplicit=*/true); |
| 3539 | if (NewLB.isInvalid() || NewUB.isInvalid()) |
| 3540 | return Cond; |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3541 | auto CondExpr = SemaRef.BuildBinOp( |
| 3542 | S, DefaultLoc, TestIsLessOp ? (TestIsStrictOp ? BO_LT : BO_LE) |
| 3543 | : (TestIsStrictOp ? BO_GT : BO_GE), |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3544 | NewLB.get(), NewUB.get()); |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3545 | if (CondExpr.isUsable()) { |
| 3546 | CondExpr = SemaRef.PerformImplicitConversion( |
| 3547 | CondExpr.get(), SemaRef.Context.BoolTy, /*Action=*/Sema::AA_Casting, |
| 3548 | /*AllowExplicit=*/true); |
| 3549 | } |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3550 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(Suppress); |
| 3551 | // Otherwise use original loop conditon and evaluate it in runtime. |
| 3552 | return CondExpr.isUsable() ? CondExpr.get() : Cond; |
| 3553 | } |
| 3554 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3555 | /// \brief Build reference expression to the counter be used for codegen. |
| 3556 | Expr *OpenMPIterationSpaceChecker::BuildCounterVar() const { |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3557 | return buildDeclRefExpr(SemaRef, Var, Var->getType().getNonReferenceType(), |
| 3558 | DefaultLoc); |
| 3559 | } |
| 3560 | |
| 3561 | Expr *OpenMPIterationSpaceChecker::BuildPrivateCounterVar() const { |
| 3562 | if (Var && !Var->isInvalidDecl()) { |
| 3563 | auto Type = Var->getType().getNonReferenceType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 3564 | auto *PrivateVar = |
| 3565 | buildVarDecl(SemaRef, DefaultLoc, Type, Var->getName(), |
| 3566 | Var->hasAttrs() ? &Var->getAttrs() : nullptr); |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3567 | if (PrivateVar->isInvalidDecl()) |
| 3568 | return nullptr; |
| 3569 | return buildDeclRefExpr(SemaRef, PrivateVar, Type, DefaultLoc); |
| 3570 | } |
| 3571 | return nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3572 | } |
| 3573 | |
| 3574 | /// \brief Build initization of the counter be used for codegen. |
| 3575 | Expr *OpenMPIterationSpaceChecker::BuildCounterInit() const { return LB; } |
| 3576 | |
| 3577 | /// \brief Build step of the counter be used for codegen. |
| 3578 | Expr *OpenMPIterationSpaceChecker::BuildCounterStep() const { return Step; } |
| 3579 | |
| 3580 | /// \brief Iteration space of a single for loop. |
| 3581 | struct LoopIterationSpace { |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3582 | /// \brief Condition of the loop. |
| 3583 | Expr *PreCond; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3584 | /// \brief This expression calculates the number of iterations in the loop. |
| 3585 | /// It is always possible to calculate it before starting the loop. |
| 3586 | Expr *NumIterations; |
| 3587 | /// \brief The loop counter variable. |
| 3588 | Expr *CounterVar; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3589 | /// \brief Private loop counter variable. |
| 3590 | Expr *PrivateCounterVar; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3591 | /// \brief This is initializer for the initial value of #CounterVar. |
| 3592 | Expr *CounterInit; |
| 3593 | /// \brief This is step for the #CounterVar used to generate its update: |
| 3594 | /// #CounterVar = #CounterInit + #CounterStep * CurrentIteration. |
| 3595 | Expr *CounterStep; |
| 3596 | /// \brief Should step be subtracted? |
| 3597 | bool Subtract; |
| 3598 | /// \brief Source range of the loop init. |
| 3599 | SourceRange InitSrcRange; |
| 3600 | /// \brief Source range of the loop condition. |
| 3601 | SourceRange CondSrcRange; |
| 3602 | /// \brief Source range of the loop increment. |
| 3603 | SourceRange IncSrcRange; |
| 3604 | }; |
| 3605 | |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 3606 | } // namespace |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3607 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3608 | void Sema::ActOnOpenMPLoopInitialization(SourceLocation ForLoc, Stmt *Init) { |
| 3609 | assert(getLangOpts().OpenMP && "OpenMP is not active."); |
| 3610 | assert(Init && "Expected loop in canonical form."); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 3611 | unsigned AssociatedLoops = DSAStack->getAssociatedLoops(); |
| 3612 | if (AssociatedLoops > 0 && |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3613 | isOpenMPLoopDirective(DSAStack->getCurrentDirective())) { |
| 3614 | OpenMPIterationSpaceChecker ISC(*this, ForLoc); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 3615 | if (!ISC.CheckInit(Init, /*EmitDiags=*/false)) |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3616 | DSAStack->addLoopControlVariable(ISC.GetLoopVar()); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 3617 | DSAStack->setAssociatedLoops(AssociatedLoops - 1); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3618 | } |
| 3619 | } |
| 3620 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3621 | /// \brief Called on a for stmt to check and extract its iteration space |
| 3622 | /// for further processing (such as collapsing). |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3623 | static bool CheckOpenMPIterationSpace( |
| 3624 | OpenMPDirectiveKind DKind, Stmt *S, Sema &SemaRef, DSAStackTy &DSA, |
| 3625 | unsigned CurrentNestedLoopCount, unsigned NestedLoopCount, |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3626 | Expr *CollapseLoopCountExpr, Expr *OrderedLoopCountExpr, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 3627 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3628 | LoopIterationSpace &ResultIterSpace) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3629 | // OpenMP [2.6, Canonical Loop Form] |
| 3630 | // for (init-expr; test-expr; incr-expr) structured-block |
| 3631 | auto For = dyn_cast_or_null<ForStmt>(S); |
| 3632 | if (!For) { |
| 3633 | SemaRef.Diag(S->getLocStart(), diag::err_omp_not_for) |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3634 | << (CollapseLoopCountExpr != nullptr || OrderedLoopCountExpr != nullptr) |
| 3635 | << getOpenMPDirectiveName(DKind) << NestedLoopCount |
| 3636 | << (CurrentNestedLoopCount > 0) << CurrentNestedLoopCount; |
| 3637 | if (NestedLoopCount > 1) { |
| 3638 | if (CollapseLoopCountExpr && OrderedLoopCountExpr) |
| 3639 | SemaRef.Diag(DSA.getConstructLoc(), |
| 3640 | diag::note_omp_collapse_ordered_expr) |
| 3641 | << 2 << CollapseLoopCountExpr->getSourceRange() |
| 3642 | << OrderedLoopCountExpr->getSourceRange(); |
| 3643 | else if (CollapseLoopCountExpr) |
| 3644 | SemaRef.Diag(CollapseLoopCountExpr->getExprLoc(), |
| 3645 | diag::note_omp_collapse_ordered_expr) |
| 3646 | << 0 << CollapseLoopCountExpr->getSourceRange(); |
| 3647 | else |
| 3648 | SemaRef.Diag(OrderedLoopCountExpr->getExprLoc(), |
| 3649 | diag::note_omp_collapse_ordered_expr) |
| 3650 | << 1 << OrderedLoopCountExpr->getSourceRange(); |
| 3651 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3652 | return true; |
| 3653 | } |
| 3654 | assert(For->getBody()); |
| 3655 | |
| 3656 | OpenMPIterationSpaceChecker ISC(SemaRef, For->getForLoc()); |
| 3657 | |
| 3658 | // Check init. |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 3659 | auto Init = For->getInit(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3660 | if (ISC.CheckInit(Init)) { |
| 3661 | return true; |
| 3662 | } |
| 3663 | |
| 3664 | bool HasErrors = false; |
| 3665 | |
| 3666 | // Check loop variable's type. |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 3667 | auto Var = ISC.GetLoopVar(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3668 | |
| 3669 | // OpenMP [2.6, Canonical Loop Form] |
| 3670 | // Var is one of the following: |
| 3671 | // A variable of signed or unsigned integer type. |
| 3672 | // For C++, a variable of a random access iterator type. |
| 3673 | // For C, a variable of a pointer type. |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3674 | auto VarType = Var->getType().getNonReferenceType(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3675 | if (!VarType->isDependentType() && !VarType->isIntegerType() && |
| 3676 | !VarType->isPointerType() && |
| 3677 | !(SemaRef.getLangOpts().CPlusPlus && VarType->isOverloadableType())) { |
| 3678 | SemaRef.Diag(Init->getLocStart(), diag::err_omp_loop_variable_type) |
| 3679 | << SemaRef.getLangOpts().CPlusPlus; |
| 3680 | HasErrors = true; |
| 3681 | } |
| 3682 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3683 | // OpenMP, 2.14.1.1 Data-sharing Attribute Rules for Variables Referenced in a |
| 3684 | // Construct |
| 3685 | // The loop iteration variable(s) in the associated for-loop(s) of a for or |
| 3686 | // parallel for construct is (are) private. |
| 3687 | // The loop iteration variable in the associated for-loop of a simd construct |
| 3688 | // with just one associated for-loop is linear with a constant-linear-step |
| 3689 | // that is the increment of the associated for-loop. |
| 3690 | // Exclude loop var from the list of variables with implicitly defined data |
| 3691 | // sharing attributes. |
Benjamin Kramer | ad8e079 | 2014-10-10 15:32:48 +0000 | [diff] [blame] | 3692 | VarsWithImplicitDSA.erase(Var); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3693 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3694 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced in |
| 3695 | // a Construct, C/C++]. |
Alexey Bataev | cefffae | 2014-06-23 08:21:53 +0000 | [diff] [blame] | 3696 | // The loop iteration variable in the associated for-loop of a simd construct |
| 3697 | // with just one associated for-loop may be listed in a linear clause with a |
| 3698 | // constant-linear-step that is the increment of the associated for-loop. |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3699 | // The loop iteration variable(s) in the associated for-loop(s) of a for or |
| 3700 | // parallel for construct may be listed in a private or lastprivate clause. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 3701 | DSAStackTy::DSAVarData DVar = DSA.getTopDSA(Var, false); |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3702 | auto LoopVarRefExpr = ISC.GetLoopVarRefExpr(); |
| 3703 | // If LoopVarRefExpr is nullptr it means the corresponding loop variable is |
| 3704 | // declared in the loop and it is predetermined as a private. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3705 | auto PredeterminedCKind = |
| 3706 | isOpenMPSimdDirective(DKind) |
| 3707 | ? ((NestedLoopCount == 1) ? OMPC_linear : OMPC_lastprivate) |
| 3708 | : OMPC_private; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3709 | if (((isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown && |
Alexey Bataev | e648e80 | 2015-12-25 13:38:08 +0000 | [diff] [blame] | 3710 | DVar.CKind != PredeterminedCKind) || |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 3711 | ((isOpenMPWorksharingDirective(DKind) || DKind == OMPD_taskloop || |
Alexey Bataev | e648e80 | 2015-12-25 13:38:08 +0000 | [diff] [blame] | 3712 | isOpenMPDistributeDirective(DKind)) && |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 3713 | !isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown && |
Alexey Bataev | e648e80 | 2015-12-25 13:38:08 +0000 | [diff] [blame] | 3714 | DVar.CKind != OMPC_private && DVar.CKind != OMPC_lastprivate)) && |
| 3715 | (DVar.CKind != OMPC_private || DVar.RefExpr != nullptr)) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3716 | SemaRef.Diag(Init->getLocStart(), diag::err_omp_loop_var_dsa) |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3717 | << getOpenMPClauseName(DVar.CKind) << getOpenMPDirectiveName(DKind) |
| 3718 | << getOpenMPClauseName(PredeterminedCKind); |
Alexey Bataev | f2453a0 | 2015-05-06 07:25:08 +0000 | [diff] [blame] | 3719 | if (DVar.RefExpr == nullptr) |
| 3720 | DVar.CKind = PredeterminedCKind; |
| 3721 | ReportOriginalDSA(SemaRef, &DSA, Var, DVar, /*IsLoopIterVar=*/true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3722 | HasErrors = true; |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3723 | } else if (LoopVarRefExpr != nullptr) { |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3724 | // Make the loop iteration variable private (for worksharing constructs), |
| 3725 | // linear (for simd directives with the only one associated loop) or |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3726 | // lastprivate (for simd directives with several collapsed or ordered |
| 3727 | // loops). |
Alexey Bataev | 9aba41c | 2014-11-14 04:08:45 +0000 | [diff] [blame] | 3728 | if (DVar.CKind == OMPC_unknown) |
| 3729 | DVar = DSA.hasDSA(Var, isOpenMPPrivate, MatchesAlways(), |
| 3730 | /*FromParent=*/false); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3731 | DSA.addDSA(Var, LoopVarRefExpr, PredeterminedCKind); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3732 | } |
| 3733 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 3734 | assert(isOpenMPLoopDirective(DKind) && "DSA for non-loop vars"); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 3735 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3736 | // Check test-expr. |
| 3737 | HasErrors |= ISC.CheckCond(For->getCond()); |
| 3738 | |
| 3739 | // Check incr-expr. |
| 3740 | HasErrors |= ISC.CheckInc(For->getInc()); |
| 3741 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3742 | if (ISC.Dependent() || SemaRef.CurContext->isDependentContext() || HasErrors) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3743 | return HasErrors; |
| 3744 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3745 | // Build the loop's iteration space representation. |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3746 | ResultIterSpace.PreCond = ISC.BuildPreCond(DSA.getCurScope(), For->getCond()); |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3747 | ResultIterSpace.NumIterations = ISC.BuildNumIterations( |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 3748 | DSA.getCurScope(), (isOpenMPWorksharingDirective(DKind) || |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 3749 | isOpenMPTaskLoopDirective(DKind) || |
| 3750 | isOpenMPDistributeDirective(DKind))); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3751 | ResultIterSpace.CounterVar = ISC.BuildCounterVar(); |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3752 | ResultIterSpace.PrivateCounterVar = ISC.BuildPrivateCounterVar(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3753 | ResultIterSpace.CounterInit = ISC.BuildCounterInit(); |
| 3754 | ResultIterSpace.CounterStep = ISC.BuildCounterStep(); |
| 3755 | ResultIterSpace.InitSrcRange = ISC.GetInitSrcRange(); |
| 3756 | ResultIterSpace.CondSrcRange = ISC.GetConditionSrcRange(); |
| 3757 | ResultIterSpace.IncSrcRange = ISC.GetIncrementSrcRange(); |
| 3758 | ResultIterSpace.Subtract = ISC.ShouldSubtractStep(); |
| 3759 | |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3760 | HasErrors |= (ResultIterSpace.PreCond == nullptr || |
| 3761 | ResultIterSpace.NumIterations == nullptr || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3762 | ResultIterSpace.CounterVar == nullptr || |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3763 | ResultIterSpace.PrivateCounterVar == nullptr || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3764 | ResultIterSpace.CounterInit == nullptr || |
| 3765 | ResultIterSpace.CounterStep == nullptr); |
| 3766 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3767 | return HasErrors; |
| 3768 | } |
| 3769 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3770 | /// \brief Build 'VarRef = Start. |
| 3771 | static ExprResult BuildCounterInit(Sema &SemaRef, Scope *S, SourceLocation Loc, |
| 3772 | ExprResult VarRef, ExprResult Start) { |
| 3773 | TransformToNewDefs Transform(SemaRef); |
| 3774 | // Build 'VarRef = Start. |
| 3775 | auto NewStart = Transform.TransformExpr(Start.get()->IgnoreImplicit()); |
| 3776 | if (NewStart.isInvalid()) |
| 3777 | return ExprError(); |
| 3778 | NewStart = SemaRef.PerformImplicitConversion( |
| 3779 | NewStart.get(), Start.get()->IgnoreImplicit()->getType(), |
| 3780 | Sema::AA_Converting, |
| 3781 | /*AllowExplicit=*/true); |
| 3782 | if (NewStart.isInvalid()) |
| 3783 | return ExprError(); |
| 3784 | NewStart = SemaRef.PerformImplicitConversion( |
| 3785 | NewStart.get(), VarRef.get()->getType(), Sema::AA_Converting, |
| 3786 | /*AllowExplicit=*/true); |
| 3787 | if (!NewStart.isUsable()) |
| 3788 | return ExprError(); |
| 3789 | |
| 3790 | auto Init = |
| 3791 | SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), NewStart.get()); |
| 3792 | return Init; |
| 3793 | } |
| 3794 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3795 | /// \brief Build 'VarRef = Start + Iter * Step'. |
| 3796 | static ExprResult BuildCounterUpdate(Sema &SemaRef, Scope *S, |
| 3797 | SourceLocation Loc, ExprResult VarRef, |
| 3798 | ExprResult Start, ExprResult Iter, |
| 3799 | ExprResult Step, bool Subtract) { |
| 3800 | // Add parentheses (for debugging purposes only). |
| 3801 | Iter = SemaRef.ActOnParenExpr(Loc, Loc, Iter.get()); |
| 3802 | if (!VarRef.isUsable() || !Start.isUsable() || !Iter.isUsable() || |
| 3803 | !Step.isUsable()) |
| 3804 | return ExprError(); |
| 3805 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3806 | TransformToNewDefs Transform(SemaRef); |
| 3807 | auto NewStep = Transform.TransformExpr(Step.get()->IgnoreImplicit()); |
| 3808 | if (NewStep.isInvalid()) |
| 3809 | return ExprError(); |
| 3810 | NewStep = SemaRef.PerformImplicitConversion( |
| 3811 | NewStep.get(), Step.get()->IgnoreImplicit()->getType(), |
| 3812 | Sema::AA_Converting, |
| 3813 | /*AllowExplicit=*/true); |
| 3814 | if (NewStep.isInvalid()) |
| 3815 | return ExprError(); |
| 3816 | ExprResult Update = |
| 3817 | SemaRef.BuildBinOp(S, Loc, BO_Mul, Iter.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3818 | if (!Update.isUsable()) |
| 3819 | return ExprError(); |
| 3820 | |
| 3821 | // Build 'VarRef = Start + Iter * Step'. |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3822 | auto NewStart = Transform.TransformExpr(Start.get()->IgnoreImplicit()); |
| 3823 | if (NewStart.isInvalid()) |
| 3824 | return ExprError(); |
| 3825 | NewStart = SemaRef.PerformImplicitConversion( |
| 3826 | NewStart.get(), Start.get()->IgnoreImplicit()->getType(), |
| 3827 | Sema::AA_Converting, |
| 3828 | /*AllowExplicit=*/true); |
| 3829 | if (NewStart.isInvalid()) |
| 3830 | return ExprError(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3831 | Update = SemaRef.BuildBinOp(S, Loc, (Subtract ? BO_Sub : BO_Add), |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3832 | NewStart.get(), Update.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3833 | if (!Update.isUsable()) |
| 3834 | return ExprError(); |
| 3835 | |
| 3836 | Update = SemaRef.PerformImplicitConversion( |
| 3837 | Update.get(), VarRef.get()->getType(), Sema::AA_Converting, true); |
| 3838 | if (!Update.isUsable()) |
| 3839 | return ExprError(); |
| 3840 | |
| 3841 | Update = SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), Update.get()); |
| 3842 | return Update; |
| 3843 | } |
| 3844 | |
| 3845 | /// \brief Convert integer expression \a E to make it have at least \a Bits |
| 3846 | /// bits. |
| 3847 | static ExprResult WidenIterationCount(unsigned Bits, Expr *E, |
| 3848 | Sema &SemaRef) { |
| 3849 | if (E == nullptr) |
| 3850 | return ExprError(); |
| 3851 | auto &C = SemaRef.Context; |
| 3852 | QualType OldType = E->getType(); |
| 3853 | unsigned HasBits = C.getTypeSize(OldType); |
| 3854 | if (HasBits >= Bits) |
| 3855 | return ExprResult(E); |
| 3856 | // OK to convert to signed, because new type has more bits than old. |
| 3857 | QualType NewType = C.getIntTypeForBitwidth(Bits, /* Signed */ true); |
| 3858 | return SemaRef.PerformImplicitConversion(E, NewType, Sema::AA_Converting, |
| 3859 | true); |
| 3860 | } |
| 3861 | |
| 3862 | /// \brief Check if the given expression \a E is a constant integer that fits |
| 3863 | /// into \a Bits bits. |
| 3864 | static bool FitsInto(unsigned Bits, bool Signed, Expr *E, Sema &SemaRef) { |
| 3865 | if (E == nullptr) |
| 3866 | return false; |
| 3867 | llvm::APSInt Result; |
| 3868 | if (E->isIntegerConstantExpr(Result, SemaRef.Context)) |
| 3869 | return Signed ? Result.isSignedIntN(Bits) : Result.isIntN(Bits); |
| 3870 | return false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3871 | } |
| 3872 | |
| 3873 | /// \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] | 3874 | /// \return Returns 0 if one of the collapsed stmts is not canonical for loop, |
| 3875 | /// number of collapsed loops otherwise. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3876 | static unsigned |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3877 | CheckOpenMPLoop(OpenMPDirectiveKind DKind, Expr *CollapseLoopCountExpr, |
| 3878 | Expr *OrderedLoopCountExpr, Stmt *AStmt, Sema &SemaRef, |
| 3879 | DSAStackTy &DSA, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 3880 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA, |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3881 | OMPLoopDirective::HelperExprs &Built) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3882 | unsigned NestedLoopCount = 1; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3883 | if (CollapseLoopCountExpr) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3884 | // Found 'collapse' clause - calculate collapse number. |
| 3885 | llvm::APSInt Result; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3886 | if (CollapseLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext())) |
Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 3887 | NestedLoopCount = Result.getLimitedValue(); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3888 | } |
| 3889 | if (OrderedLoopCountExpr) { |
| 3890 | // Found 'ordered' clause - calculate collapse number. |
| 3891 | llvm::APSInt Result; |
Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 3892 | if (OrderedLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext())) { |
| 3893 | if (Result.getLimitedValue() < NestedLoopCount) { |
| 3894 | SemaRef.Diag(OrderedLoopCountExpr->getExprLoc(), |
| 3895 | diag::err_omp_wrong_ordered_loop_count) |
| 3896 | << OrderedLoopCountExpr->getSourceRange(); |
| 3897 | SemaRef.Diag(CollapseLoopCountExpr->getExprLoc(), |
| 3898 | diag::note_collapse_loop_count) |
| 3899 | << CollapseLoopCountExpr->getSourceRange(); |
| 3900 | } |
| 3901 | NestedLoopCount = Result.getLimitedValue(); |
| 3902 | } |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3903 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3904 | // This is helper routine for loop directives (e.g., 'for', 'simd', |
| 3905 | // 'for simd', etc.). |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3906 | SmallVector<LoopIterationSpace, 4> IterSpaces; |
| 3907 | IterSpaces.resize(NestedLoopCount); |
| 3908 | Stmt *CurStmt = AStmt->IgnoreContainers(/* IgnoreCaptured */ true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3909 | for (unsigned Cnt = 0; Cnt < NestedLoopCount; ++Cnt) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3910 | if (CheckOpenMPIterationSpace(DKind, CurStmt, SemaRef, DSA, Cnt, |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3911 | NestedLoopCount, CollapseLoopCountExpr, |
| 3912 | OrderedLoopCountExpr, VarsWithImplicitDSA, |
| 3913 | IterSpaces[Cnt])) |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 3914 | return 0; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3915 | // 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] | 3916 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 3917 | // All loops associated with the construct must be perfectly nested; that |
| 3918 | // is, there must be no intervening code nor any OpenMP directive between |
| 3919 | // any two loops. |
| 3920 | CurStmt = cast<ForStmt>(CurStmt)->getBody()->IgnoreContainers(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3921 | } |
| 3922 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3923 | Built.clear(/* size */ NestedLoopCount); |
| 3924 | |
| 3925 | if (SemaRef.CurContext->isDependentContext()) |
| 3926 | return NestedLoopCount; |
| 3927 | |
| 3928 | // An example of what is generated for the following code: |
| 3929 | // |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3930 | // #pragma omp simd collapse(2) ordered(2) |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3931 | // for (i = 0; i < NI; ++i) |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3932 | // for (k = 0; k < NK; ++k) |
| 3933 | // for (j = J0; j < NJ; j+=2) { |
| 3934 | // <loop body> |
| 3935 | // } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3936 | // |
| 3937 | // We generate the code below. |
| 3938 | // Note: the loop body may be outlined in CodeGen. |
| 3939 | // Note: some counters may be C++ classes, operator- is used to find number of |
| 3940 | // iterations and operator+= to calculate counter value. |
| 3941 | // Note: decltype(NumIterations) must be integer type (in 'omp for', only i32 |
| 3942 | // or i64 is currently supported). |
| 3943 | // |
| 3944 | // #define NumIterations (NI * ((NJ - J0 - 1 + 2) / 2)) |
| 3945 | // for (int[32|64]_t IV = 0; IV < NumIterations; ++IV ) { |
| 3946 | // .local.i = IV / ((NJ - J0 - 1 + 2) / 2); |
| 3947 | // .local.j = J0 + (IV % ((NJ - J0 - 1 + 2) / 2)) * 2; |
| 3948 | // // similar updates for vars in clauses (e.g. 'linear') |
| 3949 | // <loop body (using local i and j)> |
| 3950 | // } |
| 3951 | // i = NI; // assign final values of counters |
| 3952 | // j = NJ; |
| 3953 | // |
| 3954 | |
| 3955 | // Last iteration number is (I1 * I2 * ... In) - 1, where I1, I2 ... In are |
| 3956 | // the iteration counts of the collapsed for loops. |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3957 | // Precondition tests if there is at least one iteration (all conditions are |
| 3958 | // true). |
| 3959 | auto PreCond = ExprResult(IterSpaces[0].PreCond); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3960 | auto N0 = IterSpaces[0].NumIterations; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3961 | ExprResult LastIteration32 = WidenIterationCount( |
| 3962 | 32 /* Bits */, SemaRef.PerformImplicitConversion( |
| 3963 | N0->IgnoreImpCasts(), N0->getType(), |
| 3964 | Sema::AA_Converting, /*AllowExplicit=*/true) |
| 3965 | .get(), |
| 3966 | SemaRef); |
| 3967 | ExprResult LastIteration64 = WidenIterationCount( |
| 3968 | 64 /* Bits */, SemaRef.PerformImplicitConversion( |
| 3969 | N0->IgnoreImpCasts(), N0->getType(), |
| 3970 | Sema::AA_Converting, /*AllowExplicit=*/true) |
| 3971 | .get(), |
| 3972 | SemaRef); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3973 | |
| 3974 | if (!LastIteration32.isUsable() || !LastIteration64.isUsable()) |
| 3975 | return NestedLoopCount; |
| 3976 | |
| 3977 | auto &C = SemaRef.Context; |
| 3978 | bool AllCountsNeedLessThan32Bits = C.getTypeSize(N0->getType()) < 32; |
| 3979 | |
| 3980 | Scope *CurScope = DSA.getCurScope(); |
| 3981 | for (unsigned Cnt = 1; Cnt < NestedLoopCount; ++Cnt) { |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3982 | if (PreCond.isUsable()) { |
| 3983 | PreCond = SemaRef.BuildBinOp(CurScope, SourceLocation(), BO_LAnd, |
| 3984 | PreCond.get(), IterSpaces[Cnt].PreCond); |
| 3985 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3986 | auto N = IterSpaces[Cnt].NumIterations; |
| 3987 | AllCountsNeedLessThan32Bits &= C.getTypeSize(N->getType()) < 32; |
| 3988 | if (LastIteration32.isUsable()) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3989 | LastIteration32 = SemaRef.BuildBinOp( |
| 3990 | CurScope, SourceLocation(), BO_Mul, LastIteration32.get(), |
| 3991 | SemaRef.PerformImplicitConversion(N->IgnoreImpCasts(), N->getType(), |
| 3992 | Sema::AA_Converting, |
| 3993 | /*AllowExplicit=*/true) |
| 3994 | .get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3995 | if (LastIteration64.isUsable()) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3996 | LastIteration64 = SemaRef.BuildBinOp( |
| 3997 | CurScope, SourceLocation(), BO_Mul, LastIteration64.get(), |
| 3998 | SemaRef.PerformImplicitConversion(N->IgnoreImpCasts(), N->getType(), |
| 3999 | Sema::AA_Converting, |
| 4000 | /*AllowExplicit=*/true) |
| 4001 | .get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4002 | } |
| 4003 | |
| 4004 | // Choose either the 32-bit or 64-bit version. |
| 4005 | ExprResult LastIteration = LastIteration64; |
| 4006 | if (LastIteration32.isUsable() && |
| 4007 | C.getTypeSize(LastIteration32.get()->getType()) == 32 && |
| 4008 | (AllCountsNeedLessThan32Bits || NestedLoopCount == 1 || |
| 4009 | FitsInto( |
| 4010 | 32 /* Bits */, |
| 4011 | LastIteration32.get()->getType()->hasSignedIntegerRepresentation(), |
| 4012 | LastIteration64.get(), SemaRef))) |
| 4013 | LastIteration = LastIteration32; |
| 4014 | |
| 4015 | if (!LastIteration.isUsable()) |
| 4016 | return 0; |
| 4017 | |
| 4018 | // Save the number of iterations. |
| 4019 | ExprResult NumIterations = LastIteration; |
| 4020 | { |
| 4021 | LastIteration = SemaRef.BuildBinOp( |
| 4022 | CurScope, SourceLocation(), BO_Sub, LastIteration.get(), |
| 4023 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 4024 | if (!LastIteration.isUsable()) |
| 4025 | return 0; |
| 4026 | } |
| 4027 | |
| 4028 | // Calculate the last iteration number beforehand instead of doing this on |
| 4029 | // each iteration. Do not do this if the number of iterations may be kfold-ed. |
| 4030 | llvm::APSInt Result; |
| 4031 | bool IsConstant = |
| 4032 | LastIteration.get()->isIntegerConstantExpr(Result, SemaRef.Context); |
| 4033 | ExprResult CalcLastIteration; |
| 4034 | if (!IsConstant) { |
| 4035 | SourceLocation SaveLoc; |
| 4036 | VarDecl *SaveVar = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4037 | buildVarDecl(SemaRef, SaveLoc, LastIteration.get()->getType(), |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4038 | ".omp.last.iteration"); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4039 | ExprResult SaveRef = buildDeclRefExpr( |
| 4040 | SemaRef, SaveVar, LastIteration.get()->getType(), SaveLoc); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4041 | CalcLastIteration = SemaRef.BuildBinOp(CurScope, SaveLoc, BO_Assign, |
| 4042 | SaveRef.get(), LastIteration.get()); |
| 4043 | LastIteration = SaveRef; |
| 4044 | |
| 4045 | // Prepare SaveRef + 1. |
| 4046 | NumIterations = SemaRef.BuildBinOp( |
| 4047 | CurScope, SaveLoc, BO_Add, SaveRef.get(), |
| 4048 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 4049 | if (!NumIterations.isUsable()) |
| 4050 | return 0; |
| 4051 | } |
| 4052 | |
| 4053 | SourceLocation InitLoc = IterSpaces[0].InitSrcRange.getBegin(); |
| 4054 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4055 | QualType VType = LastIteration.get()->getType(); |
| 4056 | // Build variables passed into runtime, nesessary for worksharing directives. |
| 4057 | ExprResult LB, UB, IL, ST, EUB; |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 4058 | if (isOpenMPWorksharingDirective(DKind) || isOpenMPTaskLoopDirective(DKind) || |
| 4059 | isOpenMPDistributeDirective(DKind)) { |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4060 | // Lower bound variable, initialized with zero. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4061 | VarDecl *LBDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.lb"); |
| 4062 | LB = buildDeclRefExpr(SemaRef, LBDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4063 | SemaRef.AddInitializerToDecl( |
| 4064 | LBDecl, SemaRef.ActOnIntegerConstant(InitLoc, 0).get(), |
| 4065 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 4066 | |
| 4067 | // Upper bound variable, initialized with last iteration number. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4068 | VarDecl *UBDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.ub"); |
| 4069 | UB = buildDeclRefExpr(SemaRef, UBDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4070 | SemaRef.AddInitializerToDecl(UBDecl, LastIteration.get(), |
| 4071 | /*DirectInit*/ false, |
| 4072 | /*TypeMayContainAuto*/ false); |
| 4073 | |
| 4074 | // A 32-bit variable-flag where runtime returns 1 for the last iteration. |
| 4075 | // This will be used to implement clause 'lastprivate'. |
| 4076 | QualType Int32Ty = SemaRef.Context.getIntTypeForBitwidth(32, true); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4077 | VarDecl *ILDecl = buildVarDecl(SemaRef, InitLoc, Int32Ty, ".omp.is_last"); |
| 4078 | IL = buildDeclRefExpr(SemaRef, ILDecl, Int32Ty, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4079 | SemaRef.AddInitializerToDecl( |
| 4080 | ILDecl, SemaRef.ActOnIntegerConstant(InitLoc, 0).get(), |
| 4081 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 4082 | |
| 4083 | // Stride variable returned by runtime (we initialize it to 1 by default). |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4084 | VarDecl *STDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.stride"); |
| 4085 | ST = buildDeclRefExpr(SemaRef, STDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4086 | SemaRef.AddInitializerToDecl( |
| 4087 | STDecl, SemaRef.ActOnIntegerConstant(InitLoc, 1).get(), |
| 4088 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 4089 | |
| 4090 | // Build expression: UB = min(UB, LastIteration) |
| 4091 | // It is nesessary for CodeGen of directives with static scheduling. |
| 4092 | ExprResult IsUBGreater = SemaRef.BuildBinOp(CurScope, InitLoc, BO_GT, |
| 4093 | UB.get(), LastIteration.get()); |
| 4094 | ExprResult CondOp = SemaRef.ActOnConditionalOp( |
| 4095 | InitLoc, InitLoc, IsUBGreater.get(), LastIteration.get(), UB.get()); |
| 4096 | EUB = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, UB.get(), |
| 4097 | CondOp.get()); |
| 4098 | EUB = SemaRef.ActOnFinishFullExpr(EUB.get()); |
| 4099 | } |
| 4100 | |
| 4101 | // Build the iteration variable and its initialization before loop. |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4102 | ExprResult IV; |
| 4103 | ExprResult Init; |
| 4104 | { |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4105 | VarDecl *IVDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.iv"); |
| 4106 | IV = buildDeclRefExpr(SemaRef, IVDecl, VType, InitLoc); |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 4107 | Expr *RHS = (isOpenMPWorksharingDirective(DKind) || |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 4108 | isOpenMPTaskLoopDirective(DKind) || |
| 4109 | isOpenMPDistributeDirective(DKind)) |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4110 | ? LB.get() |
| 4111 | : SemaRef.ActOnIntegerConstant(SourceLocation(), 0).get(); |
| 4112 | Init = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, IV.get(), RHS); |
| 4113 | Init = SemaRef.ActOnFinishFullExpr(Init.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4114 | } |
| 4115 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4116 | // Loop condition (IV < NumIterations) or (IV <= UB) for worksharing loops. |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4117 | SourceLocation CondLoc; |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4118 | ExprResult Cond = |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 4119 | (isOpenMPWorksharingDirective(DKind) || |
| 4120 | isOpenMPTaskLoopDirective(DKind) || isOpenMPDistributeDirective(DKind)) |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4121 | ? SemaRef.BuildBinOp(CurScope, CondLoc, BO_LE, IV.get(), UB.get()) |
| 4122 | : SemaRef.BuildBinOp(CurScope, CondLoc, BO_LT, IV.get(), |
| 4123 | NumIterations.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4124 | |
| 4125 | // Loop increment (IV = IV + 1) |
| 4126 | SourceLocation IncLoc; |
| 4127 | ExprResult Inc = |
| 4128 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, IV.get(), |
| 4129 | SemaRef.ActOnIntegerConstant(IncLoc, 1).get()); |
| 4130 | if (!Inc.isUsable()) |
| 4131 | return 0; |
| 4132 | Inc = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, IV.get(), Inc.get()); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4133 | Inc = SemaRef.ActOnFinishFullExpr(Inc.get()); |
| 4134 | if (!Inc.isUsable()) |
| 4135 | return 0; |
| 4136 | |
| 4137 | // Increments for worksharing loops (LB = LB + ST; UB = UB + ST). |
| 4138 | // Used for directives with static scheduling. |
| 4139 | ExprResult NextLB, NextUB; |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 4140 | if (isOpenMPWorksharingDirective(DKind) || isOpenMPTaskLoopDirective(DKind) || |
| 4141 | isOpenMPDistributeDirective(DKind)) { |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4142 | // LB + ST |
| 4143 | NextLB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, LB.get(), ST.get()); |
| 4144 | if (!NextLB.isUsable()) |
| 4145 | return 0; |
| 4146 | // LB = LB + ST |
| 4147 | NextLB = |
| 4148 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, LB.get(), NextLB.get()); |
| 4149 | NextLB = SemaRef.ActOnFinishFullExpr(NextLB.get()); |
| 4150 | if (!NextLB.isUsable()) |
| 4151 | return 0; |
| 4152 | // UB + ST |
| 4153 | NextUB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, UB.get(), ST.get()); |
| 4154 | if (!NextUB.isUsable()) |
| 4155 | return 0; |
| 4156 | // UB = UB + ST |
| 4157 | NextUB = |
| 4158 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, UB.get(), NextUB.get()); |
| 4159 | NextUB = SemaRef.ActOnFinishFullExpr(NextUB.get()); |
| 4160 | if (!NextUB.isUsable()) |
| 4161 | return 0; |
| 4162 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4163 | |
| 4164 | // Build updates and final values of the loop counters. |
| 4165 | bool HasErrors = false; |
| 4166 | Built.Counters.resize(NestedLoopCount); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4167 | Built.Inits.resize(NestedLoopCount); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4168 | Built.Updates.resize(NestedLoopCount); |
| 4169 | Built.Finals.resize(NestedLoopCount); |
| 4170 | { |
| 4171 | ExprResult Div; |
| 4172 | // Go from inner nested loop to outer. |
| 4173 | for (int Cnt = NestedLoopCount - 1; Cnt >= 0; --Cnt) { |
| 4174 | LoopIterationSpace &IS = IterSpaces[Cnt]; |
| 4175 | SourceLocation UpdLoc = IS.IncSrcRange.getBegin(); |
| 4176 | // Build: Iter = (IV / Div) % IS.NumIters |
| 4177 | // where Div is product of previous iterations' IS.NumIters. |
| 4178 | ExprResult Iter; |
| 4179 | if (Div.isUsable()) { |
| 4180 | Iter = |
| 4181 | SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Div, IV.get(), Div.get()); |
| 4182 | } else { |
| 4183 | Iter = IV; |
| 4184 | assert((Cnt == (int)NestedLoopCount - 1) && |
| 4185 | "unusable div expected on first iteration only"); |
| 4186 | } |
| 4187 | |
| 4188 | if (Cnt != 0 && Iter.isUsable()) |
| 4189 | Iter = SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Rem, Iter.get(), |
| 4190 | IS.NumIterations); |
| 4191 | if (!Iter.isUsable()) { |
| 4192 | HasErrors = true; |
| 4193 | break; |
| 4194 | } |
| 4195 | |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4196 | // Build update: IS.CounterVar(Private) = IS.Start + Iter * IS.Step |
| 4197 | auto *CounterVar = buildDeclRefExpr( |
| 4198 | SemaRef, cast<VarDecl>(cast<DeclRefExpr>(IS.CounterVar)->getDecl()), |
| 4199 | IS.CounterVar->getType(), IS.CounterVar->getExprLoc(), |
| 4200 | /*RefersToCapture=*/true); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4201 | ExprResult Init = BuildCounterInit(SemaRef, CurScope, UpdLoc, CounterVar, |
| 4202 | IS.CounterInit); |
| 4203 | if (!Init.isUsable()) { |
| 4204 | HasErrors = true; |
| 4205 | break; |
| 4206 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4207 | ExprResult Update = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4208 | BuildCounterUpdate(SemaRef, CurScope, UpdLoc, CounterVar, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4209 | IS.CounterInit, Iter, IS.CounterStep, IS.Subtract); |
| 4210 | if (!Update.isUsable()) { |
| 4211 | HasErrors = true; |
| 4212 | break; |
| 4213 | } |
| 4214 | |
| 4215 | // Build final: IS.CounterVar = IS.Start + IS.NumIters * IS.Step |
| 4216 | ExprResult Final = BuildCounterUpdate( |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4217 | SemaRef, CurScope, UpdLoc, CounterVar, IS.CounterInit, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4218 | IS.NumIterations, IS.CounterStep, IS.Subtract); |
| 4219 | if (!Final.isUsable()) { |
| 4220 | HasErrors = true; |
| 4221 | break; |
| 4222 | } |
| 4223 | |
| 4224 | // Build Div for the next iteration: Div <- Div * IS.NumIters |
| 4225 | if (Cnt != 0) { |
| 4226 | if (Div.isUnset()) |
| 4227 | Div = IS.NumIterations; |
| 4228 | else |
| 4229 | Div = SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Mul, Div.get(), |
| 4230 | IS.NumIterations); |
| 4231 | |
| 4232 | // Add parentheses (for debugging purposes only). |
| 4233 | if (Div.isUsable()) |
| 4234 | Div = SemaRef.ActOnParenExpr(UpdLoc, UpdLoc, Div.get()); |
| 4235 | if (!Div.isUsable()) { |
| 4236 | HasErrors = true; |
| 4237 | break; |
| 4238 | } |
| 4239 | } |
| 4240 | if (!Update.isUsable() || !Final.isUsable()) { |
| 4241 | HasErrors = true; |
| 4242 | break; |
| 4243 | } |
| 4244 | // Save results |
| 4245 | Built.Counters[Cnt] = IS.CounterVar; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 4246 | Built.PrivateCounters[Cnt] = IS.PrivateCounterVar; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4247 | Built.Inits[Cnt] = Init.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4248 | Built.Updates[Cnt] = Update.get(); |
| 4249 | Built.Finals[Cnt] = Final.get(); |
| 4250 | } |
| 4251 | } |
| 4252 | |
| 4253 | if (HasErrors) |
| 4254 | return 0; |
| 4255 | |
| 4256 | // Save results |
| 4257 | Built.IterationVarRef = IV.get(); |
| 4258 | Built.LastIteration = LastIteration.get(); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 4259 | Built.NumIterations = NumIterations.get(); |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 4260 | Built.CalcLastIteration = |
| 4261 | SemaRef.ActOnFinishFullExpr(CalcLastIteration.get()).get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4262 | Built.PreCond = PreCond.get(); |
| 4263 | Built.Cond = Cond.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4264 | Built.Init = Init.get(); |
| 4265 | Built.Inc = Inc.get(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4266 | Built.LB = LB.get(); |
| 4267 | Built.UB = UB.get(); |
| 4268 | Built.IL = IL.get(); |
| 4269 | Built.ST = ST.get(); |
| 4270 | Built.EUB = EUB.get(); |
| 4271 | Built.NLB = NextLB.get(); |
| 4272 | Built.NUB = NextUB.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4273 | |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 4274 | return NestedLoopCount; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4275 | } |
| 4276 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4277 | static Expr *getCollapseNumberExpr(ArrayRef<OMPClause *> Clauses) { |
Benjamin Kramer | fc600dc | 2015-08-30 15:12:28 +0000 | [diff] [blame] | 4278 | auto CollapseClauses = |
| 4279 | OMPExecutableDirective::getClausesOfKind<OMPCollapseClause>(Clauses); |
| 4280 | if (CollapseClauses.begin() != CollapseClauses.end()) |
| 4281 | return (*CollapseClauses.begin())->getNumForLoops(); |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 4282 | return nullptr; |
| 4283 | } |
| 4284 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4285 | static Expr *getOrderedNumberExpr(ArrayRef<OMPClause *> Clauses) { |
Benjamin Kramer | fc600dc | 2015-08-30 15:12:28 +0000 | [diff] [blame] | 4286 | auto OrderedClauses = |
| 4287 | OMPExecutableDirective::getClausesOfKind<OMPOrderedClause>(Clauses); |
| 4288 | if (OrderedClauses.begin() != OrderedClauses.end()) |
| 4289 | return (*OrderedClauses.begin())->getNumForLoops(); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4290 | return nullptr; |
| 4291 | } |
| 4292 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 4293 | static bool checkSimdlenSafelenValues(Sema &S, const Expr *Simdlen, |
| 4294 | const Expr *Safelen) { |
| 4295 | llvm::APSInt SimdlenRes, SafelenRes; |
| 4296 | if (Simdlen->isValueDependent() || Simdlen->isTypeDependent() || |
| 4297 | Simdlen->isInstantiationDependent() || |
| 4298 | Simdlen->containsUnexpandedParameterPack()) |
| 4299 | return false; |
| 4300 | if (Safelen->isValueDependent() || Safelen->isTypeDependent() || |
| 4301 | Safelen->isInstantiationDependent() || |
| 4302 | Safelen->containsUnexpandedParameterPack()) |
| 4303 | return false; |
| 4304 | Simdlen->EvaluateAsInt(SimdlenRes, S.Context); |
| 4305 | Safelen->EvaluateAsInt(SafelenRes, S.Context); |
| 4306 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 4307 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 4308 | // parameter must be less than or equal to the value of the safelen parameter. |
| 4309 | if (SimdlenRes > SafelenRes) { |
| 4310 | S.Diag(Simdlen->getExprLoc(), diag::err_omp_wrong_simdlen_safelen_values) |
| 4311 | << Simdlen->getSourceRange() << Safelen->getSourceRange(); |
| 4312 | return true; |
| 4313 | } |
| 4314 | return false; |
| 4315 | } |
| 4316 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4317 | StmtResult Sema::ActOnOpenMPSimdDirective( |
| 4318 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4319 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 4320 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4321 | if (!AStmt) |
| 4322 | return StmtError(); |
| 4323 | |
| 4324 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4325 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4326 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4327 | // define the nested loops number. |
| 4328 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 4329 | OMPD_simd, getCollapseNumberExpr(Clauses), getOrderedNumberExpr(Clauses), |
| 4330 | AStmt, *this, *DSAStack, VarsWithImplicitDSA, B); |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 4331 | if (NestedLoopCount == 0) |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 4332 | return StmtError(); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 4333 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4334 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 4335 | "omp simd loop exprs were not built"); |
| 4336 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 4337 | if (!CurContext->isDependentContext()) { |
| 4338 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4339 | for (auto C : Clauses) { |
| 4340 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 4341 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 4342 | B.NumIterations, *this, CurScope)) |
| 4343 | return StmtError(); |
| 4344 | } |
| 4345 | } |
| 4346 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 4347 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 4348 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 4349 | // parameter must be less than or equal to the value of the safelen parameter. |
| 4350 | OMPSafelenClause *Safelen = nullptr; |
| 4351 | OMPSimdlenClause *Simdlen = nullptr; |
| 4352 | for (auto *Clause : Clauses) { |
| 4353 | if (Clause->getClauseKind() == OMPC_safelen) |
| 4354 | Safelen = cast<OMPSafelenClause>(Clause); |
| 4355 | else if (Clause->getClauseKind() == OMPC_simdlen) |
| 4356 | Simdlen = cast<OMPSimdlenClause>(Clause); |
| 4357 | if (Safelen && Simdlen) |
| 4358 | break; |
| 4359 | } |
| 4360 | if (Simdlen && Safelen && |
| 4361 | checkSimdlenSafelenValues(*this, Simdlen->getSimdlen(), |
| 4362 | Safelen->getSafelen())) |
| 4363 | return StmtError(); |
| 4364 | |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 4365 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4366 | return OMPSimdDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| 4367 | Clauses, AStmt, B); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 4368 | } |
| 4369 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4370 | StmtResult Sema::ActOnOpenMPForDirective( |
| 4371 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4372 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 4373 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4374 | if (!AStmt) |
| 4375 | return StmtError(); |
| 4376 | |
| 4377 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4378 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4379 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4380 | // define the nested loops number. |
| 4381 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 4382 | OMPD_for, getCollapseNumberExpr(Clauses), getOrderedNumberExpr(Clauses), |
| 4383 | AStmt, *this, *DSAStack, VarsWithImplicitDSA, B); |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 4384 | if (NestedLoopCount == 0) |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4385 | return StmtError(); |
| 4386 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4387 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 4388 | "omp for loop exprs were not built"); |
| 4389 | |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 4390 | if (!CurContext->isDependentContext()) { |
| 4391 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4392 | for (auto C : Clauses) { |
| 4393 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 4394 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 4395 | B.NumIterations, *this, CurScope)) |
| 4396 | return StmtError(); |
| 4397 | } |
| 4398 | } |
| 4399 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4400 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4401 | return OMPForDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4402 | Clauses, AStmt, B, DSAStack->isCancelRegion()); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4403 | } |
| 4404 | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4405 | StmtResult Sema::ActOnOpenMPForSimdDirective( |
| 4406 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4407 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 4408 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4409 | if (!AStmt) |
| 4410 | return StmtError(); |
| 4411 | |
| 4412 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4413 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4414 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4415 | // define the nested loops number. |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4416 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4417 | CheckOpenMPLoop(OMPD_for_simd, getCollapseNumberExpr(Clauses), |
| 4418 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 4419 | VarsWithImplicitDSA, B); |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4420 | if (NestedLoopCount == 0) |
| 4421 | return StmtError(); |
| 4422 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4423 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 4424 | "omp for simd loop exprs were not built"); |
| 4425 | |
Alexey Bataev | 58e5bdb | 2015-06-18 04:45:29 +0000 | [diff] [blame] | 4426 | if (!CurContext->isDependentContext()) { |
| 4427 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4428 | for (auto C : Clauses) { |
| 4429 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 4430 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 4431 | B.NumIterations, *this, CurScope)) |
| 4432 | return StmtError(); |
| 4433 | } |
| 4434 | } |
| 4435 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 4436 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 4437 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 4438 | // parameter must be less than or equal to the value of the safelen parameter. |
| 4439 | OMPSafelenClause *Safelen = nullptr; |
| 4440 | OMPSimdlenClause *Simdlen = nullptr; |
| 4441 | for (auto *Clause : Clauses) { |
| 4442 | if (Clause->getClauseKind() == OMPC_safelen) |
| 4443 | Safelen = cast<OMPSafelenClause>(Clause); |
| 4444 | else if (Clause->getClauseKind() == OMPC_simdlen) |
| 4445 | Simdlen = cast<OMPSimdlenClause>(Clause); |
| 4446 | if (Safelen && Simdlen) |
| 4447 | break; |
| 4448 | } |
| 4449 | if (Simdlen && Safelen && |
| 4450 | checkSimdlenSafelenValues(*this, Simdlen->getSimdlen(), |
| 4451 | Safelen->getSafelen())) |
| 4452 | return StmtError(); |
| 4453 | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4454 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4455 | return OMPForSimdDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| 4456 | Clauses, AStmt, B); |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4457 | } |
| 4458 | |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4459 | StmtResult Sema::ActOnOpenMPSectionsDirective(ArrayRef<OMPClause *> Clauses, |
| 4460 | Stmt *AStmt, |
| 4461 | SourceLocation StartLoc, |
| 4462 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4463 | if (!AStmt) |
| 4464 | return StmtError(); |
| 4465 | |
| 4466 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4467 | auto BaseStmt = AStmt; |
| 4468 | while (CapturedStmt *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt)) |
| 4469 | BaseStmt = CS->getCapturedStmt(); |
| 4470 | if (auto C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) { |
| 4471 | auto S = C->children(); |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 4472 | if (S.begin() == S.end()) |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4473 | return StmtError(); |
| 4474 | // All associated statements must be '#pragma omp section' except for |
| 4475 | // the first one. |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 4476 | for (Stmt *SectionStmt : llvm::make_range(std::next(S.begin()), S.end())) { |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4477 | if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) { |
| 4478 | if (SectionStmt) |
| 4479 | Diag(SectionStmt->getLocStart(), |
| 4480 | diag::err_omp_sections_substmt_not_section); |
| 4481 | return StmtError(); |
| 4482 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4483 | cast<OMPSectionDirective>(SectionStmt) |
| 4484 | ->setHasCancel(DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4485 | } |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4486 | } else { |
| 4487 | Diag(AStmt->getLocStart(), diag::err_omp_sections_not_compound_stmt); |
| 4488 | return StmtError(); |
| 4489 | } |
| 4490 | |
| 4491 | getCurFunction()->setHasBranchProtectedScope(); |
| 4492 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4493 | return OMPSectionsDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 4494 | DSAStack->isCancelRegion()); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4495 | } |
| 4496 | |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4497 | StmtResult Sema::ActOnOpenMPSectionDirective(Stmt *AStmt, |
| 4498 | SourceLocation StartLoc, |
| 4499 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4500 | if (!AStmt) |
| 4501 | return StmtError(); |
| 4502 | |
| 4503 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4504 | |
| 4505 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4506 | DSAStack->setParentCancelRegion(DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4507 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4508 | return OMPSectionDirective::Create(Context, StartLoc, EndLoc, AStmt, |
| 4509 | DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4510 | } |
| 4511 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 4512 | StmtResult Sema::ActOnOpenMPSingleDirective(ArrayRef<OMPClause *> Clauses, |
| 4513 | Stmt *AStmt, |
| 4514 | SourceLocation StartLoc, |
| 4515 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4516 | if (!AStmt) |
| 4517 | return StmtError(); |
| 4518 | |
| 4519 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 74a05c9 | 2014-07-15 02:55:09 +0000 | [diff] [blame] | 4520 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 4521 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | 74a05c9 | 2014-07-15 02:55:09 +0000 | [diff] [blame] | 4522 | |
Alexey Bataev | 3255bf3 | 2015-01-19 05:20:46 +0000 | [diff] [blame] | 4523 | // OpenMP [2.7.3, single Construct, Restrictions] |
| 4524 | // The copyprivate clause must not be used with the nowait clause. |
| 4525 | OMPClause *Nowait = nullptr; |
| 4526 | OMPClause *Copyprivate = nullptr; |
| 4527 | for (auto *Clause : Clauses) { |
| 4528 | if (Clause->getClauseKind() == OMPC_nowait) |
| 4529 | Nowait = Clause; |
| 4530 | else if (Clause->getClauseKind() == OMPC_copyprivate) |
| 4531 | Copyprivate = Clause; |
| 4532 | if (Copyprivate && Nowait) { |
| 4533 | Diag(Copyprivate->getLocStart(), |
| 4534 | diag::err_omp_single_copyprivate_with_nowait); |
| 4535 | Diag(Nowait->getLocStart(), diag::note_omp_nowait_clause_here); |
| 4536 | return StmtError(); |
| 4537 | } |
| 4538 | } |
| 4539 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 4540 | return OMPSingleDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 4541 | } |
| 4542 | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 4543 | StmtResult Sema::ActOnOpenMPMasterDirective(Stmt *AStmt, |
| 4544 | SourceLocation StartLoc, |
| 4545 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4546 | if (!AStmt) |
| 4547 | return StmtError(); |
| 4548 | |
| 4549 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 4550 | |
| 4551 | getCurFunction()->setHasBranchProtectedScope(); |
| 4552 | |
| 4553 | return OMPMasterDirective::Create(Context, StartLoc, EndLoc, AStmt); |
| 4554 | } |
| 4555 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 4556 | StmtResult Sema::ActOnOpenMPCriticalDirective( |
| 4557 | const DeclarationNameInfo &DirName, ArrayRef<OMPClause *> Clauses, |
| 4558 | Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4559 | if (!AStmt) |
| 4560 | return StmtError(); |
| 4561 | |
| 4562 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 4563 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 4564 | bool ErrorFound = false; |
| 4565 | llvm::APSInt Hint; |
| 4566 | SourceLocation HintLoc; |
| 4567 | bool DependentHint = false; |
| 4568 | for (auto *C : Clauses) { |
| 4569 | if (C->getClauseKind() == OMPC_hint) { |
| 4570 | if (!DirName.getName()) { |
| 4571 | Diag(C->getLocStart(), diag::err_omp_hint_clause_no_name); |
| 4572 | ErrorFound = true; |
| 4573 | } |
| 4574 | Expr *E = cast<OMPHintClause>(C)->getHint(); |
| 4575 | if (E->isTypeDependent() || E->isValueDependent() || |
| 4576 | E->isInstantiationDependent()) |
| 4577 | DependentHint = true; |
| 4578 | else { |
| 4579 | Hint = E->EvaluateKnownConstInt(Context); |
| 4580 | HintLoc = C->getLocStart(); |
| 4581 | } |
| 4582 | } |
| 4583 | } |
| 4584 | if (ErrorFound) |
| 4585 | return StmtError(); |
| 4586 | auto Pair = DSAStack->getCriticalWithHint(DirName); |
| 4587 | if (Pair.first && DirName.getName() && !DependentHint) { |
| 4588 | if (llvm::APSInt::compareValues(Hint, Pair.second) != 0) { |
| 4589 | Diag(StartLoc, diag::err_omp_critical_with_hint); |
| 4590 | if (HintLoc.isValid()) { |
| 4591 | Diag(HintLoc, diag::note_omp_critical_hint_here) |
| 4592 | << 0 << Hint.toString(/*Radix=*/10, /*Signed=*/false); |
| 4593 | } else |
| 4594 | Diag(StartLoc, diag::note_omp_critical_no_hint) << 0; |
| 4595 | if (auto *C = Pair.first->getSingleClause<OMPHintClause>()) { |
| 4596 | Diag(C->getLocStart(), diag::note_omp_critical_hint_here) |
| 4597 | << 1 |
| 4598 | << C->getHint()->EvaluateKnownConstInt(Context).toString( |
| 4599 | /*Radix=*/10, /*Signed=*/false); |
| 4600 | } else |
| 4601 | Diag(Pair.first->getLocStart(), diag::note_omp_critical_no_hint) << 1; |
| 4602 | } |
| 4603 | } |
| 4604 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 4605 | getCurFunction()->setHasBranchProtectedScope(); |
| 4606 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 4607 | auto *Dir = OMPCriticalDirective::Create(Context, DirName, StartLoc, EndLoc, |
| 4608 | Clauses, AStmt); |
| 4609 | if (!Pair.first && DirName.getName() && !DependentHint) |
| 4610 | DSAStack->addCriticalWithHint(Dir, Hint); |
| 4611 | return Dir; |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 4612 | } |
| 4613 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4614 | StmtResult Sema::ActOnOpenMPParallelForDirective( |
| 4615 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4616 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 4617 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4618 | if (!AStmt) |
| 4619 | return StmtError(); |
| 4620 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4621 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 4622 | // 1.2.2 OpenMP Language Terminology |
| 4623 | // Structured block - An executable statement with a single entry at the |
| 4624 | // top and a single exit at the bottom. |
| 4625 | // The point of exit cannot be a branch out of the structured block. |
| 4626 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 4627 | CS->getCapturedDecl()->setNothrow(); |
| 4628 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4629 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4630 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4631 | // define the nested loops number. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4632 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4633 | CheckOpenMPLoop(OMPD_parallel_for, getCollapseNumberExpr(Clauses), |
| 4634 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 4635 | VarsWithImplicitDSA, B); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4636 | if (NestedLoopCount == 0) |
| 4637 | return StmtError(); |
| 4638 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4639 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 4640 | "omp parallel for loop exprs were not built"); |
| 4641 | |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 4642 | if (!CurContext->isDependentContext()) { |
| 4643 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4644 | for (auto C : Clauses) { |
| 4645 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 4646 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 4647 | B.NumIterations, *this, CurScope)) |
| 4648 | return StmtError(); |
| 4649 | } |
| 4650 | } |
| 4651 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4652 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4653 | return OMPParallelForDirective::Create(Context, StartLoc, EndLoc, |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4654 | NestedLoopCount, Clauses, AStmt, B, |
| 4655 | DSAStack->isCancelRegion()); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4656 | } |
| 4657 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4658 | StmtResult Sema::ActOnOpenMPParallelForSimdDirective( |
| 4659 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4660 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 4661 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4662 | if (!AStmt) |
| 4663 | return StmtError(); |
| 4664 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4665 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 4666 | // 1.2.2 OpenMP Language Terminology |
| 4667 | // Structured block - An executable statement with a single entry at the |
| 4668 | // top and a single exit at the bottom. |
| 4669 | // The point of exit cannot be a branch out of the structured block. |
| 4670 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 4671 | CS->getCapturedDecl()->setNothrow(); |
| 4672 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4673 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4674 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4675 | // define the nested loops number. |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4676 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4677 | CheckOpenMPLoop(OMPD_parallel_for_simd, getCollapseNumberExpr(Clauses), |
| 4678 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 4679 | VarsWithImplicitDSA, B); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4680 | if (NestedLoopCount == 0) |
| 4681 | return StmtError(); |
| 4682 | |
Alexey Bataev | 3b5b5c4 | 2015-06-18 10:10:12 +0000 | [diff] [blame] | 4683 | if (!CurContext->isDependentContext()) { |
| 4684 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4685 | for (auto C : Clauses) { |
| 4686 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 4687 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 4688 | B.NumIterations, *this, CurScope)) |
| 4689 | return StmtError(); |
| 4690 | } |
| 4691 | } |
| 4692 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 4693 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 4694 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 4695 | // parameter must be less than or equal to the value of the safelen parameter. |
| 4696 | OMPSafelenClause *Safelen = nullptr; |
| 4697 | OMPSimdlenClause *Simdlen = nullptr; |
| 4698 | for (auto *Clause : Clauses) { |
| 4699 | if (Clause->getClauseKind() == OMPC_safelen) |
| 4700 | Safelen = cast<OMPSafelenClause>(Clause); |
| 4701 | else if (Clause->getClauseKind() == OMPC_simdlen) |
| 4702 | Simdlen = cast<OMPSimdlenClause>(Clause); |
| 4703 | if (Safelen && Simdlen) |
| 4704 | break; |
| 4705 | } |
| 4706 | if (Simdlen && Safelen && |
| 4707 | checkSimdlenSafelenValues(*this, Simdlen->getSimdlen(), |
| 4708 | Safelen->getSafelen())) |
| 4709 | return StmtError(); |
| 4710 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4711 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4712 | return OMPParallelForSimdDirective::Create( |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4713 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4714 | } |
| 4715 | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4716 | StmtResult |
| 4717 | Sema::ActOnOpenMPParallelSectionsDirective(ArrayRef<OMPClause *> Clauses, |
| 4718 | Stmt *AStmt, SourceLocation StartLoc, |
| 4719 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4720 | if (!AStmt) |
| 4721 | return StmtError(); |
| 4722 | |
| 4723 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4724 | auto BaseStmt = AStmt; |
| 4725 | while (CapturedStmt *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt)) |
| 4726 | BaseStmt = CS->getCapturedStmt(); |
| 4727 | if (auto C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) { |
| 4728 | auto S = C->children(); |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 4729 | if (S.begin() == S.end()) |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4730 | return StmtError(); |
| 4731 | // All associated statements must be '#pragma omp section' except for |
| 4732 | // the first one. |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 4733 | for (Stmt *SectionStmt : llvm::make_range(std::next(S.begin()), S.end())) { |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4734 | if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) { |
| 4735 | if (SectionStmt) |
| 4736 | Diag(SectionStmt->getLocStart(), |
| 4737 | diag::err_omp_parallel_sections_substmt_not_section); |
| 4738 | return StmtError(); |
| 4739 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4740 | cast<OMPSectionDirective>(SectionStmt) |
| 4741 | ->setHasCancel(DSAStack->isCancelRegion()); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4742 | } |
| 4743 | } else { |
| 4744 | Diag(AStmt->getLocStart(), |
| 4745 | diag::err_omp_parallel_sections_not_compound_stmt); |
| 4746 | return StmtError(); |
| 4747 | } |
| 4748 | |
| 4749 | getCurFunction()->setHasBranchProtectedScope(); |
| 4750 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4751 | return OMPParallelSectionsDirective::Create( |
| 4752 | Context, StartLoc, EndLoc, Clauses, AStmt, DSAStack->isCancelRegion()); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4753 | } |
| 4754 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 4755 | StmtResult Sema::ActOnOpenMPTaskDirective(ArrayRef<OMPClause *> Clauses, |
| 4756 | Stmt *AStmt, SourceLocation StartLoc, |
| 4757 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4758 | if (!AStmt) |
| 4759 | return StmtError(); |
| 4760 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 4761 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 4762 | // 1.2.2 OpenMP Language Terminology |
| 4763 | // Structured block - An executable statement with a single entry at the |
| 4764 | // top and a single exit at the bottom. |
| 4765 | // The point of exit cannot be a branch out of the structured block. |
| 4766 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 4767 | CS->getCapturedDecl()->setNothrow(); |
| 4768 | |
| 4769 | getCurFunction()->setHasBranchProtectedScope(); |
| 4770 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4771 | return OMPTaskDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 4772 | DSAStack->isCancelRegion()); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 4773 | } |
| 4774 | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 4775 | StmtResult Sema::ActOnOpenMPTaskyieldDirective(SourceLocation StartLoc, |
| 4776 | SourceLocation EndLoc) { |
| 4777 | return OMPTaskyieldDirective::Create(Context, StartLoc, EndLoc); |
| 4778 | } |
| 4779 | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 4780 | StmtResult Sema::ActOnOpenMPBarrierDirective(SourceLocation StartLoc, |
| 4781 | SourceLocation EndLoc) { |
| 4782 | return OMPBarrierDirective::Create(Context, StartLoc, EndLoc); |
| 4783 | } |
| 4784 | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 4785 | StmtResult Sema::ActOnOpenMPTaskwaitDirective(SourceLocation StartLoc, |
| 4786 | SourceLocation EndLoc) { |
| 4787 | return OMPTaskwaitDirective::Create(Context, StartLoc, EndLoc); |
| 4788 | } |
| 4789 | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 4790 | StmtResult Sema::ActOnOpenMPTaskgroupDirective(Stmt *AStmt, |
| 4791 | SourceLocation StartLoc, |
| 4792 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4793 | if (!AStmt) |
| 4794 | return StmtError(); |
| 4795 | |
| 4796 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 4797 | |
| 4798 | getCurFunction()->setHasBranchProtectedScope(); |
| 4799 | |
| 4800 | return OMPTaskgroupDirective::Create(Context, StartLoc, EndLoc, AStmt); |
| 4801 | } |
| 4802 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 4803 | StmtResult Sema::ActOnOpenMPFlushDirective(ArrayRef<OMPClause *> Clauses, |
| 4804 | SourceLocation StartLoc, |
| 4805 | SourceLocation EndLoc) { |
| 4806 | assert(Clauses.size() <= 1 && "Extra clauses in flush directive"); |
| 4807 | return OMPFlushDirective::Create(Context, StartLoc, EndLoc, Clauses); |
| 4808 | } |
| 4809 | |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 4810 | StmtResult Sema::ActOnOpenMPOrderedDirective(ArrayRef<OMPClause *> Clauses, |
| 4811 | Stmt *AStmt, |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 4812 | SourceLocation StartLoc, |
| 4813 | SourceLocation EndLoc) { |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 4814 | OMPClause *DependFound = nullptr; |
| 4815 | OMPClause *DependSourceClause = nullptr; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 4816 | OMPClause *DependSinkClause = nullptr; |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 4817 | bool ErrorFound = false; |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 4818 | OMPThreadsClause *TC = nullptr; |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 4819 | OMPSIMDClause *SC = nullptr; |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 4820 | for (auto *C : Clauses) { |
| 4821 | if (auto *DC = dyn_cast<OMPDependClause>(C)) { |
| 4822 | DependFound = C; |
| 4823 | if (DC->getDependencyKind() == OMPC_DEPEND_source) { |
| 4824 | if (DependSourceClause) { |
| 4825 | Diag(C->getLocStart(), diag::err_omp_more_one_clause) |
| 4826 | << getOpenMPDirectiveName(OMPD_ordered) |
| 4827 | << getOpenMPClauseName(OMPC_depend) << 2; |
| 4828 | ErrorFound = true; |
| 4829 | } else |
| 4830 | DependSourceClause = C; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 4831 | if (DependSinkClause) { |
| 4832 | Diag(C->getLocStart(), diag::err_omp_depend_sink_source_not_allowed) |
| 4833 | << 0; |
| 4834 | ErrorFound = true; |
| 4835 | } |
| 4836 | } else if (DC->getDependencyKind() == OMPC_DEPEND_sink) { |
| 4837 | if (DependSourceClause) { |
| 4838 | Diag(C->getLocStart(), diag::err_omp_depend_sink_source_not_allowed) |
| 4839 | << 1; |
| 4840 | ErrorFound = true; |
| 4841 | } |
| 4842 | DependSinkClause = C; |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 4843 | } |
| 4844 | } else if (C->getClauseKind() == OMPC_threads) |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 4845 | TC = cast<OMPThreadsClause>(C); |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 4846 | else if (C->getClauseKind() == OMPC_simd) |
| 4847 | SC = cast<OMPSIMDClause>(C); |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 4848 | } |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 4849 | if (!ErrorFound && !SC && |
| 4850 | isOpenMPSimdDirective(DSAStack->getParentDirective())) { |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 4851 | // OpenMP [2.8.1,simd Construct, Restrictions] |
| 4852 | // An ordered construct with the simd clause is the only OpenMP construct |
| 4853 | // that can appear in the simd region. |
| 4854 | Diag(StartLoc, diag::err_omp_prohibited_region_simd); |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 4855 | ErrorFound = true; |
| 4856 | } else if (DependFound && (TC || SC)) { |
| 4857 | Diag(DependFound->getLocStart(), diag::err_omp_depend_clause_thread_simd) |
| 4858 | << getOpenMPClauseName(TC ? TC->getClauseKind() : SC->getClauseKind()); |
| 4859 | ErrorFound = true; |
| 4860 | } else if (DependFound && !DSAStack->getParentOrderedRegionParam()) { |
| 4861 | Diag(DependFound->getLocStart(), |
| 4862 | diag::err_omp_ordered_directive_without_param); |
| 4863 | ErrorFound = true; |
| 4864 | } else if (TC || Clauses.empty()) { |
| 4865 | if (auto *Param = DSAStack->getParentOrderedRegionParam()) { |
| 4866 | SourceLocation ErrLoc = TC ? TC->getLocStart() : StartLoc; |
| 4867 | Diag(ErrLoc, diag::err_omp_ordered_directive_with_param) |
| 4868 | << (TC != nullptr); |
| 4869 | Diag(Param->getLocStart(), diag::note_omp_ordered_param); |
| 4870 | ErrorFound = true; |
| 4871 | } |
| 4872 | } |
| 4873 | if ((!AStmt && !DependFound) || ErrorFound) |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 4874 | return StmtError(); |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 4875 | |
| 4876 | if (AStmt) { |
| 4877 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 4878 | |
| 4879 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 4880 | } |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 4881 | |
| 4882 | return OMPOrderedDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 4883 | } |
| 4884 | |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4885 | namespace { |
| 4886 | /// \brief Helper class for checking expression in 'omp atomic [update]' |
| 4887 | /// construct. |
| 4888 | class OpenMPAtomicUpdateChecker { |
| 4889 | /// \brief Error results for atomic update expressions. |
| 4890 | enum ExprAnalysisErrorCode { |
| 4891 | /// \brief A statement is not an expression statement. |
| 4892 | NotAnExpression, |
| 4893 | /// \brief Expression is not builtin binary or unary operation. |
| 4894 | NotABinaryOrUnaryExpression, |
| 4895 | /// \brief Unary operation is not post-/pre- increment/decrement operation. |
| 4896 | NotAnUnaryIncDecExpression, |
| 4897 | /// \brief An expression is not of scalar type. |
| 4898 | NotAScalarType, |
| 4899 | /// \brief A binary operation is not an assignment operation. |
| 4900 | NotAnAssignmentOp, |
| 4901 | /// \brief RHS part of the binary operation is not a binary expression. |
| 4902 | NotABinaryExpression, |
| 4903 | /// \brief RHS part is not additive/multiplicative/shift/biwise binary |
| 4904 | /// expression. |
| 4905 | NotABinaryOperator, |
| 4906 | /// \brief RHS binary operation does not have reference to the updated LHS |
| 4907 | /// part. |
| 4908 | NotAnUpdateExpression, |
| 4909 | /// \brief No errors is found. |
| 4910 | NoError |
| 4911 | }; |
| 4912 | /// \brief Reference to Sema. |
| 4913 | Sema &SemaRef; |
| 4914 | /// \brief A location for note diagnostics (when error is found). |
| 4915 | SourceLocation NoteLoc; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4916 | /// \brief 'x' lvalue part of the source atomic expression. |
| 4917 | Expr *X; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4918 | /// \brief 'expr' rvalue part of the source atomic expression. |
| 4919 | Expr *E; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4920 | /// \brief Helper expression of the form |
| 4921 | /// 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or |
| 4922 | /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'. |
| 4923 | Expr *UpdateExpr; |
| 4924 | /// \brief Is 'x' a LHS in a RHS part of full update expression. It is |
| 4925 | /// important for non-associative operations. |
| 4926 | bool IsXLHSInRHSPart; |
| 4927 | BinaryOperatorKind Op; |
| 4928 | SourceLocation OpLoc; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4929 | /// \brief true if the source expression is a postfix unary operation, false |
| 4930 | /// if it is a prefix unary operation. |
| 4931 | bool IsPostfixUpdate; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4932 | |
| 4933 | public: |
| 4934 | OpenMPAtomicUpdateChecker(Sema &SemaRef) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4935 | : SemaRef(SemaRef), X(nullptr), E(nullptr), UpdateExpr(nullptr), |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4936 | IsXLHSInRHSPart(false), Op(BO_PtrMemD), IsPostfixUpdate(false) {} |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4937 | /// \brief Check specified statement that it is suitable for 'atomic update' |
| 4938 | /// constructs and extract 'x', 'expr' and Operation from the original |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4939 | /// expression. If DiagId and NoteId == 0, then only check is performed |
| 4940 | /// without error notification. |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4941 | /// \param DiagId Diagnostic which should be emitted if error is found. |
| 4942 | /// \param NoteId Diagnostic note for the main error message. |
| 4943 | /// \return true if statement is not an update expression, false otherwise. |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4944 | bool checkStatement(Stmt *S, unsigned DiagId = 0, unsigned NoteId = 0); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4945 | /// \brief Return the 'x' lvalue part of the source atomic expression. |
| 4946 | Expr *getX() const { return X; } |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4947 | /// \brief Return the 'expr' rvalue part of the source atomic expression. |
| 4948 | Expr *getExpr() const { return E; } |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4949 | /// \brief Return the update expression used in calculation of the updated |
| 4950 | /// value. Always has form 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or |
| 4951 | /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'. |
| 4952 | Expr *getUpdateExpr() const { return UpdateExpr; } |
| 4953 | /// \brief Return true if 'x' is LHS in RHS part of full update expression, |
| 4954 | /// false otherwise. |
| 4955 | bool isXLHSInRHSPart() const { return IsXLHSInRHSPart; } |
| 4956 | |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4957 | /// \brief true if the source expression is a postfix unary operation, false |
| 4958 | /// if it is a prefix unary operation. |
| 4959 | bool isPostfixUpdate() const { return IsPostfixUpdate; } |
| 4960 | |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4961 | private: |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4962 | bool checkBinaryOperation(BinaryOperator *AtomicBinOp, unsigned DiagId = 0, |
| 4963 | unsigned NoteId = 0); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4964 | }; |
| 4965 | } // namespace |
| 4966 | |
| 4967 | bool OpenMPAtomicUpdateChecker::checkBinaryOperation( |
| 4968 | BinaryOperator *AtomicBinOp, unsigned DiagId, unsigned NoteId) { |
| 4969 | ExprAnalysisErrorCode ErrorFound = NoError; |
| 4970 | SourceLocation ErrorLoc, NoteLoc; |
| 4971 | SourceRange ErrorRange, NoteRange; |
| 4972 | // Allowed constructs are: |
| 4973 | // x = x binop expr; |
| 4974 | // x = expr binop x; |
| 4975 | if (AtomicBinOp->getOpcode() == BO_Assign) { |
| 4976 | X = AtomicBinOp->getLHS(); |
| 4977 | if (auto *AtomicInnerBinOp = dyn_cast<BinaryOperator>( |
| 4978 | AtomicBinOp->getRHS()->IgnoreParenImpCasts())) { |
| 4979 | if (AtomicInnerBinOp->isMultiplicativeOp() || |
| 4980 | AtomicInnerBinOp->isAdditiveOp() || AtomicInnerBinOp->isShiftOp() || |
| 4981 | AtomicInnerBinOp->isBitwiseOp()) { |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4982 | Op = AtomicInnerBinOp->getOpcode(); |
| 4983 | OpLoc = AtomicInnerBinOp->getOperatorLoc(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4984 | auto *LHS = AtomicInnerBinOp->getLHS(); |
| 4985 | auto *RHS = AtomicInnerBinOp->getRHS(); |
| 4986 | llvm::FoldingSetNodeID XId, LHSId, RHSId; |
| 4987 | X->IgnoreParenImpCasts()->Profile(XId, SemaRef.getASTContext(), |
| 4988 | /*Canonical=*/true); |
| 4989 | LHS->IgnoreParenImpCasts()->Profile(LHSId, SemaRef.getASTContext(), |
| 4990 | /*Canonical=*/true); |
| 4991 | RHS->IgnoreParenImpCasts()->Profile(RHSId, SemaRef.getASTContext(), |
| 4992 | /*Canonical=*/true); |
| 4993 | if (XId == LHSId) { |
| 4994 | E = RHS; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4995 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4996 | } else if (XId == RHSId) { |
| 4997 | E = LHS; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4998 | IsXLHSInRHSPart = false; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4999 | } else { |
| 5000 | ErrorLoc = AtomicInnerBinOp->getExprLoc(); |
| 5001 | ErrorRange = AtomicInnerBinOp->getSourceRange(); |
| 5002 | NoteLoc = X->getExprLoc(); |
| 5003 | NoteRange = X->getSourceRange(); |
| 5004 | ErrorFound = NotAnUpdateExpression; |
| 5005 | } |
| 5006 | } else { |
| 5007 | ErrorLoc = AtomicInnerBinOp->getExprLoc(); |
| 5008 | ErrorRange = AtomicInnerBinOp->getSourceRange(); |
| 5009 | NoteLoc = AtomicInnerBinOp->getOperatorLoc(); |
| 5010 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 5011 | ErrorFound = NotABinaryOperator; |
| 5012 | } |
| 5013 | } else { |
| 5014 | NoteLoc = ErrorLoc = AtomicBinOp->getRHS()->getExprLoc(); |
| 5015 | NoteRange = ErrorRange = AtomicBinOp->getRHS()->getSourceRange(); |
| 5016 | ErrorFound = NotABinaryExpression; |
| 5017 | } |
| 5018 | } else { |
| 5019 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5020 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5021 | NoteLoc = AtomicBinOp->getOperatorLoc(); |
| 5022 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 5023 | ErrorFound = NotAnAssignmentOp; |
| 5024 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5025 | if (ErrorFound != NoError && DiagId != 0 && NoteId != 0) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5026 | SemaRef.Diag(ErrorLoc, DiagId) << ErrorRange; |
| 5027 | SemaRef.Diag(NoteLoc, NoteId) << ErrorFound << NoteRange; |
| 5028 | return true; |
| 5029 | } else if (SemaRef.CurContext->isDependentContext()) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5030 | E = X = UpdateExpr = nullptr; |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5031 | return ErrorFound != NoError; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5032 | } |
| 5033 | |
| 5034 | bool OpenMPAtomicUpdateChecker::checkStatement(Stmt *S, unsigned DiagId, |
| 5035 | unsigned NoteId) { |
| 5036 | ExprAnalysisErrorCode ErrorFound = NoError; |
| 5037 | SourceLocation ErrorLoc, NoteLoc; |
| 5038 | SourceRange ErrorRange, NoteRange; |
| 5039 | // Allowed constructs are: |
| 5040 | // x++; |
| 5041 | // x--; |
| 5042 | // ++x; |
| 5043 | // --x; |
| 5044 | // x binop= expr; |
| 5045 | // x = x binop expr; |
| 5046 | // x = expr binop x; |
| 5047 | if (auto *AtomicBody = dyn_cast<Expr>(S)) { |
| 5048 | AtomicBody = AtomicBody->IgnoreParenImpCasts(); |
| 5049 | if (AtomicBody->getType()->isScalarType() || |
| 5050 | AtomicBody->isInstantiationDependent()) { |
| 5051 | if (auto *AtomicCompAssignOp = dyn_cast<CompoundAssignOperator>( |
| 5052 | AtomicBody->IgnoreParenImpCasts())) { |
| 5053 | // Check for Compound Assignment Operation |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5054 | Op = BinaryOperator::getOpForCompoundAssignment( |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5055 | AtomicCompAssignOp->getOpcode()); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5056 | OpLoc = AtomicCompAssignOp->getOperatorLoc(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5057 | E = AtomicCompAssignOp->getRHS(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5058 | X = AtomicCompAssignOp->getLHS(); |
| 5059 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5060 | } else if (auto *AtomicBinOp = dyn_cast<BinaryOperator>( |
| 5061 | AtomicBody->IgnoreParenImpCasts())) { |
| 5062 | // Check for Binary Operation |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5063 | if(checkBinaryOperation(AtomicBinOp, DiagId, NoteId)) |
| 5064 | return true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5065 | } else if (auto *AtomicUnaryOp = |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5066 | dyn_cast<UnaryOperator>(AtomicBody->IgnoreParenImpCasts())) { |
| 5067 | // Check for Unary Operation |
| 5068 | if (AtomicUnaryOp->isIncrementDecrementOp()) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5069 | IsPostfixUpdate = AtomicUnaryOp->isPostfix(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5070 | Op = AtomicUnaryOp->isIncrementOp() ? BO_Add : BO_Sub; |
| 5071 | OpLoc = AtomicUnaryOp->getOperatorLoc(); |
| 5072 | X = AtomicUnaryOp->getSubExpr(); |
| 5073 | E = SemaRef.ActOnIntegerConstant(OpLoc, /*uint64_t Val=*/1).get(); |
| 5074 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5075 | } else { |
| 5076 | ErrorFound = NotAnUnaryIncDecExpression; |
| 5077 | ErrorLoc = AtomicUnaryOp->getExprLoc(); |
| 5078 | ErrorRange = AtomicUnaryOp->getSourceRange(); |
| 5079 | NoteLoc = AtomicUnaryOp->getOperatorLoc(); |
| 5080 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 5081 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5082 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5083 | ErrorFound = NotABinaryOrUnaryExpression; |
| 5084 | NoteLoc = ErrorLoc = AtomicBody->getExprLoc(); |
| 5085 | NoteRange = ErrorRange = AtomicBody->getSourceRange(); |
| 5086 | } |
| 5087 | } else { |
| 5088 | ErrorFound = NotAScalarType; |
| 5089 | NoteLoc = ErrorLoc = AtomicBody->getLocStart(); |
| 5090 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
| 5091 | } |
| 5092 | } else { |
| 5093 | ErrorFound = NotAnExpression; |
| 5094 | NoteLoc = ErrorLoc = S->getLocStart(); |
| 5095 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
| 5096 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5097 | if (ErrorFound != NoError && DiagId != 0 && NoteId != 0) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5098 | SemaRef.Diag(ErrorLoc, DiagId) << ErrorRange; |
| 5099 | SemaRef.Diag(NoteLoc, NoteId) << ErrorFound << NoteRange; |
| 5100 | return true; |
| 5101 | } else if (SemaRef.CurContext->isDependentContext()) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5102 | E = X = UpdateExpr = nullptr; |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5103 | if (ErrorFound == NoError && E && X) { |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5104 | // Build an update expression of form 'OpaqueValueExpr(x) binop |
| 5105 | // OpaqueValueExpr(expr)' or 'OpaqueValueExpr(expr) binop |
| 5106 | // OpaqueValueExpr(x)' and then cast it to the type of the 'x' expression. |
| 5107 | auto *OVEX = new (SemaRef.getASTContext()) |
| 5108 | OpaqueValueExpr(X->getExprLoc(), X->getType(), VK_RValue); |
| 5109 | auto *OVEExpr = new (SemaRef.getASTContext()) |
| 5110 | OpaqueValueExpr(E->getExprLoc(), E->getType(), VK_RValue); |
| 5111 | auto Update = |
| 5112 | SemaRef.CreateBuiltinBinOp(OpLoc, Op, IsXLHSInRHSPart ? OVEX : OVEExpr, |
| 5113 | IsXLHSInRHSPart ? OVEExpr : OVEX); |
| 5114 | if (Update.isInvalid()) |
| 5115 | return true; |
| 5116 | Update = SemaRef.PerformImplicitConversion(Update.get(), X->getType(), |
| 5117 | Sema::AA_Casting); |
| 5118 | if (Update.isInvalid()) |
| 5119 | return true; |
| 5120 | UpdateExpr = Update.get(); |
| 5121 | } |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5122 | return ErrorFound != NoError; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5123 | } |
| 5124 | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 5125 | StmtResult Sema::ActOnOpenMPAtomicDirective(ArrayRef<OMPClause *> Clauses, |
| 5126 | Stmt *AStmt, |
| 5127 | SourceLocation StartLoc, |
| 5128 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5129 | if (!AStmt) |
| 5130 | return StmtError(); |
| 5131 | |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5132 | auto CS = cast<CapturedStmt>(AStmt); |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 5133 | // 1.2.2 OpenMP Language Terminology |
| 5134 | // Structured block - An executable statement with a single entry at the |
| 5135 | // top and a single exit at the bottom. |
| 5136 | // The point of exit cannot be a branch out of the structured block. |
| 5137 | // longjmp() and throw() must not violate the entry/exit criteria. |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5138 | OpenMPClauseKind AtomicKind = OMPC_unknown; |
| 5139 | SourceLocation AtomicKindLoc; |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5140 | for (auto *C : Clauses) { |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5141 | if (C->getClauseKind() == OMPC_read || C->getClauseKind() == OMPC_write || |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5142 | C->getClauseKind() == OMPC_update || |
| 5143 | C->getClauseKind() == OMPC_capture) { |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5144 | if (AtomicKind != OMPC_unknown) { |
| 5145 | Diag(C->getLocStart(), diag::err_omp_atomic_several_clauses) |
| 5146 | << SourceRange(C->getLocStart(), C->getLocEnd()); |
| 5147 | Diag(AtomicKindLoc, diag::note_omp_atomic_previous_clause) |
| 5148 | << getOpenMPClauseName(AtomicKind); |
| 5149 | } else { |
| 5150 | AtomicKind = C->getClauseKind(); |
| 5151 | AtomicKindLoc = C->getLocStart(); |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5152 | } |
| 5153 | } |
| 5154 | } |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5155 | |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5156 | auto Body = CS->getCapturedStmt(); |
Alexey Bataev | 10fec57 | 2015-03-11 04:48:56 +0000 | [diff] [blame] | 5157 | if (auto *EWC = dyn_cast<ExprWithCleanups>(Body)) |
| 5158 | Body = EWC->getSubExpr(); |
| 5159 | |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5160 | Expr *X = nullptr; |
| 5161 | Expr *V = nullptr; |
| 5162 | Expr *E = nullptr; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5163 | Expr *UE = nullptr; |
| 5164 | bool IsXLHSInRHSPart = false; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5165 | bool IsPostfixUpdate = false; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5166 | // OpenMP [2.12.6, atomic Construct] |
| 5167 | // In the next expressions: |
| 5168 | // * x and v (as applicable) are both l-value expressions with scalar type. |
| 5169 | // * During the execution of an atomic region, multiple syntactic |
| 5170 | // occurrences of x must designate the same storage location. |
| 5171 | // * Neither of v and expr (as applicable) may access the storage location |
| 5172 | // designated by x. |
| 5173 | // * Neither of x and expr (as applicable) may access the storage location |
| 5174 | // designated by v. |
| 5175 | // * expr is an expression with scalar type. |
| 5176 | // * binop is one of +, *, -, /, &, ^, |, <<, or >>. |
| 5177 | // * binop, binop=, ++, and -- are not overloaded operators. |
| 5178 | // * The expression x binop expr must be numerically equivalent to x binop |
| 5179 | // (expr). This requirement is satisfied if the operators in expr have |
| 5180 | // precedence greater than binop, or by using parentheses around expr or |
| 5181 | // subexpressions of expr. |
| 5182 | // * The expression expr binop x must be numerically equivalent to (expr) |
| 5183 | // binop x. This requirement is satisfied if the operators in expr have |
| 5184 | // precedence equal to or greater than binop, or by using parentheses around |
| 5185 | // expr or subexpressions of expr. |
| 5186 | // * For forms that allow multiple occurrences of x, the number of times |
| 5187 | // that x is evaluated is unspecified. |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5188 | if (AtomicKind == OMPC_read) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5189 | enum { |
| 5190 | NotAnExpression, |
| 5191 | NotAnAssignmentOp, |
| 5192 | NotAScalarType, |
| 5193 | NotAnLValue, |
| 5194 | NoError |
| 5195 | } ErrorFound = NoError; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5196 | SourceLocation ErrorLoc, NoteLoc; |
| 5197 | SourceRange ErrorRange, NoteRange; |
| 5198 | // If clause is read: |
| 5199 | // v = x; |
| 5200 | if (auto AtomicBody = dyn_cast<Expr>(Body)) { |
| 5201 | auto AtomicBinOp = |
| 5202 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 5203 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
| 5204 | X = AtomicBinOp->getRHS()->IgnoreParenImpCasts(); |
| 5205 | V = AtomicBinOp->getLHS()->IgnoreParenImpCasts(); |
| 5206 | if ((X->isInstantiationDependent() || X->getType()->isScalarType()) && |
| 5207 | (V->isInstantiationDependent() || V->getType()->isScalarType())) { |
| 5208 | if (!X->isLValue() || !V->isLValue()) { |
| 5209 | auto NotLValueExpr = X->isLValue() ? V : X; |
| 5210 | ErrorFound = NotAnLValue; |
| 5211 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5212 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5213 | NoteLoc = NotLValueExpr->getExprLoc(); |
| 5214 | NoteRange = NotLValueExpr->getSourceRange(); |
| 5215 | } |
| 5216 | } else if (!X->isInstantiationDependent() || |
| 5217 | !V->isInstantiationDependent()) { |
| 5218 | auto NotScalarExpr = |
| 5219 | (X->isInstantiationDependent() || X->getType()->isScalarType()) |
| 5220 | ? V |
| 5221 | : X; |
| 5222 | ErrorFound = NotAScalarType; |
| 5223 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5224 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5225 | NoteLoc = NotScalarExpr->getExprLoc(); |
| 5226 | NoteRange = NotScalarExpr->getSourceRange(); |
| 5227 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5228 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5229 | ErrorFound = NotAnAssignmentOp; |
| 5230 | ErrorLoc = AtomicBody->getExprLoc(); |
| 5231 | ErrorRange = AtomicBody->getSourceRange(); |
| 5232 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 5233 | : AtomicBody->getExprLoc(); |
| 5234 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 5235 | : AtomicBody->getSourceRange(); |
| 5236 | } |
| 5237 | } else { |
| 5238 | ErrorFound = NotAnExpression; |
| 5239 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 5240 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5241 | } |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5242 | if (ErrorFound != NoError) { |
| 5243 | Diag(ErrorLoc, diag::err_omp_atomic_read_not_expression_statement) |
| 5244 | << ErrorRange; |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5245 | Diag(NoteLoc, diag::note_omp_atomic_read_write) << ErrorFound |
| 5246 | << NoteRange; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5247 | return StmtError(); |
| 5248 | } else if (CurContext->isDependentContext()) |
| 5249 | V = X = nullptr; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5250 | } else if (AtomicKind == OMPC_write) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5251 | enum { |
| 5252 | NotAnExpression, |
| 5253 | NotAnAssignmentOp, |
| 5254 | NotAScalarType, |
| 5255 | NotAnLValue, |
| 5256 | NoError |
| 5257 | } ErrorFound = NoError; |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5258 | SourceLocation ErrorLoc, NoteLoc; |
| 5259 | SourceRange ErrorRange, NoteRange; |
| 5260 | // If clause is write: |
| 5261 | // x = expr; |
| 5262 | if (auto AtomicBody = dyn_cast<Expr>(Body)) { |
| 5263 | auto AtomicBinOp = |
| 5264 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 5265 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
Alexey Bataev | b832926 | 2015-02-27 06:33:30 +0000 | [diff] [blame] | 5266 | X = AtomicBinOp->getLHS(); |
| 5267 | E = AtomicBinOp->getRHS(); |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5268 | if ((X->isInstantiationDependent() || X->getType()->isScalarType()) && |
| 5269 | (E->isInstantiationDependent() || E->getType()->isScalarType())) { |
| 5270 | if (!X->isLValue()) { |
| 5271 | ErrorFound = NotAnLValue; |
| 5272 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5273 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5274 | NoteLoc = X->getExprLoc(); |
| 5275 | NoteRange = X->getSourceRange(); |
| 5276 | } |
| 5277 | } else if (!X->isInstantiationDependent() || |
| 5278 | !E->isInstantiationDependent()) { |
| 5279 | auto NotScalarExpr = |
| 5280 | (X->isInstantiationDependent() || X->getType()->isScalarType()) |
| 5281 | ? E |
| 5282 | : X; |
| 5283 | ErrorFound = NotAScalarType; |
| 5284 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5285 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5286 | NoteLoc = NotScalarExpr->getExprLoc(); |
| 5287 | NoteRange = NotScalarExpr->getSourceRange(); |
| 5288 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5289 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5290 | ErrorFound = NotAnAssignmentOp; |
| 5291 | ErrorLoc = AtomicBody->getExprLoc(); |
| 5292 | ErrorRange = AtomicBody->getSourceRange(); |
| 5293 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 5294 | : AtomicBody->getExprLoc(); |
| 5295 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 5296 | : AtomicBody->getSourceRange(); |
| 5297 | } |
| 5298 | } else { |
| 5299 | ErrorFound = NotAnExpression; |
| 5300 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 5301 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5302 | } |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5303 | if (ErrorFound != NoError) { |
| 5304 | Diag(ErrorLoc, diag::err_omp_atomic_write_not_expression_statement) |
| 5305 | << ErrorRange; |
| 5306 | Diag(NoteLoc, diag::note_omp_atomic_read_write) << ErrorFound |
| 5307 | << NoteRange; |
| 5308 | return StmtError(); |
| 5309 | } else if (CurContext->isDependentContext()) |
| 5310 | E = X = nullptr; |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5311 | } else if (AtomicKind == OMPC_update || AtomicKind == OMPC_unknown) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5312 | // If clause is update: |
| 5313 | // x++; |
| 5314 | // x--; |
| 5315 | // ++x; |
| 5316 | // --x; |
| 5317 | // x binop= expr; |
| 5318 | // x = x binop expr; |
| 5319 | // x = expr binop x; |
| 5320 | OpenMPAtomicUpdateChecker Checker(*this); |
| 5321 | if (Checker.checkStatement( |
| 5322 | Body, (AtomicKind == OMPC_update) |
| 5323 | ? diag::err_omp_atomic_update_not_expression_statement |
| 5324 | : diag::err_omp_atomic_not_expression_statement, |
| 5325 | diag::note_omp_atomic_update)) |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5326 | return StmtError(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5327 | if (!CurContext->isDependentContext()) { |
| 5328 | E = Checker.getExpr(); |
| 5329 | X = Checker.getX(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5330 | UE = Checker.getUpdateExpr(); |
| 5331 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5332 | } |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5333 | } else if (AtomicKind == OMPC_capture) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5334 | enum { |
| 5335 | NotAnAssignmentOp, |
| 5336 | NotACompoundStatement, |
| 5337 | NotTwoSubstatements, |
| 5338 | NotASpecificExpression, |
| 5339 | NoError |
| 5340 | } ErrorFound = NoError; |
| 5341 | SourceLocation ErrorLoc, NoteLoc; |
| 5342 | SourceRange ErrorRange, NoteRange; |
| 5343 | if (auto *AtomicBody = dyn_cast<Expr>(Body)) { |
| 5344 | // If clause is a capture: |
| 5345 | // v = x++; |
| 5346 | // v = x--; |
| 5347 | // v = ++x; |
| 5348 | // v = --x; |
| 5349 | // v = x binop= expr; |
| 5350 | // v = x = x binop expr; |
| 5351 | // v = x = expr binop x; |
| 5352 | auto *AtomicBinOp = |
| 5353 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 5354 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
| 5355 | V = AtomicBinOp->getLHS(); |
| 5356 | Body = AtomicBinOp->getRHS()->IgnoreParenImpCasts(); |
| 5357 | OpenMPAtomicUpdateChecker Checker(*this); |
| 5358 | if (Checker.checkStatement( |
| 5359 | Body, diag::err_omp_atomic_capture_not_expression_statement, |
| 5360 | diag::note_omp_atomic_update)) |
| 5361 | return StmtError(); |
| 5362 | E = Checker.getExpr(); |
| 5363 | X = Checker.getX(); |
| 5364 | UE = Checker.getUpdateExpr(); |
| 5365 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
| 5366 | IsPostfixUpdate = Checker.isPostfixUpdate(); |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5367 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5368 | ErrorLoc = AtomicBody->getExprLoc(); |
| 5369 | ErrorRange = AtomicBody->getSourceRange(); |
| 5370 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 5371 | : AtomicBody->getExprLoc(); |
| 5372 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 5373 | : AtomicBody->getSourceRange(); |
| 5374 | ErrorFound = NotAnAssignmentOp; |
| 5375 | } |
| 5376 | if (ErrorFound != NoError) { |
| 5377 | Diag(ErrorLoc, diag::err_omp_atomic_capture_not_expression_statement) |
| 5378 | << ErrorRange; |
| 5379 | Diag(NoteLoc, diag::note_omp_atomic_capture) << ErrorFound << NoteRange; |
| 5380 | return StmtError(); |
| 5381 | } else if (CurContext->isDependentContext()) { |
| 5382 | UE = V = E = X = nullptr; |
| 5383 | } |
| 5384 | } else { |
| 5385 | // If clause is a capture: |
| 5386 | // { v = x; x = expr; } |
| 5387 | // { v = x; x++; } |
| 5388 | // { v = x; x--; } |
| 5389 | // { v = x; ++x; } |
| 5390 | // { v = x; --x; } |
| 5391 | // { v = x; x binop= expr; } |
| 5392 | // { v = x; x = x binop expr; } |
| 5393 | // { v = x; x = expr binop x; } |
| 5394 | // { x++; v = x; } |
| 5395 | // { x--; v = x; } |
| 5396 | // { ++x; v = x; } |
| 5397 | // { --x; v = x; } |
| 5398 | // { x binop= expr; v = x; } |
| 5399 | // { x = x binop expr; v = x; } |
| 5400 | // { x = expr binop x; v = x; } |
| 5401 | if (auto *CS = dyn_cast<CompoundStmt>(Body)) { |
| 5402 | // Check that this is { expr1; expr2; } |
| 5403 | if (CS->size() == 2) { |
| 5404 | auto *First = CS->body_front(); |
| 5405 | auto *Second = CS->body_back(); |
| 5406 | if (auto *EWC = dyn_cast<ExprWithCleanups>(First)) |
| 5407 | First = EWC->getSubExpr()->IgnoreParenImpCasts(); |
| 5408 | if (auto *EWC = dyn_cast<ExprWithCleanups>(Second)) |
| 5409 | Second = EWC->getSubExpr()->IgnoreParenImpCasts(); |
| 5410 | // Need to find what subexpression is 'v' and what is 'x'. |
| 5411 | OpenMPAtomicUpdateChecker Checker(*this); |
| 5412 | bool IsUpdateExprFound = !Checker.checkStatement(Second); |
| 5413 | BinaryOperator *BinOp = nullptr; |
| 5414 | if (IsUpdateExprFound) { |
| 5415 | BinOp = dyn_cast<BinaryOperator>(First); |
| 5416 | IsUpdateExprFound = BinOp && BinOp->getOpcode() == BO_Assign; |
| 5417 | } |
| 5418 | if (IsUpdateExprFound && !CurContext->isDependentContext()) { |
| 5419 | // { v = x; x++; } |
| 5420 | // { v = x; x--; } |
| 5421 | // { v = x; ++x; } |
| 5422 | // { v = x; --x; } |
| 5423 | // { v = x; x binop= expr; } |
| 5424 | // { v = x; x = x binop expr; } |
| 5425 | // { v = x; x = expr binop x; } |
| 5426 | // Check that the first expression has form v = x. |
| 5427 | auto *PossibleX = BinOp->getRHS()->IgnoreParenImpCasts(); |
| 5428 | llvm::FoldingSetNodeID XId, PossibleXId; |
| 5429 | Checker.getX()->Profile(XId, Context, /*Canonical=*/true); |
| 5430 | PossibleX->Profile(PossibleXId, Context, /*Canonical=*/true); |
| 5431 | IsUpdateExprFound = XId == PossibleXId; |
| 5432 | if (IsUpdateExprFound) { |
| 5433 | V = BinOp->getLHS(); |
| 5434 | X = Checker.getX(); |
| 5435 | E = Checker.getExpr(); |
| 5436 | UE = Checker.getUpdateExpr(); |
| 5437 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5438 | IsPostfixUpdate = true; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5439 | } |
| 5440 | } |
| 5441 | if (!IsUpdateExprFound) { |
| 5442 | IsUpdateExprFound = !Checker.checkStatement(First); |
| 5443 | BinOp = nullptr; |
| 5444 | if (IsUpdateExprFound) { |
| 5445 | BinOp = dyn_cast<BinaryOperator>(Second); |
| 5446 | IsUpdateExprFound = BinOp && BinOp->getOpcode() == BO_Assign; |
| 5447 | } |
| 5448 | if (IsUpdateExprFound && !CurContext->isDependentContext()) { |
| 5449 | // { x++; v = x; } |
| 5450 | // { x--; v = x; } |
| 5451 | // { ++x; v = x; } |
| 5452 | // { --x; v = x; } |
| 5453 | // { x binop= expr; v = x; } |
| 5454 | // { x = x binop expr; v = x; } |
| 5455 | // { x = expr binop x; v = x; } |
| 5456 | // Check that the second expression has form v = x. |
| 5457 | auto *PossibleX = BinOp->getRHS()->IgnoreParenImpCasts(); |
| 5458 | llvm::FoldingSetNodeID XId, PossibleXId; |
| 5459 | Checker.getX()->Profile(XId, Context, /*Canonical=*/true); |
| 5460 | PossibleX->Profile(PossibleXId, Context, /*Canonical=*/true); |
| 5461 | IsUpdateExprFound = XId == PossibleXId; |
| 5462 | if (IsUpdateExprFound) { |
| 5463 | V = BinOp->getLHS(); |
| 5464 | X = Checker.getX(); |
| 5465 | E = Checker.getExpr(); |
| 5466 | UE = Checker.getUpdateExpr(); |
| 5467 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5468 | IsPostfixUpdate = false; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5469 | } |
| 5470 | } |
| 5471 | } |
| 5472 | if (!IsUpdateExprFound) { |
| 5473 | // { v = x; x = expr; } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5474 | auto *FirstExpr = dyn_cast<Expr>(First); |
| 5475 | auto *SecondExpr = dyn_cast<Expr>(Second); |
| 5476 | if (!FirstExpr || !SecondExpr || |
| 5477 | !(FirstExpr->isInstantiationDependent() || |
| 5478 | SecondExpr->isInstantiationDependent())) { |
| 5479 | auto *FirstBinOp = dyn_cast<BinaryOperator>(First); |
| 5480 | if (!FirstBinOp || FirstBinOp->getOpcode() != BO_Assign) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5481 | ErrorFound = NotAnAssignmentOp; |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5482 | NoteLoc = ErrorLoc = FirstBinOp ? FirstBinOp->getOperatorLoc() |
| 5483 | : First->getLocStart(); |
| 5484 | NoteRange = ErrorRange = FirstBinOp |
| 5485 | ? FirstBinOp->getSourceRange() |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5486 | : SourceRange(ErrorLoc, ErrorLoc); |
| 5487 | } else { |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5488 | auto *SecondBinOp = dyn_cast<BinaryOperator>(Second); |
| 5489 | if (!SecondBinOp || SecondBinOp->getOpcode() != BO_Assign) { |
| 5490 | ErrorFound = NotAnAssignmentOp; |
| 5491 | NoteLoc = ErrorLoc = SecondBinOp |
| 5492 | ? SecondBinOp->getOperatorLoc() |
| 5493 | : Second->getLocStart(); |
| 5494 | NoteRange = ErrorRange = |
| 5495 | SecondBinOp ? SecondBinOp->getSourceRange() |
| 5496 | : SourceRange(ErrorLoc, ErrorLoc); |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5497 | } else { |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5498 | auto *PossibleXRHSInFirst = |
| 5499 | FirstBinOp->getRHS()->IgnoreParenImpCasts(); |
| 5500 | auto *PossibleXLHSInSecond = |
| 5501 | SecondBinOp->getLHS()->IgnoreParenImpCasts(); |
| 5502 | llvm::FoldingSetNodeID X1Id, X2Id; |
| 5503 | PossibleXRHSInFirst->Profile(X1Id, Context, |
| 5504 | /*Canonical=*/true); |
| 5505 | PossibleXLHSInSecond->Profile(X2Id, Context, |
| 5506 | /*Canonical=*/true); |
| 5507 | IsUpdateExprFound = X1Id == X2Id; |
| 5508 | if (IsUpdateExprFound) { |
| 5509 | V = FirstBinOp->getLHS(); |
| 5510 | X = SecondBinOp->getLHS(); |
| 5511 | E = SecondBinOp->getRHS(); |
| 5512 | UE = nullptr; |
| 5513 | IsXLHSInRHSPart = false; |
| 5514 | IsPostfixUpdate = true; |
| 5515 | } else { |
| 5516 | ErrorFound = NotASpecificExpression; |
| 5517 | ErrorLoc = FirstBinOp->getExprLoc(); |
| 5518 | ErrorRange = FirstBinOp->getSourceRange(); |
| 5519 | NoteLoc = SecondBinOp->getLHS()->getExprLoc(); |
| 5520 | NoteRange = SecondBinOp->getRHS()->getSourceRange(); |
| 5521 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5522 | } |
| 5523 | } |
| 5524 | } |
| 5525 | } |
| 5526 | } else { |
| 5527 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 5528 | NoteRange = ErrorRange = |
| 5529 | SourceRange(Body->getLocStart(), Body->getLocStart()); |
| 5530 | ErrorFound = NotTwoSubstatements; |
| 5531 | } |
| 5532 | } else { |
| 5533 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 5534 | NoteRange = ErrorRange = |
| 5535 | SourceRange(Body->getLocStart(), Body->getLocStart()); |
| 5536 | ErrorFound = NotACompoundStatement; |
| 5537 | } |
| 5538 | if (ErrorFound != NoError) { |
| 5539 | Diag(ErrorLoc, diag::err_omp_atomic_capture_not_compound_statement) |
| 5540 | << ErrorRange; |
| 5541 | Diag(NoteLoc, diag::note_omp_atomic_capture) << ErrorFound << NoteRange; |
| 5542 | return StmtError(); |
| 5543 | } else if (CurContext->isDependentContext()) { |
| 5544 | UE = V = E = X = nullptr; |
| 5545 | } |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5546 | } |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5547 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 5548 | |
| 5549 | getCurFunction()->setHasBranchProtectedScope(); |
| 5550 | |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5551 | return OMPAtomicDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5552 | X, V, E, UE, IsXLHSInRHSPart, |
| 5553 | IsPostfixUpdate); |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 5554 | } |
| 5555 | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 5556 | StmtResult Sema::ActOnOpenMPTargetDirective(ArrayRef<OMPClause *> Clauses, |
| 5557 | Stmt *AStmt, |
| 5558 | SourceLocation StartLoc, |
| 5559 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5560 | if (!AStmt) |
| 5561 | return StmtError(); |
| 5562 | |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 5563 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 5564 | // 1.2.2 OpenMP Language Terminology |
| 5565 | // Structured block - An executable statement with a single entry at the |
| 5566 | // top and a single exit at the bottom. |
| 5567 | // The point of exit cannot be a branch out of the structured block. |
| 5568 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5569 | CS->getCapturedDecl()->setNothrow(); |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 5570 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 5571 | // OpenMP [2.16, Nesting of Regions] |
| 5572 | // If specified, a teams construct must be contained within a target |
| 5573 | // construct. That target construct must contain no statements or directives |
| 5574 | // outside of the teams construct. |
| 5575 | if (DSAStack->hasInnerTeamsRegion()) { |
| 5576 | auto S = AStmt->IgnoreContainers(/*IgnoreCaptured*/ true); |
| 5577 | bool OMPTeamsFound = true; |
| 5578 | if (auto *CS = dyn_cast<CompoundStmt>(S)) { |
| 5579 | auto I = CS->body_begin(); |
| 5580 | while (I != CS->body_end()) { |
| 5581 | auto OED = dyn_cast<OMPExecutableDirective>(*I); |
| 5582 | if (!OED || !isOpenMPTeamsDirective(OED->getDirectiveKind())) { |
| 5583 | OMPTeamsFound = false; |
| 5584 | break; |
| 5585 | } |
| 5586 | ++I; |
| 5587 | } |
| 5588 | assert(I != CS->body_end() && "Not found statement"); |
| 5589 | S = *I; |
| 5590 | } |
| 5591 | if (!OMPTeamsFound) { |
| 5592 | Diag(StartLoc, diag::err_omp_target_contains_not_only_teams); |
| 5593 | Diag(DSAStack->getInnerTeamsRegionLoc(), |
| 5594 | diag::note_omp_nested_teams_construct_here); |
| 5595 | Diag(S->getLocStart(), diag::note_omp_nested_statement_here) |
| 5596 | << isa<OMPExecutableDirective>(S); |
| 5597 | return StmtError(); |
| 5598 | } |
| 5599 | } |
| 5600 | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 5601 | getCurFunction()->setHasBranchProtectedScope(); |
| 5602 | |
| 5603 | return OMPTargetDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 5604 | } |
| 5605 | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 5606 | /// \brief Check for existence of a map clause in the list of clauses. |
| 5607 | static bool HasMapClause(ArrayRef<OMPClause *> Clauses) { |
| 5608 | for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end(); |
| 5609 | I != E; ++I) { |
| 5610 | if (*I != nullptr && (*I)->getClauseKind() == OMPC_map) { |
| 5611 | return true; |
| 5612 | } |
| 5613 | } |
| 5614 | |
| 5615 | return false; |
| 5616 | } |
| 5617 | |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 5618 | StmtResult Sema::ActOnOpenMPTargetDataDirective(ArrayRef<OMPClause *> Clauses, |
| 5619 | Stmt *AStmt, |
| 5620 | SourceLocation StartLoc, |
| 5621 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5622 | if (!AStmt) |
| 5623 | return StmtError(); |
| 5624 | |
| 5625 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 5626 | |
Arpith Chacko Jacob | 46a04bb | 2016-01-21 19:57:55 +0000 | [diff] [blame] | 5627 | // OpenMP [2.10.1, Restrictions, p. 97] |
| 5628 | // At least one map clause must appear on the directive. |
| 5629 | if (!HasMapClause(Clauses)) { |
| 5630 | Diag(StartLoc, diag::err_omp_no_map_for_directive) << |
| 5631 | getOpenMPDirectiveName(OMPD_target_data); |
| 5632 | return StmtError(); |
| 5633 | } |
| 5634 | |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 5635 | getCurFunction()->setHasBranchProtectedScope(); |
| 5636 | |
| 5637 | return OMPTargetDataDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 5638 | AStmt); |
| 5639 | } |
| 5640 | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 5641 | StmtResult |
| 5642 | Sema::ActOnOpenMPTargetEnterDataDirective(ArrayRef<OMPClause *> Clauses, |
| 5643 | SourceLocation StartLoc, |
| 5644 | SourceLocation EndLoc) { |
| 5645 | // OpenMP [2.10.2, Restrictions, p. 99] |
| 5646 | // At least one map clause must appear on the directive. |
| 5647 | if (!HasMapClause(Clauses)) { |
| 5648 | Diag(StartLoc, diag::err_omp_no_map_for_directive) |
| 5649 | << getOpenMPDirectiveName(OMPD_target_enter_data); |
| 5650 | return StmtError(); |
| 5651 | } |
| 5652 | |
| 5653 | return OMPTargetEnterDataDirective::Create(Context, StartLoc, EndLoc, |
| 5654 | Clauses); |
| 5655 | } |
| 5656 | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 5657 | StmtResult |
| 5658 | Sema::ActOnOpenMPTargetExitDataDirective(ArrayRef<OMPClause *> Clauses, |
| 5659 | SourceLocation StartLoc, |
| 5660 | SourceLocation EndLoc) { |
| 5661 | // OpenMP [2.10.3, Restrictions, p. 102] |
| 5662 | // At least one map clause must appear on the directive. |
| 5663 | if (!HasMapClause(Clauses)) { |
| 5664 | Diag(StartLoc, diag::err_omp_no_map_for_directive) |
| 5665 | << getOpenMPDirectiveName(OMPD_target_exit_data); |
| 5666 | return StmtError(); |
| 5667 | } |
| 5668 | |
| 5669 | return OMPTargetExitDataDirective::Create(Context, StartLoc, EndLoc, Clauses); |
| 5670 | } |
| 5671 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 5672 | StmtResult Sema::ActOnOpenMPTeamsDirective(ArrayRef<OMPClause *> Clauses, |
| 5673 | Stmt *AStmt, SourceLocation StartLoc, |
| 5674 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5675 | if (!AStmt) |
| 5676 | return StmtError(); |
| 5677 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 5678 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 5679 | // 1.2.2 OpenMP Language Terminology |
| 5680 | // Structured block - An executable statement with a single entry at the |
| 5681 | // top and a single exit at the bottom. |
| 5682 | // The point of exit cannot be a branch out of the structured block. |
| 5683 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5684 | CS->getCapturedDecl()->setNothrow(); |
| 5685 | |
| 5686 | getCurFunction()->setHasBranchProtectedScope(); |
| 5687 | |
| 5688 | return OMPTeamsDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 5689 | } |
| 5690 | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 5691 | StmtResult |
| 5692 | Sema::ActOnOpenMPCancellationPointDirective(SourceLocation StartLoc, |
| 5693 | SourceLocation EndLoc, |
| 5694 | OpenMPDirectiveKind CancelRegion) { |
| 5695 | if (CancelRegion != OMPD_parallel && CancelRegion != OMPD_for && |
| 5696 | CancelRegion != OMPD_sections && CancelRegion != OMPD_taskgroup) { |
| 5697 | Diag(StartLoc, diag::err_omp_wrong_cancel_region) |
| 5698 | << getOpenMPDirectiveName(CancelRegion); |
| 5699 | return StmtError(); |
| 5700 | } |
| 5701 | if (DSAStack->isParentNowaitRegion()) { |
| 5702 | Diag(StartLoc, diag::err_omp_parent_cancel_region_nowait) << 0; |
| 5703 | return StmtError(); |
| 5704 | } |
| 5705 | if (DSAStack->isParentOrderedRegion()) { |
| 5706 | Diag(StartLoc, diag::err_omp_parent_cancel_region_ordered) << 0; |
| 5707 | return StmtError(); |
| 5708 | } |
| 5709 | return OMPCancellationPointDirective::Create(Context, StartLoc, EndLoc, |
| 5710 | CancelRegion); |
| 5711 | } |
| 5712 | |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 5713 | StmtResult Sema::ActOnOpenMPCancelDirective(ArrayRef<OMPClause *> Clauses, |
| 5714 | SourceLocation StartLoc, |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 5715 | SourceLocation EndLoc, |
| 5716 | OpenMPDirectiveKind CancelRegion) { |
| 5717 | if (CancelRegion != OMPD_parallel && CancelRegion != OMPD_for && |
| 5718 | CancelRegion != OMPD_sections && CancelRegion != OMPD_taskgroup) { |
| 5719 | Diag(StartLoc, diag::err_omp_wrong_cancel_region) |
| 5720 | << getOpenMPDirectiveName(CancelRegion); |
| 5721 | return StmtError(); |
| 5722 | } |
| 5723 | if (DSAStack->isParentNowaitRegion()) { |
| 5724 | Diag(StartLoc, diag::err_omp_parent_cancel_region_nowait) << 1; |
| 5725 | return StmtError(); |
| 5726 | } |
| 5727 | if (DSAStack->isParentOrderedRegion()) { |
| 5728 | Diag(StartLoc, diag::err_omp_parent_cancel_region_ordered) << 1; |
| 5729 | return StmtError(); |
| 5730 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 5731 | DSAStack->setParentCancelRegion(/*Cancel=*/true); |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 5732 | return OMPCancelDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 5733 | CancelRegion); |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 5734 | } |
| 5735 | |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 5736 | static bool checkGrainsizeNumTasksClauses(Sema &S, |
| 5737 | ArrayRef<OMPClause *> Clauses) { |
| 5738 | OMPClause *PrevClause = nullptr; |
| 5739 | bool ErrorFound = false; |
| 5740 | for (auto *C : Clauses) { |
| 5741 | if (C->getClauseKind() == OMPC_grainsize || |
| 5742 | C->getClauseKind() == OMPC_num_tasks) { |
| 5743 | if (!PrevClause) |
| 5744 | PrevClause = C; |
| 5745 | else if (PrevClause->getClauseKind() != C->getClauseKind()) { |
| 5746 | S.Diag(C->getLocStart(), |
| 5747 | diag::err_omp_grainsize_num_tasks_mutually_exclusive) |
| 5748 | << getOpenMPClauseName(C->getClauseKind()) |
| 5749 | << getOpenMPClauseName(PrevClause->getClauseKind()); |
| 5750 | S.Diag(PrevClause->getLocStart(), |
| 5751 | diag::note_omp_previous_grainsize_num_tasks) |
| 5752 | << getOpenMPClauseName(PrevClause->getClauseKind()); |
| 5753 | ErrorFound = true; |
| 5754 | } |
| 5755 | } |
| 5756 | } |
| 5757 | return ErrorFound; |
| 5758 | } |
| 5759 | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 5760 | StmtResult Sema::ActOnOpenMPTaskLoopDirective( |
| 5761 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 5762 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 5763 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 5764 | if (!AStmt) |
| 5765 | return StmtError(); |
| 5766 | |
| 5767 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 5768 | OMPLoopDirective::HelperExprs B; |
| 5769 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 5770 | // define the nested loops number. |
| 5771 | unsigned NestedLoopCount = |
| 5772 | CheckOpenMPLoop(OMPD_taskloop, getCollapseNumberExpr(Clauses), |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 5773 | /*OrderedLoopCountExpr=*/nullptr, AStmt, *this, *DSAStack, |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 5774 | VarsWithImplicitDSA, B); |
| 5775 | if (NestedLoopCount == 0) |
| 5776 | return StmtError(); |
| 5777 | |
| 5778 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 5779 | "omp for loop exprs were not built"); |
| 5780 | |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 5781 | // OpenMP, [2.9.2 taskloop Construct, Restrictions] |
| 5782 | // The grainsize clause and num_tasks clause are mutually exclusive and may |
| 5783 | // not appear on the same taskloop directive. |
| 5784 | if (checkGrainsizeNumTasksClauses(*this, Clauses)) |
| 5785 | return StmtError(); |
| 5786 | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 5787 | getCurFunction()->setHasBranchProtectedScope(); |
| 5788 | return OMPTaskLoopDirective::Create(Context, StartLoc, EndLoc, |
| 5789 | NestedLoopCount, Clauses, AStmt, B); |
| 5790 | } |
| 5791 | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 5792 | StmtResult Sema::ActOnOpenMPTaskLoopSimdDirective( |
| 5793 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 5794 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 5795 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 5796 | if (!AStmt) |
| 5797 | return StmtError(); |
| 5798 | |
| 5799 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 5800 | OMPLoopDirective::HelperExprs B; |
| 5801 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 5802 | // define the nested loops number. |
| 5803 | unsigned NestedLoopCount = |
| 5804 | CheckOpenMPLoop(OMPD_taskloop_simd, getCollapseNumberExpr(Clauses), |
| 5805 | /*OrderedLoopCountExpr=*/nullptr, AStmt, *this, *DSAStack, |
| 5806 | VarsWithImplicitDSA, B); |
| 5807 | if (NestedLoopCount == 0) |
| 5808 | return StmtError(); |
| 5809 | |
| 5810 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 5811 | "omp for loop exprs were not built"); |
| 5812 | |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 5813 | // OpenMP, [2.9.2 taskloop Construct, Restrictions] |
| 5814 | // The grainsize clause and num_tasks clause are mutually exclusive and may |
| 5815 | // not appear on the same taskloop directive. |
| 5816 | if (checkGrainsizeNumTasksClauses(*this, Clauses)) |
| 5817 | return StmtError(); |
| 5818 | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 5819 | getCurFunction()->setHasBranchProtectedScope(); |
| 5820 | return OMPTaskLoopSimdDirective::Create(Context, StartLoc, EndLoc, |
| 5821 | NestedLoopCount, Clauses, AStmt, B); |
| 5822 | } |
| 5823 | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 5824 | StmtResult Sema::ActOnOpenMPDistributeDirective( |
| 5825 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 5826 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 5827 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 5828 | if (!AStmt) |
| 5829 | return StmtError(); |
| 5830 | |
| 5831 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 5832 | OMPLoopDirective::HelperExprs B; |
| 5833 | // In presence of clause 'collapse' with number of loops, it will |
| 5834 | // define the nested loops number. |
| 5835 | unsigned NestedLoopCount = |
| 5836 | CheckOpenMPLoop(OMPD_distribute, getCollapseNumberExpr(Clauses), |
| 5837 | nullptr /*ordered not a clause on distribute*/, AStmt, |
| 5838 | *this, *DSAStack, VarsWithImplicitDSA, B); |
| 5839 | if (NestedLoopCount == 0) |
| 5840 | return StmtError(); |
| 5841 | |
| 5842 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 5843 | "omp for loop exprs were not built"); |
| 5844 | |
| 5845 | getCurFunction()->setHasBranchProtectedScope(); |
| 5846 | return OMPDistributeDirective::Create(Context, StartLoc, EndLoc, |
| 5847 | NestedLoopCount, Clauses, AStmt, B); |
| 5848 | } |
| 5849 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5850 | OMPClause *Sema::ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, Expr *Expr, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5851 | SourceLocation StartLoc, |
| 5852 | SourceLocation LParenLoc, |
| 5853 | SourceLocation EndLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 5854 | OMPClause *Res = nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5855 | switch (Kind) { |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 5856 | case OMPC_final: |
| 5857 | Res = ActOnOpenMPFinalClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5858 | break; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5859 | case OMPC_num_threads: |
| 5860 | Res = ActOnOpenMPNumThreadsClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5861 | break; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5862 | case OMPC_safelen: |
| 5863 | Res = ActOnOpenMPSafelenClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5864 | break; |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 5865 | case OMPC_simdlen: |
| 5866 | Res = ActOnOpenMPSimdlenClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5867 | break; |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 5868 | case OMPC_collapse: |
| 5869 | Res = ActOnOpenMPCollapseClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5870 | break; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5871 | case OMPC_ordered: |
| 5872 | Res = ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Expr); |
| 5873 | break; |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 5874 | case OMPC_device: |
| 5875 | Res = ActOnOpenMPDeviceClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5876 | break; |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 5877 | case OMPC_num_teams: |
| 5878 | Res = ActOnOpenMPNumTeamsClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5879 | break; |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 5880 | case OMPC_thread_limit: |
| 5881 | Res = ActOnOpenMPThreadLimitClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5882 | break; |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 5883 | case OMPC_priority: |
| 5884 | Res = ActOnOpenMPPriorityClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5885 | break; |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 5886 | case OMPC_grainsize: |
| 5887 | Res = ActOnOpenMPGrainsizeClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5888 | break; |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 5889 | case OMPC_num_tasks: |
| 5890 | Res = ActOnOpenMPNumTasksClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5891 | break; |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 5892 | case OMPC_hint: |
| 5893 | Res = ActOnOpenMPHintClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5894 | break; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5895 | case OMPC_if: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5896 | case OMPC_default: |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 5897 | case OMPC_proc_bind: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5898 | case OMPC_schedule: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5899 | case OMPC_private: |
| 5900 | case OMPC_firstprivate: |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 5901 | case OMPC_lastprivate: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5902 | case OMPC_shared: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5903 | case OMPC_reduction: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 5904 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 5905 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 5906 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 5907 | case OMPC_copyprivate: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 5908 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 5909 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 5910 | case OMPC_mergeable: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5911 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 5912 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5913 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5914 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5915 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5916 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 5917 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 5918 | case OMPC_depend: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5919 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5920 | case OMPC_simd: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 5921 | case OMPC_map: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 5922 | case OMPC_nogroup: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 5923 | case OMPC_dist_schedule: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5924 | case OMPC_unknown: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5925 | llvm_unreachable("Clause is not allowed."); |
| 5926 | } |
| 5927 | return Res; |
| 5928 | } |
| 5929 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5930 | OMPClause *Sema::ActOnOpenMPIfClause(OpenMPDirectiveKind NameModifier, |
| 5931 | Expr *Condition, SourceLocation StartLoc, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5932 | SourceLocation LParenLoc, |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5933 | SourceLocation NameModifierLoc, |
| 5934 | SourceLocation ColonLoc, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5935 | SourceLocation EndLoc) { |
| 5936 | Expr *ValExpr = Condition; |
| 5937 | if (!Condition->isValueDependent() && !Condition->isTypeDependent() && |
| 5938 | !Condition->isInstantiationDependent() && |
| 5939 | !Condition->containsUnexpandedParameterPack()) { |
| 5940 | ExprResult Val = ActOnBooleanCondition(DSAStack->getCurScope(), |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5941 | Condition->getExprLoc(), Condition); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5942 | if (Val.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 5943 | return nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5944 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 5945 | ValExpr = Val.get(); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5946 | } |
| 5947 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5948 | return new (Context) OMPIfClause(NameModifier, ValExpr, StartLoc, LParenLoc, |
| 5949 | NameModifierLoc, ColonLoc, EndLoc); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5950 | } |
| 5951 | |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 5952 | OMPClause *Sema::ActOnOpenMPFinalClause(Expr *Condition, |
| 5953 | SourceLocation StartLoc, |
| 5954 | SourceLocation LParenLoc, |
| 5955 | SourceLocation EndLoc) { |
| 5956 | Expr *ValExpr = Condition; |
| 5957 | if (!Condition->isValueDependent() && !Condition->isTypeDependent() && |
| 5958 | !Condition->isInstantiationDependent() && |
| 5959 | !Condition->containsUnexpandedParameterPack()) { |
| 5960 | ExprResult Val = ActOnBooleanCondition(DSAStack->getCurScope(), |
| 5961 | Condition->getExprLoc(), Condition); |
| 5962 | if (Val.isInvalid()) |
| 5963 | return nullptr; |
| 5964 | |
| 5965 | ValExpr = Val.get(); |
| 5966 | } |
| 5967 | |
| 5968 | return new (Context) OMPFinalClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 5969 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5970 | ExprResult Sema::PerformOpenMPImplicitIntegerConversion(SourceLocation Loc, |
| 5971 | Expr *Op) { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5972 | if (!Op) |
| 5973 | return ExprError(); |
| 5974 | |
| 5975 | class IntConvertDiagnoser : public ICEConvertDiagnoser { |
| 5976 | public: |
| 5977 | IntConvertDiagnoser() |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5978 | : ICEConvertDiagnoser(/*AllowScopedEnumerations*/ false, false, true) {} |
Craig Topper | e14c0f8 | 2014-03-12 04:55:44 +0000 | [diff] [blame] | 5979 | SemaDiagnosticBuilder diagnoseNotInt(Sema &S, SourceLocation Loc, |
| 5980 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5981 | return S.Diag(Loc, diag::err_omp_not_integral) << T; |
| 5982 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5983 | SemaDiagnosticBuilder diagnoseIncomplete(Sema &S, SourceLocation Loc, |
| 5984 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5985 | return S.Diag(Loc, diag::err_omp_incomplete_type) << T; |
| 5986 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5987 | SemaDiagnosticBuilder diagnoseExplicitConv(Sema &S, SourceLocation Loc, |
| 5988 | QualType T, |
| 5989 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5990 | return S.Diag(Loc, diag::err_omp_explicit_conversion) << T << ConvTy; |
| 5991 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5992 | SemaDiagnosticBuilder noteExplicitConv(Sema &S, CXXConversionDecl *Conv, |
| 5993 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5994 | return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5995 | << ConvTy->isEnumeralType() << ConvTy; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5996 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5997 | SemaDiagnosticBuilder diagnoseAmbiguous(Sema &S, SourceLocation Loc, |
| 5998 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5999 | return S.Diag(Loc, diag::err_omp_ambiguous_conversion) << T; |
| 6000 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6001 | SemaDiagnosticBuilder noteAmbiguous(Sema &S, CXXConversionDecl *Conv, |
| 6002 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6003 | return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6004 | << ConvTy->isEnumeralType() << ConvTy; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6005 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6006 | SemaDiagnosticBuilder diagnoseConversion(Sema &, SourceLocation, QualType, |
| 6007 | QualType) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6008 | llvm_unreachable("conversion functions are permitted"); |
| 6009 | } |
| 6010 | } ConvertDiagnoser; |
| 6011 | return PerformContextualImplicitConversion(Loc, Op, ConvertDiagnoser); |
| 6012 | } |
| 6013 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6014 | static bool IsNonNegativeIntegerValue(Expr *&ValExpr, Sema &SemaRef, |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6015 | OpenMPClauseKind CKind, |
| 6016 | bool StrictlyPositive) { |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6017 | if (!ValExpr->isTypeDependent() && !ValExpr->isValueDependent() && |
| 6018 | !ValExpr->isInstantiationDependent()) { |
| 6019 | SourceLocation Loc = ValExpr->getExprLoc(); |
| 6020 | ExprResult Value = |
| 6021 | SemaRef.PerformOpenMPImplicitIntegerConversion(Loc, ValExpr); |
| 6022 | if (Value.isInvalid()) |
| 6023 | return false; |
| 6024 | |
| 6025 | ValExpr = Value.get(); |
| 6026 | // The expression must evaluate to a non-negative integer value. |
| 6027 | llvm::APSInt Result; |
| 6028 | if (ValExpr->isIntegerConstantExpr(Result, SemaRef.Context) && |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6029 | Result.isSigned() && |
| 6030 | !((!StrictlyPositive && Result.isNonNegative()) || |
| 6031 | (StrictlyPositive && Result.isStrictlyPositive()))) { |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6032 | SemaRef.Diag(Loc, diag::err_omp_negative_expression_in_clause) |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6033 | << getOpenMPClauseName(CKind) << (StrictlyPositive ? 1 : 0) |
| 6034 | << ValExpr->getSourceRange(); |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6035 | return false; |
| 6036 | } |
| 6037 | } |
| 6038 | return true; |
| 6039 | } |
| 6040 | |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6041 | OMPClause *Sema::ActOnOpenMPNumThreadsClause(Expr *NumThreads, |
| 6042 | SourceLocation StartLoc, |
| 6043 | SourceLocation LParenLoc, |
| 6044 | SourceLocation EndLoc) { |
| 6045 | Expr *ValExpr = NumThreads; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6046 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6047 | // OpenMP [2.5, Restrictions] |
| 6048 | // The num_threads expression must evaluate to a positive integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6049 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_num_threads, |
| 6050 | /*StrictlyPositive=*/true)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6051 | return nullptr; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6052 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6053 | return new (Context) |
| 6054 | OMPNumThreadsClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6055 | } |
| 6056 | |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6057 | ExprResult Sema::VerifyPositiveIntegerConstantInClause(Expr *E, |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 6058 | OpenMPClauseKind CKind, |
| 6059 | bool StrictlyPositive) { |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6060 | if (!E) |
| 6061 | return ExprError(); |
| 6062 | if (E->isValueDependent() || E->isTypeDependent() || |
| 6063 | E->isInstantiationDependent() || E->containsUnexpandedParameterPack()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6064 | return E; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6065 | llvm::APSInt Result; |
| 6066 | ExprResult ICE = VerifyIntegerConstantExpression(E, &Result); |
| 6067 | if (ICE.isInvalid()) |
| 6068 | return ExprError(); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 6069 | if ((StrictlyPositive && !Result.isStrictlyPositive()) || |
| 6070 | (!StrictlyPositive && !Result.isNonNegative())) { |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6071 | Diag(E->getExprLoc(), diag::err_omp_negative_expression_in_clause) |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 6072 | << getOpenMPClauseName(CKind) << (StrictlyPositive ? 1 : 0) |
| 6073 | << E->getSourceRange(); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6074 | return ExprError(); |
| 6075 | } |
Alexander Musman | 09184fe | 2014-09-30 05:29:28 +0000 | [diff] [blame] | 6076 | if (CKind == OMPC_aligned && !Result.isPowerOf2()) { |
| 6077 | Diag(E->getExprLoc(), diag::warn_omp_alignment_not_power_of_two) |
| 6078 | << E->getSourceRange(); |
| 6079 | return ExprError(); |
| 6080 | } |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 6081 | if (CKind == OMPC_collapse && DSAStack->getAssociatedLoops() == 1) |
| 6082 | DSAStack->setAssociatedLoops(Result.getExtValue()); |
Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 6083 | else if (CKind == OMPC_ordered) |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 6084 | DSAStack->setAssociatedLoops(Result.getExtValue()); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6085 | return ICE; |
| 6086 | } |
| 6087 | |
| 6088 | OMPClause *Sema::ActOnOpenMPSafelenClause(Expr *Len, SourceLocation StartLoc, |
| 6089 | SourceLocation LParenLoc, |
| 6090 | SourceLocation EndLoc) { |
| 6091 | // OpenMP [2.8.1, simd construct, Description] |
| 6092 | // The parameter of the safelen clause must be a constant |
| 6093 | // positive integer expression. |
| 6094 | ExprResult Safelen = VerifyPositiveIntegerConstantInClause(Len, OMPC_safelen); |
| 6095 | if (Safelen.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6096 | return nullptr; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6097 | return new (Context) |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6098 | OMPSafelenClause(Safelen.get(), StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6099 | } |
| 6100 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 6101 | OMPClause *Sema::ActOnOpenMPSimdlenClause(Expr *Len, SourceLocation StartLoc, |
| 6102 | SourceLocation LParenLoc, |
| 6103 | SourceLocation EndLoc) { |
| 6104 | // OpenMP [2.8.1, simd construct, Description] |
| 6105 | // The parameter of the simdlen clause must be a constant |
| 6106 | // positive integer expression. |
| 6107 | ExprResult Simdlen = VerifyPositiveIntegerConstantInClause(Len, OMPC_simdlen); |
| 6108 | if (Simdlen.isInvalid()) |
| 6109 | return nullptr; |
| 6110 | return new (Context) |
| 6111 | OMPSimdlenClause(Simdlen.get(), StartLoc, LParenLoc, EndLoc); |
| 6112 | } |
| 6113 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6114 | OMPClause *Sema::ActOnOpenMPCollapseClause(Expr *NumForLoops, |
| 6115 | SourceLocation StartLoc, |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6116 | SourceLocation LParenLoc, |
| 6117 | SourceLocation EndLoc) { |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6118 | // OpenMP [2.7.1, loop construct, Description] |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6119 | // OpenMP [2.8.1, simd construct, Description] |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6120 | // OpenMP [2.9.6, distribute construct, Description] |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6121 | // The parameter of the collapse clause must be a constant |
| 6122 | // positive integer expression. |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6123 | ExprResult NumForLoopsResult = |
| 6124 | VerifyPositiveIntegerConstantInClause(NumForLoops, OMPC_collapse); |
| 6125 | if (NumForLoopsResult.isInvalid()) |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6126 | return nullptr; |
| 6127 | return new (Context) |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6128 | OMPCollapseClause(NumForLoopsResult.get(), StartLoc, LParenLoc, EndLoc); |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6129 | } |
| 6130 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 6131 | OMPClause *Sema::ActOnOpenMPOrderedClause(SourceLocation StartLoc, |
| 6132 | SourceLocation EndLoc, |
| 6133 | SourceLocation LParenLoc, |
| 6134 | Expr *NumForLoops) { |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 6135 | // OpenMP [2.7.1, loop construct, Description] |
| 6136 | // OpenMP [2.8.1, simd construct, Description] |
| 6137 | // OpenMP [2.9.6, distribute construct, Description] |
| 6138 | // The parameter of the ordered clause must be a constant |
| 6139 | // positive integer expression if any. |
| 6140 | if (NumForLoops && LParenLoc.isValid()) { |
| 6141 | ExprResult NumForLoopsResult = |
| 6142 | VerifyPositiveIntegerConstantInClause(NumForLoops, OMPC_ordered); |
| 6143 | if (NumForLoopsResult.isInvalid()) |
| 6144 | return nullptr; |
| 6145 | NumForLoops = NumForLoopsResult.get(); |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6146 | } else |
| 6147 | NumForLoops = nullptr; |
| 6148 | DSAStack->setOrderedRegion(/*IsOrdered=*/true, NumForLoops); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 6149 | return new (Context) |
| 6150 | OMPOrderedClause(NumForLoops, StartLoc, LParenLoc, EndLoc); |
| 6151 | } |
| 6152 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6153 | OMPClause *Sema::ActOnOpenMPSimpleClause( |
| 6154 | OpenMPClauseKind Kind, unsigned Argument, SourceLocation ArgumentLoc, |
| 6155 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6156 | OMPClause *Res = nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6157 | switch (Kind) { |
| 6158 | case OMPC_default: |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6159 | Res = |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6160 | ActOnOpenMPDefaultClause(static_cast<OpenMPDefaultClauseKind>(Argument), |
| 6161 | ArgumentLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6162 | break; |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6163 | case OMPC_proc_bind: |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6164 | Res = ActOnOpenMPProcBindClause( |
| 6165 | static_cast<OpenMPProcBindClauseKind>(Argument), ArgumentLoc, StartLoc, |
| 6166 | LParenLoc, EndLoc); |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6167 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6168 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 6169 | case OMPC_final: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6170 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6171 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 6172 | case OMPC_simdlen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6173 | case OMPC_collapse: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6174 | case OMPC_schedule: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6175 | case OMPC_private: |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6176 | case OMPC_firstprivate: |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6177 | case OMPC_lastprivate: |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6178 | case OMPC_shared: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6179 | case OMPC_reduction: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6180 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 6181 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6182 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6183 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6184 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6185 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 6186 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 6187 | case OMPC_mergeable: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6188 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 6189 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6190 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6191 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6192 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6193 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 6194 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6195 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 6196 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6197 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6198 | case OMPC_simd: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 6199 | case OMPC_map: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 6200 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6201 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6202 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 6203 | case OMPC_grainsize: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 6204 | case OMPC_nogroup: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6205 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 6206 | case OMPC_hint: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 6207 | case OMPC_dist_schedule: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6208 | case OMPC_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6209 | llvm_unreachable("Clause is not allowed."); |
| 6210 | } |
| 6211 | return Res; |
| 6212 | } |
| 6213 | |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6214 | static std::string |
| 6215 | getListOfPossibleValues(OpenMPClauseKind K, unsigned First, unsigned Last, |
| 6216 | ArrayRef<unsigned> Exclude = llvm::None) { |
| 6217 | std::string Values; |
| 6218 | unsigned Bound = Last >= 2 ? Last - 2 : 0; |
| 6219 | unsigned Skipped = Exclude.size(); |
| 6220 | auto S = Exclude.begin(), E = Exclude.end(); |
| 6221 | for (unsigned i = First; i < Last; ++i) { |
| 6222 | if (std::find(S, E, i) != E) { |
| 6223 | --Skipped; |
| 6224 | continue; |
| 6225 | } |
| 6226 | Values += "'"; |
| 6227 | Values += getOpenMPSimpleClauseTypeName(K, i); |
| 6228 | Values += "'"; |
| 6229 | if (i == Bound - Skipped) |
| 6230 | Values += " or "; |
| 6231 | else if (i != Bound + 1 - Skipped) |
| 6232 | Values += ", "; |
| 6233 | } |
| 6234 | return Values; |
| 6235 | } |
| 6236 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6237 | OMPClause *Sema::ActOnOpenMPDefaultClause(OpenMPDefaultClauseKind Kind, |
| 6238 | SourceLocation KindKwLoc, |
| 6239 | SourceLocation StartLoc, |
| 6240 | SourceLocation LParenLoc, |
| 6241 | SourceLocation EndLoc) { |
| 6242 | if (Kind == OMPC_DEFAULT_unknown) { |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 6243 | static_assert(OMPC_DEFAULT_unknown > 0, |
| 6244 | "OMPC_DEFAULT_unknown not greater than 0"); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6245 | Diag(KindKwLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6246 | << getListOfPossibleValues(OMPC_default, /*First=*/0, |
| 6247 | /*Last=*/OMPC_DEFAULT_unknown) |
| 6248 | << getOpenMPClauseName(OMPC_default); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6249 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6250 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6251 | switch (Kind) { |
| 6252 | case OMPC_DEFAULT_none: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6253 | DSAStack->setDefaultDSANone(KindKwLoc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6254 | break; |
| 6255 | case OMPC_DEFAULT_shared: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6256 | DSAStack->setDefaultDSAShared(KindKwLoc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6257 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6258 | case OMPC_DEFAULT_unknown: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6259 | llvm_unreachable("Clause kind is not allowed."); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6260 | break; |
| 6261 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6262 | return new (Context) |
| 6263 | OMPDefaultClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6264 | } |
| 6265 | |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6266 | OMPClause *Sema::ActOnOpenMPProcBindClause(OpenMPProcBindClauseKind Kind, |
| 6267 | SourceLocation KindKwLoc, |
| 6268 | SourceLocation StartLoc, |
| 6269 | SourceLocation LParenLoc, |
| 6270 | SourceLocation EndLoc) { |
| 6271 | if (Kind == OMPC_PROC_BIND_unknown) { |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6272 | Diag(KindKwLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6273 | << getListOfPossibleValues(OMPC_proc_bind, /*First=*/0, |
| 6274 | /*Last=*/OMPC_PROC_BIND_unknown) |
| 6275 | << getOpenMPClauseName(OMPC_proc_bind); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6276 | return nullptr; |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6277 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6278 | return new (Context) |
| 6279 | OMPProcBindClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6280 | } |
| 6281 | |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6282 | OMPClause *Sema::ActOnOpenMPSingleExprWithArgClause( |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6283 | OpenMPClauseKind Kind, ArrayRef<unsigned> Argument, Expr *Expr, |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6284 | SourceLocation StartLoc, SourceLocation LParenLoc, |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6285 | ArrayRef<SourceLocation> ArgumentLoc, SourceLocation DelimLoc, |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6286 | SourceLocation EndLoc) { |
| 6287 | OMPClause *Res = nullptr; |
| 6288 | switch (Kind) { |
| 6289 | case OMPC_schedule: |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6290 | enum { Modifier1, Modifier2, ScheduleKind, NumberOfElements }; |
| 6291 | assert(Argument.size() == NumberOfElements && |
| 6292 | ArgumentLoc.size() == NumberOfElements); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6293 | Res = ActOnOpenMPScheduleClause( |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6294 | static_cast<OpenMPScheduleClauseModifier>(Argument[Modifier1]), |
| 6295 | static_cast<OpenMPScheduleClauseModifier>(Argument[Modifier2]), |
| 6296 | static_cast<OpenMPScheduleClauseKind>(Argument[ScheduleKind]), Expr, |
| 6297 | StartLoc, LParenLoc, ArgumentLoc[Modifier1], ArgumentLoc[Modifier2], |
| 6298 | ArgumentLoc[ScheduleKind], DelimLoc, EndLoc); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6299 | break; |
| 6300 | case OMPC_if: |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6301 | assert(Argument.size() == 1 && ArgumentLoc.size() == 1); |
| 6302 | Res = ActOnOpenMPIfClause(static_cast<OpenMPDirectiveKind>(Argument.back()), |
| 6303 | Expr, StartLoc, LParenLoc, ArgumentLoc.back(), |
| 6304 | DelimLoc, EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6305 | break; |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 6306 | case OMPC_dist_schedule: |
| 6307 | Res = ActOnOpenMPDistScheduleClause( |
| 6308 | static_cast<OpenMPDistScheduleClauseKind>(Argument.back()), Expr, |
| 6309 | StartLoc, LParenLoc, ArgumentLoc.back(), DelimLoc, EndLoc); |
| 6310 | break; |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 6311 | case OMPC_final: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6312 | case OMPC_num_threads: |
| 6313 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 6314 | case OMPC_simdlen: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6315 | case OMPC_collapse: |
| 6316 | case OMPC_default: |
| 6317 | case OMPC_proc_bind: |
| 6318 | case OMPC_private: |
| 6319 | case OMPC_firstprivate: |
| 6320 | case OMPC_lastprivate: |
| 6321 | case OMPC_shared: |
| 6322 | case OMPC_reduction: |
| 6323 | case OMPC_linear: |
| 6324 | case OMPC_aligned: |
| 6325 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6326 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6327 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6328 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 6329 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 6330 | case OMPC_mergeable: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6331 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 6332 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6333 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6334 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6335 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6336 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 6337 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6338 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 6339 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6340 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6341 | case OMPC_simd: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 6342 | case OMPC_map: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 6343 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6344 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6345 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 6346 | case OMPC_grainsize: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 6347 | case OMPC_nogroup: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6348 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 6349 | case OMPC_hint: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6350 | case OMPC_unknown: |
| 6351 | llvm_unreachable("Clause is not allowed."); |
| 6352 | } |
| 6353 | return Res; |
| 6354 | } |
| 6355 | |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6356 | static bool checkScheduleModifiers(Sema &S, OpenMPScheduleClauseModifier M1, |
| 6357 | OpenMPScheduleClauseModifier M2, |
| 6358 | SourceLocation M1Loc, SourceLocation M2Loc) { |
| 6359 | if (M1 == OMPC_SCHEDULE_MODIFIER_unknown && M1Loc.isValid()) { |
| 6360 | SmallVector<unsigned, 2> Excluded; |
| 6361 | if (M2 != OMPC_SCHEDULE_MODIFIER_unknown) |
| 6362 | Excluded.push_back(M2); |
| 6363 | if (M2 == OMPC_SCHEDULE_MODIFIER_nonmonotonic) |
| 6364 | Excluded.push_back(OMPC_SCHEDULE_MODIFIER_monotonic); |
| 6365 | if (M2 == OMPC_SCHEDULE_MODIFIER_monotonic) |
| 6366 | Excluded.push_back(OMPC_SCHEDULE_MODIFIER_nonmonotonic); |
| 6367 | S.Diag(M1Loc, diag::err_omp_unexpected_clause_value) |
| 6368 | << getListOfPossibleValues(OMPC_schedule, |
| 6369 | /*First=*/OMPC_SCHEDULE_MODIFIER_unknown + 1, |
| 6370 | /*Last=*/OMPC_SCHEDULE_MODIFIER_last, |
| 6371 | Excluded) |
| 6372 | << getOpenMPClauseName(OMPC_schedule); |
| 6373 | return true; |
| 6374 | } |
| 6375 | return false; |
| 6376 | } |
| 6377 | |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6378 | OMPClause *Sema::ActOnOpenMPScheduleClause( |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6379 | OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2, |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6380 | OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6381 | SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc, |
| 6382 | SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) { |
| 6383 | if (checkScheduleModifiers(*this, M1, M2, M1Loc, M2Loc) || |
| 6384 | checkScheduleModifiers(*this, M2, M1, M2Loc, M1Loc)) |
| 6385 | return nullptr; |
| 6386 | // OpenMP, 2.7.1, Loop Construct, Restrictions |
| 6387 | // Either the monotonic modifier or the nonmonotonic modifier can be specified |
| 6388 | // but not both. |
| 6389 | if ((M1 == M2 && M1 != OMPC_SCHEDULE_MODIFIER_unknown) || |
| 6390 | (M1 == OMPC_SCHEDULE_MODIFIER_monotonic && |
| 6391 | M2 == OMPC_SCHEDULE_MODIFIER_nonmonotonic) || |
| 6392 | (M1 == OMPC_SCHEDULE_MODIFIER_nonmonotonic && |
| 6393 | M2 == OMPC_SCHEDULE_MODIFIER_monotonic)) { |
| 6394 | Diag(M2Loc, diag::err_omp_unexpected_schedule_modifier) |
| 6395 | << getOpenMPSimpleClauseTypeName(OMPC_schedule, M2) |
| 6396 | << getOpenMPSimpleClauseTypeName(OMPC_schedule, M1); |
| 6397 | return nullptr; |
| 6398 | } |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6399 | if (Kind == OMPC_SCHEDULE_unknown) { |
| 6400 | std::string Values; |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6401 | if (M1Loc.isInvalid() && M2Loc.isInvalid()) { |
| 6402 | unsigned Exclude[] = {OMPC_SCHEDULE_unknown}; |
| 6403 | Values = getListOfPossibleValues(OMPC_schedule, /*First=*/0, |
| 6404 | /*Last=*/OMPC_SCHEDULE_MODIFIER_last, |
| 6405 | Exclude); |
| 6406 | } else { |
| 6407 | Values = getListOfPossibleValues(OMPC_schedule, /*First=*/0, |
| 6408 | /*Last=*/OMPC_SCHEDULE_unknown); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6409 | } |
| 6410 | Diag(KindLoc, diag::err_omp_unexpected_clause_value) |
| 6411 | << Values << getOpenMPClauseName(OMPC_schedule); |
| 6412 | return nullptr; |
| 6413 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6414 | // OpenMP, 2.7.1, Loop Construct, Restrictions |
| 6415 | // The nonmonotonic modifier can only be specified with schedule(dynamic) or |
| 6416 | // schedule(guided). |
| 6417 | if ((M1 == OMPC_SCHEDULE_MODIFIER_nonmonotonic || |
| 6418 | M2 == OMPC_SCHEDULE_MODIFIER_nonmonotonic) && |
| 6419 | Kind != OMPC_SCHEDULE_dynamic && Kind != OMPC_SCHEDULE_guided) { |
| 6420 | Diag(M1 == OMPC_SCHEDULE_MODIFIER_nonmonotonic ? M1Loc : M2Loc, |
| 6421 | diag::err_omp_schedule_nonmonotonic_static); |
| 6422 | return nullptr; |
| 6423 | } |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6424 | Expr *ValExpr = ChunkSize; |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 6425 | Expr *HelperValExpr = nullptr; |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6426 | if (ChunkSize) { |
| 6427 | if (!ChunkSize->isValueDependent() && !ChunkSize->isTypeDependent() && |
| 6428 | !ChunkSize->isInstantiationDependent() && |
| 6429 | !ChunkSize->containsUnexpandedParameterPack()) { |
| 6430 | SourceLocation ChunkSizeLoc = ChunkSize->getLocStart(); |
| 6431 | ExprResult Val = |
| 6432 | PerformOpenMPImplicitIntegerConversion(ChunkSizeLoc, ChunkSize); |
| 6433 | if (Val.isInvalid()) |
| 6434 | return nullptr; |
| 6435 | |
| 6436 | ValExpr = Val.get(); |
| 6437 | |
| 6438 | // OpenMP [2.7.1, Restrictions] |
| 6439 | // chunk_size must be a loop invariant integer expression with a positive |
| 6440 | // value. |
| 6441 | llvm::APSInt Result; |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 6442 | if (ValExpr->isIntegerConstantExpr(Result, Context)) { |
| 6443 | if (Result.isSigned() && !Result.isStrictlyPositive()) { |
| 6444 | Diag(ChunkSizeLoc, diag::err_omp_negative_expression_in_clause) |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6445 | << "schedule" << 1 << ChunkSize->getSourceRange(); |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 6446 | return nullptr; |
| 6447 | } |
| 6448 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective())) { |
| 6449 | auto *ImpVar = buildVarDecl(*this, ChunkSize->getExprLoc(), |
| 6450 | ChunkSize->getType(), ".chunk."); |
| 6451 | auto *ImpVarRef = buildDeclRefExpr(*this, ImpVar, ChunkSize->getType(), |
| 6452 | ChunkSize->getExprLoc(), |
| 6453 | /*RefersToCapture=*/true); |
| 6454 | HelperValExpr = ImpVarRef; |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6455 | } |
| 6456 | } |
| 6457 | } |
| 6458 | |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6459 | return new (Context) |
| 6460 | OMPScheduleClause(StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc, Kind, |
| 6461 | ValExpr, HelperValExpr, M1, M1Loc, M2, M2Loc); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6462 | } |
| 6463 | |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6464 | OMPClause *Sema::ActOnOpenMPClause(OpenMPClauseKind Kind, |
| 6465 | SourceLocation StartLoc, |
| 6466 | SourceLocation EndLoc) { |
| 6467 | OMPClause *Res = nullptr; |
| 6468 | switch (Kind) { |
| 6469 | case OMPC_ordered: |
| 6470 | Res = ActOnOpenMPOrderedClause(StartLoc, EndLoc); |
| 6471 | break; |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6472 | case OMPC_nowait: |
| 6473 | Res = ActOnOpenMPNowaitClause(StartLoc, EndLoc); |
| 6474 | break; |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 6475 | case OMPC_untied: |
| 6476 | Res = ActOnOpenMPUntiedClause(StartLoc, EndLoc); |
| 6477 | break; |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 6478 | case OMPC_mergeable: |
| 6479 | Res = ActOnOpenMPMergeableClause(StartLoc, EndLoc); |
| 6480 | break; |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6481 | case OMPC_read: |
| 6482 | Res = ActOnOpenMPReadClause(StartLoc, EndLoc); |
| 6483 | break; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6484 | case OMPC_write: |
| 6485 | Res = ActOnOpenMPWriteClause(StartLoc, EndLoc); |
| 6486 | break; |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6487 | case OMPC_update: |
| 6488 | Res = ActOnOpenMPUpdateClause(StartLoc, EndLoc); |
| 6489 | break; |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6490 | case OMPC_capture: |
| 6491 | Res = ActOnOpenMPCaptureClause(StartLoc, EndLoc); |
| 6492 | break; |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 6493 | case OMPC_seq_cst: |
| 6494 | Res = ActOnOpenMPSeqCstClause(StartLoc, EndLoc); |
| 6495 | break; |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6496 | case OMPC_threads: |
| 6497 | Res = ActOnOpenMPThreadsClause(StartLoc, EndLoc); |
| 6498 | break; |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6499 | case OMPC_simd: |
| 6500 | Res = ActOnOpenMPSIMDClause(StartLoc, EndLoc); |
| 6501 | break; |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 6502 | case OMPC_nogroup: |
| 6503 | Res = ActOnOpenMPNogroupClause(StartLoc, EndLoc); |
| 6504 | break; |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6505 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 6506 | case OMPC_final: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6507 | case OMPC_num_threads: |
| 6508 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 6509 | case OMPC_simdlen: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6510 | case OMPC_collapse: |
| 6511 | case OMPC_schedule: |
| 6512 | case OMPC_private: |
| 6513 | case OMPC_firstprivate: |
| 6514 | case OMPC_lastprivate: |
| 6515 | case OMPC_shared: |
| 6516 | case OMPC_reduction: |
| 6517 | case OMPC_linear: |
| 6518 | case OMPC_aligned: |
| 6519 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6520 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6521 | case OMPC_default: |
| 6522 | case OMPC_proc_bind: |
| 6523 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 6524 | case OMPC_flush: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6525 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 6526 | case OMPC_device: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 6527 | case OMPC_map: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 6528 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6529 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6530 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 6531 | case OMPC_grainsize: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6532 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 6533 | case OMPC_hint: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 6534 | case OMPC_dist_schedule: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6535 | case OMPC_unknown: |
| 6536 | llvm_unreachable("Clause is not allowed."); |
| 6537 | } |
| 6538 | return Res; |
| 6539 | } |
| 6540 | |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6541 | OMPClause *Sema::ActOnOpenMPNowaitClause(SourceLocation StartLoc, |
| 6542 | SourceLocation EndLoc) { |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 6543 | DSAStack->setNowaitRegion(); |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6544 | return new (Context) OMPNowaitClause(StartLoc, EndLoc); |
| 6545 | } |
| 6546 | |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 6547 | OMPClause *Sema::ActOnOpenMPUntiedClause(SourceLocation StartLoc, |
| 6548 | SourceLocation EndLoc) { |
| 6549 | return new (Context) OMPUntiedClause(StartLoc, EndLoc); |
| 6550 | } |
| 6551 | |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 6552 | OMPClause *Sema::ActOnOpenMPMergeableClause(SourceLocation StartLoc, |
| 6553 | SourceLocation EndLoc) { |
| 6554 | return new (Context) OMPMergeableClause(StartLoc, EndLoc); |
| 6555 | } |
| 6556 | |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6557 | OMPClause *Sema::ActOnOpenMPReadClause(SourceLocation StartLoc, |
| 6558 | SourceLocation EndLoc) { |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6559 | return new (Context) OMPReadClause(StartLoc, EndLoc); |
| 6560 | } |
| 6561 | |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6562 | OMPClause *Sema::ActOnOpenMPWriteClause(SourceLocation StartLoc, |
| 6563 | SourceLocation EndLoc) { |
| 6564 | return new (Context) OMPWriteClause(StartLoc, EndLoc); |
| 6565 | } |
| 6566 | |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6567 | OMPClause *Sema::ActOnOpenMPUpdateClause(SourceLocation StartLoc, |
| 6568 | SourceLocation EndLoc) { |
| 6569 | return new (Context) OMPUpdateClause(StartLoc, EndLoc); |
| 6570 | } |
| 6571 | |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6572 | OMPClause *Sema::ActOnOpenMPCaptureClause(SourceLocation StartLoc, |
| 6573 | SourceLocation EndLoc) { |
| 6574 | return new (Context) OMPCaptureClause(StartLoc, EndLoc); |
| 6575 | } |
| 6576 | |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 6577 | OMPClause *Sema::ActOnOpenMPSeqCstClause(SourceLocation StartLoc, |
| 6578 | SourceLocation EndLoc) { |
| 6579 | return new (Context) OMPSeqCstClause(StartLoc, EndLoc); |
| 6580 | } |
| 6581 | |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6582 | OMPClause *Sema::ActOnOpenMPThreadsClause(SourceLocation StartLoc, |
| 6583 | SourceLocation EndLoc) { |
| 6584 | return new (Context) OMPThreadsClause(StartLoc, EndLoc); |
| 6585 | } |
| 6586 | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6587 | OMPClause *Sema::ActOnOpenMPSIMDClause(SourceLocation StartLoc, |
| 6588 | SourceLocation EndLoc) { |
| 6589 | return new (Context) OMPSIMDClause(StartLoc, EndLoc); |
| 6590 | } |
| 6591 | |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 6592 | OMPClause *Sema::ActOnOpenMPNogroupClause(SourceLocation StartLoc, |
| 6593 | SourceLocation EndLoc) { |
| 6594 | return new (Context) OMPNogroupClause(StartLoc, EndLoc); |
| 6595 | } |
| 6596 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6597 | OMPClause *Sema::ActOnOpenMPVarListClause( |
| 6598 | OpenMPClauseKind Kind, ArrayRef<Expr *> VarList, Expr *TailExpr, |
| 6599 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, |
| 6600 | SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6601 | const DeclarationNameInfo &ReductionId, OpenMPDependClauseKind DepKind, |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 6602 | OpenMPLinearClauseKind LinKind, OpenMPMapClauseKind MapTypeModifier, |
| 6603 | OpenMPMapClauseKind MapType, bool IsMapTypeImplicit, |
| 6604 | SourceLocation DepLinMapLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6605 | OMPClause *Res = nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6606 | switch (Kind) { |
| 6607 | case OMPC_private: |
| 6608 | Res = ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 6609 | break; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6610 | case OMPC_firstprivate: |
| 6611 | Res = ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 6612 | break; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6613 | case OMPC_lastprivate: |
| 6614 | Res = ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 6615 | break; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6616 | case OMPC_shared: |
| 6617 | Res = ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 6618 | break; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6619 | case OMPC_reduction: |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 6620 | Res = ActOnOpenMPReductionClause(VarList, StartLoc, LParenLoc, ColonLoc, |
| 6621 | EndLoc, ReductionIdScopeSpec, ReductionId); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6622 | break; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6623 | case OMPC_linear: |
| 6624 | Res = ActOnOpenMPLinearClause(VarList, TailExpr, StartLoc, LParenLoc, |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 6625 | LinKind, DepLinMapLoc, ColonLoc, EndLoc); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6626 | break; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 6627 | case OMPC_aligned: |
| 6628 | Res = ActOnOpenMPAlignedClause(VarList, TailExpr, StartLoc, LParenLoc, |
| 6629 | ColonLoc, EndLoc); |
| 6630 | break; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6631 | case OMPC_copyin: |
| 6632 | Res = ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 6633 | break; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6634 | case OMPC_copyprivate: |
| 6635 | Res = ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 6636 | break; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 6637 | case OMPC_flush: |
| 6638 | Res = ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 6639 | break; |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6640 | case OMPC_depend: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 6641 | Res = ActOnOpenMPDependClause(DepKind, DepLinMapLoc, ColonLoc, VarList, |
| 6642 | StartLoc, LParenLoc, EndLoc); |
| 6643 | break; |
| 6644 | case OMPC_map: |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 6645 | Res = ActOnOpenMPMapClause(MapTypeModifier, MapType, IsMapTypeImplicit, |
| 6646 | DepLinMapLoc, ColonLoc, VarList, StartLoc, |
| 6647 | LParenLoc, EndLoc); |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6648 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6649 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 6650 | case OMPC_final: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6651 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6652 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 6653 | case OMPC_simdlen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6654 | case OMPC_collapse: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6655 | case OMPC_default: |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6656 | case OMPC_proc_bind: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6657 | case OMPC_schedule: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6658 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6659 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 6660 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 6661 | case OMPC_mergeable: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6662 | case OMPC_threadprivate: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6663 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6664 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6665 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6666 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 6667 | case OMPC_seq_cst: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 6668 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6669 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6670 | case OMPC_simd: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 6671 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6672 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6673 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 6674 | case OMPC_grainsize: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 6675 | case OMPC_nogroup: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6676 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 6677 | case OMPC_hint: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 6678 | case OMPC_dist_schedule: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6679 | case OMPC_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6680 | llvm_unreachable("Clause is not allowed."); |
| 6681 | } |
| 6682 | return Res; |
| 6683 | } |
| 6684 | |
| 6685 | OMPClause *Sema::ActOnOpenMPPrivateClause(ArrayRef<Expr *> VarList, |
| 6686 | SourceLocation StartLoc, |
| 6687 | SourceLocation LParenLoc, |
| 6688 | SourceLocation EndLoc) { |
| 6689 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 6690 | SmallVector<Expr *, 8> PrivateCopies; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6691 | for (auto &RefExpr : VarList) { |
| 6692 | assert(RefExpr && "NULL expr in OpenMP private clause."); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 6693 | if (RefExpr->isTypeDependent() || RefExpr->isValueDependent() || |
| 6694 | RefExpr->containsUnexpandedParameterPack()) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6695 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6696 | Vars.push_back(RefExpr); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 6697 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6698 | continue; |
| 6699 | } |
| 6700 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6701 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Carlo Bertolli | 9e8c6c1 | 2016-01-19 16:53:55 +0000 | [diff] [blame] | 6702 | // OpenMP [3.1, C/C++] |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6703 | // A list item is a variable name. |
| 6704 | // OpenMP [2.9.3.3, Restrictions, p.1] |
| 6705 | // A variable that is part of another variable (as an array or |
| 6706 | // structure element) cannot appear in a private clause. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 6707 | auto *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr->IgnoreParens()); |
| 6708 | auto *ME = dyn_cast_or_null<MemberExpr>(RefExpr->IgnoreParens()); |
| 6709 | if ((!DE || !isa<VarDecl>(DE->getDecl())) && |
| 6710 | (getCurrentThisType().isNull() || !ME || |
| 6711 | !isa<CXXThisExpr>(ME->getBase()->IgnoreParenImpCasts()) || |
| 6712 | !isa<FieldDecl>(ME->getMemberDecl()))) { |
| 6713 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr) |
| 6714 | << (getCurrentThisType().isNull() ? 0 : 1) |
| 6715 | << RefExpr->getSourceRange(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6716 | continue; |
| 6717 | } |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 6718 | ValueDecl *D = DE ? DE->getDecl() : ME->getMemberDecl(); |
| 6719 | QualType Type = D->getType(); |
| 6720 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6721 | |
| 6722 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 6723 | // A variable that appears in a private clause must not have an incomplete |
| 6724 | // type or a reference type. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 6725 | if (RequireCompleteType(ELoc, Type, diag::err_omp_private_incomplete_type)) |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6726 | continue; |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 6727 | Type = Type.getNonReferenceType(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6728 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6729 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 6730 | // in a Construct] |
| 6731 | // Variables with the predetermined data-sharing attributes may not be |
| 6732 | // listed in data-sharing attributes clauses, except for the cases |
| 6733 | // listed below. For these exceptions only, listing a predetermined |
| 6734 | // variable in a data-sharing attribute clause is allowed and overrides |
| 6735 | // the variable's predetermined data-sharing attributes. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 6736 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6737 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_private) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6738 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 6739 | << getOpenMPClauseName(OMPC_private); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 6740 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6741 | continue; |
| 6742 | } |
| 6743 | |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 6744 | // Variably modified types are not supported for tasks. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 6745 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType() && |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 6746 | DSAStack->getCurrentDirective() == OMPD_task) { |
| 6747 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
| 6748 | << getOpenMPClauseName(OMPC_private) << Type |
| 6749 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 6750 | bool IsDecl = |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 6751 | !VD || |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 6752 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 6753 | Diag(D->getLocation(), |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 6754 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 6755 | << D; |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 6756 | continue; |
| 6757 | } |
| 6758 | |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6759 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.1] |
| 6760 | // A variable of class type (or array thereof) that appears in a private |
| 6761 | // clause requires an accessible, unambiguous default constructor for the |
| 6762 | // class type. |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 6763 | // Generate helper private variable and initialize it with the default |
| 6764 | // value. The address of the original variable is replaced by the address of |
| 6765 | // the new private variable in CodeGen. This new variable is not added to |
| 6766 | // IdResolver, so the code in the OpenMP region uses original variable for |
| 6767 | // proper diagnostics. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6768 | Type = Type.getUnqualifiedType(); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 6769 | auto VDPrivate = buildVarDecl(*this, ELoc, Type, D->getName(), |
| 6770 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6771 | ActOnUninitializedDecl(VDPrivate, /*TypeMayContainAuto=*/false); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 6772 | if (VDPrivate->isInvalidDecl()) |
| 6773 | continue; |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6774 | auto VDPrivateRefExpr = buildDeclRefExpr( |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 6775 | *this, VDPrivate, RefExpr->getType().getUnqualifiedType(), ELoc); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 6776 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 6777 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_private); |
| 6778 | Vars.push_back(RefExpr->IgnoreParens()); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 6779 | PrivateCopies.push_back(VDPrivateRefExpr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6780 | } |
| 6781 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6782 | if (Vars.empty()) |
| 6783 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6784 | |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 6785 | return OMPPrivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
| 6786 | PrivateCopies); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6787 | } |
| 6788 | |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6789 | namespace { |
| 6790 | class DiagsUninitializedSeveretyRAII { |
| 6791 | private: |
| 6792 | DiagnosticsEngine &Diags; |
| 6793 | SourceLocation SavedLoc; |
| 6794 | bool IsIgnored; |
| 6795 | |
| 6796 | public: |
| 6797 | DiagsUninitializedSeveretyRAII(DiagnosticsEngine &Diags, SourceLocation Loc, |
| 6798 | bool IsIgnored) |
| 6799 | : Diags(Diags), SavedLoc(Loc), IsIgnored(IsIgnored) { |
| 6800 | if (!IsIgnored) { |
| 6801 | Diags.setSeverity(/*Diag*/ diag::warn_uninit_self_reference_in_init, |
| 6802 | /*Map*/ diag::Severity::Ignored, Loc); |
| 6803 | } |
| 6804 | } |
| 6805 | ~DiagsUninitializedSeveretyRAII() { |
| 6806 | if (!IsIgnored) |
| 6807 | Diags.popMappings(SavedLoc); |
| 6808 | } |
| 6809 | }; |
Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 6810 | } |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6811 | |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6812 | OMPClause *Sema::ActOnOpenMPFirstprivateClause(ArrayRef<Expr *> VarList, |
| 6813 | SourceLocation StartLoc, |
| 6814 | SourceLocation LParenLoc, |
| 6815 | SourceLocation EndLoc) { |
| 6816 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6817 | SmallVector<Expr *, 8> PrivateCopies; |
| 6818 | SmallVector<Expr *, 8> Inits; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6819 | bool IsImplicitClause = |
| 6820 | StartLoc.isInvalid() && LParenLoc.isInvalid() && EndLoc.isInvalid(); |
| 6821 | auto ImplicitClauseLoc = DSAStack->getConstructLoc(); |
| 6822 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6823 | for (auto &RefExpr : VarList) { |
| 6824 | assert(RefExpr && "NULL expr in OpenMP firstprivate clause."); |
| 6825 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6826 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6827 | Vars.push_back(RefExpr); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6828 | PrivateCopies.push_back(nullptr); |
| 6829 | Inits.push_back(nullptr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6830 | continue; |
| 6831 | } |
| 6832 | |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6833 | SourceLocation ELoc = |
| 6834 | IsImplicitClause ? ImplicitClauseLoc : RefExpr->getExprLoc(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6835 | // OpenMP [2.1, C/C++] |
| 6836 | // A list item is a variable name. |
| 6837 | // OpenMP [2.9.3.3, Restrictions, p.1] |
| 6838 | // A variable that is part of another variable (as an array or |
| 6839 | // structure element) cannot appear in a private clause. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6840 | DeclRefExpr *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6841 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 6842 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr) |
| 6843 | << 0 << RefExpr->getSourceRange(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6844 | continue; |
| 6845 | } |
| 6846 | Decl *D = DE->getDecl(); |
| 6847 | VarDecl *VD = cast<VarDecl>(D); |
| 6848 | |
| 6849 | QualType Type = VD->getType(); |
| 6850 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 6851 | // It will be analyzed later. |
| 6852 | Vars.push_back(DE); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6853 | PrivateCopies.push_back(nullptr); |
| 6854 | Inits.push_back(nullptr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6855 | continue; |
| 6856 | } |
| 6857 | |
| 6858 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 6859 | // A variable that appears in a private clause must not have an incomplete |
| 6860 | // type or a reference type. |
| 6861 | if (RequireCompleteType(ELoc, Type, |
| 6862 | diag::err_omp_firstprivate_incomplete_type)) { |
| 6863 | continue; |
| 6864 | } |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 6865 | Type = Type.getNonReferenceType(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6866 | |
| 6867 | // OpenMP [2.9.3.4, Restrictions, C/C++, p.1] |
| 6868 | // 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] | 6869 | // clause requires an accessible, unambiguous copy constructor for the |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6870 | // class type. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6871 | auto ElemType = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6872 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6873 | // If an implicit firstprivate variable found it was checked already. |
| 6874 | if (!IsImplicitClause) { |
| 6875 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6876 | bool IsConstant = ElemType.isConstant(Context); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6877 | // OpenMP [2.4.13, Data-sharing Attribute Clauses] |
| 6878 | // A list item that specifies a given variable may not appear in more |
| 6879 | // than one clause on the same directive, except that a variable may be |
| 6880 | // specified in both firstprivate and lastprivate clauses. |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6881 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_firstprivate && |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6882 | DVar.CKind != OMPC_lastprivate && DVar.RefExpr) { |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6883 | Diag(ELoc, diag::err_omp_wrong_dsa) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6884 | << getOpenMPClauseName(DVar.CKind) |
| 6885 | << getOpenMPClauseName(OMPC_firstprivate); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 6886 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6887 | continue; |
| 6888 | } |
| 6889 | |
| 6890 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 6891 | // in a Construct] |
| 6892 | // Variables with the predetermined data-sharing attributes may not be |
| 6893 | // listed in data-sharing attributes clauses, except for the cases |
| 6894 | // listed below. For these exceptions only, listing a predetermined |
| 6895 | // variable in a data-sharing attribute clause is allowed and overrides |
| 6896 | // the variable's predetermined data-sharing attributes. |
| 6897 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 6898 | // in a Construct, C/C++, p.2] |
| 6899 | // Variables with const-qualified type having no mutable member may be |
| 6900 | // listed in a firstprivate clause, even if they are static data members. |
| 6901 | if (!(IsConstant || VD->isStaticDataMember()) && !DVar.RefExpr && |
| 6902 | DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared) { |
| 6903 | Diag(ELoc, diag::err_omp_wrong_dsa) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6904 | << getOpenMPClauseName(DVar.CKind) |
| 6905 | << getOpenMPClauseName(OMPC_firstprivate); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 6906 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6907 | continue; |
| 6908 | } |
| 6909 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6910 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6911 | // OpenMP [2.9.3.4, Restrictions, p.2] |
| 6912 | // A list item that is private within a parallel region must not appear |
| 6913 | // in a firstprivate clause on a worksharing construct if any of the |
| 6914 | // worksharing regions arising from the worksharing construct ever bind |
| 6915 | // to any of the parallel regions arising from the parallel construct. |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 6916 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 6917 | !isOpenMPParallelDirective(CurrDir)) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6918 | DVar = DSAStack->getImplicitDSA(VD, true); |
| 6919 | if (DVar.CKind != OMPC_shared && |
| 6920 | (isOpenMPParallelDirective(DVar.DKind) || |
| 6921 | DVar.DKind == OMPD_unknown)) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6922 | Diag(ELoc, diag::err_omp_required_access) |
| 6923 | << getOpenMPClauseName(OMPC_firstprivate) |
| 6924 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 6925 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6926 | continue; |
| 6927 | } |
| 6928 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6929 | // OpenMP [2.9.3.4, Restrictions, p.3] |
| 6930 | // A list item that appears in a reduction clause of a parallel construct |
| 6931 | // must not appear in a firstprivate clause on a worksharing or task |
| 6932 | // construct if any of the worksharing or task regions arising from the |
| 6933 | // worksharing or task construct ever bind to any of the parallel regions |
| 6934 | // arising from the parallel construct. |
| 6935 | // OpenMP [2.9.3.4, Restrictions, p.4] |
| 6936 | // A list item that appears in a reduction clause in worksharing |
| 6937 | // construct must not appear in a firstprivate clause in a task construct |
| 6938 | // encountered during execution of any of the worksharing regions arising |
| 6939 | // from the worksharing construct. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6940 | if (CurrDir == OMPD_task) { |
| 6941 | DVar = |
| 6942 | DSAStack->hasInnermostDSA(VD, MatchesAnyClause(OMPC_reduction), |
| 6943 | [](OpenMPDirectiveKind K) -> bool { |
| 6944 | return isOpenMPParallelDirective(K) || |
| 6945 | isOpenMPWorksharingDirective(K); |
| 6946 | }, |
| 6947 | false); |
| 6948 | if (DVar.CKind == OMPC_reduction && |
| 6949 | (isOpenMPParallelDirective(DVar.DKind) || |
| 6950 | isOpenMPWorksharingDirective(DVar.DKind))) { |
| 6951 | Diag(ELoc, diag::err_omp_parallel_reduction_in_task_firstprivate) |
| 6952 | << getOpenMPDirectiveName(DVar.DKind); |
| 6953 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 6954 | continue; |
| 6955 | } |
| 6956 | } |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 6957 | |
| 6958 | // OpenMP 4.5 [2.15.3.4, Restrictions, p.3] |
| 6959 | // A list item that is private within a teams region must not appear in a |
| 6960 | // firstprivate clause on a distribute construct if any of the distribute |
| 6961 | // regions arising from the distribute construct ever bind to any of the |
| 6962 | // teams regions arising from the teams construct. |
| 6963 | // OpenMP 4.5 [2.15.3.4, Restrictions, p.3] |
| 6964 | // A list item that appears in a reduction clause of a teams construct |
| 6965 | // must not appear in a firstprivate clause on a distribute construct if |
| 6966 | // any of the distribute regions arising from the distribute construct |
| 6967 | // ever bind to any of the teams regions arising from the teams construct. |
| 6968 | // OpenMP 4.5 [2.10.8, Distribute Construct, p.3] |
| 6969 | // A list item may appear in a firstprivate or lastprivate clause but not |
| 6970 | // both. |
| 6971 | if (CurrDir == OMPD_distribute) { |
| 6972 | DVar = DSAStack->hasInnermostDSA(VD, MatchesAnyClause(OMPC_private), |
| 6973 | [](OpenMPDirectiveKind K) -> bool { |
| 6974 | return isOpenMPTeamsDirective(K); |
| 6975 | }, |
| 6976 | false); |
| 6977 | if (DVar.CKind == OMPC_private && isOpenMPTeamsDirective(DVar.DKind)) { |
| 6978 | Diag(ELoc, diag::err_omp_firstprivate_distribute_private_teams); |
| 6979 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 6980 | continue; |
| 6981 | } |
| 6982 | DVar = DSAStack->hasInnermostDSA(VD, MatchesAnyClause(OMPC_reduction), |
| 6983 | [](OpenMPDirectiveKind K) -> bool { |
| 6984 | return isOpenMPTeamsDirective(K); |
| 6985 | }, |
| 6986 | false); |
| 6987 | if (DVar.CKind == OMPC_reduction && |
| 6988 | isOpenMPTeamsDirective(DVar.DKind)) { |
| 6989 | Diag(ELoc, diag::err_omp_firstprivate_distribute_in_teams_reduction); |
| 6990 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 6991 | continue; |
| 6992 | } |
| 6993 | DVar = DSAStack->getTopDSA(VD, false); |
| 6994 | if (DVar.CKind == OMPC_lastprivate) { |
| 6995 | Diag(ELoc, diag::err_omp_firstprivate_and_lastprivate_in_distribute); |
| 6996 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 6997 | continue; |
| 6998 | } |
| 6999 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7000 | } |
| 7001 | |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7002 | // Variably modified types are not supported for tasks. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 7003 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType() && |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7004 | DSAStack->getCurrentDirective() == OMPD_task) { |
| 7005 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
| 7006 | << getOpenMPClauseName(OMPC_firstprivate) << Type |
| 7007 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 7008 | bool IsDecl = |
| 7009 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 7010 | Diag(VD->getLocation(), |
| 7011 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7012 | << VD; |
| 7013 | continue; |
| 7014 | } |
| 7015 | |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7016 | Type = Type.getUnqualifiedType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 7017 | auto VDPrivate = buildVarDecl(*this, ELoc, Type, VD->getName(), |
| 7018 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7019 | // Generate helper private variable and initialize it with the value of the |
| 7020 | // original variable. The address of the original variable is replaced by |
| 7021 | // the address of the new private variable in the CodeGen. This new variable |
| 7022 | // is not added to IdResolver, so the code in the OpenMP region uses |
| 7023 | // original variable for proper diagnostics and variable capturing. |
| 7024 | Expr *VDInitRefExpr = nullptr; |
| 7025 | // For arrays generate initializer for single element and replace it by the |
| 7026 | // original array element in CodeGen. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7027 | if (Type->isArrayType()) { |
| 7028 | auto VDInit = |
| 7029 | buildVarDecl(*this, DE->getExprLoc(), ElemType, VD->getName()); |
| 7030 | VDInitRefExpr = buildDeclRefExpr(*this, VDInit, ElemType, ELoc); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7031 | auto Init = DefaultLvalueConversion(VDInitRefExpr).get(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7032 | ElemType = ElemType.getUnqualifiedType(); |
| 7033 | auto *VDInitTemp = buildVarDecl(*this, DE->getLocStart(), ElemType, |
| 7034 | ".firstprivate.temp"); |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 7035 | InitializedEntity Entity = |
| 7036 | InitializedEntity::InitializeVariable(VDInitTemp); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7037 | InitializationKind Kind = InitializationKind::CreateCopy(ELoc, ELoc); |
| 7038 | |
| 7039 | InitializationSequence InitSeq(*this, Entity, Kind, Init); |
| 7040 | ExprResult Result = InitSeq.Perform(*this, Entity, Kind, Init); |
| 7041 | if (Result.isInvalid()) |
| 7042 | VDPrivate->setInvalidDecl(); |
| 7043 | else |
| 7044 | VDPrivate->setInit(Result.getAs<Expr>()); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7045 | // Remove temp variable declaration. |
| 7046 | Context.Deallocate(VDInitTemp); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7047 | } else { |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 7048 | auto *VDInit = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7049 | buildVarDecl(*this, DE->getLocStart(), Type, ".firstprivate.temp"); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7050 | VDInitRefExpr = |
| 7051 | buildDeclRefExpr(*this, VDInit, DE->getType(), DE->getExprLoc()); |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 7052 | AddInitializerToDecl(VDPrivate, |
| 7053 | DefaultLvalueConversion(VDInitRefExpr).get(), |
| 7054 | /*DirectInit=*/false, /*TypeMayContainAuto=*/false); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7055 | } |
| 7056 | if (VDPrivate->isInvalidDecl()) { |
| 7057 | if (IsImplicitClause) { |
| 7058 | Diag(DE->getExprLoc(), |
| 7059 | diag::note_omp_task_predetermined_firstprivate_here); |
| 7060 | } |
| 7061 | continue; |
| 7062 | } |
| 7063 | CurContext->addDecl(VDPrivate); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7064 | auto VDPrivateRefExpr = buildDeclRefExpr( |
| 7065 | *this, VDPrivate, DE->getType().getUnqualifiedType(), DE->getExprLoc()); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7066 | DSAStack->addDSA(VD, DE, OMPC_firstprivate); |
| 7067 | Vars.push_back(DE); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7068 | PrivateCopies.push_back(VDPrivateRefExpr); |
| 7069 | Inits.push_back(VDInitRefExpr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7070 | } |
| 7071 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7072 | if (Vars.empty()) |
| 7073 | return nullptr; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7074 | |
| 7075 | return OMPFirstprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7076 | Vars, PrivateCopies, Inits); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7077 | } |
| 7078 | |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7079 | OMPClause *Sema::ActOnOpenMPLastprivateClause(ArrayRef<Expr *> VarList, |
| 7080 | SourceLocation StartLoc, |
| 7081 | SourceLocation LParenLoc, |
| 7082 | SourceLocation EndLoc) { |
| 7083 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7084 | SmallVector<Expr *, 8> SrcExprs; |
| 7085 | SmallVector<Expr *, 8> DstExprs; |
| 7086 | SmallVector<Expr *, 8> AssignmentOps; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7087 | for (auto &RefExpr : VarList) { |
| 7088 | assert(RefExpr && "NULL expr in OpenMP lastprivate clause."); |
| 7089 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 7090 | // It will be analyzed later. |
| 7091 | Vars.push_back(RefExpr); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7092 | SrcExprs.push_back(nullptr); |
| 7093 | DstExprs.push_back(nullptr); |
| 7094 | AssignmentOps.push_back(nullptr); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7095 | continue; |
| 7096 | } |
| 7097 | |
| 7098 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 7099 | // OpenMP [2.1, C/C++] |
| 7100 | // A list item is a variable name. |
| 7101 | // OpenMP [2.14.3.5, Restrictions, p.1] |
| 7102 | // A variable that is part of another variable (as an array or structure |
| 7103 | // element) cannot appear in a lastprivate clause. |
| 7104 | DeclRefExpr *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr); |
| 7105 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7106 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr) |
| 7107 | << 0 << RefExpr->getSourceRange(); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7108 | continue; |
| 7109 | } |
| 7110 | Decl *D = DE->getDecl(); |
| 7111 | VarDecl *VD = cast<VarDecl>(D); |
| 7112 | |
| 7113 | QualType Type = VD->getType(); |
| 7114 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 7115 | // It will be analyzed later. |
| 7116 | Vars.push_back(DE); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7117 | SrcExprs.push_back(nullptr); |
| 7118 | DstExprs.push_back(nullptr); |
| 7119 | AssignmentOps.push_back(nullptr); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7120 | continue; |
| 7121 | } |
| 7122 | |
| 7123 | // OpenMP [2.14.3.5, Restrictions, C/C++, p.2] |
| 7124 | // A variable that appears in a lastprivate clause must not have an |
| 7125 | // incomplete type or a reference type. |
| 7126 | if (RequireCompleteType(ELoc, Type, |
| 7127 | diag::err_omp_lastprivate_incomplete_type)) { |
| 7128 | continue; |
| 7129 | } |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7130 | Type = Type.getNonReferenceType(); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7131 | |
| 7132 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 7133 | // in a Construct] |
| 7134 | // Variables with the predetermined data-sharing attributes may not be |
| 7135 | // listed in data-sharing attributes clauses, except for the cases |
| 7136 | // listed below. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7137 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7138 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_lastprivate && |
| 7139 | DVar.CKind != OMPC_firstprivate && |
| 7140 | (DVar.CKind != OMPC_private || DVar.RefExpr != nullptr)) { |
| 7141 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 7142 | << getOpenMPClauseName(DVar.CKind) |
| 7143 | << getOpenMPClauseName(OMPC_lastprivate); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 7144 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7145 | continue; |
| 7146 | } |
| 7147 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7148 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
| 7149 | // OpenMP [2.14.3.5, Restrictions, p.2] |
| 7150 | // A list item that is private within a parallel region, or that appears in |
| 7151 | // the reduction clause of a parallel construct, must not appear in a |
| 7152 | // lastprivate clause on a worksharing construct if any of the corresponding |
| 7153 | // worksharing regions ever binds to any of the corresponding parallel |
| 7154 | // regions. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7155 | DSAStackTy::DSAVarData TopDVar = DVar; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 7156 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 7157 | !isOpenMPParallelDirective(CurrDir)) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7158 | DVar = DSAStack->getImplicitDSA(VD, true); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7159 | if (DVar.CKind != OMPC_shared) { |
| 7160 | Diag(ELoc, diag::err_omp_required_access) |
| 7161 | << getOpenMPClauseName(OMPC_lastprivate) |
| 7162 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 7163 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7164 | continue; |
| 7165 | } |
| 7166 | } |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7167 | // OpenMP [2.14.3.5, Restrictions, C++, p.1,2] |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7168 | // A variable of class type (or array thereof) that appears in a |
| 7169 | // lastprivate clause requires an accessible, unambiguous default |
| 7170 | // constructor for the class type, unless the list item is also specified |
| 7171 | // in a firstprivate clause. |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7172 | // A variable of class type (or array thereof) that appears in a |
| 7173 | // lastprivate clause requires an accessible, unambiguous copy assignment |
| 7174 | // operator for the class type. |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7175 | Type = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7176 | auto *SrcVD = buildVarDecl(*this, DE->getLocStart(), |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 7177 | Type.getUnqualifiedType(), ".lastprivate.src", |
| 7178 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7179 | auto *PseudoSrcExpr = buildDeclRefExpr( |
| 7180 | *this, SrcVD, Type.getUnqualifiedType(), DE->getExprLoc()); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7181 | auto *DstVD = |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 7182 | buildVarDecl(*this, DE->getLocStart(), Type, ".lastprivate.dst", |
| 7183 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7184 | auto *PseudoDstExpr = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7185 | buildDeclRefExpr(*this, DstVD, Type, DE->getExprLoc()); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7186 | // For arrays generate assignment operation for single element and replace |
| 7187 | // it by the original array element in CodeGen. |
| 7188 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, DE->getExprLoc(), BO_Assign, |
| 7189 | PseudoDstExpr, PseudoSrcExpr); |
| 7190 | if (AssignmentOp.isInvalid()) |
| 7191 | continue; |
| 7192 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), DE->getExprLoc(), |
| 7193 | /*DiscardedValue=*/true); |
| 7194 | if (AssignmentOp.isInvalid()) |
| 7195 | continue; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7196 | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7197 | // OpenMP 4.5 [2.10.8, Distribute Construct, p.3] |
| 7198 | // A list item may appear in a firstprivate or lastprivate clause but not |
| 7199 | // both. |
| 7200 | if (CurrDir == OMPD_distribute) { |
| 7201 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
| 7202 | if (DVar.CKind == OMPC_firstprivate) { |
| 7203 | Diag(ELoc, diag::err_omp_firstprivate_and_lastprivate_in_distribute); |
| 7204 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 7205 | continue; |
| 7206 | } |
| 7207 | } |
| 7208 | |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7209 | if (TopDVar.CKind != OMPC_firstprivate) |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7210 | DSAStack->addDSA(VD, DE, OMPC_lastprivate); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7211 | Vars.push_back(DE); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7212 | SrcExprs.push_back(PseudoSrcExpr); |
| 7213 | DstExprs.push_back(PseudoDstExpr); |
| 7214 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7215 | } |
| 7216 | |
| 7217 | if (Vars.empty()) |
| 7218 | return nullptr; |
| 7219 | |
| 7220 | return OMPLastprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7221 | Vars, SrcExprs, DstExprs, AssignmentOps); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7222 | } |
| 7223 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7224 | OMPClause *Sema::ActOnOpenMPSharedClause(ArrayRef<Expr *> VarList, |
| 7225 | SourceLocation StartLoc, |
| 7226 | SourceLocation LParenLoc, |
| 7227 | SourceLocation EndLoc) { |
| 7228 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7229 | for (auto &RefExpr : VarList) { |
| 7230 | assert(RefExpr && "NULL expr in OpenMP shared clause."); |
| 7231 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7232 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7233 | Vars.push_back(RefExpr); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7234 | continue; |
| 7235 | } |
| 7236 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7237 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7238 | // OpenMP [2.1, C/C++] |
| 7239 | // A list item is a variable name. |
Alexey Bataev | d4dbdf5 | 2014-03-06 12:27:56 +0000 | [diff] [blame] | 7240 | // OpenMP [2.14.3.2, Restrictions, p.1] |
| 7241 | // A variable that is part of another variable (as an array or structure |
| 7242 | // element) cannot appear in a shared unless it is a static data member |
| 7243 | // of a C++ class. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7244 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7245 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7246 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr) |
| 7247 | << 0 << RefExpr->getSourceRange(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7248 | continue; |
| 7249 | } |
| 7250 | Decl *D = DE->getDecl(); |
| 7251 | VarDecl *VD = cast<VarDecl>(D); |
| 7252 | |
| 7253 | QualType Type = VD->getType(); |
| 7254 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 7255 | // It will be analyzed later. |
| 7256 | Vars.push_back(DE); |
| 7257 | continue; |
| 7258 | } |
| 7259 | |
| 7260 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 7261 | // in a Construct] |
| 7262 | // Variables with the predetermined data-sharing attributes may not be |
| 7263 | // listed in data-sharing attributes clauses, except for the cases |
| 7264 | // listed below. For these exceptions only, listing a predetermined |
| 7265 | // variable in a data-sharing attribute clause is allowed and overrides |
| 7266 | // the variable's predetermined data-sharing attributes. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7267 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7268 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared && |
| 7269 | DVar.RefExpr) { |
| 7270 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 7271 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 7272 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7273 | continue; |
| 7274 | } |
| 7275 | |
| 7276 | DSAStack->addDSA(VD, DE, OMPC_shared); |
| 7277 | Vars.push_back(DE); |
| 7278 | } |
| 7279 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7280 | if (Vars.empty()) |
| 7281 | return nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7282 | |
| 7283 | return OMPSharedClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars); |
| 7284 | } |
| 7285 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7286 | namespace { |
| 7287 | class DSARefChecker : public StmtVisitor<DSARefChecker, bool> { |
| 7288 | DSAStackTy *Stack; |
| 7289 | |
| 7290 | public: |
| 7291 | bool VisitDeclRefExpr(DeclRefExpr *E) { |
| 7292 | if (VarDecl *VD = dyn_cast<VarDecl>(E->getDecl())) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7293 | DSAStackTy::DSAVarData DVar = Stack->getTopDSA(VD, false); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7294 | if (DVar.CKind == OMPC_shared && !DVar.RefExpr) |
| 7295 | return false; |
| 7296 | if (DVar.CKind != OMPC_unknown) |
| 7297 | return true; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7298 | DSAStackTy::DSAVarData DVarPrivate = |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7299 | Stack->hasDSA(VD, isOpenMPPrivate, MatchesAlways(), false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7300 | if (DVarPrivate.CKind != OMPC_unknown) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7301 | return true; |
| 7302 | return false; |
| 7303 | } |
| 7304 | return false; |
| 7305 | } |
| 7306 | bool VisitStmt(Stmt *S) { |
| 7307 | for (auto Child : S->children()) { |
| 7308 | if (Child && Visit(Child)) |
| 7309 | return true; |
| 7310 | } |
| 7311 | return false; |
| 7312 | } |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 7313 | explicit DSARefChecker(DSAStackTy *S) : Stack(S) {} |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7314 | }; |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 7315 | } // namespace |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7316 | |
| 7317 | OMPClause *Sema::ActOnOpenMPReductionClause( |
| 7318 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, SourceLocation LParenLoc, |
| 7319 | SourceLocation ColonLoc, SourceLocation EndLoc, |
| 7320 | CXXScopeSpec &ReductionIdScopeSpec, |
| 7321 | const DeclarationNameInfo &ReductionId) { |
| 7322 | // TODO: Allow scope specification search when 'declare reduction' is |
| 7323 | // supported. |
| 7324 | assert(ReductionIdScopeSpec.isEmpty() && |
| 7325 | "No support for scoped reduction identifiers yet."); |
| 7326 | |
| 7327 | auto DN = ReductionId.getName(); |
| 7328 | auto OOK = DN.getCXXOverloadedOperator(); |
| 7329 | BinaryOperatorKind BOK = BO_Comma; |
| 7330 | |
| 7331 | // OpenMP [2.14.3.6, reduction clause] |
| 7332 | // C |
| 7333 | // reduction-identifier is either an identifier or one of the following |
| 7334 | // operators: +, -, *, &, |, ^, && and || |
| 7335 | // C++ |
| 7336 | // reduction-identifier is either an id-expression or one of the following |
| 7337 | // operators: +, -, *, &, |, ^, && and || |
| 7338 | // FIXME: Only 'min' and 'max' identifiers are supported for now. |
| 7339 | switch (OOK) { |
| 7340 | case OO_Plus: |
| 7341 | case OO_Minus: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7342 | BOK = BO_Add; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7343 | break; |
| 7344 | case OO_Star: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7345 | BOK = BO_Mul; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7346 | break; |
| 7347 | case OO_Amp: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7348 | BOK = BO_And; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7349 | break; |
| 7350 | case OO_Pipe: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7351 | BOK = BO_Or; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7352 | break; |
| 7353 | case OO_Caret: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7354 | BOK = BO_Xor; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7355 | break; |
| 7356 | case OO_AmpAmp: |
| 7357 | BOK = BO_LAnd; |
| 7358 | break; |
| 7359 | case OO_PipePipe: |
| 7360 | BOK = BO_LOr; |
| 7361 | break; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7362 | case OO_New: |
| 7363 | case OO_Delete: |
| 7364 | case OO_Array_New: |
| 7365 | case OO_Array_Delete: |
| 7366 | case OO_Slash: |
| 7367 | case OO_Percent: |
| 7368 | case OO_Tilde: |
| 7369 | case OO_Exclaim: |
| 7370 | case OO_Equal: |
| 7371 | case OO_Less: |
| 7372 | case OO_Greater: |
| 7373 | case OO_LessEqual: |
| 7374 | case OO_GreaterEqual: |
| 7375 | case OO_PlusEqual: |
| 7376 | case OO_MinusEqual: |
| 7377 | case OO_StarEqual: |
| 7378 | case OO_SlashEqual: |
| 7379 | case OO_PercentEqual: |
| 7380 | case OO_CaretEqual: |
| 7381 | case OO_AmpEqual: |
| 7382 | case OO_PipeEqual: |
| 7383 | case OO_LessLess: |
| 7384 | case OO_GreaterGreater: |
| 7385 | case OO_LessLessEqual: |
| 7386 | case OO_GreaterGreaterEqual: |
| 7387 | case OO_EqualEqual: |
| 7388 | case OO_ExclaimEqual: |
| 7389 | case OO_PlusPlus: |
| 7390 | case OO_MinusMinus: |
| 7391 | case OO_Comma: |
| 7392 | case OO_ArrowStar: |
| 7393 | case OO_Arrow: |
| 7394 | case OO_Call: |
| 7395 | case OO_Subscript: |
| 7396 | case OO_Conditional: |
Richard Smith | 9be594e | 2015-10-22 05:12:22 +0000 | [diff] [blame] | 7397 | case OO_Coawait: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7398 | case NUM_OVERLOADED_OPERATORS: |
| 7399 | llvm_unreachable("Unexpected reduction identifier"); |
| 7400 | case OO_None: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7401 | if (auto II = DN.getAsIdentifierInfo()) { |
| 7402 | if (II->isStr("max")) |
| 7403 | BOK = BO_GT; |
| 7404 | else if (II->isStr("min")) |
| 7405 | BOK = BO_LT; |
| 7406 | } |
| 7407 | break; |
| 7408 | } |
| 7409 | SourceRange ReductionIdRange; |
| 7410 | if (ReductionIdScopeSpec.isValid()) { |
| 7411 | ReductionIdRange.setBegin(ReductionIdScopeSpec.getBeginLoc()); |
| 7412 | } |
| 7413 | ReductionIdRange.setEnd(ReductionId.getEndLoc()); |
| 7414 | if (BOK == BO_Comma) { |
| 7415 | // Not allowed reduction identifier is found. |
| 7416 | Diag(ReductionId.getLocStart(), diag::err_omp_unknown_reduction_identifier) |
| 7417 | << ReductionIdRange; |
| 7418 | return nullptr; |
| 7419 | } |
| 7420 | |
| 7421 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7422 | SmallVector<Expr *, 8> Privates; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7423 | SmallVector<Expr *, 8> LHSs; |
| 7424 | SmallVector<Expr *, 8> RHSs; |
| 7425 | SmallVector<Expr *, 8> ReductionOps; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7426 | for (auto RefExpr : VarList) { |
| 7427 | assert(RefExpr && "nullptr expr in OpenMP reduction clause."); |
| 7428 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 7429 | // It will be analyzed later. |
| 7430 | Vars.push_back(RefExpr); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7431 | Privates.push_back(nullptr); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7432 | LHSs.push_back(nullptr); |
| 7433 | RHSs.push_back(nullptr); |
| 7434 | ReductionOps.push_back(nullptr); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7435 | continue; |
| 7436 | } |
| 7437 | |
| 7438 | if (RefExpr->isTypeDependent() || RefExpr->isValueDependent() || |
| 7439 | RefExpr->isInstantiationDependent() || |
| 7440 | RefExpr->containsUnexpandedParameterPack()) { |
| 7441 | // It will be analyzed later. |
| 7442 | Vars.push_back(RefExpr); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7443 | Privates.push_back(nullptr); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7444 | LHSs.push_back(nullptr); |
| 7445 | RHSs.push_back(nullptr); |
| 7446 | ReductionOps.push_back(nullptr); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7447 | continue; |
| 7448 | } |
| 7449 | |
| 7450 | auto ELoc = RefExpr->getExprLoc(); |
| 7451 | auto ERange = RefExpr->getSourceRange(); |
| 7452 | // OpenMP [2.1, C/C++] |
| 7453 | // A list item is a variable or array section, subject to the restrictions |
| 7454 | // specified in Section 2.4 on page 42 and in each of the sections |
| 7455 | // describing clauses and directives for which a list appears. |
| 7456 | // OpenMP [2.14.3.3, Restrictions, p.1] |
| 7457 | // A variable that is part of another variable (as an array or |
| 7458 | // structure element) cannot appear in a private clause. |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7459 | auto *DE = dyn_cast<DeclRefExpr>(RefExpr); |
| 7460 | auto *ASE = dyn_cast<ArraySubscriptExpr>(RefExpr); |
| 7461 | auto *OASE = dyn_cast<OMPArraySectionExpr>(RefExpr); |
| 7462 | if (!ASE && !OASE && (!DE || !isa<VarDecl>(DE->getDecl()))) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7463 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr_or_array_item) |
| 7464 | << 0 << ERange; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7465 | continue; |
| 7466 | } |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7467 | QualType Type; |
| 7468 | VarDecl *VD = nullptr; |
| 7469 | if (DE) { |
| 7470 | auto D = DE->getDecl(); |
| 7471 | VD = cast<VarDecl>(D); |
Alexey Bataev | 1189bd0 | 2016-01-26 12:20:39 +0000 | [diff] [blame^] | 7472 | Type = Context.getBaseElementType(VD->getType()); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7473 | } else if (ASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7474 | Type = ASE->getType(); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7475 | auto *Base = ASE->getBase()->IgnoreParenImpCasts(); |
| 7476 | while (auto *TempASE = dyn_cast<ArraySubscriptExpr>(Base)) |
| 7477 | Base = TempASE->getBase()->IgnoreParenImpCasts(); |
| 7478 | DE = dyn_cast<DeclRefExpr>(Base); |
| 7479 | if (DE) |
| 7480 | VD = dyn_cast<VarDecl>(DE->getDecl()); |
| 7481 | if (!VD) { |
| 7482 | Diag(Base->getExprLoc(), diag::err_omp_expected_base_var_name) |
| 7483 | << 0 << Base->getSourceRange(); |
| 7484 | continue; |
| 7485 | } |
| 7486 | } else if (OASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7487 | auto BaseType = OMPArraySectionExpr::getBaseOriginalType(OASE->getBase()); |
| 7488 | if (auto *ATy = BaseType->getAsArrayTypeUnsafe()) |
| 7489 | Type = ATy->getElementType(); |
| 7490 | else |
| 7491 | Type = BaseType->getPointeeType(); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7492 | auto *Base = OASE->getBase()->IgnoreParenImpCasts(); |
| 7493 | while (auto *TempOASE = dyn_cast<OMPArraySectionExpr>(Base)) |
| 7494 | Base = TempOASE->getBase()->IgnoreParenImpCasts(); |
| 7495 | while (auto *TempASE = dyn_cast<ArraySubscriptExpr>(Base)) |
| 7496 | Base = TempASE->getBase()->IgnoreParenImpCasts(); |
| 7497 | DE = dyn_cast<DeclRefExpr>(Base); |
| 7498 | if (DE) |
| 7499 | VD = dyn_cast<VarDecl>(DE->getDecl()); |
| 7500 | if (!VD) { |
| 7501 | Diag(Base->getExprLoc(), diag::err_omp_expected_base_var_name) |
| 7502 | << 1 << Base->getSourceRange(); |
| 7503 | continue; |
| 7504 | } |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7505 | } |
| 7506 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7507 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 7508 | // A variable that appears in a private clause must not have an incomplete |
| 7509 | // type or a reference type. |
| 7510 | if (RequireCompleteType(ELoc, Type, |
| 7511 | diag::err_omp_reduction_incomplete_type)) |
| 7512 | continue; |
| 7513 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7514 | // A list item that appears in a reduction clause must not be |
| 7515 | // const-qualified. |
| 7516 | if (Type.getNonReferenceType().isConstant(Context)) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7517 | Diag(ELoc, diag::err_omp_const_reduction_list_item) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7518 | << getOpenMPClauseName(OMPC_reduction) << Type << ERange; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7519 | if (!ASE && !OASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7520 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 7521 | VarDecl::DeclarationOnly; |
| 7522 | Diag(VD->getLocation(), |
| 7523 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7524 | << VD; |
| 7525 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7526 | continue; |
| 7527 | } |
| 7528 | // OpenMP [2.9.3.6, Restrictions, C/C++, p.4] |
| 7529 | // If a list-item is a reference type then it must bind to the same object |
| 7530 | // for all threads of the team. |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7531 | if (!ASE && !OASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7532 | VarDecl *VDDef = VD->getDefinition(); |
| 7533 | if (Type->isReferenceType() && VDDef) { |
| 7534 | DSARefChecker Check(DSAStack); |
| 7535 | if (Check.Visit(VDDef->getInit())) { |
| 7536 | Diag(ELoc, diag::err_omp_reduction_ref_type_arg) << ERange; |
| 7537 | Diag(VDDef->getLocation(), diag::note_defined_here) << VDDef; |
| 7538 | continue; |
| 7539 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7540 | } |
| 7541 | } |
| 7542 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
| 7543 | // The type of a list item that appears in a reduction clause must be valid |
| 7544 | // for the reduction-identifier. For a max or min reduction in C, the type |
| 7545 | // of the list item must be an allowed arithmetic data type: char, int, |
| 7546 | // float, double, or _Bool, possibly modified with long, short, signed, or |
| 7547 | // unsigned. For a max or min reduction in C++, the type of the list item |
| 7548 | // must be an allowed arithmetic data type: char, wchar_t, int, float, |
| 7549 | // double, or bool, possibly modified with long, short, signed, or unsigned. |
| 7550 | if ((BOK == BO_GT || BOK == BO_LT) && |
| 7551 | !(Type->isScalarType() || |
| 7552 | (getLangOpts().CPlusPlus && Type->isArithmeticType()))) { |
| 7553 | Diag(ELoc, diag::err_omp_clause_not_arithmetic_type_arg) |
| 7554 | << getLangOpts().CPlusPlus; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7555 | if (!ASE && !OASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7556 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 7557 | VarDecl::DeclarationOnly; |
| 7558 | Diag(VD->getLocation(), |
| 7559 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7560 | << VD; |
| 7561 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7562 | continue; |
| 7563 | } |
| 7564 | if ((BOK == BO_OrAssign || BOK == BO_AndAssign || BOK == BO_XorAssign) && |
| 7565 | !getLangOpts().CPlusPlus && Type->isFloatingType()) { |
| 7566 | Diag(ELoc, diag::err_omp_clause_floating_type_arg); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7567 | if (!ASE && !OASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7568 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 7569 | VarDecl::DeclarationOnly; |
| 7570 | Diag(VD->getLocation(), |
| 7571 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7572 | << VD; |
| 7573 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7574 | continue; |
| 7575 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7576 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 7577 | // in a Construct] |
| 7578 | // Variables with the predetermined data-sharing attributes may not be |
| 7579 | // listed in data-sharing attributes clauses, except for the cases |
| 7580 | // listed below. For these exceptions only, listing a predetermined |
| 7581 | // variable in a data-sharing attribute clause is allowed and overrides |
| 7582 | // the variable's predetermined data-sharing attributes. |
| 7583 | // OpenMP [2.14.3.6, Restrictions, p.3] |
| 7584 | // Any number of reduction clauses can be specified on the directive, |
| 7585 | // but a list item can appear only once in the reduction clauses for that |
| 7586 | // directive. |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7587 | DSAStackTy::DSAVarData DVar; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7588 | DVar = DSAStack->getTopDSA(VD, false); |
| 7589 | if (DVar.CKind == OMPC_reduction) { |
| 7590 | Diag(ELoc, diag::err_omp_once_referenced) |
| 7591 | << getOpenMPClauseName(OMPC_reduction); |
| 7592 | if (DVar.RefExpr) { |
| 7593 | Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_referenced); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7594 | } |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7595 | } else if (DVar.CKind != OMPC_unknown) { |
| 7596 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 7597 | << getOpenMPClauseName(DVar.CKind) |
| 7598 | << getOpenMPClauseName(OMPC_reduction); |
| 7599 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 7600 | continue; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7601 | } |
| 7602 | |
| 7603 | // OpenMP [2.14.3.6, Restrictions, p.1] |
| 7604 | // A list item that appears in a reduction clause of a worksharing |
| 7605 | // construct must be shared in the parallel regions to which any of the |
| 7606 | // worksharing regions arising from the worksharing construct bind. |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7607 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
| 7608 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 7609 | !isOpenMPParallelDirective(CurrDir)) { |
| 7610 | DVar = DSAStack->getImplicitDSA(VD, true); |
| 7611 | if (DVar.CKind != OMPC_shared) { |
| 7612 | Diag(ELoc, diag::err_omp_required_access) |
| 7613 | << getOpenMPClauseName(OMPC_reduction) |
| 7614 | << getOpenMPClauseName(OMPC_shared); |
| 7615 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 7616 | continue; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7617 | } |
| 7618 | } |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7619 | |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7620 | Type = Type.getNonLValueExprType(Context).getUnqualifiedType(); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7621 | auto *LHSVD = buildVarDecl(*this, ELoc, Type, ".reduction.lhs", |
| 7622 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
| 7623 | auto *RHSVD = buildVarDecl(*this, ELoc, Type, VD->getName(), |
| 7624 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
| 7625 | auto PrivateTy = Type; |
Alexey Bataev | 1189bd0 | 2016-01-26 12:20:39 +0000 | [diff] [blame^] | 7626 | if (OASE || |
| 7627 | (DE && VD->getType().getNonReferenceType()->isVariablyModifiedType())) { |
| 7628 | // For arays/array sections only: |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7629 | // Create pseudo array type for private copy. The size for this array will |
| 7630 | // be generated during codegen. |
| 7631 | // For array subscripts or single variables Private Ty is the same as Type |
| 7632 | // (type of the variable or single array element). |
| 7633 | PrivateTy = Context.getVariableArrayType( |
| 7634 | Type, new (Context) OpaqueValueExpr(SourceLocation(), |
| 7635 | Context.getSizeType(), VK_RValue), |
| 7636 | ArrayType::Normal, /*IndexTypeQuals=*/0, SourceRange()); |
Alexey Bataev | 1189bd0 | 2016-01-26 12:20:39 +0000 | [diff] [blame^] | 7637 | } else if (DE && |
| 7638 | Context.getAsArrayType(VD->getType().getNonReferenceType())) |
| 7639 | PrivateTy = VD->getType().getNonReferenceType(); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7640 | // Private copy. |
| 7641 | auto *PrivateVD = buildVarDecl(*this, ELoc, PrivateTy, VD->getName(), |
| 7642 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7643 | // Add initializer for private variable. |
| 7644 | Expr *Init = nullptr; |
| 7645 | switch (BOK) { |
| 7646 | case BO_Add: |
| 7647 | case BO_Xor: |
| 7648 | case BO_Or: |
| 7649 | case BO_LOr: |
| 7650 | // '+', '-', '^', '|', '||' reduction ops - initializer is '0'. |
| 7651 | if (Type->isScalarType() || Type->isAnyComplexType()) { |
| 7652 | Init = ActOnIntegerConstant(ELoc, /*Val=*/0).get(); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7653 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7654 | break; |
| 7655 | case BO_Mul: |
| 7656 | case BO_LAnd: |
| 7657 | if (Type->isScalarType() || Type->isAnyComplexType()) { |
| 7658 | // '*' and '&&' reduction ops - initializer is '1'. |
| 7659 | Init = ActOnIntegerConstant(ELoc, /*Val=*/1).get(); |
| 7660 | } |
| 7661 | break; |
| 7662 | case BO_And: { |
| 7663 | // '&' reduction op - initializer is '~0'. |
| 7664 | QualType OrigType = Type; |
| 7665 | if (auto *ComplexTy = OrigType->getAs<ComplexType>()) { |
| 7666 | Type = ComplexTy->getElementType(); |
| 7667 | } |
| 7668 | if (Type->isRealFloatingType()) { |
| 7669 | llvm::APFloat InitValue = |
| 7670 | llvm::APFloat::getAllOnesValue(Context.getTypeSize(Type), |
| 7671 | /*isIEEE=*/true); |
| 7672 | Init = FloatingLiteral::Create(Context, InitValue, /*isexact=*/true, |
| 7673 | Type, ELoc); |
| 7674 | } else if (Type->isScalarType()) { |
| 7675 | auto Size = Context.getTypeSize(Type); |
| 7676 | QualType IntTy = Context.getIntTypeForBitwidth(Size, /*Signed=*/0); |
| 7677 | llvm::APInt InitValue = llvm::APInt::getAllOnesValue(Size); |
| 7678 | Init = IntegerLiteral::Create(Context, InitValue, IntTy, ELoc); |
| 7679 | } |
| 7680 | if (Init && OrigType->isAnyComplexType()) { |
| 7681 | // Init = 0xFFFF + 0xFFFFi; |
| 7682 | auto *Im = new (Context) ImaginaryLiteral(Init, OrigType); |
| 7683 | Init = CreateBuiltinBinOp(ELoc, BO_Add, Init, Im).get(); |
| 7684 | } |
| 7685 | Type = OrigType; |
| 7686 | break; |
| 7687 | } |
| 7688 | case BO_LT: |
| 7689 | case BO_GT: { |
| 7690 | // 'min' reduction op - initializer is 'Largest representable number in |
| 7691 | // the reduction list item type'. |
| 7692 | // 'max' reduction op - initializer is 'Least representable number in |
| 7693 | // the reduction list item type'. |
| 7694 | if (Type->isIntegerType() || Type->isPointerType()) { |
| 7695 | bool IsSigned = Type->hasSignedIntegerRepresentation(); |
| 7696 | auto Size = Context.getTypeSize(Type); |
| 7697 | QualType IntTy = |
| 7698 | Context.getIntTypeForBitwidth(Size, /*Signed=*/IsSigned); |
| 7699 | llvm::APInt InitValue = |
| 7700 | (BOK != BO_LT) |
| 7701 | ? IsSigned ? llvm::APInt::getSignedMinValue(Size) |
| 7702 | : llvm::APInt::getMinValue(Size) |
| 7703 | : IsSigned ? llvm::APInt::getSignedMaxValue(Size) |
| 7704 | : llvm::APInt::getMaxValue(Size); |
| 7705 | Init = IntegerLiteral::Create(Context, InitValue, IntTy, ELoc); |
| 7706 | if (Type->isPointerType()) { |
| 7707 | // Cast to pointer type. |
| 7708 | auto CastExpr = BuildCStyleCastExpr( |
| 7709 | SourceLocation(), Context.getTrivialTypeSourceInfo(Type, ELoc), |
| 7710 | SourceLocation(), Init); |
| 7711 | if (CastExpr.isInvalid()) |
| 7712 | continue; |
| 7713 | Init = CastExpr.get(); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7714 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7715 | } else if (Type->isRealFloatingType()) { |
| 7716 | llvm::APFloat InitValue = llvm::APFloat::getLargest( |
| 7717 | Context.getFloatTypeSemantics(Type), BOK != BO_LT); |
| 7718 | Init = FloatingLiteral::Create(Context, InitValue, /*isexact=*/true, |
| 7719 | Type, ELoc); |
| 7720 | } |
| 7721 | break; |
| 7722 | } |
| 7723 | case BO_PtrMemD: |
| 7724 | case BO_PtrMemI: |
| 7725 | case BO_MulAssign: |
| 7726 | case BO_Div: |
| 7727 | case BO_Rem: |
| 7728 | case BO_Sub: |
| 7729 | case BO_Shl: |
| 7730 | case BO_Shr: |
| 7731 | case BO_LE: |
| 7732 | case BO_GE: |
| 7733 | case BO_EQ: |
| 7734 | case BO_NE: |
| 7735 | case BO_AndAssign: |
| 7736 | case BO_XorAssign: |
| 7737 | case BO_OrAssign: |
| 7738 | case BO_Assign: |
| 7739 | case BO_AddAssign: |
| 7740 | case BO_SubAssign: |
| 7741 | case BO_DivAssign: |
| 7742 | case BO_RemAssign: |
| 7743 | case BO_ShlAssign: |
| 7744 | case BO_ShrAssign: |
| 7745 | case BO_Comma: |
| 7746 | llvm_unreachable("Unexpected reduction operation"); |
| 7747 | } |
| 7748 | if (Init) { |
| 7749 | AddInitializerToDecl(RHSVD, Init, /*DirectInit=*/false, |
| 7750 | /*TypeMayContainAuto=*/false); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7751 | } else |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7752 | ActOnUninitializedDecl(RHSVD, /*TypeMayContainAuto=*/false); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7753 | if (!RHSVD->hasInit()) { |
| 7754 | Diag(ELoc, diag::err_omp_reduction_id_not_compatible) << Type |
| 7755 | << ReductionIdRange; |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7756 | if (VD) { |
| 7757 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 7758 | VarDecl::DeclarationOnly; |
| 7759 | Diag(VD->getLocation(), |
| 7760 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7761 | << VD; |
| 7762 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7763 | continue; |
| 7764 | } |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7765 | // Store initializer for single element in private copy. Will be used during |
| 7766 | // codegen. |
| 7767 | PrivateVD->setInit(RHSVD->getInit()); |
| 7768 | PrivateVD->setInitStyle(RHSVD->getInitStyle()); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7769 | auto *LHSDRE = buildDeclRefExpr(*this, LHSVD, Type, ELoc); |
| 7770 | auto *RHSDRE = buildDeclRefExpr(*this, RHSVD, Type, ELoc); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7771 | auto *PrivateDRE = buildDeclRefExpr(*this, PrivateVD, PrivateTy, ELoc); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7772 | ExprResult ReductionOp = |
| 7773 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), BOK, |
| 7774 | LHSDRE, RHSDRE); |
| 7775 | if (ReductionOp.isUsable()) { |
Alexey Bataev | 69a4779 | 2015-05-07 03:54:03 +0000 | [diff] [blame] | 7776 | if (BOK != BO_LT && BOK != BO_GT) { |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7777 | ReductionOp = |
| 7778 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), |
| 7779 | BO_Assign, LHSDRE, ReductionOp.get()); |
| 7780 | } else { |
| 7781 | auto *ConditionalOp = new (Context) ConditionalOperator( |
| 7782 | ReductionOp.get(), SourceLocation(), LHSDRE, SourceLocation(), |
| 7783 | RHSDRE, Type, VK_LValue, OK_Ordinary); |
| 7784 | ReductionOp = |
| 7785 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), |
| 7786 | BO_Assign, LHSDRE, ConditionalOp); |
| 7787 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 7788 | ReductionOp = ActOnFinishFullExpr(ReductionOp.get()); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7789 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7790 | if (ReductionOp.isInvalid()) |
| 7791 | continue; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7792 | |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7793 | DSAStack->addDSA(VD, DE, OMPC_reduction); |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7794 | Vars.push_back(RefExpr); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7795 | Privates.push_back(PrivateDRE); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7796 | LHSs.push_back(LHSDRE); |
| 7797 | RHSs.push_back(RHSDRE); |
| 7798 | ReductionOps.push_back(ReductionOp.get()); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7799 | } |
| 7800 | |
| 7801 | if (Vars.empty()) |
| 7802 | return nullptr; |
| 7803 | |
| 7804 | return OMPReductionClause::Create( |
| 7805 | Context, StartLoc, LParenLoc, ColonLoc, EndLoc, Vars, |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7806 | ReductionIdScopeSpec.getWithLocInContext(Context), ReductionId, Privates, |
| 7807 | LHSs, RHSs, ReductionOps); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7808 | } |
| 7809 | |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 7810 | OMPClause *Sema::ActOnOpenMPLinearClause( |
| 7811 | ArrayRef<Expr *> VarList, Expr *Step, SourceLocation StartLoc, |
| 7812 | SourceLocation LParenLoc, OpenMPLinearClauseKind LinKind, |
| 7813 | SourceLocation LinLoc, SourceLocation ColonLoc, SourceLocation EndLoc) { |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7814 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7815 | SmallVector<Expr *, 8> Privates; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7816 | SmallVector<Expr *, 8> Inits; |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 7817 | if ((!LangOpts.CPlusPlus && LinKind != OMPC_LINEAR_val) || |
| 7818 | LinKind == OMPC_LINEAR_unknown) { |
| 7819 | Diag(LinLoc, diag::err_omp_wrong_linear_modifier) << LangOpts.CPlusPlus; |
| 7820 | LinKind = OMPC_LINEAR_val; |
| 7821 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7822 | for (auto &RefExpr : VarList) { |
| 7823 | assert(RefExpr && "NULL expr in OpenMP linear clause."); |
| 7824 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7825 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7826 | Vars.push_back(RefExpr); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7827 | Privates.push_back(nullptr); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7828 | Inits.push_back(nullptr); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7829 | continue; |
| 7830 | } |
| 7831 | |
| 7832 | // OpenMP [2.14.3.7, linear clause] |
| 7833 | // A list item that appears in a linear clause is subject to the private |
| 7834 | // clause semantics described in Section 2.14.3.3 on page 159 except as |
| 7835 | // noted. In addition, the value of the new list item on each iteration |
| 7836 | // of the associated loop(s) corresponds to the value of the original |
| 7837 | // list item before entering the construct plus the logical number of |
| 7838 | // the iteration times linear-step. |
| 7839 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7840 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7841 | // OpenMP [2.1, C/C++] |
| 7842 | // A list item is a variable name. |
| 7843 | // OpenMP [2.14.3.3, Restrictions, p.1] |
| 7844 | // A variable that is part of another variable (as an array or |
| 7845 | // structure element) cannot appear in a private clause. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7846 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7847 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7848 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr) |
| 7849 | << 0 << RefExpr->getSourceRange(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7850 | continue; |
| 7851 | } |
| 7852 | |
| 7853 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); |
| 7854 | |
| 7855 | // OpenMP [2.14.3.7, linear clause] |
| 7856 | // A list-item cannot appear in more than one linear clause. |
| 7857 | // A list-item that appears in a linear clause cannot appear in any |
| 7858 | // other data-sharing attribute clause. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7859 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7860 | if (DVar.RefExpr) { |
| 7861 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 7862 | << getOpenMPClauseName(OMPC_linear); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 7863 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7864 | continue; |
| 7865 | } |
| 7866 | |
| 7867 | QualType QType = VD->getType(); |
| 7868 | if (QType->isDependentType() || QType->isInstantiationDependentType()) { |
| 7869 | // It will be analyzed later. |
| 7870 | Vars.push_back(DE); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7871 | Privates.push_back(nullptr); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7872 | Inits.push_back(nullptr); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7873 | continue; |
| 7874 | } |
| 7875 | |
| 7876 | // A variable must not have an incomplete type or a reference type. |
| 7877 | if (RequireCompleteType(ELoc, QType, |
| 7878 | diag::err_omp_linear_incomplete_type)) { |
| 7879 | continue; |
| 7880 | } |
Alexey Bataev | 1185e19 | 2015-08-20 12:15:57 +0000 | [diff] [blame] | 7881 | if ((LinKind == OMPC_LINEAR_uval || LinKind == OMPC_LINEAR_ref) && |
| 7882 | !QType->isReferenceType()) { |
| 7883 | Diag(ELoc, diag::err_omp_wrong_linear_modifier_non_reference) |
| 7884 | << QType << getOpenMPSimpleClauseTypeName(OMPC_linear, LinKind); |
| 7885 | continue; |
| 7886 | } |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7887 | QType = QType.getNonReferenceType(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7888 | |
| 7889 | // A list item must not be const-qualified. |
| 7890 | if (QType.isConstant(Context)) { |
| 7891 | Diag(ELoc, diag::err_omp_const_variable) |
| 7892 | << getOpenMPClauseName(OMPC_linear); |
| 7893 | bool IsDecl = |
| 7894 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 7895 | Diag(VD->getLocation(), |
| 7896 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7897 | << VD; |
| 7898 | continue; |
| 7899 | } |
| 7900 | |
| 7901 | // A list item must be of integral or pointer type. |
| 7902 | QType = QType.getUnqualifiedType().getCanonicalType(); |
| 7903 | const Type *Ty = QType.getTypePtrOrNull(); |
| 7904 | if (!Ty || (!Ty->isDependentType() && !Ty->isIntegralType(Context) && |
| 7905 | !Ty->isPointerType())) { |
| 7906 | Diag(ELoc, diag::err_omp_linear_expected_int_or_ptr) << QType; |
| 7907 | bool IsDecl = |
| 7908 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 7909 | Diag(VD->getLocation(), |
| 7910 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7911 | << VD; |
| 7912 | continue; |
| 7913 | } |
| 7914 | |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7915 | // Build private copy of original var. |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 7916 | auto *Private = buildVarDecl(*this, ELoc, QType, VD->getName(), |
| 7917 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7918 | auto *PrivateRef = buildDeclRefExpr( |
| 7919 | *this, Private, DE->getType().getUnqualifiedType(), DE->getExprLoc()); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7920 | // Build var to save initial value. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7921 | VarDecl *Init = buildVarDecl(*this, ELoc, QType, ".linear.start"); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 7922 | Expr *InitExpr; |
| 7923 | if (LinKind == OMPC_LINEAR_uval) |
| 7924 | InitExpr = VD->getInit(); |
| 7925 | else |
| 7926 | InitExpr = DE; |
| 7927 | AddInitializerToDecl(Init, DefaultLvalueConversion(InitExpr).get(), |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7928 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7929 | auto InitRef = buildDeclRefExpr( |
| 7930 | *this, Init, DE->getType().getUnqualifiedType(), DE->getExprLoc()); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7931 | DSAStack->addDSA(VD, DE, OMPC_linear); |
| 7932 | Vars.push_back(DE); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7933 | Privates.push_back(PrivateRef); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7934 | Inits.push_back(InitRef); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7935 | } |
| 7936 | |
| 7937 | if (Vars.empty()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 7938 | return nullptr; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7939 | |
| 7940 | Expr *StepExpr = Step; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7941 | Expr *CalcStepExpr = nullptr; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7942 | if (Step && !Step->isValueDependent() && !Step->isTypeDependent() && |
| 7943 | !Step->isInstantiationDependent() && |
| 7944 | !Step->containsUnexpandedParameterPack()) { |
| 7945 | SourceLocation StepLoc = Step->getLocStart(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 7946 | ExprResult Val = PerformOpenMPImplicitIntegerConversion(StepLoc, Step); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7947 | if (Val.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 7948 | return nullptr; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 7949 | StepExpr = Val.get(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7950 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7951 | // Build var to save the step value. |
| 7952 | VarDecl *SaveVar = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7953 | buildVarDecl(*this, StepLoc, StepExpr->getType(), ".linear.step"); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7954 | ExprResult SaveRef = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7955 | buildDeclRefExpr(*this, SaveVar, StepExpr->getType(), StepLoc); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7956 | ExprResult CalcStep = |
| 7957 | BuildBinOp(CurScope, StepLoc, BO_Assign, SaveRef.get(), StepExpr); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 7958 | CalcStep = ActOnFinishFullExpr(CalcStep.get()); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7959 | |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7960 | // Warn about zero linear step (it would be probably better specified as |
| 7961 | // making corresponding variables 'const'). |
| 7962 | llvm::APSInt Result; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7963 | bool IsConstant = StepExpr->isIntegerConstantExpr(Result, Context); |
| 7964 | if (IsConstant && !Result.isNegative() && !Result.isStrictlyPositive()) |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7965 | Diag(StepLoc, diag::warn_omp_linear_step_zero) << Vars[0] |
| 7966 | << (Vars.size() > 1); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7967 | if (!IsConstant && CalcStep.isUsable()) { |
| 7968 | // Calculate the step beforehand instead of doing this on each iteration. |
| 7969 | // (This is not used if the number of iterations may be kfold-ed). |
| 7970 | CalcStepExpr = CalcStep.get(); |
| 7971 | } |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7972 | } |
| 7973 | |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 7974 | return OMPLinearClause::Create(Context, StartLoc, LParenLoc, LinKind, LinLoc, |
| 7975 | ColonLoc, EndLoc, Vars, Privates, Inits, |
| 7976 | StepExpr, CalcStepExpr); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7977 | } |
| 7978 | |
| 7979 | static bool FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV, |
| 7980 | Expr *NumIterations, Sema &SemaRef, |
| 7981 | Scope *S) { |
| 7982 | // Walk the vars and build update/final expressions for the CodeGen. |
| 7983 | SmallVector<Expr *, 8> Updates; |
| 7984 | SmallVector<Expr *, 8> Finals; |
| 7985 | Expr *Step = Clause.getStep(); |
| 7986 | Expr *CalcStep = Clause.getCalcStep(); |
| 7987 | // OpenMP [2.14.3.7, linear clause] |
| 7988 | // If linear-step is not specified it is assumed to be 1. |
| 7989 | if (Step == nullptr) |
| 7990 | Step = SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get(); |
| 7991 | else if (CalcStep) |
| 7992 | Step = cast<BinaryOperator>(CalcStep)->getLHS(); |
| 7993 | bool HasErrors = false; |
| 7994 | auto CurInit = Clause.inits().begin(); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7995 | auto CurPrivate = Clause.privates().begin(); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 7996 | auto LinKind = Clause.getModifier(); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7997 | for (auto &RefExpr : Clause.varlists()) { |
| 7998 | Expr *InitExpr = *CurInit; |
| 7999 | |
| 8000 | // Build privatized reference to the current linear var. |
| 8001 | auto DE = cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 8002 | Expr *CapturedRef; |
| 8003 | if (LinKind == OMPC_LINEAR_uval) |
| 8004 | CapturedRef = cast<VarDecl>(DE->getDecl())->getInit(); |
| 8005 | else |
| 8006 | CapturedRef = |
| 8007 | buildDeclRefExpr(SemaRef, cast<VarDecl>(DE->getDecl()), |
| 8008 | DE->getType().getUnqualifiedType(), DE->getExprLoc(), |
| 8009 | /*RefersToCapture=*/true); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8010 | |
| 8011 | // Build update: Var = InitExpr + IV * Step |
| 8012 | ExprResult Update = |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8013 | BuildCounterUpdate(SemaRef, S, RefExpr->getExprLoc(), *CurPrivate, |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8014 | InitExpr, IV, Step, /* Subtract */ false); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 8015 | Update = SemaRef.ActOnFinishFullExpr(Update.get(), DE->getLocStart(), |
| 8016 | /*DiscardedValue=*/true); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8017 | |
| 8018 | // Build final: Var = InitExpr + NumIterations * Step |
| 8019 | ExprResult Final = |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8020 | BuildCounterUpdate(SemaRef, S, RefExpr->getExprLoc(), CapturedRef, |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 8021 | InitExpr, NumIterations, Step, /* Subtract */ false); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 8022 | Final = SemaRef.ActOnFinishFullExpr(Final.get(), DE->getLocStart(), |
| 8023 | /*DiscardedValue=*/true); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8024 | if (!Update.isUsable() || !Final.isUsable()) { |
| 8025 | Updates.push_back(nullptr); |
| 8026 | Finals.push_back(nullptr); |
| 8027 | HasErrors = true; |
| 8028 | } else { |
| 8029 | Updates.push_back(Update.get()); |
| 8030 | Finals.push_back(Final.get()); |
| 8031 | } |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8032 | ++CurInit, ++CurPrivate; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8033 | } |
| 8034 | Clause.setUpdates(Updates); |
| 8035 | Clause.setFinals(Finals); |
| 8036 | return HasErrors; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8037 | } |
| 8038 | |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 8039 | OMPClause *Sema::ActOnOpenMPAlignedClause( |
| 8040 | ArrayRef<Expr *> VarList, Expr *Alignment, SourceLocation StartLoc, |
| 8041 | SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc) { |
| 8042 | |
| 8043 | SmallVector<Expr *, 8> Vars; |
| 8044 | for (auto &RefExpr : VarList) { |
| 8045 | assert(RefExpr && "NULL expr in OpenMP aligned clause."); |
| 8046 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 8047 | // It will be analyzed later. |
| 8048 | Vars.push_back(RefExpr); |
| 8049 | continue; |
| 8050 | } |
| 8051 | |
| 8052 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 8053 | // OpenMP [2.1, C/C++] |
| 8054 | // A list item is a variable name. |
| 8055 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
| 8056 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8057 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr) |
| 8058 | << 0 << RefExpr->getSourceRange(); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 8059 | continue; |
| 8060 | } |
| 8061 | |
| 8062 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); |
| 8063 | |
| 8064 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 8065 | // The type of list items appearing in the aligned clause must be |
| 8066 | // array, pointer, reference to array, or reference to pointer. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8067 | QualType QType = VD->getType(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8068 | QType = QType.getNonReferenceType().getUnqualifiedType().getCanonicalType(); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 8069 | const Type *Ty = QType.getTypePtrOrNull(); |
| 8070 | if (!Ty || (!Ty->isDependentType() && !Ty->isArrayType() && |
| 8071 | !Ty->isPointerType())) { |
| 8072 | Diag(ELoc, diag::err_omp_aligned_expected_array_or_ptr) |
| 8073 | << QType << getLangOpts().CPlusPlus << RefExpr->getSourceRange(); |
| 8074 | bool IsDecl = |
| 8075 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 8076 | Diag(VD->getLocation(), |
| 8077 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 8078 | << VD; |
| 8079 | continue; |
| 8080 | } |
| 8081 | |
| 8082 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 8083 | // A list-item cannot appear in more than one aligned clause. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8084 | if (Expr *PrevRef = DSAStack->addUniqueAligned(VD, DE)) { |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 8085 | Diag(ELoc, diag::err_omp_aligned_twice) << RefExpr->getSourceRange(); |
| 8086 | Diag(PrevRef->getExprLoc(), diag::note_omp_explicit_dsa) |
| 8087 | << getOpenMPClauseName(OMPC_aligned); |
| 8088 | continue; |
| 8089 | } |
| 8090 | |
| 8091 | Vars.push_back(DE); |
| 8092 | } |
| 8093 | |
| 8094 | // OpenMP [2.8.1, simd construct, Description] |
| 8095 | // The parameter of the aligned clause, alignment, must be a constant |
| 8096 | // positive integer expression. |
| 8097 | // If no optional parameter is specified, implementation-defined default |
| 8098 | // alignments for SIMD instructions on the target platforms are assumed. |
| 8099 | if (Alignment != nullptr) { |
| 8100 | ExprResult AlignResult = |
| 8101 | VerifyPositiveIntegerConstantInClause(Alignment, OMPC_aligned); |
| 8102 | if (AlignResult.isInvalid()) |
| 8103 | return nullptr; |
| 8104 | Alignment = AlignResult.get(); |
| 8105 | } |
| 8106 | if (Vars.empty()) |
| 8107 | return nullptr; |
| 8108 | |
| 8109 | return OMPAlignedClause::Create(Context, StartLoc, LParenLoc, ColonLoc, |
| 8110 | EndLoc, Vars, Alignment); |
| 8111 | } |
| 8112 | |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8113 | OMPClause *Sema::ActOnOpenMPCopyinClause(ArrayRef<Expr *> VarList, |
| 8114 | SourceLocation StartLoc, |
| 8115 | SourceLocation LParenLoc, |
| 8116 | SourceLocation EndLoc) { |
| 8117 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 8118 | SmallVector<Expr *, 8> SrcExprs; |
| 8119 | SmallVector<Expr *, 8> DstExprs; |
| 8120 | SmallVector<Expr *, 8> AssignmentOps; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8121 | for (auto &RefExpr : VarList) { |
| 8122 | assert(RefExpr && "NULL expr in OpenMP copyin clause."); |
| 8123 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8124 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8125 | Vars.push_back(RefExpr); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 8126 | SrcExprs.push_back(nullptr); |
| 8127 | DstExprs.push_back(nullptr); |
| 8128 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8129 | continue; |
| 8130 | } |
| 8131 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8132 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8133 | // OpenMP [2.1, C/C++] |
| 8134 | // A list item is a variable name. |
| 8135 | // OpenMP [2.14.4.1, Restrictions, p.1] |
| 8136 | // A list item that appears in a copyin clause must be threadprivate. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8137 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8138 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8139 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr) |
| 8140 | << 0 << RefExpr->getSourceRange(); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8141 | continue; |
| 8142 | } |
| 8143 | |
| 8144 | Decl *D = DE->getDecl(); |
| 8145 | VarDecl *VD = cast<VarDecl>(D); |
| 8146 | |
| 8147 | QualType Type = VD->getType(); |
| 8148 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 8149 | // It will be analyzed later. |
| 8150 | Vars.push_back(DE); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 8151 | SrcExprs.push_back(nullptr); |
| 8152 | DstExprs.push_back(nullptr); |
| 8153 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8154 | continue; |
| 8155 | } |
| 8156 | |
| 8157 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.1] |
| 8158 | // A list item that appears in a copyin clause must be threadprivate. |
| 8159 | if (!DSAStack->isThreadPrivate(VD)) { |
| 8160 | Diag(ELoc, diag::err_omp_required_access) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8161 | << getOpenMPClauseName(OMPC_copyin) |
| 8162 | << getOpenMPDirectiveName(OMPD_threadprivate); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8163 | continue; |
| 8164 | } |
| 8165 | |
| 8166 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.2] |
| 8167 | // A variable of class type (or array thereof) that appears in a |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 8168 | // copyin clause requires an accessible, unambiguous copy assignment |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8169 | // operator for the class type. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8170 | auto ElemType = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 8171 | auto *SrcVD = |
| 8172 | buildVarDecl(*this, DE->getLocStart(), ElemType.getUnqualifiedType(), |
| 8173 | ".copyin.src", VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 8174 | auto *PseudoSrcExpr = buildDeclRefExpr( |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8175 | *this, SrcVD, ElemType.getUnqualifiedType(), DE->getExprLoc()); |
| 8176 | auto *DstVD = |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 8177 | buildVarDecl(*this, DE->getLocStart(), ElemType, ".copyin.dst", |
| 8178 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 8179 | auto *PseudoDstExpr = |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8180 | buildDeclRefExpr(*this, DstVD, ElemType, DE->getExprLoc()); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 8181 | // For arrays generate assignment operation for single element and replace |
| 8182 | // it by the original array element in CodeGen. |
| 8183 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, DE->getExprLoc(), BO_Assign, |
| 8184 | PseudoDstExpr, PseudoSrcExpr); |
| 8185 | if (AssignmentOp.isInvalid()) |
| 8186 | continue; |
| 8187 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), DE->getExprLoc(), |
| 8188 | /*DiscardedValue=*/true); |
| 8189 | if (AssignmentOp.isInvalid()) |
| 8190 | continue; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8191 | |
| 8192 | DSAStack->addDSA(VD, DE, OMPC_copyin); |
| 8193 | Vars.push_back(DE); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 8194 | SrcExprs.push_back(PseudoSrcExpr); |
| 8195 | DstExprs.push_back(PseudoDstExpr); |
| 8196 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8197 | } |
| 8198 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8199 | if (Vars.empty()) |
| 8200 | return nullptr; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8201 | |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 8202 | return OMPCopyinClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
| 8203 | SrcExprs, DstExprs, AssignmentOps); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8204 | } |
| 8205 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8206 | OMPClause *Sema::ActOnOpenMPCopyprivateClause(ArrayRef<Expr *> VarList, |
| 8207 | SourceLocation StartLoc, |
| 8208 | SourceLocation LParenLoc, |
| 8209 | SourceLocation EndLoc) { |
| 8210 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 8211 | SmallVector<Expr *, 8> SrcExprs; |
| 8212 | SmallVector<Expr *, 8> DstExprs; |
| 8213 | SmallVector<Expr *, 8> AssignmentOps; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8214 | for (auto &RefExpr : VarList) { |
| 8215 | assert(RefExpr && "NULL expr in OpenMP copyprivate clause."); |
| 8216 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 8217 | // It will be analyzed later. |
| 8218 | Vars.push_back(RefExpr); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 8219 | SrcExprs.push_back(nullptr); |
| 8220 | DstExprs.push_back(nullptr); |
| 8221 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8222 | continue; |
| 8223 | } |
| 8224 | |
| 8225 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 8226 | // OpenMP [2.1, C/C++] |
| 8227 | // A list item is a variable name. |
| 8228 | // OpenMP [2.14.4.1, Restrictions, p.1] |
| 8229 | // A list item that appears in a copyin clause must be threadprivate. |
| 8230 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
| 8231 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8232 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr) |
| 8233 | << 0 << RefExpr->getSourceRange(); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8234 | continue; |
| 8235 | } |
| 8236 | |
| 8237 | Decl *D = DE->getDecl(); |
| 8238 | VarDecl *VD = cast<VarDecl>(D); |
| 8239 | |
| 8240 | QualType Type = VD->getType(); |
| 8241 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 8242 | // It will be analyzed later. |
| 8243 | Vars.push_back(DE); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 8244 | SrcExprs.push_back(nullptr); |
| 8245 | DstExprs.push_back(nullptr); |
| 8246 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8247 | continue; |
| 8248 | } |
| 8249 | |
| 8250 | // OpenMP [2.14.4.2, Restrictions, p.2] |
| 8251 | // A list item that appears in a copyprivate clause may not appear in a |
| 8252 | // private or firstprivate clause on the single construct. |
| 8253 | if (!DSAStack->isThreadPrivate(VD)) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 8254 | auto DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 8255 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_copyprivate && |
| 8256 | DVar.RefExpr) { |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8257 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 8258 | << getOpenMPClauseName(DVar.CKind) |
| 8259 | << getOpenMPClauseName(OMPC_copyprivate); |
| 8260 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 8261 | continue; |
| 8262 | } |
| 8263 | |
| 8264 | // OpenMP [2.11.4.2, Restrictions, p.1] |
| 8265 | // All list items that appear in a copyprivate clause must be either |
| 8266 | // threadprivate or private in the enclosing context. |
| 8267 | if (DVar.CKind == OMPC_unknown) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 8268 | DVar = DSAStack->getImplicitDSA(VD, false); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8269 | if (DVar.CKind == OMPC_shared) { |
| 8270 | Diag(ELoc, diag::err_omp_required_access) |
| 8271 | << getOpenMPClauseName(OMPC_copyprivate) |
| 8272 | << "threadprivate or private in the enclosing context"; |
| 8273 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 8274 | continue; |
| 8275 | } |
| 8276 | } |
| 8277 | } |
| 8278 | |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 8279 | // Variably modified types are not supported. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 8280 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType()) { |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 8281 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8282 | << getOpenMPClauseName(OMPC_copyprivate) << Type |
| 8283 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 8284 | bool IsDecl = |
| 8285 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 8286 | Diag(VD->getLocation(), |
| 8287 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 8288 | << VD; |
| 8289 | continue; |
| 8290 | } |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8291 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8292 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.2] |
| 8293 | // A variable of class type (or array thereof) that appears in a |
| 8294 | // copyin clause requires an accessible, unambiguous copy assignment |
| 8295 | // operator for the class type. |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8296 | Type = Context.getBaseElementType(Type.getNonReferenceType()) |
| 8297 | .getUnqualifiedType(); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 8298 | auto *SrcVD = |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 8299 | buildVarDecl(*this, DE->getLocStart(), Type, ".copyprivate.src", |
| 8300 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 8301 | auto *PseudoSrcExpr = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 8302 | buildDeclRefExpr(*this, SrcVD, Type, DE->getExprLoc()); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 8303 | auto *DstVD = |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 8304 | buildVarDecl(*this, DE->getLocStart(), Type, ".copyprivate.dst", |
| 8305 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 8306 | auto *PseudoDstExpr = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 8307 | buildDeclRefExpr(*this, DstVD, Type, DE->getExprLoc()); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 8308 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, DE->getExprLoc(), BO_Assign, |
| 8309 | PseudoDstExpr, PseudoSrcExpr); |
| 8310 | if (AssignmentOp.isInvalid()) |
| 8311 | continue; |
| 8312 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), DE->getExprLoc(), |
| 8313 | /*DiscardedValue=*/true); |
| 8314 | if (AssignmentOp.isInvalid()) |
| 8315 | continue; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8316 | |
| 8317 | // No need to mark vars as copyprivate, they are already threadprivate or |
| 8318 | // implicitly private. |
| 8319 | Vars.push_back(DE); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 8320 | SrcExprs.push_back(PseudoSrcExpr); |
| 8321 | DstExprs.push_back(PseudoDstExpr); |
| 8322 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8323 | } |
| 8324 | |
| 8325 | if (Vars.empty()) |
| 8326 | return nullptr; |
| 8327 | |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 8328 | return OMPCopyprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| 8329 | Vars, SrcExprs, DstExprs, AssignmentOps); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8330 | } |
| 8331 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 8332 | OMPClause *Sema::ActOnOpenMPFlushClause(ArrayRef<Expr *> VarList, |
| 8333 | SourceLocation StartLoc, |
| 8334 | SourceLocation LParenLoc, |
| 8335 | SourceLocation EndLoc) { |
| 8336 | if (VarList.empty()) |
| 8337 | return nullptr; |
| 8338 | |
| 8339 | return OMPFlushClause::Create(Context, StartLoc, LParenLoc, EndLoc, VarList); |
| 8340 | } |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 8341 | |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8342 | OMPClause * |
| 8343 | Sema::ActOnOpenMPDependClause(OpenMPDependClauseKind DepKind, |
| 8344 | SourceLocation DepLoc, SourceLocation ColonLoc, |
| 8345 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
| 8346 | SourceLocation LParenLoc, SourceLocation EndLoc) { |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 8347 | if (DSAStack->getCurrentDirective() == OMPD_ordered && |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 8348 | DepKind != OMPC_DEPEND_source && DepKind != OMPC_DEPEND_sink) { |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 8349 | Diag(DepLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 8350 | << "'source' or 'sink'" << getOpenMPClauseName(OMPC_depend); |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 8351 | return nullptr; |
| 8352 | } |
| 8353 | if (DSAStack->getCurrentDirective() != OMPD_ordered && |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 8354 | (DepKind == OMPC_DEPEND_unknown || DepKind == OMPC_DEPEND_source || |
| 8355 | DepKind == OMPC_DEPEND_sink)) { |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 8356 | unsigned Except[] = {OMPC_DEPEND_source, OMPC_DEPEND_sink}; |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8357 | Diag(DepLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 8358 | << getListOfPossibleValues(OMPC_depend, /*First=*/0, |
| 8359 | /*Last=*/OMPC_DEPEND_unknown, Except) |
| 8360 | << getOpenMPClauseName(OMPC_depend); |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8361 | return nullptr; |
| 8362 | } |
| 8363 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 8364 | llvm::APSInt DepCounter(/*BitWidth=*/32); |
| 8365 | llvm::APSInt TotalDepCount(/*BitWidth=*/32); |
| 8366 | if (DepKind == OMPC_DEPEND_sink) { |
| 8367 | if (auto *OrderedCountExpr = DSAStack->getParentOrderedRegionParam()) { |
| 8368 | TotalDepCount = OrderedCountExpr->EvaluateKnownConstInt(Context); |
| 8369 | TotalDepCount.setIsUnsigned(/*Val=*/true); |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8370 | } |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8371 | } |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 8372 | if ((DepKind != OMPC_DEPEND_sink && DepKind != OMPC_DEPEND_source) || |
| 8373 | DSAStack->getParentOrderedRegionParam()) { |
| 8374 | for (auto &RefExpr : VarList) { |
| 8375 | assert(RefExpr && "NULL expr in OpenMP shared clause."); |
| 8376 | if (isa<DependentScopeDeclRefExpr>(RefExpr) || |
| 8377 | (DepKind == OMPC_DEPEND_sink && CurContext->isDependentContext())) { |
| 8378 | // It will be analyzed later. |
| 8379 | Vars.push_back(RefExpr); |
| 8380 | continue; |
| 8381 | } |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8382 | |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 8383 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 8384 | auto *SimpleExpr = RefExpr->IgnoreParenCasts(); |
| 8385 | if (DepKind == OMPC_DEPEND_sink) { |
| 8386 | if (DepCounter >= TotalDepCount) { |
| 8387 | Diag(ELoc, diag::err_omp_depend_sink_unexpected_expr); |
| 8388 | continue; |
| 8389 | } |
| 8390 | ++DepCounter; |
| 8391 | // OpenMP [2.13.9, Summary] |
| 8392 | // depend(dependence-type : vec), where dependence-type is: |
| 8393 | // 'sink' and where vec is the iteration vector, which has the form: |
| 8394 | // x1 [+- d1], x2 [+- d2 ], . . . , xn [+- dn] |
| 8395 | // where n is the value specified by the ordered clause in the loop |
| 8396 | // directive, xi denotes the loop iteration variable of the i-th nested |
| 8397 | // loop associated with the loop directive, and di is a constant |
| 8398 | // non-negative integer. |
| 8399 | SimpleExpr = SimpleExpr->IgnoreImplicit(); |
| 8400 | auto *DE = dyn_cast<DeclRefExpr>(SimpleExpr); |
| 8401 | if (!DE) { |
| 8402 | OverloadedOperatorKind OOK = OO_None; |
| 8403 | SourceLocation OOLoc; |
| 8404 | Expr *LHS, *RHS; |
| 8405 | if (auto *BO = dyn_cast<BinaryOperator>(SimpleExpr)) { |
| 8406 | OOK = BinaryOperator::getOverloadedOperator(BO->getOpcode()); |
| 8407 | OOLoc = BO->getOperatorLoc(); |
| 8408 | LHS = BO->getLHS()->IgnoreParenImpCasts(); |
| 8409 | RHS = BO->getRHS()->IgnoreParenImpCasts(); |
| 8410 | } else if (auto *OCE = dyn_cast<CXXOperatorCallExpr>(SimpleExpr)) { |
| 8411 | OOK = OCE->getOperator(); |
| 8412 | OOLoc = OCE->getOperatorLoc(); |
| 8413 | LHS = OCE->getArg(/*Arg=*/0)->IgnoreParenImpCasts(); |
| 8414 | RHS = OCE->getArg(/*Arg=*/1)->IgnoreParenImpCasts(); |
| 8415 | } else if (auto *MCE = dyn_cast<CXXMemberCallExpr>(SimpleExpr)) { |
| 8416 | OOK = MCE->getMethodDecl() |
| 8417 | ->getNameInfo() |
| 8418 | .getName() |
| 8419 | .getCXXOverloadedOperator(); |
| 8420 | OOLoc = MCE->getCallee()->getExprLoc(); |
| 8421 | LHS = MCE->getImplicitObjectArgument()->IgnoreParenImpCasts(); |
| 8422 | RHS = MCE->getArg(/*Arg=*/0)->IgnoreParenImpCasts(); |
| 8423 | } else { |
| 8424 | Diag(ELoc, diag::err_omp_depend_sink_wrong_expr); |
| 8425 | continue; |
| 8426 | } |
| 8427 | DE = dyn_cast<DeclRefExpr>(LHS); |
| 8428 | if (!DE) { |
| 8429 | Diag(LHS->getExprLoc(), |
| 8430 | diag::err_omp_depend_sink_expected_loop_iteration) |
| 8431 | << DSAStack->getParentLoopControlVariable( |
| 8432 | DepCounter.getZExtValue()); |
| 8433 | continue; |
| 8434 | } |
| 8435 | if (OOK != OO_Plus && OOK != OO_Minus) { |
| 8436 | Diag(OOLoc, diag::err_omp_depend_sink_expected_plus_minus); |
| 8437 | continue; |
| 8438 | } |
| 8439 | ExprResult Res = VerifyPositiveIntegerConstantInClause( |
| 8440 | RHS, OMPC_depend, /*StrictlyPositive=*/false); |
| 8441 | if (Res.isInvalid()) |
| 8442 | continue; |
| 8443 | } |
| 8444 | auto *VD = dyn_cast<VarDecl>(DE->getDecl()); |
| 8445 | if (!CurContext->isDependentContext() && |
| 8446 | DSAStack->getParentOrderedRegionParam() && |
| 8447 | (!VD || DepCounter != DSAStack->isParentLoopControlVariable(VD))) { |
| 8448 | Diag(DE->getExprLoc(), |
| 8449 | diag::err_omp_depend_sink_expected_loop_iteration) |
| 8450 | << DSAStack->getParentLoopControlVariable( |
| 8451 | DepCounter.getZExtValue()); |
| 8452 | continue; |
| 8453 | } |
| 8454 | } else { |
| 8455 | // OpenMP [2.11.1.1, Restrictions, p.3] |
| 8456 | // A variable that is part of another variable (such as a field of a |
| 8457 | // structure) but is not an array element or an array section cannot |
| 8458 | // appear in a depend clause. |
| 8459 | auto *DE = dyn_cast<DeclRefExpr>(SimpleExpr); |
| 8460 | auto *ASE = dyn_cast<ArraySubscriptExpr>(SimpleExpr); |
| 8461 | auto *OASE = dyn_cast<OMPArraySectionExpr>(SimpleExpr); |
| 8462 | if (!RefExpr->IgnoreParenImpCasts()->isLValue() || |
| 8463 | (!ASE && !DE && !OASE) || (DE && !isa<VarDecl>(DE->getDecl())) || |
| 8464 | (ASE && !ASE->getBase()->getType()->isAnyPointerType() && |
| 8465 | !ASE->getBase()->getType()->isArrayType())) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8466 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr_or_array_item) |
| 8467 | << 0 << RefExpr->getSourceRange(); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 8468 | continue; |
| 8469 | } |
| 8470 | } |
| 8471 | |
| 8472 | Vars.push_back(RefExpr->IgnoreParenImpCasts()); |
| 8473 | } |
| 8474 | |
| 8475 | if (!CurContext->isDependentContext() && DepKind == OMPC_DEPEND_sink && |
| 8476 | TotalDepCount > VarList.size() && |
| 8477 | DSAStack->getParentOrderedRegionParam()) { |
| 8478 | Diag(EndLoc, diag::err_omp_depend_sink_expected_loop_iteration) |
| 8479 | << DSAStack->getParentLoopControlVariable(VarList.size() + 1); |
| 8480 | } |
| 8481 | if (DepKind != OMPC_DEPEND_source && DepKind != OMPC_DEPEND_sink && |
| 8482 | Vars.empty()) |
| 8483 | return nullptr; |
| 8484 | } |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8485 | |
| 8486 | return OMPDependClause::Create(Context, StartLoc, LParenLoc, EndLoc, DepKind, |
| 8487 | DepLoc, ColonLoc, Vars); |
| 8488 | } |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 8489 | |
| 8490 | OMPClause *Sema::ActOnOpenMPDeviceClause(Expr *Device, SourceLocation StartLoc, |
| 8491 | SourceLocation LParenLoc, |
| 8492 | SourceLocation EndLoc) { |
| 8493 | Expr *ValExpr = Device; |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 8494 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 8495 | // OpenMP [2.9.1, Restrictions] |
| 8496 | // The device expression must evaluate to a non-negative integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 8497 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_device, |
| 8498 | /*StrictlyPositive=*/false)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 8499 | return nullptr; |
| 8500 | |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 8501 | return new (Context) OMPDeviceClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 8502 | } |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 8503 | |
| 8504 | static bool IsCXXRecordForMappable(Sema &SemaRef, SourceLocation Loc, |
| 8505 | DSAStackTy *Stack, CXXRecordDecl *RD) { |
| 8506 | if (!RD || RD->isInvalidDecl()) |
| 8507 | return true; |
| 8508 | |
Alexey Bataev | c9bd03d | 2015-12-17 06:55:08 +0000 | [diff] [blame] | 8509 | if (auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(RD)) |
| 8510 | if (auto *CTD = CTSD->getSpecializedTemplate()) |
| 8511 | RD = CTD->getTemplatedDecl(); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 8512 | auto QTy = SemaRef.Context.getRecordType(RD); |
| 8513 | if (RD->isDynamicClass()) { |
| 8514 | SemaRef.Diag(Loc, diag::err_omp_not_mappable_type) << QTy; |
| 8515 | SemaRef.Diag(RD->getLocation(), diag::note_omp_polymorphic_in_target); |
| 8516 | return false; |
| 8517 | } |
| 8518 | auto *DC = RD; |
| 8519 | bool IsCorrect = true; |
| 8520 | for (auto *I : DC->decls()) { |
| 8521 | if (I) { |
| 8522 | if (auto *MD = dyn_cast<CXXMethodDecl>(I)) { |
| 8523 | if (MD->isStatic()) { |
| 8524 | SemaRef.Diag(Loc, diag::err_omp_not_mappable_type) << QTy; |
| 8525 | SemaRef.Diag(MD->getLocation(), |
| 8526 | diag::note_omp_static_member_in_target); |
| 8527 | IsCorrect = false; |
| 8528 | } |
| 8529 | } else if (auto *VD = dyn_cast<VarDecl>(I)) { |
| 8530 | if (VD->isStaticDataMember()) { |
| 8531 | SemaRef.Diag(Loc, diag::err_omp_not_mappable_type) << QTy; |
| 8532 | SemaRef.Diag(VD->getLocation(), |
| 8533 | diag::note_omp_static_member_in_target); |
| 8534 | IsCorrect = false; |
| 8535 | } |
| 8536 | } |
| 8537 | } |
| 8538 | } |
| 8539 | |
| 8540 | for (auto &I : RD->bases()) { |
| 8541 | if (!IsCXXRecordForMappable(SemaRef, I.getLocStart(), Stack, |
| 8542 | I.getType()->getAsCXXRecordDecl())) |
| 8543 | IsCorrect = false; |
| 8544 | } |
| 8545 | return IsCorrect; |
| 8546 | } |
| 8547 | |
| 8548 | static bool CheckTypeMappable(SourceLocation SL, SourceRange SR, Sema &SemaRef, |
| 8549 | DSAStackTy *Stack, QualType QTy) { |
| 8550 | NamedDecl *ND; |
| 8551 | if (QTy->isIncompleteType(&ND)) { |
| 8552 | SemaRef.Diag(SL, diag::err_incomplete_type) << QTy << SR; |
| 8553 | return false; |
| 8554 | } else if (CXXRecordDecl *RD = dyn_cast_or_null<CXXRecordDecl>(ND)) { |
| 8555 | if (!RD->isInvalidDecl() && |
| 8556 | !IsCXXRecordForMappable(SemaRef, SL, Stack, RD)) |
| 8557 | return false; |
| 8558 | } |
| 8559 | return true; |
| 8560 | } |
| 8561 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 8562 | // Return the expression of the base of the map clause or null if it cannot |
| 8563 | // be determined and do all the necessary checks to see if the expression is |
| 8564 | // valid as a standalone map clause expression. |
| 8565 | static Expr *CheckMapClauseExpressionBase(Sema &SemaRef, Expr *E) { |
| 8566 | SourceLocation ELoc = E->getExprLoc(); |
| 8567 | SourceRange ERange = E->getSourceRange(); |
| 8568 | |
| 8569 | // The base of elements of list in a map clause have to be either: |
| 8570 | // - a reference to variable or field. |
| 8571 | // - a member expression. |
| 8572 | // - an array expression. |
| 8573 | // |
| 8574 | // E.g. if we have the expression 'r.S.Arr[:12]', we want to retrieve the |
| 8575 | // reference to 'r'. |
| 8576 | // |
| 8577 | // If we have: |
| 8578 | // |
| 8579 | // struct SS { |
| 8580 | // Bla S; |
| 8581 | // foo() { |
| 8582 | // #pragma omp target map (S.Arr[:12]); |
| 8583 | // } |
| 8584 | // } |
| 8585 | // |
| 8586 | // We want to retrieve the member expression 'this->S'; |
| 8587 | |
| 8588 | Expr *RelevantExpr = nullptr; |
| 8589 | |
| 8590 | // Flags to help capture some memory |
| 8591 | |
| 8592 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.2] |
| 8593 | // If a list item is an array section, it must specify contiguous storage. |
| 8594 | // |
| 8595 | // For this restriction it is sufficient that we make sure only references |
| 8596 | // to variables or fields and array expressions, and that no array sections |
| 8597 | // exist except in the rightmost expression. E.g. these would be invalid: |
| 8598 | // |
| 8599 | // r.ArrS[3:5].Arr[6:7] |
| 8600 | // |
| 8601 | // r.ArrS[3:5].x |
| 8602 | // |
| 8603 | // but these would be valid: |
| 8604 | // r.ArrS[3].Arr[6:7] |
| 8605 | // |
| 8606 | // r.ArrS[3].x |
| 8607 | |
| 8608 | bool IsRightMostExpression = true; |
| 8609 | |
| 8610 | while (!RelevantExpr) { |
| 8611 | auto AllowArraySection = IsRightMostExpression; |
| 8612 | IsRightMostExpression = false; |
| 8613 | |
| 8614 | E = E->IgnoreParenImpCasts(); |
| 8615 | |
| 8616 | if (auto *CurE = dyn_cast<DeclRefExpr>(E)) { |
| 8617 | if (!isa<VarDecl>(CurE->getDecl())) |
| 8618 | break; |
| 8619 | |
| 8620 | RelevantExpr = CurE; |
| 8621 | continue; |
| 8622 | } |
| 8623 | |
| 8624 | if (auto *CurE = dyn_cast<MemberExpr>(E)) { |
| 8625 | auto *BaseE = CurE->getBase()->IgnoreParenImpCasts(); |
| 8626 | |
| 8627 | if (isa<CXXThisExpr>(BaseE)) |
| 8628 | // We found a base expression: this->Val. |
| 8629 | RelevantExpr = CurE; |
| 8630 | else |
| 8631 | E = BaseE; |
| 8632 | |
| 8633 | if (!isa<FieldDecl>(CurE->getMemberDecl())) { |
| 8634 | SemaRef.Diag(ELoc, diag::err_omp_expected_access_to_data_field) |
| 8635 | << CurE->getSourceRange(); |
| 8636 | break; |
| 8637 | } |
| 8638 | |
| 8639 | auto *FD = cast<FieldDecl>(CurE->getMemberDecl()); |
| 8640 | |
| 8641 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C/C++, p.3] |
| 8642 | // A bit-field cannot appear in a map clause. |
| 8643 | // |
| 8644 | if (FD->isBitField()) { |
| 8645 | SemaRef.Diag(ELoc, diag::err_omp_bit_fields_forbidden_in_map_clause) |
| 8646 | << CurE->getSourceRange(); |
| 8647 | break; |
| 8648 | } |
| 8649 | |
| 8650 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] |
| 8651 | // If the type of a list item is a reference to a type T then the type |
| 8652 | // will be considered to be T for all purposes of this clause. |
| 8653 | QualType CurType = BaseE->getType(); |
| 8654 | if (CurType->isReferenceType()) |
| 8655 | CurType = CurType->getPointeeType(); |
| 8656 | |
| 8657 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C/C++, p.2] |
| 8658 | // A list item cannot be a variable that is a member of a structure with |
| 8659 | // a union type. |
| 8660 | // |
| 8661 | if (auto *RT = CurType->getAs<RecordType>()) |
| 8662 | if (RT->isUnionType()) { |
| 8663 | SemaRef.Diag(ELoc, diag::err_omp_union_type_not_allowed) |
| 8664 | << CurE->getSourceRange(); |
| 8665 | break; |
| 8666 | } |
| 8667 | |
| 8668 | continue; |
| 8669 | } |
| 8670 | |
| 8671 | if (auto *CurE = dyn_cast<ArraySubscriptExpr>(E)) { |
| 8672 | E = CurE->getBase()->IgnoreParenImpCasts(); |
| 8673 | |
| 8674 | if (!E->getType()->isAnyPointerType() && !E->getType()->isArrayType()) { |
| 8675 | SemaRef.Diag(ELoc, diag::err_omp_expected_base_var_name) |
| 8676 | << 0 << CurE->getSourceRange(); |
| 8677 | break; |
| 8678 | } |
| 8679 | continue; |
| 8680 | } |
| 8681 | |
| 8682 | if (auto *CurE = dyn_cast<OMPArraySectionExpr>(E)) { |
| 8683 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.7] |
| 8684 | // If a list item is an element of a structure, only the rightmost symbol |
| 8685 | // of the variable reference can be an array section. |
| 8686 | // |
| 8687 | if (!AllowArraySection) { |
| 8688 | SemaRef.Diag(ELoc, diag::err_omp_array_section_in_rightmost_expression) |
| 8689 | << CurE->getSourceRange(); |
| 8690 | break; |
| 8691 | } |
| 8692 | |
| 8693 | E = CurE->getBase()->IgnoreParenImpCasts(); |
| 8694 | |
| 8695 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] |
| 8696 | // If the type of a list item is a reference to a type T then the type |
| 8697 | // will be considered to be T for all purposes of this clause. |
| 8698 | QualType CurType = E->getType(); |
| 8699 | if (CurType->isReferenceType()) |
| 8700 | CurType = CurType->getPointeeType(); |
| 8701 | |
| 8702 | if (!CurType->isAnyPointerType() && !CurType->isArrayType()) { |
| 8703 | SemaRef.Diag(ELoc, diag::err_omp_expected_base_var_name) |
| 8704 | << 0 << CurE->getSourceRange(); |
| 8705 | break; |
| 8706 | } |
| 8707 | |
| 8708 | continue; |
| 8709 | } |
| 8710 | |
| 8711 | // If nothing else worked, this is not a valid map clause expression. |
| 8712 | SemaRef.Diag(ELoc, |
| 8713 | diag::err_omp_expected_named_var_member_or_array_expression) |
| 8714 | << ERange; |
| 8715 | break; |
| 8716 | } |
| 8717 | |
| 8718 | return RelevantExpr; |
| 8719 | } |
| 8720 | |
| 8721 | // Return true if expression E associated with value VD has conflicts with other |
| 8722 | // map information. |
| 8723 | static bool CheckMapConflicts(Sema &SemaRef, DSAStackTy *DSAS, ValueDecl *VD, |
| 8724 | Expr *E, bool CurrentRegionOnly) { |
| 8725 | assert(VD && E); |
| 8726 | |
| 8727 | // Types used to organize the components of a valid map clause. |
| 8728 | typedef std::pair<Expr *, ValueDecl *> MapExpressionComponent; |
| 8729 | typedef SmallVector<MapExpressionComponent, 4> MapExpressionComponents; |
| 8730 | |
| 8731 | // Helper to extract the components in the map clause expression E and store |
| 8732 | // them into MEC. This assumes that E is a valid map clause expression, i.e. |
| 8733 | // it has already passed the single clause checks. |
| 8734 | auto ExtractMapExpressionComponents = [](Expr *TE, |
| 8735 | MapExpressionComponents &MEC) { |
| 8736 | while (true) { |
| 8737 | TE = TE->IgnoreParenImpCasts(); |
| 8738 | |
| 8739 | if (auto *CurE = dyn_cast<DeclRefExpr>(TE)) { |
| 8740 | MEC.push_back( |
| 8741 | MapExpressionComponent(CurE, cast<VarDecl>(CurE->getDecl()))); |
| 8742 | break; |
| 8743 | } |
| 8744 | |
| 8745 | if (auto *CurE = dyn_cast<MemberExpr>(TE)) { |
| 8746 | auto *BaseE = CurE->getBase()->IgnoreParenImpCasts(); |
| 8747 | |
| 8748 | MEC.push_back(MapExpressionComponent( |
| 8749 | CurE, cast<FieldDecl>(CurE->getMemberDecl()))); |
| 8750 | if (isa<CXXThisExpr>(BaseE)) |
| 8751 | break; |
| 8752 | |
| 8753 | TE = BaseE; |
| 8754 | continue; |
| 8755 | } |
| 8756 | |
| 8757 | if (auto *CurE = dyn_cast<ArraySubscriptExpr>(TE)) { |
| 8758 | MEC.push_back(MapExpressionComponent(CurE, nullptr)); |
| 8759 | TE = CurE->getBase()->IgnoreParenImpCasts(); |
| 8760 | continue; |
| 8761 | } |
| 8762 | |
| 8763 | if (auto *CurE = dyn_cast<OMPArraySectionExpr>(TE)) { |
| 8764 | MEC.push_back(MapExpressionComponent(CurE, nullptr)); |
| 8765 | TE = CurE->getBase()->IgnoreParenImpCasts(); |
| 8766 | continue; |
| 8767 | } |
| 8768 | |
| 8769 | llvm_unreachable( |
| 8770 | "Expecting only valid map clause expressions at this point!"); |
| 8771 | } |
| 8772 | }; |
| 8773 | |
| 8774 | SourceLocation ELoc = E->getExprLoc(); |
| 8775 | SourceRange ERange = E->getSourceRange(); |
| 8776 | |
| 8777 | // In order to easily check the conflicts we need to match each component of |
| 8778 | // the expression under test with the components of the expressions that are |
| 8779 | // already in the stack. |
| 8780 | |
| 8781 | MapExpressionComponents CurComponents; |
| 8782 | ExtractMapExpressionComponents(E, CurComponents); |
| 8783 | |
| 8784 | assert(!CurComponents.empty() && "Map clause expression with no components!"); |
| 8785 | assert(CurComponents.back().second == VD && |
| 8786 | "Map clause expression with unexpected base!"); |
| 8787 | |
| 8788 | // Variables to help detecting enclosing problems in data environment nests. |
| 8789 | bool IsEnclosedByDataEnvironmentExpr = false; |
| 8790 | Expr *EnclosingExpr = nullptr; |
| 8791 | |
| 8792 | bool FoundError = |
| 8793 | DSAS->checkMapInfoForVar(VD, CurrentRegionOnly, [&](Expr *RE) -> bool { |
| 8794 | MapExpressionComponents StackComponents; |
| 8795 | ExtractMapExpressionComponents(RE, StackComponents); |
| 8796 | assert(!StackComponents.empty() && |
| 8797 | "Map clause expression with no components!"); |
| 8798 | assert(StackComponents.back().second == VD && |
| 8799 | "Map clause expression with unexpected base!"); |
| 8800 | |
| 8801 | // Expressions must start from the same base. Here we detect at which |
| 8802 | // point both expressions diverge from each other and see if we can |
| 8803 | // detect if the memory referred to both expressions is contiguous and |
| 8804 | // do not overlap. |
| 8805 | auto CI = CurComponents.rbegin(); |
| 8806 | auto CE = CurComponents.rend(); |
| 8807 | auto SI = StackComponents.rbegin(); |
| 8808 | auto SE = StackComponents.rend(); |
| 8809 | for (; CI != CE && SI != SE; ++CI, ++SI) { |
| 8810 | |
| 8811 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.3] |
| 8812 | // At most one list item can be an array item derived from a given |
| 8813 | // variable in map clauses of the same construct. |
| 8814 | if (CurrentRegionOnly && (isa<ArraySubscriptExpr>(CI->first) || |
| 8815 | isa<OMPArraySectionExpr>(CI->first)) && |
| 8816 | (isa<ArraySubscriptExpr>(SI->first) || |
| 8817 | isa<OMPArraySectionExpr>(SI->first))) { |
| 8818 | SemaRef.Diag(CI->first->getExprLoc(), |
| 8819 | diag::err_omp_multiple_array_items_in_map_clause) |
| 8820 | << CI->first->getSourceRange(); |
| 8821 | ; |
| 8822 | SemaRef.Diag(SI->first->getExprLoc(), diag::note_used_here) |
| 8823 | << SI->first->getSourceRange(); |
| 8824 | return true; |
| 8825 | } |
| 8826 | |
| 8827 | // Do both expressions have the same kind? |
| 8828 | if (CI->first->getStmtClass() != SI->first->getStmtClass()) |
| 8829 | break; |
| 8830 | |
| 8831 | // Are we dealing with different variables/fields? |
| 8832 | if (CI->second != SI->second) |
| 8833 | break; |
| 8834 | } |
| 8835 | |
| 8836 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.4] |
| 8837 | // List items of map clauses in the same construct must not share |
| 8838 | // original storage. |
| 8839 | // |
| 8840 | // If the expressions are exactly the same or one is a subset of the |
| 8841 | // other, it means they are sharing storage. |
| 8842 | if (CI == CE && SI == SE) { |
| 8843 | if (CurrentRegionOnly) { |
| 8844 | SemaRef.Diag(ELoc, diag::err_omp_map_shared_storage) << ERange; |
| 8845 | SemaRef.Diag(RE->getExprLoc(), diag::note_used_here) |
| 8846 | << RE->getSourceRange(); |
| 8847 | return true; |
| 8848 | } else { |
| 8849 | // If we find the same expression in the enclosing data environment, |
| 8850 | // that is legal. |
| 8851 | IsEnclosedByDataEnvironmentExpr = true; |
| 8852 | return false; |
| 8853 | } |
| 8854 | } |
| 8855 | |
| 8856 | QualType DerivedType = std::prev(CI)->first->getType(); |
| 8857 | SourceLocation DerivedLoc = std::prev(CI)->first->getExprLoc(); |
| 8858 | |
| 8859 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] |
| 8860 | // If the type of a list item is a reference to a type T then the type |
| 8861 | // will be considered to be T for all purposes of this clause. |
| 8862 | if (DerivedType->isReferenceType()) |
| 8863 | DerivedType = DerivedType->getPointeeType(); |
| 8864 | |
| 8865 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C/C++, p.1] |
| 8866 | // A variable for which the type is pointer and an array section |
| 8867 | // derived from that variable must not appear as list items of map |
| 8868 | // clauses of the same construct. |
| 8869 | // |
| 8870 | // Also, cover one of the cases in: |
| 8871 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.5] |
| 8872 | // If any part of the original storage of a list item has corresponding |
| 8873 | // storage in the device data environment, all of the original storage |
| 8874 | // must have corresponding storage in the device data environment. |
| 8875 | // |
| 8876 | if (DerivedType->isAnyPointerType()) { |
| 8877 | if (CI == CE || SI == SE) { |
| 8878 | SemaRef.Diag( |
| 8879 | DerivedLoc, |
| 8880 | diag::err_omp_pointer_mapped_along_with_derived_section) |
| 8881 | << DerivedLoc; |
| 8882 | } else { |
| 8883 | assert(CI != CE && SI != SE); |
| 8884 | SemaRef.Diag(DerivedLoc, diag::err_omp_same_pointer_derreferenced) |
| 8885 | << DerivedLoc; |
| 8886 | } |
| 8887 | SemaRef.Diag(RE->getExprLoc(), diag::note_used_here) |
| 8888 | << RE->getSourceRange(); |
| 8889 | return true; |
| 8890 | } |
| 8891 | |
| 8892 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.4] |
| 8893 | // List items of map clauses in the same construct must not share |
| 8894 | // original storage. |
| 8895 | // |
| 8896 | // An expression is a subset of the other. |
| 8897 | if (CurrentRegionOnly && (CI == CE || SI == SE)) { |
| 8898 | SemaRef.Diag(ELoc, diag::err_omp_map_shared_storage) << ERange; |
| 8899 | SemaRef.Diag(RE->getExprLoc(), diag::note_used_here) |
| 8900 | << RE->getSourceRange(); |
| 8901 | return true; |
| 8902 | } |
| 8903 | |
| 8904 | // The current expression uses the same base as other expression in the |
| 8905 | // data environment but does not contain it completelly. |
| 8906 | if (!CurrentRegionOnly && SI != SE) |
| 8907 | EnclosingExpr = RE; |
| 8908 | |
| 8909 | // The current expression is a subset of the expression in the data |
| 8910 | // environment. |
| 8911 | IsEnclosedByDataEnvironmentExpr |= |
| 8912 | (!CurrentRegionOnly && CI != CE && SI == SE); |
| 8913 | |
| 8914 | return false; |
| 8915 | }); |
| 8916 | |
| 8917 | if (CurrentRegionOnly) |
| 8918 | return FoundError; |
| 8919 | |
| 8920 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.5] |
| 8921 | // If any part of the original storage of a list item has corresponding |
| 8922 | // storage in the device data environment, all of the original storage must |
| 8923 | // have corresponding storage in the device data environment. |
| 8924 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.6] |
| 8925 | // If a list item is an element of a structure, and a different element of |
| 8926 | // the structure has a corresponding list item in the device data environment |
| 8927 | // prior to a task encountering the construct associated with the map clause, |
| 8928 | // then the list item must also have a correspnding list item in the device |
| 8929 | // data environment prior to the task encountering the construct. |
| 8930 | // |
| 8931 | if (EnclosingExpr && !IsEnclosedByDataEnvironmentExpr) { |
| 8932 | SemaRef.Diag(ELoc, |
| 8933 | diag::err_omp_original_storage_is_shared_and_does_not_contain) |
| 8934 | << ERange; |
| 8935 | SemaRef.Diag(EnclosingExpr->getExprLoc(), diag::note_used_here) |
| 8936 | << EnclosingExpr->getSourceRange(); |
| 8937 | return true; |
| 8938 | } |
| 8939 | |
| 8940 | return FoundError; |
| 8941 | } |
| 8942 | |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 8943 | OMPClause * |
| 8944 | Sema::ActOnOpenMPMapClause(OpenMPMapClauseKind MapTypeModifier, |
| 8945 | OpenMPMapClauseKind MapType, bool IsMapTypeImplicit, |
| 8946 | SourceLocation MapLoc, SourceLocation ColonLoc, |
| 8947 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
| 8948 | SourceLocation LParenLoc, SourceLocation EndLoc) { |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 8949 | SmallVector<Expr *, 4> Vars; |
| 8950 | |
| 8951 | for (auto &RE : VarList) { |
| 8952 | assert(RE && "Null expr in omp map"); |
| 8953 | if (isa<DependentScopeDeclRefExpr>(RE)) { |
| 8954 | // It will be analyzed later. |
| 8955 | Vars.push_back(RE); |
| 8956 | continue; |
| 8957 | } |
| 8958 | SourceLocation ELoc = RE->getExprLoc(); |
| 8959 | |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 8960 | auto *VE = RE->IgnoreParenLValueCasts(); |
| 8961 | |
| 8962 | if (VE->isValueDependent() || VE->isTypeDependent() || |
| 8963 | VE->isInstantiationDependent() || |
| 8964 | VE->containsUnexpandedParameterPack()) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 8965 | // We can only analyze this information once the missing information is |
| 8966 | // resolved. |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 8967 | Vars.push_back(RE); |
| 8968 | continue; |
| 8969 | } |
| 8970 | |
| 8971 | auto *SimpleExpr = RE->IgnoreParenCasts(); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 8972 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 8973 | if (!RE->IgnoreParenImpCasts()->isLValue()) { |
| 8974 | Diag(ELoc, diag::err_omp_expected_named_var_member_or_array_expression) |
| 8975 | << RE->getSourceRange(); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 8976 | continue; |
| 8977 | } |
| 8978 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 8979 | // Obtain the array or member expression bases if required. |
| 8980 | auto *BE = CheckMapClauseExpressionBase(*this, SimpleExpr); |
| 8981 | if (!BE) |
| 8982 | continue; |
| 8983 | |
| 8984 | // If the base is a reference to a variable, we rely on that variable for |
| 8985 | // the following checks. If it is a 'this' expression we rely on the field. |
| 8986 | ValueDecl *D = nullptr; |
| 8987 | if (auto *DRE = dyn_cast<DeclRefExpr>(BE)) { |
| 8988 | D = DRE->getDecl(); |
| 8989 | } else { |
| 8990 | auto *ME = cast<MemberExpr>(BE); |
| 8991 | assert(isa<CXXThisExpr>(ME->getBase()) && "Unexpected expression!"); |
| 8992 | D = ME->getMemberDecl(); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 8993 | } |
| 8994 | assert(D && "Null decl on map clause."); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 8995 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 8996 | auto *VD = dyn_cast<VarDecl>(D); |
| 8997 | auto *FD = dyn_cast<FieldDecl>(D); |
| 8998 | |
| 8999 | assert((VD || FD) && "Only variables or fields are expected here!"); |
NAKAMURA Takumi | 6dcb814 | 2016-01-23 01:38:20 +0000 | [diff] [blame] | 9000 | (void)FD; |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9001 | |
| 9002 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.10] |
| 9003 | // threadprivate variables cannot appear in a map clause. |
| 9004 | if (VD && DSAStack->isThreadPrivate(VD)) { |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9005 | auto DVar = DSAStack->getTopDSA(VD, false); |
| 9006 | Diag(ELoc, diag::err_omp_threadprivate_in_map); |
| 9007 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 9008 | continue; |
| 9009 | } |
| 9010 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9011 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.9] |
| 9012 | // A list item cannot appear in both a map clause and a data-sharing |
| 9013 | // attribute clause on the same construct. |
| 9014 | // |
| 9015 | // TODO: Implement this check - it cannot currently be tested because of |
| 9016 | // missing implementation of the other data sharing clauses in target |
| 9017 | // directives. |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9018 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9019 | // Check conflicts with other map clause expressions. We check the conflicts |
| 9020 | // with the current construct separately from the enclosing data |
| 9021 | // environment, because the restrictions are different. |
| 9022 | if (CheckMapConflicts(*this, DSAStack, D, SimpleExpr, |
| 9023 | /*CurrentRegionOnly=*/true)) |
| 9024 | break; |
| 9025 | if (CheckMapConflicts(*this, DSAStack, D, SimpleExpr, |
| 9026 | /*CurrentRegionOnly=*/false)) |
| 9027 | break; |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9028 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9029 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] |
| 9030 | // If the type of a list item is a reference to a type T then the type will |
| 9031 | // be considered to be T for all purposes of this clause. |
| 9032 | QualType Type = D->getType(); |
| 9033 | if (Type->isReferenceType()) |
| 9034 | Type = Type->getPointeeType(); |
| 9035 | |
| 9036 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.9] |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9037 | // A list item must have a mappable type. |
| 9038 | if (!CheckTypeMappable(VE->getExprLoc(), VE->getSourceRange(), *this, |
| 9039 | DSAStack, Type)) |
| 9040 | continue; |
| 9041 | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 9042 | // target enter data |
| 9043 | // OpenMP [2.10.2, Restrictions, p. 99] |
| 9044 | // A map-type must be specified in all map clauses and must be either |
| 9045 | // to or alloc. |
| 9046 | OpenMPDirectiveKind DKind = DSAStack->getCurrentDirective(); |
| 9047 | if (DKind == OMPD_target_enter_data && |
| 9048 | !(MapType == OMPC_MAP_to || MapType == OMPC_MAP_alloc)) { |
| 9049 | Diag(StartLoc, diag::err_omp_invalid_map_type_for_directive) |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 9050 | << (IsMapTypeImplicit ? 1 : 0) |
| 9051 | << getOpenMPSimpleClauseTypeName(OMPC_map, MapType) |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 9052 | << getOpenMPDirectiveName(DKind); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9053 | continue; |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 9054 | } |
| 9055 | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 9056 | // target exit_data |
| 9057 | // OpenMP [2.10.3, Restrictions, p. 102] |
| 9058 | // A map-type must be specified in all map clauses and must be either |
| 9059 | // from, release, or delete. |
| 9060 | DKind = DSAStack->getCurrentDirective(); |
| 9061 | if (DKind == OMPD_target_exit_data && |
| 9062 | !(MapType == OMPC_MAP_from || MapType == OMPC_MAP_release || |
| 9063 | MapType == OMPC_MAP_delete)) { |
| 9064 | Diag(StartLoc, diag::err_omp_invalid_map_type_for_directive) |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 9065 | << (IsMapTypeImplicit ? 1 : 0) |
| 9066 | << getOpenMPSimpleClauseTypeName(OMPC_map, MapType) |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 9067 | << getOpenMPDirectiveName(DKind); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9068 | continue; |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 9069 | } |
| 9070 | |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9071 | Vars.push_back(RE); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9072 | DSAStack->addExprToVarMapInfo(D, RE); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9073 | } |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9074 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9075 | // We need to produce a map clause even if we don't have variables so that |
| 9076 | // other diagnostics related with non-existing map clauses are accurate. |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9077 | return OMPMapClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 9078 | MapTypeModifier, MapType, IsMapTypeImplicit, |
| 9079 | MapLoc); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9080 | } |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 9081 | |
| 9082 | OMPClause *Sema::ActOnOpenMPNumTeamsClause(Expr *NumTeams, |
| 9083 | SourceLocation StartLoc, |
| 9084 | SourceLocation LParenLoc, |
| 9085 | SourceLocation EndLoc) { |
| 9086 | Expr *ValExpr = NumTeams; |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 9087 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 9088 | // OpenMP [teams Constrcut, Restrictions] |
| 9089 | // The num_teams expression must evaluate to a positive integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 9090 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_num_teams, |
| 9091 | /*StrictlyPositive=*/true)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 9092 | return nullptr; |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 9093 | |
| 9094 | return new (Context) OMPNumTeamsClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 9095 | } |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 9096 | |
| 9097 | OMPClause *Sema::ActOnOpenMPThreadLimitClause(Expr *ThreadLimit, |
| 9098 | SourceLocation StartLoc, |
| 9099 | SourceLocation LParenLoc, |
| 9100 | SourceLocation EndLoc) { |
| 9101 | Expr *ValExpr = ThreadLimit; |
| 9102 | |
| 9103 | // OpenMP [teams Constrcut, Restrictions] |
| 9104 | // The thread_limit expression must evaluate to a positive integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 9105 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_thread_limit, |
| 9106 | /*StrictlyPositive=*/true)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 9107 | return nullptr; |
| 9108 | |
| 9109 | return new (Context) OMPThreadLimitClause(ValExpr, StartLoc, LParenLoc, |
| 9110 | EndLoc); |
| 9111 | } |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 9112 | |
| 9113 | OMPClause *Sema::ActOnOpenMPPriorityClause(Expr *Priority, |
| 9114 | SourceLocation StartLoc, |
| 9115 | SourceLocation LParenLoc, |
| 9116 | SourceLocation EndLoc) { |
| 9117 | Expr *ValExpr = Priority; |
| 9118 | |
| 9119 | // OpenMP [2.9.1, task Constrcut] |
| 9120 | // The priority-value is a non-negative numerical scalar expression. |
| 9121 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_priority, |
| 9122 | /*StrictlyPositive=*/false)) |
| 9123 | return nullptr; |
| 9124 | |
| 9125 | return new (Context) OMPPriorityClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 9126 | } |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 9127 | |
| 9128 | OMPClause *Sema::ActOnOpenMPGrainsizeClause(Expr *Grainsize, |
| 9129 | SourceLocation StartLoc, |
| 9130 | SourceLocation LParenLoc, |
| 9131 | SourceLocation EndLoc) { |
| 9132 | Expr *ValExpr = Grainsize; |
| 9133 | |
| 9134 | // OpenMP [2.9.2, taskloop Constrcut] |
| 9135 | // The parameter of the grainsize clause must be a positive integer |
| 9136 | // expression. |
| 9137 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_grainsize, |
| 9138 | /*StrictlyPositive=*/true)) |
| 9139 | return nullptr; |
| 9140 | |
| 9141 | return new (Context) OMPGrainsizeClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 9142 | } |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 9143 | |
| 9144 | OMPClause *Sema::ActOnOpenMPNumTasksClause(Expr *NumTasks, |
| 9145 | SourceLocation StartLoc, |
| 9146 | SourceLocation LParenLoc, |
| 9147 | SourceLocation EndLoc) { |
| 9148 | Expr *ValExpr = NumTasks; |
| 9149 | |
| 9150 | // OpenMP [2.9.2, taskloop Constrcut] |
| 9151 | // The parameter of the num_tasks clause must be a positive integer |
| 9152 | // expression. |
| 9153 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_num_tasks, |
| 9154 | /*StrictlyPositive=*/true)) |
| 9155 | return nullptr; |
| 9156 | |
| 9157 | return new (Context) OMPNumTasksClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 9158 | } |
| 9159 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 9160 | OMPClause *Sema::ActOnOpenMPHintClause(Expr *Hint, SourceLocation StartLoc, |
| 9161 | SourceLocation LParenLoc, |
| 9162 | SourceLocation EndLoc) { |
| 9163 | // OpenMP [2.13.2, critical construct, Description] |
| 9164 | // ... where hint-expression is an integer constant expression that evaluates |
| 9165 | // to a valid lock hint. |
| 9166 | ExprResult HintExpr = VerifyPositiveIntegerConstantInClause(Hint, OMPC_hint); |
| 9167 | if (HintExpr.isInvalid()) |
| 9168 | return nullptr; |
| 9169 | return new (Context) |
| 9170 | OMPHintClause(HintExpr.get(), StartLoc, LParenLoc, EndLoc); |
| 9171 | } |
| 9172 | |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 9173 | OMPClause *Sema::ActOnOpenMPDistScheduleClause( |
| 9174 | OpenMPDistScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, |
| 9175 | SourceLocation LParenLoc, SourceLocation KindLoc, SourceLocation CommaLoc, |
| 9176 | SourceLocation EndLoc) { |
| 9177 | if (Kind == OMPC_DIST_SCHEDULE_unknown) { |
| 9178 | std::string Values; |
| 9179 | Values += "'"; |
| 9180 | Values += getOpenMPSimpleClauseTypeName(OMPC_dist_schedule, 0); |
| 9181 | Values += "'"; |
| 9182 | Diag(KindLoc, diag::err_omp_unexpected_clause_value) |
| 9183 | << Values << getOpenMPClauseName(OMPC_dist_schedule); |
| 9184 | return nullptr; |
| 9185 | } |
| 9186 | Expr *ValExpr = ChunkSize; |
| 9187 | Expr *HelperValExpr = nullptr; |
| 9188 | if (ChunkSize) { |
| 9189 | if (!ChunkSize->isValueDependent() && !ChunkSize->isTypeDependent() && |
| 9190 | !ChunkSize->isInstantiationDependent() && |
| 9191 | !ChunkSize->containsUnexpandedParameterPack()) { |
| 9192 | SourceLocation ChunkSizeLoc = ChunkSize->getLocStart(); |
| 9193 | ExprResult Val = |
| 9194 | PerformOpenMPImplicitIntegerConversion(ChunkSizeLoc, ChunkSize); |
| 9195 | if (Val.isInvalid()) |
| 9196 | return nullptr; |
| 9197 | |
| 9198 | ValExpr = Val.get(); |
| 9199 | |
| 9200 | // OpenMP [2.7.1, Restrictions] |
| 9201 | // chunk_size must be a loop invariant integer expression with a positive |
| 9202 | // value. |
| 9203 | llvm::APSInt Result; |
| 9204 | if (ValExpr->isIntegerConstantExpr(Result, Context)) { |
| 9205 | if (Result.isSigned() && !Result.isStrictlyPositive()) { |
| 9206 | Diag(ChunkSizeLoc, diag::err_omp_negative_expression_in_clause) |
| 9207 | << "dist_schedule" << ChunkSize->getSourceRange(); |
| 9208 | return nullptr; |
| 9209 | } |
| 9210 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective())) { |
| 9211 | auto *ImpVar = buildVarDecl(*this, ChunkSize->getExprLoc(), |
| 9212 | ChunkSize->getType(), ".chunk."); |
| 9213 | auto *ImpVarRef = buildDeclRefExpr(*this, ImpVar, ChunkSize->getType(), |
| 9214 | ChunkSize->getExprLoc(), |
| 9215 | /*RefersToCapture=*/true); |
| 9216 | HelperValExpr = ImpVarRef; |
| 9217 | } |
| 9218 | } |
| 9219 | } |
| 9220 | |
| 9221 | return new (Context) |
| 9222 | OMPDistScheduleClause(StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc, |
| 9223 | Kind, ValExpr, HelperValExpr); |
| 9224 | } |