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 | |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 812 | if (isOpenMPTargetExecutionDirective(DKind)) { |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 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 { |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 910 | return isOpenMPTargetExecutionDirective(K); |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 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() && |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 947 | DSAStack->hasExplicitDirective(isOpenMPTargetExecutionDirective, |
| 948 | Level); |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 949 | } |
| 950 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 951 | void Sema::DestroyDataSharingAttributesStack() { delete DSAStack; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 952 | |
| 953 | void Sema::StartOpenMPDSABlock(OpenMPDirectiveKind DKind, |
| 954 | const DeclarationNameInfo &DirName, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 955 | Scope *CurScope, SourceLocation Loc) { |
| 956 | DSAStack->push(DKind, DirName, CurScope, Loc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 957 | PushExpressionEvaluationContext(PotentiallyEvaluated); |
| 958 | } |
| 959 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 960 | void Sema::StartOpenMPClause(OpenMPClauseKind K) { |
| 961 | DSAStack->setClauseParsingMode(K); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 962 | } |
| 963 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 964 | void Sema::EndOpenMPClause() { |
| 965 | DSAStack->setClauseParsingMode(/*K=*/OMPC_unknown); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 966 | } |
| 967 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 968 | void Sema::EndOpenMPDSABlock(Stmt *CurDirective) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 969 | // OpenMP [2.14.3.5, Restrictions, C/C++, p.1] |
| 970 | // A variable of class type (or array thereof) that appears in a lastprivate |
| 971 | // clause requires an accessible, unambiguous default constructor for the |
| 972 | // class type, unless the list item is also specified in a firstprivate |
| 973 | // clause. |
| 974 | if (auto D = dyn_cast_or_null<OMPExecutableDirective>(CurDirective)) { |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 975 | for (auto *C : D->clauses()) { |
| 976 | if (auto *Clause = dyn_cast<OMPLastprivateClause>(C)) { |
| 977 | SmallVector<Expr *, 8> PrivateCopies; |
| 978 | for (auto *DE : Clause->varlists()) { |
| 979 | if (DE->isValueDependent() || DE->isTypeDependent()) { |
| 980 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 981 | continue; |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 982 | } |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 983 | DE = DE->IgnoreParens(); |
| 984 | VarDecl *VD = nullptr; |
| 985 | FieldDecl *FD = nullptr; |
| 986 | ValueDecl *D; |
| 987 | if (auto *DRE = dyn_cast<DeclRefExpr>(DE)) { |
| 988 | VD = cast<VarDecl>(DRE->getDecl()); |
| 989 | D = VD; |
| 990 | } else { |
| 991 | assert(isa<MemberExpr>(DE)); |
| 992 | FD = cast<FieldDecl>(cast<MemberExpr>(DE)->getMemberDecl()); |
| 993 | D = FD; |
| 994 | } |
| 995 | QualType Type = D->getType().getNonReferenceType(); |
| 996 | auto DVar = DSAStack->getTopDSA(D, false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 997 | if (DVar.CKind == OMPC_lastprivate) { |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 998 | // Generate helper private variable and initialize it with the |
| 999 | // default value. The address of the original variable is replaced |
| 1000 | // by the address of the new private variable in CodeGen. This new |
| 1001 | // variable is not added to IdResolver, so the code in the OpenMP |
| 1002 | // region uses original variable for proper diagnostics. |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 1003 | auto *VDPrivate = buildVarDecl( |
| 1004 | *this, DE->getExprLoc(), Type.getUnqualifiedType(), |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1005 | D->getName(), D->hasAttrs() ? &D->getAttrs() : nullptr); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1006 | ActOnUninitializedDecl(VDPrivate, /*TypeMayContainAuto=*/false); |
| 1007 | if (VDPrivate->isInvalidDecl()) |
| 1008 | continue; |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 1009 | PrivateCopies.push_back(buildDeclRefExpr( |
| 1010 | *this, VDPrivate, DE->getType(), DE->getExprLoc())); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1011 | } else { |
| 1012 | // The variable is also a firstprivate, so initialization sequence |
| 1013 | // for private copy is generated already. |
| 1014 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1015 | } |
| 1016 | } |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1017 | // Set initializers to private copies if no errors were found. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1018 | if (PrivateCopies.size() == Clause->varlist_size()) |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1019 | Clause->setPrivateCopies(PrivateCopies); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1020 | } |
| 1021 | } |
| 1022 | } |
| 1023 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1024 | DSAStack->pop(); |
| 1025 | DiscardCleanupsInEvaluationContext(); |
| 1026 | PopExpressionEvaluationContext(); |
| 1027 | } |
| 1028 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 1029 | static bool FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV, |
| 1030 | Expr *NumIterations, Sema &SemaRef, |
| 1031 | Scope *S); |
| 1032 | |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1033 | namespace { |
| 1034 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1035 | class VarDeclFilterCCC : public CorrectionCandidateCallback { |
| 1036 | private: |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1037 | Sema &SemaRef; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1038 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1039 | public: |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1040 | explicit VarDeclFilterCCC(Sema &S) : SemaRef(S) {} |
Craig Topper | e14c0f8 | 2014-03-12 04:55:44 +0000 | [diff] [blame] | 1041 | bool ValidateCandidate(const TypoCorrection &Candidate) override { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1042 | NamedDecl *ND = Candidate.getCorrectionDecl(); |
| 1043 | if (VarDecl *VD = dyn_cast_or_null<VarDecl>(ND)) { |
| 1044 | return VD->hasGlobalStorage() && |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1045 | SemaRef.isDeclInScope(ND, SemaRef.getCurLexicalContext(), |
| 1046 | SemaRef.getCurScope()); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1047 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1048 | return false; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1049 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1050 | }; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1051 | } // namespace |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1052 | |
| 1053 | ExprResult Sema::ActOnOpenMPIdExpression(Scope *CurScope, |
| 1054 | CXXScopeSpec &ScopeSpec, |
| 1055 | const DeclarationNameInfo &Id) { |
| 1056 | LookupResult Lookup(*this, Id, LookupOrdinaryName); |
| 1057 | LookupParsedName(Lookup, CurScope, &ScopeSpec, true); |
| 1058 | |
| 1059 | if (Lookup.isAmbiguous()) |
| 1060 | return ExprError(); |
| 1061 | |
| 1062 | VarDecl *VD; |
| 1063 | if (!Lookup.isSingleResult()) { |
Kaelyn Takata | 89c881b | 2014-10-27 18:07:29 +0000 | [diff] [blame] | 1064 | if (TypoCorrection Corrected = CorrectTypo( |
| 1065 | Id, LookupOrdinaryName, CurScope, nullptr, |
| 1066 | llvm::make_unique<VarDeclFilterCCC>(*this), CTK_ErrorRecovery)) { |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 1067 | diagnoseTypo(Corrected, |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 1068 | PDiag(Lookup.empty() |
| 1069 | ? diag::err_undeclared_var_use_suggest |
| 1070 | : diag::err_omp_expected_var_arg_suggest) |
| 1071 | << Id.getName()); |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 1072 | VD = Corrected.getCorrectionDeclAs<VarDecl>(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1073 | } else { |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 1074 | Diag(Id.getLoc(), Lookup.empty() ? diag::err_undeclared_var_use |
| 1075 | : diag::err_omp_expected_var_arg) |
| 1076 | << Id.getName(); |
| 1077 | return ExprError(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1078 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1079 | } else { |
| 1080 | if (!(VD = Lookup.getAsSingle<VarDecl>())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1081 | Diag(Id.getLoc(), diag::err_omp_expected_var_arg) << Id.getName(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1082 | Diag(Lookup.getFoundDecl()->getLocation(), diag::note_declared_at); |
| 1083 | return ExprError(); |
| 1084 | } |
| 1085 | } |
| 1086 | Lookup.suppressDiagnostics(); |
| 1087 | |
| 1088 | // OpenMP [2.9.2, Syntax, C/C++] |
| 1089 | // Variables must be file-scope, namespace-scope, or static block-scope. |
| 1090 | if (!VD->hasGlobalStorage()) { |
| 1091 | Diag(Id.getLoc(), diag::err_omp_global_var_arg) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1092 | << getOpenMPDirectiveName(OMPD_threadprivate) << !VD->isStaticLocal(); |
| 1093 | bool IsDecl = |
| 1094 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1095 | Diag(VD->getLocation(), |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1096 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1097 | << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1098 | return ExprError(); |
| 1099 | } |
| 1100 | |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1101 | VarDecl *CanonicalVD = VD->getCanonicalDecl(); |
| 1102 | NamedDecl *ND = cast<NamedDecl>(CanonicalVD); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1103 | // OpenMP [2.9.2, Restrictions, C/C++, p.2] |
| 1104 | // A threadprivate directive for file-scope variables must appear outside |
| 1105 | // any definition or declaration. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1106 | if (CanonicalVD->getDeclContext()->isTranslationUnit() && |
| 1107 | !getCurLexicalContext()->isTranslationUnit()) { |
| 1108 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1109 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1110 | bool IsDecl = |
| 1111 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1112 | Diag(VD->getLocation(), |
| 1113 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1114 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1115 | return ExprError(); |
| 1116 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1117 | // OpenMP [2.9.2, Restrictions, C/C++, p.3] |
| 1118 | // A threadprivate directive for static class member variables must appear |
| 1119 | // in the class definition, in the same scope in which the member |
| 1120 | // variables are declared. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1121 | if (CanonicalVD->isStaticDataMember() && |
| 1122 | !CanonicalVD->getDeclContext()->Equals(getCurLexicalContext())) { |
| 1123 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1124 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1125 | bool IsDecl = |
| 1126 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1127 | Diag(VD->getLocation(), |
| 1128 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1129 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1130 | return ExprError(); |
| 1131 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1132 | // OpenMP [2.9.2, Restrictions, C/C++, p.4] |
| 1133 | // A threadprivate directive for namespace-scope variables must appear |
| 1134 | // outside any definition or declaration other than the namespace |
| 1135 | // definition itself. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1136 | if (CanonicalVD->getDeclContext()->isNamespace() && |
| 1137 | (!getCurLexicalContext()->isFileContext() || |
| 1138 | !getCurLexicalContext()->Encloses(CanonicalVD->getDeclContext()))) { |
| 1139 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1140 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1141 | bool IsDecl = |
| 1142 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1143 | Diag(VD->getLocation(), |
| 1144 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1145 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1146 | return ExprError(); |
| 1147 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1148 | // OpenMP [2.9.2, Restrictions, C/C++, p.6] |
| 1149 | // A threadprivate directive for static block-scope variables must appear |
| 1150 | // in the scope of the variable and not in a nested scope. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1151 | if (CanonicalVD->isStaticLocal() && CurScope && |
| 1152 | !isDeclInScope(ND, getCurLexicalContext(), CurScope)) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1153 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1154 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1155 | bool IsDecl = |
| 1156 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1157 | Diag(VD->getLocation(), |
| 1158 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1159 | << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1160 | return ExprError(); |
| 1161 | } |
| 1162 | |
| 1163 | // OpenMP [2.9.2, Restrictions, C/C++, p.2-6] |
| 1164 | // A threadprivate directive must lexically precede all references to any |
| 1165 | // of the variables in its list. |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 1166 | if (VD->isUsed() && !DSAStack->isThreadPrivate(VD)) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1167 | Diag(Id.getLoc(), diag::err_omp_var_used) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1168 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1169 | return ExprError(); |
| 1170 | } |
| 1171 | |
| 1172 | QualType ExprType = VD->getType().getNonReferenceType(); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 1173 | ExprResult DE = buildDeclRefExpr(*this, VD, ExprType, Id.getLoc()); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1174 | return DE; |
| 1175 | } |
| 1176 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1177 | Sema::DeclGroupPtrTy |
| 1178 | Sema::ActOnOpenMPThreadprivateDirective(SourceLocation Loc, |
| 1179 | ArrayRef<Expr *> VarList) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1180 | if (OMPThreadPrivateDecl *D = CheckOMPThreadPrivateDecl(Loc, VarList)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1181 | CurContext->addDecl(D); |
| 1182 | return DeclGroupPtrTy::make(DeclGroupRef(D)); |
| 1183 | } |
David Blaikie | 0403cb1 | 2016-01-15 23:43:25 +0000 | [diff] [blame] | 1184 | return nullptr; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1185 | } |
| 1186 | |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1187 | namespace { |
| 1188 | class LocalVarRefChecker : public ConstStmtVisitor<LocalVarRefChecker, bool> { |
| 1189 | Sema &SemaRef; |
| 1190 | |
| 1191 | public: |
| 1192 | bool VisitDeclRefExpr(const DeclRefExpr *E) { |
| 1193 | if (auto VD = dyn_cast<VarDecl>(E->getDecl())) { |
| 1194 | if (VD->hasLocalStorage()) { |
| 1195 | SemaRef.Diag(E->getLocStart(), |
| 1196 | diag::err_omp_local_var_in_threadprivate_init) |
| 1197 | << E->getSourceRange(); |
| 1198 | SemaRef.Diag(VD->getLocation(), diag::note_defined_here) |
| 1199 | << VD << VD->getSourceRange(); |
| 1200 | return true; |
| 1201 | } |
| 1202 | } |
| 1203 | return false; |
| 1204 | } |
| 1205 | bool VisitStmt(const Stmt *S) { |
| 1206 | for (auto Child : S->children()) { |
| 1207 | if (Child && Visit(Child)) |
| 1208 | return true; |
| 1209 | } |
| 1210 | return false; |
| 1211 | } |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 1212 | explicit LocalVarRefChecker(Sema &SemaRef) : SemaRef(SemaRef) {} |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1213 | }; |
| 1214 | } // namespace |
| 1215 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1216 | OMPThreadPrivateDecl * |
| 1217 | Sema::CheckOMPThreadPrivateDecl(SourceLocation Loc, ArrayRef<Expr *> VarList) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1218 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1219 | for (auto &RefExpr : VarList) { |
| 1220 | DeclRefExpr *DE = cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1221 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); |
| 1222 | SourceLocation ILoc = DE->getExprLoc(); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1223 | |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 1224 | QualType QType = VD->getType(); |
| 1225 | if (QType->isDependentType() || QType->isInstantiationDependentType()) { |
| 1226 | // It will be analyzed later. |
| 1227 | Vars.push_back(DE); |
| 1228 | continue; |
| 1229 | } |
| 1230 | |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1231 | // OpenMP [2.9.2, Restrictions, C/C++, p.10] |
| 1232 | // A threadprivate variable must not have an incomplete type. |
| 1233 | if (RequireCompleteType(ILoc, VD->getType(), |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1234 | diag::err_omp_threadprivate_incomplete_type)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1235 | continue; |
| 1236 | } |
| 1237 | |
| 1238 | // OpenMP [2.9.2, Restrictions, C/C++, p.10] |
| 1239 | // A threadprivate variable must not have a reference type. |
| 1240 | if (VD->getType()->isReferenceType()) { |
| 1241 | Diag(ILoc, diag::err_omp_ref_type_arg) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1242 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD->getType(); |
| 1243 | bool IsDecl = |
| 1244 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1245 | Diag(VD->getLocation(), |
| 1246 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1247 | << VD; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1248 | continue; |
| 1249 | } |
| 1250 | |
Samuel Antao | f8b5012 | 2015-07-13 22:54:53 +0000 | [diff] [blame] | 1251 | // Check if this is a TLS variable. If TLS is not being supported, produce |
| 1252 | // the corresponding diagnostic. |
| 1253 | if ((VD->getTLSKind() != VarDecl::TLS_None && |
| 1254 | !(VD->hasAttr<OMPThreadPrivateDeclAttr>() && |
| 1255 | getLangOpts().OpenMPUseTLS && |
| 1256 | getASTContext().getTargetInfo().isTLSSupported())) || |
Alexey Bataev | 1a8b3f1 | 2015-05-06 06:34:55 +0000 | [diff] [blame] | 1257 | (VD->getStorageClass() == SC_Register && VD->hasAttr<AsmLabelAttr>() && |
| 1258 | !VD->isLocalVarDecl())) { |
Alexey Bataev | 26a3924 | 2015-01-13 03:35:30 +0000 | [diff] [blame] | 1259 | Diag(ILoc, diag::err_omp_var_thread_local) |
| 1260 | << VD << ((VD->getTLSKind() != VarDecl::TLS_None) ? 0 : 1); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1261 | bool IsDecl = |
| 1262 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1263 | Diag(VD->getLocation(), |
| 1264 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1265 | << VD; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1266 | continue; |
| 1267 | } |
| 1268 | |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1269 | // Check if initial value of threadprivate variable reference variable with |
| 1270 | // local storage (it is not supported by runtime). |
| 1271 | if (auto Init = VD->getAnyInitializer()) { |
| 1272 | LocalVarRefChecker Checker(*this); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1273 | if (Checker.Visit(Init)) |
| 1274 | continue; |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1275 | } |
| 1276 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1277 | Vars.push_back(RefExpr); |
Alexey Bataev | d178ad4 | 2014-03-07 08:03:37 +0000 | [diff] [blame] | 1278 | DSAStack->addDSA(VD, DE, OMPC_threadprivate); |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 1279 | VD->addAttr(OMPThreadPrivateDeclAttr::CreateImplicit( |
| 1280 | Context, SourceRange(Loc, Loc))); |
| 1281 | if (auto *ML = Context.getASTMutationListener()) |
| 1282 | ML->DeclarationMarkedOpenMPThreadPrivate(VD); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1283 | } |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 1284 | OMPThreadPrivateDecl *D = nullptr; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 1285 | if (!Vars.empty()) { |
| 1286 | D = OMPThreadPrivateDecl::Create(Context, getCurLexicalContext(), Loc, |
| 1287 | Vars); |
| 1288 | D->setAccess(AS_public); |
| 1289 | } |
| 1290 | return D; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1291 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1292 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1293 | static void ReportOriginalDSA(Sema &SemaRef, DSAStackTy *Stack, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1294 | const ValueDecl *D, DSAStackTy::DSAVarData DVar, |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1295 | bool IsLoopIterVar = false) { |
| 1296 | if (DVar.RefExpr) { |
| 1297 | SemaRef.Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_explicit_dsa) |
| 1298 | << getOpenMPClauseName(DVar.CKind); |
| 1299 | return; |
| 1300 | } |
| 1301 | enum { |
| 1302 | PDSA_StaticMemberShared, |
| 1303 | PDSA_StaticLocalVarShared, |
| 1304 | PDSA_LoopIterVarPrivate, |
| 1305 | PDSA_LoopIterVarLinear, |
| 1306 | PDSA_LoopIterVarLastprivate, |
| 1307 | PDSA_ConstVarShared, |
| 1308 | PDSA_GlobalVarShared, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1309 | PDSA_TaskVarFirstprivate, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1310 | PDSA_LocalVarPrivate, |
| 1311 | PDSA_Implicit |
| 1312 | } Reason = PDSA_Implicit; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1313 | bool ReportHint = false; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1314 | auto ReportLoc = D->getLocation(); |
| 1315 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1316 | if (IsLoopIterVar) { |
| 1317 | if (DVar.CKind == OMPC_private) |
| 1318 | Reason = PDSA_LoopIterVarPrivate; |
| 1319 | else if (DVar.CKind == OMPC_lastprivate) |
| 1320 | Reason = PDSA_LoopIterVarLastprivate; |
| 1321 | else |
| 1322 | Reason = PDSA_LoopIterVarLinear; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1323 | } else if (DVar.DKind == OMPD_task && DVar.CKind == OMPC_firstprivate) { |
| 1324 | Reason = PDSA_TaskVarFirstprivate; |
| 1325 | ReportLoc = DVar.ImplicitDSALoc; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1326 | } else if (VD && VD->isStaticLocal()) |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1327 | Reason = PDSA_StaticLocalVarShared; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1328 | else if (VD && VD->isStaticDataMember()) |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1329 | Reason = PDSA_StaticMemberShared; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1330 | else if (VD && VD->isFileVarDecl()) |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1331 | Reason = PDSA_GlobalVarShared; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1332 | else if (D->getType().isConstant(SemaRef.getASTContext())) |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1333 | Reason = PDSA_ConstVarShared; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1334 | else if (VD && VD->isLocalVarDecl() && DVar.CKind == OMPC_private) { |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1335 | ReportHint = true; |
| 1336 | Reason = PDSA_LocalVarPrivate; |
| 1337 | } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1338 | if (Reason != PDSA_Implicit) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1339 | SemaRef.Diag(ReportLoc, diag::note_omp_predetermined_dsa) |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1340 | << Reason << ReportHint |
| 1341 | << getOpenMPDirectiveName(Stack->getCurrentDirective()); |
| 1342 | } else if (DVar.ImplicitDSALoc.isValid()) { |
| 1343 | SemaRef.Diag(DVar.ImplicitDSALoc, diag::note_omp_implicit_dsa) |
| 1344 | << getOpenMPClauseName(DVar.CKind); |
| 1345 | } |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1346 | } |
| 1347 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1348 | namespace { |
| 1349 | class DSAAttrChecker : public StmtVisitor<DSAAttrChecker, void> { |
| 1350 | DSAStackTy *Stack; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1351 | Sema &SemaRef; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1352 | bool ErrorFound; |
| 1353 | CapturedStmt *CS; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1354 | llvm::SmallVector<Expr *, 8> ImplicitFirstprivate; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1355 | llvm::DenseMap<ValueDecl *, Expr *> VarsWithInheritedDSA; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1356 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1357 | public: |
| 1358 | void VisitDeclRefExpr(DeclRefExpr *E) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1359 | if (auto *VD = dyn_cast<VarDecl>(E->getDecl())) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1360 | // Skip internally declared variables. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1361 | if (VD->isLocalVarDecl() && !CS->capturesVariable(VD)) |
| 1362 | return; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1363 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1364 | auto DVar = Stack->getTopDSA(VD, false); |
| 1365 | // Check if the variable has explicit DSA set and stop analysis if it so. |
| 1366 | if (DVar.RefExpr) return; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1367 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1368 | auto ELoc = E->getExprLoc(); |
| 1369 | auto DKind = Stack->getCurrentDirective(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1370 | // The default(none) clause requires that each variable that is referenced |
| 1371 | // in the construct, and does not have a predetermined data-sharing |
| 1372 | // attribute, must have its data-sharing attribute explicitly determined |
| 1373 | // by being listed in a data-sharing attribute clause. |
| 1374 | if (DVar.CKind == OMPC_unknown && Stack->getDefaultDSA() == DSA_none && |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1375 | isParallelOrTaskRegion(DKind) && |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1376 | VarsWithInheritedDSA.count(VD) == 0) { |
| 1377 | VarsWithInheritedDSA[VD] = E; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1378 | return; |
| 1379 | } |
| 1380 | |
| 1381 | // OpenMP [2.9.3.6, Restrictions, p.2] |
| 1382 | // A list item that appears in a reduction clause of the innermost |
| 1383 | // enclosing worksharing or parallel construct may not be accessed in an |
| 1384 | // explicit task. |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1385 | DVar = Stack->hasInnermostDSA(VD, MatchesAnyClause(OMPC_reduction), |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1386 | [](OpenMPDirectiveKind K) -> bool { |
| 1387 | return isOpenMPParallelDirective(K) || |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1388 | isOpenMPWorksharingDirective(K) || |
| 1389 | isOpenMPTeamsDirective(K); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1390 | }, |
| 1391 | false); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1392 | if (DKind == OMPD_task && DVar.CKind == OMPC_reduction) { |
| 1393 | ErrorFound = true; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1394 | SemaRef.Diag(ELoc, diag::err_omp_reduction_in_task); |
| 1395 | ReportOriginalDSA(SemaRef, Stack, VD, DVar); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1396 | return; |
| 1397 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1398 | |
| 1399 | // Define implicit data-sharing attributes for task. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1400 | DVar = Stack->getImplicitDSA(VD, false); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1401 | if (DKind == OMPD_task && DVar.CKind != OMPC_shared) |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1402 | ImplicitFirstprivate.push_back(E); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1403 | } |
| 1404 | } |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1405 | void VisitMemberExpr(MemberExpr *E) { |
| 1406 | if (isa<CXXThisExpr>(E->getBase()->IgnoreParens())) { |
| 1407 | if (auto *FD = dyn_cast<FieldDecl>(E->getMemberDecl())) { |
| 1408 | auto DVar = Stack->getTopDSA(FD, false); |
| 1409 | // Check if the variable has explicit DSA set and stop analysis if it |
| 1410 | // so. |
| 1411 | if (DVar.RefExpr) |
| 1412 | return; |
| 1413 | |
| 1414 | auto ELoc = E->getExprLoc(); |
| 1415 | auto DKind = Stack->getCurrentDirective(); |
| 1416 | // OpenMP [2.9.3.6, Restrictions, p.2] |
| 1417 | // A list item that appears in a reduction clause of the innermost |
| 1418 | // enclosing worksharing or parallel construct may not be accessed in |
| 1419 | // an |
| 1420 | // explicit task. |
| 1421 | DVar = |
| 1422 | Stack->hasInnermostDSA(FD, MatchesAnyClause(OMPC_reduction), |
| 1423 | [](OpenMPDirectiveKind K) -> bool { |
| 1424 | return isOpenMPParallelDirective(K) || |
| 1425 | isOpenMPWorksharingDirective(K) || |
| 1426 | isOpenMPTeamsDirective(K); |
| 1427 | }, |
| 1428 | false); |
| 1429 | if (DKind == OMPD_task && DVar.CKind == OMPC_reduction) { |
| 1430 | ErrorFound = true; |
| 1431 | SemaRef.Diag(ELoc, diag::err_omp_reduction_in_task); |
| 1432 | ReportOriginalDSA(SemaRef, Stack, FD, DVar); |
| 1433 | return; |
| 1434 | } |
| 1435 | |
| 1436 | // Define implicit data-sharing attributes for task. |
| 1437 | DVar = Stack->getImplicitDSA(FD, false); |
| 1438 | if (DKind == OMPD_task && DVar.CKind != OMPC_shared) |
| 1439 | ImplicitFirstprivate.push_back(E); |
| 1440 | } |
| 1441 | } |
| 1442 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1443 | void VisitOMPExecutableDirective(OMPExecutableDirective *S) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1444 | for (auto *C : S->clauses()) { |
| 1445 | // Skip analysis of arguments of implicitly defined firstprivate clause |
| 1446 | // for task directives. |
| 1447 | if (C && (!isa<OMPFirstprivateClause>(C) || C->getLocStart().isValid())) |
| 1448 | for (auto *CC : C->children()) { |
| 1449 | if (CC) |
| 1450 | Visit(CC); |
| 1451 | } |
| 1452 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1453 | } |
| 1454 | void VisitStmt(Stmt *S) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1455 | for (auto *C : S->children()) { |
| 1456 | if (C && !isa<OMPExecutableDirective>(C)) |
| 1457 | Visit(C); |
| 1458 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1459 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1460 | |
| 1461 | bool isErrorFound() { return ErrorFound; } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1462 | ArrayRef<Expr *> getImplicitFirstprivate() { return ImplicitFirstprivate; } |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1463 | llvm::DenseMap<ValueDecl *, Expr *> &getVarsWithInheritedDSA() { |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1464 | return VarsWithInheritedDSA; |
| 1465 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1466 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1467 | DSAAttrChecker(DSAStackTy *S, Sema &SemaRef, CapturedStmt *CS) |
| 1468 | : Stack(S), SemaRef(SemaRef), ErrorFound(false), CS(CS) {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1469 | }; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1470 | } // namespace |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1471 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1472 | void Sema::ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, Scope *CurScope) { |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1473 | switch (DKind) { |
| 1474 | case OMPD_parallel: { |
| 1475 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1476 | QualType KmpInt32PtrTy = |
| 1477 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1478 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1479 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1480 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1481 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1482 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1483 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1484 | Params); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1485 | break; |
| 1486 | } |
| 1487 | case OMPD_simd: { |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1488 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1489 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1490 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1491 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1492 | Params); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1493 | break; |
| 1494 | } |
| 1495 | case OMPD_for: { |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1496 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1497 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1498 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1499 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1500 | Params); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1501 | break; |
| 1502 | } |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1503 | case OMPD_for_simd: { |
| 1504 | Sema::CapturedParamNameType Params[] = { |
| 1505 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1506 | }; |
| 1507 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1508 | Params); |
| 1509 | break; |
| 1510 | } |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 1511 | case OMPD_sections: { |
| 1512 | Sema::CapturedParamNameType Params[] = { |
| 1513 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1514 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1515 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1516 | Params); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 1517 | break; |
| 1518 | } |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1519 | case OMPD_section: { |
| 1520 | Sema::CapturedParamNameType Params[] = { |
| 1521 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1522 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1523 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1524 | Params); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1525 | break; |
| 1526 | } |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 1527 | case OMPD_single: { |
| 1528 | Sema::CapturedParamNameType Params[] = { |
| 1529 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1530 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1531 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1532 | Params); |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 1533 | break; |
| 1534 | } |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1535 | case OMPD_master: { |
| 1536 | Sema::CapturedParamNameType Params[] = { |
| 1537 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1538 | }; |
| 1539 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1540 | Params); |
| 1541 | break; |
| 1542 | } |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1543 | case OMPD_critical: { |
| 1544 | Sema::CapturedParamNameType Params[] = { |
| 1545 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1546 | }; |
| 1547 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1548 | Params); |
| 1549 | break; |
| 1550 | } |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1551 | case OMPD_parallel_for: { |
| 1552 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1553 | QualType KmpInt32PtrTy = |
| 1554 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1555 | Sema::CapturedParamNameType Params[] = { |
| 1556 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1557 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1558 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1559 | }; |
| 1560 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1561 | Params); |
| 1562 | break; |
| 1563 | } |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1564 | case OMPD_parallel_for_simd: { |
| 1565 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1566 | QualType KmpInt32PtrTy = |
| 1567 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1568 | Sema::CapturedParamNameType Params[] = { |
| 1569 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1570 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1571 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1572 | }; |
| 1573 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1574 | Params); |
| 1575 | break; |
| 1576 | } |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1577 | case OMPD_parallel_sections: { |
Alexey Bataev | 68adb7d | 2015-04-14 03:29:22 +0000 | [diff] [blame] | 1578 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1579 | QualType KmpInt32PtrTy = |
| 1580 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1581 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | 68adb7d | 2015-04-14 03:29:22 +0000 | [diff] [blame] | 1582 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1583 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1584 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1585 | }; |
| 1586 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1587 | Params); |
| 1588 | break; |
| 1589 | } |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1590 | case OMPD_task: { |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1591 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 3ae88e2 | 2015-05-22 08:56:35 +0000 | [diff] [blame] | 1592 | QualType Args[] = {Context.VoidPtrTy.withConst().withRestrict()}; |
| 1593 | FunctionProtoType::ExtProtoInfo EPI; |
| 1594 | EPI.Variadic = true; |
| 1595 | QualType CopyFnType = Context.getFunctionType(Context.VoidTy, Args, EPI); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1596 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1597 | std::make_pair(".global_tid.", KmpInt32Ty), |
| 1598 | std::make_pair(".part_id.", KmpInt32Ty), |
Alexey Bataev | 3ae88e2 | 2015-05-22 08:56:35 +0000 | [diff] [blame] | 1599 | std::make_pair(".privates.", |
| 1600 | Context.VoidPtrTy.withConst().withRestrict()), |
| 1601 | std::make_pair( |
| 1602 | ".copy_fn.", |
| 1603 | Context.getPointerType(CopyFnType).withConst().withRestrict()), |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1604 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1605 | }; |
| 1606 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1607 | Params); |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1608 | // Mark this captured region as inlined, because we don't use outlined |
| 1609 | // function directly. |
| 1610 | getCurCapturedRegion()->TheCapturedDecl->addAttr( |
| 1611 | AlwaysInlineAttr::CreateImplicit( |
| 1612 | Context, AlwaysInlineAttr::Keyword_forceinline, SourceRange())); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1613 | break; |
| 1614 | } |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1615 | case OMPD_ordered: { |
| 1616 | Sema::CapturedParamNameType Params[] = { |
| 1617 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1618 | }; |
| 1619 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1620 | Params); |
| 1621 | break; |
| 1622 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1623 | case OMPD_atomic: { |
| 1624 | Sema::CapturedParamNameType Params[] = { |
| 1625 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1626 | }; |
| 1627 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1628 | Params); |
| 1629 | break; |
| 1630 | } |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 1631 | case OMPD_target_data: |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 1632 | case OMPD_target: |
| 1633 | case OMPD_target_parallel: { |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1634 | Sema::CapturedParamNameType Params[] = { |
| 1635 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1636 | }; |
| 1637 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1638 | Params); |
| 1639 | break; |
| 1640 | } |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1641 | case OMPD_teams: { |
| 1642 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1643 | QualType KmpInt32PtrTy = |
| 1644 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1645 | Sema::CapturedParamNameType Params[] = { |
| 1646 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1647 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1648 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1649 | }; |
| 1650 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1651 | Params); |
| 1652 | break; |
| 1653 | } |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1654 | case OMPD_taskgroup: { |
| 1655 | Sema::CapturedParamNameType Params[] = { |
| 1656 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1657 | }; |
| 1658 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1659 | Params); |
| 1660 | break; |
| 1661 | } |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1662 | case OMPD_taskloop: { |
| 1663 | Sema::CapturedParamNameType Params[] = { |
| 1664 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1665 | }; |
| 1666 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1667 | Params); |
| 1668 | break; |
| 1669 | } |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1670 | case OMPD_taskloop_simd: { |
| 1671 | Sema::CapturedParamNameType Params[] = { |
| 1672 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1673 | }; |
| 1674 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1675 | Params); |
| 1676 | break; |
| 1677 | } |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1678 | case OMPD_distribute: { |
| 1679 | Sema::CapturedParamNameType Params[] = { |
| 1680 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1681 | }; |
| 1682 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1683 | Params); |
| 1684 | break; |
| 1685 | } |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1686 | case OMPD_threadprivate: |
Alexey Bataev | ee9af45 | 2014-11-21 11:33:46 +0000 | [diff] [blame] | 1687 | case OMPD_taskyield: |
| 1688 | case OMPD_barrier: |
| 1689 | case OMPD_taskwait: |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1690 | case OMPD_cancellation_point: |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1691 | case OMPD_cancel: |
Alexey Bataev | ee9af45 | 2014-11-21 11:33:46 +0000 | [diff] [blame] | 1692 | case OMPD_flush: |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1693 | case OMPD_target_enter_data: |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1694 | case OMPD_target_exit_data: |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1695 | llvm_unreachable("OpenMP Directive is not allowed"); |
| 1696 | case OMPD_unknown: |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1697 | llvm_unreachable("Unknown OpenMP directive"); |
| 1698 | } |
| 1699 | } |
| 1700 | |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1701 | StmtResult Sema::ActOnOpenMPRegionEnd(StmtResult S, |
| 1702 | ArrayRef<OMPClause *> Clauses) { |
| 1703 | if (!S.isUsable()) { |
| 1704 | ActOnCapturedRegionError(); |
| 1705 | return StmtError(); |
| 1706 | } |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1707 | |
| 1708 | OMPOrderedClause *OC = nullptr; |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1709 | OMPScheduleClause *SC = nullptr; |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1710 | SmallVector<OMPLinearClause *, 4> LCs; |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1711 | // This is required for proper codegen. |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1712 | for (auto *Clause : Clauses) { |
Alexey Bataev | 16dc7b6 | 2015-05-20 03:46:04 +0000 | [diff] [blame] | 1713 | if (isOpenMPPrivate(Clause->getClauseKind()) || |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 1714 | Clause->getClauseKind() == OMPC_copyprivate || |
| 1715 | (getLangOpts().OpenMPUseTLS && |
| 1716 | getASTContext().getTargetInfo().isTLSSupported() && |
| 1717 | Clause->getClauseKind() == OMPC_copyin)) { |
| 1718 | DSAStack->setForceVarCapturing(Clause->getClauseKind() == OMPC_copyin); |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1719 | // Mark all variables in private list clauses as used in inner region. |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1720 | for (auto *VarRef : Clause->children()) { |
| 1721 | if (auto *E = cast_or_null<Expr>(VarRef)) { |
Alexey Bataev | 8bf6b3e | 2015-04-02 13:07:08 +0000 | [diff] [blame] | 1722 | MarkDeclarationsReferencedInExpr(E); |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1723 | } |
| 1724 | } |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 1725 | DSAStack->setForceVarCapturing(/*V=*/false); |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1726 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective()) && |
| 1727 | Clause->getClauseKind() == OMPC_schedule) { |
| 1728 | // Mark all variables in private list clauses as used in inner region. |
| 1729 | // Required for proper codegen of combined directives. |
| 1730 | // TODO: add processing for other clauses. |
| 1731 | if (auto *E = cast_or_null<Expr>( |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1732 | cast<OMPScheduleClause>(Clause)->getHelperChunkSize())) |
| 1733 | MarkDeclarationsReferencedInExpr(E); |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1734 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1735 | if (Clause->getClauseKind() == OMPC_schedule) |
| 1736 | SC = cast<OMPScheduleClause>(Clause); |
| 1737 | else if (Clause->getClauseKind() == OMPC_ordered) |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1738 | OC = cast<OMPOrderedClause>(Clause); |
| 1739 | else if (Clause->getClauseKind() == OMPC_linear) |
| 1740 | LCs.push_back(cast<OMPLinearClause>(Clause)); |
| 1741 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1742 | bool ErrorFound = false; |
| 1743 | // OpenMP, 2.7.1 Loop Construct, Restrictions |
| 1744 | // The nonmonotonic modifier cannot be specified if an ordered clause is |
| 1745 | // specified. |
| 1746 | if (SC && |
| 1747 | (SC->getFirstScheduleModifier() == OMPC_SCHEDULE_MODIFIER_nonmonotonic || |
| 1748 | SC->getSecondScheduleModifier() == |
| 1749 | OMPC_SCHEDULE_MODIFIER_nonmonotonic) && |
| 1750 | OC) { |
| 1751 | Diag(SC->getFirstScheduleModifier() == OMPC_SCHEDULE_MODIFIER_nonmonotonic |
| 1752 | ? SC->getFirstScheduleModifierLoc() |
| 1753 | : SC->getSecondScheduleModifierLoc(), |
| 1754 | diag::err_omp_schedule_nonmonotonic_ordered) |
| 1755 | << SourceRange(OC->getLocStart(), OC->getLocEnd()); |
| 1756 | ErrorFound = true; |
| 1757 | } |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1758 | if (!LCs.empty() && OC && OC->getNumForLoops()) { |
| 1759 | for (auto *C : LCs) { |
| 1760 | Diag(C->getLocStart(), diag::err_omp_linear_ordered) |
| 1761 | << SourceRange(OC->getLocStart(), OC->getLocEnd()); |
| 1762 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1763 | ErrorFound = true; |
| 1764 | } |
Alexey Bataev | 113438c | 2015-12-30 12:06:23 +0000 | [diff] [blame] | 1765 | if (isOpenMPWorksharingDirective(DSAStack->getCurrentDirective()) && |
| 1766 | isOpenMPSimdDirective(DSAStack->getCurrentDirective()) && OC && |
| 1767 | OC->getNumForLoops()) { |
| 1768 | Diag(OC->getLocStart(), diag::err_omp_ordered_simd) |
| 1769 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 1770 | ErrorFound = true; |
| 1771 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1772 | if (ErrorFound) { |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1773 | ActOnCapturedRegionError(); |
| 1774 | return StmtError(); |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1775 | } |
| 1776 | return ActOnCapturedRegionEnd(S.get()); |
| 1777 | } |
| 1778 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1779 | static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, |
| 1780 | OpenMPDirectiveKind CurrentRegion, |
| 1781 | const DeclarationNameInfo &CurrentName, |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1782 | OpenMPDirectiveKind CancelRegion, |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1783 | SourceLocation StartLoc) { |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1784 | // Allowed nesting of constructs |
| 1785 | // +------------------+-----------------+------------------------------------+ |
| 1786 | // | Parent directive | Child directive | Closely (!), No-Closely(+), Both(*)| |
| 1787 | // +------------------+-----------------+------------------------------------+ |
| 1788 | // | parallel | parallel | * | |
| 1789 | // | parallel | for | * | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1790 | // | parallel | for simd | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1791 | // | parallel | master | * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1792 | // | parallel | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1793 | // | parallel | simd | * | |
| 1794 | // | parallel | sections | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1795 | // | parallel | section | + | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1796 | // | parallel | single | * | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1797 | // | parallel | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1798 | // | parallel |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1799 | // | parallel |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1800 | // | parallel | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1801 | // | parallel | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1802 | // | parallel | barrier | * | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1803 | // | parallel | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1804 | // | parallel | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1805 | // | parallel | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1806 | // | parallel | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1807 | // | parallel | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1808 | // | parallel | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 1809 | // | parallel | target parallel | * | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1810 | // | parallel | target enter | * | |
| 1811 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1812 | // | parallel | target exit | * | |
| 1813 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1814 | // | parallel | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1815 | // | parallel | cancellation | | |
| 1816 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1817 | // | parallel | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1818 | // | parallel | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1819 | // | parallel | taskloop simd | * | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1820 | // | parallel | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1821 | // +------------------+-----------------+------------------------------------+ |
| 1822 | // | for | parallel | * | |
| 1823 | // | for | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1824 | // | for | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1825 | // | for | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1826 | // | for | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1827 | // | for | simd | * | |
| 1828 | // | for | sections | + | |
| 1829 | // | for | section | + | |
| 1830 | // | for | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1831 | // | for | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1832 | // | for |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1833 | // | for |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1834 | // | for | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1835 | // | for | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1836 | // | for | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1837 | // | for | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1838 | // | for | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1839 | // | for | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1840 | // | for | ordered | * (if construct is ordered) | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1841 | // | for | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1842 | // | for | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 1843 | // | for | target parallel | * | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1844 | // | for | target enter | * | |
| 1845 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1846 | // | for | target exit | * | |
| 1847 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1848 | // | for | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1849 | // | for | cancellation | | |
| 1850 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1851 | // | for | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1852 | // | for | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1853 | // | for | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1854 | // | for | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1855 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1856 | // | master | parallel | * | |
| 1857 | // | master | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1858 | // | master | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1859 | // | master | master | * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1860 | // | master | critical | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1861 | // | master | simd | * | |
| 1862 | // | master | sections | + | |
| 1863 | // | master | section | + | |
| 1864 | // | master | single | + | |
| 1865 | // | master | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1866 | // | master |parallel for simd| * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1867 | // | master |parallel sections| * | |
| 1868 | // | master | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1869 | // | master | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1870 | // | master | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1871 | // | master | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1872 | // | master | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1873 | // | master | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1874 | // | master | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1875 | // | master | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1876 | // | master | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 1877 | // | master | target parallel | * | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1878 | // | master | target enter | * | |
| 1879 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1880 | // | master | target exit | * | |
| 1881 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1882 | // | master | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1883 | // | master | cancellation | | |
| 1884 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1885 | // | master | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1886 | // | master | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1887 | // | master | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1888 | // | master | distribute | | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1889 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1890 | // | critical | parallel | * | |
| 1891 | // | critical | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1892 | // | critical | for simd | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1893 | // | critical | master | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1894 | // | critical | critical | * (should have different names) | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1895 | // | critical | simd | * | |
| 1896 | // | critical | sections | + | |
| 1897 | // | critical | section | + | |
| 1898 | // | critical | single | + | |
| 1899 | // | critical | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1900 | // | critical |parallel for simd| * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1901 | // | critical |parallel sections| * | |
| 1902 | // | critical | task | * | |
| 1903 | // | critical | taskyield | * | |
| 1904 | // | critical | barrier | + | |
| 1905 | // | critical | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1906 | // | critical | taskgroup | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1907 | // | critical | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1908 | // | critical | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1909 | // | critical | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 1910 | // | critical | target parallel | * | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1911 | // | critical | target enter | * | |
| 1912 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1913 | // | critical | target exit | * | |
| 1914 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1915 | // | critical | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1916 | // | critical | cancellation | | |
| 1917 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1918 | // | critical | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1919 | // | critical | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1920 | // | critical | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1921 | // | critical | distribute | | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1922 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1923 | // | simd | parallel | | |
| 1924 | // | simd | for | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1925 | // | simd | for simd | | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1926 | // | simd | master | | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1927 | // | simd | critical | | |
Alexey Bataev | 1f09221 | 2016-02-02 04:59:52 +0000 | [diff] [blame^] | 1928 | // | simd | simd | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1929 | // | simd | sections | | |
| 1930 | // | simd | section | | |
| 1931 | // | simd | single | | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1932 | // | simd | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1933 | // | simd |parallel for simd| | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1934 | // | simd |parallel sections| | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1935 | // | simd | task | | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1936 | // | simd | taskyield | | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1937 | // | simd | barrier | | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1938 | // | simd | taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1939 | // | simd | taskgroup | | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1940 | // | simd | flush | | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 1941 | // | simd | ordered | + (with simd clause) | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1942 | // | simd | atomic | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1943 | // | simd | target | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 1944 | // | simd | target parallel | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1945 | // | simd | target enter | | |
| 1946 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1947 | // | simd | target exit | | |
| 1948 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1949 | // | simd | teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1950 | // | simd | cancellation | | |
| 1951 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1952 | // | simd | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1953 | // | simd | taskloop | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1954 | // | simd | taskloop simd | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1955 | // | simd | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1956 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1957 | // | for simd | parallel | | |
| 1958 | // | for simd | for | | |
| 1959 | // | for simd | for simd | | |
| 1960 | // | for simd | master | | |
| 1961 | // | for simd | critical | | |
Alexey Bataev | 1f09221 | 2016-02-02 04:59:52 +0000 | [diff] [blame^] | 1962 | // | for simd | simd | * | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1963 | // | for simd | sections | | |
| 1964 | // | for simd | section | | |
| 1965 | // | for simd | single | | |
| 1966 | // | for simd | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1967 | // | for simd |parallel for simd| | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1968 | // | for simd |parallel sections| | |
| 1969 | // | for simd | task | | |
| 1970 | // | for simd | taskyield | | |
| 1971 | // | for simd | barrier | | |
| 1972 | // | for simd | taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1973 | // | for simd | taskgroup | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1974 | // | for simd | flush | | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 1975 | // | for simd | ordered | + (with simd clause) | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1976 | // | for simd | atomic | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1977 | // | for simd | target | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 1978 | // | for simd | target parallel | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1979 | // | for simd | target enter | | |
| 1980 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1981 | // | for simd | target exit | | |
| 1982 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1983 | // | for simd | teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1984 | // | for simd | cancellation | | |
| 1985 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1986 | // | for simd | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1987 | // | for simd | taskloop | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1988 | // | for simd | taskloop simd | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1989 | // | for simd | distribute | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1990 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1991 | // | parallel for simd| parallel | | |
| 1992 | // | parallel for simd| for | | |
| 1993 | // | parallel for simd| for simd | | |
| 1994 | // | parallel for simd| master | | |
| 1995 | // | parallel for simd| critical | | |
Alexey Bataev | 1f09221 | 2016-02-02 04:59:52 +0000 | [diff] [blame^] | 1996 | // | parallel for simd| simd | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1997 | // | parallel for simd| sections | | |
| 1998 | // | parallel for simd| section | | |
| 1999 | // | parallel for simd| single | | |
| 2000 | // | parallel for simd| parallel for | | |
| 2001 | // | parallel for simd|parallel for simd| | |
| 2002 | // | parallel for simd|parallel sections| | |
| 2003 | // | parallel for simd| task | | |
| 2004 | // | parallel for simd| taskyield | | |
| 2005 | // | parallel for simd| barrier | | |
| 2006 | // | parallel for simd| taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2007 | // | parallel for simd| taskgroup | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2008 | // | parallel for simd| flush | | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2009 | // | parallel for simd| ordered | + (with simd clause) | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2010 | // | parallel for simd| atomic | | |
| 2011 | // | parallel for simd| target | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2012 | // | parallel for simd| target parallel | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2013 | // | parallel for simd| target enter | | |
| 2014 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2015 | // | parallel for simd| target exit | | |
| 2016 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2017 | // | parallel for simd| teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2018 | // | parallel for simd| cancellation | | |
| 2019 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2020 | // | parallel for simd| cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2021 | // | parallel for simd| taskloop | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2022 | // | parallel for simd| taskloop simd | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2023 | // | parallel for simd| distribute | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2024 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2025 | // | sections | parallel | * | |
| 2026 | // | sections | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2027 | // | sections | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2028 | // | sections | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2029 | // | sections | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2030 | // | sections | simd | * | |
| 2031 | // | sections | sections | + | |
| 2032 | // | sections | section | * | |
| 2033 | // | sections | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2034 | // | sections | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2035 | // | sections |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2036 | // | sections |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2037 | // | sections | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2038 | // | sections | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2039 | // | sections | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2040 | // | sections | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2041 | // | sections | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2042 | // | sections | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2043 | // | sections | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2044 | // | sections | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2045 | // | sections | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2046 | // | sections | target parallel | * | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2047 | // | sections | target enter | * | |
| 2048 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2049 | // | sections | target exit | * | |
| 2050 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2051 | // | sections | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2052 | // | sections | cancellation | | |
| 2053 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2054 | // | sections | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2055 | // | sections | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2056 | // | sections | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2057 | // | sections | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2058 | // +------------------+-----------------+------------------------------------+ |
| 2059 | // | section | parallel | * | |
| 2060 | // | section | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2061 | // | section | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2062 | // | section | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2063 | // | section | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2064 | // | section | simd | * | |
| 2065 | // | section | sections | + | |
| 2066 | // | section | section | + | |
| 2067 | // | section | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2068 | // | section | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2069 | // | section |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2070 | // | section |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2071 | // | section | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2072 | // | section | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2073 | // | section | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2074 | // | section | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2075 | // | section | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2076 | // | section | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2077 | // | section | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2078 | // | section | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2079 | // | section | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2080 | // | section | target parallel | * | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2081 | // | section | target enter | * | |
| 2082 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2083 | // | section | target exit | * | |
| 2084 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2085 | // | section | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2086 | // | section | cancellation | | |
| 2087 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2088 | // | section | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2089 | // | section | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2090 | // | section | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2091 | // | section | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2092 | // +------------------+-----------------+------------------------------------+ |
| 2093 | // | single | parallel | * | |
| 2094 | // | single | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2095 | // | single | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2096 | // | single | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2097 | // | single | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2098 | // | single | simd | * | |
| 2099 | // | single | sections | + | |
| 2100 | // | single | section | + | |
| 2101 | // | single | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2102 | // | single | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2103 | // | single |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2104 | // | single |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2105 | // | single | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2106 | // | single | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2107 | // | single | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2108 | // | single | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2109 | // | single | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2110 | // | single | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2111 | // | single | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2112 | // | single | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2113 | // | single | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2114 | // | single | target parallel | * | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2115 | // | single | target enter | * | |
| 2116 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2117 | // | single | target exit | * | |
| 2118 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2119 | // | single | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2120 | // | single | cancellation | | |
| 2121 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2122 | // | single | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2123 | // | single | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2124 | // | single | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2125 | // | single | distribute | | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2126 | // +------------------+-----------------+------------------------------------+ |
| 2127 | // | parallel for | parallel | * | |
| 2128 | // | parallel for | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2129 | // | parallel for | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2130 | // | parallel for | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2131 | // | parallel for | critical | * | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2132 | // | parallel for | simd | * | |
| 2133 | // | parallel for | sections | + | |
| 2134 | // | parallel for | section | + | |
| 2135 | // | parallel for | single | + | |
| 2136 | // | parallel for | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2137 | // | parallel for |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2138 | // | parallel for |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2139 | // | parallel for | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2140 | // | parallel for | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2141 | // | parallel for | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2142 | // | parallel for | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2143 | // | parallel for | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2144 | // | parallel for | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2145 | // | parallel for | ordered | * (if construct is ordered) | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2146 | // | parallel for | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2147 | // | parallel for | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2148 | // | parallel for | target parallel | * | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2149 | // | parallel for | target enter | * | |
| 2150 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2151 | // | parallel for | target exit | * | |
| 2152 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2153 | // | parallel for | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2154 | // | parallel for | cancellation | | |
| 2155 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2156 | // | parallel for | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2157 | // | parallel for | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2158 | // | parallel for | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2159 | // | parallel for | distribute | | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2160 | // +------------------+-----------------+------------------------------------+ |
| 2161 | // | parallel sections| parallel | * | |
| 2162 | // | parallel sections| for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2163 | // | parallel sections| for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2164 | // | parallel sections| master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2165 | // | parallel sections| critical | + | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2166 | // | parallel sections| simd | * | |
| 2167 | // | parallel sections| sections | + | |
| 2168 | // | parallel sections| section | * | |
| 2169 | // | parallel sections| single | + | |
| 2170 | // | parallel sections| parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2171 | // | parallel sections|parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2172 | // | parallel sections|parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2173 | // | parallel sections| task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2174 | // | parallel sections| taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2175 | // | parallel sections| barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2176 | // | parallel sections| taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2177 | // | parallel sections| taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2178 | // | parallel sections| flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2179 | // | parallel sections| ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2180 | // | parallel sections| atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2181 | // | parallel sections| target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2182 | // | parallel sections| target parallel | * | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2183 | // | parallel sections| target enter | * | |
| 2184 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2185 | // | parallel sections| target exit | * | |
| 2186 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2187 | // | parallel sections| teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2188 | // | parallel sections| cancellation | | |
| 2189 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2190 | // | parallel sections| cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2191 | // | parallel sections| taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2192 | // | parallel sections| taskloop simd | * | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2193 | // | parallel sections| distribute | | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2194 | // +------------------+-----------------+------------------------------------+ |
| 2195 | // | task | parallel | * | |
| 2196 | // | task | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2197 | // | task | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2198 | // | task | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2199 | // | task | critical | * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2200 | // | task | simd | * | |
| 2201 | // | task | sections | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2202 | // | task | section | + | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2203 | // | task | single | + | |
| 2204 | // | task | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2205 | // | task |parallel for simd| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2206 | // | task |parallel sections| * | |
| 2207 | // | task | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2208 | // | task | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2209 | // | task | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2210 | // | task | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2211 | // | task | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2212 | // | task | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2213 | // | task | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2214 | // | task | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2215 | // | task | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2216 | // | task | target parallel | * | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2217 | // | task | target enter | * | |
| 2218 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2219 | // | task | target exit | * | |
| 2220 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2221 | // | task | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2222 | // | task | cancellation | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2223 | // | | point | ! | |
| 2224 | // | task | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2225 | // | task | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2226 | // | task | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2227 | // | task | distribute | | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2228 | // +------------------+-----------------+------------------------------------+ |
| 2229 | // | ordered | parallel | * | |
| 2230 | // | ordered | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2231 | // | ordered | for simd | + | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2232 | // | ordered | master | * | |
| 2233 | // | ordered | critical | * | |
| 2234 | // | ordered | simd | * | |
| 2235 | // | ordered | sections | + | |
| 2236 | // | ordered | section | + | |
| 2237 | // | ordered | single | + | |
| 2238 | // | ordered | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2239 | // | ordered |parallel for simd| * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2240 | // | ordered |parallel sections| * | |
| 2241 | // | ordered | task | * | |
| 2242 | // | ordered | taskyield | * | |
| 2243 | // | ordered | barrier | + | |
| 2244 | // | ordered | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2245 | // | ordered | taskgroup | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2246 | // | ordered | flush | * | |
| 2247 | // | ordered | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2248 | // | ordered | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2249 | // | ordered | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2250 | // | ordered | target parallel | * | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2251 | // | ordered | target enter | * | |
| 2252 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2253 | // | ordered | target exit | * | |
| 2254 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2255 | // | ordered | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2256 | // | ordered | cancellation | | |
| 2257 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2258 | // | ordered | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2259 | // | ordered | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2260 | // | ordered | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2261 | // | ordered | distribute | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2262 | // +------------------+-----------------+------------------------------------+ |
| 2263 | // | atomic | parallel | | |
| 2264 | // | atomic | for | | |
| 2265 | // | atomic | for simd | | |
| 2266 | // | atomic | master | | |
| 2267 | // | atomic | critical | | |
| 2268 | // | atomic | simd | | |
| 2269 | // | atomic | sections | | |
| 2270 | // | atomic | section | | |
| 2271 | // | atomic | single | | |
| 2272 | // | atomic | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2273 | // | atomic |parallel for simd| | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2274 | // | atomic |parallel sections| | |
| 2275 | // | atomic | task | | |
| 2276 | // | atomic | taskyield | | |
| 2277 | // | atomic | barrier | | |
| 2278 | // | atomic | taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2279 | // | atomic | taskgroup | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2280 | // | atomic | flush | | |
| 2281 | // | atomic | ordered | | |
| 2282 | // | atomic | atomic | | |
| 2283 | // | atomic | target | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2284 | // | atomic | target parallel | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2285 | // | atomic | target enter | | |
| 2286 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2287 | // | atomic | target exit | | |
| 2288 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2289 | // | atomic | teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2290 | // | atomic | cancellation | | |
| 2291 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2292 | // | atomic | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2293 | // | atomic | taskloop | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2294 | // | atomic | taskloop simd | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2295 | // | atomic | distribute | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2296 | // +------------------+-----------------+------------------------------------+ |
| 2297 | // | target | parallel | * | |
| 2298 | // | target | for | * | |
| 2299 | // | target | for simd | * | |
| 2300 | // | target | master | * | |
| 2301 | // | target | critical | * | |
| 2302 | // | target | simd | * | |
| 2303 | // | target | sections | * | |
| 2304 | // | target | section | * | |
| 2305 | // | target | single | * | |
| 2306 | // | target | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2307 | // | target |parallel for simd| * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2308 | // | target |parallel sections| * | |
| 2309 | // | target | task | * | |
| 2310 | // | target | taskyield | * | |
| 2311 | // | target | barrier | * | |
| 2312 | // | target | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2313 | // | target | taskgroup | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2314 | // | target | flush | * | |
| 2315 | // | target | ordered | * | |
| 2316 | // | target | atomic | * | |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2317 | // | target | target | | |
| 2318 | // | target | target parallel | | |
| 2319 | // | target | target enter | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2320 | // | | data | | |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2321 | // | target | target exit | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2322 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2323 | // | target | teams | * | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2324 | // | target | cancellation | | |
| 2325 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2326 | // | target | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2327 | // | target | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2328 | // | target | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2329 | // | target | distribute | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2330 | // +------------------+-----------------+------------------------------------+ |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2331 | // | target parallel | parallel | * | |
| 2332 | // | target parallel | for | * | |
| 2333 | // | target parallel | for simd | * | |
| 2334 | // | target parallel | master | * | |
| 2335 | // | target parallel | critical | * | |
| 2336 | // | target parallel | simd | * | |
| 2337 | // | target parallel | sections | * | |
| 2338 | // | target parallel | section | * | |
| 2339 | // | target parallel | single | * | |
| 2340 | // | target parallel | parallel for | * | |
| 2341 | // | target parallel |parallel for simd| * | |
| 2342 | // | target parallel |parallel sections| * | |
| 2343 | // | target parallel | task | * | |
| 2344 | // | target parallel | taskyield | * | |
| 2345 | // | target parallel | barrier | * | |
| 2346 | // | target parallel | taskwait | * | |
| 2347 | // | target parallel | taskgroup | * | |
| 2348 | // | target parallel | flush | * | |
| 2349 | // | target parallel | ordered | * | |
| 2350 | // | target parallel | atomic | * | |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2351 | // | target parallel | target | | |
| 2352 | // | target parallel | target parallel | | |
| 2353 | // | target parallel | target enter | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2354 | // | | data | | |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2355 | // | target parallel | target exit | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2356 | // | | data | | |
| 2357 | // | target parallel | teams | | |
| 2358 | // | target parallel | cancellation | | |
| 2359 | // | | point | ! | |
| 2360 | // | target parallel | cancel | ! | |
| 2361 | // | target parallel | taskloop | * | |
| 2362 | // | target parallel | taskloop simd | * | |
| 2363 | // | target parallel | distribute | | |
| 2364 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2365 | // | teams | parallel | * | |
| 2366 | // | teams | for | + | |
| 2367 | // | teams | for simd | + | |
| 2368 | // | teams | master | + | |
| 2369 | // | teams | critical | + | |
| 2370 | // | teams | simd | + | |
| 2371 | // | teams | sections | + | |
| 2372 | // | teams | section | + | |
| 2373 | // | teams | single | + | |
| 2374 | // | teams | parallel for | * | |
| 2375 | // | teams |parallel for simd| * | |
| 2376 | // | teams |parallel sections| * | |
| 2377 | // | teams | task | + | |
| 2378 | // | teams | taskyield | + | |
| 2379 | // | teams | barrier | + | |
| 2380 | // | teams | taskwait | + | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2381 | // | teams | taskgroup | + | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2382 | // | teams | flush | + | |
| 2383 | // | teams | ordered | + | |
| 2384 | // | teams | atomic | + | |
| 2385 | // | teams | target | + | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2386 | // | teams | target parallel | + | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2387 | // | teams | target enter | + | |
| 2388 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2389 | // | teams | target exit | + | |
| 2390 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2391 | // | teams | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2392 | // | teams | cancellation | | |
| 2393 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2394 | // | teams | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2395 | // | teams | taskloop | + | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2396 | // | teams | taskloop simd | + | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2397 | // | teams | distribute | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2398 | // +------------------+-----------------+------------------------------------+ |
| 2399 | // | taskloop | parallel | * | |
| 2400 | // | taskloop | for | + | |
| 2401 | // | taskloop | for simd | + | |
| 2402 | // | taskloop | master | + | |
| 2403 | // | taskloop | critical | * | |
| 2404 | // | taskloop | simd | * | |
| 2405 | // | taskloop | sections | + | |
| 2406 | // | taskloop | section | + | |
| 2407 | // | taskloop | single | + | |
| 2408 | // | taskloop | parallel for | * | |
| 2409 | // | taskloop |parallel for simd| * | |
| 2410 | // | taskloop |parallel sections| * | |
| 2411 | // | taskloop | task | * | |
| 2412 | // | taskloop | taskyield | * | |
| 2413 | // | taskloop | barrier | + | |
| 2414 | // | taskloop | taskwait | * | |
| 2415 | // | taskloop | taskgroup | * | |
| 2416 | // | taskloop | flush | * | |
| 2417 | // | taskloop | ordered | + | |
| 2418 | // | taskloop | atomic | * | |
| 2419 | // | taskloop | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2420 | // | taskloop | target parallel | * | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2421 | // | taskloop | target enter | * | |
| 2422 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2423 | // | taskloop | target exit | * | |
| 2424 | // | | data | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2425 | // | taskloop | teams | + | |
| 2426 | // | taskloop | cancellation | | |
| 2427 | // | | point | | |
| 2428 | // | taskloop | cancel | | |
| 2429 | // | taskloop | taskloop | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2430 | // | taskloop | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2431 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2432 | // | taskloop simd | parallel | | |
| 2433 | // | taskloop simd | for | | |
| 2434 | // | taskloop simd | for simd | | |
| 2435 | // | taskloop simd | master | | |
| 2436 | // | taskloop simd | critical | | |
Alexey Bataev | 1f09221 | 2016-02-02 04:59:52 +0000 | [diff] [blame^] | 2437 | // | taskloop simd | simd | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2438 | // | taskloop simd | sections | | |
| 2439 | // | taskloop simd | section | | |
| 2440 | // | taskloop simd | single | | |
| 2441 | // | taskloop simd | parallel for | | |
| 2442 | // | taskloop simd |parallel for simd| | |
| 2443 | // | taskloop simd |parallel sections| | |
| 2444 | // | taskloop simd | task | | |
| 2445 | // | taskloop simd | taskyield | | |
| 2446 | // | taskloop simd | barrier | | |
| 2447 | // | taskloop simd | taskwait | | |
| 2448 | // | taskloop simd | taskgroup | | |
| 2449 | // | taskloop simd | flush | | |
| 2450 | // | taskloop simd | ordered | + (with simd clause) | |
| 2451 | // | taskloop simd | atomic | | |
| 2452 | // | taskloop simd | target | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2453 | // | taskloop simd | target parallel | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2454 | // | taskloop simd | target enter | | |
| 2455 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2456 | // | taskloop simd | target exit | | |
| 2457 | // | | data | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2458 | // | taskloop simd | teams | | |
| 2459 | // | taskloop simd | cancellation | | |
| 2460 | // | | point | | |
| 2461 | // | taskloop simd | cancel | | |
| 2462 | // | taskloop simd | taskloop | | |
| 2463 | // | taskloop simd | taskloop simd | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2464 | // | taskloop simd | distribute | | |
| 2465 | // +------------------+-----------------+------------------------------------+ |
| 2466 | // | distribute | parallel | * | |
| 2467 | // | distribute | for | * | |
| 2468 | // | distribute | for simd | * | |
| 2469 | // | distribute | master | * | |
| 2470 | // | distribute | critical | * | |
| 2471 | // | distribute | simd | * | |
| 2472 | // | distribute | sections | * | |
| 2473 | // | distribute | section | * | |
| 2474 | // | distribute | single | * | |
| 2475 | // | distribute | parallel for | * | |
| 2476 | // | distribute |parallel for simd| * | |
| 2477 | // | distribute |parallel sections| * | |
| 2478 | // | distribute | task | * | |
| 2479 | // | distribute | taskyield | * | |
| 2480 | // | distribute | barrier | * | |
| 2481 | // | distribute | taskwait | * | |
| 2482 | // | distribute | taskgroup | * | |
| 2483 | // | distribute | flush | * | |
| 2484 | // | distribute | ordered | + | |
| 2485 | // | distribute | atomic | * | |
| 2486 | // | distribute | target | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2487 | // | distribute | target parallel | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2488 | // | distribute | target enter | | |
| 2489 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2490 | // | distribute | target exit | | |
| 2491 | // | | data | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2492 | // | distribute | teams | | |
| 2493 | // | distribute | cancellation | + | |
| 2494 | // | | point | | |
| 2495 | // | distribute | cancel | + | |
| 2496 | // | distribute | taskloop | * | |
| 2497 | // | distribute | taskloop simd | * | |
| 2498 | // | distribute | distribute | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2499 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2500 | if (Stack->getCurScope()) { |
| 2501 | auto ParentRegion = Stack->getParentDirective(); |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2502 | auto OffendingRegion = ParentRegion; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2503 | bool NestingProhibited = false; |
| 2504 | bool CloseNesting = true; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2505 | enum { |
| 2506 | NoRecommend, |
| 2507 | ShouldBeInParallelRegion, |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2508 | ShouldBeInOrderedRegion, |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2509 | ShouldBeInTargetRegion, |
| 2510 | ShouldBeInTeamsRegion |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2511 | } Recommend = NoRecommend; |
Alexey Bataev | 1f09221 | 2016-02-02 04:59:52 +0000 | [diff] [blame^] | 2512 | if (isOpenMPSimdDirective(ParentRegion) && CurrentRegion != OMPD_ordered && |
| 2513 | CurrentRegion != OMPD_simd) { |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2514 | // OpenMP [2.16, Nesting of Regions] |
| 2515 | // OpenMP constructs may not be nested inside a simd region. |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2516 | // OpenMP [2.8.1,simd Construct, Restrictions] |
| 2517 | // An ordered construct with the simd clause is the only OpenMP construct |
| 2518 | // that can appear in the simd region. |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2519 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region_simd); |
| 2520 | return true; |
| 2521 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2522 | if (ParentRegion == OMPD_atomic) { |
| 2523 | // OpenMP [2.16, Nesting of Regions] |
| 2524 | // OpenMP constructs may not be nested inside an atomic region. |
| 2525 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region_atomic); |
| 2526 | return true; |
| 2527 | } |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2528 | if (CurrentRegion == OMPD_section) { |
| 2529 | // OpenMP [2.7.2, sections Construct, Restrictions] |
| 2530 | // Orphaned section directives are prohibited. That is, the section |
| 2531 | // directives must appear within the sections construct and must not be |
| 2532 | // encountered elsewhere in the sections region. |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2533 | if (ParentRegion != OMPD_sections && |
| 2534 | ParentRegion != OMPD_parallel_sections) { |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2535 | SemaRef.Diag(StartLoc, diag::err_omp_orphaned_section_directive) |
| 2536 | << (ParentRegion != OMPD_unknown) |
| 2537 | << getOpenMPDirectiveName(ParentRegion); |
| 2538 | return true; |
| 2539 | } |
| 2540 | return false; |
| 2541 | } |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2542 | // Allow some constructs to be orphaned (they could be used in functions, |
| 2543 | // called from OpenMP regions with the required preconditions). |
| 2544 | if (ParentRegion == OMPD_unknown) |
| 2545 | return false; |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2546 | if (CurrentRegion == OMPD_cancellation_point || |
| 2547 | CurrentRegion == OMPD_cancel) { |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2548 | // OpenMP [2.16, Nesting of Regions] |
| 2549 | // A cancellation point construct for which construct-type-clause is |
| 2550 | // taskgroup must be nested inside a task construct. A cancellation |
| 2551 | // point construct for which construct-type-clause is not taskgroup must |
| 2552 | // be closely nested inside an OpenMP construct that matches the type |
| 2553 | // specified in construct-type-clause. |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2554 | // A cancel construct for which construct-type-clause is taskgroup must be |
| 2555 | // nested inside a task construct. A cancel construct for which |
| 2556 | // construct-type-clause is not taskgroup must be closely nested inside an |
| 2557 | // OpenMP construct that matches the type specified in |
| 2558 | // construct-type-clause. |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2559 | NestingProhibited = |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2560 | !((CancelRegion == OMPD_parallel && |
| 2561 | (ParentRegion == OMPD_parallel || |
| 2562 | ParentRegion == OMPD_target_parallel)) || |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 2563 | (CancelRegion == OMPD_for && |
| 2564 | (ParentRegion == OMPD_for || ParentRegion == OMPD_parallel_for)) || |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2565 | (CancelRegion == OMPD_taskgroup && ParentRegion == OMPD_task) || |
| 2566 | (CancelRegion == OMPD_sections && |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 2567 | (ParentRegion == OMPD_section || ParentRegion == OMPD_sections || |
| 2568 | ParentRegion == OMPD_parallel_sections))); |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2569 | } else if (CurrentRegion == OMPD_master) { |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2570 | // OpenMP [2.16, Nesting of Regions] |
| 2571 | // A master region may not be closely nested inside a worksharing, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2572 | // atomic, or explicit task region. |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2573 | NestingProhibited = isOpenMPWorksharingDirective(ParentRegion) || |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2574 | ParentRegion == OMPD_task || |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2575 | isOpenMPTaskLoopDirective(ParentRegion); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2576 | } else if (CurrentRegion == OMPD_critical && CurrentName.getName()) { |
| 2577 | // OpenMP [2.16, Nesting of Regions] |
| 2578 | // A critical region may not be nested (closely or otherwise) inside a |
| 2579 | // critical region with the same name. Note that this restriction is not |
| 2580 | // sufficient to prevent deadlock. |
| 2581 | SourceLocation PreviousCriticalLoc; |
| 2582 | bool DeadLock = |
| 2583 | Stack->hasDirective([CurrentName, &PreviousCriticalLoc]( |
| 2584 | OpenMPDirectiveKind K, |
| 2585 | const DeclarationNameInfo &DNI, |
| 2586 | SourceLocation Loc) |
| 2587 | ->bool { |
| 2588 | if (K == OMPD_critical && |
| 2589 | DNI.getName() == CurrentName.getName()) { |
| 2590 | PreviousCriticalLoc = Loc; |
| 2591 | return true; |
| 2592 | } else |
| 2593 | return false; |
| 2594 | }, |
| 2595 | false /* skip top directive */); |
| 2596 | if (DeadLock) { |
| 2597 | SemaRef.Diag(StartLoc, |
| 2598 | diag::err_omp_prohibited_region_critical_same_name) |
| 2599 | << CurrentName.getName(); |
| 2600 | if (PreviousCriticalLoc.isValid()) |
| 2601 | SemaRef.Diag(PreviousCriticalLoc, |
| 2602 | diag::note_omp_previous_critical_region); |
| 2603 | return true; |
| 2604 | } |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2605 | } else if (CurrentRegion == OMPD_barrier) { |
| 2606 | // OpenMP [2.16, Nesting of Regions] |
| 2607 | // A barrier region may not be closely nested inside a worksharing, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2608 | // explicit task, critical, ordered, atomic, or master region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2609 | NestingProhibited = |
| 2610 | isOpenMPWorksharingDirective(ParentRegion) || |
| 2611 | ParentRegion == OMPD_task || ParentRegion == OMPD_master || |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2612 | ParentRegion == OMPD_critical || ParentRegion == OMPD_ordered || |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2613 | isOpenMPTaskLoopDirective(ParentRegion); |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2614 | } else if (isOpenMPWorksharingDirective(CurrentRegion) && |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2615 | !isOpenMPParallelDirective(CurrentRegion)) { |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2616 | // OpenMP [2.16, Nesting of Regions] |
| 2617 | // A worksharing region may not be closely nested inside a worksharing, |
| 2618 | // explicit task, critical, ordered, atomic, or master region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2619 | NestingProhibited = |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2620 | isOpenMPWorksharingDirective(ParentRegion) || |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2621 | ParentRegion == OMPD_task || ParentRegion == OMPD_master || |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2622 | ParentRegion == OMPD_critical || ParentRegion == OMPD_ordered || |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2623 | isOpenMPTaskLoopDirective(ParentRegion); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2624 | Recommend = ShouldBeInParallelRegion; |
| 2625 | } else if (CurrentRegion == OMPD_ordered) { |
| 2626 | // OpenMP [2.16, Nesting of Regions] |
| 2627 | // An ordered region may not be closely nested inside a critical, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2628 | // atomic, or explicit task region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2629 | // An ordered region must be closely nested inside a loop region (or |
| 2630 | // parallel loop region) with an ordered clause. |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2631 | // OpenMP [2.8.1,simd Construct, Restrictions] |
| 2632 | // An ordered construct with the simd clause is the only OpenMP construct |
| 2633 | // that can appear in the simd region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2634 | NestingProhibited = ParentRegion == OMPD_critical || |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2635 | ParentRegion == OMPD_task || |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2636 | isOpenMPTaskLoopDirective(ParentRegion) || |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2637 | !(isOpenMPSimdDirective(ParentRegion) || |
| 2638 | Stack->isParentOrderedRegion()); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2639 | Recommend = ShouldBeInOrderedRegion; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2640 | } else if (isOpenMPTeamsDirective(CurrentRegion)) { |
| 2641 | // OpenMP [2.16, Nesting of Regions] |
| 2642 | // If specified, a teams construct must be contained within a target |
| 2643 | // construct. |
| 2644 | NestingProhibited = ParentRegion != OMPD_target; |
| 2645 | Recommend = ShouldBeInTargetRegion; |
| 2646 | Stack->setParentTeamsRegionLoc(Stack->getConstructLoc()); |
| 2647 | } |
| 2648 | if (!NestingProhibited && isOpenMPTeamsDirective(ParentRegion)) { |
| 2649 | // OpenMP [2.16, Nesting of Regions] |
| 2650 | // distribute, parallel, parallel sections, parallel workshare, and the |
| 2651 | // parallel loop and parallel loop SIMD constructs are the only OpenMP |
| 2652 | // constructs that can be closely nested in the teams region. |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2653 | NestingProhibited = !isOpenMPParallelDirective(CurrentRegion) && |
| 2654 | !isOpenMPDistributeDirective(CurrentRegion); |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2655 | Recommend = ShouldBeInParallelRegion; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2656 | } |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2657 | if (!NestingProhibited && isOpenMPDistributeDirective(CurrentRegion)) { |
| 2658 | // OpenMP 4.5 [2.17 Nesting of Regions] |
| 2659 | // The region associated with the distribute construct must be strictly |
| 2660 | // nested inside a teams region |
| 2661 | NestingProhibited = !isOpenMPTeamsDirective(ParentRegion); |
| 2662 | Recommend = ShouldBeInTeamsRegion; |
| 2663 | } |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2664 | if (!NestingProhibited && |
| 2665 | (isOpenMPTargetExecutionDirective(CurrentRegion) || |
| 2666 | isOpenMPTargetDataManagementDirective(CurrentRegion))) { |
| 2667 | // OpenMP 4.5 [2.17 Nesting of Regions] |
| 2668 | // If a target, target update, target data, target enter data, or |
| 2669 | // target exit data construct is encountered during execution of a |
| 2670 | // target region, the behavior is unspecified. |
| 2671 | NestingProhibited = Stack->hasDirective( |
| 2672 | [&OffendingRegion](OpenMPDirectiveKind K, |
| 2673 | const DeclarationNameInfo &DNI, |
| 2674 | SourceLocation Loc) -> bool { |
| 2675 | if (isOpenMPTargetExecutionDirective(K)) { |
| 2676 | OffendingRegion = K; |
| 2677 | return true; |
| 2678 | } else |
| 2679 | return false; |
| 2680 | }, |
| 2681 | false /* don't skip top directive */); |
| 2682 | CloseNesting = false; |
| 2683 | } |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2684 | if (NestingProhibited) { |
| 2685 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region) |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2686 | << CloseNesting << getOpenMPDirectiveName(OffendingRegion) |
| 2687 | << Recommend << getOpenMPDirectiveName(CurrentRegion); |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2688 | return true; |
| 2689 | } |
| 2690 | } |
| 2691 | return false; |
| 2692 | } |
| 2693 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2694 | static bool checkIfClauses(Sema &S, OpenMPDirectiveKind Kind, |
| 2695 | ArrayRef<OMPClause *> Clauses, |
| 2696 | ArrayRef<OpenMPDirectiveKind> AllowedNameModifiers) { |
| 2697 | bool ErrorFound = false; |
| 2698 | unsigned NamedModifiersNumber = 0; |
| 2699 | SmallVector<const OMPIfClause *, OMPC_unknown + 1> FoundNameModifiers( |
| 2700 | OMPD_unknown + 1); |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2701 | SmallVector<SourceLocation, 4> NameModifierLoc; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2702 | for (const auto *C : Clauses) { |
| 2703 | if (const auto *IC = dyn_cast_or_null<OMPIfClause>(C)) { |
| 2704 | // At most one if clause without a directive-name-modifier can appear on |
| 2705 | // the directive. |
| 2706 | OpenMPDirectiveKind CurNM = IC->getNameModifier(); |
| 2707 | if (FoundNameModifiers[CurNM]) { |
| 2708 | S.Diag(C->getLocStart(), diag::err_omp_more_one_clause) |
| 2709 | << getOpenMPDirectiveName(Kind) << getOpenMPClauseName(OMPC_if) |
| 2710 | << (CurNM != OMPD_unknown) << getOpenMPDirectiveName(CurNM); |
| 2711 | ErrorFound = true; |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2712 | } else if (CurNM != OMPD_unknown) { |
| 2713 | NameModifierLoc.push_back(IC->getNameModifierLoc()); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2714 | ++NamedModifiersNumber; |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2715 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2716 | FoundNameModifiers[CurNM] = IC; |
| 2717 | if (CurNM == OMPD_unknown) |
| 2718 | continue; |
| 2719 | // Check if the specified name modifier is allowed for the current |
| 2720 | // directive. |
| 2721 | // At most one if clause with the particular directive-name-modifier can |
| 2722 | // appear on the directive. |
| 2723 | bool MatchFound = false; |
| 2724 | for (auto NM : AllowedNameModifiers) { |
| 2725 | if (CurNM == NM) { |
| 2726 | MatchFound = true; |
| 2727 | break; |
| 2728 | } |
| 2729 | } |
| 2730 | if (!MatchFound) { |
| 2731 | S.Diag(IC->getNameModifierLoc(), |
| 2732 | diag::err_omp_wrong_if_directive_name_modifier) |
| 2733 | << getOpenMPDirectiveName(CurNM) << getOpenMPDirectiveName(Kind); |
| 2734 | ErrorFound = true; |
| 2735 | } |
| 2736 | } |
| 2737 | } |
| 2738 | // If any if clause on the directive includes a directive-name-modifier then |
| 2739 | // all if clauses on the directive must include a directive-name-modifier. |
| 2740 | if (FoundNameModifiers[OMPD_unknown] && NamedModifiersNumber > 0) { |
| 2741 | if (NamedModifiersNumber == AllowedNameModifiers.size()) { |
| 2742 | S.Diag(FoundNameModifiers[OMPD_unknown]->getLocStart(), |
| 2743 | diag::err_omp_no_more_if_clause); |
| 2744 | } else { |
| 2745 | std::string Values; |
| 2746 | std::string Sep(", "); |
| 2747 | unsigned AllowedCnt = 0; |
| 2748 | unsigned TotalAllowedNum = |
| 2749 | AllowedNameModifiers.size() - NamedModifiersNumber; |
| 2750 | for (unsigned Cnt = 0, End = AllowedNameModifiers.size(); Cnt < End; |
| 2751 | ++Cnt) { |
| 2752 | OpenMPDirectiveKind NM = AllowedNameModifiers[Cnt]; |
| 2753 | if (!FoundNameModifiers[NM]) { |
| 2754 | Values += "'"; |
| 2755 | Values += getOpenMPDirectiveName(NM); |
| 2756 | Values += "'"; |
| 2757 | if (AllowedCnt + 2 == TotalAllowedNum) |
| 2758 | Values += " or "; |
| 2759 | else if (AllowedCnt + 1 != TotalAllowedNum) |
| 2760 | Values += Sep; |
| 2761 | ++AllowedCnt; |
| 2762 | } |
| 2763 | } |
| 2764 | S.Diag(FoundNameModifiers[OMPD_unknown]->getCondition()->getLocStart(), |
| 2765 | diag::err_omp_unnamed_if_clause) |
| 2766 | << (TotalAllowedNum > 1) << Values; |
| 2767 | } |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2768 | for (auto Loc : NameModifierLoc) { |
| 2769 | S.Diag(Loc, diag::note_omp_previous_named_if_clause); |
| 2770 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2771 | ErrorFound = true; |
| 2772 | } |
| 2773 | return ErrorFound; |
| 2774 | } |
| 2775 | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2776 | StmtResult Sema::ActOnOpenMPExecutableDirective( |
| 2777 | OpenMPDirectiveKind Kind, const DeclarationNameInfo &DirName, |
| 2778 | OpenMPDirectiveKind CancelRegion, ArrayRef<OMPClause *> Clauses, |
| 2779 | Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2780 | StmtResult Res = StmtError(); |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2781 | if (CheckNestingOfRegions(*this, DSAStack, Kind, DirName, CancelRegion, |
| 2782 | StartLoc)) |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2783 | return StmtError(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2784 | |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2785 | llvm::SmallVector<OMPClause *, 8> ClausesWithImplicit; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 2786 | llvm::DenseMap<ValueDecl *, Expr *> VarsWithInheritedDSA; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2787 | bool ErrorFound = false; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2788 | ClausesWithImplicit.append(Clauses.begin(), Clauses.end()); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2789 | if (AStmt) { |
| 2790 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 2791 | |
| 2792 | // Check default data sharing attributes for referenced variables. |
| 2793 | DSAAttrChecker DSAChecker(DSAStack, *this, cast<CapturedStmt>(AStmt)); |
| 2794 | DSAChecker.Visit(cast<CapturedStmt>(AStmt)->getCapturedStmt()); |
| 2795 | if (DSAChecker.isErrorFound()) |
| 2796 | return StmtError(); |
| 2797 | // Generate list of implicitly defined firstprivate variables. |
| 2798 | VarsWithInheritedDSA = DSAChecker.getVarsWithInheritedDSA(); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2799 | |
| 2800 | if (!DSAChecker.getImplicitFirstprivate().empty()) { |
| 2801 | if (OMPClause *Implicit = ActOnOpenMPFirstprivateClause( |
| 2802 | DSAChecker.getImplicitFirstprivate(), SourceLocation(), |
| 2803 | SourceLocation(), SourceLocation())) { |
| 2804 | ClausesWithImplicit.push_back(Implicit); |
| 2805 | ErrorFound = cast<OMPFirstprivateClause>(Implicit)->varlist_size() != |
| 2806 | DSAChecker.getImplicitFirstprivate().size(); |
| 2807 | } else |
| 2808 | ErrorFound = true; |
| 2809 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2810 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2811 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2812 | llvm::SmallVector<OpenMPDirectiveKind, 4> AllowedNameModifiers; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2813 | switch (Kind) { |
| 2814 | case OMPD_parallel: |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2815 | Res = ActOnOpenMPParallelDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2816 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2817 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2818 | break; |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 2819 | case OMPD_simd: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2820 | Res = ActOnOpenMPSimdDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc, |
| 2821 | VarsWithInheritedDSA); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 2822 | break; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2823 | case OMPD_for: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2824 | Res = ActOnOpenMPForDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc, |
| 2825 | VarsWithInheritedDSA); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2826 | break; |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2827 | case OMPD_for_simd: |
| 2828 | Res = ActOnOpenMPForSimdDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2829 | EndLoc, VarsWithInheritedDSA); |
| 2830 | break; |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 2831 | case OMPD_sections: |
| 2832 | Res = ActOnOpenMPSectionsDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2833 | EndLoc); |
| 2834 | break; |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2835 | case OMPD_section: |
| 2836 | assert(ClausesWithImplicit.empty() && |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2837 | "No clauses are allowed for 'omp section' directive"); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2838 | Res = ActOnOpenMPSectionDirective(AStmt, StartLoc, EndLoc); |
| 2839 | break; |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 2840 | case OMPD_single: |
| 2841 | Res = ActOnOpenMPSingleDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2842 | EndLoc); |
| 2843 | break; |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2844 | case OMPD_master: |
| 2845 | assert(ClausesWithImplicit.empty() && |
| 2846 | "No clauses are allowed for 'omp master' directive"); |
| 2847 | Res = ActOnOpenMPMasterDirective(AStmt, StartLoc, EndLoc); |
| 2848 | break; |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2849 | case OMPD_critical: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 2850 | Res = ActOnOpenMPCriticalDirective(DirName, ClausesWithImplicit, AStmt, |
| 2851 | StartLoc, EndLoc); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2852 | break; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2853 | case OMPD_parallel_for: |
| 2854 | Res = ActOnOpenMPParallelForDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2855 | EndLoc, VarsWithInheritedDSA); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2856 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2857 | break; |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2858 | case OMPD_parallel_for_simd: |
| 2859 | Res = ActOnOpenMPParallelForSimdDirective( |
| 2860 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2861 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2862 | break; |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2863 | case OMPD_parallel_sections: |
| 2864 | Res = ActOnOpenMPParallelSectionsDirective(ClausesWithImplicit, AStmt, |
| 2865 | StartLoc, EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2866 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2867 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2868 | case OMPD_task: |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2869 | Res = |
| 2870 | ActOnOpenMPTaskDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2871 | AllowedNameModifiers.push_back(OMPD_task); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2872 | break; |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2873 | case OMPD_taskyield: |
| 2874 | assert(ClausesWithImplicit.empty() && |
| 2875 | "No clauses are allowed for 'omp taskyield' directive"); |
| 2876 | assert(AStmt == nullptr && |
| 2877 | "No associated statement allowed for 'omp taskyield' directive"); |
| 2878 | Res = ActOnOpenMPTaskyieldDirective(StartLoc, EndLoc); |
| 2879 | break; |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2880 | case OMPD_barrier: |
| 2881 | assert(ClausesWithImplicit.empty() && |
| 2882 | "No clauses are allowed for 'omp barrier' directive"); |
| 2883 | assert(AStmt == nullptr && |
| 2884 | "No associated statement allowed for 'omp barrier' directive"); |
| 2885 | Res = ActOnOpenMPBarrierDirective(StartLoc, EndLoc); |
| 2886 | break; |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2887 | case OMPD_taskwait: |
| 2888 | assert(ClausesWithImplicit.empty() && |
| 2889 | "No clauses are allowed for 'omp taskwait' directive"); |
| 2890 | assert(AStmt == nullptr && |
| 2891 | "No associated statement allowed for 'omp taskwait' directive"); |
| 2892 | Res = ActOnOpenMPTaskwaitDirective(StartLoc, EndLoc); |
| 2893 | break; |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2894 | case OMPD_taskgroup: |
| 2895 | assert(ClausesWithImplicit.empty() && |
| 2896 | "No clauses are allowed for 'omp taskgroup' directive"); |
| 2897 | Res = ActOnOpenMPTaskgroupDirective(AStmt, StartLoc, EndLoc); |
| 2898 | break; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2899 | case OMPD_flush: |
| 2900 | assert(AStmt == nullptr && |
| 2901 | "No associated statement allowed for 'omp flush' directive"); |
| 2902 | Res = ActOnOpenMPFlushDirective(ClausesWithImplicit, StartLoc, EndLoc); |
| 2903 | break; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2904 | case OMPD_ordered: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 2905 | Res = ActOnOpenMPOrderedDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2906 | EndLoc); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2907 | break; |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2908 | case OMPD_atomic: |
| 2909 | Res = ActOnOpenMPAtomicDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2910 | EndLoc); |
| 2911 | break; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2912 | case OMPD_teams: |
| 2913 | Res = |
| 2914 | ActOnOpenMPTeamsDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); |
| 2915 | break; |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2916 | case OMPD_target: |
| 2917 | Res = ActOnOpenMPTargetDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2918 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2919 | AllowedNameModifiers.push_back(OMPD_target); |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2920 | break; |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2921 | case OMPD_target_parallel: |
| 2922 | Res = ActOnOpenMPTargetParallelDirective(ClausesWithImplicit, AStmt, |
| 2923 | StartLoc, EndLoc); |
| 2924 | AllowedNameModifiers.push_back(OMPD_target); |
| 2925 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 2926 | break; |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2927 | case OMPD_cancellation_point: |
| 2928 | assert(ClausesWithImplicit.empty() && |
| 2929 | "No clauses are allowed for 'omp cancellation point' directive"); |
| 2930 | assert(AStmt == nullptr && "No associated statement allowed for 'omp " |
| 2931 | "cancellation point' directive"); |
| 2932 | Res = ActOnOpenMPCancellationPointDirective(StartLoc, EndLoc, CancelRegion); |
| 2933 | break; |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2934 | case OMPD_cancel: |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2935 | assert(AStmt == nullptr && |
| 2936 | "No associated statement allowed for 'omp cancel' directive"); |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 2937 | Res = ActOnOpenMPCancelDirective(ClausesWithImplicit, StartLoc, EndLoc, |
| 2938 | CancelRegion); |
| 2939 | AllowedNameModifiers.push_back(OMPD_cancel); |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2940 | break; |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 2941 | case OMPD_target_data: |
| 2942 | Res = ActOnOpenMPTargetDataDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2943 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2944 | AllowedNameModifiers.push_back(OMPD_target_data); |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 2945 | break; |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2946 | case OMPD_target_enter_data: |
| 2947 | Res = ActOnOpenMPTargetEnterDataDirective(ClausesWithImplicit, StartLoc, |
| 2948 | EndLoc); |
| 2949 | AllowedNameModifiers.push_back(OMPD_target_enter_data); |
| 2950 | break; |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2951 | case OMPD_target_exit_data: |
| 2952 | Res = ActOnOpenMPTargetExitDataDirective(ClausesWithImplicit, StartLoc, |
| 2953 | EndLoc); |
| 2954 | AllowedNameModifiers.push_back(OMPD_target_exit_data); |
| 2955 | break; |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2956 | case OMPD_taskloop: |
| 2957 | Res = ActOnOpenMPTaskLoopDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2958 | EndLoc, VarsWithInheritedDSA); |
| 2959 | AllowedNameModifiers.push_back(OMPD_taskloop); |
| 2960 | break; |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2961 | case OMPD_taskloop_simd: |
| 2962 | Res = ActOnOpenMPTaskLoopSimdDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2963 | EndLoc, VarsWithInheritedDSA); |
| 2964 | AllowedNameModifiers.push_back(OMPD_taskloop); |
| 2965 | break; |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2966 | case OMPD_distribute: |
| 2967 | Res = ActOnOpenMPDistributeDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2968 | EndLoc, VarsWithInheritedDSA); |
| 2969 | break; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2970 | case OMPD_threadprivate: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2971 | llvm_unreachable("OpenMP Directive is not allowed"); |
| 2972 | case OMPD_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2973 | llvm_unreachable("Unknown OpenMP directive"); |
| 2974 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2975 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2976 | for (auto P : VarsWithInheritedDSA) { |
| 2977 | Diag(P.second->getExprLoc(), diag::err_omp_no_dsa_for_variable) |
| 2978 | << P.first << P.second->getSourceRange(); |
| 2979 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2980 | ErrorFound = !VarsWithInheritedDSA.empty() || ErrorFound; |
| 2981 | |
| 2982 | if (!AllowedNameModifiers.empty()) |
| 2983 | ErrorFound = checkIfClauses(*this, Kind, Clauses, AllowedNameModifiers) || |
| 2984 | ErrorFound; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2985 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2986 | if (ErrorFound) |
| 2987 | return StmtError(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2988 | return Res; |
| 2989 | } |
| 2990 | |
| 2991 | StmtResult Sema::ActOnOpenMPParallelDirective(ArrayRef<OMPClause *> Clauses, |
| 2992 | Stmt *AStmt, |
| 2993 | SourceLocation StartLoc, |
| 2994 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2995 | if (!AStmt) |
| 2996 | return StmtError(); |
| 2997 | |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 2998 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 2999 | // 1.2.2 OpenMP Language Terminology |
| 3000 | // Structured block - An executable statement with a single entry at the |
| 3001 | // top and a single exit at the bottom. |
| 3002 | // The point of exit cannot be a branch out of the structured block. |
| 3003 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 3004 | CS->getCapturedDecl()->setNothrow(); |
| 3005 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3006 | getCurFunction()->setHasBranchProtectedScope(); |
| 3007 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 3008 | return OMPParallelDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 3009 | DSAStack->isCancelRegion()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3010 | } |
| 3011 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3012 | namespace { |
| 3013 | /// \brief Helper class for checking canonical form of the OpenMP loops and |
| 3014 | /// extracting iteration space of each loop in the loop nest, that will be used |
| 3015 | /// for IR generation. |
| 3016 | class OpenMPIterationSpaceChecker { |
| 3017 | /// \brief Reference to Sema. |
| 3018 | Sema &SemaRef; |
| 3019 | /// \brief A location for diagnostics (when there is no some better location). |
| 3020 | SourceLocation DefaultLoc; |
| 3021 | /// \brief A location for diagnostics (when increment is not compatible). |
| 3022 | SourceLocation ConditionLoc; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3023 | /// \brief A source location for referring to loop init later. |
| 3024 | SourceRange InitSrcRange; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3025 | /// \brief A source location for referring to condition later. |
| 3026 | SourceRange ConditionSrcRange; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3027 | /// \brief A source location for referring to increment later. |
| 3028 | SourceRange IncrementSrcRange; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3029 | /// \brief Loop variable. |
| 3030 | VarDecl *Var; |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3031 | /// \brief Reference to loop variable. |
| 3032 | DeclRefExpr *VarRef; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3033 | /// \brief Lower bound (initializer for the var). |
| 3034 | Expr *LB; |
| 3035 | /// \brief Upper bound. |
| 3036 | Expr *UB; |
| 3037 | /// \brief Loop step (increment). |
| 3038 | Expr *Step; |
| 3039 | /// \brief This flag is true when condition is one of: |
| 3040 | /// Var < UB |
| 3041 | /// Var <= UB |
| 3042 | /// UB > Var |
| 3043 | /// UB >= Var |
| 3044 | bool TestIsLessOp; |
| 3045 | /// \brief This flag is true when condition is strict ( < or > ). |
| 3046 | bool TestIsStrictOp; |
| 3047 | /// \brief This flag is true when step is subtracted on each iteration. |
| 3048 | bool SubtractStep; |
| 3049 | |
| 3050 | public: |
| 3051 | OpenMPIterationSpaceChecker(Sema &SemaRef, SourceLocation DefaultLoc) |
| 3052 | : SemaRef(SemaRef), DefaultLoc(DefaultLoc), ConditionLoc(DefaultLoc), |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3053 | InitSrcRange(SourceRange()), ConditionSrcRange(SourceRange()), |
| 3054 | IncrementSrcRange(SourceRange()), Var(nullptr), VarRef(nullptr), |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3055 | LB(nullptr), UB(nullptr), Step(nullptr), TestIsLessOp(false), |
| 3056 | TestIsStrictOp(false), SubtractStep(false) {} |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3057 | /// \brief Check init-expr for canonical loop form and save loop counter |
| 3058 | /// variable - #Var and its initialization value - #LB. |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3059 | bool CheckInit(Stmt *S, bool EmitDiags = true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3060 | /// \brief Check test-expr for canonical form, save upper-bound (#UB), flags |
| 3061 | /// for less/greater and for strict/non-strict comparison. |
| 3062 | bool CheckCond(Expr *S); |
| 3063 | /// \brief Check incr-expr for canonical loop form and return true if it |
| 3064 | /// does not conform, otherwise save loop step (#Step). |
| 3065 | bool CheckInc(Expr *S); |
| 3066 | /// \brief Return the loop counter variable. |
| 3067 | VarDecl *GetLoopVar() const { return Var; } |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3068 | /// \brief Return the reference expression to loop counter variable. |
| 3069 | DeclRefExpr *GetLoopVarRefExpr() const { return VarRef; } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3070 | /// \brief Source range of the loop init. |
| 3071 | SourceRange GetInitSrcRange() const { return InitSrcRange; } |
| 3072 | /// \brief Source range of the loop condition. |
| 3073 | SourceRange GetConditionSrcRange() const { return ConditionSrcRange; } |
| 3074 | /// \brief Source range of the loop increment. |
| 3075 | SourceRange GetIncrementSrcRange() const { return IncrementSrcRange; } |
| 3076 | /// \brief True if the step should be subtracted. |
| 3077 | bool ShouldSubtractStep() const { return SubtractStep; } |
| 3078 | /// \brief Build the expression to calculate the number of iterations. |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3079 | Expr *BuildNumIterations(Scope *S, const bool LimitedType) const; |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3080 | /// \brief Build the precondition expression for the loops. |
| 3081 | Expr *BuildPreCond(Scope *S, Expr *Cond) const; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3082 | /// \brief Build reference expression to the counter be used for codegen. |
| 3083 | Expr *BuildCounterVar() const; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3084 | /// \brief Build reference expression to the private counter be used for |
| 3085 | /// codegen. |
| 3086 | Expr *BuildPrivateCounterVar() const; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3087 | /// \brief Build initization of the counter be used for codegen. |
| 3088 | Expr *BuildCounterInit() const; |
| 3089 | /// \brief Build step of the counter be used for codegen. |
| 3090 | Expr *BuildCounterStep() const; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3091 | /// \brief Return true if any expression is dependent. |
| 3092 | bool Dependent() const; |
| 3093 | |
| 3094 | private: |
| 3095 | /// \brief Check the right-hand side of an assignment in the increment |
| 3096 | /// expression. |
| 3097 | bool CheckIncRHS(Expr *RHS); |
| 3098 | /// \brief Helper to set loop counter variable and its initializer. |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3099 | bool SetVarAndLB(VarDecl *NewVar, DeclRefExpr *NewVarRefExpr, Expr *NewLB); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3100 | /// \brief Helper to set upper bound. |
Craig Topper | e335f25 | 2015-10-04 04:53:55 +0000 | [diff] [blame] | 3101 | bool SetUB(Expr *NewUB, bool LessOp, bool StrictOp, SourceRange SR, |
Craig Topper | 9cd5e4f | 2015-09-21 01:23:32 +0000 | [diff] [blame] | 3102 | SourceLocation SL); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3103 | /// \brief Helper to set loop increment. |
| 3104 | bool SetStep(Expr *NewStep, bool Subtract); |
| 3105 | }; |
| 3106 | |
| 3107 | bool OpenMPIterationSpaceChecker::Dependent() const { |
| 3108 | if (!Var) { |
| 3109 | assert(!LB && !UB && !Step); |
| 3110 | return false; |
| 3111 | } |
| 3112 | return Var->getType()->isDependentType() || (LB && LB->isValueDependent()) || |
| 3113 | (UB && UB->isValueDependent()) || (Step && Step->isValueDependent()); |
| 3114 | } |
| 3115 | |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3116 | template <typename T> |
| 3117 | static T *getExprAsWritten(T *E) { |
| 3118 | if (auto *ExprTemp = dyn_cast<ExprWithCleanups>(E)) |
| 3119 | E = ExprTemp->getSubExpr(); |
| 3120 | |
| 3121 | if (auto *MTE = dyn_cast<MaterializeTemporaryExpr>(E)) |
| 3122 | E = MTE->GetTemporaryExpr(); |
| 3123 | |
| 3124 | while (auto *Binder = dyn_cast<CXXBindTemporaryExpr>(E)) |
| 3125 | E = Binder->getSubExpr(); |
| 3126 | |
| 3127 | if (auto *ICE = dyn_cast<ImplicitCastExpr>(E)) |
| 3128 | E = ICE->getSubExprAsWritten(); |
| 3129 | return E->IgnoreParens(); |
| 3130 | } |
| 3131 | |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3132 | bool OpenMPIterationSpaceChecker::SetVarAndLB(VarDecl *NewVar, |
| 3133 | DeclRefExpr *NewVarRefExpr, |
| 3134 | Expr *NewLB) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3135 | // State consistency checking to ensure correct usage. |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3136 | assert(Var == nullptr && LB == nullptr && VarRef == nullptr && |
| 3137 | UB == nullptr && Step == nullptr && !TestIsLessOp && !TestIsStrictOp); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3138 | if (!NewVar || !NewLB) |
| 3139 | return true; |
| 3140 | Var = NewVar; |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3141 | VarRef = NewVarRefExpr; |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3142 | if (auto *CE = dyn_cast_or_null<CXXConstructExpr>(NewLB)) |
| 3143 | if (const CXXConstructorDecl *Ctor = CE->getConstructor()) |
Alexey Bataev | 0d08a7f | 2015-07-16 04:19:43 +0000 | [diff] [blame] | 3144 | if ((Ctor->isCopyOrMoveConstructor() || |
| 3145 | Ctor->isConvertingConstructor(/*AllowExplicit=*/false)) && |
| 3146 | CE->getNumArgs() > 0 && CE->getArg(0) != nullptr) |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3147 | NewLB = CE->getArg(0)->IgnoreParenImpCasts(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3148 | LB = NewLB; |
| 3149 | return false; |
| 3150 | } |
| 3151 | |
| 3152 | bool OpenMPIterationSpaceChecker::SetUB(Expr *NewUB, bool LessOp, bool StrictOp, |
Craig Topper | e335f25 | 2015-10-04 04:53:55 +0000 | [diff] [blame] | 3153 | SourceRange SR, SourceLocation SL) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3154 | // State consistency checking to ensure correct usage. |
| 3155 | assert(Var != nullptr && LB != nullptr && UB == nullptr && Step == nullptr && |
| 3156 | !TestIsLessOp && !TestIsStrictOp); |
| 3157 | if (!NewUB) |
| 3158 | return true; |
| 3159 | UB = NewUB; |
| 3160 | TestIsLessOp = LessOp; |
| 3161 | TestIsStrictOp = StrictOp; |
| 3162 | ConditionSrcRange = SR; |
| 3163 | ConditionLoc = SL; |
| 3164 | return false; |
| 3165 | } |
| 3166 | |
| 3167 | bool OpenMPIterationSpaceChecker::SetStep(Expr *NewStep, bool Subtract) { |
| 3168 | // State consistency checking to ensure correct usage. |
| 3169 | assert(Var != nullptr && LB != nullptr && Step == nullptr); |
| 3170 | if (!NewStep) |
| 3171 | return true; |
| 3172 | if (!NewStep->isValueDependent()) { |
| 3173 | // Check that the step is integer expression. |
| 3174 | SourceLocation StepLoc = NewStep->getLocStart(); |
| 3175 | ExprResult Val = |
| 3176 | SemaRef.PerformOpenMPImplicitIntegerConversion(StepLoc, NewStep); |
| 3177 | if (Val.isInvalid()) |
| 3178 | return true; |
| 3179 | NewStep = Val.get(); |
| 3180 | |
| 3181 | // OpenMP [2.6, Canonical Loop Form, Restrictions] |
| 3182 | // If test-expr is of form var relational-op b and relational-op is < or |
| 3183 | // <= then incr-expr must cause var to increase on each iteration of the |
| 3184 | // loop. If test-expr is of form var relational-op b and relational-op is |
| 3185 | // > or >= then incr-expr must cause var to decrease on each iteration of |
| 3186 | // the loop. |
| 3187 | // If test-expr is of form b relational-op var and relational-op is < or |
| 3188 | // <= then incr-expr must cause var to decrease on each iteration of the |
| 3189 | // loop. If test-expr is of form b relational-op var and relational-op is |
| 3190 | // > or >= then incr-expr must cause var to increase on each iteration of |
| 3191 | // the loop. |
| 3192 | llvm::APSInt Result; |
| 3193 | bool IsConstant = NewStep->isIntegerConstantExpr(Result, SemaRef.Context); |
| 3194 | bool IsUnsigned = !NewStep->getType()->hasSignedIntegerRepresentation(); |
| 3195 | bool IsConstNeg = |
| 3196 | IsConstant && Result.isSigned() && (Subtract != Result.isNegative()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3197 | bool IsConstPos = |
| 3198 | IsConstant && Result.isSigned() && (Subtract == Result.isNegative()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3199 | bool IsConstZero = IsConstant && !Result.getBoolValue(); |
| 3200 | if (UB && (IsConstZero || |
| 3201 | (TestIsLessOp ? (IsConstNeg || (IsUnsigned && Subtract)) |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3202 | : (IsConstPos || (IsUnsigned && !Subtract))))) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3203 | SemaRef.Diag(NewStep->getExprLoc(), |
| 3204 | diag::err_omp_loop_incr_not_compatible) |
| 3205 | << Var << TestIsLessOp << NewStep->getSourceRange(); |
| 3206 | SemaRef.Diag(ConditionLoc, |
| 3207 | diag::note_omp_loop_cond_requres_compatible_incr) |
| 3208 | << TestIsLessOp << ConditionSrcRange; |
| 3209 | return true; |
| 3210 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3211 | if (TestIsLessOp == Subtract) { |
| 3212 | NewStep = SemaRef.CreateBuiltinUnaryOp(NewStep->getExprLoc(), UO_Minus, |
| 3213 | NewStep).get(); |
| 3214 | Subtract = !Subtract; |
| 3215 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3216 | } |
| 3217 | |
| 3218 | Step = NewStep; |
| 3219 | SubtractStep = Subtract; |
| 3220 | return false; |
| 3221 | } |
| 3222 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3223 | bool OpenMPIterationSpaceChecker::CheckInit(Stmt *S, bool EmitDiags) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3224 | // Check init-expr for canonical loop form and save loop counter |
| 3225 | // variable - #Var and its initialization value - #LB. |
| 3226 | // OpenMP [2.6] Canonical loop form. init-expr may be one of the following: |
| 3227 | // var = lb |
| 3228 | // integer-type var = lb |
| 3229 | // random-access-iterator-type var = lb |
| 3230 | // pointer-type var = lb |
| 3231 | // |
| 3232 | if (!S) { |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3233 | if (EmitDiags) { |
| 3234 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_init); |
| 3235 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3236 | return true; |
| 3237 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3238 | InitSrcRange = S->getSourceRange(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3239 | if (Expr *E = dyn_cast<Expr>(S)) |
| 3240 | S = E->IgnoreParens(); |
| 3241 | if (auto BO = dyn_cast<BinaryOperator>(S)) { |
| 3242 | if (BO->getOpcode() == BO_Assign) |
| 3243 | if (auto DRE = dyn_cast<DeclRefExpr>(BO->getLHS()->IgnoreParens())) |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3244 | return SetVarAndLB(dyn_cast<VarDecl>(DRE->getDecl()), DRE, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3245 | BO->getRHS()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3246 | } else if (auto DS = dyn_cast<DeclStmt>(S)) { |
| 3247 | if (DS->isSingleDecl()) { |
| 3248 | if (auto Var = dyn_cast_or_null<VarDecl>(DS->getSingleDecl())) { |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3249 | if (Var->hasInit() && !Var->getType()->isReferenceType()) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3250 | // Accept non-canonical init form here but emit ext. warning. |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3251 | if (Var->getInitStyle() != VarDecl::CInit && EmitDiags) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3252 | SemaRef.Diag(S->getLocStart(), |
| 3253 | diag::ext_omp_loop_not_canonical_init) |
| 3254 | << S->getSourceRange(); |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3255 | return SetVarAndLB(Var, nullptr, Var->getInit()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3256 | } |
| 3257 | } |
| 3258 | } |
| 3259 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) |
| 3260 | if (CE->getOperator() == OO_Equal) |
| 3261 | if (auto DRE = dyn_cast<DeclRefExpr>(CE->getArg(0))) |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3262 | return SetVarAndLB(dyn_cast<VarDecl>(DRE->getDecl()), DRE, |
| 3263 | CE->getArg(1)); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3264 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3265 | if (EmitDiags) { |
| 3266 | SemaRef.Diag(S->getLocStart(), diag::err_omp_loop_not_canonical_init) |
| 3267 | << S->getSourceRange(); |
| 3268 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3269 | return true; |
| 3270 | } |
| 3271 | |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 3272 | /// \brief Ignore parenthesizes, implicit casts, copy constructor and return the |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3273 | /// variable (which may be the loop variable) if possible. |
| 3274 | static const VarDecl *GetInitVarDecl(const Expr *E) { |
| 3275 | if (!E) |
Craig Topper | 4b56692 | 2014-06-09 02:04:02 +0000 | [diff] [blame] | 3276 | return nullptr; |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3277 | E = getExprAsWritten(E); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3278 | if (auto *CE = dyn_cast_or_null<CXXConstructExpr>(E)) |
| 3279 | if (const CXXConstructorDecl *Ctor = CE->getConstructor()) |
Alexey Bataev | 0d08a7f | 2015-07-16 04:19:43 +0000 | [diff] [blame] | 3280 | if ((Ctor->isCopyOrMoveConstructor() || |
| 3281 | Ctor->isConvertingConstructor(/*AllowExplicit=*/false)) && |
| 3282 | CE->getNumArgs() > 0 && CE->getArg(0) != nullptr) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3283 | E = CE->getArg(0)->IgnoreParenImpCasts(); |
| 3284 | auto DRE = dyn_cast_or_null<DeclRefExpr>(E); |
| 3285 | if (!DRE) |
| 3286 | return nullptr; |
| 3287 | return dyn_cast<VarDecl>(DRE->getDecl()); |
| 3288 | } |
| 3289 | |
| 3290 | bool OpenMPIterationSpaceChecker::CheckCond(Expr *S) { |
| 3291 | // Check test-expr for canonical form, save upper-bound UB, flags for |
| 3292 | // less/greater and for strict/non-strict comparison. |
| 3293 | // OpenMP [2.6] Canonical loop form. Test-expr may be one of the following: |
| 3294 | // var relational-op b |
| 3295 | // b relational-op var |
| 3296 | // |
| 3297 | if (!S) { |
| 3298 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_cond) << Var; |
| 3299 | return true; |
| 3300 | } |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3301 | S = getExprAsWritten(S); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3302 | SourceLocation CondLoc = S->getLocStart(); |
| 3303 | if (auto BO = dyn_cast<BinaryOperator>(S)) { |
| 3304 | if (BO->isRelationalOp()) { |
| 3305 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 3306 | return SetUB(BO->getRHS(), |
| 3307 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_LE), |
| 3308 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_GT), |
| 3309 | BO->getSourceRange(), BO->getOperatorLoc()); |
| 3310 | if (GetInitVarDecl(BO->getRHS()) == Var) |
| 3311 | return SetUB(BO->getLHS(), |
| 3312 | (BO->getOpcode() == BO_GT || BO->getOpcode() == BO_GE), |
| 3313 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_GT), |
| 3314 | BO->getSourceRange(), BO->getOperatorLoc()); |
| 3315 | } |
| 3316 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
| 3317 | if (CE->getNumArgs() == 2) { |
| 3318 | auto Op = CE->getOperator(); |
| 3319 | switch (Op) { |
| 3320 | case OO_Greater: |
| 3321 | case OO_GreaterEqual: |
| 3322 | case OO_Less: |
| 3323 | case OO_LessEqual: |
| 3324 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 3325 | return SetUB(CE->getArg(1), Op == OO_Less || Op == OO_LessEqual, |
| 3326 | Op == OO_Less || Op == OO_Greater, CE->getSourceRange(), |
| 3327 | CE->getOperatorLoc()); |
| 3328 | if (GetInitVarDecl(CE->getArg(1)) == Var) |
| 3329 | return SetUB(CE->getArg(0), Op == OO_Greater || Op == OO_GreaterEqual, |
| 3330 | Op == OO_Less || Op == OO_Greater, CE->getSourceRange(), |
| 3331 | CE->getOperatorLoc()); |
| 3332 | break; |
| 3333 | default: |
| 3334 | break; |
| 3335 | } |
| 3336 | } |
| 3337 | } |
| 3338 | SemaRef.Diag(CondLoc, diag::err_omp_loop_not_canonical_cond) |
| 3339 | << S->getSourceRange() << Var; |
| 3340 | return true; |
| 3341 | } |
| 3342 | |
| 3343 | bool OpenMPIterationSpaceChecker::CheckIncRHS(Expr *RHS) { |
| 3344 | // RHS of canonical loop form increment can be: |
| 3345 | // var + incr |
| 3346 | // incr + var |
| 3347 | // var - incr |
| 3348 | // |
| 3349 | RHS = RHS->IgnoreParenImpCasts(); |
| 3350 | if (auto BO = dyn_cast<BinaryOperator>(RHS)) { |
| 3351 | if (BO->isAdditiveOp()) { |
| 3352 | bool IsAdd = BO->getOpcode() == BO_Add; |
| 3353 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 3354 | return SetStep(BO->getRHS(), !IsAdd); |
| 3355 | if (IsAdd && GetInitVarDecl(BO->getRHS()) == Var) |
| 3356 | return SetStep(BO->getLHS(), false); |
| 3357 | } |
| 3358 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(RHS)) { |
| 3359 | bool IsAdd = CE->getOperator() == OO_Plus; |
| 3360 | if ((IsAdd || CE->getOperator() == OO_Minus) && CE->getNumArgs() == 2) { |
| 3361 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 3362 | return SetStep(CE->getArg(1), !IsAdd); |
| 3363 | if (IsAdd && GetInitVarDecl(CE->getArg(1)) == Var) |
| 3364 | return SetStep(CE->getArg(0), false); |
| 3365 | } |
| 3366 | } |
| 3367 | SemaRef.Diag(RHS->getLocStart(), diag::err_omp_loop_not_canonical_incr) |
| 3368 | << RHS->getSourceRange() << Var; |
| 3369 | return true; |
| 3370 | } |
| 3371 | |
| 3372 | bool OpenMPIterationSpaceChecker::CheckInc(Expr *S) { |
| 3373 | // Check incr-expr for canonical loop form and return true if it |
| 3374 | // does not conform. |
| 3375 | // OpenMP [2.6] Canonical loop form. Test-expr may be one of the following: |
| 3376 | // ++var |
| 3377 | // var++ |
| 3378 | // --var |
| 3379 | // var-- |
| 3380 | // var += incr |
| 3381 | // var -= incr |
| 3382 | // var = var + incr |
| 3383 | // var = incr + var |
| 3384 | // var = var - incr |
| 3385 | // |
| 3386 | if (!S) { |
| 3387 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_incr) << Var; |
| 3388 | return true; |
| 3389 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3390 | IncrementSrcRange = S->getSourceRange(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3391 | S = S->IgnoreParens(); |
| 3392 | if (auto UO = dyn_cast<UnaryOperator>(S)) { |
| 3393 | if (UO->isIncrementDecrementOp() && GetInitVarDecl(UO->getSubExpr()) == Var) |
| 3394 | return SetStep( |
| 3395 | SemaRef.ActOnIntegerConstant(UO->getLocStart(), |
| 3396 | (UO->isDecrementOp() ? -1 : 1)).get(), |
| 3397 | false); |
| 3398 | } else if (auto BO = dyn_cast<BinaryOperator>(S)) { |
| 3399 | switch (BO->getOpcode()) { |
| 3400 | case BO_AddAssign: |
| 3401 | case BO_SubAssign: |
| 3402 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 3403 | return SetStep(BO->getRHS(), BO->getOpcode() == BO_SubAssign); |
| 3404 | break; |
| 3405 | case BO_Assign: |
| 3406 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 3407 | return CheckIncRHS(BO->getRHS()); |
| 3408 | break; |
| 3409 | default: |
| 3410 | break; |
| 3411 | } |
| 3412 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
| 3413 | switch (CE->getOperator()) { |
| 3414 | case OO_PlusPlus: |
| 3415 | case OO_MinusMinus: |
| 3416 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 3417 | return SetStep( |
| 3418 | SemaRef.ActOnIntegerConstant( |
| 3419 | CE->getLocStart(), |
| 3420 | ((CE->getOperator() == OO_MinusMinus) ? -1 : 1)).get(), |
| 3421 | false); |
| 3422 | break; |
| 3423 | case OO_PlusEqual: |
| 3424 | case OO_MinusEqual: |
| 3425 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 3426 | return SetStep(CE->getArg(1), CE->getOperator() == OO_MinusEqual); |
| 3427 | break; |
| 3428 | case OO_Equal: |
| 3429 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 3430 | return CheckIncRHS(CE->getArg(1)); |
| 3431 | break; |
| 3432 | default: |
| 3433 | break; |
| 3434 | } |
| 3435 | } |
| 3436 | SemaRef.Diag(S->getLocStart(), diag::err_omp_loop_not_canonical_incr) |
| 3437 | << S->getSourceRange() << Var; |
| 3438 | return true; |
| 3439 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3440 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3441 | namespace { |
| 3442 | // Transform variables declared in GNU statement expressions to new ones to |
| 3443 | // avoid crash on codegen. |
| 3444 | class TransformToNewDefs : public TreeTransform<TransformToNewDefs> { |
| 3445 | typedef TreeTransform<TransformToNewDefs> BaseTransform; |
| 3446 | |
| 3447 | public: |
| 3448 | TransformToNewDefs(Sema &SemaRef) : BaseTransform(SemaRef) {} |
| 3449 | |
| 3450 | Decl *TransformDefinition(SourceLocation Loc, Decl *D) { |
| 3451 | if (auto *VD = cast<VarDecl>(D)) |
| 3452 | if (!isa<ParmVarDecl>(D) && !isa<VarTemplateSpecializationDecl>(D) && |
| 3453 | !isa<ImplicitParamDecl>(D)) { |
| 3454 | auto *NewVD = VarDecl::Create( |
| 3455 | SemaRef.Context, VD->getDeclContext(), VD->getLocStart(), |
| 3456 | VD->getLocation(), VD->getIdentifier(), VD->getType(), |
| 3457 | VD->getTypeSourceInfo(), VD->getStorageClass()); |
| 3458 | NewVD->setTSCSpec(VD->getTSCSpec()); |
| 3459 | NewVD->setInit(VD->getInit()); |
| 3460 | NewVD->setInitStyle(VD->getInitStyle()); |
| 3461 | NewVD->setExceptionVariable(VD->isExceptionVariable()); |
| 3462 | NewVD->setNRVOVariable(VD->isNRVOVariable()); |
| 3463 | NewVD->setCXXForRangeDecl(VD->isInExternCXXContext()); |
| 3464 | NewVD->setConstexpr(VD->isConstexpr()); |
| 3465 | NewVD->setInitCapture(VD->isInitCapture()); |
| 3466 | NewVD->setPreviousDeclInSameBlockScope( |
| 3467 | VD->isPreviousDeclInSameBlockScope()); |
| 3468 | VD->getDeclContext()->addHiddenDecl(NewVD); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 3469 | if (VD->hasAttrs()) |
| 3470 | NewVD->setAttrs(VD->getAttrs()); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3471 | transformedLocalDecl(VD, NewVD); |
| 3472 | return NewVD; |
| 3473 | } |
| 3474 | return BaseTransform::TransformDefinition(Loc, D); |
| 3475 | } |
| 3476 | |
| 3477 | ExprResult TransformDeclRefExpr(DeclRefExpr *E) { |
| 3478 | if (auto *NewD = TransformDecl(E->getExprLoc(), E->getDecl())) |
| 3479 | if (E->getDecl() != NewD) { |
| 3480 | NewD->setReferenced(); |
| 3481 | NewD->markUsed(SemaRef.Context); |
| 3482 | return DeclRefExpr::Create( |
| 3483 | SemaRef.Context, E->getQualifierLoc(), E->getTemplateKeywordLoc(), |
| 3484 | cast<ValueDecl>(NewD), E->refersToEnclosingVariableOrCapture(), |
| 3485 | E->getNameInfo(), E->getType(), E->getValueKind()); |
| 3486 | } |
| 3487 | return BaseTransform::TransformDeclRefExpr(E); |
| 3488 | } |
| 3489 | }; |
| 3490 | } |
| 3491 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3492 | /// \brief Build the expression to calculate the number of iterations. |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3493 | Expr * |
| 3494 | OpenMPIterationSpaceChecker::BuildNumIterations(Scope *S, |
| 3495 | const bool LimitedType) const { |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3496 | TransformToNewDefs Transform(SemaRef); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3497 | ExprResult Diff; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3498 | auto VarType = Var->getType().getNonReferenceType(); |
| 3499 | if (VarType->isIntegerType() || VarType->isPointerType() || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3500 | SemaRef.getLangOpts().CPlusPlus) { |
| 3501 | // Upper - Lower |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3502 | auto *UBExpr = TestIsLessOp ? UB : LB; |
| 3503 | auto *LBExpr = TestIsLessOp ? LB : UB; |
| 3504 | Expr *Upper = Transform.TransformExpr(UBExpr).get(); |
| 3505 | Expr *Lower = Transform.TransformExpr(LBExpr).get(); |
| 3506 | if (!Upper || !Lower) |
| 3507 | return nullptr; |
| 3508 | Upper = SemaRef.PerformImplicitConversion(Upper, UBExpr->getType(), |
| 3509 | Sema::AA_Converting, |
| 3510 | /*AllowExplicit=*/true) |
| 3511 | .get(); |
| 3512 | Lower = SemaRef.PerformImplicitConversion(Lower, LBExpr->getType(), |
| 3513 | Sema::AA_Converting, |
| 3514 | /*AllowExplicit=*/true) |
| 3515 | .get(); |
| 3516 | if (!Upper || !Lower) |
| 3517 | return nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3518 | |
| 3519 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Sub, Upper, Lower); |
| 3520 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3521 | if (!Diff.isUsable() && VarType->getAsCXXRecordDecl()) { |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3522 | // BuildBinOp already emitted error, this one is to point user to upper |
| 3523 | // and lower bound, and to tell what is passed to 'operator-'. |
| 3524 | SemaRef.Diag(Upper->getLocStart(), diag::err_omp_loop_diff_cxx) |
| 3525 | << Upper->getSourceRange() << Lower->getSourceRange(); |
| 3526 | return nullptr; |
| 3527 | } |
| 3528 | } |
| 3529 | |
| 3530 | if (!Diff.isUsable()) |
| 3531 | return nullptr; |
| 3532 | |
| 3533 | // Upper - Lower [- 1] |
| 3534 | if (TestIsStrictOp) |
| 3535 | Diff = SemaRef.BuildBinOp( |
| 3536 | S, DefaultLoc, BO_Sub, Diff.get(), |
| 3537 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 3538 | if (!Diff.isUsable()) |
| 3539 | return nullptr; |
| 3540 | |
| 3541 | // Upper - Lower [- 1] + Step |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3542 | auto NewStep = Transform.TransformExpr(Step->IgnoreImplicit()); |
| 3543 | if (NewStep.isInvalid()) |
| 3544 | return nullptr; |
| 3545 | NewStep = SemaRef.PerformImplicitConversion( |
| 3546 | NewStep.get(), Step->IgnoreImplicit()->getType(), Sema::AA_Converting, |
| 3547 | /*AllowExplicit=*/true); |
| 3548 | if (NewStep.isInvalid()) |
| 3549 | return nullptr; |
| 3550 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Add, Diff.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3551 | if (!Diff.isUsable()) |
| 3552 | return nullptr; |
| 3553 | |
| 3554 | // Parentheses (for dumping/debugging purposes only). |
| 3555 | Diff = SemaRef.ActOnParenExpr(DefaultLoc, DefaultLoc, Diff.get()); |
| 3556 | if (!Diff.isUsable()) |
| 3557 | return nullptr; |
| 3558 | |
| 3559 | // (Upper - Lower [- 1] + Step) / Step |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3560 | NewStep = Transform.TransformExpr(Step->IgnoreImplicit()); |
| 3561 | if (NewStep.isInvalid()) |
| 3562 | return nullptr; |
| 3563 | NewStep = SemaRef.PerformImplicitConversion( |
| 3564 | NewStep.get(), Step->IgnoreImplicit()->getType(), Sema::AA_Converting, |
| 3565 | /*AllowExplicit=*/true); |
| 3566 | if (NewStep.isInvalid()) |
| 3567 | return nullptr; |
| 3568 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Div, Diff.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3569 | if (!Diff.isUsable()) |
| 3570 | return nullptr; |
| 3571 | |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3572 | // OpenMP runtime requires 32-bit or 64-bit loop variables. |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3573 | QualType Type = Diff.get()->getType(); |
| 3574 | auto &C = SemaRef.Context; |
| 3575 | bool UseVarType = VarType->hasIntegerRepresentation() && |
| 3576 | C.getTypeSize(Type) > C.getTypeSize(VarType); |
| 3577 | if (!Type->isIntegerType() || UseVarType) { |
| 3578 | unsigned NewSize = |
| 3579 | UseVarType ? C.getTypeSize(VarType) : C.getTypeSize(Type); |
| 3580 | bool IsSigned = UseVarType ? VarType->hasSignedIntegerRepresentation() |
| 3581 | : Type->hasSignedIntegerRepresentation(); |
| 3582 | Type = C.getIntTypeForBitwidth(NewSize, IsSigned); |
| 3583 | Diff = SemaRef.PerformImplicitConversion( |
| 3584 | Diff.get(), Type, Sema::AA_Converting, /*AllowExplicit=*/true); |
| 3585 | if (!Diff.isUsable()) |
| 3586 | return nullptr; |
| 3587 | } |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3588 | if (LimitedType) { |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3589 | unsigned NewSize = (C.getTypeSize(Type) > 32) ? 64 : 32; |
| 3590 | if (NewSize != C.getTypeSize(Type)) { |
| 3591 | if (NewSize < C.getTypeSize(Type)) { |
| 3592 | assert(NewSize == 64 && "incorrect loop var size"); |
| 3593 | SemaRef.Diag(DefaultLoc, diag::warn_omp_loop_64_bit_var) |
| 3594 | << InitSrcRange << ConditionSrcRange; |
| 3595 | } |
| 3596 | QualType NewType = C.getIntTypeForBitwidth( |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3597 | NewSize, Type->hasSignedIntegerRepresentation() || |
| 3598 | C.getTypeSize(Type) < NewSize); |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3599 | Diff = SemaRef.PerformImplicitConversion(Diff.get(), NewType, |
| 3600 | Sema::AA_Converting, true); |
| 3601 | if (!Diff.isUsable()) |
| 3602 | return nullptr; |
| 3603 | } |
| 3604 | } |
| 3605 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3606 | return Diff.get(); |
| 3607 | } |
| 3608 | |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3609 | Expr *OpenMPIterationSpaceChecker::BuildPreCond(Scope *S, Expr *Cond) const { |
| 3610 | // Try to build LB <op> UB, where <op> is <, >, <=, or >=. |
| 3611 | bool Suppress = SemaRef.getDiagnostics().getSuppressAllDiagnostics(); |
| 3612 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(/*Val=*/true); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3613 | TransformToNewDefs Transform(SemaRef); |
| 3614 | |
| 3615 | auto NewLB = Transform.TransformExpr(LB); |
| 3616 | auto NewUB = Transform.TransformExpr(UB); |
| 3617 | if (NewLB.isInvalid() || NewUB.isInvalid()) |
| 3618 | return Cond; |
| 3619 | NewLB = SemaRef.PerformImplicitConversion(NewLB.get(), LB->getType(), |
| 3620 | Sema::AA_Converting, |
| 3621 | /*AllowExplicit=*/true); |
| 3622 | NewUB = SemaRef.PerformImplicitConversion(NewUB.get(), UB->getType(), |
| 3623 | Sema::AA_Converting, |
| 3624 | /*AllowExplicit=*/true); |
| 3625 | if (NewLB.isInvalid() || NewUB.isInvalid()) |
| 3626 | return Cond; |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3627 | auto CondExpr = SemaRef.BuildBinOp( |
| 3628 | S, DefaultLoc, TestIsLessOp ? (TestIsStrictOp ? BO_LT : BO_LE) |
| 3629 | : (TestIsStrictOp ? BO_GT : BO_GE), |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3630 | NewLB.get(), NewUB.get()); |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3631 | if (CondExpr.isUsable()) { |
| 3632 | CondExpr = SemaRef.PerformImplicitConversion( |
| 3633 | CondExpr.get(), SemaRef.Context.BoolTy, /*Action=*/Sema::AA_Casting, |
| 3634 | /*AllowExplicit=*/true); |
| 3635 | } |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3636 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(Suppress); |
| 3637 | // Otherwise use original loop conditon and evaluate it in runtime. |
| 3638 | return CondExpr.isUsable() ? CondExpr.get() : Cond; |
| 3639 | } |
| 3640 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3641 | /// \brief Build reference expression to the counter be used for codegen. |
| 3642 | Expr *OpenMPIterationSpaceChecker::BuildCounterVar() const { |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3643 | return buildDeclRefExpr(SemaRef, Var, Var->getType().getNonReferenceType(), |
| 3644 | DefaultLoc); |
| 3645 | } |
| 3646 | |
| 3647 | Expr *OpenMPIterationSpaceChecker::BuildPrivateCounterVar() const { |
| 3648 | if (Var && !Var->isInvalidDecl()) { |
| 3649 | auto Type = Var->getType().getNonReferenceType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 3650 | auto *PrivateVar = |
| 3651 | buildVarDecl(SemaRef, DefaultLoc, Type, Var->getName(), |
| 3652 | Var->hasAttrs() ? &Var->getAttrs() : nullptr); |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3653 | if (PrivateVar->isInvalidDecl()) |
| 3654 | return nullptr; |
| 3655 | return buildDeclRefExpr(SemaRef, PrivateVar, Type, DefaultLoc); |
| 3656 | } |
| 3657 | return nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3658 | } |
| 3659 | |
| 3660 | /// \brief Build initization of the counter be used for codegen. |
| 3661 | Expr *OpenMPIterationSpaceChecker::BuildCounterInit() const { return LB; } |
| 3662 | |
| 3663 | /// \brief Build step of the counter be used for codegen. |
| 3664 | Expr *OpenMPIterationSpaceChecker::BuildCounterStep() const { return Step; } |
| 3665 | |
| 3666 | /// \brief Iteration space of a single for loop. |
| 3667 | struct LoopIterationSpace { |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3668 | /// \brief Condition of the loop. |
| 3669 | Expr *PreCond; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3670 | /// \brief This expression calculates the number of iterations in the loop. |
| 3671 | /// It is always possible to calculate it before starting the loop. |
| 3672 | Expr *NumIterations; |
| 3673 | /// \brief The loop counter variable. |
| 3674 | Expr *CounterVar; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3675 | /// \brief Private loop counter variable. |
| 3676 | Expr *PrivateCounterVar; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3677 | /// \brief This is initializer for the initial value of #CounterVar. |
| 3678 | Expr *CounterInit; |
| 3679 | /// \brief This is step for the #CounterVar used to generate its update: |
| 3680 | /// #CounterVar = #CounterInit + #CounterStep * CurrentIteration. |
| 3681 | Expr *CounterStep; |
| 3682 | /// \brief Should step be subtracted? |
| 3683 | bool Subtract; |
| 3684 | /// \brief Source range of the loop init. |
| 3685 | SourceRange InitSrcRange; |
| 3686 | /// \brief Source range of the loop condition. |
| 3687 | SourceRange CondSrcRange; |
| 3688 | /// \brief Source range of the loop increment. |
| 3689 | SourceRange IncSrcRange; |
| 3690 | }; |
| 3691 | |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 3692 | } // namespace |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3693 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3694 | void Sema::ActOnOpenMPLoopInitialization(SourceLocation ForLoc, Stmt *Init) { |
| 3695 | assert(getLangOpts().OpenMP && "OpenMP is not active."); |
| 3696 | assert(Init && "Expected loop in canonical form."); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 3697 | unsigned AssociatedLoops = DSAStack->getAssociatedLoops(); |
| 3698 | if (AssociatedLoops > 0 && |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3699 | isOpenMPLoopDirective(DSAStack->getCurrentDirective())) { |
| 3700 | OpenMPIterationSpaceChecker ISC(*this, ForLoc); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 3701 | if (!ISC.CheckInit(Init, /*EmitDiags=*/false)) |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3702 | DSAStack->addLoopControlVariable(ISC.GetLoopVar()); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 3703 | DSAStack->setAssociatedLoops(AssociatedLoops - 1); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3704 | } |
| 3705 | } |
| 3706 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3707 | /// \brief Called on a for stmt to check and extract its iteration space |
| 3708 | /// for further processing (such as collapsing). |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3709 | static bool CheckOpenMPIterationSpace( |
| 3710 | OpenMPDirectiveKind DKind, Stmt *S, Sema &SemaRef, DSAStackTy &DSA, |
| 3711 | unsigned CurrentNestedLoopCount, unsigned NestedLoopCount, |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3712 | Expr *CollapseLoopCountExpr, Expr *OrderedLoopCountExpr, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 3713 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3714 | LoopIterationSpace &ResultIterSpace) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3715 | // OpenMP [2.6, Canonical Loop Form] |
| 3716 | // for (init-expr; test-expr; incr-expr) structured-block |
| 3717 | auto For = dyn_cast_or_null<ForStmt>(S); |
| 3718 | if (!For) { |
| 3719 | SemaRef.Diag(S->getLocStart(), diag::err_omp_not_for) |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3720 | << (CollapseLoopCountExpr != nullptr || OrderedLoopCountExpr != nullptr) |
| 3721 | << getOpenMPDirectiveName(DKind) << NestedLoopCount |
| 3722 | << (CurrentNestedLoopCount > 0) << CurrentNestedLoopCount; |
| 3723 | if (NestedLoopCount > 1) { |
| 3724 | if (CollapseLoopCountExpr && OrderedLoopCountExpr) |
| 3725 | SemaRef.Diag(DSA.getConstructLoc(), |
| 3726 | diag::note_omp_collapse_ordered_expr) |
| 3727 | << 2 << CollapseLoopCountExpr->getSourceRange() |
| 3728 | << OrderedLoopCountExpr->getSourceRange(); |
| 3729 | else if (CollapseLoopCountExpr) |
| 3730 | SemaRef.Diag(CollapseLoopCountExpr->getExprLoc(), |
| 3731 | diag::note_omp_collapse_ordered_expr) |
| 3732 | << 0 << CollapseLoopCountExpr->getSourceRange(); |
| 3733 | else |
| 3734 | SemaRef.Diag(OrderedLoopCountExpr->getExprLoc(), |
| 3735 | diag::note_omp_collapse_ordered_expr) |
| 3736 | << 1 << OrderedLoopCountExpr->getSourceRange(); |
| 3737 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3738 | return true; |
| 3739 | } |
| 3740 | assert(For->getBody()); |
| 3741 | |
| 3742 | OpenMPIterationSpaceChecker ISC(SemaRef, For->getForLoc()); |
| 3743 | |
| 3744 | // Check init. |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 3745 | auto Init = For->getInit(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3746 | if (ISC.CheckInit(Init)) { |
| 3747 | return true; |
| 3748 | } |
| 3749 | |
| 3750 | bool HasErrors = false; |
| 3751 | |
| 3752 | // Check loop variable's type. |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 3753 | auto Var = ISC.GetLoopVar(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3754 | |
| 3755 | // OpenMP [2.6, Canonical Loop Form] |
| 3756 | // Var is one of the following: |
| 3757 | // A variable of signed or unsigned integer type. |
| 3758 | // For C++, a variable of a random access iterator type. |
| 3759 | // For C, a variable of a pointer type. |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3760 | auto VarType = Var->getType().getNonReferenceType(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3761 | if (!VarType->isDependentType() && !VarType->isIntegerType() && |
| 3762 | !VarType->isPointerType() && |
| 3763 | !(SemaRef.getLangOpts().CPlusPlus && VarType->isOverloadableType())) { |
| 3764 | SemaRef.Diag(Init->getLocStart(), diag::err_omp_loop_variable_type) |
| 3765 | << SemaRef.getLangOpts().CPlusPlus; |
| 3766 | HasErrors = true; |
| 3767 | } |
| 3768 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3769 | // OpenMP, 2.14.1.1 Data-sharing Attribute Rules for Variables Referenced in a |
| 3770 | // Construct |
| 3771 | // The loop iteration variable(s) in the associated for-loop(s) of a for or |
| 3772 | // parallel for construct is (are) private. |
| 3773 | // The loop iteration variable in the associated for-loop of a simd construct |
| 3774 | // with just one associated for-loop is linear with a constant-linear-step |
| 3775 | // that is the increment of the associated for-loop. |
| 3776 | // Exclude loop var from the list of variables with implicitly defined data |
| 3777 | // sharing attributes. |
Benjamin Kramer | ad8e079 | 2014-10-10 15:32:48 +0000 | [diff] [blame] | 3778 | VarsWithImplicitDSA.erase(Var); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3779 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3780 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced in |
| 3781 | // a Construct, C/C++]. |
Alexey Bataev | cefffae | 2014-06-23 08:21:53 +0000 | [diff] [blame] | 3782 | // The loop iteration variable in the associated for-loop of a simd construct |
| 3783 | // with just one associated for-loop may be listed in a linear clause with a |
| 3784 | // constant-linear-step that is the increment of the associated for-loop. |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3785 | // The loop iteration variable(s) in the associated for-loop(s) of a for or |
| 3786 | // parallel for construct may be listed in a private or lastprivate clause. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 3787 | DSAStackTy::DSAVarData DVar = DSA.getTopDSA(Var, false); |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3788 | auto LoopVarRefExpr = ISC.GetLoopVarRefExpr(); |
| 3789 | // If LoopVarRefExpr is nullptr it means the corresponding loop variable is |
| 3790 | // declared in the loop and it is predetermined as a private. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3791 | auto PredeterminedCKind = |
| 3792 | isOpenMPSimdDirective(DKind) |
| 3793 | ? ((NestedLoopCount == 1) ? OMPC_linear : OMPC_lastprivate) |
| 3794 | : OMPC_private; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3795 | if (((isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown && |
Alexey Bataev | e648e80 | 2015-12-25 13:38:08 +0000 | [diff] [blame] | 3796 | DVar.CKind != PredeterminedCKind) || |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 3797 | ((isOpenMPWorksharingDirective(DKind) || DKind == OMPD_taskloop || |
Alexey Bataev | e648e80 | 2015-12-25 13:38:08 +0000 | [diff] [blame] | 3798 | isOpenMPDistributeDirective(DKind)) && |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 3799 | !isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown && |
Alexey Bataev | e648e80 | 2015-12-25 13:38:08 +0000 | [diff] [blame] | 3800 | DVar.CKind != OMPC_private && DVar.CKind != OMPC_lastprivate)) && |
| 3801 | (DVar.CKind != OMPC_private || DVar.RefExpr != nullptr)) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3802 | SemaRef.Diag(Init->getLocStart(), diag::err_omp_loop_var_dsa) |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3803 | << getOpenMPClauseName(DVar.CKind) << getOpenMPDirectiveName(DKind) |
| 3804 | << getOpenMPClauseName(PredeterminedCKind); |
Alexey Bataev | f2453a0 | 2015-05-06 07:25:08 +0000 | [diff] [blame] | 3805 | if (DVar.RefExpr == nullptr) |
| 3806 | DVar.CKind = PredeterminedCKind; |
| 3807 | ReportOriginalDSA(SemaRef, &DSA, Var, DVar, /*IsLoopIterVar=*/true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3808 | HasErrors = true; |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3809 | } else if (LoopVarRefExpr != nullptr) { |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3810 | // Make the loop iteration variable private (for worksharing constructs), |
| 3811 | // linear (for simd directives with the only one associated loop) or |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3812 | // lastprivate (for simd directives with several collapsed or ordered |
| 3813 | // loops). |
Alexey Bataev | 9aba41c | 2014-11-14 04:08:45 +0000 | [diff] [blame] | 3814 | if (DVar.CKind == OMPC_unknown) |
| 3815 | DVar = DSA.hasDSA(Var, isOpenMPPrivate, MatchesAlways(), |
| 3816 | /*FromParent=*/false); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3817 | DSA.addDSA(Var, LoopVarRefExpr, PredeterminedCKind); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3818 | } |
| 3819 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 3820 | assert(isOpenMPLoopDirective(DKind) && "DSA for non-loop vars"); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 3821 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3822 | // Check test-expr. |
| 3823 | HasErrors |= ISC.CheckCond(For->getCond()); |
| 3824 | |
| 3825 | // Check incr-expr. |
| 3826 | HasErrors |= ISC.CheckInc(For->getInc()); |
| 3827 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3828 | if (ISC.Dependent() || SemaRef.CurContext->isDependentContext() || HasErrors) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3829 | return HasErrors; |
| 3830 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3831 | // Build the loop's iteration space representation. |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3832 | ResultIterSpace.PreCond = ISC.BuildPreCond(DSA.getCurScope(), For->getCond()); |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3833 | ResultIterSpace.NumIterations = ISC.BuildNumIterations( |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 3834 | DSA.getCurScope(), (isOpenMPWorksharingDirective(DKind) || |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 3835 | isOpenMPTaskLoopDirective(DKind) || |
| 3836 | isOpenMPDistributeDirective(DKind))); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3837 | ResultIterSpace.CounterVar = ISC.BuildCounterVar(); |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3838 | ResultIterSpace.PrivateCounterVar = ISC.BuildPrivateCounterVar(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3839 | ResultIterSpace.CounterInit = ISC.BuildCounterInit(); |
| 3840 | ResultIterSpace.CounterStep = ISC.BuildCounterStep(); |
| 3841 | ResultIterSpace.InitSrcRange = ISC.GetInitSrcRange(); |
| 3842 | ResultIterSpace.CondSrcRange = ISC.GetConditionSrcRange(); |
| 3843 | ResultIterSpace.IncSrcRange = ISC.GetIncrementSrcRange(); |
| 3844 | ResultIterSpace.Subtract = ISC.ShouldSubtractStep(); |
| 3845 | |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3846 | HasErrors |= (ResultIterSpace.PreCond == nullptr || |
| 3847 | ResultIterSpace.NumIterations == nullptr || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3848 | ResultIterSpace.CounterVar == nullptr || |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3849 | ResultIterSpace.PrivateCounterVar == nullptr || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3850 | ResultIterSpace.CounterInit == nullptr || |
| 3851 | ResultIterSpace.CounterStep == nullptr); |
| 3852 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3853 | return HasErrors; |
| 3854 | } |
| 3855 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3856 | /// \brief Build 'VarRef = Start. |
| 3857 | static ExprResult BuildCounterInit(Sema &SemaRef, Scope *S, SourceLocation Loc, |
| 3858 | ExprResult VarRef, ExprResult Start) { |
| 3859 | TransformToNewDefs Transform(SemaRef); |
| 3860 | // Build 'VarRef = Start. |
| 3861 | auto NewStart = Transform.TransformExpr(Start.get()->IgnoreImplicit()); |
| 3862 | if (NewStart.isInvalid()) |
| 3863 | return ExprError(); |
| 3864 | NewStart = SemaRef.PerformImplicitConversion( |
| 3865 | NewStart.get(), Start.get()->IgnoreImplicit()->getType(), |
| 3866 | Sema::AA_Converting, |
| 3867 | /*AllowExplicit=*/true); |
| 3868 | if (NewStart.isInvalid()) |
| 3869 | return ExprError(); |
| 3870 | NewStart = SemaRef.PerformImplicitConversion( |
| 3871 | NewStart.get(), VarRef.get()->getType(), Sema::AA_Converting, |
| 3872 | /*AllowExplicit=*/true); |
| 3873 | if (!NewStart.isUsable()) |
| 3874 | return ExprError(); |
| 3875 | |
| 3876 | auto Init = |
| 3877 | SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), NewStart.get()); |
| 3878 | return Init; |
| 3879 | } |
| 3880 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3881 | /// \brief Build 'VarRef = Start + Iter * Step'. |
| 3882 | static ExprResult BuildCounterUpdate(Sema &SemaRef, Scope *S, |
| 3883 | SourceLocation Loc, ExprResult VarRef, |
| 3884 | ExprResult Start, ExprResult Iter, |
| 3885 | ExprResult Step, bool Subtract) { |
| 3886 | // Add parentheses (for debugging purposes only). |
| 3887 | Iter = SemaRef.ActOnParenExpr(Loc, Loc, Iter.get()); |
| 3888 | if (!VarRef.isUsable() || !Start.isUsable() || !Iter.isUsable() || |
| 3889 | !Step.isUsable()) |
| 3890 | return ExprError(); |
| 3891 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3892 | TransformToNewDefs Transform(SemaRef); |
| 3893 | auto NewStep = Transform.TransformExpr(Step.get()->IgnoreImplicit()); |
| 3894 | if (NewStep.isInvalid()) |
| 3895 | return ExprError(); |
| 3896 | NewStep = SemaRef.PerformImplicitConversion( |
| 3897 | NewStep.get(), Step.get()->IgnoreImplicit()->getType(), |
| 3898 | Sema::AA_Converting, |
| 3899 | /*AllowExplicit=*/true); |
| 3900 | if (NewStep.isInvalid()) |
| 3901 | return ExprError(); |
| 3902 | ExprResult Update = |
| 3903 | SemaRef.BuildBinOp(S, Loc, BO_Mul, Iter.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3904 | if (!Update.isUsable()) |
| 3905 | return ExprError(); |
| 3906 | |
| 3907 | // Build 'VarRef = Start + Iter * Step'. |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3908 | auto NewStart = Transform.TransformExpr(Start.get()->IgnoreImplicit()); |
| 3909 | if (NewStart.isInvalid()) |
| 3910 | return ExprError(); |
| 3911 | NewStart = SemaRef.PerformImplicitConversion( |
| 3912 | NewStart.get(), Start.get()->IgnoreImplicit()->getType(), |
| 3913 | Sema::AA_Converting, |
| 3914 | /*AllowExplicit=*/true); |
| 3915 | if (NewStart.isInvalid()) |
| 3916 | return ExprError(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3917 | Update = SemaRef.BuildBinOp(S, Loc, (Subtract ? BO_Sub : BO_Add), |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3918 | NewStart.get(), Update.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3919 | if (!Update.isUsable()) |
| 3920 | return ExprError(); |
| 3921 | |
| 3922 | Update = SemaRef.PerformImplicitConversion( |
| 3923 | Update.get(), VarRef.get()->getType(), Sema::AA_Converting, true); |
| 3924 | if (!Update.isUsable()) |
| 3925 | return ExprError(); |
| 3926 | |
| 3927 | Update = SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), Update.get()); |
| 3928 | return Update; |
| 3929 | } |
| 3930 | |
| 3931 | /// \brief Convert integer expression \a E to make it have at least \a Bits |
| 3932 | /// bits. |
| 3933 | static ExprResult WidenIterationCount(unsigned Bits, Expr *E, |
| 3934 | Sema &SemaRef) { |
| 3935 | if (E == nullptr) |
| 3936 | return ExprError(); |
| 3937 | auto &C = SemaRef.Context; |
| 3938 | QualType OldType = E->getType(); |
| 3939 | unsigned HasBits = C.getTypeSize(OldType); |
| 3940 | if (HasBits >= Bits) |
| 3941 | return ExprResult(E); |
| 3942 | // OK to convert to signed, because new type has more bits than old. |
| 3943 | QualType NewType = C.getIntTypeForBitwidth(Bits, /* Signed */ true); |
| 3944 | return SemaRef.PerformImplicitConversion(E, NewType, Sema::AA_Converting, |
| 3945 | true); |
| 3946 | } |
| 3947 | |
| 3948 | /// \brief Check if the given expression \a E is a constant integer that fits |
| 3949 | /// into \a Bits bits. |
| 3950 | static bool FitsInto(unsigned Bits, bool Signed, Expr *E, Sema &SemaRef) { |
| 3951 | if (E == nullptr) |
| 3952 | return false; |
| 3953 | llvm::APSInt Result; |
| 3954 | if (E->isIntegerConstantExpr(Result, SemaRef.Context)) |
| 3955 | return Signed ? Result.isSignedIntN(Bits) : Result.isIntN(Bits); |
| 3956 | return false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3957 | } |
| 3958 | |
| 3959 | /// \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] | 3960 | /// \return Returns 0 if one of the collapsed stmts is not canonical for loop, |
| 3961 | /// number of collapsed loops otherwise. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3962 | static unsigned |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3963 | CheckOpenMPLoop(OpenMPDirectiveKind DKind, Expr *CollapseLoopCountExpr, |
| 3964 | Expr *OrderedLoopCountExpr, Stmt *AStmt, Sema &SemaRef, |
| 3965 | DSAStackTy &DSA, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 3966 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA, |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3967 | OMPLoopDirective::HelperExprs &Built) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3968 | unsigned NestedLoopCount = 1; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3969 | if (CollapseLoopCountExpr) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3970 | // Found 'collapse' clause - calculate collapse number. |
| 3971 | llvm::APSInt Result; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3972 | if (CollapseLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext())) |
Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 3973 | NestedLoopCount = Result.getLimitedValue(); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3974 | } |
| 3975 | if (OrderedLoopCountExpr) { |
| 3976 | // Found 'ordered' clause - calculate collapse number. |
| 3977 | llvm::APSInt Result; |
Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 3978 | if (OrderedLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext())) { |
| 3979 | if (Result.getLimitedValue() < NestedLoopCount) { |
| 3980 | SemaRef.Diag(OrderedLoopCountExpr->getExprLoc(), |
| 3981 | diag::err_omp_wrong_ordered_loop_count) |
| 3982 | << OrderedLoopCountExpr->getSourceRange(); |
| 3983 | SemaRef.Diag(CollapseLoopCountExpr->getExprLoc(), |
| 3984 | diag::note_collapse_loop_count) |
| 3985 | << CollapseLoopCountExpr->getSourceRange(); |
| 3986 | } |
| 3987 | NestedLoopCount = Result.getLimitedValue(); |
| 3988 | } |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3989 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3990 | // This is helper routine for loop directives (e.g., 'for', 'simd', |
| 3991 | // 'for simd', etc.). |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3992 | SmallVector<LoopIterationSpace, 4> IterSpaces; |
| 3993 | IterSpaces.resize(NestedLoopCount); |
| 3994 | Stmt *CurStmt = AStmt->IgnoreContainers(/* IgnoreCaptured */ true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3995 | for (unsigned Cnt = 0; Cnt < NestedLoopCount; ++Cnt) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3996 | if (CheckOpenMPIterationSpace(DKind, CurStmt, SemaRef, DSA, Cnt, |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3997 | NestedLoopCount, CollapseLoopCountExpr, |
| 3998 | OrderedLoopCountExpr, VarsWithImplicitDSA, |
| 3999 | IterSpaces[Cnt])) |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 4000 | return 0; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4001 | // 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] | 4002 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 4003 | // All loops associated with the construct must be perfectly nested; that |
| 4004 | // is, there must be no intervening code nor any OpenMP directive between |
| 4005 | // any two loops. |
| 4006 | CurStmt = cast<ForStmt>(CurStmt)->getBody()->IgnoreContainers(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4007 | } |
| 4008 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4009 | Built.clear(/* size */ NestedLoopCount); |
| 4010 | |
| 4011 | if (SemaRef.CurContext->isDependentContext()) |
| 4012 | return NestedLoopCount; |
| 4013 | |
| 4014 | // An example of what is generated for the following code: |
| 4015 | // |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4016 | // #pragma omp simd collapse(2) ordered(2) |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4017 | // for (i = 0; i < NI; ++i) |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4018 | // for (k = 0; k < NK; ++k) |
| 4019 | // for (j = J0; j < NJ; j+=2) { |
| 4020 | // <loop body> |
| 4021 | // } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4022 | // |
| 4023 | // We generate the code below. |
| 4024 | // Note: the loop body may be outlined in CodeGen. |
| 4025 | // Note: some counters may be C++ classes, operator- is used to find number of |
| 4026 | // iterations and operator+= to calculate counter value. |
| 4027 | // Note: decltype(NumIterations) must be integer type (in 'omp for', only i32 |
| 4028 | // or i64 is currently supported). |
| 4029 | // |
| 4030 | // #define NumIterations (NI * ((NJ - J0 - 1 + 2) / 2)) |
| 4031 | // for (int[32|64]_t IV = 0; IV < NumIterations; ++IV ) { |
| 4032 | // .local.i = IV / ((NJ - J0 - 1 + 2) / 2); |
| 4033 | // .local.j = J0 + (IV % ((NJ - J0 - 1 + 2) / 2)) * 2; |
| 4034 | // // similar updates for vars in clauses (e.g. 'linear') |
| 4035 | // <loop body (using local i and j)> |
| 4036 | // } |
| 4037 | // i = NI; // assign final values of counters |
| 4038 | // j = NJ; |
| 4039 | // |
| 4040 | |
| 4041 | // Last iteration number is (I1 * I2 * ... In) - 1, where I1, I2 ... In are |
| 4042 | // the iteration counts of the collapsed for loops. |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 4043 | // Precondition tests if there is at least one iteration (all conditions are |
| 4044 | // true). |
| 4045 | auto PreCond = ExprResult(IterSpaces[0].PreCond); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4046 | auto N0 = IterSpaces[0].NumIterations; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4047 | ExprResult LastIteration32 = WidenIterationCount( |
| 4048 | 32 /* Bits */, SemaRef.PerformImplicitConversion( |
| 4049 | N0->IgnoreImpCasts(), N0->getType(), |
| 4050 | Sema::AA_Converting, /*AllowExplicit=*/true) |
| 4051 | .get(), |
| 4052 | SemaRef); |
| 4053 | ExprResult LastIteration64 = WidenIterationCount( |
| 4054 | 64 /* Bits */, SemaRef.PerformImplicitConversion( |
| 4055 | N0->IgnoreImpCasts(), N0->getType(), |
| 4056 | Sema::AA_Converting, /*AllowExplicit=*/true) |
| 4057 | .get(), |
| 4058 | SemaRef); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4059 | |
| 4060 | if (!LastIteration32.isUsable() || !LastIteration64.isUsable()) |
| 4061 | return NestedLoopCount; |
| 4062 | |
| 4063 | auto &C = SemaRef.Context; |
| 4064 | bool AllCountsNeedLessThan32Bits = C.getTypeSize(N0->getType()) < 32; |
| 4065 | |
| 4066 | Scope *CurScope = DSA.getCurScope(); |
| 4067 | for (unsigned Cnt = 1; Cnt < NestedLoopCount; ++Cnt) { |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 4068 | if (PreCond.isUsable()) { |
| 4069 | PreCond = SemaRef.BuildBinOp(CurScope, SourceLocation(), BO_LAnd, |
| 4070 | PreCond.get(), IterSpaces[Cnt].PreCond); |
| 4071 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4072 | auto N = IterSpaces[Cnt].NumIterations; |
| 4073 | AllCountsNeedLessThan32Bits &= C.getTypeSize(N->getType()) < 32; |
| 4074 | if (LastIteration32.isUsable()) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4075 | LastIteration32 = SemaRef.BuildBinOp( |
| 4076 | CurScope, SourceLocation(), BO_Mul, LastIteration32.get(), |
| 4077 | SemaRef.PerformImplicitConversion(N->IgnoreImpCasts(), N->getType(), |
| 4078 | Sema::AA_Converting, |
| 4079 | /*AllowExplicit=*/true) |
| 4080 | .get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4081 | if (LastIteration64.isUsable()) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4082 | LastIteration64 = SemaRef.BuildBinOp( |
| 4083 | CurScope, SourceLocation(), BO_Mul, LastIteration64.get(), |
| 4084 | SemaRef.PerformImplicitConversion(N->IgnoreImpCasts(), N->getType(), |
| 4085 | Sema::AA_Converting, |
| 4086 | /*AllowExplicit=*/true) |
| 4087 | .get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4088 | } |
| 4089 | |
| 4090 | // Choose either the 32-bit or 64-bit version. |
| 4091 | ExprResult LastIteration = LastIteration64; |
| 4092 | if (LastIteration32.isUsable() && |
| 4093 | C.getTypeSize(LastIteration32.get()->getType()) == 32 && |
| 4094 | (AllCountsNeedLessThan32Bits || NestedLoopCount == 1 || |
| 4095 | FitsInto( |
| 4096 | 32 /* Bits */, |
| 4097 | LastIteration32.get()->getType()->hasSignedIntegerRepresentation(), |
| 4098 | LastIteration64.get(), SemaRef))) |
| 4099 | LastIteration = LastIteration32; |
| 4100 | |
| 4101 | if (!LastIteration.isUsable()) |
| 4102 | return 0; |
| 4103 | |
| 4104 | // Save the number of iterations. |
| 4105 | ExprResult NumIterations = LastIteration; |
| 4106 | { |
| 4107 | LastIteration = SemaRef.BuildBinOp( |
| 4108 | CurScope, SourceLocation(), BO_Sub, LastIteration.get(), |
| 4109 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 4110 | if (!LastIteration.isUsable()) |
| 4111 | return 0; |
| 4112 | } |
| 4113 | |
| 4114 | // Calculate the last iteration number beforehand instead of doing this on |
| 4115 | // each iteration. Do not do this if the number of iterations may be kfold-ed. |
| 4116 | llvm::APSInt Result; |
| 4117 | bool IsConstant = |
| 4118 | LastIteration.get()->isIntegerConstantExpr(Result, SemaRef.Context); |
| 4119 | ExprResult CalcLastIteration; |
| 4120 | if (!IsConstant) { |
| 4121 | SourceLocation SaveLoc; |
| 4122 | VarDecl *SaveVar = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4123 | buildVarDecl(SemaRef, SaveLoc, LastIteration.get()->getType(), |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4124 | ".omp.last.iteration"); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4125 | ExprResult SaveRef = buildDeclRefExpr( |
| 4126 | SemaRef, SaveVar, LastIteration.get()->getType(), SaveLoc); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4127 | CalcLastIteration = SemaRef.BuildBinOp(CurScope, SaveLoc, BO_Assign, |
| 4128 | SaveRef.get(), LastIteration.get()); |
| 4129 | LastIteration = SaveRef; |
| 4130 | |
| 4131 | // Prepare SaveRef + 1. |
| 4132 | NumIterations = SemaRef.BuildBinOp( |
| 4133 | CurScope, SaveLoc, BO_Add, SaveRef.get(), |
| 4134 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 4135 | if (!NumIterations.isUsable()) |
| 4136 | return 0; |
| 4137 | } |
| 4138 | |
| 4139 | SourceLocation InitLoc = IterSpaces[0].InitSrcRange.getBegin(); |
| 4140 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4141 | QualType VType = LastIteration.get()->getType(); |
| 4142 | // Build variables passed into runtime, nesessary for worksharing directives. |
| 4143 | ExprResult LB, UB, IL, ST, EUB; |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 4144 | if (isOpenMPWorksharingDirective(DKind) || isOpenMPTaskLoopDirective(DKind) || |
| 4145 | isOpenMPDistributeDirective(DKind)) { |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4146 | // Lower bound variable, initialized with zero. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4147 | VarDecl *LBDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.lb"); |
| 4148 | LB = buildDeclRefExpr(SemaRef, LBDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4149 | SemaRef.AddInitializerToDecl( |
| 4150 | LBDecl, SemaRef.ActOnIntegerConstant(InitLoc, 0).get(), |
| 4151 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 4152 | |
| 4153 | // Upper bound variable, initialized with last iteration number. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4154 | VarDecl *UBDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.ub"); |
| 4155 | UB = buildDeclRefExpr(SemaRef, UBDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4156 | SemaRef.AddInitializerToDecl(UBDecl, LastIteration.get(), |
| 4157 | /*DirectInit*/ false, |
| 4158 | /*TypeMayContainAuto*/ false); |
| 4159 | |
| 4160 | // A 32-bit variable-flag where runtime returns 1 for the last iteration. |
| 4161 | // This will be used to implement clause 'lastprivate'. |
| 4162 | QualType Int32Ty = SemaRef.Context.getIntTypeForBitwidth(32, true); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4163 | VarDecl *ILDecl = buildVarDecl(SemaRef, InitLoc, Int32Ty, ".omp.is_last"); |
| 4164 | IL = buildDeclRefExpr(SemaRef, ILDecl, Int32Ty, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4165 | SemaRef.AddInitializerToDecl( |
| 4166 | ILDecl, SemaRef.ActOnIntegerConstant(InitLoc, 0).get(), |
| 4167 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 4168 | |
| 4169 | // Stride variable returned by runtime (we initialize it to 1 by default). |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4170 | VarDecl *STDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.stride"); |
| 4171 | ST = buildDeclRefExpr(SemaRef, STDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4172 | SemaRef.AddInitializerToDecl( |
| 4173 | STDecl, SemaRef.ActOnIntegerConstant(InitLoc, 1).get(), |
| 4174 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 4175 | |
| 4176 | // Build expression: UB = min(UB, LastIteration) |
| 4177 | // It is nesessary for CodeGen of directives with static scheduling. |
| 4178 | ExprResult IsUBGreater = SemaRef.BuildBinOp(CurScope, InitLoc, BO_GT, |
| 4179 | UB.get(), LastIteration.get()); |
| 4180 | ExprResult CondOp = SemaRef.ActOnConditionalOp( |
| 4181 | InitLoc, InitLoc, IsUBGreater.get(), LastIteration.get(), UB.get()); |
| 4182 | EUB = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, UB.get(), |
| 4183 | CondOp.get()); |
| 4184 | EUB = SemaRef.ActOnFinishFullExpr(EUB.get()); |
| 4185 | } |
| 4186 | |
| 4187 | // Build the iteration variable and its initialization before loop. |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4188 | ExprResult IV; |
| 4189 | ExprResult Init; |
| 4190 | { |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4191 | VarDecl *IVDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.iv"); |
| 4192 | IV = buildDeclRefExpr(SemaRef, IVDecl, VType, InitLoc); |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 4193 | Expr *RHS = (isOpenMPWorksharingDirective(DKind) || |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 4194 | isOpenMPTaskLoopDirective(DKind) || |
| 4195 | isOpenMPDistributeDirective(DKind)) |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4196 | ? LB.get() |
| 4197 | : SemaRef.ActOnIntegerConstant(SourceLocation(), 0).get(); |
| 4198 | Init = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, IV.get(), RHS); |
| 4199 | Init = SemaRef.ActOnFinishFullExpr(Init.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4200 | } |
| 4201 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4202 | // Loop condition (IV < NumIterations) or (IV <= UB) for worksharing loops. |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4203 | SourceLocation CondLoc; |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4204 | ExprResult Cond = |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 4205 | (isOpenMPWorksharingDirective(DKind) || |
| 4206 | isOpenMPTaskLoopDirective(DKind) || isOpenMPDistributeDirective(DKind)) |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4207 | ? SemaRef.BuildBinOp(CurScope, CondLoc, BO_LE, IV.get(), UB.get()) |
| 4208 | : SemaRef.BuildBinOp(CurScope, CondLoc, BO_LT, IV.get(), |
| 4209 | NumIterations.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4210 | |
| 4211 | // Loop increment (IV = IV + 1) |
| 4212 | SourceLocation IncLoc; |
| 4213 | ExprResult Inc = |
| 4214 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, IV.get(), |
| 4215 | SemaRef.ActOnIntegerConstant(IncLoc, 1).get()); |
| 4216 | if (!Inc.isUsable()) |
| 4217 | return 0; |
| 4218 | Inc = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, IV.get(), Inc.get()); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4219 | Inc = SemaRef.ActOnFinishFullExpr(Inc.get()); |
| 4220 | if (!Inc.isUsable()) |
| 4221 | return 0; |
| 4222 | |
| 4223 | // Increments for worksharing loops (LB = LB + ST; UB = UB + ST). |
| 4224 | // Used for directives with static scheduling. |
| 4225 | ExprResult NextLB, NextUB; |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 4226 | if (isOpenMPWorksharingDirective(DKind) || isOpenMPTaskLoopDirective(DKind) || |
| 4227 | isOpenMPDistributeDirective(DKind)) { |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4228 | // LB + ST |
| 4229 | NextLB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, LB.get(), ST.get()); |
| 4230 | if (!NextLB.isUsable()) |
| 4231 | return 0; |
| 4232 | // LB = LB + ST |
| 4233 | NextLB = |
| 4234 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, LB.get(), NextLB.get()); |
| 4235 | NextLB = SemaRef.ActOnFinishFullExpr(NextLB.get()); |
| 4236 | if (!NextLB.isUsable()) |
| 4237 | return 0; |
| 4238 | // UB + ST |
| 4239 | NextUB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, UB.get(), ST.get()); |
| 4240 | if (!NextUB.isUsable()) |
| 4241 | return 0; |
| 4242 | // UB = UB + ST |
| 4243 | NextUB = |
| 4244 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, UB.get(), NextUB.get()); |
| 4245 | NextUB = SemaRef.ActOnFinishFullExpr(NextUB.get()); |
| 4246 | if (!NextUB.isUsable()) |
| 4247 | return 0; |
| 4248 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4249 | |
| 4250 | // Build updates and final values of the loop counters. |
| 4251 | bool HasErrors = false; |
| 4252 | Built.Counters.resize(NestedLoopCount); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4253 | Built.Inits.resize(NestedLoopCount); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4254 | Built.Updates.resize(NestedLoopCount); |
| 4255 | Built.Finals.resize(NestedLoopCount); |
| 4256 | { |
| 4257 | ExprResult Div; |
| 4258 | // Go from inner nested loop to outer. |
| 4259 | for (int Cnt = NestedLoopCount - 1; Cnt >= 0; --Cnt) { |
| 4260 | LoopIterationSpace &IS = IterSpaces[Cnt]; |
| 4261 | SourceLocation UpdLoc = IS.IncSrcRange.getBegin(); |
| 4262 | // Build: Iter = (IV / Div) % IS.NumIters |
| 4263 | // where Div is product of previous iterations' IS.NumIters. |
| 4264 | ExprResult Iter; |
| 4265 | if (Div.isUsable()) { |
| 4266 | Iter = |
| 4267 | SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Div, IV.get(), Div.get()); |
| 4268 | } else { |
| 4269 | Iter = IV; |
| 4270 | assert((Cnt == (int)NestedLoopCount - 1) && |
| 4271 | "unusable div expected on first iteration only"); |
| 4272 | } |
| 4273 | |
| 4274 | if (Cnt != 0 && Iter.isUsable()) |
| 4275 | Iter = SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Rem, Iter.get(), |
| 4276 | IS.NumIterations); |
| 4277 | if (!Iter.isUsable()) { |
| 4278 | HasErrors = true; |
| 4279 | break; |
| 4280 | } |
| 4281 | |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4282 | // Build update: IS.CounterVar(Private) = IS.Start + Iter * IS.Step |
| 4283 | auto *CounterVar = buildDeclRefExpr( |
| 4284 | SemaRef, cast<VarDecl>(cast<DeclRefExpr>(IS.CounterVar)->getDecl()), |
| 4285 | IS.CounterVar->getType(), IS.CounterVar->getExprLoc(), |
| 4286 | /*RefersToCapture=*/true); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4287 | ExprResult Init = BuildCounterInit(SemaRef, CurScope, UpdLoc, CounterVar, |
| 4288 | IS.CounterInit); |
| 4289 | if (!Init.isUsable()) { |
| 4290 | HasErrors = true; |
| 4291 | break; |
| 4292 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4293 | ExprResult Update = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4294 | BuildCounterUpdate(SemaRef, CurScope, UpdLoc, CounterVar, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4295 | IS.CounterInit, Iter, IS.CounterStep, IS.Subtract); |
| 4296 | if (!Update.isUsable()) { |
| 4297 | HasErrors = true; |
| 4298 | break; |
| 4299 | } |
| 4300 | |
| 4301 | // Build final: IS.CounterVar = IS.Start + IS.NumIters * IS.Step |
| 4302 | ExprResult Final = BuildCounterUpdate( |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4303 | SemaRef, CurScope, UpdLoc, CounterVar, IS.CounterInit, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4304 | IS.NumIterations, IS.CounterStep, IS.Subtract); |
| 4305 | if (!Final.isUsable()) { |
| 4306 | HasErrors = true; |
| 4307 | break; |
| 4308 | } |
| 4309 | |
| 4310 | // Build Div for the next iteration: Div <- Div * IS.NumIters |
| 4311 | if (Cnt != 0) { |
| 4312 | if (Div.isUnset()) |
| 4313 | Div = IS.NumIterations; |
| 4314 | else |
| 4315 | Div = SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Mul, Div.get(), |
| 4316 | IS.NumIterations); |
| 4317 | |
| 4318 | // Add parentheses (for debugging purposes only). |
| 4319 | if (Div.isUsable()) |
| 4320 | Div = SemaRef.ActOnParenExpr(UpdLoc, UpdLoc, Div.get()); |
| 4321 | if (!Div.isUsable()) { |
| 4322 | HasErrors = true; |
| 4323 | break; |
| 4324 | } |
| 4325 | } |
| 4326 | if (!Update.isUsable() || !Final.isUsable()) { |
| 4327 | HasErrors = true; |
| 4328 | break; |
| 4329 | } |
| 4330 | // Save results |
| 4331 | Built.Counters[Cnt] = IS.CounterVar; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 4332 | Built.PrivateCounters[Cnt] = IS.PrivateCounterVar; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4333 | Built.Inits[Cnt] = Init.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4334 | Built.Updates[Cnt] = Update.get(); |
| 4335 | Built.Finals[Cnt] = Final.get(); |
| 4336 | } |
| 4337 | } |
| 4338 | |
| 4339 | if (HasErrors) |
| 4340 | return 0; |
| 4341 | |
| 4342 | // Save results |
| 4343 | Built.IterationVarRef = IV.get(); |
| 4344 | Built.LastIteration = LastIteration.get(); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 4345 | Built.NumIterations = NumIterations.get(); |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 4346 | Built.CalcLastIteration = |
| 4347 | SemaRef.ActOnFinishFullExpr(CalcLastIteration.get()).get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4348 | Built.PreCond = PreCond.get(); |
| 4349 | Built.Cond = Cond.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4350 | Built.Init = Init.get(); |
| 4351 | Built.Inc = Inc.get(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4352 | Built.LB = LB.get(); |
| 4353 | Built.UB = UB.get(); |
| 4354 | Built.IL = IL.get(); |
| 4355 | Built.ST = ST.get(); |
| 4356 | Built.EUB = EUB.get(); |
| 4357 | Built.NLB = NextLB.get(); |
| 4358 | Built.NUB = NextUB.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4359 | |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 4360 | return NestedLoopCount; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4361 | } |
| 4362 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4363 | static Expr *getCollapseNumberExpr(ArrayRef<OMPClause *> Clauses) { |
Benjamin Kramer | fc600dc | 2015-08-30 15:12:28 +0000 | [diff] [blame] | 4364 | auto CollapseClauses = |
| 4365 | OMPExecutableDirective::getClausesOfKind<OMPCollapseClause>(Clauses); |
| 4366 | if (CollapseClauses.begin() != CollapseClauses.end()) |
| 4367 | return (*CollapseClauses.begin())->getNumForLoops(); |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 4368 | return nullptr; |
| 4369 | } |
| 4370 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4371 | static Expr *getOrderedNumberExpr(ArrayRef<OMPClause *> Clauses) { |
Benjamin Kramer | fc600dc | 2015-08-30 15:12:28 +0000 | [diff] [blame] | 4372 | auto OrderedClauses = |
| 4373 | OMPExecutableDirective::getClausesOfKind<OMPOrderedClause>(Clauses); |
| 4374 | if (OrderedClauses.begin() != OrderedClauses.end()) |
| 4375 | return (*OrderedClauses.begin())->getNumForLoops(); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4376 | return nullptr; |
| 4377 | } |
| 4378 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 4379 | static bool checkSimdlenSafelenValues(Sema &S, const Expr *Simdlen, |
| 4380 | const Expr *Safelen) { |
| 4381 | llvm::APSInt SimdlenRes, SafelenRes; |
| 4382 | if (Simdlen->isValueDependent() || Simdlen->isTypeDependent() || |
| 4383 | Simdlen->isInstantiationDependent() || |
| 4384 | Simdlen->containsUnexpandedParameterPack()) |
| 4385 | return false; |
| 4386 | if (Safelen->isValueDependent() || Safelen->isTypeDependent() || |
| 4387 | Safelen->isInstantiationDependent() || |
| 4388 | Safelen->containsUnexpandedParameterPack()) |
| 4389 | return false; |
| 4390 | Simdlen->EvaluateAsInt(SimdlenRes, S.Context); |
| 4391 | Safelen->EvaluateAsInt(SafelenRes, S.Context); |
| 4392 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 4393 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 4394 | // parameter must be less than or equal to the value of the safelen parameter. |
| 4395 | if (SimdlenRes > SafelenRes) { |
| 4396 | S.Diag(Simdlen->getExprLoc(), diag::err_omp_wrong_simdlen_safelen_values) |
| 4397 | << Simdlen->getSourceRange() << Safelen->getSourceRange(); |
| 4398 | return true; |
| 4399 | } |
| 4400 | return false; |
| 4401 | } |
| 4402 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4403 | StmtResult Sema::ActOnOpenMPSimdDirective( |
| 4404 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4405 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 4406 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4407 | if (!AStmt) |
| 4408 | return StmtError(); |
| 4409 | |
| 4410 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4411 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4412 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4413 | // define the nested loops number. |
| 4414 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 4415 | OMPD_simd, getCollapseNumberExpr(Clauses), getOrderedNumberExpr(Clauses), |
| 4416 | AStmt, *this, *DSAStack, VarsWithImplicitDSA, B); |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 4417 | if (NestedLoopCount == 0) |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 4418 | return StmtError(); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 4419 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4420 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 4421 | "omp simd loop exprs were not built"); |
| 4422 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 4423 | if (!CurContext->isDependentContext()) { |
| 4424 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4425 | for (auto C : Clauses) { |
| 4426 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 4427 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 4428 | B.NumIterations, *this, CurScope)) |
| 4429 | return StmtError(); |
| 4430 | } |
| 4431 | } |
| 4432 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 4433 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 4434 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 4435 | // parameter must be less than or equal to the value of the safelen parameter. |
| 4436 | OMPSafelenClause *Safelen = nullptr; |
| 4437 | OMPSimdlenClause *Simdlen = nullptr; |
| 4438 | for (auto *Clause : Clauses) { |
| 4439 | if (Clause->getClauseKind() == OMPC_safelen) |
| 4440 | Safelen = cast<OMPSafelenClause>(Clause); |
| 4441 | else if (Clause->getClauseKind() == OMPC_simdlen) |
| 4442 | Simdlen = cast<OMPSimdlenClause>(Clause); |
| 4443 | if (Safelen && Simdlen) |
| 4444 | break; |
| 4445 | } |
| 4446 | if (Simdlen && Safelen && |
| 4447 | checkSimdlenSafelenValues(*this, Simdlen->getSimdlen(), |
| 4448 | Safelen->getSafelen())) |
| 4449 | return StmtError(); |
| 4450 | |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 4451 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4452 | return OMPSimdDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| 4453 | Clauses, AStmt, B); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 4454 | } |
| 4455 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4456 | StmtResult Sema::ActOnOpenMPForDirective( |
| 4457 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4458 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 4459 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4460 | if (!AStmt) |
| 4461 | return StmtError(); |
| 4462 | |
| 4463 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4464 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4465 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4466 | // define the nested loops number. |
| 4467 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 4468 | OMPD_for, getCollapseNumberExpr(Clauses), getOrderedNumberExpr(Clauses), |
| 4469 | AStmt, *this, *DSAStack, VarsWithImplicitDSA, B); |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 4470 | if (NestedLoopCount == 0) |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4471 | return StmtError(); |
| 4472 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4473 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 4474 | "omp for loop exprs were not built"); |
| 4475 | |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 4476 | if (!CurContext->isDependentContext()) { |
| 4477 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4478 | for (auto C : Clauses) { |
| 4479 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 4480 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 4481 | B.NumIterations, *this, CurScope)) |
| 4482 | return StmtError(); |
| 4483 | } |
| 4484 | } |
| 4485 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4486 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4487 | return OMPForDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4488 | Clauses, AStmt, B, DSAStack->isCancelRegion()); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4489 | } |
| 4490 | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4491 | StmtResult Sema::ActOnOpenMPForSimdDirective( |
| 4492 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4493 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 4494 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4495 | if (!AStmt) |
| 4496 | return StmtError(); |
| 4497 | |
| 4498 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4499 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4500 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4501 | // define the nested loops number. |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4502 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4503 | CheckOpenMPLoop(OMPD_for_simd, getCollapseNumberExpr(Clauses), |
| 4504 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 4505 | VarsWithImplicitDSA, B); |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4506 | if (NestedLoopCount == 0) |
| 4507 | return StmtError(); |
| 4508 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4509 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 4510 | "omp for simd loop exprs were not built"); |
| 4511 | |
Alexey Bataev | 58e5bdb | 2015-06-18 04:45:29 +0000 | [diff] [blame] | 4512 | if (!CurContext->isDependentContext()) { |
| 4513 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4514 | for (auto C : Clauses) { |
| 4515 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 4516 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 4517 | B.NumIterations, *this, CurScope)) |
| 4518 | return StmtError(); |
| 4519 | } |
| 4520 | } |
| 4521 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 4522 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 4523 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 4524 | // parameter must be less than or equal to the value of the safelen parameter. |
| 4525 | OMPSafelenClause *Safelen = nullptr; |
| 4526 | OMPSimdlenClause *Simdlen = nullptr; |
| 4527 | for (auto *Clause : Clauses) { |
| 4528 | if (Clause->getClauseKind() == OMPC_safelen) |
| 4529 | Safelen = cast<OMPSafelenClause>(Clause); |
| 4530 | else if (Clause->getClauseKind() == OMPC_simdlen) |
| 4531 | Simdlen = cast<OMPSimdlenClause>(Clause); |
| 4532 | if (Safelen && Simdlen) |
| 4533 | break; |
| 4534 | } |
| 4535 | if (Simdlen && Safelen && |
| 4536 | checkSimdlenSafelenValues(*this, Simdlen->getSimdlen(), |
| 4537 | Safelen->getSafelen())) |
| 4538 | return StmtError(); |
| 4539 | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4540 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4541 | return OMPForSimdDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| 4542 | Clauses, AStmt, B); |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4543 | } |
| 4544 | |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4545 | StmtResult Sema::ActOnOpenMPSectionsDirective(ArrayRef<OMPClause *> Clauses, |
| 4546 | Stmt *AStmt, |
| 4547 | SourceLocation StartLoc, |
| 4548 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4549 | if (!AStmt) |
| 4550 | return StmtError(); |
| 4551 | |
| 4552 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4553 | auto BaseStmt = AStmt; |
| 4554 | while (CapturedStmt *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt)) |
| 4555 | BaseStmt = CS->getCapturedStmt(); |
| 4556 | if (auto C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) { |
| 4557 | auto S = C->children(); |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 4558 | if (S.begin() == S.end()) |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4559 | return StmtError(); |
| 4560 | // All associated statements must be '#pragma omp section' except for |
| 4561 | // the first one. |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 4562 | for (Stmt *SectionStmt : llvm::make_range(std::next(S.begin()), S.end())) { |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4563 | if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) { |
| 4564 | if (SectionStmt) |
| 4565 | Diag(SectionStmt->getLocStart(), |
| 4566 | diag::err_omp_sections_substmt_not_section); |
| 4567 | return StmtError(); |
| 4568 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4569 | cast<OMPSectionDirective>(SectionStmt) |
| 4570 | ->setHasCancel(DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4571 | } |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4572 | } else { |
| 4573 | Diag(AStmt->getLocStart(), diag::err_omp_sections_not_compound_stmt); |
| 4574 | return StmtError(); |
| 4575 | } |
| 4576 | |
| 4577 | getCurFunction()->setHasBranchProtectedScope(); |
| 4578 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4579 | return OMPSectionsDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 4580 | DSAStack->isCancelRegion()); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4581 | } |
| 4582 | |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4583 | StmtResult Sema::ActOnOpenMPSectionDirective(Stmt *AStmt, |
| 4584 | SourceLocation StartLoc, |
| 4585 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4586 | if (!AStmt) |
| 4587 | return StmtError(); |
| 4588 | |
| 4589 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4590 | |
| 4591 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4592 | DSAStack->setParentCancelRegion(DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4593 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4594 | return OMPSectionDirective::Create(Context, StartLoc, EndLoc, AStmt, |
| 4595 | DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4596 | } |
| 4597 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 4598 | StmtResult Sema::ActOnOpenMPSingleDirective(ArrayRef<OMPClause *> Clauses, |
| 4599 | Stmt *AStmt, |
| 4600 | SourceLocation StartLoc, |
| 4601 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4602 | if (!AStmt) |
| 4603 | return StmtError(); |
| 4604 | |
| 4605 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 74a05c9 | 2014-07-15 02:55:09 +0000 | [diff] [blame] | 4606 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 4607 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | 74a05c9 | 2014-07-15 02:55:09 +0000 | [diff] [blame] | 4608 | |
Alexey Bataev | 3255bf3 | 2015-01-19 05:20:46 +0000 | [diff] [blame] | 4609 | // OpenMP [2.7.3, single Construct, Restrictions] |
| 4610 | // The copyprivate clause must not be used with the nowait clause. |
| 4611 | OMPClause *Nowait = nullptr; |
| 4612 | OMPClause *Copyprivate = nullptr; |
| 4613 | for (auto *Clause : Clauses) { |
| 4614 | if (Clause->getClauseKind() == OMPC_nowait) |
| 4615 | Nowait = Clause; |
| 4616 | else if (Clause->getClauseKind() == OMPC_copyprivate) |
| 4617 | Copyprivate = Clause; |
| 4618 | if (Copyprivate && Nowait) { |
| 4619 | Diag(Copyprivate->getLocStart(), |
| 4620 | diag::err_omp_single_copyprivate_with_nowait); |
| 4621 | Diag(Nowait->getLocStart(), diag::note_omp_nowait_clause_here); |
| 4622 | return StmtError(); |
| 4623 | } |
| 4624 | } |
| 4625 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 4626 | return OMPSingleDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 4627 | } |
| 4628 | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 4629 | StmtResult Sema::ActOnOpenMPMasterDirective(Stmt *AStmt, |
| 4630 | SourceLocation StartLoc, |
| 4631 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4632 | if (!AStmt) |
| 4633 | return StmtError(); |
| 4634 | |
| 4635 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 4636 | |
| 4637 | getCurFunction()->setHasBranchProtectedScope(); |
| 4638 | |
| 4639 | return OMPMasterDirective::Create(Context, StartLoc, EndLoc, AStmt); |
| 4640 | } |
| 4641 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 4642 | StmtResult Sema::ActOnOpenMPCriticalDirective( |
| 4643 | const DeclarationNameInfo &DirName, ArrayRef<OMPClause *> Clauses, |
| 4644 | Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4645 | if (!AStmt) |
| 4646 | return StmtError(); |
| 4647 | |
| 4648 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 4649 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 4650 | bool ErrorFound = false; |
| 4651 | llvm::APSInt Hint; |
| 4652 | SourceLocation HintLoc; |
| 4653 | bool DependentHint = false; |
| 4654 | for (auto *C : Clauses) { |
| 4655 | if (C->getClauseKind() == OMPC_hint) { |
| 4656 | if (!DirName.getName()) { |
| 4657 | Diag(C->getLocStart(), diag::err_omp_hint_clause_no_name); |
| 4658 | ErrorFound = true; |
| 4659 | } |
| 4660 | Expr *E = cast<OMPHintClause>(C)->getHint(); |
| 4661 | if (E->isTypeDependent() || E->isValueDependent() || |
| 4662 | E->isInstantiationDependent()) |
| 4663 | DependentHint = true; |
| 4664 | else { |
| 4665 | Hint = E->EvaluateKnownConstInt(Context); |
| 4666 | HintLoc = C->getLocStart(); |
| 4667 | } |
| 4668 | } |
| 4669 | } |
| 4670 | if (ErrorFound) |
| 4671 | return StmtError(); |
| 4672 | auto Pair = DSAStack->getCriticalWithHint(DirName); |
| 4673 | if (Pair.first && DirName.getName() && !DependentHint) { |
| 4674 | if (llvm::APSInt::compareValues(Hint, Pair.second) != 0) { |
| 4675 | Diag(StartLoc, diag::err_omp_critical_with_hint); |
| 4676 | if (HintLoc.isValid()) { |
| 4677 | Diag(HintLoc, diag::note_omp_critical_hint_here) |
| 4678 | << 0 << Hint.toString(/*Radix=*/10, /*Signed=*/false); |
| 4679 | } else |
| 4680 | Diag(StartLoc, diag::note_omp_critical_no_hint) << 0; |
| 4681 | if (auto *C = Pair.first->getSingleClause<OMPHintClause>()) { |
| 4682 | Diag(C->getLocStart(), diag::note_omp_critical_hint_here) |
| 4683 | << 1 |
| 4684 | << C->getHint()->EvaluateKnownConstInt(Context).toString( |
| 4685 | /*Radix=*/10, /*Signed=*/false); |
| 4686 | } else |
| 4687 | Diag(Pair.first->getLocStart(), diag::note_omp_critical_no_hint) << 1; |
| 4688 | } |
| 4689 | } |
| 4690 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 4691 | getCurFunction()->setHasBranchProtectedScope(); |
| 4692 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 4693 | auto *Dir = OMPCriticalDirective::Create(Context, DirName, StartLoc, EndLoc, |
| 4694 | Clauses, AStmt); |
| 4695 | if (!Pair.first && DirName.getName() && !DependentHint) |
| 4696 | DSAStack->addCriticalWithHint(Dir, Hint); |
| 4697 | return Dir; |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 4698 | } |
| 4699 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4700 | StmtResult Sema::ActOnOpenMPParallelForDirective( |
| 4701 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4702 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 4703 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4704 | if (!AStmt) |
| 4705 | return StmtError(); |
| 4706 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4707 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 4708 | // 1.2.2 OpenMP Language Terminology |
| 4709 | // Structured block - An executable statement with a single entry at the |
| 4710 | // top and a single exit at the bottom. |
| 4711 | // The point of exit cannot be a branch out of the structured block. |
| 4712 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 4713 | CS->getCapturedDecl()->setNothrow(); |
| 4714 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4715 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4716 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4717 | // define the nested loops number. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4718 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4719 | CheckOpenMPLoop(OMPD_parallel_for, getCollapseNumberExpr(Clauses), |
| 4720 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 4721 | VarsWithImplicitDSA, B); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4722 | if (NestedLoopCount == 0) |
| 4723 | return StmtError(); |
| 4724 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4725 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 4726 | "omp parallel for loop exprs were not built"); |
| 4727 | |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 4728 | if (!CurContext->isDependentContext()) { |
| 4729 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4730 | for (auto C : Clauses) { |
| 4731 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 4732 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 4733 | B.NumIterations, *this, CurScope)) |
| 4734 | return StmtError(); |
| 4735 | } |
| 4736 | } |
| 4737 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4738 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4739 | return OMPParallelForDirective::Create(Context, StartLoc, EndLoc, |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4740 | NestedLoopCount, Clauses, AStmt, B, |
| 4741 | DSAStack->isCancelRegion()); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4742 | } |
| 4743 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4744 | StmtResult Sema::ActOnOpenMPParallelForSimdDirective( |
| 4745 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4746 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 4747 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4748 | if (!AStmt) |
| 4749 | return StmtError(); |
| 4750 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4751 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 4752 | // 1.2.2 OpenMP Language Terminology |
| 4753 | // Structured block - An executable statement with a single entry at the |
| 4754 | // top and a single exit at the bottom. |
| 4755 | // The point of exit cannot be a branch out of the structured block. |
| 4756 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 4757 | CS->getCapturedDecl()->setNothrow(); |
| 4758 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4759 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4760 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4761 | // define the nested loops number. |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4762 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4763 | CheckOpenMPLoop(OMPD_parallel_for_simd, getCollapseNumberExpr(Clauses), |
| 4764 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 4765 | VarsWithImplicitDSA, B); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4766 | if (NestedLoopCount == 0) |
| 4767 | return StmtError(); |
| 4768 | |
Alexey Bataev | 3b5b5c4 | 2015-06-18 10:10:12 +0000 | [diff] [blame] | 4769 | if (!CurContext->isDependentContext()) { |
| 4770 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4771 | for (auto C : Clauses) { |
| 4772 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 4773 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 4774 | B.NumIterations, *this, CurScope)) |
| 4775 | return StmtError(); |
| 4776 | } |
| 4777 | } |
| 4778 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 4779 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 4780 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 4781 | // parameter must be less than or equal to the value of the safelen parameter. |
| 4782 | OMPSafelenClause *Safelen = nullptr; |
| 4783 | OMPSimdlenClause *Simdlen = nullptr; |
| 4784 | for (auto *Clause : Clauses) { |
| 4785 | if (Clause->getClauseKind() == OMPC_safelen) |
| 4786 | Safelen = cast<OMPSafelenClause>(Clause); |
| 4787 | else if (Clause->getClauseKind() == OMPC_simdlen) |
| 4788 | Simdlen = cast<OMPSimdlenClause>(Clause); |
| 4789 | if (Safelen && Simdlen) |
| 4790 | break; |
| 4791 | } |
| 4792 | if (Simdlen && Safelen && |
| 4793 | checkSimdlenSafelenValues(*this, Simdlen->getSimdlen(), |
| 4794 | Safelen->getSafelen())) |
| 4795 | return StmtError(); |
| 4796 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4797 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4798 | return OMPParallelForSimdDirective::Create( |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4799 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4800 | } |
| 4801 | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4802 | StmtResult |
| 4803 | Sema::ActOnOpenMPParallelSectionsDirective(ArrayRef<OMPClause *> Clauses, |
| 4804 | Stmt *AStmt, SourceLocation StartLoc, |
| 4805 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4806 | if (!AStmt) |
| 4807 | return StmtError(); |
| 4808 | |
| 4809 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4810 | auto BaseStmt = AStmt; |
| 4811 | while (CapturedStmt *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt)) |
| 4812 | BaseStmt = CS->getCapturedStmt(); |
| 4813 | if (auto C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) { |
| 4814 | auto S = C->children(); |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 4815 | if (S.begin() == S.end()) |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4816 | return StmtError(); |
| 4817 | // All associated statements must be '#pragma omp section' except for |
| 4818 | // the first one. |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 4819 | for (Stmt *SectionStmt : llvm::make_range(std::next(S.begin()), S.end())) { |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4820 | if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) { |
| 4821 | if (SectionStmt) |
| 4822 | Diag(SectionStmt->getLocStart(), |
| 4823 | diag::err_omp_parallel_sections_substmt_not_section); |
| 4824 | return StmtError(); |
| 4825 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4826 | cast<OMPSectionDirective>(SectionStmt) |
| 4827 | ->setHasCancel(DSAStack->isCancelRegion()); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4828 | } |
| 4829 | } else { |
| 4830 | Diag(AStmt->getLocStart(), |
| 4831 | diag::err_omp_parallel_sections_not_compound_stmt); |
| 4832 | return StmtError(); |
| 4833 | } |
| 4834 | |
| 4835 | getCurFunction()->setHasBranchProtectedScope(); |
| 4836 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4837 | return OMPParallelSectionsDirective::Create( |
| 4838 | Context, StartLoc, EndLoc, Clauses, AStmt, DSAStack->isCancelRegion()); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4839 | } |
| 4840 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 4841 | StmtResult Sema::ActOnOpenMPTaskDirective(ArrayRef<OMPClause *> Clauses, |
| 4842 | Stmt *AStmt, SourceLocation StartLoc, |
| 4843 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4844 | if (!AStmt) |
| 4845 | return StmtError(); |
| 4846 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 4847 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 4848 | // 1.2.2 OpenMP Language Terminology |
| 4849 | // Structured block - An executable statement with a single entry at the |
| 4850 | // top and a single exit at the bottom. |
| 4851 | // The point of exit cannot be a branch out of the structured block. |
| 4852 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 4853 | CS->getCapturedDecl()->setNothrow(); |
| 4854 | |
| 4855 | getCurFunction()->setHasBranchProtectedScope(); |
| 4856 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4857 | return OMPTaskDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 4858 | DSAStack->isCancelRegion()); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 4859 | } |
| 4860 | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 4861 | StmtResult Sema::ActOnOpenMPTaskyieldDirective(SourceLocation StartLoc, |
| 4862 | SourceLocation EndLoc) { |
| 4863 | return OMPTaskyieldDirective::Create(Context, StartLoc, EndLoc); |
| 4864 | } |
| 4865 | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 4866 | StmtResult Sema::ActOnOpenMPBarrierDirective(SourceLocation StartLoc, |
| 4867 | SourceLocation EndLoc) { |
| 4868 | return OMPBarrierDirective::Create(Context, StartLoc, EndLoc); |
| 4869 | } |
| 4870 | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 4871 | StmtResult Sema::ActOnOpenMPTaskwaitDirective(SourceLocation StartLoc, |
| 4872 | SourceLocation EndLoc) { |
| 4873 | return OMPTaskwaitDirective::Create(Context, StartLoc, EndLoc); |
| 4874 | } |
| 4875 | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 4876 | StmtResult Sema::ActOnOpenMPTaskgroupDirective(Stmt *AStmt, |
| 4877 | SourceLocation StartLoc, |
| 4878 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4879 | if (!AStmt) |
| 4880 | return StmtError(); |
| 4881 | |
| 4882 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 4883 | |
| 4884 | getCurFunction()->setHasBranchProtectedScope(); |
| 4885 | |
| 4886 | return OMPTaskgroupDirective::Create(Context, StartLoc, EndLoc, AStmt); |
| 4887 | } |
| 4888 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 4889 | StmtResult Sema::ActOnOpenMPFlushDirective(ArrayRef<OMPClause *> Clauses, |
| 4890 | SourceLocation StartLoc, |
| 4891 | SourceLocation EndLoc) { |
| 4892 | assert(Clauses.size() <= 1 && "Extra clauses in flush directive"); |
| 4893 | return OMPFlushDirective::Create(Context, StartLoc, EndLoc, Clauses); |
| 4894 | } |
| 4895 | |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 4896 | StmtResult Sema::ActOnOpenMPOrderedDirective(ArrayRef<OMPClause *> Clauses, |
| 4897 | Stmt *AStmt, |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 4898 | SourceLocation StartLoc, |
| 4899 | SourceLocation EndLoc) { |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 4900 | OMPClause *DependFound = nullptr; |
| 4901 | OMPClause *DependSourceClause = nullptr; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 4902 | OMPClause *DependSinkClause = nullptr; |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 4903 | bool ErrorFound = false; |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 4904 | OMPThreadsClause *TC = nullptr; |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 4905 | OMPSIMDClause *SC = nullptr; |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 4906 | for (auto *C : Clauses) { |
| 4907 | if (auto *DC = dyn_cast<OMPDependClause>(C)) { |
| 4908 | DependFound = C; |
| 4909 | if (DC->getDependencyKind() == OMPC_DEPEND_source) { |
| 4910 | if (DependSourceClause) { |
| 4911 | Diag(C->getLocStart(), diag::err_omp_more_one_clause) |
| 4912 | << getOpenMPDirectiveName(OMPD_ordered) |
| 4913 | << getOpenMPClauseName(OMPC_depend) << 2; |
| 4914 | ErrorFound = true; |
| 4915 | } else |
| 4916 | DependSourceClause = C; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 4917 | if (DependSinkClause) { |
| 4918 | Diag(C->getLocStart(), diag::err_omp_depend_sink_source_not_allowed) |
| 4919 | << 0; |
| 4920 | ErrorFound = true; |
| 4921 | } |
| 4922 | } else if (DC->getDependencyKind() == OMPC_DEPEND_sink) { |
| 4923 | if (DependSourceClause) { |
| 4924 | Diag(C->getLocStart(), diag::err_omp_depend_sink_source_not_allowed) |
| 4925 | << 1; |
| 4926 | ErrorFound = true; |
| 4927 | } |
| 4928 | DependSinkClause = C; |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 4929 | } |
| 4930 | } else if (C->getClauseKind() == OMPC_threads) |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 4931 | TC = cast<OMPThreadsClause>(C); |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 4932 | else if (C->getClauseKind() == OMPC_simd) |
| 4933 | SC = cast<OMPSIMDClause>(C); |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 4934 | } |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 4935 | if (!ErrorFound && !SC && |
| 4936 | isOpenMPSimdDirective(DSAStack->getParentDirective())) { |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 4937 | // OpenMP [2.8.1,simd Construct, Restrictions] |
| 4938 | // An ordered construct with the simd clause is the only OpenMP construct |
| 4939 | // that can appear in the simd region. |
| 4940 | Diag(StartLoc, diag::err_omp_prohibited_region_simd); |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 4941 | ErrorFound = true; |
| 4942 | } else if (DependFound && (TC || SC)) { |
| 4943 | Diag(DependFound->getLocStart(), diag::err_omp_depend_clause_thread_simd) |
| 4944 | << getOpenMPClauseName(TC ? TC->getClauseKind() : SC->getClauseKind()); |
| 4945 | ErrorFound = true; |
| 4946 | } else if (DependFound && !DSAStack->getParentOrderedRegionParam()) { |
| 4947 | Diag(DependFound->getLocStart(), |
| 4948 | diag::err_omp_ordered_directive_without_param); |
| 4949 | ErrorFound = true; |
| 4950 | } else if (TC || Clauses.empty()) { |
| 4951 | if (auto *Param = DSAStack->getParentOrderedRegionParam()) { |
| 4952 | SourceLocation ErrLoc = TC ? TC->getLocStart() : StartLoc; |
| 4953 | Diag(ErrLoc, diag::err_omp_ordered_directive_with_param) |
| 4954 | << (TC != nullptr); |
| 4955 | Diag(Param->getLocStart(), diag::note_omp_ordered_param); |
| 4956 | ErrorFound = true; |
| 4957 | } |
| 4958 | } |
| 4959 | if ((!AStmt && !DependFound) || ErrorFound) |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 4960 | return StmtError(); |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 4961 | |
| 4962 | if (AStmt) { |
| 4963 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 4964 | |
| 4965 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 4966 | } |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 4967 | |
| 4968 | return OMPOrderedDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 4969 | } |
| 4970 | |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4971 | namespace { |
| 4972 | /// \brief Helper class for checking expression in 'omp atomic [update]' |
| 4973 | /// construct. |
| 4974 | class OpenMPAtomicUpdateChecker { |
| 4975 | /// \brief Error results for atomic update expressions. |
| 4976 | enum ExprAnalysisErrorCode { |
| 4977 | /// \brief A statement is not an expression statement. |
| 4978 | NotAnExpression, |
| 4979 | /// \brief Expression is not builtin binary or unary operation. |
| 4980 | NotABinaryOrUnaryExpression, |
| 4981 | /// \brief Unary operation is not post-/pre- increment/decrement operation. |
| 4982 | NotAnUnaryIncDecExpression, |
| 4983 | /// \brief An expression is not of scalar type. |
| 4984 | NotAScalarType, |
| 4985 | /// \brief A binary operation is not an assignment operation. |
| 4986 | NotAnAssignmentOp, |
| 4987 | /// \brief RHS part of the binary operation is not a binary expression. |
| 4988 | NotABinaryExpression, |
| 4989 | /// \brief RHS part is not additive/multiplicative/shift/biwise binary |
| 4990 | /// expression. |
| 4991 | NotABinaryOperator, |
| 4992 | /// \brief RHS binary operation does not have reference to the updated LHS |
| 4993 | /// part. |
| 4994 | NotAnUpdateExpression, |
| 4995 | /// \brief No errors is found. |
| 4996 | NoError |
| 4997 | }; |
| 4998 | /// \brief Reference to Sema. |
| 4999 | Sema &SemaRef; |
| 5000 | /// \brief A location for note diagnostics (when error is found). |
| 5001 | SourceLocation NoteLoc; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5002 | /// \brief 'x' lvalue part of the source atomic expression. |
| 5003 | Expr *X; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5004 | /// \brief 'expr' rvalue part of the source atomic expression. |
| 5005 | Expr *E; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5006 | /// \brief Helper expression of the form |
| 5007 | /// 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or |
| 5008 | /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'. |
| 5009 | Expr *UpdateExpr; |
| 5010 | /// \brief Is 'x' a LHS in a RHS part of full update expression. It is |
| 5011 | /// important for non-associative operations. |
| 5012 | bool IsXLHSInRHSPart; |
| 5013 | BinaryOperatorKind Op; |
| 5014 | SourceLocation OpLoc; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5015 | /// \brief true if the source expression is a postfix unary operation, false |
| 5016 | /// if it is a prefix unary operation. |
| 5017 | bool IsPostfixUpdate; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5018 | |
| 5019 | public: |
| 5020 | OpenMPAtomicUpdateChecker(Sema &SemaRef) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5021 | : SemaRef(SemaRef), X(nullptr), E(nullptr), UpdateExpr(nullptr), |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5022 | IsXLHSInRHSPart(false), Op(BO_PtrMemD), IsPostfixUpdate(false) {} |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5023 | /// \brief Check specified statement that it is suitable for 'atomic update' |
| 5024 | /// constructs and extract 'x', 'expr' and Operation from the original |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5025 | /// expression. If DiagId and NoteId == 0, then only check is performed |
| 5026 | /// without error notification. |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5027 | /// \param DiagId Diagnostic which should be emitted if error is found. |
| 5028 | /// \param NoteId Diagnostic note for the main error message. |
| 5029 | /// \return true if statement is not an update expression, false otherwise. |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5030 | bool checkStatement(Stmt *S, unsigned DiagId = 0, unsigned NoteId = 0); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5031 | /// \brief Return the 'x' lvalue part of the source atomic expression. |
| 5032 | Expr *getX() const { return X; } |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5033 | /// \brief Return the 'expr' rvalue part of the source atomic expression. |
| 5034 | Expr *getExpr() const { return E; } |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5035 | /// \brief Return the update expression used in calculation of the updated |
| 5036 | /// value. Always has form 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or |
| 5037 | /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'. |
| 5038 | Expr *getUpdateExpr() const { return UpdateExpr; } |
| 5039 | /// \brief Return true if 'x' is LHS in RHS part of full update expression, |
| 5040 | /// false otherwise. |
| 5041 | bool isXLHSInRHSPart() const { return IsXLHSInRHSPart; } |
| 5042 | |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5043 | /// \brief true if the source expression is a postfix unary operation, false |
| 5044 | /// if it is a prefix unary operation. |
| 5045 | bool isPostfixUpdate() const { return IsPostfixUpdate; } |
| 5046 | |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5047 | private: |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5048 | bool checkBinaryOperation(BinaryOperator *AtomicBinOp, unsigned DiagId = 0, |
| 5049 | unsigned NoteId = 0); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5050 | }; |
| 5051 | } // namespace |
| 5052 | |
| 5053 | bool OpenMPAtomicUpdateChecker::checkBinaryOperation( |
| 5054 | BinaryOperator *AtomicBinOp, unsigned DiagId, unsigned NoteId) { |
| 5055 | ExprAnalysisErrorCode ErrorFound = NoError; |
| 5056 | SourceLocation ErrorLoc, NoteLoc; |
| 5057 | SourceRange ErrorRange, NoteRange; |
| 5058 | // Allowed constructs are: |
| 5059 | // x = x binop expr; |
| 5060 | // x = expr binop x; |
| 5061 | if (AtomicBinOp->getOpcode() == BO_Assign) { |
| 5062 | X = AtomicBinOp->getLHS(); |
| 5063 | if (auto *AtomicInnerBinOp = dyn_cast<BinaryOperator>( |
| 5064 | AtomicBinOp->getRHS()->IgnoreParenImpCasts())) { |
| 5065 | if (AtomicInnerBinOp->isMultiplicativeOp() || |
| 5066 | AtomicInnerBinOp->isAdditiveOp() || AtomicInnerBinOp->isShiftOp() || |
| 5067 | AtomicInnerBinOp->isBitwiseOp()) { |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5068 | Op = AtomicInnerBinOp->getOpcode(); |
| 5069 | OpLoc = AtomicInnerBinOp->getOperatorLoc(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5070 | auto *LHS = AtomicInnerBinOp->getLHS(); |
| 5071 | auto *RHS = AtomicInnerBinOp->getRHS(); |
| 5072 | llvm::FoldingSetNodeID XId, LHSId, RHSId; |
| 5073 | X->IgnoreParenImpCasts()->Profile(XId, SemaRef.getASTContext(), |
| 5074 | /*Canonical=*/true); |
| 5075 | LHS->IgnoreParenImpCasts()->Profile(LHSId, SemaRef.getASTContext(), |
| 5076 | /*Canonical=*/true); |
| 5077 | RHS->IgnoreParenImpCasts()->Profile(RHSId, SemaRef.getASTContext(), |
| 5078 | /*Canonical=*/true); |
| 5079 | if (XId == LHSId) { |
| 5080 | E = RHS; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5081 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5082 | } else if (XId == RHSId) { |
| 5083 | E = LHS; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5084 | IsXLHSInRHSPart = false; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5085 | } else { |
| 5086 | ErrorLoc = AtomicInnerBinOp->getExprLoc(); |
| 5087 | ErrorRange = AtomicInnerBinOp->getSourceRange(); |
| 5088 | NoteLoc = X->getExprLoc(); |
| 5089 | NoteRange = X->getSourceRange(); |
| 5090 | ErrorFound = NotAnUpdateExpression; |
| 5091 | } |
| 5092 | } else { |
| 5093 | ErrorLoc = AtomicInnerBinOp->getExprLoc(); |
| 5094 | ErrorRange = AtomicInnerBinOp->getSourceRange(); |
| 5095 | NoteLoc = AtomicInnerBinOp->getOperatorLoc(); |
| 5096 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 5097 | ErrorFound = NotABinaryOperator; |
| 5098 | } |
| 5099 | } else { |
| 5100 | NoteLoc = ErrorLoc = AtomicBinOp->getRHS()->getExprLoc(); |
| 5101 | NoteRange = ErrorRange = AtomicBinOp->getRHS()->getSourceRange(); |
| 5102 | ErrorFound = NotABinaryExpression; |
| 5103 | } |
| 5104 | } else { |
| 5105 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5106 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5107 | NoteLoc = AtomicBinOp->getOperatorLoc(); |
| 5108 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 5109 | ErrorFound = NotAnAssignmentOp; |
| 5110 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5111 | if (ErrorFound != NoError && DiagId != 0 && NoteId != 0) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5112 | SemaRef.Diag(ErrorLoc, DiagId) << ErrorRange; |
| 5113 | SemaRef.Diag(NoteLoc, NoteId) << ErrorFound << NoteRange; |
| 5114 | return true; |
| 5115 | } else if (SemaRef.CurContext->isDependentContext()) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5116 | E = X = UpdateExpr = nullptr; |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5117 | return ErrorFound != NoError; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5118 | } |
| 5119 | |
| 5120 | bool OpenMPAtomicUpdateChecker::checkStatement(Stmt *S, unsigned DiagId, |
| 5121 | unsigned NoteId) { |
| 5122 | ExprAnalysisErrorCode ErrorFound = NoError; |
| 5123 | SourceLocation ErrorLoc, NoteLoc; |
| 5124 | SourceRange ErrorRange, NoteRange; |
| 5125 | // Allowed constructs are: |
| 5126 | // x++; |
| 5127 | // x--; |
| 5128 | // ++x; |
| 5129 | // --x; |
| 5130 | // x binop= expr; |
| 5131 | // x = x binop expr; |
| 5132 | // x = expr binop x; |
| 5133 | if (auto *AtomicBody = dyn_cast<Expr>(S)) { |
| 5134 | AtomicBody = AtomicBody->IgnoreParenImpCasts(); |
| 5135 | if (AtomicBody->getType()->isScalarType() || |
| 5136 | AtomicBody->isInstantiationDependent()) { |
| 5137 | if (auto *AtomicCompAssignOp = dyn_cast<CompoundAssignOperator>( |
| 5138 | AtomicBody->IgnoreParenImpCasts())) { |
| 5139 | // Check for Compound Assignment Operation |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5140 | Op = BinaryOperator::getOpForCompoundAssignment( |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5141 | AtomicCompAssignOp->getOpcode()); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5142 | OpLoc = AtomicCompAssignOp->getOperatorLoc(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5143 | E = AtomicCompAssignOp->getRHS(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5144 | X = AtomicCompAssignOp->getLHS(); |
| 5145 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5146 | } else if (auto *AtomicBinOp = dyn_cast<BinaryOperator>( |
| 5147 | AtomicBody->IgnoreParenImpCasts())) { |
| 5148 | // Check for Binary Operation |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5149 | if(checkBinaryOperation(AtomicBinOp, DiagId, NoteId)) |
| 5150 | return true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5151 | } else if (auto *AtomicUnaryOp = |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5152 | dyn_cast<UnaryOperator>(AtomicBody->IgnoreParenImpCasts())) { |
| 5153 | // Check for Unary Operation |
| 5154 | if (AtomicUnaryOp->isIncrementDecrementOp()) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5155 | IsPostfixUpdate = AtomicUnaryOp->isPostfix(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5156 | Op = AtomicUnaryOp->isIncrementOp() ? BO_Add : BO_Sub; |
| 5157 | OpLoc = AtomicUnaryOp->getOperatorLoc(); |
| 5158 | X = AtomicUnaryOp->getSubExpr(); |
| 5159 | E = SemaRef.ActOnIntegerConstant(OpLoc, /*uint64_t Val=*/1).get(); |
| 5160 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5161 | } else { |
| 5162 | ErrorFound = NotAnUnaryIncDecExpression; |
| 5163 | ErrorLoc = AtomicUnaryOp->getExprLoc(); |
| 5164 | ErrorRange = AtomicUnaryOp->getSourceRange(); |
| 5165 | NoteLoc = AtomicUnaryOp->getOperatorLoc(); |
| 5166 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 5167 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5168 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5169 | ErrorFound = NotABinaryOrUnaryExpression; |
| 5170 | NoteLoc = ErrorLoc = AtomicBody->getExprLoc(); |
| 5171 | NoteRange = ErrorRange = AtomicBody->getSourceRange(); |
| 5172 | } |
| 5173 | } else { |
| 5174 | ErrorFound = NotAScalarType; |
| 5175 | NoteLoc = ErrorLoc = AtomicBody->getLocStart(); |
| 5176 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
| 5177 | } |
| 5178 | } else { |
| 5179 | ErrorFound = NotAnExpression; |
| 5180 | NoteLoc = ErrorLoc = S->getLocStart(); |
| 5181 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
| 5182 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5183 | if (ErrorFound != NoError && DiagId != 0 && NoteId != 0) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5184 | SemaRef.Diag(ErrorLoc, DiagId) << ErrorRange; |
| 5185 | SemaRef.Diag(NoteLoc, NoteId) << ErrorFound << NoteRange; |
| 5186 | return true; |
| 5187 | } else if (SemaRef.CurContext->isDependentContext()) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5188 | E = X = UpdateExpr = nullptr; |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5189 | if (ErrorFound == NoError && E && X) { |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5190 | // Build an update expression of form 'OpaqueValueExpr(x) binop |
| 5191 | // OpaqueValueExpr(expr)' or 'OpaqueValueExpr(expr) binop |
| 5192 | // OpaqueValueExpr(x)' and then cast it to the type of the 'x' expression. |
| 5193 | auto *OVEX = new (SemaRef.getASTContext()) |
| 5194 | OpaqueValueExpr(X->getExprLoc(), X->getType(), VK_RValue); |
| 5195 | auto *OVEExpr = new (SemaRef.getASTContext()) |
| 5196 | OpaqueValueExpr(E->getExprLoc(), E->getType(), VK_RValue); |
| 5197 | auto Update = |
| 5198 | SemaRef.CreateBuiltinBinOp(OpLoc, Op, IsXLHSInRHSPart ? OVEX : OVEExpr, |
| 5199 | IsXLHSInRHSPart ? OVEExpr : OVEX); |
| 5200 | if (Update.isInvalid()) |
| 5201 | return true; |
| 5202 | Update = SemaRef.PerformImplicitConversion(Update.get(), X->getType(), |
| 5203 | Sema::AA_Casting); |
| 5204 | if (Update.isInvalid()) |
| 5205 | return true; |
| 5206 | UpdateExpr = Update.get(); |
| 5207 | } |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5208 | return ErrorFound != NoError; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5209 | } |
| 5210 | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 5211 | StmtResult Sema::ActOnOpenMPAtomicDirective(ArrayRef<OMPClause *> Clauses, |
| 5212 | Stmt *AStmt, |
| 5213 | SourceLocation StartLoc, |
| 5214 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5215 | if (!AStmt) |
| 5216 | return StmtError(); |
| 5217 | |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5218 | auto CS = cast<CapturedStmt>(AStmt); |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 5219 | // 1.2.2 OpenMP Language Terminology |
| 5220 | // Structured block - An executable statement with a single entry at the |
| 5221 | // top and a single exit at the bottom. |
| 5222 | // The point of exit cannot be a branch out of the structured block. |
| 5223 | // longjmp() and throw() must not violate the entry/exit criteria. |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5224 | OpenMPClauseKind AtomicKind = OMPC_unknown; |
| 5225 | SourceLocation AtomicKindLoc; |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5226 | for (auto *C : Clauses) { |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5227 | if (C->getClauseKind() == OMPC_read || C->getClauseKind() == OMPC_write || |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5228 | C->getClauseKind() == OMPC_update || |
| 5229 | C->getClauseKind() == OMPC_capture) { |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5230 | if (AtomicKind != OMPC_unknown) { |
| 5231 | Diag(C->getLocStart(), diag::err_omp_atomic_several_clauses) |
| 5232 | << SourceRange(C->getLocStart(), C->getLocEnd()); |
| 5233 | Diag(AtomicKindLoc, diag::note_omp_atomic_previous_clause) |
| 5234 | << getOpenMPClauseName(AtomicKind); |
| 5235 | } else { |
| 5236 | AtomicKind = C->getClauseKind(); |
| 5237 | AtomicKindLoc = C->getLocStart(); |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5238 | } |
| 5239 | } |
| 5240 | } |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5241 | |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5242 | auto Body = CS->getCapturedStmt(); |
Alexey Bataev | 10fec57 | 2015-03-11 04:48:56 +0000 | [diff] [blame] | 5243 | if (auto *EWC = dyn_cast<ExprWithCleanups>(Body)) |
| 5244 | Body = EWC->getSubExpr(); |
| 5245 | |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5246 | Expr *X = nullptr; |
| 5247 | Expr *V = nullptr; |
| 5248 | Expr *E = nullptr; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5249 | Expr *UE = nullptr; |
| 5250 | bool IsXLHSInRHSPart = false; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5251 | bool IsPostfixUpdate = false; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5252 | // OpenMP [2.12.6, atomic Construct] |
| 5253 | // In the next expressions: |
| 5254 | // * x and v (as applicable) are both l-value expressions with scalar type. |
| 5255 | // * During the execution of an atomic region, multiple syntactic |
| 5256 | // occurrences of x must designate the same storage location. |
| 5257 | // * Neither of v and expr (as applicable) may access the storage location |
| 5258 | // designated by x. |
| 5259 | // * Neither of x and expr (as applicable) may access the storage location |
| 5260 | // designated by v. |
| 5261 | // * expr is an expression with scalar type. |
| 5262 | // * binop is one of +, *, -, /, &, ^, |, <<, or >>. |
| 5263 | // * binop, binop=, ++, and -- are not overloaded operators. |
| 5264 | // * The expression x binop expr must be numerically equivalent to x binop |
| 5265 | // (expr). This requirement is satisfied if the operators in expr have |
| 5266 | // precedence greater than binop, or by using parentheses around expr or |
| 5267 | // subexpressions of expr. |
| 5268 | // * The expression expr binop x must be numerically equivalent to (expr) |
| 5269 | // binop x. This requirement is satisfied if the operators in expr have |
| 5270 | // precedence equal to or greater than binop, or by using parentheses around |
| 5271 | // expr or subexpressions of expr. |
| 5272 | // * For forms that allow multiple occurrences of x, the number of times |
| 5273 | // that x is evaluated is unspecified. |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5274 | if (AtomicKind == OMPC_read) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5275 | enum { |
| 5276 | NotAnExpression, |
| 5277 | NotAnAssignmentOp, |
| 5278 | NotAScalarType, |
| 5279 | NotAnLValue, |
| 5280 | NoError |
| 5281 | } ErrorFound = NoError; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5282 | SourceLocation ErrorLoc, NoteLoc; |
| 5283 | SourceRange ErrorRange, NoteRange; |
| 5284 | // If clause is read: |
| 5285 | // v = x; |
| 5286 | if (auto AtomicBody = dyn_cast<Expr>(Body)) { |
| 5287 | auto AtomicBinOp = |
| 5288 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 5289 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
| 5290 | X = AtomicBinOp->getRHS()->IgnoreParenImpCasts(); |
| 5291 | V = AtomicBinOp->getLHS()->IgnoreParenImpCasts(); |
| 5292 | if ((X->isInstantiationDependent() || X->getType()->isScalarType()) && |
| 5293 | (V->isInstantiationDependent() || V->getType()->isScalarType())) { |
| 5294 | if (!X->isLValue() || !V->isLValue()) { |
| 5295 | auto NotLValueExpr = X->isLValue() ? V : X; |
| 5296 | ErrorFound = NotAnLValue; |
| 5297 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5298 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5299 | NoteLoc = NotLValueExpr->getExprLoc(); |
| 5300 | NoteRange = NotLValueExpr->getSourceRange(); |
| 5301 | } |
| 5302 | } else if (!X->isInstantiationDependent() || |
| 5303 | !V->isInstantiationDependent()) { |
| 5304 | auto NotScalarExpr = |
| 5305 | (X->isInstantiationDependent() || X->getType()->isScalarType()) |
| 5306 | ? V |
| 5307 | : X; |
| 5308 | ErrorFound = NotAScalarType; |
| 5309 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5310 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5311 | NoteLoc = NotScalarExpr->getExprLoc(); |
| 5312 | NoteRange = NotScalarExpr->getSourceRange(); |
| 5313 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5314 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5315 | ErrorFound = NotAnAssignmentOp; |
| 5316 | ErrorLoc = AtomicBody->getExprLoc(); |
| 5317 | ErrorRange = AtomicBody->getSourceRange(); |
| 5318 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 5319 | : AtomicBody->getExprLoc(); |
| 5320 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 5321 | : AtomicBody->getSourceRange(); |
| 5322 | } |
| 5323 | } else { |
| 5324 | ErrorFound = NotAnExpression; |
| 5325 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 5326 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5327 | } |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5328 | if (ErrorFound != NoError) { |
| 5329 | Diag(ErrorLoc, diag::err_omp_atomic_read_not_expression_statement) |
| 5330 | << ErrorRange; |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5331 | Diag(NoteLoc, diag::note_omp_atomic_read_write) << ErrorFound |
| 5332 | << NoteRange; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5333 | return StmtError(); |
| 5334 | } else if (CurContext->isDependentContext()) |
| 5335 | V = X = nullptr; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5336 | } else if (AtomicKind == OMPC_write) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5337 | enum { |
| 5338 | NotAnExpression, |
| 5339 | NotAnAssignmentOp, |
| 5340 | NotAScalarType, |
| 5341 | NotAnLValue, |
| 5342 | NoError |
| 5343 | } ErrorFound = NoError; |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5344 | SourceLocation ErrorLoc, NoteLoc; |
| 5345 | SourceRange ErrorRange, NoteRange; |
| 5346 | // If clause is write: |
| 5347 | // x = expr; |
| 5348 | if (auto AtomicBody = dyn_cast<Expr>(Body)) { |
| 5349 | auto AtomicBinOp = |
| 5350 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 5351 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
Alexey Bataev | b832926 | 2015-02-27 06:33:30 +0000 | [diff] [blame] | 5352 | X = AtomicBinOp->getLHS(); |
| 5353 | E = AtomicBinOp->getRHS(); |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5354 | if ((X->isInstantiationDependent() || X->getType()->isScalarType()) && |
| 5355 | (E->isInstantiationDependent() || E->getType()->isScalarType())) { |
| 5356 | if (!X->isLValue()) { |
| 5357 | ErrorFound = NotAnLValue; |
| 5358 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5359 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5360 | NoteLoc = X->getExprLoc(); |
| 5361 | NoteRange = X->getSourceRange(); |
| 5362 | } |
| 5363 | } else if (!X->isInstantiationDependent() || |
| 5364 | !E->isInstantiationDependent()) { |
| 5365 | auto NotScalarExpr = |
| 5366 | (X->isInstantiationDependent() || X->getType()->isScalarType()) |
| 5367 | ? E |
| 5368 | : X; |
| 5369 | ErrorFound = NotAScalarType; |
| 5370 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5371 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5372 | NoteLoc = NotScalarExpr->getExprLoc(); |
| 5373 | NoteRange = NotScalarExpr->getSourceRange(); |
| 5374 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5375 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5376 | ErrorFound = NotAnAssignmentOp; |
| 5377 | ErrorLoc = AtomicBody->getExprLoc(); |
| 5378 | ErrorRange = AtomicBody->getSourceRange(); |
| 5379 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 5380 | : AtomicBody->getExprLoc(); |
| 5381 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 5382 | : AtomicBody->getSourceRange(); |
| 5383 | } |
| 5384 | } else { |
| 5385 | ErrorFound = NotAnExpression; |
| 5386 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 5387 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5388 | } |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5389 | if (ErrorFound != NoError) { |
| 5390 | Diag(ErrorLoc, diag::err_omp_atomic_write_not_expression_statement) |
| 5391 | << ErrorRange; |
| 5392 | Diag(NoteLoc, diag::note_omp_atomic_read_write) << ErrorFound |
| 5393 | << NoteRange; |
| 5394 | return StmtError(); |
| 5395 | } else if (CurContext->isDependentContext()) |
| 5396 | E = X = nullptr; |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5397 | } else if (AtomicKind == OMPC_update || AtomicKind == OMPC_unknown) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5398 | // If clause is update: |
| 5399 | // x++; |
| 5400 | // x--; |
| 5401 | // ++x; |
| 5402 | // --x; |
| 5403 | // x binop= expr; |
| 5404 | // x = x binop expr; |
| 5405 | // x = expr binop x; |
| 5406 | OpenMPAtomicUpdateChecker Checker(*this); |
| 5407 | if (Checker.checkStatement( |
| 5408 | Body, (AtomicKind == OMPC_update) |
| 5409 | ? diag::err_omp_atomic_update_not_expression_statement |
| 5410 | : diag::err_omp_atomic_not_expression_statement, |
| 5411 | diag::note_omp_atomic_update)) |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5412 | return StmtError(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5413 | if (!CurContext->isDependentContext()) { |
| 5414 | E = Checker.getExpr(); |
| 5415 | X = Checker.getX(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5416 | UE = Checker.getUpdateExpr(); |
| 5417 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5418 | } |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5419 | } else if (AtomicKind == OMPC_capture) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5420 | enum { |
| 5421 | NotAnAssignmentOp, |
| 5422 | NotACompoundStatement, |
| 5423 | NotTwoSubstatements, |
| 5424 | NotASpecificExpression, |
| 5425 | NoError |
| 5426 | } ErrorFound = NoError; |
| 5427 | SourceLocation ErrorLoc, NoteLoc; |
| 5428 | SourceRange ErrorRange, NoteRange; |
| 5429 | if (auto *AtomicBody = dyn_cast<Expr>(Body)) { |
| 5430 | // If clause is a capture: |
| 5431 | // v = x++; |
| 5432 | // v = x--; |
| 5433 | // v = ++x; |
| 5434 | // v = --x; |
| 5435 | // v = x binop= expr; |
| 5436 | // v = x = x binop expr; |
| 5437 | // v = x = expr binop x; |
| 5438 | auto *AtomicBinOp = |
| 5439 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 5440 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
| 5441 | V = AtomicBinOp->getLHS(); |
| 5442 | Body = AtomicBinOp->getRHS()->IgnoreParenImpCasts(); |
| 5443 | OpenMPAtomicUpdateChecker Checker(*this); |
| 5444 | if (Checker.checkStatement( |
| 5445 | Body, diag::err_omp_atomic_capture_not_expression_statement, |
| 5446 | diag::note_omp_atomic_update)) |
| 5447 | return StmtError(); |
| 5448 | E = Checker.getExpr(); |
| 5449 | X = Checker.getX(); |
| 5450 | UE = Checker.getUpdateExpr(); |
| 5451 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
| 5452 | IsPostfixUpdate = Checker.isPostfixUpdate(); |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5453 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5454 | ErrorLoc = AtomicBody->getExprLoc(); |
| 5455 | ErrorRange = AtomicBody->getSourceRange(); |
| 5456 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 5457 | : AtomicBody->getExprLoc(); |
| 5458 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 5459 | : AtomicBody->getSourceRange(); |
| 5460 | ErrorFound = NotAnAssignmentOp; |
| 5461 | } |
| 5462 | if (ErrorFound != NoError) { |
| 5463 | Diag(ErrorLoc, diag::err_omp_atomic_capture_not_expression_statement) |
| 5464 | << ErrorRange; |
| 5465 | Diag(NoteLoc, diag::note_omp_atomic_capture) << ErrorFound << NoteRange; |
| 5466 | return StmtError(); |
| 5467 | } else if (CurContext->isDependentContext()) { |
| 5468 | UE = V = E = X = nullptr; |
| 5469 | } |
| 5470 | } else { |
| 5471 | // If clause is a capture: |
| 5472 | // { v = x; x = expr; } |
| 5473 | // { v = x; x++; } |
| 5474 | // { v = x; x--; } |
| 5475 | // { v = x; ++x; } |
| 5476 | // { v = x; --x; } |
| 5477 | // { v = x; x binop= expr; } |
| 5478 | // { v = x; x = x binop expr; } |
| 5479 | // { v = x; x = expr binop x; } |
| 5480 | // { x++; v = x; } |
| 5481 | // { x--; v = x; } |
| 5482 | // { ++x; v = x; } |
| 5483 | // { --x; v = x; } |
| 5484 | // { x binop= expr; v = x; } |
| 5485 | // { x = x binop expr; v = x; } |
| 5486 | // { x = expr binop x; v = x; } |
| 5487 | if (auto *CS = dyn_cast<CompoundStmt>(Body)) { |
| 5488 | // Check that this is { expr1; expr2; } |
| 5489 | if (CS->size() == 2) { |
| 5490 | auto *First = CS->body_front(); |
| 5491 | auto *Second = CS->body_back(); |
| 5492 | if (auto *EWC = dyn_cast<ExprWithCleanups>(First)) |
| 5493 | First = EWC->getSubExpr()->IgnoreParenImpCasts(); |
| 5494 | if (auto *EWC = dyn_cast<ExprWithCleanups>(Second)) |
| 5495 | Second = EWC->getSubExpr()->IgnoreParenImpCasts(); |
| 5496 | // Need to find what subexpression is 'v' and what is 'x'. |
| 5497 | OpenMPAtomicUpdateChecker Checker(*this); |
| 5498 | bool IsUpdateExprFound = !Checker.checkStatement(Second); |
| 5499 | BinaryOperator *BinOp = nullptr; |
| 5500 | if (IsUpdateExprFound) { |
| 5501 | BinOp = dyn_cast<BinaryOperator>(First); |
| 5502 | IsUpdateExprFound = BinOp && BinOp->getOpcode() == BO_Assign; |
| 5503 | } |
| 5504 | if (IsUpdateExprFound && !CurContext->isDependentContext()) { |
| 5505 | // { v = x; x++; } |
| 5506 | // { v = x; x--; } |
| 5507 | // { v = x; ++x; } |
| 5508 | // { v = x; --x; } |
| 5509 | // { v = x; x binop= expr; } |
| 5510 | // { v = x; x = x binop expr; } |
| 5511 | // { v = x; x = expr binop x; } |
| 5512 | // Check that the first expression has form v = x. |
| 5513 | auto *PossibleX = BinOp->getRHS()->IgnoreParenImpCasts(); |
| 5514 | llvm::FoldingSetNodeID XId, PossibleXId; |
| 5515 | Checker.getX()->Profile(XId, Context, /*Canonical=*/true); |
| 5516 | PossibleX->Profile(PossibleXId, Context, /*Canonical=*/true); |
| 5517 | IsUpdateExprFound = XId == PossibleXId; |
| 5518 | if (IsUpdateExprFound) { |
| 5519 | V = BinOp->getLHS(); |
| 5520 | X = Checker.getX(); |
| 5521 | E = Checker.getExpr(); |
| 5522 | UE = Checker.getUpdateExpr(); |
| 5523 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5524 | IsPostfixUpdate = true; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5525 | } |
| 5526 | } |
| 5527 | if (!IsUpdateExprFound) { |
| 5528 | IsUpdateExprFound = !Checker.checkStatement(First); |
| 5529 | BinOp = nullptr; |
| 5530 | if (IsUpdateExprFound) { |
| 5531 | BinOp = dyn_cast<BinaryOperator>(Second); |
| 5532 | IsUpdateExprFound = BinOp && BinOp->getOpcode() == BO_Assign; |
| 5533 | } |
| 5534 | if (IsUpdateExprFound && !CurContext->isDependentContext()) { |
| 5535 | // { x++; v = x; } |
| 5536 | // { x--; v = x; } |
| 5537 | // { ++x; v = x; } |
| 5538 | // { --x; v = x; } |
| 5539 | // { x binop= expr; v = x; } |
| 5540 | // { x = x binop expr; v = x; } |
| 5541 | // { x = expr binop x; v = x; } |
| 5542 | // Check that the second expression has form v = x. |
| 5543 | auto *PossibleX = BinOp->getRHS()->IgnoreParenImpCasts(); |
| 5544 | llvm::FoldingSetNodeID XId, PossibleXId; |
| 5545 | Checker.getX()->Profile(XId, Context, /*Canonical=*/true); |
| 5546 | PossibleX->Profile(PossibleXId, Context, /*Canonical=*/true); |
| 5547 | IsUpdateExprFound = XId == PossibleXId; |
| 5548 | if (IsUpdateExprFound) { |
| 5549 | V = BinOp->getLHS(); |
| 5550 | X = Checker.getX(); |
| 5551 | E = Checker.getExpr(); |
| 5552 | UE = Checker.getUpdateExpr(); |
| 5553 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5554 | IsPostfixUpdate = false; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5555 | } |
| 5556 | } |
| 5557 | } |
| 5558 | if (!IsUpdateExprFound) { |
| 5559 | // { v = x; x = expr; } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5560 | auto *FirstExpr = dyn_cast<Expr>(First); |
| 5561 | auto *SecondExpr = dyn_cast<Expr>(Second); |
| 5562 | if (!FirstExpr || !SecondExpr || |
| 5563 | !(FirstExpr->isInstantiationDependent() || |
| 5564 | SecondExpr->isInstantiationDependent())) { |
| 5565 | auto *FirstBinOp = dyn_cast<BinaryOperator>(First); |
| 5566 | if (!FirstBinOp || FirstBinOp->getOpcode() != BO_Assign) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5567 | ErrorFound = NotAnAssignmentOp; |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5568 | NoteLoc = ErrorLoc = FirstBinOp ? FirstBinOp->getOperatorLoc() |
| 5569 | : First->getLocStart(); |
| 5570 | NoteRange = ErrorRange = FirstBinOp |
| 5571 | ? FirstBinOp->getSourceRange() |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5572 | : SourceRange(ErrorLoc, ErrorLoc); |
| 5573 | } else { |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5574 | auto *SecondBinOp = dyn_cast<BinaryOperator>(Second); |
| 5575 | if (!SecondBinOp || SecondBinOp->getOpcode() != BO_Assign) { |
| 5576 | ErrorFound = NotAnAssignmentOp; |
| 5577 | NoteLoc = ErrorLoc = SecondBinOp |
| 5578 | ? SecondBinOp->getOperatorLoc() |
| 5579 | : Second->getLocStart(); |
| 5580 | NoteRange = ErrorRange = |
| 5581 | SecondBinOp ? SecondBinOp->getSourceRange() |
| 5582 | : SourceRange(ErrorLoc, ErrorLoc); |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5583 | } else { |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5584 | auto *PossibleXRHSInFirst = |
| 5585 | FirstBinOp->getRHS()->IgnoreParenImpCasts(); |
| 5586 | auto *PossibleXLHSInSecond = |
| 5587 | SecondBinOp->getLHS()->IgnoreParenImpCasts(); |
| 5588 | llvm::FoldingSetNodeID X1Id, X2Id; |
| 5589 | PossibleXRHSInFirst->Profile(X1Id, Context, |
| 5590 | /*Canonical=*/true); |
| 5591 | PossibleXLHSInSecond->Profile(X2Id, Context, |
| 5592 | /*Canonical=*/true); |
| 5593 | IsUpdateExprFound = X1Id == X2Id; |
| 5594 | if (IsUpdateExprFound) { |
| 5595 | V = FirstBinOp->getLHS(); |
| 5596 | X = SecondBinOp->getLHS(); |
| 5597 | E = SecondBinOp->getRHS(); |
| 5598 | UE = nullptr; |
| 5599 | IsXLHSInRHSPart = false; |
| 5600 | IsPostfixUpdate = true; |
| 5601 | } else { |
| 5602 | ErrorFound = NotASpecificExpression; |
| 5603 | ErrorLoc = FirstBinOp->getExprLoc(); |
| 5604 | ErrorRange = FirstBinOp->getSourceRange(); |
| 5605 | NoteLoc = SecondBinOp->getLHS()->getExprLoc(); |
| 5606 | NoteRange = SecondBinOp->getRHS()->getSourceRange(); |
| 5607 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5608 | } |
| 5609 | } |
| 5610 | } |
| 5611 | } |
| 5612 | } else { |
| 5613 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 5614 | NoteRange = ErrorRange = |
| 5615 | SourceRange(Body->getLocStart(), Body->getLocStart()); |
| 5616 | ErrorFound = NotTwoSubstatements; |
| 5617 | } |
| 5618 | } else { |
| 5619 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 5620 | NoteRange = ErrorRange = |
| 5621 | SourceRange(Body->getLocStart(), Body->getLocStart()); |
| 5622 | ErrorFound = NotACompoundStatement; |
| 5623 | } |
| 5624 | if (ErrorFound != NoError) { |
| 5625 | Diag(ErrorLoc, diag::err_omp_atomic_capture_not_compound_statement) |
| 5626 | << ErrorRange; |
| 5627 | Diag(NoteLoc, diag::note_omp_atomic_capture) << ErrorFound << NoteRange; |
| 5628 | return StmtError(); |
| 5629 | } else if (CurContext->isDependentContext()) { |
| 5630 | UE = V = E = X = nullptr; |
| 5631 | } |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5632 | } |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5633 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 5634 | |
| 5635 | getCurFunction()->setHasBranchProtectedScope(); |
| 5636 | |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5637 | return OMPAtomicDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5638 | X, V, E, UE, IsXLHSInRHSPart, |
| 5639 | IsPostfixUpdate); |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 5640 | } |
| 5641 | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 5642 | StmtResult Sema::ActOnOpenMPTargetDirective(ArrayRef<OMPClause *> Clauses, |
| 5643 | Stmt *AStmt, |
| 5644 | SourceLocation StartLoc, |
| 5645 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5646 | if (!AStmt) |
| 5647 | return StmtError(); |
| 5648 | |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 5649 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 5650 | // 1.2.2 OpenMP Language Terminology |
| 5651 | // Structured block - An executable statement with a single entry at the |
| 5652 | // top and a single exit at the bottom. |
| 5653 | // The point of exit cannot be a branch out of the structured block. |
| 5654 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5655 | CS->getCapturedDecl()->setNothrow(); |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 5656 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 5657 | // OpenMP [2.16, Nesting of Regions] |
| 5658 | // If specified, a teams construct must be contained within a target |
| 5659 | // construct. That target construct must contain no statements or directives |
| 5660 | // outside of the teams construct. |
| 5661 | if (DSAStack->hasInnerTeamsRegion()) { |
| 5662 | auto S = AStmt->IgnoreContainers(/*IgnoreCaptured*/ true); |
| 5663 | bool OMPTeamsFound = true; |
| 5664 | if (auto *CS = dyn_cast<CompoundStmt>(S)) { |
| 5665 | auto I = CS->body_begin(); |
| 5666 | while (I != CS->body_end()) { |
| 5667 | auto OED = dyn_cast<OMPExecutableDirective>(*I); |
| 5668 | if (!OED || !isOpenMPTeamsDirective(OED->getDirectiveKind())) { |
| 5669 | OMPTeamsFound = false; |
| 5670 | break; |
| 5671 | } |
| 5672 | ++I; |
| 5673 | } |
| 5674 | assert(I != CS->body_end() && "Not found statement"); |
| 5675 | S = *I; |
| 5676 | } |
| 5677 | if (!OMPTeamsFound) { |
| 5678 | Diag(StartLoc, diag::err_omp_target_contains_not_only_teams); |
| 5679 | Diag(DSAStack->getInnerTeamsRegionLoc(), |
| 5680 | diag::note_omp_nested_teams_construct_here); |
| 5681 | Diag(S->getLocStart(), diag::note_omp_nested_statement_here) |
| 5682 | << isa<OMPExecutableDirective>(S); |
| 5683 | return StmtError(); |
| 5684 | } |
| 5685 | } |
| 5686 | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 5687 | getCurFunction()->setHasBranchProtectedScope(); |
| 5688 | |
| 5689 | return OMPTargetDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 5690 | } |
| 5691 | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 5692 | StmtResult |
| 5693 | Sema::ActOnOpenMPTargetParallelDirective(ArrayRef<OMPClause *> Clauses, |
| 5694 | Stmt *AStmt, SourceLocation StartLoc, |
| 5695 | SourceLocation EndLoc) { |
| 5696 | if (!AStmt) |
| 5697 | return StmtError(); |
| 5698 | |
| 5699 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 5700 | // 1.2.2 OpenMP Language Terminology |
| 5701 | // Structured block - An executable statement with a single entry at the |
| 5702 | // top and a single exit at the bottom. |
| 5703 | // The point of exit cannot be a branch out of the structured block. |
| 5704 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5705 | CS->getCapturedDecl()->setNothrow(); |
| 5706 | |
| 5707 | getCurFunction()->setHasBranchProtectedScope(); |
| 5708 | |
| 5709 | return OMPTargetParallelDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 5710 | AStmt); |
| 5711 | } |
| 5712 | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 5713 | /// \brief Check for existence of a map clause in the list of clauses. |
| 5714 | static bool HasMapClause(ArrayRef<OMPClause *> Clauses) { |
| 5715 | for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end(); |
| 5716 | I != E; ++I) { |
| 5717 | if (*I != nullptr && (*I)->getClauseKind() == OMPC_map) { |
| 5718 | return true; |
| 5719 | } |
| 5720 | } |
| 5721 | |
| 5722 | return false; |
| 5723 | } |
| 5724 | |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 5725 | StmtResult Sema::ActOnOpenMPTargetDataDirective(ArrayRef<OMPClause *> Clauses, |
| 5726 | Stmt *AStmt, |
| 5727 | SourceLocation StartLoc, |
| 5728 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5729 | if (!AStmt) |
| 5730 | return StmtError(); |
| 5731 | |
| 5732 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 5733 | |
Arpith Chacko Jacob | 46a04bb | 2016-01-21 19:57:55 +0000 | [diff] [blame] | 5734 | // OpenMP [2.10.1, Restrictions, p. 97] |
| 5735 | // At least one map clause must appear on the directive. |
| 5736 | if (!HasMapClause(Clauses)) { |
| 5737 | Diag(StartLoc, diag::err_omp_no_map_for_directive) << |
| 5738 | getOpenMPDirectiveName(OMPD_target_data); |
| 5739 | return StmtError(); |
| 5740 | } |
| 5741 | |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 5742 | getCurFunction()->setHasBranchProtectedScope(); |
| 5743 | |
| 5744 | return OMPTargetDataDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 5745 | AStmt); |
| 5746 | } |
| 5747 | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 5748 | StmtResult |
| 5749 | Sema::ActOnOpenMPTargetEnterDataDirective(ArrayRef<OMPClause *> Clauses, |
| 5750 | SourceLocation StartLoc, |
| 5751 | SourceLocation EndLoc) { |
| 5752 | // OpenMP [2.10.2, Restrictions, p. 99] |
| 5753 | // At least one map clause must appear on the directive. |
| 5754 | if (!HasMapClause(Clauses)) { |
| 5755 | Diag(StartLoc, diag::err_omp_no_map_for_directive) |
| 5756 | << getOpenMPDirectiveName(OMPD_target_enter_data); |
| 5757 | return StmtError(); |
| 5758 | } |
| 5759 | |
| 5760 | return OMPTargetEnterDataDirective::Create(Context, StartLoc, EndLoc, |
| 5761 | Clauses); |
| 5762 | } |
| 5763 | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 5764 | StmtResult |
| 5765 | Sema::ActOnOpenMPTargetExitDataDirective(ArrayRef<OMPClause *> Clauses, |
| 5766 | SourceLocation StartLoc, |
| 5767 | SourceLocation EndLoc) { |
| 5768 | // OpenMP [2.10.3, Restrictions, p. 102] |
| 5769 | // At least one map clause must appear on the directive. |
| 5770 | if (!HasMapClause(Clauses)) { |
| 5771 | Diag(StartLoc, diag::err_omp_no_map_for_directive) |
| 5772 | << getOpenMPDirectiveName(OMPD_target_exit_data); |
| 5773 | return StmtError(); |
| 5774 | } |
| 5775 | |
| 5776 | return OMPTargetExitDataDirective::Create(Context, StartLoc, EndLoc, Clauses); |
| 5777 | } |
| 5778 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 5779 | StmtResult Sema::ActOnOpenMPTeamsDirective(ArrayRef<OMPClause *> Clauses, |
| 5780 | Stmt *AStmt, SourceLocation StartLoc, |
| 5781 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5782 | if (!AStmt) |
| 5783 | return StmtError(); |
| 5784 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 5785 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 5786 | // 1.2.2 OpenMP Language Terminology |
| 5787 | // Structured block - An executable statement with a single entry at the |
| 5788 | // top and a single exit at the bottom. |
| 5789 | // The point of exit cannot be a branch out of the structured block. |
| 5790 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5791 | CS->getCapturedDecl()->setNothrow(); |
| 5792 | |
| 5793 | getCurFunction()->setHasBranchProtectedScope(); |
| 5794 | |
| 5795 | return OMPTeamsDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 5796 | } |
| 5797 | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 5798 | StmtResult |
| 5799 | Sema::ActOnOpenMPCancellationPointDirective(SourceLocation StartLoc, |
| 5800 | SourceLocation EndLoc, |
| 5801 | OpenMPDirectiveKind CancelRegion) { |
| 5802 | if (CancelRegion != OMPD_parallel && CancelRegion != OMPD_for && |
| 5803 | CancelRegion != OMPD_sections && CancelRegion != OMPD_taskgroup) { |
| 5804 | Diag(StartLoc, diag::err_omp_wrong_cancel_region) |
| 5805 | << getOpenMPDirectiveName(CancelRegion); |
| 5806 | return StmtError(); |
| 5807 | } |
| 5808 | if (DSAStack->isParentNowaitRegion()) { |
| 5809 | Diag(StartLoc, diag::err_omp_parent_cancel_region_nowait) << 0; |
| 5810 | return StmtError(); |
| 5811 | } |
| 5812 | if (DSAStack->isParentOrderedRegion()) { |
| 5813 | Diag(StartLoc, diag::err_omp_parent_cancel_region_ordered) << 0; |
| 5814 | return StmtError(); |
| 5815 | } |
| 5816 | return OMPCancellationPointDirective::Create(Context, StartLoc, EndLoc, |
| 5817 | CancelRegion); |
| 5818 | } |
| 5819 | |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 5820 | StmtResult Sema::ActOnOpenMPCancelDirective(ArrayRef<OMPClause *> Clauses, |
| 5821 | SourceLocation StartLoc, |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 5822 | SourceLocation EndLoc, |
| 5823 | OpenMPDirectiveKind CancelRegion) { |
| 5824 | if (CancelRegion != OMPD_parallel && CancelRegion != OMPD_for && |
| 5825 | CancelRegion != OMPD_sections && CancelRegion != OMPD_taskgroup) { |
| 5826 | Diag(StartLoc, diag::err_omp_wrong_cancel_region) |
| 5827 | << getOpenMPDirectiveName(CancelRegion); |
| 5828 | return StmtError(); |
| 5829 | } |
| 5830 | if (DSAStack->isParentNowaitRegion()) { |
| 5831 | Diag(StartLoc, diag::err_omp_parent_cancel_region_nowait) << 1; |
| 5832 | return StmtError(); |
| 5833 | } |
| 5834 | if (DSAStack->isParentOrderedRegion()) { |
| 5835 | Diag(StartLoc, diag::err_omp_parent_cancel_region_ordered) << 1; |
| 5836 | return StmtError(); |
| 5837 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 5838 | DSAStack->setParentCancelRegion(/*Cancel=*/true); |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 5839 | return OMPCancelDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 5840 | CancelRegion); |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 5841 | } |
| 5842 | |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 5843 | static bool checkGrainsizeNumTasksClauses(Sema &S, |
| 5844 | ArrayRef<OMPClause *> Clauses) { |
| 5845 | OMPClause *PrevClause = nullptr; |
| 5846 | bool ErrorFound = false; |
| 5847 | for (auto *C : Clauses) { |
| 5848 | if (C->getClauseKind() == OMPC_grainsize || |
| 5849 | C->getClauseKind() == OMPC_num_tasks) { |
| 5850 | if (!PrevClause) |
| 5851 | PrevClause = C; |
| 5852 | else if (PrevClause->getClauseKind() != C->getClauseKind()) { |
| 5853 | S.Diag(C->getLocStart(), |
| 5854 | diag::err_omp_grainsize_num_tasks_mutually_exclusive) |
| 5855 | << getOpenMPClauseName(C->getClauseKind()) |
| 5856 | << getOpenMPClauseName(PrevClause->getClauseKind()); |
| 5857 | S.Diag(PrevClause->getLocStart(), |
| 5858 | diag::note_omp_previous_grainsize_num_tasks) |
| 5859 | << getOpenMPClauseName(PrevClause->getClauseKind()); |
| 5860 | ErrorFound = true; |
| 5861 | } |
| 5862 | } |
| 5863 | } |
| 5864 | return ErrorFound; |
| 5865 | } |
| 5866 | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 5867 | StmtResult Sema::ActOnOpenMPTaskLoopDirective( |
| 5868 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 5869 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 5870 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 5871 | if (!AStmt) |
| 5872 | return StmtError(); |
| 5873 | |
| 5874 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 5875 | OMPLoopDirective::HelperExprs B; |
| 5876 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 5877 | // define the nested loops number. |
| 5878 | unsigned NestedLoopCount = |
| 5879 | CheckOpenMPLoop(OMPD_taskloop, getCollapseNumberExpr(Clauses), |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 5880 | /*OrderedLoopCountExpr=*/nullptr, AStmt, *this, *DSAStack, |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 5881 | VarsWithImplicitDSA, B); |
| 5882 | if (NestedLoopCount == 0) |
| 5883 | return StmtError(); |
| 5884 | |
| 5885 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 5886 | "omp for loop exprs were not built"); |
| 5887 | |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 5888 | // OpenMP, [2.9.2 taskloop Construct, Restrictions] |
| 5889 | // The grainsize clause and num_tasks clause are mutually exclusive and may |
| 5890 | // not appear on the same taskloop directive. |
| 5891 | if (checkGrainsizeNumTasksClauses(*this, Clauses)) |
| 5892 | return StmtError(); |
| 5893 | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 5894 | getCurFunction()->setHasBranchProtectedScope(); |
| 5895 | return OMPTaskLoopDirective::Create(Context, StartLoc, EndLoc, |
| 5896 | NestedLoopCount, Clauses, AStmt, B); |
| 5897 | } |
| 5898 | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 5899 | StmtResult Sema::ActOnOpenMPTaskLoopSimdDirective( |
| 5900 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 5901 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 5902 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 5903 | if (!AStmt) |
| 5904 | return StmtError(); |
| 5905 | |
| 5906 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 5907 | OMPLoopDirective::HelperExprs B; |
| 5908 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 5909 | // define the nested loops number. |
| 5910 | unsigned NestedLoopCount = |
| 5911 | CheckOpenMPLoop(OMPD_taskloop_simd, getCollapseNumberExpr(Clauses), |
| 5912 | /*OrderedLoopCountExpr=*/nullptr, AStmt, *this, *DSAStack, |
| 5913 | VarsWithImplicitDSA, B); |
| 5914 | if (NestedLoopCount == 0) |
| 5915 | return StmtError(); |
| 5916 | |
| 5917 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 5918 | "omp for loop exprs were not built"); |
| 5919 | |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 5920 | // OpenMP, [2.9.2 taskloop Construct, Restrictions] |
| 5921 | // The grainsize clause and num_tasks clause are mutually exclusive and may |
| 5922 | // not appear on the same taskloop directive. |
| 5923 | if (checkGrainsizeNumTasksClauses(*this, Clauses)) |
| 5924 | return StmtError(); |
| 5925 | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 5926 | getCurFunction()->setHasBranchProtectedScope(); |
| 5927 | return OMPTaskLoopSimdDirective::Create(Context, StartLoc, EndLoc, |
| 5928 | NestedLoopCount, Clauses, AStmt, B); |
| 5929 | } |
| 5930 | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 5931 | StmtResult Sema::ActOnOpenMPDistributeDirective( |
| 5932 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 5933 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 5934 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 5935 | if (!AStmt) |
| 5936 | return StmtError(); |
| 5937 | |
| 5938 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 5939 | OMPLoopDirective::HelperExprs B; |
| 5940 | // In presence of clause 'collapse' with number of loops, it will |
| 5941 | // define the nested loops number. |
| 5942 | unsigned NestedLoopCount = |
| 5943 | CheckOpenMPLoop(OMPD_distribute, getCollapseNumberExpr(Clauses), |
| 5944 | nullptr /*ordered not a clause on distribute*/, AStmt, |
| 5945 | *this, *DSAStack, VarsWithImplicitDSA, B); |
| 5946 | if (NestedLoopCount == 0) |
| 5947 | return StmtError(); |
| 5948 | |
| 5949 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 5950 | "omp for loop exprs were not built"); |
| 5951 | |
| 5952 | getCurFunction()->setHasBranchProtectedScope(); |
| 5953 | return OMPDistributeDirective::Create(Context, StartLoc, EndLoc, |
| 5954 | NestedLoopCount, Clauses, AStmt, B); |
| 5955 | } |
| 5956 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5957 | OMPClause *Sema::ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, Expr *Expr, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5958 | SourceLocation StartLoc, |
| 5959 | SourceLocation LParenLoc, |
| 5960 | SourceLocation EndLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 5961 | OMPClause *Res = nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5962 | switch (Kind) { |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 5963 | case OMPC_final: |
| 5964 | Res = ActOnOpenMPFinalClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5965 | break; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5966 | case OMPC_num_threads: |
| 5967 | Res = ActOnOpenMPNumThreadsClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5968 | break; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5969 | case OMPC_safelen: |
| 5970 | Res = ActOnOpenMPSafelenClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5971 | break; |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 5972 | case OMPC_simdlen: |
| 5973 | Res = ActOnOpenMPSimdlenClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5974 | break; |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 5975 | case OMPC_collapse: |
| 5976 | Res = ActOnOpenMPCollapseClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5977 | break; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5978 | case OMPC_ordered: |
| 5979 | Res = ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Expr); |
| 5980 | break; |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 5981 | case OMPC_device: |
| 5982 | Res = ActOnOpenMPDeviceClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5983 | break; |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 5984 | case OMPC_num_teams: |
| 5985 | Res = ActOnOpenMPNumTeamsClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5986 | break; |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 5987 | case OMPC_thread_limit: |
| 5988 | Res = ActOnOpenMPThreadLimitClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5989 | break; |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 5990 | case OMPC_priority: |
| 5991 | Res = ActOnOpenMPPriorityClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5992 | break; |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 5993 | case OMPC_grainsize: |
| 5994 | Res = ActOnOpenMPGrainsizeClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5995 | break; |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 5996 | case OMPC_num_tasks: |
| 5997 | Res = ActOnOpenMPNumTasksClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5998 | break; |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 5999 | case OMPC_hint: |
| 6000 | Res = ActOnOpenMPHintClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6001 | break; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6002 | case OMPC_if: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6003 | case OMPC_default: |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6004 | case OMPC_proc_bind: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6005 | case OMPC_schedule: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6006 | case OMPC_private: |
| 6007 | case OMPC_firstprivate: |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6008 | case OMPC_lastprivate: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6009 | case OMPC_shared: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6010 | case OMPC_reduction: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6011 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 6012 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6013 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6014 | case OMPC_copyprivate: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6015 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 6016 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 6017 | case OMPC_mergeable: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6018 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 6019 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6020 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6021 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6022 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6023 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 6024 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6025 | case OMPC_depend: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6026 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6027 | case OMPC_simd: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 6028 | case OMPC_map: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 6029 | case OMPC_nogroup: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 6030 | case OMPC_dist_schedule: |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 6031 | case OMPC_defaultmap: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6032 | case OMPC_unknown: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6033 | llvm_unreachable("Clause is not allowed."); |
| 6034 | } |
| 6035 | return Res; |
| 6036 | } |
| 6037 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6038 | OMPClause *Sema::ActOnOpenMPIfClause(OpenMPDirectiveKind NameModifier, |
| 6039 | Expr *Condition, SourceLocation StartLoc, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6040 | SourceLocation LParenLoc, |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6041 | SourceLocation NameModifierLoc, |
| 6042 | SourceLocation ColonLoc, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6043 | SourceLocation EndLoc) { |
| 6044 | Expr *ValExpr = Condition; |
| 6045 | if (!Condition->isValueDependent() && !Condition->isTypeDependent() && |
| 6046 | !Condition->isInstantiationDependent() && |
| 6047 | !Condition->containsUnexpandedParameterPack()) { |
| 6048 | ExprResult Val = ActOnBooleanCondition(DSAStack->getCurScope(), |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6049 | Condition->getExprLoc(), Condition); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6050 | if (Val.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6051 | return nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6052 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6053 | ValExpr = Val.get(); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6054 | } |
| 6055 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6056 | return new (Context) OMPIfClause(NameModifier, ValExpr, StartLoc, LParenLoc, |
| 6057 | NameModifierLoc, ColonLoc, EndLoc); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6058 | } |
| 6059 | |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 6060 | OMPClause *Sema::ActOnOpenMPFinalClause(Expr *Condition, |
| 6061 | SourceLocation StartLoc, |
| 6062 | SourceLocation LParenLoc, |
| 6063 | SourceLocation EndLoc) { |
| 6064 | Expr *ValExpr = Condition; |
| 6065 | if (!Condition->isValueDependent() && !Condition->isTypeDependent() && |
| 6066 | !Condition->isInstantiationDependent() && |
| 6067 | !Condition->containsUnexpandedParameterPack()) { |
| 6068 | ExprResult Val = ActOnBooleanCondition(DSAStack->getCurScope(), |
| 6069 | Condition->getExprLoc(), Condition); |
| 6070 | if (Val.isInvalid()) |
| 6071 | return nullptr; |
| 6072 | |
| 6073 | ValExpr = Val.get(); |
| 6074 | } |
| 6075 | |
| 6076 | return new (Context) OMPFinalClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 6077 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 6078 | ExprResult Sema::PerformOpenMPImplicitIntegerConversion(SourceLocation Loc, |
| 6079 | Expr *Op) { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6080 | if (!Op) |
| 6081 | return ExprError(); |
| 6082 | |
| 6083 | class IntConvertDiagnoser : public ICEConvertDiagnoser { |
| 6084 | public: |
| 6085 | IntConvertDiagnoser() |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6086 | : ICEConvertDiagnoser(/*AllowScopedEnumerations*/ false, false, true) {} |
Craig Topper | e14c0f8 | 2014-03-12 04:55:44 +0000 | [diff] [blame] | 6087 | SemaDiagnosticBuilder diagnoseNotInt(Sema &S, SourceLocation Loc, |
| 6088 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6089 | return S.Diag(Loc, diag::err_omp_not_integral) << T; |
| 6090 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6091 | SemaDiagnosticBuilder diagnoseIncomplete(Sema &S, SourceLocation Loc, |
| 6092 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6093 | return S.Diag(Loc, diag::err_omp_incomplete_type) << T; |
| 6094 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6095 | SemaDiagnosticBuilder diagnoseExplicitConv(Sema &S, SourceLocation Loc, |
| 6096 | QualType T, |
| 6097 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6098 | return S.Diag(Loc, diag::err_omp_explicit_conversion) << T << ConvTy; |
| 6099 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6100 | SemaDiagnosticBuilder noteExplicitConv(Sema &S, CXXConversionDecl *Conv, |
| 6101 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6102 | return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6103 | << ConvTy->isEnumeralType() << ConvTy; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6104 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6105 | SemaDiagnosticBuilder diagnoseAmbiguous(Sema &S, SourceLocation Loc, |
| 6106 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6107 | return S.Diag(Loc, diag::err_omp_ambiguous_conversion) << T; |
| 6108 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6109 | SemaDiagnosticBuilder noteAmbiguous(Sema &S, CXXConversionDecl *Conv, |
| 6110 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6111 | return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6112 | << ConvTy->isEnumeralType() << ConvTy; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6113 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6114 | SemaDiagnosticBuilder diagnoseConversion(Sema &, SourceLocation, QualType, |
| 6115 | QualType) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6116 | llvm_unreachable("conversion functions are permitted"); |
| 6117 | } |
| 6118 | } ConvertDiagnoser; |
| 6119 | return PerformContextualImplicitConversion(Loc, Op, ConvertDiagnoser); |
| 6120 | } |
| 6121 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6122 | static bool IsNonNegativeIntegerValue(Expr *&ValExpr, Sema &SemaRef, |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6123 | OpenMPClauseKind CKind, |
| 6124 | bool StrictlyPositive) { |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6125 | if (!ValExpr->isTypeDependent() && !ValExpr->isValueDependent() && |
| 6126 | !ValExpr->isInstantiationDependent()) { |
| 6127 | SourceLocation Loc = ValExpr->getExprLoc(); |
| 6128 | ExprResult Value = |
| 6129 | SemaRef.PerformOpenMPImplicitIntegerConversion(Loc, ValExpr); |
| 6130 | if (Value.isInvalid()) |
| 6131 | return false; |
| 6132 | |
| 6133 | ValExpr = Value.get(); |
| 6134 | // The expression must evaluate to a non-negative integer value. |
| 6135 | llvm::APSInt Result; |
| 6136 | if (ValExpr->isIntegerConstantExpr(Result, SemaRef.Context) && |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6137 | Result.isSigned() && |
| 6138 | !((!StrictlyPositive && Result.isNonNegative()) || |
| 6139 | (StrictlyPositive && Result.isStrictlyPositive()))) { |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6140 | SemaRef.Diag(Loc, diag::err_omp_negative_expression_in_clause) |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6141 | << getOpenMPClauseName(CKind) << (StrictlyPositive ? 1 : 0) |
| 6142 | << ValExpr->getSourceRange(); |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6143 | return false; |
| 6144 | } |
| 6145 | } |
| 6146 | return true; |
| 6147 | } |
| 6148 | |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6149 | OMPClause *Sema::ActOnOpenMPNumThreadsClause(Expr *NumThreads, |
| 6150 | SourceLocation StartLoc, |
| 6151 | SourceLocation LParenLoc, |
| 6152 | SourceLocation EndLoc) { |
| 6153 | Expr *ValExpr = NumThreads; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6154 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6155 | // OpenMP [2.5, Restrictions] |
| 6156 | // The num_threads expression must evaluate to a positive integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6157 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_num_threads, |
| 6158 | /*StrictlyPositive=*/true)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6159 | return nullptr; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6160 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6161 | return new (Context) |
| 6162 | OMPNumThreadsClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6163 | } |
| 6164 | |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6165 | ExprResult Sema::VerifyPositiveIntegerConstantInClause(Expr *E, |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 6166 | OpenMPClauseKind CKind, |
| 6167 | bool StrictlyPositive) { |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6168 | if (!E) |
| 6169 | return ExprError(); |
| 6170 | if (E->isValueDependent() || E->isTypeDependent() || |
| 6171 | E->isInstantiationDependent() || E->containsUnexpandedParameterPack()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6172 | return E; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6173 | llvm::APSInt Result; |
| 6174 | ExprResult ICE = VerifyIntegerConstantExpression(E, &Result); |
| 6175 | if (ICE.isInvalid()) |
| 6176 | return ExprError(); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 6177 | if ((StrictlyPositive && !Result.isStrictlyPositive()) || |
| 6178 | (!StrictlyPositive && !Result.isNonNegative())) { |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6179 | Diag(E->getExprLoc(), diag::err_omp_negative_expression_in_clause) |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 6180 | << getOpenMPClauseName(CKind) << (StrictlyPositive ? 1 : 0) |
| 6181 | << E->getSourceRange(); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6182 | return ExprError(); |
| 6183 | } |
Alexander Musman | 09184fe | 2014-09-30 05:29:28 +0000 | [diff] [blame] | 6184 | if (CKind == OMPC_aligned && !Result.isPowerOf2()) { |
| 6185 | Diag(E->getExprLoc(), diag::warn_omp_alignment_not_power_of_two) |
| 6186 | << E->getSourceRange(); |
| 6187 | return ExprError(); |
| 6188 | } |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 6189 | if (CKind == OMPC_collapse && DSAStack->getAssociatedLoops() == 1) |
| 6190 | DSAStack->setAssociatedLoops(Result.getExtValue()); |
Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 6191 | else if (CKind == OMPC_ordered) |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 6192 | DSAStack->setAssociatedLoops(Result.getExtValue()); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6193 | return ICE; |
| 6194 | } |
| 6195 | |
| 6196 | OMPClause *Sema::ActOnOpenMPSafelenClause(Expr *Len, SourceLocation StartLoc, |
| 6197 | SourceLocation LParenLoc, |
| 6198 | SourceLocation EndLoc) { |
| 6199 | // OpenMP [2.8.1, simd construct, Description] |
| 6200 | // The parameter of the safelen clause must be a constant |
| 6201 | // positive integer expression. |
| 6202 | ExprResult Safelen = VerifyPositiveIntegerConstantInClause(Len, OMPC_safelen); |
| 6203 | if (Safelen.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6204 | return nullptr; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6205 | return new (Context) |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6206 | OMPSafelenClause(Safelen.get(), StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6207 | } |
| 6208 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 6209 | OMPClause *Sema::ActOnOpenMPSimdlenClause(Expr *Len, SourceLocation StartLoc, |
| 6210 | SourceLocation LParenLoc, |
| 6211 | SourceLocation EndLoc) { |
| 6212 | // OpenMP [2.8.1, simd construct, Description] |
| 6213 | // The parameter of the simdlen clause must be a constant |
| 6214 | // positive integer expression. |
| 6215 | ExprResult Simdlen = VerifyPositiveIntegerConstantInClause(Len, OMPC_simdlen); |
| 6216 | if (Simdlen.isInvalid()) |
| 6217 | return nullptr; |
| 6218 | return new (Context) |
| 6219 | OMPSimdlenClause(Simdlen.get(), StartLoc, LParenLoc, EndLoc); |
| 6220 | } |
| 6221 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6222 | OMPClause *Sema::ActOnOpenMPCollapseClause(Expr *NumForLoops, |
| 6223 | SourceLocation StartLoc, |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6224 | SourceLocation LParenLoc, |
| 6225 | SourceLocation EndLoc) { |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6226 | // OpenMP [2.7.1, loop construct, Description] |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6227 | // OpenMP [2.8.1, simd construct, Description] |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6228 | // OpenMP [2.9.6, distribute construct, Description] |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6229 | // The parameter of the collapse clause must be a constant |
| 6230 | // positive integer expression. |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6231 | ExprResult NumForLoopsResult = |
| 6232 | VerifyPositiveIntegerConstantInClause(NumForLoops, OMPC_collapse); |
| 6233 | if (NumForLoopsResult.isInvalid()) |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6234 | return nullptr; |
| 6235 | return new (Context) |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6236 | OMPCollapseClause(NumForLoopsResult.get(), StartLoc, LParenLoc, EndLoc); |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6237 | } |
| 6238 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 6239 | OMPClause *Sema::ActOnOpenMPOrderedClause(SourceLocation StartLoc, |
| 6240 | SourceLocation EndLoc, |
| 6241 | SourceLocation LParenLoc, |
| 6242 | Expr *NumForLoops) { |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 6243 | // OpenMP [2.7.1, loop construct, Description] |
| 6244 | // OpenMP [2.8.1, simd construct, Description] |
| 6245 | // OpenMP [2.9.6, distribute construct, Description] |
| 6246 | // The parameter of the ordered clause must be a constant |
| 6247 | // positive integer expression if any. |
| 6248 | if (NumForLoops && LParenLoc.isValid()) { |
| 6249 | ExprResult NumForLoopsResult = |
| 6250 | VerifyPositiveIntegerConstantInClause(NumForLoops, OMPC_ordered); |
| 6251 | if (NumForLoopsResult.isInvalid()) |
| 6252 | return nullptr; |
| 6253 | NumForLoops = NumForLoopsResult.get(); |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6254 | } else |
| 6255 | NumForLoops = nullptr; |
| 6256 | DSAStack->setOrderedRegion(/*IsOrdered=*/true, NumForLoops); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 6257 | return new (Context) |
| 6258 | OMPOrderedClause(NumForLoops, StartLoc, LParenLoc, EndLoc); |
| 6259 | } |
| 6260 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6261 | OMPClause *Sema::ActOnOpenMPSimpleClause( |
| 6262 | OpenMPClauseKind Kind, unsigned Argument, SourceLocation ArgumentLoc, |
| 6263 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6264 | OMPClause *Res = nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6265 | switch (Kind) { |
| 6266 | case OMPC_default: |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6267 | Res = |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6268 | ActOnOpenMPDefaultClause(static_cast<OpenMPDefaultClauseKind>(Argument), |
| 6269 | ArgumentLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6270 | break; |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6271 | case OMPC_proc_bind: |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6272 | Res = ActOnOpenMPProcBindClause( |
| 6273 | static_cast<OpenMPProcBindClauseKind>(Argument), ArgumentLoc, StartLoc, |
| 6274 | LParenLoc, EndLoc); |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6275 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6276 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 6277 | case OMPC_final: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6278 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6279 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 6280 | case OMPC_simdlen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6281 | case OMPC_collapse: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6282 | case OMPC_schedule: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6283 | case OMPC_private: |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6284 | case OMPC_firstprivate: |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6285 | case OMPC_lastprivate: |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6286 | case OMPC_shared: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6287 | case OMPC_reduction: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6288 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 6289 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6290 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6291 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6292 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6293 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 6294 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 6295 | case OMPC_mergeable: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6296 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 6297 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6298 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6299 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6300 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6301 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 6302 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6303 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 6304 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6305 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6306 | case OMPC_simd: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 6307 | case OMPC_map: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 6308 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6309 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6310 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 6311 | case OMPC_grainsize: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 6312 | case OMPC_nogroup: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6313 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 6314 | case OMPC_hint: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 6315 | case OMPC_dist_schedule: |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 6316 | case OMPC_defaultmap: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6317 | case OMPC_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6318 | llvm_unreachable("Clause is not allowed."); |
| 6319 | } |
| 6320 | return Res; |
| 6321 | } |
| 6322 | |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6323 | static std::string |
| 6324 | getListOfPossibleValues(OpenMPClauseKind K, unsigned First, unsigned Last, |
| 6325 | ArrayRef<unsigned> Exclude = llvm::None) { |
| 6326 | std::string Values; |
| 6327 | unsigned Bound = Last >= 2 ? Last - 2 : 0; |
| 6328 | unsigned Skipped = Exclude.size(); |
| 6329 | auto S = Exclude.begin(), E = Exclude.end(); |
| 6330 | for (unsigned i = First; i < Last; ++i) { |
| 6331 | if (std::find(S, E, i) != E) { |
| 6332 | --Skipped; |
| 6333 | continue; |
| 6334 | } |
| 6335 | Values += "'"; |
| 6336 | Values += getOpenMPSimpleClauseTypeName(K, i); |
| 6337 | Values += "'"; |
| 6338 | if (i == Bound - Skipped) |
| 6339 | Values += " or "; |
| 6340 | else if (i != Bound + 1 - Skipped) |
| 6341 | Values += ", "; |
| 6342 | } |
| 6343 | return Values; |
| 6344 | } |
| 6345 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6346 | OMPClause *Sema::ActOnOpenMPDefaultClause(OpenMPDefaultClauseKind Kind, |
| 6347 | SourceLocation KindKwLoc, |
| 6348 | SourceLocation StartLoc, |
| 6349 | SourceLocation LParenLoc, |
| 6350 | SourceLocation EndLoc) { |
| 6351 | if (Kind == OMPC_DEFAULT_unknown) { |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 6352 | static_assert(OMPC_DEFAULT_unknown > 0, |
| 6353 | "OMPC_DEFAULT_unknown not greater than 0"); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6354 | Diag(KindKwLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6355 | << getListOfPossibleValues(OMPC_default, /*First=*/0, |
| 6356 | /*Last=*/OMPC_DEFAULT_unknown) |
| 6357 | << getOpenMPClauseName(OMPC_default); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6358 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6359 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6360 | switch (Kind) { |
| 6361 | case OMPC_DEFAULT_none: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6362 | DSAStack->setDefaultDSANone(KindKwLoc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6363 | break; |
| 6364 | case OMPC_DEFAULT_shared: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6365 | DSAStack->setDefaultDSAShared(KindKwLoc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6366 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6367 | case OMPC_DEFAULT_unknown: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6368 | llvm_unreachable("Clause kind is not allowed."); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6369 | break; |
| 6370 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6371 | return new (Context) |
| 6372 | OMPDefaultClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6373 | } |
| 6374 | |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6375 | OMPClause *Sema::ActOnOpenMPProcBindClause(OpenMPProcBindClauseKind Kind, |
| 6376 | SourceLocation KindKwLoc, |
| 6377 | SourceLocation StartLoc, |
| 6378 | SourceLocation LParenLoc, |
| 6379 | SourceLocation EndLoc) { |
| 6380 | if (Kind == OMPC_PROC_BIND_unknown) { |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6381 | Diag(KindKwLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6382 | << getListOfPossibleValues(OMPC_proc_bind, /*First=*/0, |
| 6383 | /*Last=*/OMPC_PROC_BIND_unknown) |
| 6384 | << getOpenMPClauseName(OMPC_proc_bind); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6385 | return nullptr; |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6386 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6387 | return new (Context) |
| 6388 | OMPProcBindClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6389 | } |
| 6390 | |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6391 | OMPClause *Sema::ActOnOpenMPSingleExprWithArgClause( |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6392 | OpenMPClauseKind Kind, ArrayRef<unsigned> Argument, Expr *Expr, |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6393 | SourceLocation StartLoc, SourceLocation LParenLoc, |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6394 | ArrayRef<SourceLocation> ArgumentLoc, SourceLocation DelimLoc, |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6395 | SourceLocation EndLoc) { |
| 6396 | OMPClause *Res = nullptr; |
| 6397 | switch (Kind) { |
| 6398 | case OMPC_schedule: |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6399 | enum { Modifier1, Modifier2, ScheduleKind, NumberOfElements }; |
| 6400 | assert(Argument.size() == NumberOfElements && |
| 6401 | ArgumentLoc.size() == NumberOfElements); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6402 | Res = ActOnOpenMPScheduleClause( |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6403 | static_cast<OpenMPScheduleClauseModifier>(Argument[Modifier1]), |
| 6404 | static_cast<OpenMPScheduleClauseModifier>(Argument[Modifier2]), |
| 6405 | static_cast<OpenMPScheduleClauseKind>(Argument[ScheduleKind]), Expr, |
| 6406 | StartLoc, LParenLoc, ArgumentLoc[Modifier1], ArgumentLoc[Modifier2], |
| 6407 | ArgumentLoc[ScheduleKind], DelimLoc, EndLoc); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6408 | break; |
| 6409 | case OMPC_if: |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6410 | assert(Argument.size() == 1 && ArgumentLoc.size() == 1); |
| 6411 | Res = ActOnOpenMPIfClause(static_cast<OpenMPDirectiveKind>(Argument.back()), |
| 6412 | Expr, StartLoc, LParenLoc, ArgumentLoc.back(), |
| 6413 | DelimLoc, EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6414 | break; |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 6415 | case OMPC_dist_schedule: |
| 6416 | Res = ActOnOpenMPDistScheduleClause( |
| 6417 | static_cast<OpenMPDistScheduleClauseKind>(Argument.back()), Expr, |
| 6418 | StartLoc, LParenLoc, ArgumentLoc.back(), DelimLoc, EndLoc); |
| 6419 | break; |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 6420 | case OMPC_defaultmap: |
| 6421 | enum { Modifier, DefaultmapKind }; |
| 6422 | Res = ActOnOpenMPDefaultmapClause( |
| 6423 | static_cast<OpenMPDefaultmapClauseModifier>(Argument[Modifier]), |
| 6424 | static_cast<OpenMPDefaultmapClauseKind>(Argument[DefaultmapKind]), |
| 6425 | StartLoc, LParenLoc, ArgumentLoc[Modifier], |
| 6426 | ArgumentLoc[DefaultmapKind], EndLoc); |
| 6427 | break; |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 6428 | case OMPC_final: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6429 | case OMPC_num_threads: |
| 6430 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 6431 | case OMPC_simdlen: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6432 | case OMPC_collapse: |
| 6433 | case OMPC_default: |
| 6434 | case OMPC_proc_bind: |
| 6435 | case OMPC_private: |
| 6436 | case OMPC_firstprivate: |
| 6437 | case OMPC_lastprivate: |
| 6438 | case OMPC_shared: |
| 6439 | case OMPC_reduction: |
| 6440 | case OMPC_linear: |
| 6441 | case OMPC_aligned: |
| 6442 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6443 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6444 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6445 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 6446 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 6447 | case OMPC_mergeable: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6448 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 6449 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6450 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6451 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6452 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6453 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 6454 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6455 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 6456 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6457 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6458 | case OMPC_simd: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 6459 | case OMPC_map: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 6460 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6461 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6462 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 6463 | case OMPC_grainsize: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 6464 | case OMPC_nogroup: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6465 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 6466 | case OMPC_hint: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6467 | case OMPC_unknown: |
| 6468 | llvm_unreachable("Clause is not allowed."); |
| 6469 | } |
| 6470 | return Res; |
| 6471 | } |
| 6472 | |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6473 | static bool checkScheduleModifiers(Sema &S, OpenMPScheduleClauseModifier M1, |
| 6474 | OpenMPScheduleClauseModifier M2, |
| 6475 | SourceLocation M1Loc, SourceLocation M2Loc) { |
| 6476 | if (M1 == OMPC_SCHEDULE_MODIFIER_unknown && M1Loc.isValid()) { |
| 6477 | SmallVector<unsigned, 2> Excluded; |
| 6478 | if (M2 != OMPC_SCHEDULE_MODIFIER_unknown) |
| 6479 | Excluded.push_back(M2); |
| 6480 | if (M2 == OMPC_SCHEDULE_MODIFIER_nonmonotonic) |
| 6481 | Excluded.push_back(OMPC_SCHEDULE_MODIFIER_monotonic); |
| 6482 | if (M2 == OMPC_SCHEDULE_MODIFIER_monotonic) |
| 6483 | Excluded.push_back(OMPC_SCHEDULE_MODIFIER_nonmonotonic); |
| 6484 | S.Diag(M1Loc, diag::err_omp_unexpected_clause_value) |
| 6485 | << getListOfPossibleValues(OMPC_schedule, |
| 6486 | /*First=*/OMPC_SCHEDULE_MODIFIER_unknown + 1, |
| 6487 | /*Last=*/OMPC_SCHEDULE_MODIFIER_last, |
| 6488 | Excluded) |
| 6489 | << getOpenMPClauseName(OMPC_schedule); |
| 6490 | return true; |
| 6491 | } |
| 6492 | return false; |
| 6493 | } |
| 6494 | |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6495 | OMPClause *Sema::ActOnOpenMPScheduleClause( |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6496 | OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2, |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6497 | OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6498 | SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc, |
| 6499 | SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) { |
| 6500 | if (checkScheduleModifiers(*this, M1, M2, M1Loc, M2Loc) || |
| 6501 | checkScheduleModifiers(*this, M2, M1, M2Loc, M1Loc)) |
| 6502 | return nullptr; |
| 6503 | // OpenMP, 2.7.1, Loop Construct, Restrictions |
| 6504 | // Either the monotonic modifier or the nonmonotonic modifier can be specified |
| 6505 | // but not both. |
| 6506 | if ((M1 == M2 && M1 != OMPC_SCHEDULE_MODIFIER_unknown) || |
| 6507 | (M1 == OMPC_SCHEDULE_MODIFIER_monotonic && |
| 6508 | M2 == OMPC_SCHEDULE_MODIFIER_nonmonotonic) || |
| 6509 | (M1 == OMPC_SCHEDULE_MODIFIER_nonmonotonic && |
| 6510 | M2 == OMPC_SCHEDULE_MODIFIER_monotonic)) { |
| 6511 | Diag(M2Loc, diag::err_omp_unexpected_schedule_modifier) |
| 6512 | << getOpenMPSimpleClauseTypeName(OMPC_schedule, M2) |
| 6513 | << getOpenMPSimpleClauseTypeName(OMPC_schedule, M1); |
| 6514 | return nullptr; |
| 6515 | } |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6516 | if (Kind == OMPC_SCHEDULE_unknown) { |
| 6517 | std::string Values; |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6518 | if (M1Loc.isInvalid() && M2Loc.isInvalid()) { |
| 6519 | unsigned Exclude[] = {OMPC_SCHEDULE_unknown}; |
| 6520 | Values = getListOfPossibleValues(OMPC_schedule, /*First=*/0, |
| 6521 | /*Last=*/OMPC_SCHEDULE_MODIFIER_last, |
| 6522 | Exclude); |
| 6523 | } else { |
| 6524 | Values = getListOfPossibleValues(OMPC_schedule, /*First=*/0, |
| 6525 | /*Last=*/OMPC_SCHEDULE_unknown); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6526 | } |
| 6527 | Diag(KindLoc, diag::err_omp_unexpected_clause_value) |
| 6528 | << Values << getOpenMPClauseName(OMPC_schedule); |
| 6529 | return nullptr; |
| 6530 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6531 | // OpenMP, 2.7.1, Loop Construct, Restrictions |
| 6532 | // The nonmonotonic modifier can only be specified with schedule(dynamic) or |
| 6533 | // schedule(guided). |
| 6534 | if ((M1 == OMPC_SCHEDULE_MODIFIER_nonmonotonic || |
| 6535 | M2 == OMPC_SCHEDULE_MODIFIER_nonmonotonic) && |
| 6536 | Kind != OMPC_SCHEDULE_dynamic && Kind != OMPC_SCHEDULE_guided) { |
| 6537 | Diag(M1 == OMPC_SCHEDULE_MODIFIER_nonmonotonic ? M1Loc : M2Loc, |
| 6538 | diag::err_omp_schedule_nonmonotonic_static); |
| 6539 | return nullptr; |
| 6540 | } |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6541 | Expr *ValExpr = ChunkSize; |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 6542 | Expr *HelperValExpr = nullptr; |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6543 | if (ChunkSize) { |
| 6544 | if (!ChunkSize->isValueDependent() && !ChunkSize->isTypeDependent() && |
| 6545 | !ChunkSize->isInstantiationDependent() && |
| 6546 | !ChunkSize->containsUnexpandedParameterPack()) { |
| 6547 | SourceLocation ChunkSizeLoc = ChunkSize->getLocStart(); |
| 6548 | ExprResult Val = |
| 6549 | PerformOpenMPImplicitIntegerConversion(ChunkSizeLoc, ChunkSize); |
| 6550 | if (Val.isInvalid()) |
| 6551 | return nullptr; |
| 6552 | |
| 6553 | ValExpr = Val.get(); |
| 6554 | |
| 6555 | // OpenMP [2.7.1, Restrictions] |
| 6556 | // chunk_size must be a loop invariant integer expression with a positive |
| 6557 | // value. |
| 6558 | llvm::APSInt Result; |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 6559 | if (ValExpr->isIntegerConstantExpr(Result, Context)) { |
| 6560 | if (Result.isSigned() && !Result.isStrictlyPositive()) { |
| 6561 | Diag(ChunkSizeLoc, diag::err_omp_negative_expression_in_clause) |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6562 | << "schedule" << 1 << ChunkSize->getSourceRange(); |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 6563 | return nullptr; |
| 6564 | } |
| 6565 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective())) { |
| 6566 | auto *ImpVar = buildVarDecl(*this, ChunkSize->getExprLoc(), |
| 6567 | ChunkSize->getType(), ".chunk."); |
| 6568 | auto *ImpVarRef = buildDeclRefExpr(*this, ImpVar, ChunkSize->getType(), |
| 6569 | ChunkSize->getExprLoc(), |
| 6570 | /*RefersToCapture=*/true); |
| 6571 | HelperValExpr = ImpVarRef; |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6572 | } |
| 6573 | } |
| 6574 | } |
| 6575 | |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6576 | return new (Context) |
| 6577 | OMPScheduleClause(StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc, Kind, |
| 6578 | ValExpr, HelperValExpr, M1, M1Loc, M2, M2Loc); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6579 | } |
| 6580 | |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6581 | OMPClause *Sema::ActOnOpenMPClause(OpenMPClauseKind Kind, |
| 6582 | SourceLocation StartLoc, |
| 6583 | SourceLocation EndLoc) { |
| 6584 | OMPClause *Res = nullptr; |
| 6585 | switch (Kind) { |
| 6586 | case OMPC_ordered: |
| 6587 | Res = ActOnOpenMPOrderedClause(StartLoc, EndLoc); |
| 6588 | break; |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6589 | case OMPC_nowait: |
| 6590 | Res = ActOnOpenMPNowaitClause(StartLoc, EndLoc); |
| 6591 | break; |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 6592 | case OMPC_untied: |
| 6593 | Res = ActOnOpenMPUntiedClause(StartLoc, EndLoc); |
| 6594 | break; |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 6595 | case OMPC_mergeable: |
| 6596 | Res = ActOnOpenMPMergeableClause(StartLoc, EndLoc); |
| 6597 | break; |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6598 | case OMPC_read: |
| 6599 | Res = ActOnOpenMPReadClause(StartLoc, EndLoc); |
| 6600 | break; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6601 | case OMPC_write: |
| 6602 | Res = ActOnOpenMPWriteClause(StartLoc, EndLoc); |
| 6603 | break; |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6604 | case OMPC_update: |
| 6605 | Res = ActOnOpenMPUpdateClause(StartLoc, EndLoc); |
| 6606 | break; |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6607 | case OMPC_capture: |
| 6608 | Res = ActOnOpenMPCaptureClause(StartLoc, EndLoc); |
| 6609 | break; |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 6610 | case OMPC_seq_cst: |
| 6611 | Res = ActOnOpenMPSeqCstClause(StartLoc, EndLoc); |
| 6612 | break; |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6613 | case OMPC_threads: |
| 6614 | Res = ActOnOpenMPThreadsClause(StartLoc, EndLoc); |
| 6615 | break; |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6616 | case OMPC_simd: |
| 6617 | Res = ActOnOpenMPSIMDClause(StartLoc, EndLoc); |
| 6618 | break; |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 6619 | case OMPC_nogroup: |
| 6620 | Res = ActOnOpenMPNogroupClause(StartLoc, EndLoc); |
| 6621 | break; |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6622 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 6623 | case OMPC_final: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6624 | case OMPC_num_threads: |
| 6625 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 6626 | case OMPC_simdlen: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6627 | case OMPC_collapse: |
| 6628 | case OMPC_schedule: |
| 6629 | case OMPC_private: |
| 6630 | case OMPC_firstprivate: |
| 6631 | case OMPC_lastprivate: |
| 6632 | case OMPC_shared: |
| 6633 | case OMPC_reduction: |
| 6634 | case OMPC_linear: |
| 6635 | case OMPC_aligned: |
| 6636 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6637 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6638 | case OMPC_default: |
| 6639 | case OMPC_proc_bind: |
| 6640 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 6641 | case OMPC_flush: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6642 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 6643 | case OMPC_device: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 6644 | case OMPC_map: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 6645 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6646 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6647 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 6648 | case OMPC_grainsize: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6649 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 6650 | case OMPC_hint: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 6651 | case OMPC_dist_schedule: |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 6652 | case OMPC_defaultmap: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6653 | case OMPC_unknown: |
| 6654 | llvm_unreachable("Clause is not allowed."); |
| 6655 | } |
| 6656 | return Res; |
| 6657 | } |
| 6658 | |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6659 | OMPClause *Sema::ActOnOpenMPNowaitClause(SourceLocation StartLoc, |
| 6660 | SourceLocation EndLoc) { |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 6661 | DSAStack->setNowaitRegion(); |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6662 | return new (Context) OMPNowaitClause(StartLoc, EndLoc); |
| 6663 | } |
| 6664 | |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 6665 | OMPClause *Sema::ActOnOpenMPUntiedClause(SourceLocation StartLoc, |
| 6666 | SourceLocation EndLoc) { |
| 6667 | return new (Context) OMPUntiedClause(StartLoc, EndLoc); |
| 6668 | } |
| 6669 | |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 6670 | OMPClause *Sema::ActOnOpenMPMergeableClause(SourceLocation StartLoc, |
| 6671 | SourceLocation EndLoc) { |
| 6672 | return new (Context) OMPMergeableClause(StartLoc, EndLoc); |
| 6673 | } |
| 6674 | |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6675 | OMPClause *Sema::ActOnOpenMPReadClause(SourceLocation StartLoc, |
| 6676 | SourceLocation EndLoc) { |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6677 | return new (Context) OMPReadClause(StartLoc, EndLoc); |
| 6678 | } |
| 6679 | |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6680 | OMPClause *Sema::ActOnOpenMPWriteClause(SourceLocation StartLoc, |
| 6681 | SourceLocation EndLoc) { |
| 6682 | return new (Context) OMPWriteClause(StartLoc, EndLoc); |
| 6683 | } |
| 6684 | |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6685 | OMPClause *Sema::ActOnOpenMPUpdateClause(SourceLocation StartLoc, |
| 6686 | SourceLocation EndLoc) { |
| 6687 | return new (Context) OMPUpdateClause(StartLoc, EndLoc); |
| 6688 | } |
| 6689 | |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6690 | OMPClause *Sema::ActOnOpenMPCaptureClause(SourceLocation StartLoc, |
| 6691 | SourceLocation EndLoc) { |
| 6692 | return new (Context) OMPCaptureClause(StartLoc, EndLoc); |
| 6693 | } |
| 6694 | |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 6695 | OMPClause *Sema::ActOnOpenMPSeqCstClause(SourceLocation StartLoc, |
| 6696 | SourceLocation EndLoc) { |
| 6697 | return new (Context) OMPSeqCstClause(StartLoc, EndLoc); |
| 6698 | } |
| 6699 | |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6700 | OMPClause *Sema::ActOnOpenMPThreadsClause(SourceLocation StartLoc, |
| 6701 | SourceLocation EndLoc) { |
| 6702 | return new (Context) OMPThreadsClause(StartLoc, EndLoc); |
| 6703 | } |
| 6704 | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6705 | OMPClause *Sema::ActOnOpenMPSIMDClause(SourceLocation StartLoc, |
| 6706 | SourceLocation EndLoc) { |
| 6707 | return new (Context) OMPSIMDClause(StartLoc, EndLoc); |
| 6708 | } |
| 6709 | |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 6710 | OMPClause *Sema::ActOnOpenMPNogroupClause(SourceLocation StartLoc, |
| 6711 | SourceLocation EndLoc) { |
| 6712 | return new (Context) OMPNogroupClause(StartLoc, EndLoc); |
| 6713 | } |
| 6714 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6715 | OMPClause *Sema::ActOnOpenMPVarListClause( |
| 6716 | OpenMPClauseKind Kind, ArrayRef<Expr *> VarList, Expr *TailExpr, |
| 6717 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, |
| 6718 | SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6719 | const DeclarationNameInfo &ReductionId, OpenMPDependClauseKind DepKind, |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 6720 | OpenMPLinearClauseKind LinKind, OpenMPMapClauseKind MapTypeModifier, |
| 6721 | OpenMPMapClauseKind MapType, bool IsMapTypeImplicit, |
| 6722 | SourceLocation DepLinMapLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6723 | OMPClause *Res = nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6724 | switch (Kind) { |
| 6725 | case OMPC_private: |
| 6726 | Res = ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 6727 | break; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6728 | case OMPC_firstprivate: |
| 6729 | Res = ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 6730 | break; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6731 | case OMPC_lastprivate: |
| 6732 | Res = ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 6733 | break; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6734 | case OMPC_shared: |
| 6735 | Res = ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 6736 | break; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6737 | case OMPC_reduction: |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 6738 | Res = ActOnOpenMPReductionClause(VarList, StartLoc, LParenLoc, ColonLoc, |
| 6739 | EndLoc, ReductionIdScopeSpec, ReductionId); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6740 | break; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6741 | case OMPC_linear: |
| 6742 | Res = ActOnOpenMPLinearClause(VarList, TailExpr, StartLoc, LParenLoc, |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 6743 | LinKind, DepLinMapLoc, ColonLoc, EndLoc); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6744 | break; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 6745 | case OMPC_aligned: |
| 6746 | Res = ActOnOpenMPAlignedClause(VarList, TailExpr, StartLoc, LParenLoc, |
| 6747 | ColonLoc, EndLoc); |
| 6748 | break; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6749 | case OMPC_copyin: |
| 6750 | Res = ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 6751 | break; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6752 | case OMPC_copyprivate: |
| 6753 | Res = ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 6754 | break; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 6755 | case OMPC_flush: |
| 6756 | Res = ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 6757 | break; |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6758 | case OMPC_depend: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 6759 | Res = ActOnOpenMPDependClause(DepKind, DepLinMapLoc, ColonLoc, VarList, |
| 6760 | StartLoc, LParenLoc, EndLoc); |
| 6761 | break; |
| 6762 | case OMPC_map: |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 6763 | Res = ActOnOpenMPMapClause(MapTypeModifier, MapType, IsMapTypeImplicit, |
| 6764 | DepLinMapLoc, ColonLoc, VarList, StartLoc, |
| 6765 | LParenLoc, EndLoc); |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6766 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6767 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 6768 | case OMPC_final: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6769 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6770 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 6771 | case OMPC_simdlen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6772 | case OMPC_collapse: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6773 | case OMPC_default: |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6774 | case OMPC_proc_bind: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6775 | case OMPC_schedule: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6776 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6777 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 6778 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 6779 | case OMPC_mergeable: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6780 | case OMPC_threadprivate: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6781 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6782 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6783 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6784 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 6785 | case OMPC_seq_cst: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 6786 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6787 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6788 | case OMPC_simd: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 6789 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6790 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6791 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 6792 | case OMPC_grainsize: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 6793 | case OMPC_nogroup: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6794 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 6795 | case OMPC_hint: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 6796 | case OMPC_dist_schedule: |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 6797 | case OMPC_defaultmap: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6798 | case OMPC_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6799 | llvm_unreachable("Clause is not allowed."); |
| 6800 | } |
| 6801 | return Res; |
| 6802 | } |
| 6803 | |
| 6804 | OMPClause *Sema::ActOnOpenMPPrivateClause(ArrayRef<Expr *> VarList, |
| 6805 | SourceLocation StartLoc, |
| 6806 | SourceLocation LParenLoc, |
| 6807 | SourceLocation EndLoc) { |
| 6808 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 6809 | SmallVector<Expr *, 8> PrivateCopies; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6810 | for (auto &RefExpr : VarList) { |
| 6811 | assert(RefExpr && "NULL expr in OpenMP private clause."); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 6812 | if (RefExpr->isTypeDependent() || RefExpr->isValueDependent() || |
| 6813 | RefExpr->containsUnexpandedParameterPack()) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6814 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6815 | Vars.push_back(RefExpr); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 6816 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6817 | continue; |
| 6818 | } |
| 6819 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6820 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Carlo Bertolli | 9e8c6c1 | 2016-01-19 16:53:55 +0000 | [diff] [blame] | 6821 | // OpenMP [3.1, C/C++] |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6822 | // A list item is a variable name. |
| 6823 | // OpenMP [2.9.3.3, Restrictions, p.1] |
| 6824 | // A variable that is part of another variable (as an array or |
| 6825 | // structure element) cannot appear in a private clause. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 6826 | auto *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr->IgnoreParens()); |
| 6827 | auto *ME = dyn_cast_or_null<MemberExpr>(RefExpr->IgnoreParens()); |
| 6828 | if ((!DE || !isa<VarDecl>(DE->getDecl())) && |
| 6829 | (getCurrentThisType().isNull() || !ME || |
| 6830 | !isa<CXXThisExpr>(ME->getBase()->IgnoreParenImpCasts()) || |
| 6831 | !isa<FieldDecl>(ME->getMemberDecl()))) { |
| 6832 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr) |
| 6833 | << (getCurrentThisType().isNull() ? 0 : 1) |
| 6834 | << RefExpr->getSourceRange(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6835 | continue; |
| 6836 | } |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 6837 | ValueDecl *D = DE ? DE->getDecl() : ME->getMemberDecl(); |
| 6838 | QualType Type = D->getType(); |
| 6839 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6840 | |
| 6841 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 6842 | // A variable that appears in a private clause must not have an incomplete |
| 6843 | // type or a reference type. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 6844 | if (RequireCompleteType(ELoc, Type, diag::err_omp_private_incomplete_type)) |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6845 | continue; |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 6846 | Type = Type.getNonReferenceType(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6847 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6848 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 6849 | // in a Construct] |
| 6850 | // Variables with the predetermined data-sharing attributes may not be |
| 6851 | // listed in data-sharing attributes clauses, except for the cases |
| 6852 | // listed below. For these exceptions only, listing a predetermined |
| 6853 | // variable in a data-sharing attribute clause is allowed and overrides |
| 6854 | // the variable's predetermined data-sharing attributes. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 6855 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6856 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_private) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6857 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 6858 | << getOpenMPClauseName(OMPC_private); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 6859 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6860 | continue; |
| 6861 | } |
| 6862 | |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 6863 | // Variably modified types are not supported for tasks. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 6864 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType() && |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 6865 | DSAStack->getCurrentDirective() == OMPD_task) { |
| 6866 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
| 6867 | << getOpenMPClauseName(OMPC_private) << Type |
| 6868 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 6869 | bool IsDecl = |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 6870 | !VD || |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 6871 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 6872 | Diag(D->getLocation(), |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 6873 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 6874 | << D; |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 6875 | continue; |
| 6876 | } |
| 6877 | |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6878 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.1] |
| 6879 | // A variable of class type (or array thereof) that appears in a private |
| 6880 | // clause requires an accessible, unambiguous default constructor for the |
| 6881 | // class type. |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 6882 | // Generate helper private variable and initialize it with the default |
| 6883 | // value. The address of the original variable is replaced by the address of |
| 6884 | // the new private variable in CodeGen. This new variable is not added to |
| 6885 | // IdResolver, so the code in the OpenMP region uses original variable for |
| 6886 | // proper diagnostics. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6887 | Type = Type.getUnqualifiedType(); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 6888 | auto VDPrivate = buildVarDecl(*this, ELoc, Type, D->getName(), |
| 6889 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6890 | ActOnUninitializedDecl(VDPrivate, /*TypeMayContainAuto=*/false); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 6891 | if (VDPrivate->isInvalidDecl()) |
| 6892 | continue; |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6893 | auto VDPrivateRefExpr = buildDeclRefExpr( |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 6894 | *this, VDPrivate, RefExpr->getType().getUnqualifiedType(), ELoc); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 6895 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 6896 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_private); |
| 6897 | Vars.push_back(RefExpr->IgnoreParens()); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 6898 | PrivateCopies.push_back(VDPrivateRefExpr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6899 | } |
| 6900 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6901 | if (Vars.empty()) |
| 6902 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6903 | |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 6904 | return OMPPrivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
| 6905 | PrivateCopies); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6906 | } |
| 6907 | |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6908 | namespace { |
| 6909 | class DiagsUninitializedSeveretyRAII { |
| 6910 | private: |
| 6911 | DiagnosticsEngine &Diags; |
| 6912 | SourceLocation SavedLoc; |
| 6913 | bool IsIgnored; |
| 6914 | |
| 6915 | public: |
| 6916 | DiagsUninitializedSeveretyRAII(DiagnosticsEngine &Diags, SourceLocation Loc, |
| 6917 | bool IsIgnored) |
| 6918 | : Diags(Diags), SavedLoc(Loc), IsIgnored(IsIgnored) { |
| 6919 | if (!IsIgnored) { |
| 6920 | Diags.setSeverity(/*Diag*/ diag::warn_uninit_self_reference_in_init, |
| 6921 | /*Map*/ diag::Severity::Ignored, Loc); |
| 6922 | } |
| 6923 | } |
| 6924 | ~DiagsUninitializedSeveretyRAII() { |
| 6925 | if (!IsIgnored) |
| 6926 | Diags.popMappings(SavedLoc); |
| 6927 | } |
| 6928 | }; |
Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 6929 | } |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6930 | |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6931 | OMPClause *Sema::ActOnOpenMPFirstprivateClause(ArrayRef<Expr *> VarList, |
| 6932 | SourceLocation StartLoc, |
| 6933 | SourceLocation LParenLoc, |
| 6934 | SourceLocation EndLoc) { |
| 6935 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6936 | SmallVector<Expr *, 8> PrivateCopies; |
| 6937 | SmallVector<Expr *, 8> Inits; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6938 | bool IsImplicitClause = |
| 6939 | StartLoc.isInvalid() && LParenLoc.isInvalid() && EndLoc.isInvalid(); |
| 6940 | auto ImplicitClauseLoc = DSAStack->getConstructLoc(); |
| 6941 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6942 | for (auto &RefExpr : VarList) { |
| 6943 | assert(RefExpr && "NULL expr in OpenMP firstprivate clause."); |
| 6944 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6945 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6946 | Vars.push_back(RefExpr); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6947 | PrivateCopies.push_back(nullptr); |
| 6948 | Inits.push_back(nullptr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6949 | continue; |
| 6950 | } |
| 6951 | |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6952 | SourceLocation ELoc = |
| 6953 | IsImplicitClause ? ImplicitClauseLoc : RefExpr->getExprLoc(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6954 | // OpenMP [2.1, C/C++] |
| 6955 | // A list item is a variable name. |
| 6956 | // OpenMP [2.9.3.3, Restrictions, p.1] |
| 6957 | // A variable that is part of another variable (as an array or |
| 6958 | // structure element) cannot appear in a private clause. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6959 | DeclRefExpr *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6960 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 6961 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr) |
| 6962 | << 0 << RefExpr->getSourceRange(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6963 | continue; |
| 6964 | } |
| 6965 | Decl *D = DE->getDecl(); |
| 6966 | VarDecl *VD = cast<VarDecl>(D); |
| 6967 | |
| 6968 | QualType Type = VD->getType(); |
| 6969 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 6970 | // It will be analyzed later. |
| 6971 | Vars.push_back(DE); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6972 | PrivateCopies.push_back(nullptr); |
| 6973 | Inits.push_back(nullptr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6974 | continue; |
| 6975 | } |
| 6976 | |
| 6977 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 6978 | // A variable that appears in a private clause must not have an incomplete |
| 6979 | // type or a reference type. |
| 6980 | if (RequireCompleteType(ELoc, Type, |
| 6981 | diag::err_omp_firstprivate_incomplete_type)) { |
| 6982 | continue; |
| 6983 | } |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 6984 | Type = Type.getNonReferenceType(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6985 | |
| 6986 | // OpenMP [2.9.3.4, Restrictions, C/C++, p.1] |
| 6987 | // 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] | 6988 | // clause requires an accessible, unambiguous copy constructor for the |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6989 | // class type. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6990 | auto ElemType = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6991 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6992 | // If an implicit firstprivate variable found it was checked already. |
| 6993 | if (!IsImplicitClause) { |
| 6994 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6995 | bool IsConstant = ElemType.isConstant(Context); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6996 | // OpenMP [2.4.13, Data-sharing Attribute Clauses] |
| 6997 | // A list item that specifies a given variable may not appear in more |
| 6998 | // than one clause on the same directive, except that a variable may be |
| 6999 | // specified in both firstprivate and lastprivate clauses. |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7000 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_firstprivate && |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7001 | DVar.CKind != OMPC_lastprivate && DVar.RefExpr) { |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7002 | Diag(ELoc, diag::err_omp_wrong_dsa) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7003 | << getOpenMPClauseName(DVar.CKind) |
| 7004 | << getOpenMPClauseName(OMPC_firstprivate); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 7005 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7006 | continue; |
| 7007 | } |
| 7008 | |
| 7009 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 7010 | // in a Construct] |
| 7011 | // Variables with the predetermined data-sharing attributes may not be |
| 7012 | // listed in data-sharing attributes clauses, except for the cases |
| 7013 | // listed below. For these exceptions only, listing a predetermined |
| 7014 | // variable in a data-sharing attribute clause is allowed and overrides |
| 7015 | // the variable's predetermined data-sharing attributes. |
| 7016 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 7017 | // in a Construct, C/C++, p.2] |
| 7018 | // Variables with const-qualified type having no mutable member may be |
| 7019 | // listed in a firstprivate clause, even if they are static data members. |
| 7020 | if (!(IsConstant || VD->isStaticDataMember()) && !DVar.RefExpr && |
| 7021 | DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared) { |
| 7022 | Diag(ELoc, diag::err_omp_wrong_dsa) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7023 | << getOpenMPClauseName(DVar.CKind) |
| 7024 | << getOpenMPClauseName(OMPC_firstprivate); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 7025 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7026 | continue; |
| 7027 | } |
| 7028 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7029 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7030 | // OpenMP [2.9.3.4, Restrictions, p.2] |
| 7031 | // A list item that is private within a parallel region must not appear |
| 7032 | // in a firstprivate clause on a worksharing construct if any of the |
| 7033 | // worksharing regions arising from the worksharing construct ever bind |
| 7034 | // to any of the parallel regions arising from the parallel construct. |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 7035 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 7036 | !isOpenMPParallelDirective(CurrDir)) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7037 | DVar = DSAStack->getImplicitDSA(VD, true); |
| 7038 | if (DVar.CKind != OMPC_shared && |
| 7039 | (isOpenMPParallelDirective(DVar.DKind) || |
| 7040 | DVar.DKind == OMPD_unknown)) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7041 | Diag(ELoc, diag::err_omp_required_access) |
| 7042 | << getOpenMPClauseName(OMPC_firstprivate) |
| 7043 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 7044 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7045 | continue; |
| 7046 | } |
| 7047 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7048 | // OpenMP [2.9.3.4, Restrictions, p.3] |
| 7049 | // A list item that appears in a reduction clause of a parallel construct |
| 7050 | // must not appear in a firstprivate clause on a worksharing or task |
| 7051 | // construct if any of the worksharing or task regions arising from the |
| 7052 | // worksharing or task construct ever bind to any of the parallel regions |
| 7053 | // arising from the parallel construct. |
| 7054 | // OpenMP [2.9.3.4, Restrictions, p.4] |
| 7055 | // A list item that appears in a reduction clause in worksharing |
| 7056 | // construct must not appear in a firstprivate clause in a task construct |
| 7057 | // encountered during execution of any of the worksharing regions arising |
| 7058 | // from the worksharing construct. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7059 | if (CurrDir == OMPD_task) { |
| 7060 | DVar = |
| 7061 | DSAStack->hasInnermostDSA(VD, MatchesAnyClause(OMPC_reduction), |
| 7062 | [](OpenMPDirectiveKind K) -> bool { |
| 7063 | return isOpenMPParallelDirective(K) || |
| 7064 | isOpenMPWorksharingDirective(K); |
| 7065 | }, |
| 7066 | false); |
| 7067 | if (DVar.CKind == OMPC_reduction && |
| 7068 | (isOpenMPParallelDirective(DVar.DKind) || |
| 7069 | isOpenMPWorksharingDirective(DVar.DKind))) { |
| 7070 | Diag(ELoc, diag::err_omp_parallel_reduction_in_task_firstprivate) |
| 7071 | << getOpenMPDirectiveName(DVar.DKind); |
| 7072 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 7073 | continue; |
| 7074 | } |
| 7075 | } |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7076 | |
| 7077 | // OpenMP 4.5 [2.15.3.4, Restrictions, p.3] |
| 7078 | // A list item that is private within a teams region must not appear in a |
| 7079 | // firstprivate clause on a distribute construct if any of the distribute |
| 7080 | // regions arising from the distribute construct ever bind to any of the |
| 7081 | // teams regions arising from the teams construct. |
| 7082 | // OpenMP 4.5 [2.15.3.4, Restrictions, p.3] |
| 7083 | // A list item that appears in a reduction clause of a teams construct |
| 7084 | // must not appear in a firstprivate clause on a distribute construct if |
| 7085 | // any of the distribute regions arising from the distribute construct |
| 7086 | // ever bind to any of the teams regions arising from the teams construct. |
| 7087 | // OpenMP 4.5 [2.10.8, Distribute Construct, p.3] |
| 7088 | // A list item may appear in a firstprivate or lastprivate clause but not |
| 7089 | // both. |
| 7090 | if (CurrDir == OMPD_distribute) { |
| 7091 | DVar = DSAStack->hasInnermostDSA(VD, MatchesAnyClause(OMPC_private), |
| 7092 | [](OpenMPDirectiveKind K) -> bool { |
| 7093 | return isOpenMPTeamsDirective(K); |
| 7094 | }, |
| 7095 | false); |
| 7096 | if (DVar.CKind == OMPC_private && isOpenMPTeamsDirective(DVar.DKind)) { |
| 7097 | Diag(ELoc, diag::err_omp_firstprivate_distribute_private_teams); |
| 7098 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 7099 | continue; |
| 7100 | } |
| 7101 | DVar = DSAStack->hasInnermostDSA(VD, MatchesAnyClause(OMPC_reduction), |
| 7102 | [](OpenMPDirectiveKind K) -> bool { |
| 7103 | return isOpenMPTeamsDirective(K); |
| 7104 | }, |
| 7105 | false); |
| 7106 | if (DVar.CKind == OMPC_reduction && |
| 7107 | isOpenMPTeamsDirective(DVar.DKind)) { |
| 7108 | Diag(ELoc, diag::err_omp_firstprivate_distribute_in_teams_reduction); |
| 7109 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 7110 | continue; |
| 7111 | } |
| 7112 | DVar = DSAStack->getTopDSA(VD, false); |
| 7113 | if (DVar.CKind == OMPC_lastprivate) { |
| 7114 | Diag(ELoc, diag::err_omp_firstprivate_and_lastprivate_in_distribute); |
| 7115 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 7116 | continue; |
| 7117 | } |
| 7118 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7119 | } |
| 7120 | |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7121 | // Variably modified types are not supported for tasks. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 7122 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType() && |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7123 | DSAStack->getCurrentDirective() == OMPD_task) { |
| 7124 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
| 7125 | << getOpenMPClauseName(OMPC_firstprivate) << Type |
| 7126 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 7127 | bool IsDecl = |
| 7128 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 7129 | Diag(VD->getLocation(), |
| 7130 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7131 | << VD; |
| 7132 | continue; |
| 7133 | } |
| 7134 | |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7135 | Type = Type.getUnqualifiedType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 7136 | auto VDPrivate = buildVarDecl(*this, ELoc, Type, VD->getName(), |
| 7137 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7138 | // Generate helper private variable and initialize it with the value of the |
| 7139 | // original variable. The address of the original variable is replaced by |
| 7140 | // the address of the new private variable in the CodeGen. This new variable |
| 7141 | // is not added to IdResolver, so the code in the OpenMP region uses |
| 7142 | // original variable for proper diagnostics and variable capturing. |
| 7143 | Expr *VDInitRefExpr = nullptr; |
| 7144 | // For arrays generate initializer for single element and replace it by the |
| 7145 | // original array element in CodeGen. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7146 | if (Type->isArrayType()) { |
| 7147 | auto VDInit = |
| 7148 | buildVarDecl(*this, DE->getExprLoc(), ElemType, VD->getName()); |
| 7149 | VDInitRefExpr = buildDeclRefExpr(*this, VDInit, ElemType, ELoc); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7150 | auto Init = DefaultLvalueConversion(VDInitRefExpr).get(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7151 | ElemType = ElemType.getUnqualifiedType(); |
| 7152 | auto *VDInitTemp = buildVarDecl(*this, DE->getLocStart(), ElemType, |
| 7153 | ".firstprivate.temp"); |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 7154 | InitializedEntity Entity = |
| 7155 | InitializedEntity::InitializeVariable(VDInitTemp); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7156 | InitializationKind Kind = InitializationKind::CreateCopy(ELoc, ELoc); |
| 7157 | |
| 7158 | InitializationSequence InitSeq(*this, Entity, Kind, Init); |
| 7159 | ExprResult Result = InitSeq.Perform(*this, Entity, Kind, Init); |
| 7160 | if (Result.isInvalid()) |
| 7161 | VDPrivate->setInvalidDecl(); |
| 7162 | else |
| 7163 | VDPrivate->setInit(Result.getAs<Expr>()); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7164 | // Remove temp variable declaration. |
| 7165 | Context.Deallocate(VDInitTemp); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7166 | } else { |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 7167 | auto *VDInit = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7168 | buildVarDecl(*this, DE->getLocStart(), Type, ".firstprivate.temp"); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7169 | VDInitRefExpr = |
| 7170 | buildDeclRefExpr(*this, VDInit, DE->getType(), DE->getExprLoc()); |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 7171 | AddInitializerToDecl(VDPrivate, |
| 7172 | DefaultLvalueConversion(VDInitRefExpr).get(), |
| 7173 | /*DirectInit=*/false, /*TypeMayContainAuto=*/false); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7174 | } |
| 7175 | if (VDPrivate->isInvalidDecl()) { |
| 7176 | if (IsImplicitClause) { |
| 7177 | Diag(DE->getExprLoc(), |
| 7178 | diag::note_omp_task_predetermined_firstprivate_here); |
| 7179 | } |
| 7180 | continue; |
| 7181 | } |
| 7182 | CurContext->addDecl(VDPrivate); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7183 | auto VDPrivateRefExpr = buildDeclRefExpr( |
| 7184 | *this, VDPrivate, DE->getType().getUnqualifiedType(), DE->getExprLoc()); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7185 | DSAStack->addDSA(VD, DE, OMPC_firstprivate); |
| 7186 | Vars.push_back(DE); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7187 | PrivateCopies.push_back(VDPrivateRefExpr); |
| 7188 | Inits.push_back(VDInitRefExpr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7189 | } |
| 7190 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7191 | if (Vars.empty()) |
| 7192 | return nullptr; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7193 | |
| 7194 | return OMPFirstprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7195 | Vars, PrivateCopies, Inits); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7196 | } |
| 7197 | |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7198 | OMPClause *Sema::ActOnOpenMPLastprivateClause(ArrayRef<Expr *> VarList, |
| 7199 | SourceLocation StartLoc, |
| 7200 | SourceLocation LParenLoc, |
| 7201 | SourceLocation EndLoc) { |
| 7202 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7203 | SmallVector<Expr *, 8> SrcExprs; |
| 7204 | SmallVector<Expr *, 8> DstExprs; |
| 7205 | SmallVector<Expr *, 8> AssignmentOps; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7206 | for (auto &RefExpr : VarList) { |
| 7207 | assert(RefExpr && "NULL expr in OpenMP lastprivate clause."); |
| 7208 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 7209 | // It will be analyzed later. |
| 7210 | Vars.push_back(RefExpr); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7211 | SrcExprs.push_back(nullptr); |
| 7212 | DstExprs.push_back(nullptr); |
| 7213 | AssignmentOps.push_back(nullptr); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7214 | continue; |
| 7215 | } |
| 7216 | |
| 7217 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 7218 | // OpenMP [2.1, C/C++] |
| 7219 | // A list item is a variable name. |
| 7220 | // OpenMP [2.14.3.5, Restrictions, p.1] |
| 7221 | // A variable that is part of another variable (as an array or structure |
| 7222 | // element) cannot appear in a lastprivate clause. |
| 7223 | DeclRefExpr *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr); |
| 7224 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7225 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr) |
| 7226 | << 0 << RefExpr->getSourceRange(); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7227 | continue; |
| 7228 | } |
| 7229 | Decl *D = DE->getDecl(); |
| 7230 | VarDecl *VD = cast<VarDecl>(D); |
| 7231 | |
| 7232 | QualType Type = VD->getType(); |
| 7233 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 7234 | // It will be analyzed later. |
| 7235 | Vars.push_back(DE); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7236 | SrcExprs.push_back(nullptr); |
| 7237 | DstExprs.push_back(nullptr); |
| 7238 | AssignmentOps.push_back(nullptr); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7239 | continue; |
| 7240 | } |
| 7241 | |
| 7242 | // OpenMP [2.14.3.5, Restrictions, C/C++, p.2] |
| 7243 | // A variable that appears in a lastprivate clause must not have an |
| 7244 | // incomplete type or a reference type. |
| 7245 | if (RequireCompleteType(ELoc, Type, |
| 7246 | diag::err_omp_lastprivate_incomplete_type)) { |
| 7247 | continue; |
| 7248 | } |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7249 | Type = Type.getNonReferenceType(); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7250 | |
| 7251 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 7252 | // in a Construct] |
| 7253 | // Variables with the predetermined data-sharing attributes may not be |
| 7254 | // listed in data-sharing attributes clauses, except for the cases |
| 7255 | // listed below. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7256 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7257 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_lastprivate && |
| 7258 | DVar.CKind != OMPC_firstprivate && |
| 7259 | (DVar.CKind != OMPC_private || DVar.RefExpr != nullptr)) { |
| 7260 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 7261 | << getOpenMPClauseName(DVar.CKind) |
| 7262 | << getOpenMPClauseName(OMPC_lastprivate); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 7263 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7264 | continue; |
| 7265 | } |
| 7266 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7267 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
| 7268 | // OpenMP [2.14.3.5, Restrictions, p.2] |
| 7269 | // A list item that is private within a parallel region, or that appears in |
| 7270 | // the reduction clause of a parallel construct, must not appear in a |
| 7271 | // lastprivate clause on a worksharing construct if any of the corresponding |
| 7272 | // worksharing regions ever binds to any of the corresponding parallel |
| 7273 | // regions. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7274 | DSAStackTy::DSAVarData TopDVar = DVar; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 7275 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 7276 | !isOpenMPParallelDirective(CurrDir)) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7277 | DVar = DSAStack->getImplicitDSA(VD, true); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7278 | if (DVar.CKind != OMPC_shared) { |
| 7279 | Diag(ELoc, diag::err_omp_required_access) |
| 7280 | << getOpenMPClauseName(OMPC_lastprivate) |
| 7281 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 7282 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7283 | continue; |
| 7284 | } |
| 7285 | } |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7286 | // OpenMP [2.14.3.5, Restrictions, C++, p.1,2] |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7287 | // A variable of class type (or array thereof) that appears in a |
| 7288 | // lastprivate clause requires an accessible, unambiguous default |
| 7289 | // constructor for the class type, unless the list item is also specified |
| 7290 | // in a firstprivate clause. |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7291 | // A variable of class type (or array thereof) that appears in a |
| 7292 | // lastprivate clause requires an accessible, unambiguous copy assignment |
| 7293 | // operator for the class type. |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7294 | Type = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7295 | auto *SrcVD = buildVarDecl(*this, DE->getLocStart(), |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 7296 | Type.getUnqualifiedType(), ".lastprivate.src", |
| 7297 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7298 | auto *PseudoSrcExpr = buildDeclRefExpr( |
| 7299 | *this, SrcVD, Type.getUnqualifiedType(), DE->getExprLoc()); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7300 | auto *DstVD = |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 7301 | buildVarDecl(*this, DE->getLocStart(), Type, ".lastprivate.dst", |
| 7302 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7303 | auto *PseudoDstExpr = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7304 | buildDeclRefExpr(*this, DstVD, Type, DE->getExprLoc()); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7305 | // For arrays generate assignment operation for single element and replace |
| 7306 | // it by the original array element in CodeGen. |
| 7307 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, DE->getExprLoc(), BO_Assign, |
| 7308 | PseudoDstExpr, PseudoSrcExpr); |
| 7309 | if (AssignmentOp.isInvalid()) |
| 7310 | continue; |
| 7311 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), DE->getExprLoc(), |
| 7312 | /*DiscardedValue=*/true); |
| 7313 | if (AssignmentOp.isInvalid()) |
| 7314 | continue; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7315 | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7316 | // OpenMP 4.5 [2.10.8, Distribute Construct, p.3] |
| 7317 | // A list item may appear in a firstprivate or lastprivate clause but not |
| 7318 | // both. |
| 7319 | if (CurrDir == OMPD_distribute) { |
| 7320 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
| 7321 | if (DVar.CKind == OMPC_firstprivate) { |
| 7322 | Diag(ELoc, diag::err_omp_firstprivate_and_lastprivate_in_distribute); |
| 7323 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 7324 | continue; |
| 7325 | } |
| 7326 | } |
| 7327 | |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7328 | if (TopDVar.CKind != OMPC_firstprivate) |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7329 | DSAStack->addDSA(VD, DE, OMPC_lastprivate); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7330 | Vars.push_back(DE); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7331 | SrcExprs.push_back(PseudoSrcExpr); |
| 7332 | DstExprs.push_back(PseudoDstExpr); |
| 7333 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7334 | } |
| 7335 | |
| 7336 | if (Vars.empty()) |
| 7337 | return nullptr; |
| 7338 | |
| 7339 | return OMPLastprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7340 | Vars, SrcExprs, DstExprs, AssignmentOps); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7341 | } |
| 7342 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7343 | OMPClause *Sema::ActOnOpenMPSharedClause(ArrayRef<Expr *> VarList, |
| 7344 | SourceLocation StartLoc, |
| 7345 | SourceLocation LParenLoc, |
| 7346 | SourceLocation EndLoc) { |
| 7347 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7348 | for (auto &RefExpr : VarList) { |
| 7349 | assert(RefExpr && "NULL expr in OpenMP shared clause."); |
| 7350 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7351 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7352 | Vars.push_back(RefExpr); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7353 | continue; |
| 7354 | } |
| 7355 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7356 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7357 | // OpenMP [2.1, C/C++] |
| 7358 | // A list item is a variable name. |
Alexey Bataev | d4dbdf5 | 2014-03-06 12:27:56 +0000 | [diff] [blame] | 7359 | // OpenMP [2.14.3.2, Restrictions, p.1] |
| 7360 | // A variable that is part of another variable (as an array or structure |
| 7361 | // element) cannot appear in a shared unless it is a static data member |
| 7362 | // of a C++ class. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7363 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7364 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7365 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr) |
| 7366 | << 0 << RefExpr->getSourceRange(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7367 | continue; |
| 7368 | } |
| 7369 | Decl *D = DE->getDecl(); |
| 7370 | VarDecl *VD = cast<VarDecl>(D); |
| 7371 | |
| 7372 | QualType Type = VD->getType(); |
| 7373 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 7374 | // It will be analyzed later. |
| 7375 | Vars.push_back(DE); |
| 7376 | continue; |
| 7377 | } |
| 7378 | |
| 7379 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 7380 | // in a Construct] |
| 7381 | // Variables with the predetermined data-sharing attributes may not be |
| 7382 | // listed in data-sharing attributes clauses, except for the cases |
| 7383 | // listed below. For these exceptions only, listing a predetermined |
| 7384 | // variable in a data-sharing attribute clause is allowed and overrides |
| 7385 | // the variable's predetermined data-sharing attributes. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7386 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7387 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared && |
| 7388 | DVar.RefExpr) { |
| 7389 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 7390 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 7391 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7392 | continue; |
| 7393 | } |
| 7394 | |
| 7395 | DSAStack->addDSA(VD, DE, OMPC_shared); |
| 7396 | Vars.push_back(DE); |
| 7397 | } |
| 7398 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7399 | if (Vars.empty()) |
| 7400 | return nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7401 | |
| 7402 | return OMPSharedClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars); |
| 7403 | } |
| 7404 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7405 | namespace { |
| 7406 | class DSARefChecker : public StmtVisitor<DSARefChecker, bool> { |
| 7407 | DSAStackTy *Stack; |
| 7408 | |
| 7409 | public: |
| 7410 | bool VisitDeclRefExpr(DeclRefExpr *E) { |
| 7411 | if (VarDecl *VD = dyn_cast<VarDecl>(E->getDecl())) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7412 | DSAStackTy::DSAVarData DVar = Stack->getTopDSA(VD, false); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7413 | if (DVar.CKind == OMPC_shared && !DVar.RefExpr) |
| 7414 | return false; |
| 7415 | if (DVar.CKind != OMPC_unknown) |
| 7416 | return true; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7417 | DSAStackTy::DSAVarData DVarPrivate = |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7418 | Stack->hasDSA(VD, isOpenMPPrivate, MatchesAlways(), false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7419 | if (DVarPrivate.CKind != OMPC_unknown) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7420 | return true; |
| 7421 | return false; |
| 7422 | } |
| 7423 | return false; |
| 7424 | } |
| 7425 | bool VisitStmt(Stmt *S) { |
| 7426 | for (auto Child : S->children()) { |
| 7427 | if (Child && Visit(Child)) |
| 7428 | return true; |
| 7429 | } |
| 7430 | return false; |
| 7431 | } |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 7432 | explicit DSARefChecker(DSAStackTy *S) : Stack(S) {} |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7433 | }; |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 7434 | } // namespace |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7435 | |
| 7436 | OMPClause *Sema::ActOnOpenMPReductionClause( |
| 7437 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, SourceLocation LParenLoc, |
| 7438 | SourceLocation ColonLoc, SourceLocation EndLoc, |
| 7439 | CXXScopeSpec &ReductionIdScopeSpec, |
| 7440 | const DeclarationNameInfo &ReductionId) { |
| 7441 | // TODO: Allow scope specification search when 'declare reduction' is |
| 7442 | // supported. |
| 7443 | assert(ReductionIdScopeSpec.isEmpty() && |
| 7444 | "No support for scoped reduction identifiers yet."); |
| 7445 | |
| 7446 | auto DN = ReductionId.getName(); |
| 7447 | auto OOK = DN.getCXXOverloadedOperator(); |
| 7448 | BinaryOperatorKind BOK = BO_Comma; |
| 7449 | |
| 7450 | // OpenMP [2.14.3.6, reduction clause] |
| 7451 | // C |
| 7452 | // reduction-identifier is either an identifier or one of the following |
| 7453 | // operators: +, -, *, &, |, ^, && and || |
| 7454 | // C++ |
| 7455 | // reduction-identifier is either an id-expression or one of the following |
| 7456 | // operators: +, -, *, &, |, ^, && and || |
| 7457 | // FIXME: Only 'min' and 'max' identifiers are supported for now. |
| 7458 | switch (OOK) { |
| 7459 | case OO_Plus: |
| 7460 | case OO_Minus: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7461 | BOK = BO_Add; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7462 | break; |
| 7463 | case OO_Star: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7464 | BOK = BO_Mul; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7465 | break; |
| 7466 | case OO_Amp: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7467 | BOK = BO_And; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7468 | break; |
| 7469 | case OO_Pipe: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7470 | BOK = BO_Or; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7471 | break; |
| 7472 | case OO_Caret: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7473 | BOK = BO_Xor; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7474 | break; |
| 7475 | case OO_AmpAmp: |
| 7476 | BOK = BO_LAnd; |
| 7477 | break; |
| 7478 | case OO_PipePipe: |
| 7479 | BOK = BO_LOr; |
| 7480 | break; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7481 | case OO_New: |
| 7482 | case OO_Delete: |
| 7483 | case OO_Array_New: |
| 7484 | case OO_Array_Delete: |
| 7485 | case OO_Slash: |
| 7486 | case OO_Percent: |
| 7487 | case OO_Tilde: |
| 7488 | case OO_Exclaim: |
| 7489 | case OO_Equal: |
| 7490 | case OO_Less: |
| 7491 | case OO_Greater: |
| 7492 | case OO_LessEqual: |
| 7493 | case OO_GreaterEqual: |
| 7494 | case OO_PlusEqual: |
| 7495 | case OO_MinusEqual: |
| 7496 | case OO_StarEqual: |
| 7497 | case OO_SlashEqual: |
| 7498 | case OO_PercentEqual: |
| 7499 | case OO_CaretEqual: |
| 7500 | case OO_AmpEqual: |
| 7501 | case OO_PipeEqual: |
| 7502 | case OO_LessLess: |
| 7503 | case OO_GreaterGreater: |
| 7504 | case OO_LessLessEqual: |
| 7505 | case OO_GreaterGreaterEqual: |
| 7506 | case OO_EqualEqual: |
| 7507 | case OO_ExclaimEqual: |
| 7508 | case OO_PlusPlus: |
| 7509 | case OO_MinusMinus: |
| 7510 | case OO_Comma: |
| 7511 | case OO_ArrowStar: |
| 7512 | case OO_Arrow: |
| 7513 | case OO_Call: |
| 7514 | case OO_Subscript: |
| 7515 | case OO_Conditional: |
Richard Smith | 9be594e | 2015-10-22 05:12:22 +0000 | [diff] [blame] | 7516 | case OO_Coawait: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7517 | case NUM_OVERLOADED_OPERATORS: |
| 7518 | llvm_unreachable("Unexpected reduction identifier"); |
| 7519 | case OO_None: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7520 | if (auto II = DN.getAsIdentifierInfo()) { |
| 7521 | if (II->isStr("max")) |
| 7522 | BOK = BO_GT; |
| 7523 | else if (II->isStr("min")) |
| 7524 | BOK = BO_LT; |
| 7525 | } |
| 7526 | break; |
| 7527 | } |
| 7528 | SourceRange ReductionIdRange; |
| 7529 | if (ReductionIdScopeSpec.isValid()) { |
| 7530 | ReductionIdRange.setBegin(ReductionIdScopeSpec.getBeginLoc()); |
| 7531 | } |
| 7532 | ReductionIdRange.setEnd(ReductionId.getEndLoc()); |
| 7533 | if (BOK == BO_Comma) { |
| 7534 | // Not allowed reduction identifier is found. |
| 7535 | Diag(ReductionId.getLocStart(), diag::err_omp_unknown_reduction_identifier) |
| 7536 | << ReductionIdRange; |
| 7537 | return nullptr; |
| 7538 | } |
| 7539 | |
| 7540 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7541 | SmallVector<Expr *, 8> Privates; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7542 | SmallVector<Expr *, 8> LHSs; |
| 7543 | SmallVector<Expr *, 8> RHSs; |
| 7544 | SmallVector<Expr *, 8> ReductionOps; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7545 | for (auto RefExpr : VarList) { |
| 7546 | assert(RefExpr && "nullptr expr in OpenMP reduction clause."); |
| 7547 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 7548 | // It will be analyzed later. |
| 7549 | Vars.push_back(RefExpr); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7550 | Privates.push_back(nullptr); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7551 | LHSs.push_back(nullptr); |
| 7552 | RHSs.push_back(nullptr); |
| 7553 | ReductionOps.push_back(nullptr); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7554 | continue; |
| 7555 | } |
| 7556 | |
| 7557 | if (RefExpr->isTypeDependent() || RefExpr->isValueDependent() || |
| 7558 | RefExpr->isInstantiationDependent() || |
| 7559 | RefExpr->containsUnexpandedParameterPack()) { |
| 7560 | // It will be analyzed later. |
| 7561 | Vars.push_back(RefExpr); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7562 | Privates.push_back(nullptr); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7563 | LHSs.push_back(nullptr); |
| 7564 | RHSs.push_back(nullptr); |
| 7565 | ReductionOps.push_back(nullptr); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7566 | continue; |
| 7567 | } |
| 7568 | |
| 7569 | auto ELoc = RefExpr->getExprLoc(); |
| 7570 | auto ERange = RefExpr->getSourceRange(); |
| 7571 | // OpenMP [2.1, C/C++] |
| 7572 | // A list item is a variable or array section, subject to the restrictions |
| 7573 | // specified in Section 2.4 on page 42 and in each of the sections |
| 7574 | // describing clauses and directives for which a list appears. |
| 7575 | // OpenMP [2.14.3.3, Restrictions, p.1] |
| 7576 | // A variable that is part of another variable (as an array or |
| 7577 | // structure element) cannot appear in a private clause. |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7578 | auto *DE = dyn_cast<DeclRefExpr>(RefExpr); |
| 7579 | auto *ASE = dyn_cast<ArraySubscriptExpr>(RefExpr); |
| 7580 | auto *OASE = dyn_cast<OMPArraySectionExpr>(RefExpr); |
| 7581 | if (!ASE && !OASE && (!DE || !isa<VarDecl>(DE->getDecl()))) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7582 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr_or_array_item) |
| 7583 | << 0 << ERange; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7584 | continue; |
| 7585 | } |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7586 | QualType Type; |
| 7587 | VarDecl *VD = nullptr; |
| 7588 | if (DE) { |
| 7589 | auto D = DE->getDecl(); |
| 7590 | VD = cast<VarDecl>(D); |
Alexey Bataev | 1189bd0 | 2016-01-26 12:20:39 +0000 | [diff] [blame] | 7591 | Type = Context.getBaseElementType(VD->getType()); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7592 | } else if (ASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7593 | Type = ASE->getType(); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7594 | auto *Base = ASE->getBase()->IgnoreParenImpCasts(); |
| 7595 | while (auto *TempASE = dyn_cast<ArraySubscriptExpr>(Base)) |
| 7596 | Base = TempASE->getBase()->IgnoreParenImpCasts(); |
| 7597 | DE = dyn_cast<DeclRefExpr>(Base); |
| 7598 | if (DE) |
| 7599 | VD = dyn_cast<VarDecl>(DE->getDecl()); |
| 7600 | if (!VD) { |
| 7601 | Diag(Base->getExprLoc(), diag::err_omp_expected_base_var_name) |
| 7602 | << 0 << Base->getSourceRange(); |
| 7603 | continue; |
| 7604 | } |
| 7605 | } else if (OASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7606 | auto BaseType = OMPArraySectionExpr::getBaseOriginalType(OASE->getBase()); |
| 7607 | if (auto *ATy = BaseType->getAsArrayTypeUnsafe()) |
| 7608 | Type = ATy->getElementType(); |
| 7609 | else |
| 7610 | Type = BaseType->getPointeeType(); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7611 | auto *Base = OASE->getBase()->IgnoreParenImpCasts(); |
| 7612 | while (auto *TempOASE = dyn_cast<OMPArraySectionExpr>(Base)) |
| 7613 | Base = TempOASE->getBase()->IgnoreParenImpCasts(); |
| 7614 | while (auto *TempASE = dyn_cast<ArraySubscriptExpr>(Base)) |
| 7615 | Base = TempASE->getBase()->IgnoreParenImpCasts(); |
| 7616 | DE = dyn_cast<DeclRefExpr>(Base); |
| 7617 | if (DE) |
| 7618 | VD = dyn_cast<VarDecl>(DE->getDecl()); |
| 7619 | if (!VD) { |
| 7620 | Diag(Base->getExprLoc(), diag::err_omp_expected_base_var_name) |
| 7621 | << 1 << Base->getSourceRange(); |
| 7622 | continue; |
| 7623 | } |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7624 | } |
| 7625 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7626 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 7627 | // A variable that appears in a private clause must not have an incomplete |
| 7628 | // type or a reference type. |
| 7629 | if (RequireCompleteType(ELoc, Type, |
| 7630 | diag::err_omp_reduction_incomplete_type)) |
| 7631 | continue; |
| 7632 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7633 | // A list item that appears in a reduction clause must not be |
| 7634 | // const-qualified. |
| 7635 | if (Type.getNonReferenceType().isConstant(Context)) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7636 | Diag(ELoc, diag::err_omp_const_reduction_list_item) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7637 | << getOpenMPClauseName(OMPC_reduction) << Type << ERange; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7638 | if (!ASE && !OASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7639 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 7640 | VarDecl::DeclarationOnly; |
| 7641 | Diag(VD->getLocation(), |
| 7642 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7643 | << VD; |
| 7644 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7645 | continue; |
| 7646 | } |
| 7647 | // OpenMP [2.9.3.6, Restrictions, C/C++, p.4] |
| 7648 | // If a list-item is a reference type then it must bind to the same object |
| 7649 | // for all threads of the team. |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7650 | if (!ASE && !OASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7651 | VarDecl *VDDef = VD->getDefinition(); |
| 7652 | if (Type->isReferenceType() && VDDef) { |
| 7653 | DSARefChecker Check(DSAStack); |
| 7654 | if (Check.Visit(VDDef->getInit())) { |
| 7655 | Diag(ELoc, diag::err_omp_reduction_ref_type_arg) << ERange; |
| 7656 | Diag(VDDef->getLocation(), diag::note_defined_here) << VDDef; |
| 7657 | continue; |
| 7658 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7659 | } |
| 7660 | } |
| 7661 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
| 7662 | // The type of a list item that appears in a reduction clause must be valid |
| 7663 | // for the reduction-identifier. For a max or min reduction in C, the type |
| 7664 | // of the list item must be an allowed arithmetic data type: char, int, |
| 7665 | // float, double, or _Bool, possibly modified with long, short, signed, or |
| 7666 | // unsigned. For a max or min reduction in C++, the type of the list item |
| 7667 | // must be an allowed arithmetic data type: char, wchar_t, int, float, |
| 7668 | // double, or bool, possibly modified with long, short, signed, or unsigned. |
| 7669 | if ((BOK == BO_GT || BOK == BO_LT) && |
| 7670 | !(Type->isScalarType() || |
| 7671 | (getLangOpts().CPlusPlus && Type->isArithmeticType()))) { |
| 7672 | Diag(ELoc, diag::err_omp_clause_not_arithmetic_type_arg) |
| 7673 | << getLangOpts().CPlusPlus; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7674 | if (!ASE && !OASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7675 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 7676 | VarDecl::DeclarationOnly; |
| 7677 | Diag(VD->getLocation(), |
| 7678 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7679 | << VD; |
| 7680 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7681 | continue; |
| 7682 | } |
| 7683 | if ((BOK == BO_OrAssign || BOK == BO_AndAssign || BOK == BO_XorAssign) && |
| 7684 | !getLangOpts().CPlusPlus && Type->isFloatingType()) { |
| 7685 | Diag(ELoc, diag::err_omp_clause_floating_type_arg); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7686 | if (!ASE && !OASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7687 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 7688 | VarDecl::DeclarationOnly; |
| 7689 | Diag(VD->getLocation(), |
| 7690 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7691 | << VD; |
| 7692 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7693 | continue; |
| 7694 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7695 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 7696 | // in a Construct] |
| 7697 | // Variables with the predetermined data-sharing attributes may not be |
| 7698 | // listed in data-sharing attributes clauses, except for the cases |
| 7699 | // listed below. For these exceptions only, listing a predetermined |
| 7700 | // variable in a data-sharing attribute clause is allowed and overrides |
| 7701 | // the variable's predetermined data-sharing attributes. |
| 7702 | // OpenMP [2.14.3.6, Restrictions, p.3] |
| 7703 | // Any number of reduction clauses can be specified on the directive, |
| 7704 | // but a list item can appear only once in the reduction clauses for that |
| 7705 | // directive. |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7706 | DSAStackTy::DSAVarData DVar; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7707 | DVar = DSAStack->getTopDSA(VD, false); |
| 7708 | if (DVar.CKind == OMPC_reduction) { |
| 7709 | Diag(ELoc, diag::err_omp_once_referenced) |
| 7710 | << getOpenMPClauseName(OMPC_reduction); |
| 7711 | if (DVar.RefExpr) { |
| 7712 | Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_referenced); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7713 | } |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7714 | } else if (DVar.CKind != OMPC_unknown) { |
| 7715 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 7716 | << getOpenMPClauseName(DVar.CKind) |
| 7717 | << getOpenMPClauseName(OMPC_reduction); |
| 7718 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 7719 | continue; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7720 | } |
| 7721 | |
| 7722 | // OpenMP [2.14.3.6, Restrictions, p.1] |
| 7723 | // A list item that appears in a reduction clause of a worksharing |
| 7724 | // construct must be shared in the parallel regions to which any of the |
| 7725 | // worksharing regions arising from the worksharing construct bind. |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7726 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
| 7727 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 7728 | !isOpenMPParallelDirective(CurrDir)) { |
| 7729 | DVar = DSAStack->getImplicitDSA(VD, true); |
| 7730 | if (DVar.CKind != OMPC_shared) { |
| 7731 | Diag(ELoc, diag::err_omp_required_access) |
| 7732 | << getOpenMPClauseName(OMPC_reduction) |
| 7733 | << getOpenMPClauseName(OMPC_shared); |
| 7734 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 7735 | continue; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7736 | } |
| 7737 | } |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7738 | |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7739 | Type = Type.getNonLValueExprType(Context).getUnqualifiedType(); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7740 | auto *LHSVD = buildVarDecl(*this, ELoc, Type, ".reduction.lhs", |
| 7741 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
| 7742 | auto *RHSVD = buildVarDecl(*this, ELoc, Type, VD->getName(), |
| 7743 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
| 7744 | auto PrivateTy = Type; |
Alexey Bataev | 1189bd0 | 2016-01-26 12:20:39 +0000 | [diff] [blame] | 7745 | if (OASE || |
| 7746 | (DE && VD->getType().getNonReferenceType()->isVariablyModifiedType())) { |
| 7747 | // For arays/array sections only: |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7748 | // Create pseudo array type for private copy. The size for this array will |
| 7749 | // be generated during codegen. |
| 7750 | // For array subscripts or single variables Private Ty is the same as Type |
| 7751 | // (type of the variable or single array element). |
| 7752 | PrivateTy = Context.getVariableArrayType( |
| 7753 | Type, new (Context) OpaqueValueExpr(SourceLocation(), |
| 7754 | Context.getSizeType(), VK_RValue), |
| 7755 | ArrayType::Normal, /*IndexTypeQuals=*/0, SourceRange()); |
Alexey Bataev | 1189bd0 | 2016-01-26 12:20:39 +0000 | [diff] [blame] | 7756 | } else if (DE && |
| 7757 | Context.getAsArrayType(VD->getType().getNonReferenceType())) |
| 7758 | PrivateTy = VD->getType().getNonReferenceType(); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7759 | // Private copy. |
| 7760 | auto *PrivateVD = buildVarDecl(*this, ELoc, PrivateTy, VD->getName(), |
| 7761 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7762 | // Add initializer for private variable. |
| 7763 | Expr *Init = nullptr; |
| 7764 | switch (BOK) { |
| 7765 | case BO_Add: |
| 7766 | case BO_Xor: |
| 7767 | case BO_Or: |
| 7768 | case BO_LOr: |
| 7769 | // '+', '-', '^', '|', '||' reduction ops - initializer is '0'. |
| 7770 | if (Type->isScalarType() || Type->isAnyComplexType()) { |
| 7771 | Init = ActOnIntegerConstant(ELoc, /*Val=*/0).get(); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7772 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7773 | break; |
| 7774 | case BO_Mul: |
| 7775 | case BO_LAnd: |
| 7776 | if (Type->isScalarType() || Type->isAnyComplexType()) { |
| 7777 | // '*' and '&&' reduction ops - initializer is '1'. |
| 7778 | Init = ActOnIntegerConstant(ELoc, /*Val=*/1).get(); |
| 7779 | } |
| 7780 | break; |
| 7781 | case BO_And: { |
| 7782 | // '&' reduction op - initializer is '~0'. |
| 7783 | QualType OrigType = Type; |
| 7784 | if (auto *ComplexTy = OrigType->getAs<ComplexType>()) { |
| 7785 | Type = ComplexTy->getElementType(); |
| 7786 | } |
| 7787 | if (Type->isRealFloatingType()) { |
| 7788 | llvm::APFloat InitValue = |
| 7789 | llvm::APFloat::getAllOnesValue(Context.getTypeSize(Type), |
| 7790 | /*isIEEE=*/true); |
| 7791 | Init = FloatingLiteral::Create(Context, InitValue, /*isexact=*/true, |
| 7792 | Type, ELoc); |
| 7793 | } else if (Type->isScalarType()) { |
| 7794 | auto Size = Context.getTypeSize(Type); |
| 7795 | QualType IntTy = Context.getIntTypeForBitwidth(Size, /*Signed=*/0); |
| 7796 | llvm::APInt InitValue = llvm::APInt::getAllOnesValue(Size); |
| 7797 | Init = IntegerLiteral::Create(Context, InitValue, IntTy, ELoc); |
| 7798 | } |
| 7799 | if (Init && OrigType->isAnyComplexType()) { |
| 7800 | // Init = 0xFFFF + 0xFFFFi; |
| 7801 | auto *Im = new (Context) ImaginaryLiteral(Init, OrigType); |
| 7802 | Init = CreateBuiltinBinOp(ELoc, BO_Add, Init, Im).get(); |
| 7803 | } |
| 7804 | Type = OrigType; |
| 7805 | break; |
| 7806 | } |
| 7807 | case BO_LT: |
| 7808 | case BO_GT: { |
| 7809 | // 'min' reduction op - initializer is 'Largest representable number in |
| 7810 | // the reduction list item type'. |
| 7811 | // 'max' reduction op - initializer is 'Least representable number in |
| 7812 | // the reduction list item type'. |
| 7813 | if (Type->isIntegerType() || Type->isPointerType()) { |
| 7814 | bool IsSigned = Type->hasSignedIntegerRepresentation(); |
| 7815 | auto Size = Context.getTypeSize(Type); |
| 7816 | QualType IntTy = |
| 7817 | Context.getIntTypeForBitwidth(Size, /*Signed=*/IsSigned); |
| 7818 | llvm::APInt InitValue = |
| 7819 | (BOK != BO_LT) |
| 7820 | ? IsSigned ? llvm::APInt::getSignedMinValue(Size) |
| 7821 | : llvm::APInt::getMinValue(Size) |
| 7822 | : IsSigned ? llvm::APInt::getSignedMaxValue(Size) |
| 7823 | : llvm::APInt::getMaxValue(Size); |
| 7824 | Init = IntegerLiteral::Create(Context, InitValue, IntTy, ELoc); |
| 7825 | if (Type->isPointerType()) { |
| 7826 | // Cast to pointer type. |
| 7827 | auto CastExpr = BuildCStyleCastExpr( |
| 7828 | SourceLocation(), Context.getTrivialTypeSourceInfo(Type, ELoc), |
| 7829 | SourceLocation(), Init); |
| 7830 | if (CastExpr.isInvalid()) |
| 7831 | continue; |
| 7832 | Init = CastExpr.get(); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7833 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7834 | } else if (Type->isRealFloatingType()) { |
| 7835 | llvm::APFloat InitValue = llvm::APFloat::getLargest( |
| 7836 | Context.getFloatTypeSemantics(Type), BOK != BO_LT); |
| 7837 | Init = FloatingLiteral::Create(Context, InitValue, /*isexact=*/true, |
| 7838 | Type, ELoc); |
| 7839 | } |
| 7840 | break; |
| 7841 | } |
| 7842 | case BO_PtrMemD: |
| 7843 | case BO_PtrMemI: |
| 7844 | case BO_MulAssign: |
| 7845 | case BO_Div: |
| 7846 | case BO_Rem: |
| 7847 | case BO_Sub: |
| 7848 | case BO_Shl: |
| 7849 | case BO_Shr: |
| 7850 | case BO_LE: |
| 7851 | case BO_GE: |
| 7852 | case BO_EQ: |
| 7853 | case BO_NE: |
| 7854 | case BO_AndAssign: |
| 7855 | case BO_XorAssign: |
| 7856 | case BO_OrAssign: |
| 7857 | case BO_Assign: |
| 7858 | case BO_AddAssign: |
| 7859 | case BO_SubAssign: |
| 7860 | case BO_DivAssign: |
| 7861 | case BO_RemAssign: |
| 7862 | case BO_ShlAssign: |
| 7863 | case BO_ShrAssign: |
| 7864 | case BO_Comma: |
| 7865 | llvm_unreachable("Unexpected reduction operation"); |
| 7866 | } |
| 7867 | if (Init) { |
| 7868 | AddInitializerToDecl(RHSVD, Init, /*DirectInit=*/false, |
| 7869 | /*TypeMayContainAuto=*/false); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7870 | } else |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7871 | ActOnUninitializedDecl(RHSVD, /*TypeMayContainAuto=*/false); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7872 | if (!RHSVD->hasInit()) { |
| 7873 | Diag(ELoc, diag::err_omp_reduction_id_not_compatible) << Type |
| 7874 | << ReductionIdRange; |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7875 | if (VD) { |
| 7876 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 7877 | VarDecl::DeclarationOnly; |
| 7878 | Diag(VD->getLocation(), |
| 7879 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7880 | << VD; |
| 7881 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7882 | continue; |
| 7883 | } |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7884 | // Store initializer for single element in private copy. Will be used during |
| 7885 | // codegen. |
| 7886 | PrivateVD->setInit(RHSVD->getInit()); |
| 7887 | PrivateVD->setInitStyle(RHSVD->getInitStyle()); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7888 | auto *LHSDRE = buildDeclRefExpr(*this, LHSVD, Type, ELoc); |
| 7889 | auto *RHSDRE = buildDeclRefExpr(*this, RHSVD, Type, ELoc); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7890 | auto *PrivateDRE = buildDeclRefExpr(*this, PrivateVD, PrivateTy, ELoc); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7891 | ExprResult ReductionOp = |
| 7892 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), BOK, |
| 7893 | LHSDRE, RHSDRE); |
| 7894 | if (ReductionOp.isUsable()) { |
Alexey Bataev | 69a4779 | 2015-05-07 03:54:03 +0000 | [diff] [blame] | 7895 | if (BOK != BO_LT && BOK != BO_GT) { |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7896 | ReductionOp = |
| 7897 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), |
| 7898 | BO_Assign, LHSDRE, ReductionOp.get()); |
| 7899 | } else { |
| 7900 | auto *ConditionalOp = new (Context) ConditionalOperator( |
| 7901 | ReductionOp.get(), SourceLocation(), LHSDRE, SourceLocation(), |
| 7902 | RHSDRE, Type, VK_LValue, OK_Ordinary); |
| 7903 | ReductionOp = |
| 7904 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), |
| 7905 | BO_Assign, LHSDRE, ConditionalOp); |
| 7906 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 7907 | ReductionOp = ActOnFinishFullExpr(ReductionOp.get()); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7908 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7909 | if (ReductionOp.isInvalid()) |
| 7910 | continue; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7911 | |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7912 | DSAStack->addDSA(VD, DE, OMPC_reduction); |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7913 | Vars.push_back(RefExpr); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7914 | Privates.push_back(PrivateDRE); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7915 | LHSs.push_back(LHSDRE); |
| 7916 | RHSs.push_back(RHSDRE); |
| 7917 | ReductionOps.push_back(ReductionOp.get()); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7918 | } |
| 7919 | |
| 7920 | if (Vars.empty()) |
| 7921 | return nullptr; |
| 7922 | |
| 7923 | return OMPReductionClause::Create( |
| 7924 | Context, StartLoc, LParenLoc, ColonLoc, EndLoc, Vars, |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7925 | ReductionIdScopeSpec.getWithLocInContext(Context), ReductionId, Privates, |
| 7926 | LHSs, RHSs, ReductionOps); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7927 | } |
| 7928 | |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 7929 | OMPClause *Sema::ActOnOpenMPLinearClause( |
| 7930 | ArrayRef<Expr *> VarList, Expr *Step, SourceLocation StartLoc, |
| 7931 | SourceLocation LParenLoc, OpenMPLinearClauseKind LinKind, |
| 7932 | SourceLocation LinLoc, SourceLocation ColonLoc, SourceLocation EndLoc) { |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7933 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7934 | SmallVector<Expr *, 8> Privates; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7935 | SmallVector<Expr *, 8> Inits; |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 7936 | if ((!LangOpts.CPlusPlus && LinKind != OMPC_LINEAR_val) || |
| 7937 | LinKind == OMPC_LINEAR_unknown) { |
| 7938 | Diag(LinLoc, diag::err_omp_wrong_linear_modifier) << LangOpts.CPlusPlus; |
| 7939 | LinKind = OMPC_LINEAR_val; |
| 7940 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7941 | for (auto &RefExpr : VarList) { |
| 7942 | assert(RefExpr && "NULL expr in OpenMP linear clause."); |
| 7943 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7944 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7945 | Vars.push_back(RefExpr); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7946 | Privates.push_back(nullptr); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7947 | Inits.push_back(nullptr); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7948 | continue; |
| 7949 | } |
| 7950 | |
| 7951 | // OpenMP [2.14.3.7, linear clause] |
| 7952 | // A list item that appears in a linear clause is subject to the private |
| 7953 | // clause semantics described in Section 2.14.3.3 on page 159 except as |
| 7954 | // noted. In addition, the value of the new list item on each iteration |
| 7955 | // of the associated loop(s) corresponds to the value of the original |
| 7956 | // list item before entering the construct plus the logical number of |
| 7957 | // the iteration times linear-step. |
| 7958 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7959 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7960 | // OpenMP [2.1, C/C++] |
| 7961 | // A list item is a variable name. |
| 7962 | // OpenMP [2.14.3.3, Restrictions, p.1] |
| 7963 | // A variable that is part of another variable (as an array or |
| 7964 | // structure element) cannot appear in a private clause. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7965 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7966 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7967 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr) |
| 7968 | << 0 << RefExpr->getSourceRange(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7969 | continue; |
| 7970 | } |
| 7971 | |
| 7972 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); |
| 7973 | |
| 7974 | // OpenMP [2.14.3.7, linear clause] |
| 7975 | // A list-item cannot appear in more than one linear clause. |
| 7976 | // A list-item that appears in a linear clause cannot appear in any |
| 7977 | // other data-sharing attribute clause. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7978 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7979 | if (DVar.RefExpr) { |
| 7980 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 7981 | << getOpenMPClauseName(OMPC_linear); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 7982 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7983 | continue; |
| 7984 | } |
| 7985 | |
| 7986 | QualType QType = VD->getType(); |
| 7987 | if (QType->isDependentType() || QType->isInstantiationDependentType()) { |
| 7988 | // It will be analyzed later. |
| 7989 | Vars.push_back(DE); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7990 | Privates.push_back(nullptr); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7991 | Inits.push_back(nullptr); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7992 | continue; |
| 7993 | } |
| 7994 | |
| 7995 | // A variable must not have an incomplete type or a reference type. |
| 7996 | if (RequireCompleteType(ELoc, QType, |
| 7997 | diag::err_omp_linear_incomplete_type)) { |
| 7998 | continue; |
| 7999 | } |
Alexey Bataev | 1185e19 | 2015-08-20 12:15:57 +0000 | [diff] [blame] | 8000 | if ((LinKind == OMPC_LINEAR_uval || LinKind == OMPC_LINEAR_ref) && |
| 8001 | !QType->isReferenceType()) { |
| 8002 | Diag(ELoc, diag::err_omp_wrong_linear_modifier_non_reference) |
| 8003 | << QType << getOpenMPSimpleClauseTypeName(OMPC_linear, LinKind); |
| 8004 | continue; |
| 8005 | } |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8006 | QType = QType.getNonReferenceType(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8007 | |
| 8008 | // A list item must not be const-qualified. |
| 8009 | if (QType.isConstant(Context)) { |
| 8010 | Diag(ELoc, diag::err_omp_const_variable) |
| 8011 | << getOpenMPClauseName(OMPC_linear); |
| 8012 | bool IsDecl = |
| 8013 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 8014 | Diag(VD->getLocation(), |
| 8015 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 8016 | << VD; |
| 8017 | continue; |
| 8018 | } |
| 8019 | |
| 8020 | // A list item must be of integral or pointer type. |
| 8021 | QType = QType.getUnqualifiedType().getCanonicalType(); |
| 8022 | const Type *Ty = QType.getTypePtrOrNull(); |
| 8023 | if (!Ty || (!Ty->isDependentType() && !Ty->isIntegralType(Context) && |
| 8024 | !Ty->isPointerType())) { |
| 8025 | Diag(ELoc, diag::err_omp_linear_expected_int_or_ptr) << QType; |
| 8026 | bool IsDecl = |
| 8027 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 8028 | Diag(VD->getLocation(), |
| 8029 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 8030 | << VD; |
| 8031 | continue; |
| 8032 | } |
| 8033 | |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8034 | // Build private copy of original var. |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 8035 | auto *Private = buildVarDecl(*this, ELoc, QType, VD->getName(), |
| 8036 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8037 | auto *PrivateRef = buildDeclRefExpr( |
| 8038 | *this, Private, DE->getType().getUnqualifiedType(), DE->getExprLoc()); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8039 | // Build var to save initial value. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8040 | VarDecl *Init = buildVarDecl(*this, ELoc, QType, ".linear.start"); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 8041 | Expr *InitExpr; |
| 8042 | if (LinKind == OMPC_LINEAR_uval) |
| 8043 | InitExpr = VD->getInit(); |
| 8044 | else |
| 8045 | InitExpr = DE; |
| 8046 | AddInitializerToDecl(Init, DefaultLvalueConversion(InitExpr).get(), |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8047 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8048 | auto InitRef = buildDeclRefExpr( |
| 8049 | *this, Init, DE->getType().getUnqualifiedType(), DE->getExprLoc()); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8050 | DSAStack->addDSA(VD, DE, OMPC_linear); |
| 8051 | Vars.push_back(DE); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8052 | Privates.push_back(PrivateRef); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8053 | Inits.push_back(InitRef); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8054 | } |
| 8055 | |
| 8056 | if (Vars.empty()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 8057 | return nullptr; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8058 | |
| 8059 | Expr *StepExpr = Step; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8060 | Expr *CalcStepExpr = nullptr; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8061 | if (Step && !Step->isValueDependent() && !Step->isTypeDependent() && |
| 8062 | !Step->isInstantiationDependent() && |
| 8063 | !Step->containsUnexpandedParameterPack()) { |
| 8064 | SourceLocation StepLoc = Step->getLocStart(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 8065 | ExprResult Val = PerformOpenMPImplicitIntegerConversion(StepLoc, Step); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8066 | if (Val.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 8067 | return nullptr; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 8068 | StepExpr = Val.get(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8069 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8070 | // Build var to save the step value. |
| 8071 | VarDecl *SaveVar = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 8072 | buildVarDecl(*this, StepLoc, StepExpr->getType(), ".linear.step"); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8073 | ExprResult SaveRef = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 8074 | buildDeclRefExpr(*this, SaveVar, StepExpr->getType(), StepLoc); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8075 | ExprResult CalcStep = |
| 8076 | BuildBinOp(CurScope, StepLoc, BO_Assign, SaveRef.get(), StepExpr); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 8077 | CalcStep = ActOnFinishFullExpr(CalcStep.get()); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8078 | |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8079 | // Warn about zero linear step (it would be probably better specified as |
| 8080 | // making corresponding variables 'const'). |
| 8081 | llvm::APSInt Result; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8082 | bool IsConstant = StepExpr->isIntegerConstantExpr(Result, Context); |
| 8083 | if (IsConstant && !Result.isNegative() && !Result.isStrictlyPositive()) |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8084 | Diag(StepLoc, diag::warn_omp_linear_step_zero) << Vars[0] |
| 8085 | << (Vars.size() > 1); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8086 | if (!IsConstant && CalcStep.isUsable()) { |
| 8087 | // Calculate the step beforehand instead of doing this on each iteration. |
| 8088 | // (This is not used if the number of iterations may be kfold-ed). |
| 8089 | CalcStepExpr = CalcStep.get(); |
| 8090 | } |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8091 | } |
| 8092 | |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 8093 | return OMPLinearClause::Create(Context, StartLoc, LParenLoc, LinKind, LinLoc, |
| 8094 | ColonLoc, EndLoc, Vars, Privates, Inits, |
| 8095 | StepExpr, CalcStepExpr); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8096 | } |
| 8097 | |
| 8098 | static bool FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV, |
| 8099 | Expr *NumIterations, Sema &SemaRef, |
| 8100 | Scope *S) { |
| 8101 | // Walk the vars and build update/final expressions for the CodeGen. |
| 8102 | SmallVector<Expr *, 8> Updates; |
| 8103 | SmallVector<Expr *, 8> Finals; |
| 8104 | Expr *Step = Clause.getStep(); |
| 8105 | Expr *CalcStep = Clause.getCalcStep(); |
| 8106 | // OpenMP [2.14.3.7, linear clause] |
| 8107 | // If linear-step is not specified it is assumed to be 1. |
| 8108 | if (Step == nullptr) |
| 8109 | Step = SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get(); |
| 8110 | else if (CalcStep) |
| 8111 | Step = cast<BinaryOperator>(CalcStep)->getLHS(); |
| 8112 | bool HasErrors = false; |
| 8113 | auto CurInit = Clause.inits().begin(); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8114 | auto CurPrivate = Clause.privates().begin(); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 8115 | auto LinKind = Clause.getModifier(); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8116 | for (auto &RefExpr : Clause.varlists()) { |
| 8117 | Expr *InitExpr = *CurInit; |
| 8118 | |
| 8119 | // Build privatized reference to the current linear var. |
| 8120 | auto DE = cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 8121 | Expr *CapturedRef; |
| 8122 | if (LinKind == OMPC_LINEAR_uval) |
| 8123 | CapturedRef = cast<VarDecl>(DE->getDecl())->getInit(); |
| 8124 | else |
| 8125 | CapturedRef = |
| 8126 | buildDeclRefExpr(SemaRef, cast<VarDecl>(DE->getDecl()), |
| 8127 | DE->getType().getUnqualifiedType(), DE->getExprLoc(), |
| 8128 | /*RefersToCapture=*/true); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8129 | |
| 8130 | // Build update: Var = InitExpr + IV * Step |
| 8131 | ExprResult Update = |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8132 | BuildCounterUpdate(SemaRef, S, RefExpr->getExprLoc(), *CurPrivate, |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8133 | InitExpr, IV, Step, /* Subtract */ false); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 8134 | Update = SemaRef.ActOnFinishFullExpr(Update.get(), DE->getLocStart(), |
| 8135 | /*DiscardedValue=*/true); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8136 | |
| 8137 | // Build final: Var = InitExpr + NumIterations * Step |
| 8138 | ExprResult Final = |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8139 | BuildCounterUpdate(SemaRef, S, RefExpr->getExprLoc(), CapturedRef, |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 8140 | InitExpr, NumIterations, Step, /* Subtract */ false); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 8141 | Final = SemaRef.ActOnFinishFullExpr(Final.get(), DE->getLocStart(), |
| 8142 | /*DiscardedValue=*/true); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8143 | if (!Update.isUsable() || !Final.isUsable()) { |
| 8144 | Updates.push_back(nullptr); |
| 8145 | Finals.push_back(nullptr); |
| 8146 | HasErrors = true; |
| 8147 | } else { |
| 8148 | Updates.push_back(Update.get()); |
| 8149 | Finals.push_back(Final.get()); |
| 8150 | } |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8151 | ++CurInit, ++CurPrivate; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8152 | } |
| 8153 | Clause.setUpdates(Updates); |
| 8154 | Clause.setFinals(Finals); |
| 8155 | return HasErrors; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8156 | } |
| 8157 | |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 8158 | OMPClause *Sema::ActOnOpenMPAlignedClause( |
| 8159 | ArrayRef<Expr *> VarList, Expr *Alignment, SourceLocation StartLoc, |
| 8160 | SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc) { |
| 8161 | |
| 8162 | SmallVector<Expr *, 8> Vars; |
| 8163 | for (auto &RefExpr : VarList) { |
| 8164 | assert(RefExpr && "NULL expr in OpenMP aligned clause."); |
| 8165 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 8166 | // It will be analyzed later. |
| 8167 | Vars.push_back(RefExpr); |
| 8168 | continue; |
| 8169 | } |
| 8170 | |
| 8171 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 8172 | // OpenMP [2.1, C/C++] |
| 8173 | // A list item is a variable name. |
| 8174 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
| 8175 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8176 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr) |
| 8177 | << 0 << RefExpr->getSourceRange(); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 8178 | continue; |
| 8179 | } |
| 8180 | |
| 8181 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); |
| 8182 | |
| 8183 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 8184 | // The type of list items appearing in the aligned clause must be |
| 8185 | // array, pointer, reference to array, or reference to pointer. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8186 | QualType QType = VD->getType(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8187 | QType = QType.getNonReferenceType().getUnqualifiedType().getCanonicalType(); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 8188 | const Type *Ty = QType.getTypePtrOrNull(); |
| 8189 | if (!Ty || (!Ty->isDependentType() && !Ty->isArrayType() && |
| 8190 | !Ty->isPointerType())) { |
| 8191 | Diag(ELoc, diag::err_omp_aligned_expected_array_or_ptr) |
| 8192 | << QType << getLangOpts().CPlusPlus << RefExpr->getSourceRange(); |
| 8193 | bool IsDecl = |
| 8194 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 8195 | Diag(VD->getLocation(), |
| 8196 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 8197 | << VD; |
| 8198 | continue; |
| 8199 | } |
| 8200 | |
| 8201 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 8202 | // A list-item cannot appear in more than one aligned clause. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8203 | if (Expr *PrevRef = DSAStack->addUniqueAligned(VD, DE)) { |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 8204 | Diag(ELoc, diag::err_omp_aligned_twice) << RefExpr->getSourceRange(); |
| 8205 | Diag(PrevRef->getExprLoc(), diag::note_omp_explicit_dsa) |
| 8206 | << getOpenMPClauseName(OMPC_aligned); |
| 8207 | continue; |
| 8208 | } |
| 8209 | |
| 8210 | Vars.push_back(DE); |
| 8211 | } |
| 8212 | |
| 8213 | // OpenMP [2.8.1, simd construct, Description] |
| 8214 | // The parameter of the aligned clause, alignment, must be a constant |
| 8215 | // positive integer expression. |
| 8216 | // If no optional parameter is specified, implementation-defined default |
| 8217 | // alignments for SIMD instructions on the target platforms are assumed. |
| 8218 | if (Alignment != nullptr) { |
| 8219 | ExprResult AlignResult = |
| 8220 | VerifyPositiveIntegerConstantInClause(Alignment, OMPC_aligned); |
| 8221 | if (AlignResult.isInvalid()) |
| 8222 | return nullptr; |
| 8223 | Alignment = AlignResult.get(); |
| 8224 | } |
| 8225 | if (Vars.empty()) |
| 8226 | return nullptr; |
| 8227 | |
| 8228 | return OMPAlignedClause::Create(Context, StartLoc, LParenLoc, ColonLoc, |
| 8229 | EndLoc, Vars, Alignment); |
| 8230 | } |
| 8231 | |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8232 | OMPClause *Sema::ActOnOpenMPCopyinClause(ArrayRef<Expr *> VarList, |
| 8233 | SourceLocation StartLoc, |
| 8234 | SourceLocation LParenLoc, |
| 8235 | SourceLocation EndLoc) { |
| 8236 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 8237 | SmallVector<Expr *, 8> SrcExprs; |
| 8238 | SmallVector<Expr *, 8> DstExprs; |
| 8239 | SmallVector<Expr *, 8> AssignmentOps; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8240 | for (auto &RefExpr : VarList) { |
| 8241 | assert(RefExpr && "NULL expr in OpenMP copyin clause."); |
| 8242 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8243 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8244 | Vars.push_back(RefExpr); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 8245 | SrcExprs.push_back(nullptr); |
| 8246 | DstExprs.push_back(nullptr); |
| 8247 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8248 | continue; |
| 8249 | } |
| 8250 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8251 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8252 | // OpenMP [2.1, C/C++] |
| 8253 | // A list item is a variable name. |
| 8254 | // OpenMP [2.14.4.1, Restrictions, p.1] |
| 8255 | // A list item that appears in a copyin clause must be threadprivate. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8256 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8257 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8258 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr) |
| 8259 | << 0 << RefExpr->getSourceRange(); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8260 | continue; |
| 8261 | } |
| 8262 | |
| 8263 | Decl *D = DE->getDecl(); |
| 8264 | VarDecl *VD = cast<VarDecl>(D); |
| 8265 | |
| 8266 | QualType Type = VD->getType(); |
| 8267 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 8268 | // It will be analyzed later. |
| 8269 | Vars.push_back(DE); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 8270 | SrcExprs.push_back(nullptr); |
| 8271 | DstExprs.push_back(nullptr); |
| 8272 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8273 | continue; |
| 8274 | } |
| 8275 | |
| 8276 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.1] |
| 8277 | // A list item that appears in a copyin clause must be threadprivate. |
| 8278 | if (!DSAStack->isThreadPrivate(VD)) { |
| 8279 | Diag(ELoc, diag::err_omp_required_access) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8280 | << getOpenMPClauseName(OMPC_copyin) |
| 8281 | << getOpenMPDirectiveName(OMPD_threadprivate); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8282 | continue; |
| 8283 | } |
| 8284 | |
| 8285 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.2] |
| 8286 | // A variable of class type (or array thereof) that appears in a |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 8287 | // copyin clause requires an accessible, unambiguous copy assignment |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8288 | // operator for the class type. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8289 | auto ElemType = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 8290 | auto *SrcVD = |
| 8291 | buildVarDecl(*this, DE->getLocStart(), ElemType.getUnqualifiedType(), |
| 8292 | ".copyin.src", VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 8293 | auto *PseudoSrcExpr = buildDeclRefExpr( |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8294 | *this, SrcVD, ElemType.getUnqualifiedType(), DE->getExprLoc()); |
| 8295 | auto *DstVD = |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 8296 | buildVarDecl(*this, DE->getLocStart(), ElemType, ".copyin.dst", |
| 8297 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 8298 | auto *PseudoDstExpr = |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8299 | buildDeclRefExpr(*this, DstVD, ElemType, DE->getExprLoc()); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 8300 | // For arrays generate assignment operation for single element and replace |
| 8301 | // it by the original array element in CodeGen. |
| 8302 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, DE->getExprLoc(), BO_Assign, |
| 8303 | PseudoDstExpr, PseudoSrcExpr); |
| 8304 | if (AssignmentOp.isInvalid()) |
| 8305 | continue; |
| 8306 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), DE->getExprLoc(), |
| 8307 | /*DiscardedValue=*/true); |
| 8308 | if (AssignmentOp.isInvalid()) |
| 8309 | continue; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8310 | |
| 8311 | DSAStack->addDSA(VD, DE, OMPC_copyin); |
| 8312 | Vars.push_back(DE); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 8313 | SrcExprs.push_back(PseudoSrcExpr); |
| 8314 | DstExprs.push_back(PseudoDstExpr); |
| 8315 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8316 | } |
| 8317 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8318 | if (Vars.empty()) |
| 8319 | return nullptr; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8320 | |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 8321 | return OMPCopyinClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
| 8322 | SrcExprs, DstExprs, AssignmentOps); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8323 | } |
| 8324 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8325 | OMPClause *Sema::ActOnOpenMPCopyprivateClause(ArrayRef<Expr *> VarList, |
| 8326 | SourceLocation StartLoc, |
| 8327 | SourceLocation LParenLoc, |
| 8328 | SourceLocation EndLoc) { |
| 8329 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 8330 | SmallVector<Expr *, 8> SrcExprs; |
| 8331 | SmallVector<Expr *, 8> DstExprs; |
| 8332 | SmallVector<Expr *, 8> AssignmentOps; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8333 | for (auto &RefExpr : VarList) { |
| 8334 | assert(RefExpr && "NULL expr in OpenMP copyprivate clause."); |
| 8335 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 8336 | // It will be analyzed later. |
| 8337 | Vars.push_back(RefExpr); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 8338 | SrcExprs.push_back(nullptr); |
| 8339 | DstExprs.push_back(nullptr); |
| 8340 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8341 | continue; |
| 8342 | } |
| 8343 | |
| 8344 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 8345 | // OpenMP [2.1, C/C++] |
| 8346 | // A list item is a variable name. |
| 8347 | // OpenMP [2.14.4.1, Restrictions, p.1] |
| 8348 | // A list item that appears in a copyin clause must be threadprivate. |
| 8349 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
| 8350 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8351 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr) |
| 8352 | << 0 << RefExpr->getSourceRange(); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8353 | continue; |
| 8354 | } |
| 8355 | |
| 8356 | Decl *D = DE->getDecl(); |
| 8357 | VarDecl *VD = cast<VarDecl>(D); |
| 8358 | |
| 8359 | QualType Type = VD->getType(); |
| 8360 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 8361 | // It will be analyzed later. |
| 8362 | Vars.push_back(DE); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 8363 | SrcExprs.push_back(nullptr); |
| 8364 | DstExprs.push_back(nullptr); |
| 8365 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8366 | continue; |
| 8367 | } |
| 8368 | |
| 8369 | // OpenMP [2.14.4.2, Restrictions, p.2] |
| 8370 | // A list item that appears in a copyprivate clause may not appear in a |
| 8371 | // private or firstprivate clause on the single construct. |
| 8372 | if (!DSAStack->isThreadPrivate(VD)) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 8373 | auto DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 8374 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_copyprivate && |
| 8375 | DVar.RefExpr) { |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8376 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 8377 | << getOpenMPClauseName(DVar.CKind) |
| 8378 | << getOpenMPClauseName(OMPC_copyprivate); |
| 8379 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 8380 | continue; |
| 8381 | } |
| 8382 | |
| 8383 | // OpenMP [2.11.4.2, Restrictions, p.1] |
| 8384 | // All list items that appear in a copyprivate clause must be either |
| 8385 | // threadprivate or private in the enclosing context. |
| 8386 | if (DVar.CKind == OMPC_unknown) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 8387 | DVar = DSAStack->getImplicitDSA(VD, false); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8388 | if (DVar.CKind == OMPC_shared) { |
| 8389 | Diag(ELoc, diag::err_omp_required_access) |
| 8390 | << getOpenMPClauseName(OMPC_copyprivate) |
| 8391 | << "threadprivate or private in the enclosing context"; |
| 8392 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 8393 | continue; |
| 8394 | } |
| 8395 | } |
| 8396 | } |
| 8397 | |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 8398 | // Variably modified types are not supported. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 8399 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType()) { |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 8400 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8401 | << getOpenMPClauseName(OMPC_copyprivate) << Type |
| 8402 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 8403 | bool IsDecl = |
| 8404 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 8405 | Diag(VD->getLocation(), |
| 8406 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 8407 | << VD; |
| 8408 | continue; |
| 8409 | } |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8410 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8411 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.2] |
| 8412 | // A variable of class type (or array thereof) that appears in a |
| 8413 | // copyin clause requires an accessible, unambiguous copy assignment |
| 8414 | // operator for the class type. |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8415 | Type = Context.getBaseElementType(Type.getNonReferenceType()) |
| 8416 | .getUnqualifiedType(); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 8417 | auto *SrcVD = |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 8418 | buildVarDecl(*this, DE->getLocStart(), Type, ".copyprivate.src", |
| 8419 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 8420 | auto *PseudoSrcExpr = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 8421 | buildDeclRefExpr(*this, SrcVD, Type, DE->getExprLoc()); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 8422 | auto *DstVD = |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 8423 | buildVarDecl(*this, DE->getLocStart(), Type, ".copyprivate.dst", |
| 8424 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 8425 | auto *PseudoDstExpr = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 8426 | buildDeclRefExpr(*this, DstVD, Type, DE->getExprLoc()); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 8427 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, DE->getExprLoc(), BO_Assign, |
| 8428 | PseudoDstExpr, PseudoSrcExpr); |
| 8429 | if (AssignmentOp.isInvalid()) |
| 8430 | continue; |
| 8431 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), DE->getExprLoc(), |
| 8432 | /*DiscardedValue=*/true); |
| 8433 | if (AssignmentOp.isInvalid()) |
| 8434 | continue; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8435 | |
| 8436 | // No need to mark vars as copyprivate, they are already threadprivate or |
| 8437 | // implicitly private. |
| 8438 | Vars.push_back(DE); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 8439 | SrcExprs.push_back(PseudoSrcExpr); |
| 8440 | DstExprs.push_back(PseudoDstExpr); |
| 8441 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8442 | } |
| 8443 | |
| 8444 | if (Vars.empty()) |
| 8445 | return nullptr; |
| 8446 | |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 8447 | return OMPCopyprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| 8448 | Vars, SrcExprs, DstExprs, AssignmentOps); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8449 | } |
| 8450 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 8451 | OMPClause *Sema::ActOnOpenMPFlushClause(ArrayRef<Expr *> VarList, |
| 8452 | SourceLocation StartLoc, |
| 8453 | SourceLocation LParenLoc, |
| 8454 | SourceLocation EndLoc) { |
| 8455 | if (VarList.empty()) |
| 8456 | return nullptr; |
| 8457 | |
| 8458 | return OMPFlushClause::Create(Context, StartLoc, LParenLoc, EndLoc, VarList); |
| 8459 | } |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 8460 | |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8461 | OMPClause * |
| 8462 | Sema::ActOnOpenMPDependClause(OpenMPDependClauseKind DepKind, |
| 8463 | SourceLocation DepLoc, SourceLocation ColonLoc, |
| 8464 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
| 8465 | SourceLocation LParenLoc, SourceLocation EndLoc) { |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 8466 | if (DSAStack->getCurrentDirective() == OMPD_ordered && |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 8467 | DepKind != OMPC_DEPEND_source && DepKind != OMPC_DEPEND_sink) { |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 8468 | Diag(DepLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 8469 | << "'source' or 'sink'" << getOpenMPClauseName(OMPC_depend); |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 8470 | return nullptr; |
| 8471 | } |
| 8472 | if (DSAStack->getCurrentDirective() != OMPD_ordered && |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 8473 | (DepKind == OMPC_DEPEND_unknown || DepKind == OMPC_DEPEND_source || |
| 8474 | DepKind == OMPC_DEPEND_sink)) { |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 8475 | unsigned Except[] = {OMPC_DEPEND_source, OMPC_DEPEND_sink}; |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8476 | Diag(DepLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 8477 | << getListOfPossibleValues(OMPC_depend, /*First=*/0, |
| 8478 | /*Last=*/OMPC_DEPEND_unknown, Except) |
| 8479 | << getOpenMPClauseName(OMPC_depend); |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8480 | return nullptr; |
| 8481 | } |
| 8482 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 8483 | llvm::APSInt DepCounter(/*BitWidth=*/32); |
| 8484 | llvm::APSInt TotalDepCount(/*BitWidth=*/32); |
| 8485 | if (DepKind == OMPC_DEPEND_sink) { |
| 8486 | if (auto *OrderedCountExpr = DSAStack->getParentOrderedRegionParam()) { |
| 8487 | TotalDepCount = OrderedCountExpr->EvaluateKnownConstInt(Context); |
| 8488 | TotalDepCount.setIsUnsigned(/*Val=*/true); |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8489 | } |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8490 | } |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 8491 | if ((DepKind != OMPC_DEPEND_sink && DepKind != OMPC_DEPEND_source) || |
| 8492 | DSAStack->getParentOrderedRegionParam()) { |
| 8493 | for (auto &RefExpr : VarList) { |
| 8494 | assert(RefExpr && "NULL expr in OpenMP shared clause."); |
| 8495 | if (isa<DependentScopeDeclRefExpr>(RefExpr) || |
| 8496 | (DepKind == OMPC_DEPEND_sink && CurContext->isDependentContext())) { |
| 8497 | // It will be analyzed later. |
| 8498 | Vars.push_back(RefExpr); |
| 8499 | continue; |
| 8500 | } |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8501 | |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 8502 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 8503 | auto *SimpleExpr = RefExpr->IgnoreParenCasts(); |
| 8504 | if (DepKind == OMPC_DEPEND_sink) { |
| 8505 | if (DepCounter >= TotalDepCount) { |
| 8506 | Diag(ELoc, diag::err_omp_depend_sink_unexpected_expr); |
| 8507 | continue; |
| 8508 | } |
| 8509 | ++DepCounter; |
| 8510 | // OpenMP [2.13.9, Summary] |
| 8511 | // depend(dependence-type : vec), where dependence-type is: |
| 8512 | // 'sink' and where vec is the iteration vector, which has the form: |
| 8513 | // x1 [+- d1], x2 [+- d2 ], . . . , xn [+- dn] |
| 8514 | // where n is the value specified by the ordered clause in the loop |
| 8515 | // directive, xi denotes the loop iteration variable of the i-th nested |
| 8516 | // loop associated with the loop directive, and di is a constant |
| 8517 | // non-negative integer. |
| 8518 | SimpleExpr = SimpleExpr->IgnoreImplicit(); |
| 8519 | auto *DE = dyn_cast<DeclRefExpr>(SimpleExpr); |
| 8520 | if (!DE) { |
| 8521 | OverloadedOperatorKind OOK = OO_None; |
| 8522 | SourceLocation OOLoc; |
| 8523 | Expr *LHS, *RHS; |
| 8524 | if (auto *BO = dyn_cast<BinaryOperator>(SimpleExpr)) { |
| 8525 | OOK = BinaryOperator::getOverloadedOperator(BO->getOpcode()); |
| 8526 | OOLoc = BO->getOperatorLoc(); |
| 8527 | LHS = BO->getLHS()->IgnoreParenImpCasts(); |
| 8528 | RHS = BO->getRHS()->IgnoreParenImpCasts(); |
| 8529 | } else if (auto *OCE = dyn_cast<CXXOperatorCallExpr>(SimpleExpr)) { |
| 8530 | OOK = OCE->getOperator(); |
| 8531 | OOLoc = OCE->getOperatorLoc(); |
| 8532 | LHS = OCE->getArg(/*Arg=*/0)->IgnoreParenImpCasts(); |
| 8533 | RHS = OCE->getArg(/*Arg=*/1)->IgnoreParenImpCasts(); |
| 8534 | } else if (auto *MCE = dyn_cast<CXXMemberCallExpr>(SimpleExpr)) { |
| 8535 | OOK = MCE->getMethodDecl() |
| 8536 | ->getNameInfo() |
| 8537 | .getName() |
| 8538 | .getCXXOverloadedOperator(); |
| 8539 | OOLoc = MCE->getCallee()->getExprLoc(); |
| 8540 | LHS = MCE->getImplicitObjectArgument()->IgnoreParenImpCasts(); |
| 8541 | RHS = MCE->getArg(/*Arg=*/0)->IgnoreParenImpCasts(); |
| 8542 | } else { |
| 8543 | Diag(ELoc, diag::err_omp_depend_sink_wrong_expr); |
| 8544 | continue; |
| 8545 | } |
| 8546 | DE = dyn_cast<DeclRefExpr>(LHS); |
| 8547 | if (!DE) { |
| 8548 | Diag(LHS->getExprLoc(), |
| 8549 | diag::err_omp_depend_sink_expected_loop_iteration) |
| 8550 | << DSAStack->getParentLoopControlVariable( |
| 8551 | DepCounter.getZExtValue()); |
| 8552 | continue; |
| 8553 | } |
| 8554 | if (OOK != OO_Plus && OOK != OO_Minus) { |
| 8555 | Diag(OOLoc, diag::err_omp_depend_sink_expected_plus_minus); |
| 8556 | continue; |
| 8557 | } |
| 8558 | ExprResult Res = VerifyPositiveIntegerConstantInClause( |
| 8559 | RHS, OMPC_depend, /*StrictlyPositive=*/false); |
| 8560 | if (Res.isInvalid()) |
| 8561 | continue; |
| 8562 | } |
| 8563 | auto *VD = dyn_cast<VarDecl>(DE->getDecl()); |
| 8564 | if (!CurContext->isDependentContext() && |
| 8565 | DSAStack->getParentOrderedRegionParam() && |
| 8566 | (!VD || DepCounter != DSAStack->isParentLoopControlVariable(VD))) { |
| 8567 | Diag(DE->getExprLoc(), |
| 8568 | diag::err_omp_depend_sink_expected_loop_iteration) |
| 8569 | << DSAStack->getParentLoopControlVariable( |
| 8570 | DepCounter.getZExtValue()); |
| 8571 | continue; |
| 8572 | } |
| 8573 | } else { |
| 8574 | // OpenMP [2.11.1.1, Restrictions, p.3] |
| 8575 | // A variable that is part of another variable (such as a field of a |
| 8576 | // structure) but is not an array element or an array section cannot |
| 8577 | // appear in a depend clause. |
| 8578 | auto *DE = dyn_cast<DeclRefExpr>(SimpleExpr); |
| 8579 | auto *ASE = dyn_cast<ArraySubscriptExpr>(SimpleExpr); |
| 8580 | auto *OASE = dyn_cast<OMPArraySectionExpr>(SimpleExpr); |
| 8581 | if (!RefExpr->IgnoreParenImpCasts()->isLValue() || |
| 8582 | (!ASE && !DE && !OASE) || (DE && !isa<VarDecl>(DE->getDecl())) || |
| 8583 | (ASE && !ASE->getBase()->getType()->isAnyPointerType() && |
| 8584 | !ASE->getBase()->getType()->isArrayType())) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8585 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr_or_array_item) |
| 8586 | << 0 << RefExpr->getSourceRange(); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 8587 | continue; |
| 8588 | } |
| 8589 | } |
| 8590 | |
| 8591 | Vars.push_back(RefExpr->IgnoreParenImpCasts()); |
| 8592 | } |
| 8593 | |
| 8594 | if (!CurContext->isDependentContext() && DepKind == OMPC_DEPEND_sink && |
| 8595 | TotalDepCount > VarList.size() && |
| 8596 | DSAStack->getParentOrderedRegionParam()) { |
| 8597 | Diag(EndLoc, diag::err_omp_depend_sink_expected_loop_iteration) |
| 8598 | << DSAStack->getParentLoopControlVariable(VarList.size() + 1); |
| 8599 | } |
| 8600 | if (DepKind != OMPC_DEPEND_source && DepKind != OMPC_DEPEND_sink && |
| 8601 | Vars.empty()) |
| 8602 | return nullptr; |
| 8603 | } |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8604 | |
| 8605 | return OMPDependClause::Create(Context, StartLoc, LParenLoc, EndLoc, DepKind, |
| 8606 | DepLoc, ColonLoc, Vars); |
| 8607 | } |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 8608 | |
| 8609 | OMPClause *Sema::ActOnOpenMPDeviceClause(Expr *Device, SourceLocation StartLoc, |
| 8610 | SourceLocation LParenLoc, |
| 8611 | SourceLocation EndLoc) { |
| 8612 | Expr *ValExpr = Device; |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 8613 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 8614 | // OpenMP [2.9.1, Restrictions] |
| 8615 | // The device expression must evaluate to a non-negative integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 8616 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_device, |
| 8617 | /*StrictlyPositive=*/false)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 8618 | return nullptr; |
| 8619 | |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 8620 | return new (Context) OMPDeviceClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 8621 | } |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 8622 | |
| 8623 | static bool IsCXXRecordForMappable(Sema &SemaRef, SourceLocation Loc, |
| 8624 | DSAStackTy *Stack, CXXRecordDecl *RD) { |
| 8625 | if (!RD || RD->isInvalidDecl()) |
| 8626 | return true; |
| 8627 | |
Alexey Bataev | c9bd03d | 2015-12-17 06:55:08 +0000 | [diff] [blame] | 8628 | if (auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(RD)) |
| 8629 | if (auto *CTD = CTSD->getSpecializedTemplate()) |
| 8630 | RD = CTD->getTemplatedDecl(); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 8631 | auto QTy = SemaRef.Context.getRecordType(RD); |
| 8632 | if (RD->isDynamicClass()) { |
| 8633 | SemaRef.Diag(Loc, diag::err_omp_not_mappable_type) << QTy; |
| 8634 | SemaRef.Diag(RD->getLocation(), diag::note_omp_polymorphic_in_target); |
| 8635 | return false; |
| 8636 | } |
| 8637 | auto *DC = RD; |
| 8638 | bool IsCorrect = true; |
| 8639 | for (auto *I : DC->decls()) { |
| 8640 | if (I) { |
| 8641 | if (auto *MD = dyn_cast<CXXMethodDecl>(I)) { |
| 8642 | if (MD->isStatic()) { |
| 8643 | SemaRef.Diag(Loc, diag::err_omp_not_mappable_type) << QTy; |
| 8644 | SemaRef.Diag(MD->getLocation(), |
| 8645 | diag::note_omp_static_member_in_target); |
| 8646 | IsCorrect = false; |
| 8647 | } |
| 8648 | } else if (auto *VD = dyn_cast<VarDecl>(I)) { |
| 8649 | if (VD->isStaticDataMember()) { |
| 8650 | SemaRef.Diag(Loc, diag::err_omp_not_mappable_type) << QTy; |
| 8651 | SemaRef.Diag(VD->getLocation(), |
| 8652 | diag::note_omp_static_member_in_target); |
| 8653 | IsCorrect = false; |
| 8654 | } |
| 8655 | } |
| 8656 | } |
| 8657 | } |
| 8658 | |
| 8659 | for (auto &I : RD->bases()) { |
| 8660 | if (!IsCXXRecordForMappable(SemaRef, I.getLocStart(), Stack, |
| 8661 | I.getType()->getAsCXXRecordDecl())) |
| 8662 | IsCorrect = false; |
| 8663 | } |
| 8664 | return IsCorrect; |
| 8665 | } |
| 8666 | |
| 8667 | static bool CheckTypeMappable(SourceLocation SL, SourceRange SR, Sema &SemaRef, |
| 8668 | DSAStackTy *Stack, QualType QTy) { |
| 8669 | NamedDecl *ND; |
| 8670 | if (QTy->isIncompleteType(&ND)) { |
| 8671 | SemaRef.Diag(SL, diag::err_incomplete_type) << QTy << SR; |
| 8672 | return false; |
| 8673 | } else if (CXXRecordDecl *RD = dyn_cast_or_null<CXXRecordDecl>(ND)) { |
| 8674 | if (!RD->isInvalidDecl() && |
| 8675 | !IsCXXRecordForMappable(SemaRef, SL, Stack, RD)) |
| 8676 | return false; |
| 8677 | } |
| 8678 | return true; |
| 8679 | } |
| 8680 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 8681 | // Return the expression of the base of the map clause or null if it cannot |
| 8682 | // be determined and do all the necessary checks to see if the expression is |
| 8683 | // valid as a standalone map clause expression. |
| 8684 | static Expr *CheckMapClauseExpressionBase(Sema &SemaRef, Expr *E) { |
| 8685 | SourceLocation ELoc = E->getExprLoc(); |
| 8686 | SourceRange ERange = E->getSourceRange(); |
| 8687 | |
| 8688 | // The base of elements of list in a map clause have to be either: |
| 8689 | // - a reference to variable or field. |
| 8690 | // - a member expression. |
| 8691 | // - an array expression. |
| 8692 | // |
| 8693 | // E.g. if we have the expression 'r.S.Arr[:12]', we want to retrieve the |
| 8694 | // reference to 'r'. |
| 8695 | // |
| 8696 | // If we have: |
| 8697 | // |
| 8698 | // struct SS { |
| 8699 | // Bla S; |
| 8700 | // foo() { |
| 8701 | // #pragma omp target map (S.Arr[:12]); |
| 8702 | // } |
| 8703 | // } |
| 8704 | // |
| 8705 | // We want to retrieve the member expression 'this->S'; |
| 8706 | |
| 8707 | Expr *RelevantExpr = nullptr; |
| 8708 | |
| 8709 | // Flags to help capture some memory |
| 8710 | |
| 8711 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.2] |
| 8712 | // If a list item is an array section, it must specify contiguous storage. |
| 8713 | // |
| 8714 | // For this restriction it is sufficient that we make sure only references |
| 8715 | // to variables or fields and array expressions, and that no array sections |
| 8716 | // exist except in the rightmost expression. E.g. these would be invalid: |
| 8717 | // |
| 8718 | // r.ArrS[3:5].Arr[6:7] |
| 8719 | // |
| 8720 | // r.ArrS[3:5].x |
| 8721 | // |
| 8722 | // but these would be valid: |
| 8723 | // r.ArrS[3].Arr[6:7] |
| 8724 | // |
| 8725 | // r.ArrS[3].x |
| 8726 | |
| 8727 | bool IsRightMostExpression = true; |
| 8728 | |
| 8729 | while (!RelevantExpr) { |
| 8730 | auto AllowArraySection = IsRightMostExpression; |
| 8731 | IsRightMostExpression = false; |
| 8732 | |
| 8733 | E = E->IgnoreParenImpCasts(); |
| 8734 | |
| 8735 | if (auto *CurE = dyn_cast<DeclRefExpr>(E)) { |
| 8736 | if (!isa<VarDecl>(CurE->getDecl())) |
| 8737 | break; |
| 8738 | |
| 8739 | RelevantExpr = CurE; |
| 8740 | continue; |
| 8741 | } |
| 8742 | |
| 8743 | if (auto *CurE = dyn_cast<MemberExpr>(E)) { |
| 8744 | auto *BaseE = CurE->getBase()->IgnoreParenImpCasts(); |
| 8745 | |
| 8746 | if (isa<CXXThisExpr>(BaseE)) |
| 8747 | // We found a base expression: this->Val. |
| 8748 | RelevantExpr = CurE; |
| 8749 | else |
| 8750 | E = BaseE; |
| 8751 | |
| 8752 | if (!isa<FieldDecl>(CurE->getMemberDecl())) { |
| 8753 | SemaRef.Diag(ELoc, diag::err_omp_expected_access_to_data_field) |
| 8754 | << CurE->getSourceRange(); |
| 8755 | break; |
| 8756 | } |
| 8757 | |
| 8758 | auto *FD = cast<FieldDecl>(CurE->getMemberDecl()); |
| 8759 | |
| 8760 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C/C++, p.3] |
| 8761 | // A bit-field cannot appear in a map clause. |
| 8762 | // |
| 8763 | if (FD->isBitField()) { |
| 8764 | SemaRef.Diag(ELoc, diag::err_omp_bit_fields_forbidden_in_map_clause) |
| 8765 | << CurE->getSourceRange(); |
| 8766 | break; |
| 8767 | } |
| 8768 | |
| 8769 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] |
| 8770 | // If the type of a list item is a reference to a type T then the type |
| 8771 | // will be considered to be T for all purposes of this clause. |
| 8772 | QualType CurType = BaseE->getType(); |
| 8773 | if (CurType->isReferenceType()) |
| 8774 | CurType = CurType->getPointeeType(); |
| 8775 | |
| 8776 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C/C++, p.2] |
| 8777 | // A list item cannot be a variable that is a member of a structure with |
| 8778 | // a union type. |
| 8779 | // |
| 8780 | if (auto *RT = CurType->getAs<RecordType>()) |
| 8781 | if (RT->isUnionType()) { |
| 8782 | SemaRef.Diag(ELoc, diag::err_omp_union_type_not_allowed) |
| 8783 | << CurE->getSourceRange(); |
| 8784 | break; |
| 8785 | } |
| 8786 | |
| 8787 | continue; |
| 8788 | } |
| 8789 | |
| 8790 | if (auto *CurE = dyn_cast<ArraySubscriptExpr>(E)) { |
| 8791 | E = CurE->getBase()->IgnoreParenImpCasts(); |
| 8792 | |
| 8793 | if (!E->getType()->isAnyPointerType() && !E->getType()->isArrayType()) { |
| 8794 | SemaRef.Diag(ELoc, diag::err_omp_expected_base_var_name) |
| 8795 | << 0 << CurE->getSourceRange(); |
| 8796 | break; |
| 8797 | } |
| 8798 | continue; |
| 8799 | } |
| 8800 | |
| 8801 | if (auto *CurE = dyn_cast<OMPArraySectionExpr>(E)) { |
| 8802 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.7] |
| 8803 | // If a list item is an element of a structure, only the rightmost symbol |
| 8804 | // of the variable reference can be an array section. |
| 8805 | // |
| 8806 | if (!AllowArraySection) { |
| 8807 | SemaRef.Diag(ELoc, diag::err_omp_array_section_in_rightmost_expression) |
| 8808 | << CurE->getSourceRange(); |
| 8809 | break; |
| 8810 | } |
| 8811 | |
| 8812 | E = CurE->getBase()->IgnoreParenImpCasts(); |
| 8813 | |
| 8814 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] |
| 8815 | // If the type of a list item is a reference to a type T then the type |
| 8816 | // will be considered to be T for all purposes of this clause. |
| 8817 | QualType CurType = E->getType(); |
| 8818 | if (CurType->isReferenceType()) |
| 8819 | CurType = CurType->getPointeeType(); |
| 8820 | |
| 8821 | if (!CurType->isAnyPointerType() && !CurType->isArrayType()) { |
| 8822 | SemaRef.Diag(ELoc, diag::err_omp_expected_base_var_name) |
| 8823 | << 0 << CurE->getSourceRange(); |
| 8824 | break; |
| 8825 | } |
| 8826 | |
| 8827 | continue; |
| 8828 | } |
| 8829 | |
| 8830 | // If nothing else worked, this is not a valid map clause expression. |
| 8831 | SemaRef.Diag(ELoc, |
| 8832 | diag::err_omp_expected_named_var_member_or_array_expression) |
| 8833 | << ERange; |
| 8834 | break; |
| 8835 | } |
| 8836 | |
| 8837 | return RelevantExpr; |
| 8838 | } |
| 8839 | |
| 8840 | // Return true if expression E associated with value VD has conflicts with other |
| 8841 | // map information. |
| 8842 | static bool CheckMapConflicts(Sema &SemaRef, DSAStackTy *DSAS, ValueDecl *VD, |
| 8843 | Expr *E, bool CurrentRegionOnly) { |
| 8844 | assert(VD && E); |
| 8845 | |
| 8846 | // Types used to organize the components of a valid map clause. |
| 8847 | typedef std::pair<Expr *, ValueDecl *> MapExpressionComponent; |
| 8848 | typedef SmallVector<MapExpressionComponent, 4> MapExpressionComponents; |
| 8849 | |
| 8850 | // Helper to extract the components in the map clause expression E and store |
| 8851 | // them into MEC. This assumes that E is a valid map clause expression, i.e. |
| 8852 | // it has already passed the single clause checks. |
| 8853 | auto ExtractMapExpressionComponents = [](Expr *TE, |
| 8854 | MapExpressionComponents &MEC) { |
| 8855 | while (true) { |
| 8856 | TE = TE->IgnoreParenImpCasts(); |
| 8857 | |
| 8858 | if (auto *CurE = dyn_cast<DeclRefExpr>(TE)) { |
| 8859 | MEC.push_back( |
| 8860 | MapExpressionComponent(CurE, cast<VarDecl>(CurE->getDecl()))); |
| 8861 | break; |
| 8862 | } |
| 8863 | |
| 8864 | if (auto *CurE = dyn_cast<MemberExpr>(TE)) { |
| 8865 | auto *BaseE = CurE->getBase()->IgnoreParenImpCasts(); |
| 8866 | |
| 8867 | MEC.push_back(MapExpressionComponent( |
| 8868 | CurE, cast<FieldDecl>(CurE->getMemberDecl()))); |
| 8869 | if (isa<CXXThisExpr>(BaseE)) |
| 8870 | break; |
| 8871 | |
| 8872 | TE = BaseE; |
| 8873 | continue; |
| 8874 | } |
| 8875 | |
| 8876 | if (auto *CurE = dyn_cast<ArraySubscriptExpr>(TE)) { |
| 8877 | MEC.push_back(MapExpressionComponent(CurE, nullptr)); |
| 8878 | TE = CurE->getBase()->IgnoreParenImpCasts(); |
| 8879 | continue; |
| 8880 | } |
| 8881 | |
| 8882 | if (auto *CurE = dyn_cast<OMPArraySectionExpr>(TE)) { |
| 8883 | MEC.push_back(MapExpressionComponent(CurE, nullptr)); |
| 8884 | TE = CurE->getBase()->IgnoreParenImpCasts(); |
| 8885 | continue; |
| 8886 | } |
| 8887 | |
| 8888 | llvm_unreachable( |
| 8889 | "Expecting only valid map clause expressions at this point!"); |
| 8890 | } |
| 8891 | }; |
| 8892 | |
| 8893 | SourceLocation ELoc = E->getExprLoc(); |
| 8894 | SourceRange ERange = E->getSourceRange(); |
| 8895 | |
| 8896 | // In order to easily check the conflicts we need to match each component of |
| 8897 | // the expression under test with the components of the expressions that are |
| 8898 | // already in the stack. |
| 8899 | |
| 8900 | MapExpressionComponents CurComponents; |
| 8901 | ExtractMapExpressionComponents(E, CurComponents); |
| 8902 | |
| 8903 | assert(!CurComponents.empty() && "Map clause expression with no components!"); |
| 8904 | assert(CurComponents.back().second == VD && |
| 8905 | "Map clause expression with unexpected base!"); |
| 8906 | |
| 8907 | // Variables to help detecting enclosing problems in data environment nests. |
| 8908 | bool IsEnclosedByDataEnvironmentExpr = false; |
| 8909 | Expr *EnclosingExpr = nullptr; |
| 8910 | |
| 8911 | bool FoundError = |
| 8912 | DSAS->checkMapInfoForVar(VD, CurrentRegionOnly, [&](Expr *RE) -> bool { |
| 8913 | MapExpressionComponents StackComponents; |
| 8914 | ExtractMapExpressionComponents(RE, StackComponents); |
| 8915 | assert(!StackComponents.empty() && |
| 8916 | "Map clause expression with no components!"); |
| 8917 | assert(StackComponents.back().second == VD && |
| 8918 | "Map clause expression with unexpected base!"); |
| 8919 | |
| 8920 | // Expressions must start from the same base. Here we detect at which |
| 8921 | // point both expressions diverge from each other and see if we can |
| 8922 | // detect if the memory referred to both expressions is contiguous and |
| 8923 | // do not overlap. |
| 8924 | auto CI = CurComponents.rbegin(); |
| 8925 | auto CE = CurComponents.rend(); |
| 8926 | auto SI = StackComponents.rbegin(); |
| 8927 | auto SE = StackComponents.rend(); |
| 8928 | for (; CI != CE && SI != SE; ++CI, ++SI) { |
| 8929 | |
| 8930 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.3] |
| 8931 | // At most one list item can be an array item derived from a given |
| 8932 | // variable in map clauses of the same construct. |
| 8933 | if (CurrentRegionOnly && (isa<ArraySubscriptExpr>(CI->first) || |
| 8934 | isa<OMPArraySectionExpr>(CI->first)) && |
| 8935 | (isa<ArraySubscriptExpr>(SI->first) || |
| 8936 | isa<OMPArraySectionExpr>(SI->first))) { |
| 8937 | SemaRef.Diag(CI->first->getExprLoc(), |
| 8938 | diag::err_omp_multiple_array_items_in_map_clause) |
| 8939 | << CI->first->getSourceRange(); |
| 8940 | ; |
| 8941 | SemaRef.Diag(SI->first->getExprLoc(), diag::note_used_here) |
| 8942 | << SI->first->getSourceRange(); |
| 8943 | return true; |
| 8944 | } |
| 8945 | |
| 8946 | // Do both expressions have the same kind? |
| 8947 | if (CI->first->getStmtClass() != SI->first->getStmtClass()) |
| 8948 | break; |
| 8949 | |
| 8950 | // Are we dealing with different variables/fields? |
| 8951 | if (CI->second != SI->second) |
| 8952 | break; |
| 8953 | } |
| 8954 | |
| 8955 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.4] |
| 8956 | // List items of map clauses in the same construct must not share |
| 8957 | // original storage. |
| 8958 | // |
| 8959 | // If the expressions are exactly the same or one is a subset of the |
| 8960 | // other, it means they are sharing storage. |
| 8961 | if (CI == CE && SI == SE) { |
| 8962 | if (CurrentRegionOnly) { |
| 8963 | SemaRef.Diag(ELoc, diag::err_omp_map_shared_storage) << ERange; |
| 8964 | SemaRef.Diag(RE->getExprLoc(), diag::note_used_here) |
| 8965 | << RE->getSourceRange(); |
| 8966 | return true; |
| 8967 | } else { |
| 8968 | // If we find the same expression in the enclosing data environment, |
| 8969 | // that is legal. |
| 8970 | IsEnclosedByDataEnvironmentExpr = true; |
| 8971 | return false; |
| 8972 | } |
| 8973 | } |
| 8974 | |
| 8975 | QualType DerivedType = std::prev(CI)->first->getType(); |
| 8976 | SourceLocation DerivedLoc = std::prev(CI)->first->getExprLoc(); |
| 8977 | |
| 8978 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] |
| 8979 | // If the type of a list item is a reference to a type T then the type |
| 8980 | // will be considered to be T for all purposes of this clause. |
| 8981 | if (DerivedType->isReferenceType()) |
| 8982 | DerivedType = DerivedType->getPointeeType(); |
| 8983 | |
| 8984 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C/C++, p.1] |
| 8985 | // A variable for which the type is pointer and an array section |
| 8986 | // derived from that variable must not appear as list items of map |
| 8987 | // clauses of the same construct. |
| 8988 | // |
| 8989 | // Also, cover one of the cases in: |
| 8990 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.5] |
| 8991 | // If any part of the original storage of a list item has corresponding |
| 8992 | // storage in the device data environment, all of the original storage |
| 8993 | // must have corresponding storage in the device data environment. |
| 8994 | // |
| 8995 | if (DerivedType->isAnyPointerType()) { |
| 8996 | if (CI == CE || SI == SE) { |
| 8997 | SemaRef.Diag( |
| 8998 | DerivedLoc, |
| 8999 | diag::err_omp_pointer_mapped_along_with_derived_section) |
| 9000 | << DerivedLoc; |
| 9001 | } else { |
| 9002 | assert(CI != CE && SI != SE); |
| 9003 | SemaRef.Diag(DerivedLoc, diag::err_omp_same_pointer_derreferenced) |
| 9004 | << DerivedLoc; |
| 9005 | } |
| 9006 | SemaRef.Diag(RE->getExprLoc(), diag::note_used_here) |
| 9007 | << RE->getSourceRange(); |
| 9008 | return true; |
| 9009 | } |
| 9010 | |
| 9011 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.4] |
| 9012 | // List items of map clauses in the same construct must not share |
| 9013 | // original storage. |
| 9014 | // |
| 9015 | // An expression is a subset of the other. |
| 9016 | if (CurrentRegionOnly && (CI == CE || SI == SE)) { |
| 9017 | SemaRef.Diag(ELoc, diag::err_omp_map_shared_storage) << ERange; |
| 9018 | SemaRef.Diag(RE->getExprLoc(), diag::note_used_here) |
| 9019 | << RE->getSourceRange(); |
| 9020 | return true; |
| 9021 | } |
| 9022 | |
| 9023 | // The current expression uses the same base as other expression in the |
| 9024 | // data environment but does not contain it completelly. |
| 9025 | if (!CurrentRegionOnly && SI != SE) |
| 9026 | EnclosingExpr = RE; |
| 9027 | |
| 9028 | // The current expression is a subset of the expression in the data |
| 9029 | // environment. |
| 9030 | IsEnclosedByDataEnvironmentExpr |= |
| 9031 | (!CurrentRegionOnly && CI != CE && SI == SE); |
| 9032 | |
| 9033 | return false; |
| 9034 | }); |
| 9035 | |
| 9036 | if (CurrentRegionOnly) |
| 9037 | return FoundError; |
| 9038 | |
| 9039 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.5] |
| 9040 | // If any part of the original storage of a list item has corresponding |
| 9041 | // storage in the device data environment, all of the original storage must |
| 9042 | // have corresponding storage in the device data environment. |
| 9043 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.6] |
| 9044 | // If a list item is an element of a structure, and a different element of |
| 9045 | // the structure has a corresponding list item in the device data environment |
| 9046 | // prior to a task encountering the construct associated with the map clause, |
| 9047 | // then the list item must also have a correspnding list item in the device |
| 9048 | // data environment prior to the task encountering the construct. |
| 9049 | // |
| 9050 | if (EnclosingExpr && !IsEnclosedByDataEnvironmentExpr) { |
| 9051 | SemaRef.Diag(ELoc, |
| 9052 | diag::err_omp_original_storage_is_shared_and_does_not_contain) |
| 9053 | << ERange; |
| 9054 | SemaRef.Diag(EnclosingExpr->getExprLoc(), diag::note_used_here) |
| 9055 | << EnclosingExpr->getSourceRange(); |
| 9056 | return true; |
| 9057 | } |
| 9058 | |
| 9059 | return FoundError; |
| 9060 | } |
| 9061 | |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 9062 | OMPClause * |
| 9063 | Sema::ActOnOpenMPMapClause(OpenMPMapClauseKind MapTypeModifier, |
| 9064 | OpenMPMapClauseKind MapType, bool IsMapTypeImplicit, |
| 9065 | SourceLocation MapLoc, SourceLocation ColonLoc, |
| 9066 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
| 9067 | SourceLocation LParenLoc, SourceLocation EndLoc) { |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9068 | SmallVector<Expr *, 4> Vars; |
| 9069 | |
| 9070 | for (auto &RE : VarList) { |
| 9071 | assert(RE && "Null expr in omp map"); |
| 9072 | if (isa<DependentScopeDeclRefExpr>(RE)) { |
| 9073 | // It will be analyzed later. |
| 9074 | Vars.push_back(RE); |
| 9075 | continue; |
| 9076 | } |
| 9077 | SourceLocation ELoc = RE->getExprLoc(); |
| 9078 | |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9079 | auto *VE = RE->IgnoreParenLValueCasts(); |
| 9080 | |
| 9081 | if (VE->isValueDependent() || VE->isTypeDependent() || |
| 9082 | VE->isInstantiationDependent() || |
| 9083 | VE->containsUnexpandedParameterPack()) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9084 | // We can only analyze this information once the missing information is |
| 9085 | // resolved. |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9086 | Vars.push_back(RE); |
| 9087 | continue; |
| 9088 | } |
| 9089 | |
| 9090 | auto *SimpleExpr = RE->IgnoreParenCasts(); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9091 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9092 | if (!RE->IgnoreParenImpCasts()->isLValue()) { |
| 9093 | Diag(ELoc, diag::err_omp_expected_named_var_member_or_array_expression) |
| 9094 | << RE->getSourceRange(); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9095 | continue; |
| 9096 | } |
| 9097 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9098 | // Obtain the array or member expression bases if required. |
| 9099 | auto *BE = CheckMapClauseExpressionBase(*this, SimpleExpr); |
| 9100 | if (!BE) |
| 9101 | continue; |
| 9102 | |
| 9103 | // If the base is a reference to a variable, we rely on that variable for |
| 9104 | // the following checks. If it is a 'this' expression we rely on the field. |
| 9105 | ValueDecl *D = nullptr; |
| 9106 | if (auto *DRE = dyn_cast<DeclRefExpr>(BE)) { |
| 9107 | D = DRE->getDecl(); |
| 9108 | } else { |
| 9109 | auto *ME = cast<MemberExpr>(BE); |
| 9110 | assert(isa<CXXThisExpr>(ME->getBase()) && "Unexpected expression!"); |
| 9111 | D = ME->getMemberDecl(); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9112 | } |
| 9113 | assert(D && "Null decl on map clause."); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9114 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9115 | auto *VD = dyn_cast<VarDecl>(D); |
| 9116 | auto *FD = dyn_cast<FieldDecl>(D); |
| 9117 | |
| 9118 | assert((VD || FD) && "Only variables or fields are expected here!"); |
NAKAMURA Takumi | 6dcb814 | 2016-01-23 01:38:20 +0000 | [diff] [blame] | 9119 | (void)FD; |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9120 | |
| 9121 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.10] |
| 9122 | // threadprivate variables cannot appear in a map clause. |
| 9123 | if (VD && DSAStack->isThreadPrivate(VD)) { |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9124 | auto DVar = DSAStack->getTopDSA(VD, false); |
| 9125 | Diag(ELoc, diag::err_omp_threadprivate_in_map); |
| 9126 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 9127 | continue; |
| 9128 | } |
| 9129 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9130 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.9] |
| 9131 | // A list item cannot appear in both a map clause and a data-sharing |
| 9132 | // attribute clause on the same construct. |
| 9133 | // |
| 9134 | // TODO: Implement this check - it cannot currently be tested because of |
| 9135 | // missing implementation of the other data sharing clauses in target |
| 9136 | // directives. |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9137 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9138 | // Check conflicts with other map clause expressions. We check the conflicts |
| 9139 | // with the current construct separately from the enclosing data |
| 9140 | // environment, because the restrictions are different. |
| 9141 | if (CheckMapConflicts(*this, DSAStack, D, SimpleExpr, |
| 9142 | /*CurrentRegionOnly=*/true)) |
| 9143 | break; |
| 9144 | if (CheckMapConflicts(*this, DSAStack, D, SimpleExpr, |
| 9145 | /*CurrentRegionOnly=*/false)) |
| 9146 | break; |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9147 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9148 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] |
| 9149 | // If the type of a list item is a reference to a type T then the type will |
| 9150 | // be considered to be T for all purposes of this clause. |
| 9151 | QualType Type = D->getType(); |
| 9152 | if (Type->isReferenceType()) |
| 9153 | Type = Type->getPointeeType(); |
| 9154 | |
| 9155 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.9] |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9156 | // A list item must have a mappable type. |
| 9157 | if (!CheckTypeMappable(VE->getExprLoc(), VE->getSourceRange(), *this, |
| 9158 | DSAStack, Type)) |
| 9159 | continue; |
| 9160 | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 9161 | // target enter data |
| 9162 | // OpenMP [2.10.2, Restrictions, p. 99] |
| 9163 | // A map-type must be specified in all map clauses and must be either |
| 9164 | // to or alloc. |
| 9165 | OpenMPDirectiveKind DKind = DSAStack->getCurrentDirective(); |
| 9166 | if (DKind == OMPD_target_enter_data && |
| 9167 | !(MapType == OMPC_MAP_to || MapType == OMPC_MAP_alloc)) { |
| 9168 | Diag(StartLoc, diag::err_omp_invalid_map_type_for_directive) |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 9169 | << (IsMapTypeImplicit ? 1 : 0) |
| 9170 | << getOpenMPSimpleClauseTypeName(OMPC_map, MapType) |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 9171 | << getOpenMPDirectiveName(DKind); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9172 | continue; |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 9173 | } |
| 9174 | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 9175 | // target exit_data |
| 9176 | // OpenMP [2.10.3, Restrictions, p. 102] |
| 9177 | // A map-type must be specified in all map clauses and must be either |
| 9178 | // from, release, or delete. |
| 9179 | DKind = DSAStack->getCurrentDirective(); |
| 9180 | if (DKind == OMPD_target_exit_data && |
| 9181 | !(MapType == OMPC_MAP_from || MapType == OMPC_MAP_release || |
| 9182 | MapType == OMPC_MAP_delete)) { |
| 9183 | Diag(StartLoc, diag::err_omp_invalid_map_type_for_directive) |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 9184 | << (IsMapTypeImplicit ? 1 : 0) |
| 9185 | << getOpenMPSimpleClauseTypeName(OMPC_map, MapType) |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 9186 | << getOpenMPDirectiveName(DKind); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9187 | continue; |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 9188 | } |
| 9189 | |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9190 | Vars.push_back(RE); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9191 | DSAStack->addExprToVarMapInfo(D, RE); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9192 | } |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9193 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9194 | // We need to produce a map clause even if we don't have variables so that |
| 9195 | // other diagnostics related with non-existing map clauses are accurate. |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9196 | return OMPMapClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 9197 | MapTypeModifier, MapType, IsMapTypeImplicit, |
| 9198 | MapLoc); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9199 | } |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 9200 | |
| 9201 | OMPClause *Sema::ActOnOpenMPNumTeamsClause(Expr *NumTeams, |
| 9202 | SourceLocation StartLoc, |
| 9203 | SourceLocation LParenLoc, |
| 9204 | SourceLocation EndLoc) { |
| 9205 | Expr *ValExpr = NumTeams; |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 9206 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 9207 | // OpenMP [teams Constrcut, Restrictions] |
| 9208 | // The num_teams expression must evaluate to a positive integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 9209 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_num_teams, |
| 9210 | /*StrictlyPositive=*/true)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 9211 | return nullptr; |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 9212 | |
| 9213 | return new (Context) OMPNumTeamsClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 9214 | } |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 9215 | |
| 9216 | OMPClause *Sema::ActOnOpenMPThreadLimitClause(Expr *ThreadLimit, |
| 9217 | SourceLocation StartLoc, |
| 9218 | SourceLocation LParenLoc, |
| 9219 | SourceLocation EndLoc) { |
| 9220 | Expr *ValExpr = ThreadLimit; |
| 9221 | |
| 9222 | // OpenMP [teams Constrcut, Restrictions] |
| 9223 | // The thread_limit expression must evaluate to a positive integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 9224 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_thread_limit, |
| 9225 | /*StrictlyPositive=*/true)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 9226 | return nullptr; |
| 9227 | |
| 9228 | return new (Context) OMPThreadLimitClause(ValExpr, StartLoc, LParenLoc, |
| 9229 | EndLoc); |
| 9230 | } |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 9231 | |
| 9232 | OMPClause *Sema::ActOnOpenMPPriorityClause(Expr *Priority, |
| 9233 | SourceLocation StartLoc, |
| 9234 | SourceLocation LParenLoc, |
| 9235 | SourceLocation EndLoc) { |
| 9236 | Expr *ValExpr = Priority; |
| 9237 | |
| 9238 | // OpenMP [2.9.1, task Constrcut] |
| 9239 | // The priority-value is a non-negative numerical scalar expression. |
| 9240 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_priority, |
| 9241 | /*StrictlyPositive=*/false)) |
| 9242 | return nullptr; |
| 9243 | |
| 9244 | return new (Context) OMPPriorityClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 9245 | } |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 9246 | |
| 9247 | OMPClause *Sema::ActOnOpenMPGrainsizeClause(Expr *Grainsize, |
| 9248 | SourceLocation StartLoc, |
| 9249 | SourceLocation LParenLoc, |
| 9250 | SourceLocation EndLoc) { |
| 9251 | Expr *ValExpr = Grainsize; |
| 9252 | |
| 9253 | // OpenMP [2.9.2, taskloop Constrcut] |
| 9254 | // The parameter of the grainsize clause must be a positive integer |
| 9255 | // expression. |
| 9256 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_grainsize, |
| 9257 | /*StrictlyPositive=*/true)) |
| 9258 | return nullptr; |
| 9259 | |
| 9260 | return new (Context) OMPGrainsizeClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 9261 | } |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 9262 | |
| 9263 | OMPClause *Sema::ActOnOpenMPNumTasksClause(Expr *NumTasks, |
| 9264 | SourceLocation StartLoc, |
| 9265 | SourceLocation LParenLoc, |
| 9266 | SourceLocation EndLoc) { |
| 9267 | Expr *ValExpr = NumTasks; |
| 9268 | |
| 9269 | // OpenMP [2.9.2, taskloop Constrcut] |
| 9270 | // The parameter of the num_tasks clause must be a positive integer |
| 9271 | // expression. |
| 9272 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_num_tasks, |
| 9273 | /*StrictlyPositive=*/true)) |
| 9274 | return nullptr; |
| 9275 | |
| 9276 | return new (Context) OMPNumTasksClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 9277 | } |
| 9278 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 9279 | OMPClause *Sema::ActOnOpenMPHintClause(Expr *Hint, SourceLocation StartLoc, |
| 9280 | SourceLocation LParenLoc, |
| 9281 | SourceLocation EndLoc) { |
| 9282 | // OpenMP [2.13.2, critical construct, Description] |
| 9283 | // ... where hint-expression is an integer constant expression that evaluates |
| 9284 | // to a valid lock hint. |
| 9285 | ExprResult HintExpr = VerifyPositiveIntegerConstantInClause(Hint, OMPC_hint); |
| 9286 | if (HintExpr.isInvalid()) |
| 9287 | return nullptr; |
| 9288 | return new (Context) |
| 9289 | OMPHintClause(HintExpr.get(), StartLoc, LParenLoc, EndLoc); |
| 9290 | } |
| 9291 | |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 9292 | OMPClause *Sema::ActOnOpenMPDistScheduleClause( |
| 9293 | OpenMPDistScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, |
| 9294 | SourceLocation LParenLoc, SourceLocation KindLoc, SourceLocation CommaLoc, |
| 9295 | SourceLocation EndLoc) { |
| 9296 | if (Kind == OMPC_DIST_SCHEDULE_unknown) { |
| 9297 | std::string Values; |
| 9298 | Values += "'"; |
| 9299 | Values += getOpenMPSimpleClauseTypeName(OMPC_dist_schedule, 0); |
| 9300 | Values += "'"; |
| 9301 | Diag(KindLoc, diag::err_omp_unexpected_clause_value) |
| 9302 | << Values << getOpenMPClauseName(OMPC_dist_schedule); |
| 9303 | return nullptr; |
| 9304 | } |
| 9305 | Expr *ValExpr = ChunkSize; |
| 9306 | Expr *HelperValExpr = nullptr; |
| 9307 | if (ChunkSize) { |
| 9308 | if (!ChunkSize->isValueDependent() && !ChunkSize->isTypeDependent() && |
| 9309 | !ChunkSize->isInstantiationDependent() && |
| 9310 | !ChunkSize->containsUnexpandedParameterPack()) { |
| 9311 | SourceLocation ChunkSizeLoc = ChunkSize->getLocStart(); |
| 9312 | ExprResult Val = |
| 9313 | PerformOpenMPImplicitIntegerConversion(ChunkSizeLoc, ChunkSize); |
| 9314 | if (Val.isInvalid()) |
| 9315 | return nullptr; |
| 9316 | |
| 9317 | ValExpr = Val.get(); |
| 9318 | |
| 9319 | // OpenMP [2.7.1, Restrictions] |
| 9320 | // chunk_size must be a loop invariant integer expression with a positive |
| 9321 | // value. |
| 9322 | llvm::APSInt Result; |
| 9323 | if (ValExpr->isIntegerConstantExpr(Result, Context)) { |
| 9324 | if (Result.isSigned() && !Result.isStrictlyPositive()) { |
| 9325 | Diag(ChunkSizeLoc, diag::err_omp_negative_expression_in_clause) |
| 9326 | << "dist_schedule" << ChunkSize->getSourceRange(); |
| 9327 | return nullptr; |
| 9328 | } |
| 9329 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective())) { |
| 9330 | auto *ImpVar = buildVarDecl(*this, ChunkSize->getExprLoc(), |
| 9331 | ChunkSize->getType(), ".chunk."); |
| 9332 | auto *ImpVarRef = buildDeclRefExpr(*this, ImpVar, ChunkSize->getType(), |
| 9333 | ChunkSize->getExprLoc(), |
| 9334 | /*RefersToCapture=*/true); |
| 9335 | HelperValExpr = ImpVarRef; |
| 9336 | } |
| 9337 | } |
| 9338 | } |
| 9339 | |
| 9340 | return new (Context) |
| 9341 | OMPDistScheduleClause(StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc, |
| 9342 | Kind, ValExpr, HelperValExpr); |
| 9343 | } |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 9344 | |
| 9345 | OMPClause *Sema::ActOnOpenMPDefaultmapClause( |
| 9346 | OpenMPDefaultmapClauseModifier M, OpenMPDefaultmapClauseKind Kind, |
| 9347 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation MLoc, |
| 9348 | SourceLocation KindLoc, SourceLocation EndLoc) { |
| 9349 | // OpenMP 4.5 only supports 'defaultmap(tofrom: scalar)' |
| 9350 | if (M != OMPC_DEFAULTMAP_MODIFIER_tofrom || |
| 9351 | Kind != OMPC_DEFAULTMAP_scalar) { |
| 9352 | std::string Value; |
| 9353 | SourceLocation Loc; |
| 9354 | Value += "'"; |
| 9355 | if (M != OMPC_DEFAULTMAP_MODIFIER_tofrom) { |
| 9356 | Value += getOpenMPSimpleClauseTypeName(OMPC_defaultmap, |
| 9357 | OMPC_DEFAULTMAP_MODIFIER_tofrom); |
| 9358 | Loc = MLoc; |
| 9359 | } else { |
| 9360 | Value += getOpenMPSimpleClauseTypeName(OMPC_defaultmap, |
| 9361 | OMPC_DEFAULTMAP_scalar); |
| 9362 | Loc = KindLoc; |
| 9363 | } |
| 9364 | Value += "'"; |
| 9365 | Diag(Loc, diag::err_omp_unexpected_clause_value) |
| 9366 | << Value << getOpenMPClauseName(OMPC_defaultmap); |
| 9367 | return nullptr; |
| 9368 | } |
| 9369 | |
| 9370 | return new (Context) |
| 9371 | OMPDefaultmapClause(StartLoc, LParenLoc, MLoc, KindLoc, EndLoc, Kind, M); |
| 9372 | } |