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 | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 24 | #include "clang/AST/TypeOrdering.h" |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 25 | #include "clang/Basic/OpenMPKinds.h" |
Samuel Antao | f8b5012 | 2015-07-13 22:54:53 +0000 | [diff] [blame] | 26 | #include "clang/Basic/TargetInfo.h" |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 27 | #include "clang/Lex/Preprocessor.h" |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 28 | #include "clang/Sema/Initialization.h" |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 29 | #include "clang/Sema/Lookup.h" |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 30 | #include "clang/Sema/Scope.h" |
| 31 | #include "clang/Sema/ScopeInfo.h" |
Chandler Carruth | 5553d0d | 2014-01-07 11:51:46 +0000 | [diff] [blame] | 32 | #include "clang/Sema/SemaInternal.h" |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 33 | using namespace clang; |
| 34 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 35 | //===----------------------------------------------------------------------===// |
| 36 | // Stack of data-sharing attributes for variables |
| 37 | //===----------------------------------------------------------------------===// |
| 38 | |
| 39 | namespace { |
| 40 | /// \brief Default data sharing attributes, which can be applied to directive. |
| 41 | enum DefaultDataSharingAttributes { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 42 | DSA_unspecified = 0, /// \brief Data sharing attribute not specified. |
| 43 | DSA_none = 1 << 0, /// \brief Default data sharing attribute 'none'. |
| 44 | DSA_shared = 1 << 1 /// \brief Default data sharing attribute 'shared'. |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 45 | }; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 46 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 47 | template <class T> struct MatchesAny { |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 48 | explicit MatchesAny(ArrayRef<T> Arr) : Arr(std::move(Arr)) {} |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 49 | bool operator()(T Kind) { |
| 50 | for (auto KindEl : Arr) |
| 51 | if (KindEl == Kind) |
| 52 | return true; |
| 53 | return false; |
| 54 | } |
| 55 | |
| 56 | private: |
| 57 | ArrayRef<T> Arr; |
| 58 | }; |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 59 | struct MatchesAlways { |
Angel Garcia Gomez | 637d1e6 | 2015-10-20 13:23:58 +0000 | [diff] [blame] | 60 | MatchesAlways() {} |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 61 | template <class T> bool operator()(T) { return true; } |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 62 | }; |
| 63 | |
| 64 | typedef MatchesAny<OpenMPClauseKind> MatchesAnyClause; |
| 65 | typedef MatchesAny<OpenMPDirectiveKind> MatchesAnyDirective; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 66 | |
| 67 | /// \brief Stack for tracking declarations used in OpenMP directives and |
| 68 | /// clauses and their data-sharing attributes. |
| 69 | class DSAStackTy { |
| 70 | public: |
| 71 | struct DSAVarData { |
| 72 | OpenMPDirectiveKind DKind; |
| 73 | OpenMPClauseKind CKind; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 74 | Expr *RefExpr; |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 75 | DeclRefExpr *PrivateCopy; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 76 | SourceLocation ImplicitDSALoc; |
| 77 | DSAVarData() |
| 78 | : DKind(OMPD_unknown), CKind(OMPC_unknown), RefExpr(nullptr), |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 79 | PrivateCopy(nullptr), ImplicitDSALoc() {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 80 | }; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 81 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 82 | private: |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 83 | typedef SmallVector<Expr *, 4> MapInfo; |
| 84 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 85 | struct DSAInfo { |
| 86 | OpenMPClauseKind Attributes; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 87 | Expr *RefExpr; |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 88 | DeclRefExpr *PrivateCopy; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 89 | }; |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 90 | typedef llvm::DenseMap<ValueDecl *, DSAInfo> DeclSAMapTy; |
| 91 | typedef llvm::DenseMap<ValueDecl *, Expr *> AlignedMapTy; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 92 | typedef llvm::DenseMap<ValueDecl *, unsigned> LoopControlVariablesMapTy; |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 93 | typedef llvm::DenseMap<ValueDecl *, MapInfo> MappedDeclsTy; |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 94 | typedef llvm::StringMap<std::pair<OMPCriticalDirective *, llvm::APSInt>> |
| 95 | CriticalsWithHintsTy; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 96 | |
| 97 | struct SharingMapTy { |
| 98 | DeclSAMapTy SharingMap; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 99 | AlignedMapTy AlignedMap; |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 100 | MappedDeclsTy MappedDecls; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 101 | LoopControlVariablesMapTy LCVMap; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 102 | DefaultDataSharingAttributes DefaultAttr; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 103 | SourceLocation DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 104 | OpenMPDirectiveKind Directive; |
| 105 | DeclarationNameInfo DirectiveName; |
| 106 | Scope *CurScope; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 107 | SourceLocation ConstructLoc; |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 108 | /// \brief first argument (Expr *) contains optional argument of the |
| 109 | /// 'ordered' clause, the second one is true if the regions has 'ordered' |
| 110 | /// clause, false otherwise. |
| 111 | llvm::PointerIntPair<Expr *, 1, bool> OrderedRegion; |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 112 | bool NowaitRegion; |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 113 | bool CancelRegion; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 114 | unsigned AssociatedLoops; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 115 | SourceLocation InnerTeamsRegionLoc; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 116 | SharingMapTy(OpenMPDirectiveKind DKind, DeclarationNameInfo Name, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 117 | Scope *CurScope, SourceLocation Loc) |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 118 | : SharingMap(), AlignedMap(), LCVMap(), DefaultAttr(DSA_unspecified), |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 119 | Directive(DKind), DirectiveName(std::move(Name)), CurScope(CurScope), |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 120 | ConstructLoc(Loc), OrderedRegion(), NowaitRegion(false), |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 121 | CancelRegion(false), AssociatedLoops(1), InnerTeamsRegionLoc() {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 122 | SharingMapTy() |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 123 | : SharingMap(), AlignedMap(), LCVMap(), DefaultAttr(DSA_unspecified), |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 124 | Directive(OMPD_unknown), DirectiveName(), CurScope(nullptr), |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 125 | ConstructLoc(), OrderedRegion(), NowaitRegion(false), |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 126 | CancelRegion(false), AssociatedLoops(1), InnerTeamsRegionLoc() {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 127 | }; |
| 128 | |
Axel Naumann | 323862e | 2016-02-03 10:45:22 +0000 | [diff] [blame] | 129 | typedef SmallVector<SharingMapTy, 4> StackTy; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 130 | |
| 131 | /// \brief Stack of used declaration and their data-sharing attributes. |
| 132 | StackTy Stack; |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 133 | /// \brief true, if check for DSA must be from parent directive, false, if |
| 134 | /// from current directive. |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 135 | OpenMPClauseKind ClauseKindMode; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 136 | Sema &SemaRef; |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 137 | bool ForceCapturing; |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 138 | CriticalsWithHintsTy Criticals; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 139 | |
| 140 | typedef SmallVector<SharingMapTy, 8>::reverse_iterator reverse_iterator; |
| 141 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 142 | DSAVarData getDSA(StackTy::reverse_iterator Iter, ValueDecl *D); |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 143 | |
| 144 | /// \brief Checks if the variable is a local for OpenMP region. |
| 145 | bool isOpenMPLocal(VarDecl *D, StackTy::reverse_iterator Iter); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 146 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 147 | public: |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 148 | explicit DSAStackTy(Sema &S) |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 149 | : Stack(1), ClauseKindMode(OMPC_unknown), SemaRef(S), |
| 150 | ForceCapturing(false) {} |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 151 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 152 | bool isClauseParsingMode() const { return ClauseKindMode != OMPC_unknown; } |
| 153 | void setClauseParsingMode(OpenMPClauseKind K) { ClauseKindMode = K; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 154 | |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 155 | bool isForceVarCapturing() const { return ForceCapturing; } |
| 156 | void setForceVarCapturing(bool V) { ForceCapturing = V; } |
| 157 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 158 | void push(OpenMPDirectiveKind DKind, const DeclarationNameInfo &DirName, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 159 | Scope *CurScope, SourceLocation Loc) { |
| 160 | Stack.push_back(SharingMapTy(DKind, DirName, CurScope, Loc)); |
| 161 | Stack.back().DefaultAttrLoc = Loc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | void pop() { |
| 165 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty!"); |
| 166 | Stack.pop_back(); |
| 167 | } |
| 168 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 169 | void addCriticalWithHint(OMPCriticalDirective *D, llvm::APSInt Hint) { |
| 170 | Criticals[D->getDirectiveName().getAsString()] = std::make_pair(D, Hint); |
| 171 | } |
| 172 | const std::pair<OMPCriticalDirective *, llvm::APSInt> |
| 173 | getCriticalWithHint(const DeclarationNameInfo &Name) const { |
| 174 | auto I = Criticals.find(Name.getAsString()); |
| 175 | if (I != Criticals.end()) |
| 176 | return I->second; |
| 177 | return std::make_pair(nullptr, llvm::APSInt()); |
| 178 | } |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 179 | /// \brief If 'aligned' declaration for given variable \a D was not seen yet, |
Alp Toker | 15e62a3 | 2014-06-06 12:02:07 +0000 | [diff] [blame] | 180 | /// add it and return NULL; otherwise return previous occurrence's expression |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 181 | /// for diagnostics. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 182 | Expr *addUniqueAligned(ValueDecl *D, Expr *NewDE); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 183 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 184 | /// \brief Register specified variable as loop control variable. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 185 | void addLoopControlVariable(ValueDecl *D); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 186 | /// \brief Check if the specified variable is a loop control variable for |
| 187 | /// current region. |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 188 | /// \return The index of the loop control variable in the list of associated |
| 189 | /// for-loops (from outer to inner). |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 190 | unsigned isLoopControlVariable(ValueDecl *D); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 191 | /// \brief Check if the specified variable is a loop control variable for |
| 192 | /// parent region. |
| 193 | /// \return The index of the loop control variable in the list of associated |
| 194 | /// for-loops (from outer to inner). |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 195 | unsigned isParentLoopControlVariable(ValueDecl *D); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 196 | /// \brief Get the loop control variable for the I-th loop (or nullptr) in |
| 197 | /// parent directive. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 198 | ValueDecl *getParentLoopControlVariable(unsigned I); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 199 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 200 | /// \brief Adds explicit data sharing attribute to the specified declaration. |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 201 | void addDSA(ValueDecl *D, Expr *E, OpenMPClauseKind A, |
| 202 | DeclRefExpr *PrivateCopy = nullptr); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 203 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 204 | /// \brief Returns data sharing attributes from top of the stack for the |
| 205 | /// specified declaration. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 206 | DSAVarData getTopDSA(ValueDecl *D, bool FromParent); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 207 | /// \brief Returns data-sharing attributes for the specified declaration. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 208 | DSAVarData getImplicitDSA(ValueDecl *D, bool FromParent); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 209 | /// \brief Checks if the specified variables has data-sharing attributes which |
| 210 | /// match specified \a CPred predicate in any directive which matches \a DPred |
| 211 | /// predicate. |
| 212 | template <class ClausesPredicate, class DirectivesPredicate> |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 213 | DSAVarData hasDSA(ValueDecl *D, ClausesPredicate CPred, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 214 | DirectivesPredicate DPred, bool FromParent); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 215 | /// \brief Checks if the specified variables has data-sharing attributes which |
| 216 | /// match specified \a CPred predicate in any innermost directive which |
| 217 | /// matches \a DPred predicate. |
| 218 | template <class ClausesPredicate, class DirectivesPredicate> |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 219 | DSAVarData hasInnermostDSA(ValueDecl *D, ClausesPredicate CPred, |
| 220 | DirectivesPredicate DPred, bool FromParent); |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 221 | /// \brief Checks if the specified variables has explicit data-sharing |
| 222 | /// attributes which match specified \a CPred predicate at the specified |
| 223 | /// OpenMP region. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 224 | bool hasExplicitDSA(ValueDecl *D, |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 225 | const llvm::function_ref<bool(OpenMPClauseKind)> &CPred, |
| 226 | unsigned Level); |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 227 | |
| 228 | /// \brief Returns true if the directive at level \Level matches in the |
| 229 | /// specified \a DPred predicate. |
| 230 | bool hasExplicitDirective( |
| 231 | const llvm::function_ref<bool(OpenMPDirectiveKind)> &DPred, |
| 232 | unsigned Level); |
| 233 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 234 | /// \brief Finds a directive which matches specified \a DPred predicate. |
| 235 | template <class NamedDirectivesPredicate> |
| 236 | bool hasDirective(NamedDirectivesPredicate DPred, bool FromParent); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 237 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 238 | /// \brief Returns currently analyzed directive. |
| 239 | OpenMPDirectiveKind getCurrentDirective() const { |
| 240 | return Stack.back().Directive; |
| 241 | } |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 242 | /// \brief Returns parent directive. |
| 243 | OpenMPDirectiveKind getParentDirective() const { |
| 244 | if (Stack.size() > 2) |
| 245 | return Stack[Stack.size() - 2].Directive; |
| 246 | return OMPD_unknown; |
| 247 | } |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 248 | /// \brief Return the directive associated with the provided scope. |
| 249 | OpenMPDirectiveKind getDirectiveForScope(const Scope *S) const; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 250 | |
| 251 | /// \brief Set default data sharing attribute to none. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 252 | void setDefaultDSANone(SourceLocation Loc) { |
| 253 | Stack.back().DefaultAttr = DSA_none; |
| 254 | Stack.back().DefaultAttrLoc = Loc; |
| 255 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 256 | /// \brief Set default data sharing attribute to shared. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 257 | void setDefaultDSAShared(SourceLocation Loc) { |
| 258 | Stack.back().DefaultAttr = DSA_shared; |
| 259 | Stack.back().DefaultAttrLoc = Loc; |
| 260 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 261 | |
| 262 | DefaultDataSharingAttributes getDefaultDSA() const { |
| 263 | return Stack.back().DefaultAttr; |
| 264 | } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 265 | SourceLocation getDefaultDSALocation() const { |
| 266 | return Stack.back().DefaultAttrLoc; |
| 267 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 268 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 269 | /// \brief Checks if the specified variable is a threadprivate. |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 270 | bool isThreadPrivate(VarDecl *D) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 271 | DSAVarData DVar = getTopDSA(D, false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 272 | return isOpenMPThreadPrivate(DVar.CKind); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 273 | } |
| 274 | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 275 | /// \brief Marks current region as ordered (it has an 'ordered' clause). |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 276 | void setOrderedRegion(bool IsOrdered, Expr *Param) { |
| 277 | Stack.back().OrderedRegion.setInt(IsOrdered); |
| 278 | Stack.back().OrderedRegion.setPointer(Param); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 279 | } |
| 280 | /// \brief Returns true, if parent region is ordered (has associated |
| 281 | /// 'ordered' clause), false - otherwise. |
| 282 | bool isParentOrderedRegion() const { |
| 283 | if (Stack.size() > 2) |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 284 | return Stack[Stack.size() - 2].OrderedRegion.getInt(); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 285 | return false; |
| 286 | } |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 287 | /// \brief Returns optional parameter for the ordered region. |
| 288 | Expr *getParentOrderedRegionParam() const { |
| 289 | if (Stack.size() > 2) |
| 290 | return Stack[Stack.size() - 2].OrderedRegion.getPointer(); |
| 291 | return nullptr; |
| 292 | } |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 293 | /// \brief Marks current region as nowait (it has a 'nowait' clause). |
| 294 | void setNowaitRegion(bool IsNowait = true) { |
| 295 | Stack.back().NowaitRegion = IsNowait; |
| 296 | } |
| 297 | /// \brief Returns true, if parent region is nowait (has associated |
| 298 | /// 'nowait' clause), false - otherwise. |
| 299 | bool isParentNowaitRegion() const { |
| 300 | if (Stack.size() > 2) |
| 301 | return Stack[Stack.size() - 2].NowaitRegion; |
| 302 | return false; |
| 303 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 304 | /// \brief Marks parent region as cancel region. |
| 305 | void setParentCancelRegion(bool Cancel = true) { |
| 306 | if (Stack.size() > 2) |
| 307 | Stack[Stack.size() - 2].CancelRegion = |
| 308 | Stack[Stack.size() - 2].CancelRegion || Cancel; |
| 309 | } |
| 310 | /// \brief Return true if current region has inner cancel construct. |
| 311 | bool isCancelRegion() const { |
| 312 | return Stack.back().CancelRegion; |
| 313 | } |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 314 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 315 | /// \brief Set collapse value for the region. |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 316 | void setAssociatedLoops(unsigned Val) { Stack.back().AssociatedLoops = Val; } |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 317 | /// \brief Return collapse value for region. |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 318 | unsigned getAssociatedLoops() const { return Stack.back().AssociatedLoops; } |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 319 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 320 | /// \brief Marks current target region as one with closely nested teams |
| 321 | /// region. |
| 322 | void setParentTeamsRegionLoc(SourceLocation TeamsRegionLoc) { |
| 323 | if (Stack.size() > 2) |
| 324 | Stack[Stack.size() - 2].InnerTeamsRegionLoc = TeamsRegionLoc; |
| 325 | } |
| 326 | /// \brief Returns true, if current region has closely nested teams region. |
| 327 | bool hasInnerTeamsRegion() const { |
| 328 | return getInnerTeamsRegionLoc().isValid(); |
| 329 | } |
| 330 | /// \brief Returns location of the nested teams region (if any). |
| 331 | SourceLocation getInnerTeamsRegionLoc() const { |
| 332 | if (Stack.size() > 1) |
| 333 | return Stack.back().InnerTeamsRegionLoc; |
| 334 | return SourceLocation(); |
| 335 | } |
| 336 | |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 337 | Scope *getCurScope() const { return Stack.back().CurScope; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 338 | Scope *getCurScope() { return Stack.back().CurScope; } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 339 | SourceLocation getConstructLoc() { return Stack.back().ConstructLoc; } |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 340 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 341 | // Do the check specified in MapInfoCheck and return true if any issue is |
| 342 | // found. |
| 343 | template <class MapInfoCheck> |
| 344 | bool checkMapInfoForVar(ValueDecl *VD, bool CurrentRegionOnly, |
| 345 | MapInfoCheck Check) { |
| 346 | auto SI = Stack.rbegin(); |
| 347 | auto SE = Stack.rend(); |
| 348 | |
| 349 | if (SI == SE) |
| 350 | return false; |
| 351 | |
| 352 | if (CurrentRegionOnly) { |
| 353 | SE = std::next(SI); |
| 354 | } else { |
| 355 | ++SI; |
| 356 | } |
| 357 | |
| 358 | for (; SI != SE; ++SI) { |
| 359 | auto MI = SI->MappedDecls.find(VD); |
| 360 | if (MI != SI->MappedDecls.end()) { |
| 361 | for (Expr *E : MI->second) { |
| 362 | if (Check(E)) |
| 363 | return true; |
| 364 | } |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 365 | } |
| 366 | } |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 367 | return false; |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 368 | } |
| 369 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 370 | void addExprToVarMapInfo(ValueDecl *VD, Expr *E) { |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 371 | if (Stack.size() > 1) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 372 | Stack.back().MappedDecls[VD].push_back(E); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 373 | } |
| 374 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 375 | }; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 376 | bool isParallelOrTaskRegion(OpenMPDirectiveKind DKind) { |
| 377 | return isOpenMPParallelDirective(DKind) || DKind == OMPD_task || |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 378 | isOpenMPTeamsDirective(DKind) || DKind == OMPD_unknown || |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 379 | isOpenMPTaskLoopDirective(DKind); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 380 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 381 | } // namespace |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 382 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 383 | static ValueDecl *getCanonicalDecl(ValueDecl *D) { |
| 384 | auto *VD = dyn_cast<VarDecl>(D); |
| 385 | auto *FD = dyn_cast<FieldDecl>(D); |
| 386 | if (VD != nullptr) { |
| 387 | VD = VD->getCanonicalDecl(); |
| 388 | D = VD; |
| 389 | } else { |
| 390 | assert(FD); |
| 391 | FD = FD->getCanonicalDecl(); |
| 392 | D = FD; |
| 393 | } |
| 394 | return D; |
| 395 | } |
| 396 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 397 | DSAStackTy::DSAVarData DSAStackTy::getDSA(StackTy::reverse_iterator Iter, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 398 | ValueDecl *D) { |
| 399 | D = getCanonicalDecl(D); |
| 400 | auto *VD = dyn_cast<VarDecl>(D); |
| 401 | auto *FD = dyn_cast<FieldDecl>(D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 402 | DSAVarData DVar; |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 403 | if (Iter == std::prev(Stack.rend())) { |
Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 404 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 405 | // in a region but not in construct] |
| 406 | // File-scope or namespace-scope variables referenced in called routines |
| 407 | // in the region are shared unless they appear in a threadprivate |
| 408 | // directive. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 409 | if (VD && !VD->isFunctionOrMethodVarDecl() && !isa<ParmVarDecl>(D)) |
Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 410 | DVar.CKind = OMPC_shared; |
| 411 | |
| 412 | // OpenMP [2.9.1.2, Data-sharing Attribute Rules for Variables Referenced |
| 413 | // in a region but not in construct] |
| 414 | // Variables with static storage duration that are declared in called |
| 415 | // routines in the region are shared. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 416 | if (VD && VD->hasGlobalStorage()) |
| 417 | DVar.CKind = OMPC_shared; |
| 418 | |
| 419 | // Non-static data members are shared by default. |
| 420 | if (FD) |
Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 421 | DVar.CKind = OMPC_shared; |
| 422 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 423 | return DVar; |
| 424 | } |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 425 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 426 | DVar.DKind = Iter->Directive; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 427 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 428 | // in a Construct, C/C++, predetermined, p.1] |
| 429 | // Variables with automatic storage duration that are declared in a scope |
| 430 | // inside the construct are private. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 431 | if (VD && isOpenMPLocal(VD, Iter) && VD->isLocalVarDecl() && |
| 432 | (VD->getStorageClass() == SC_Auto || VD->getStorageClass() == SC_None)) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 433 | DVar.CKind = OMPC_private; |
| 434 | return DVar; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 435 | } |
| 436 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 437 | // Explicitly specified attributes and local variables with predetermined |
| 438 | // attributes. |
| 439 | if (Iter->SharingMap.count(D)) { |
| 440 | DVar.RefExpr = Iter->SharingMap[D].RefExpr; |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 441 | DVar.PrivateCopy = Iter->SharingMap[D].PrivateCopy; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 442 | DVar.CKind = Iter->SharingMap[D].Attributes; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 443 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 444 | return DVar; |
| 445 | } |
| 446 | |
| 447 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 448 | // in a Construct, C/C++, implicitly determined, p.1] |
| 449 | // In a parallel or task construct, the data-sharing attributes of these |
| 450 | // variables are determined by the default clause, if present. |
| 451 | switch (Iter->DefaultAttr) { |
| 452 | case DSA_shared: |
| 453 | DVar.CKind = OMPC_shared; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 454 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 455 | return DVar; |
| 456 | case DSA_none: |
| 457 | return DVar; |
| 458 | case DSA_unspecified: |
| 459 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 460 | // in a Construct, implicitly determined, p.2] |
| 461 | // In a parallel construct, if no default clause is present, these |
| 462 | // variables are shared. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 463 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 464 | if (isOpenMPParallelDirective(DVar.DKind) || |
| 465 | isOpenMPTeamsDirective(DVar.DKind)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 466 | DVar.CKind = OMPC_shared; |
| 467 | return DVar; |
| 468 | } |
| 469 | |
| 470 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 471 | // in a Construct, implicitly determined, p.4] |
| 472 | // In a task construct, if no default clause is present, a variable that in |
| 473 | // the enclosing context is determined to be shared by all implicit tasks |
| 474 | // bound to the current team is shared. |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 475 | if (DVar.DKind == OMPD_task) { |
| 476 | DSAVarData DVarTemp; |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 477 | for (StackTy::reverse_iterator I = std::next(Iter), EE = Stack.rend(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 478 | I != EE; ++I) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 479 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables |
| 480 | // Referenced |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 481 | // in a Construct, implicitly determined, p.6] |
| 482 | // In a task construct, if no default clause is present, a variable |
| 483 | // whose data-sharing attribute is not determined by the rules above is |
| 484 | // firstprivate. |
| 485 | DVarTemp = getDSA(I, D); |
| 486 | if (DVarTemp.CKind != OMPC_shared) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 487 | DVar.RefExpr = nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 488 | DVar.DKind = OMPD_task; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 489 | DVar.CKind = OMPC_firstprivate; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 490 | return DVar; |
| 491 | } |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 492 | if (isParallelOrTaskRegion(I->Directive)) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 493 | break; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 494 | } |
| 495 | DVar.DKind = OMPD_task; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 496 | DVar.CKind = |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 497 | (DVarTemp.CKind == OMPC_unknown) ? OMPC_firstprivate : OMPC_shared; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 498 | return DVar; |
| 499 | } |
| 500 | } |
| 501 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 502 | // in a Construct, implicitly determined, p.3] |
| 503 | // For constructs other than task, if no default clause is present, these |
| 504 | // variables inherit their data-sharing attributes from the enclosing |
| 505 | // context. |
Benjamin Kramer | 167e999 | 2014-03-02 12:20:24 +0000 | [diff] [blame] | 506 | return getDSA(std::next(Iter), D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 507 | } |
| 508 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 509 | Expr *DSAStackTy::addUniqueAligned(ValueDecl *D, Expr *NewDE) { |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 510 | assert(Stack.size() > 1 && "Data sharing attributes stack is empty"); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 511 | D = getCanonicalDecl(D); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 512 | auto It = Stack.back().AlignedMap.find(D); |
| 513 | if (It == Stack.back().AlignedMap.end()) { |
| 514 | assert(NewDE && "Unexpected nullptr expr to be added into aligned map"); |
| 515 | Stack.back().AlignedMap[D] = NewDE; |
| 516 | return nullptr; |
| 517 | } else { |
| 518 | assert(It->second && "Unexpected nullptr expr in the aligned map"); |
| 519 | return It->second; |
| 520 | } |
| 521 | return nullptr; |
| 522 | } |
| 523 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 524 | void DSAStackTy::addLoopControlVariable(ValueDecl *D) { |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 525 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 526 | D = getCanonicalDecl(D); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 527 | 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] | 528 | } |
| 529 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 530 | unsigned DSAStackTy::isLoopControlVariable(ValueDecl *D) { |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 531 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 532 | D = getCanonicalDecl(D); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 533 | return Stack.back().LCVMap.count(D) > 0 ? Stack.back().LCVMap[D] : 0; |
| 534 | } |
| 535 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 536 | unsigned DSAStackTy::isParentLoopControlVariable(ValueDecl *D) { |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 537 | assert(Stack.size() > 2 && "Data-sharing attributes stack is empty"); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 538 | D = getCanonicalDecl(D); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 539 | return Stack[Stack.size() - 2].LCVMap.count(D) > 0 |
| 540 | ? Stack[Stack.size() - 2].LCVMap[D] |
| 541 | : 0; |
| 542 | } |
| 543 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 544 | ValueDecl *DSAStackTy::getParentLoopControlVariable(unsigned I) { |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 545 | assert(Stack.size() > 2 && "Data-sharing attributes stack is empty"); |
| 546 | if (Stack[Stack.size() - 2].LCVMap.size() < I) |
| 547 | return nullptr; |
| 548 | for (auto &Pair : Stack[Stack.size() - 2].LCVMap) { |
| 549 | if (Pair.second == I) |
| 550 | return Pair.first; |
| 551 | } |
| 552 | return nullptr; |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 553 | } |
| 554 | |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 555 | void DSAStackTy::addDSA(ValueDecl *D, Expr *E, OpenMPClauseKind A, |
| 556 | DeclRefExpr *PrivateCopy) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 557 | D = getCanonicalDecl(D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 558 | if (A == OMPC_threadprivate) { |
| 559 | Stack[0].SharingMap[D].Attributes = A; |
| 560 | Stack[0].SharingMap[D].RefExpr = E; |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 561 | Stack[0].SharingMap[D].PrivateCopy = nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 562 | } else { |
| 563 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); |
| 564 | Stack.back().SharingMap[D].Attributes = A; |
| 565 | Stack.back().SharingMap[D].RefExpr = E; |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 566 | Stack.back().SharingMap[D].PrivateCopy = PrivateCopy; |
| 567 | if (PrivateCopy) |
| 568 | addDSA(PrivateCopy->getDecl(), PrivateCopy, A); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 569 | } |
| 570 | } |
| 571 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 572 | bool DSAStackTy::isOpenMPLocal(VarDecl *D, StackTy::reverse_iterator Iter) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 573 | D = D->getCanonicalDecl(); |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 574 | if (Stack.size() > 2) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 575 | reverse_iterator I = Iter, E = std::prev(Stack.rend()); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 576 | Scope *TopScope = nullptr; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 577 | while (I != E && !isParallelOrTaskRegion(I->Directive)) { |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 578 | ++I; |
| 579 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 580 | if (I == E) |
| 581 | return false; |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 582 | TopScope = I->CurScope ? I->CurScope->getParent() : nullptr; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 583 | Scope *CurScope = getCurScope(); |
| 584 | while (CurScope != TopScope && !CurScope->isDeclScope(D)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 585 | CurScope = CurScope->getParent(); |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 586 | } |
| 587 | return CurScope != TopScope; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 588 | } |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 589 | return false; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 590 | } |
| 591 | |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 592 | /// \brief Build a variable declaration for OpenMP loop iteration variable. |
| 593 | static VarDecl *buildVarDecl(Sema &SemaRef, SourceLocation Loc, QualType Type, |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 594 | StringRef Name, const AttrVec *Attrs = nullptr) { |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 595 | DeclContext *DC = SemaRef.CurContext; |
| 596 | IdentifierInfo *II = &SemaRef.PP.getIdentifierTable().get(Name); |
| 597 | TypeSourceInfo *TInfo = SemaRef.Context.getTrivialTypeSourceInfo(Type, Loc); |
| 598 | VarDecl *Decl = |
| 599 | VarDecl::Create(SemaRef.Context, DC, Loc, Loc, II, Type, TInfo, SC_None); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 600 | if (Attrs) { |
| 601 | for (specific_attr_iterator<AlignedAttr> I(Attrs->begin()), E(Attrs->end()); |
| 602 | I != E; ++I) |
| 603 | Decl->addAttr(*I); |
| 604 | } |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 605 | Decl->setImplicit(); |
| 606 | return Decl; |
| 607 | } |
| 608 | |
| 609 | static DeclRefExpr *buildDeclRefExpr(Sema &S, VarDecl *D, QualType Ty, |
| 610 | SourceLocation Loc, |
| 611 | bool RefersToCapture = false) { |
| 612 | D->setReferenced(); |
| 613 | D->markUsed(S.Context); |
| 614 | return DeclRefExpr::Create(S.getASTContext(), NestedNameSpecifierLoc(), |
| 615 | SourceLocation(), D, RefersToCapture, Loc, Ty, |
| 616 | VK_LValue); |
| 617 | } |
| 618 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 619 | DSAStackTy::DSAVarData DSAStackTy::getTopDSA(ValueDecl *D, bool FromParent) { |
| 620 | D = getCanonicalDecl(D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 621 | DSAVarData DVar; |
| 622 | |
| 623 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 624 | // in a Construct, C/C++, predetermined, p.1] |
| 625 | // Variables appearing in threadprivate directives are threadprivate. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 626 | auto *VD = dyn_cast<VarDecl>(D); |
| 627 | if ((VD && VD->getTLSKind() != VarDecl::TLS_None && |
| 628 | !(VD->hasAttr<OMPThreadPrivateDeclAttr>() && |
Samuel Antao | f8b5012 | 2015-07-13 22:54:53 +0000 | [diff] [blame] | 629 | SemaRef.getLangOpts().OpenMPUseTLS && |
| 630 | SemaRef.getASTContext().getTargetInfo().isTLSSupported())) || |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 631 | (VD && VD->getStorageClass() == SC_Register && |
| 632 | VD->hasAttr<AsmLabelAttr>() && !VD->isLocalVarDecl())) { |
| 633 | addDSA(D, buildDeclRefExpr(SemaRef, VD, D->getType().getNonReferenceType(), |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 634 | D->getLocation()), |
Alexey Bataev | f2453a0 | 2015-05-06 07:25:08 +0000 | [diff] [blame] | 635 | OMPC_threadprivate); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 636 | } |
| 637 | if (Stack[0].SharingMap.count(D)) { |
| 638 | DVar.RefExpr = Stack[0].SharingMap[D].RefExpr; |
| 639 | DVar.CKind = OMPC_threadprivate; |
| 640 | return DVar; |
| 641 | } |
| 642 | |
| 643 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
Alexey Bataev | dffa93a | 2015-12-10 08:20:58 +0000 | [diff] [blame] | 644 | // in a Construct, C/C++, predetermined, p.4] |
| 645 | // Static data members are shared. |
| 646 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 647 | // in a Construct, C/C++, predetermined, p.7] |
| 648 | // Variables with static storage duration that are declared in a scope |
| 649 | // inside the construct are shared. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 650 | if (VD && VD->isStaticDataMember()) { |
Alexey Bataev | dffa93a | 2015-12-10 08:20:58 +0000 | [diff] [blame] | 651 | DSAVarData DVarTemp = |
| 652 | hasDSA(D, isOpenMPPrivate, MatchesAlways(), FromParent); |
| 653 | if (DVarTemp.CKind != OMPC_unknown && DVarTemp.RefExpr) |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 654 | return DVar; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 655 | |
Alexey Bataev | dffa93a | 2015-12-10 08:20:58 +0000 | [diff] [blame] | 656 | DVar.CKind = OMPC_shared; |
| 657 | return DVar; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 658 | } |
| 659 | |
| 660 | QualType Type = D->getType().getNonReferenceType().getCanonicalType(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 661 | bool IsConstant = Type.isConstant(SemaRef.getASTContext()); |
| 662 | Type = SemaRef.getASTContext().getBaseElementType(Type); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 663 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 664 | // in a Construct, C/C++, predetermined, p.6] |
| 665 | // Variables with const qualified type having no mutable member are |
| 666 | // shared. |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 667 | CXXRecordDecl *RD = |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 668 | SemaRef.getLangOpts().CPlusPlus ? Type->getAsCXXRecordDecl() : nullptr; |
Alexey Bataev | c9bd03d | 2015-12-17 06:55:08 +0000 | [diff] [blame] | 669 | if (auto *CTSD = dyn_cast_or_null<ClassTemplateSpecializationDecl>(RD)) |
| 670 | if (auto *CTD = CTSD->getSpecializedTemplate()) |
| 671 | RD = CTD->getTemplatedDecl(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 672 | if (IsConstant && |
Alexey Bataev | 4bcad7f | 2016-02-10 10:50:12 +0000 | [diff] [blame] | 673 | !(SemaRef.getLangOpts().CPlusPlus && RD && RD->hasDefinition() && |
| 674 | RD->hasMutableFields())) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 675 | // Variables with const-qualified type having no mutable member may be |
| 676 | // listed in a firstprivate clause, even if they are static data members. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 677 | DSAVarData DVarTemp = hasDSA(D, MatchesAnyClause(OMPC_firstprivate), |
| 678 | MatchesAlways(), FromParent); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 679 | if (DVarTemp.CKind == OMPC_firstprivate && DVarTemp.RefExpr) |
| 680 | return DVar; |
| 681 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 682 | DVar.CKind = OMPC_shared; |
| 683 | return DVar; |
| 684 | } |
| 685 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 686 | // Explicitly specified attributes and local variables with predetermined |
| 687 | // attributes. |
Alexey Bataev | dffa93a | 2015-12-10 08:20:58 +0000 | [diff] [blame] | 688 | auto StartI = std::next(Stack.rbegin()); |
| 689 | auto EndI = std::prev(Stack.rend()); |
| 690 | if (FromParent && StartI != EndI) { |
| 691 | StartI = std::next(StartI); |
| 692 | } |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 693 | auto I = std::prev(StartI); |
| 694 | if (I->SharingMap.count(D)) { |
| 695 | DVar.RefExpr = I->SharingMap[D].RefExpr; |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 696 | DVar.PrivateCopy = I->SharingMap[D].PrivateCopy; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 697 | DVar.CKind = I->SharingMap[D].Attributes; |
| 698 | DVar.ImplicitDSALoc = I->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 699 | } |
| 700 | |
| 701 | return DVar; |
| 702 | } |
| 703 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 704 | DSAStackTy::DSAVarData DSAStackTy::getImplicitDSA(ValueDecl *D, |
| 705 | bool FromParent) { |
| 706 | D = getCanonicalDecl(D); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 707 | auto StartI = Stack.rbegin(); |
| 708 | auto EndI = std::prev(Stack.rend()); |
| 709 | if (FromParent && StartI != EndI) { |
| 710 | StartI = std::next(StartI); |
| 711 | } |
| 712 | return getDSA(StartI, D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 713 | } |
| 714 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 715 | template <class ClausesPredicate, class DirectivesPredicate> |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 716 | DSAStackTy::DSAVarData DSAStackTy::hasDSA(ValueDecl *D, ClausesPredicate CPred, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 717 | DirectivesPredicate DPred, |
| 718 | bool FromParent) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 719 | D = getCanonicalDecl(D); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 720 | auto StartI = std::next(Stack.rbegin()); |
| 721 | auto EndI = std::prev(Stack.rend()); |
| 722 | if (FromParent && StartI != EndI) { |
| 723 | StartI = std::next(StartI); |
| 724 | } |
| 725 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
| 726 | if (!DPred(I->Directive) && !isParallelOrTaskRegion(I->Directive)) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 727 | continue; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 728 | DSAVarData DVar = getDSA(I, D); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 729 | if (CPred(DVar.CKind)) |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 730 | return DVar; |
| 731 | } |
| 732 | return DSAVarData(); |
| 733 | } |
| 734 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 735 | template <class ClausesPredicate, class DirectivesPredicate> |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 736 | DSAStackTy::DSAVarData |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 737 | DSAStackTy::hasInnermostDSA(ValueDecl *D, ClausesPredicate CPred, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 738 | DirectivesPredicate DPred, bool FromParent) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 739 | D = getCanonicalDecl(D); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 740 | auto StartI = std::next(Stack.rbegin()); |
| 741 | auto EndI = std::prev(Stack.rend()); |
| 742 | if (FromParent && StartI != EndI) { |
| 743 | StartI = std::next(StartI); |
| 744 | } |
| 745 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 746 | if (!DPred(I->Directive)) |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 747 | break; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 748 | DSAVarData DVar = getDSA(I, D); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 749 | if (CPred(DVar.CKind)) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 750 | return DVar; |
| 751 | return DSAVarData(); |
| 752 | } |
| 753 | return DSAVarData(); |
| 754 | } |
| 755 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 756 | bool DSAStackTy::hasExplicitDSA( |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 757 | ValueDecl *D, const llvm::function_ref<bool(OpenMPClauseKind)> &CPred, |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 758 | unsigned Level) { |
| 759 | if (CPred(ClauseKindMode)) |
| 760 | return true; |
| 761 | if (isClauseParsingMode()) |
| 762 | ++Level; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 763 | D = getCanonicalDecl(D); |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 764 | auto StartI = Stack.rbegin(); |
| 765 | auto EndI = std::prev(Stack.rend()); |
NAKAMURA Takumi | 0332eda | 2015-06-23 10:01:20 +0000 | [diff] [blame] | 766 | if (std::distance(StartI, EndI) <= (int)Level) |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 767 | return false; |
| 768 | std::advance(StartI, Level); |
| 769 | return (StartI->SharingMap.count(D) > 0) && StartI->SharingMap[D].RefExpr && |
| 770 | CPred(StartI->SharingMap[D].Attributes); |
| 771 | } |
| 772 | |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 773 | bool DSAStackTy::hasExplicitDirective( |
| 774 | const llvm::function_ref<bool(OpenMPDirectiveKind)> &DPred, |
| 775 | unsigned Level) { |
| 776 | if (isClauseParsingMode()) |
| 777 | ++Level; |
| 778 | auto StartI = Stack.rbegin(); |
| 779 | auto EndI = std::prev(Stack.rend()); |
| 780 | if (std::distance(StartI, EndI) <= (int)Level) |
| 781 | return false; |
| 782 | std::advance(StartI, Level); |
| 783 | return DPred(StartI->Directive); |
| 784 | } |
| 785 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 786 | template <class NamedDirectivesPredicate> |
| 787 | bool DSAStackTy::hasDirective(NamedDirectivesPredicate DPred, bool FromParent) { |
| 788 | auto StartI = std::next(Stack.rbegin()); |
| 789 | auto EndI = std::prev(Stack.rend()); |
| 790 | if (FromParent && StartI != EndI) { |
| 791 | StartI = std::next(StartI); |
| 792 | } |
| 793 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
| 794 | if (DPred(I->Directive, I->DirectiveName, I->ConstructLoc)) |
| 795 | return true; |
| 796 | } |
| 797 | return false; |
| 798 | } |
| 799 | |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 800 | OpenMPDirectiveKind DSAStackTy::getDirectiveForScope(const Scope *S) const { |
| 801 | for (auto I = Stack.rbegin(), EE = Stack.rend(); I != EE; ++I) |
| 802 | if (I->CurScope == S) |
| 803 | return I->Directive; |
| 804 | return OMPD_unknown; |
| 805 | } |
| 806 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 807 | void Sema::InitDataSharingAttributesStack() { |
| 808 | VarDataSharingAttributesStack = new DSAStackTy(*this); |
| 809 | } |
| 810 | |
| 811 | #define DSAStack static_cast<DSAStackTy *>(VarDataSharingAttributesStack) |
| 812 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 813 | bool Sema::IsOpenMPCapturedByRef(ValueDecl *D, |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 814 | const CapturedRegionScopeInfo *RSI) { |
| 815 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| 816 | |
| 817 | auto &Ctx = getASTContext(); |
| 818 | bool IsByRef = true; |
| 819 | |
| 820 | // Find the directive that is associated with the provided scope. |
| 821 | auto DKind = DSAStack->getDirectiveForScope(RSI->TheScope); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 822 | auto Ty = D->getType(); |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 823 | |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 824 | if (isOpenMPTargetExecutionDirective(DKind)) { |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 825 | // This table summarizes how a given variable should be passed to the device |
| 826 | // given its type and the clauses where it appears. This table is based on |
| 827 | // the description in OpenMP 4.5 [2.10.4, target Construct] and |
| 828 | // OpenMP 4.5 [2.15.5, Data-mapping Attribute Rules and Clauses]. |
| 829 | // |
| 830 | // ========================================================================= |
| 831 | // | type | defaultmap | pvt | first | is_device_ptr | map | res. | |
| 832 | // | |(tofrom:scalar)| | pvt | | | | |
| 833 | // ========================================================================= |
| 834 | // | scl | | | | - | | bycopy| |
| 835 | // | scl | | - | x | - | - | bycopy| |
| 836 | // | scl | | x | - | - | - | null | |
| 837 | // | scl | x | | | - | | byref | |
| 838 | // | scl | x | - | x | - | - | bycopy| |
| 839 | // | scl | x | x | - | - | - | null | |
| 840 | // | scl | | - | - | - | x | byref | |
| 841 | // | scl | x | - | - | - | x | byref | |
| 842 | // |
| 843 | // | agg | n.a. | | | - | | byref | |
| 844 | // | agg | n.a. | - | x | - | - | byref | |
| 845 | // | agg | n.a. | x | - | - | - | null | |
| 846 | // | agg | n.a. | - | - | - | x | byref | |
| 847 | // | agg | n.a. | - | - | - | x[] | byref | |
| 848 | // |
| 849 | // | ptr | n.a. | | | - | | bycopy| |
| 850 | // | ptr | n.a. | - | x | - | - | bycopy| |
| 851 | // | ptr | n.a. | x | - | - | - | null | |
| 852 | // | ptr | n.a. | - | - | - | x | byref | |
| 853 | // | ptr | n.a. | - | - | - | x[] | bycopy| |
| 854 | // | ptr | n.a. | - | - | x | | bycopy| |
| 855 | // | ptr | n.a. | - | - | x | x | bycopy| |
| 856 | // | ptr | n.a. | - | - | x | x[] | bycopy| |
| 857 | // ========================================================================= |
| 858 | // Legend: |
| 859 | // scl - scalar |
| 860 | // ptr - pointer |
| 861 | // agg - aggregate |
| 862 | // x - applies |
| 863 | // - - invalid in this combination |
| 864 | // [] - mapped with an array section |
| 865 | // byref - should be mapped by reference |
| 866 | // byval - should be mapped by value |
| 867 | // null - initialize a local variable to null on the device |
| 868 | // |
| 869 | // Observations: |
| 870 | // - All scalar declarations that show up in a map clause have to be passed |
| 871 | // by reference, because they may have been mapped in the enclosing data |
| 872 | // environment. |
| 873 | // - If the scalar value does not fit the size of uintptr, it has to be |
| 874 | // passed by reference, regardless the result in the table above. |
| 875 | // - For pointers mapped by value that have either an implicit map or an |
| 876 | // array section, the runtime library may pass the NULL value to the |
| 877 | // device instead of the value passed to it by the compiler. |
| 878 | |
| 879 | // FIXME: Right now, only implicit maps are implemented. Properly mapping |
| 880 | // values requires having the map, private, and firstprivate clauses SEMA |
| 881 | // and parsing in place, which we don't yet. |
| 882 | |
| 883 | if (Ty->isReferenceType()) |
| 884 | Ty = Ty->castAs<ReferenceType>()->getPointeeType(); |
| 885 | IsByRef = !Ty->isScalarType(); |
| 886 | } |
| 887 | |
| 888 | // When passing data by value, we need to make sure it fits the uintptr size |
| 889 | // and alignment, because the runtime library only deals with uintptr types. |
| 890 | // If it does not fit the uintptr size, we need to pass the data by reference |
| 891 | // instead. |
| 892 | if (!IsByRef && |
| 893 | (Ctx.getTypeSizeInChars(Ty) > |
| 894 | Ctx.getTypeSizeInChars(Ctx.getUIntPtrType()) || |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 895 | Ctx.getDeclAlign(D) > Ctx.getTypeAlignInChars(Ctx.getUIntPtrType()))) |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 896 | IsByRef = true; |
| 897 | |
| 898 | return IsByRef; |
| 899 | } |
| 900 | |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 901 | VarDecl *Sema::IsOpenMPCapturedDecl(ValueDecl *D) { |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 902 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 903 | D = getCanonicalDecl(D); |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 904 | |
| 905 | // If we are attempting to capture a global variable in a directive with |
| 906 | // 'target' we return true so that this global is also mapped to the device. |
| 907 | // |
| 908 | // FIXME: If the declaration is enclosed in a 'declare target' directive, |
| 909 | // then it should not be captured. Therefore, an extra check has to be |
| 910 | // inserted here once support for 'declare target' is added. |
| 911 | // |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 912 | auto *VD = dyn_cast<VarDecl>(D); |
| 913 | if (VD && !VD->hasLocalStorage()) { |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 914 | if (DSAStack->getCurrentDirective() == OMPD_target && |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 915 | !DSAStack->isClauseParsingMode()) |
| 916 | return VD; |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 917 | if (DSAStack->getCurScope() && |
| 918 | DSAStack->hasDirective( |
| 919 | [](OpenMPDirectiveKind K, const DeclarationNameInfo &DNI, |
| 920 | SourceLocation Loc) -> bool { |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 921 | return isOpenMPTargetExecutionDirective(K); |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 922 | }, |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 923 | false)) |
| 924 | return VD; |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 925 | } |
| 926 | |
Alexey Bataev | 48977c3 | 2015-08-04 08:10:48 +0000 | [diff] [blame] | 927 | if (DSAStack->getCurrentDirective() != OMPD_unknown && |
| 928 | (!DSAStack->isClauseParsingMode() || |
| 929 | DSAStack->getParentDirective() != OMPD_unknown)) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 930 | if (DSAStack->isLoopControlVariable(D) || |
| 931 | (VD && VD->hasLocalStorage() && |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 932 | isParallelOrTaskRegion(DSAStack->getCurrentDirective())) || |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 933 | (VD && DSAStack->isForceVarCapturing())) |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 934 | return VD; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 935 | auto DVarPrivate = DSAStack->getTopDSA(D, DSAStack->isClauseParsingMode()); |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 936 | if (DVarPrivate.CKind != OMPC_unknown && isOpenMPPrivate(DVarPrivate.CKind)) |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 937 | return VD ? VD : cast<VarDecl>(DVarPrivate.PrivateCopy->getDecl()); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 938 | DVarPrivate = DSAStack->hasDSA(D, isOpenMPPrivate, MatchesAlways(), |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 939 | DSAStack->isClauseParsingMode()); |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 940 | if (DVarPrivate.CKind != OMPC_unknown) |
| 941 | return VD ? VD : cast<VarDecl>(DVarPrivate.PrivateCopy->getDecl()); |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 942 | } |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 943 | return nullptr; |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 944 | } |
| 945 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 946 | bool Sema::isOpenMPPrivateDecl(ValueDecl *D, unsigned Level) { |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 947 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| 948 | return DSAStack->hasExplicitDSA( |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 949 | D, [](OpenMPClauseKind K) -> bool { return K == OMPC_private; }, Level); |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 950 | } |
| 951 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 952 | bool Sema::isOpenMPTargetCapturedDecl(ValueDecl *D, unsigned Level) { |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 953 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| 954 | // Return true if the current level is no longer enclosed in a target region. |
| 955 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 956 | auto *VD = dyn_cast<VarDecl>(D); |
| 957 | return VD && !VD->hasLocalStorage() && |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 958 | DSAStack->hasExplicitDirective(isOpenMPTargetExecutionDirective, |
| 959 | Level); |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 960 | } |
| 961 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 962 | void Sema::DestroyDataSharingAttributesStack() { delete DSAStack; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 963 | |
| 964 | void Sema::StartOpenMPDSABlock(OpenMPDirectiveKind DKind, |
| 965 | const DeclarationNameInfo &DirName, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 966 | Scope *CurScope, SourceLocation Loc) { |
| 967 | DSAStack->push(DKind, DirName, CurScope, Loc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 968 | PushExpressionEvaluationContext(PotentiallyEvaluated); |
| 969 | } |
| 970 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 971 | void Sema::StartOpenMPClause(OpenMPClauseKind K) { |
| 972 | DSAStack->setClauseParsingMode(K); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 973 | } |
| 974 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 975 | void Sema::EndOpenMPClause() { |
| 976 | DSAStack->setClauseParsingMode(/*K=*/OMPC_unknown); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 977 | } |
| 978 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 979 | void Sema::EndOpenMPDSABlock(Stmt *CurDirective) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 980 | // OpenMP [2.14.3.5, Restrictions, C/C++, p.1] |
| 981 | // A variable of class type (or array thereof) that appears in a lastprivate |
| 982 | // clause requires an accessible, unambiguous default constructor for the |
| 983 | // class type, unless the list item is also specified in a firstprivate |
| 984 | // clause. |
| 985 | if (auto D = dyn_cast_or_null<OMPExecutableDirective>(CurDirective)) { |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 986 | for (auto *C : D->clauses()) { |
| 987 | if (auto *Clause = dyn_cast<OMPLastprivateClause>(C)) { |
| 988 | SmallVector<Expr *, 8> PrivateCopies; |
| 989 | for (auto *DE : Clause->varlists()) { |
| 990 | if (DE->isValueDependent() || DE->isTypeDependent()) { |
| 991 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 992 | continue; |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 993 | } |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 994 | auto *DRE = cast<DeclRefExpr>(DE->IgnoreParens()); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 995 | VarDecl *VD = cast<VarDecl>(DRE->getDecl()); |
| 996 | QualType Type = VD->getType().getNonReferenceType(); |
| 997 | auto DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 998 | if (DVar.CKind == OMPC_lastprivate) { |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 999 | // Generate helper private variable and initialize it with the |
| 1000 | // default value. The address of the original variable is replaced |
| 1001 | // by the address of the new private variable in CodeGen. This new |
| 1002 | // variable is not added to IdResolver, so the code in the OpenMP |
| 1003 | // region uses original variable for proper diagnostics. |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 1004 | auto *VDPrivate = buildVarDecl( |
| 1005 | *this, DE->getExprLoc(), Type.getUnqualifiedType(), |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 1006 | VD->getName(), VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1007 | ActOnUninitializedDecl(VDPrivate, /*TypeMayContainAuto=*/false); |
| 1008 | if (VDPrivate->isInvalidDecl()) |
| 1009 | continue; |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 1010 | PrivateCopies.push_back(buildDeclRefExpr( |
| 1011 | *this, VDPrivate, DE->getType(), DE->getExprLoc())); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1012 | } else { |
| 1013 | // The variable is also a firstprivate, so initialization sequence |
| 1014 | // for private copy is generated already. |
| 1015 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1016 | } |
| 1017 | } |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1018 | // Set initializers to private copies if no errors were found. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1019 | if (PrivateCopies.size() == Clause->varlist_size()) |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1020 | Clause->setPrivateCopies(PrivateCopies); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1021 | } |
| 1022 | } |
| 1023 | } |
| 1024 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1025 | DSAStack->pop(); |
| 1026 | DiscardCleanupsInEvaluationContext(); |
| 1027 | PopExpressionEvaluationContext(); |
| 1028 | } |
| 1029 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 1030 | static bool FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV, |
| 1031 | Expr *NumIterations, Sema &SemaRef, |
| 1032 | Scope *S); |
| 1033 | |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1034 | namespace { |
| 1035 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1036 | class VarDeclFilterCCC : public CorrectionCandidateCallback { |
| 1037 | private: |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1038 | Sema &SemaRef; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1039 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1040 | public: |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1041 | explicit VarDeclFilterCCC(Sema &S) : SemaRef(S) {} |
Craig Topper | e14c0f8 | 2014-03-12 04:55:44 +0000 | [diff] [blame] | 1042 | bool ValidateCandidate(const TypoCorrection &Candidate) override { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1043 | NamedDecl *ND = Candidate.getCorrectionDecl(); |
| 1044 | if (VarDecl *VD = dyn_cast_or_null<VarDecl>(ND)) { |
| 1045 | return VD->hasGlobalStorage() && |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1046 | SemaRef.isDeclInScope(ND, SemaRef.getCurLexicalContext(), |
| 1047 | SemaRef.getCurScope()); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1048 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1049 | return false; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1050 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1051 | }; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1052 | } // namespace |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1053 | |
| 1054 | ExprResult Sema::ActOnOpenMPIdExpression(Scope *CurScope, |
| 1055 | CXXScopeSpec &ScopeSpec, |
| 1056 | const DeclarationNameInfo &Id) { |
| 1057 | LookupResult Lookup(*this, Id, LookupOrdinaryName); |
| 1058 | LookupParsedName(Lookup, CurScope, &ScopeSpec, true); |
| 1059 | |
| 1060 | if (Lookup.isAmbiguous()) |
| 1061 | return ExprError(); |
| 1062 | |
| 1063 | VarDecl *VD; |
| 1064 | if (!Lookup.isSingleResult()) { |
Kaelyn Takata | 89c881b | 2014-10-27 18:07:29 +0000 | [diff] [blame] | 1065 | if (TypoCorrection Corrected = CorrectTypo( |
| 1066 | Id, LookupOrdinaryName, CurScope, nullptr, |
| 1067 | llvm::make_unique<VarDeclFilterCCC>(*this), CTK_ErrorRecovery)) { |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 1068 | diagnoseTypo(Corrected, |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 1069 | PDiag(Lookup.empty() |
| 1070 | ? diag::err_undeclared_var_use_suggest |
| 1071 | : diag::err_omp_expected_var_arg_suggest) |
| 1072 | << Id.getName()); |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 1073 | VD = Corrected.getCorrectionDeclAs<VarDecl>(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1074 | } else { |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 1075 | Diag(Id.getLoc(), Lookup.empty() ? diag::err_undeclared_var_use |
| 1076 | : diag::err_omp_expected_var_arg) |
| 1077 | << Id.getName(); |
| 1078 | return ExprError(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1079 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1080 | } else { |
| 1081 | if (!(VD = Lookup.getAsSingle<VarDecl>())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1082 | Diag(Id.getLoc(), diag::err_omp_expected_var_arg) << Id.getName(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1083 | Diag(Lookup.getFoundDecl()->getLocation(), diag::note_declared_at); |
| 1084 | return ExprError(); |
| 1085 | } |
| 1086 | } |
| 1087 | Lookup.suppressDiagnostics(); |
| 1088 | |
| 1089 | // OpenMP [2.9.2, Syntax, C/C++] |
| 1090 | // Variables must be file-scope, namespace-scope, or static block-scope. |
| 1091 | if (!VD->hasGlobalStorage()) { |
| 1092 | Diag(Id.getLoc(), diag::err_omp_global_var_arg) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1093 | << getOpenMPDirectiveName(OMPD_threadprivate) << !VD->isStaticLocal(); |
| 1094 | bool IsDecl = |
| 1095 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1096 | Diag(VD->getLocation(), |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1097 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1098 | << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1099 | return ExprError(); |
| 1100 | } |
| 1101 | |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1102 | VarDecl *CanonicalVD = VD->getCanonicalDecl(); |
| 1103 | NamedDecl *ND = cast<NamedDecl>(CanonicalVD); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1104 | // OpenMP [2.9.2, Restrictions, C/C++, p.2] |
| 1105 | // A threadprivate directive for file-scope variables must appear outside |
| 1106 | // any definition or declaration. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1107 | if (CanonicalVD->getDeclContext()->isTranslationUnit() && |
| 1108 | !getCurLexicalContext()->isTranslationUnit()) { |
| 1109 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1110 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1111 | bool IsDecl = |
| 1112 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1113 | Diag(VD->getLocation(), |
| 1114 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1115 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1116 | return ExprError(); |
| 1117 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1118 | // OpenMP [2.9.2, Restrictions, C/C++, p.3] |
| 1119 | // A threadprivate directive for static class member variables must appear |
| 1120 | // in the class definition, in the same scope in which the member |
| 1121 | // variables are declared. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1122 | if (CanonicalVD->isStaticDataMember() && |
| 1123 | !CanonicalVD->getDeclContext()->Equals(getCurLexicalContext())) { |
| 1124 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1125 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1126 | bool IsDecl = |
| 1127 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1128 | Diag(VD->getLocation(), |
| 1129 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1130 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1131 | return ExprError(); |
| 1132 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1133 | // OpenMP [2.9.2, Restrictions, C/C++, p.4] |
| 1134 | // A threadprivate directive for namespace-scope variables must appear |
| 1135 | // outside any definition or declaration other than the namespace |
| 1136 | // definition itself. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1137 | if (CanonicalVD->getDeclContext()->isNamespace() && |
| 1138 | (!getCurLexicalContext()->isFileContext() || |
| 1139 | !getCurLexicalContext()->Encloses(CanonicalVD->getDeclContext()))) { |
| 1140 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1141 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1142 | bool IsDecl = |
| 1143 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1144 | Diag(VD->getLocation(), |
| 1145 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1146 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1147 | return ExprError(); |
| 1148 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1149 | // OpenMP [2.9.2, Restrictions, C/C++, p.6] |
| 1150 | // A threadprivate directive for static block-scope variables must appear |
| 1151 | // in the scope of the variable and not in a nested scope. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1152 | if (CanonicalVD->isStaticLocal() && CurScope && |
| 1153 | !isDeclInScope(ND, getCurLexicalContext(), CurScope)) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1154 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1155 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1156 | bool IsDecl = |
| 1157 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1158 | Diag(VD->getLocation(), |
| 1159 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1160 | << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1161 | return ExprError(); |
| 1162 | } |
| 1163 | |
| 1164 | // OpenMP [2.9.2, Restrictions, C/C++, p.2-6] |
| 1165 | // A threadprivate directive must lexically precede all references to any |
| 1166 | // of the variables in its list. |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 1167 | if (VD->isUsed() && !DSAStack->isThreadPrivate(VD)) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1168 | Diag(Id.getLoc(), diag::err_omp_var_used) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1169 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1170 | return ExprError(); |
| 1171 | } |
| 1172 | |
| 1173 | QualType ExprType = VD->getType().getNonReferenceType(); |
Alexey Bataev | 376b4a4 | 2016-02-09 09:41:09 +0000 | [diff] [blame] | 1174 | return DeclRefExpr::Create(Context, NestedNameSpecifierLoc(), |
| 1175 | SourceLocation(), VD, |
| 1176 | /*RefersToEnclosingVariableOrCapture=*/false, |
| 1177 | Id.getLoc(), ExprType, VK_LValue); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1178 | } |
| 1179 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1180 | Sema::DeclGroupPtrTy |
| 1181 | Sema::ActOnOpenMPThreadprivateDirective(SourceLocation Loc, |
| 1182 | ArrayRef<Expr *> VarList) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1183 | if (OMPThreadPrivateDecl *D = CheckOMPThreadPrivateDecl(Loc, VarList)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1184 | CurContext->addDecl(D); |
| 1185 | return DeclGroupPtrTy::make(DeclGroupRef(D)); |
| 1186 | } |
David Blaikie | 0403cb1 | 2016-01-15 23:43:25 +0000 | [diff] [blame] | 1187 | return nullptr; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1188 | } |
| 1189 | |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1190 | namespace { |
| 1191 | class LocalVarRefChecker : public ConstStmtVisitor<LocalVarRefChecker, bool> { |
| 1192 | Sema &SemaRef; |
| 1193 | |
| 1194 | public: |
| 1195 | bool VisitDeclRefExpr(const DeclRefExpr *E) { |
| 1196 | if (auto VD = dyn_cast<VarDecl>(E->getDecl())) { |
| 1197 | if (VD->hasLocalStorage()) { |
| 1198 | SemaRef.Diag(E->getLocStart(), |
| 1199 | diag::err_omp_local_var_in_threadprivate_init) |
| 1200 | << E->getSourceRange(); |
| 1201 | SemaRef.Diag(VD->getLocation(), diag::note_defined_here) |
| 1202 | << VD << VD->getSourceRange(); |
| 1203 | return true; |
| 1204 | } |
| 1205 | } |
| 1206 | return false; |
| 1207 | } |
| 1208 | bool VisitStmt(const Stmt *S) { |
| 1209 | for (auto Child : S->children()) { |
| 1210 | if (Child && Visit(Child)) |
| 1211 | return true; |
| 1212 | } |
| 1213 | return false; |
| 1214 | } |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 1215 | explicit LocalVarRefChecker(Sema &SemaRef) : SemaRef(SemaRef) {} |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1216 | }; |
| 1217 | } // namespace |
| 1218 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1219 | OMPThreadPrivateDecl * |
| 1220 | Sema::CheckOMPThreadPrivateDecl(SourceLocation Loc, ArrayRef<Expr *> VarList) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1221 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1222 | for (auto &RefExpr : VarList) { |
| 1223 | DeclRefExpr *DE = cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1224 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); |
| 1225 | SourceLocation ILoc = DE->getExprLoc(); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1226 | |
Alexey Bataev | 376b4a4 | 2016-02-09 09:41:09 +0000 | [diff] [blame] | 1227 | // Mark variable as used. |
| 1228 | VD->setReferenced(); |
| 1229 | VD->markUsed(Context); |
| 1230 | |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 1231 | QualType QType = VD->getType(); |
| 1232 | if (QType->isDependentType() || QType->isInstantiationDependentType()) { |
| 1233 | // It will be analyzed later. |
| 1234 | Vars.push_back(DE); |
| 1235 | continue; |
| 1236 | } |
| 1237 | |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1238 | // OpenMP [2.9.2, Restrictions, C/C++, p.10] |
| 1239 | // A threadprivate variable must not have an incomplete type. |
| 1240 | if (RequireCompleteType(ILoc, VD->getType(), |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1241 | diag::err_omp_threadprivate_incomplete_type)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1242 | continue; |
| 1243 | } |
| 1244 | |
| 1245 | // OpenMP [2.9.2, Restrictions, C/C++, p.10] |
| 1246 | // A threadprivate variable must not have a reference type. |
| 1247 | if (VD->getType()->isReferenceType()) { |
| 1248 | Diag(ILoc, diag::err_omp_ref_type_arg) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1249 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD->getType(); |
| 1250 | bool IsDecl = |
| 1251 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1252 | Diag(VD->getLocation(), |
| 1253 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1254 | << VD; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1255 | continue; |
| 1256 | } |
| 1257 | |
Samuel Antao | f8b5012 | 2015-07-13 22:54:53 +0000 | [diff] [blame] | 1258 | // Check if this is a TLS variable. If TLS is not being supported, produce |
| 1259 | // the corresponding diagnostic. |
| 1260 | if ((VD->getTLSKind() != VarDecl::TLS_None && |
| 1261 | !(VD->hasAttr<OMPThreadPrivateDeclAttr>() && |
| 1262 | getLangOpts().OpenMPUseTLS && |
| 1263 | getASTContext().getTargetInfo().isTLSSupported())) || |
Alexey Bataev | 1a8b3f1 | 2015-05-06 06:34:55 +0000 | [diff] [blame] | 1264 | (VD->getStorageClass() == SC_Register && VD->hasAttr<AsmLabelAttr>() && |
| 1265 | !VD->isLocalVarDecl())) { |
Alexey Bataev | 26a3924 | 2015-01-13 03:35:30 +0000 | [diff] [blame] | 1266 | Diag(ILoc, diag::err_omp_var_thread_local) |
| 1267 | << VD << ((VD->getTLSKind() != VarDecl::TLS_None) ? 0 : 1); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1268 | bool IsDecl = |
| 1269 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1270 | Diag(VD->getLocation(), |
| 1271 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1272 | << VD; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1273 | continue; |
| 1274 | } |
| 1275 | |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1276 | // Check if initial value of threadprivate variable reference variable with |
| 1277 | // local storage (it is not supported by runtime). |
| 1278 | if (auto Init = VD->getAnyInitializer()) { |
| 1279 | LocalVarRefChecker Checker(*this); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1280 | if (Checker.Visit(Init)) |
| 1281 | continue; |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1282 | } |
| 1283 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1284 | Vars.push_back(RefExpr); |
Alexey Bataev | d178ad4 | 2014-03-07 08:03:37 +0000 | [diff] [blame] | 1285 | DSAStack->addDSA(VD, DE, OMPC_threadprivate); |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 1286 | VD->addAttr(OMPThreadPrivateDeclAttr::CreateImplicit( |
| 1287 | Context, SourceRange(Loc, Loc))); |
| 1288 | if (auto *ML = Context.getASTMutationListener()) |
| 1289 | ML->DeclarationMarkedOpenMPThreadPrivate(VD); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1290 | } |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 1291 | OMPThreadPrivateDecl *D = nullptr; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 1292 | if (!Vars.empty()) { |
| 1293 | D = OMPThreadPrivateDecl::Create(Context, getCurLexicalContext(), Loc, |
| 1294 | Vars); |
| 1295 | D->setAccess(AS_public); |
| 1296 | } |
| 1297 | return D; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1298 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1299 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1300 | static void ReportOriginalDSA(Sema &SemaRef, DSAStackTy *Stack, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1301 | const ValueDecl *D, DSAStackTy::DSAVarData DVar, |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1302 | bool IsLoopIterVar = false) { |
| 1303 | if (DVar.RefExpr) { |
| 1304 | SemaRef.Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_explicit_dsa) |
| 1305 | << getOpenMPClauseName(DVar.CKind); |
| 1306 | return; |
| 1307 | } |
| 1308 | enum { |
| 1309 | PDSA_StaticMemberShared, |
| 1310 | PDSA_StaticLocalVarShared, |
| 1311 | PDSA_LoopIterVarPrivate, |
| 1312 | PDSA_LoopIterVarLinear, |
| 1313 | PDSA_LoopIterVarLastprivate, |
| 1314 | PDSA_ConstVarShared, |
| 1315 | PDSA_GlobalVarShared, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1316 | PDSA_TaskVarFirstprivate, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1317 | PDSA_LocalVarPrivate, |
| 1318 | PDSA_Implicit |
| 1319 | } Reason = PDSA_Implicit; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1320 | bool ReportHint = false; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1321 | auto ReportLoc = D->getLocation(); |
| 1322 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1323 | if (IsLoopIterVar) { |
| 1324 | if (DVar.CKind == OMPC_private) |
| 1325 | Reason = PDSA_LoopIterVarPrivate; |
| 1326 | else if (DVar.CKind == OMPC_lastprivate) |
| 1327 | Reason = PDSA_LoopIterVarLastprivate; |
| 1328 | else |
| 1329 | Reason = PDSA_LoopIterVarLinear; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1330 | } else if (DVar.DKind == OMPD_task && DVar.CKind == OMPC_firstprivate) { |
| 1331 | Reason = PDSA_TaskVarFirstprivate; |
| 1332 | ReportLoc = DVar.ImplicitDSALoc; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1333 | } else if (VD && VD->isStaticLocal()) |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1334 | Reason = PDSA_StaticLocalVarShared; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1335 | else if (VD && VD->isStaticDataMember()) |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1336 | Reason = PDSA_StaticMemberShared; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1337 | else if (VD && VD->isFileVarDecl()) |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1338 | Reason = PDSA_GlobalVarShared; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1339 | else if (D->getType().isConstant(SemaRef.getASTContext())) |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1340 | Reason = PDSA_ConstVarShared; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1341 | else if (VD && VD->isLocalVarDecl() && DVar.CKind == OMPC_private) { |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1342 | ReportHint = true; |
| 1343 | Reason = PDSA_LocalVarPrivate; |
| 1344 | } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1345 | if (Reason != PDSA_Implicit) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1346 | SemaRef.Diag(ReportLoc, diag::note_omp_predetermined_dsa) |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1347 | << Reason << ReportHint |
| 1348 | << getOpenMPDirectiveName(Stack->getCurrentDirective()); |
| 1349 | } else if (DVar.ImplicitDSALoc.isValid()) { |
| 1350 | SemaRef.Diag(DVar.ImplicitDSALoc, diag::note_omp_implicit_dsa) |
| 1351 | << getOpenMPClauseName(DVar.CKind); |
| 1352 | } |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1353 | } |
| 1354 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1355 | namespace { |
| 1356 | class DSAAttrChecker : public StmtVisitor<DSAAttrChecker, void> { |
| 1357 | DSAStackTy *Stack; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1358 | Sema &SemaRef; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1359 | bool ErrorFound; |
| 1360 | CapturedStmt *CS; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1361 | llvm::SmallVector<Expr *, 8> ImplicitFirstprivate; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1362 | llvm::DenseMap<ValueDecl *, Expr *> VarsWithInheritedDSA; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1363 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1364 | public: |
| 1365 | void VisitDeclRefExpr(DeclRefExpr *E) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1366 | if (auto *VD = dyn_cast<VarDecl>(E->getDecl())) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1367 | // Skip internally declared variables. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1368 | if (VD->isLocalVarDecl() && !CS->capturesVariable(VD)) |
| 1369 | return; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1370 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1371 | auto DVar = Stack->getTopDSA(VD, false); |
| 1372 | // Check if the variable has explicit DSA set and stop analysis if it so. |
| 1373 | if (DVar.RefExpr) return; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1374 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1375 | auto ELoc = E->getExprLoc(); |
| 1376 | auto DKind = Stack->getCurrentDirective(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1377 | // The default(none) clause requires that each variable that is referenced |
| 1378 | // in the construct, and does not have a predetermined data-sharing |
| 1379 | // attribute, must have its data-sharing attribute explicitly determined |
| 1380 | // by being listed in a data-sharing attribute clause. |
| 1381 | if (DVar.CKind == OMPC_unknown && Stack->getDefaultDSA() == DSA_none && |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1382 | isParallelOrTaskRegion(DKind) && |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1383 | VarsWithInheritedDSA.count(VD) == 0) { |
| 1384 | VarsWithInheritedDSA[VD] = E; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1385 | return; |
| 1386 | } |
| 1387 | |
| 1388 | // OpenMP [2.9.3.6, Restrictions, p.2] |
| 1389 | // A list item that appears in a reduction clause of the innermost |
| 1390 | // enclosing worksharing or parallel construct may not be accessed in an |
| 1391 | // explicit task. |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1392 | DVar = Stack->hasInnermostDSA(VD, MatchesAnyClause(OMPC_reduction), |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1393 | [](OpenMPDirectiveKind K) -> bool { |
| 1394 | return isOpenMPParallelDirective(K) || |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1395 | isOpenMPWorksharingDirective(K) || |
| 1396 | isOpenMPTeamsDirective(K); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1397 | }, |
| 1398 | false); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1399 | if (DKind == OMPD_task && DVar.CKind == OMPC_reduction) { |
| 1400 | ErrorFound = true; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1401 | SemaRef.Diag(ELoc, diag::err_omp_reduction_in_task); |
| 1402 | ReportOriginalDSA(SemaRef, Stack, VD, DVar); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1403 | return; |
| 1404 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1405 | |
| 1406 | // Define implicit data-sharing attributes for task. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1407 | DVar = Stack->getImplicitDSA(VD, false); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1408 | if (DKind == OMPD_task && DVar.CKind != OMPC_shared) |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1409 | ImplicitFirstprivate.push_back(E); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1410 | } |
| 1411 | } |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1412 | void VisitMemberExpr(MemberExpr *E) { |
| 1413 | if (isa<CXXThisExpr>(E->getBase()->IgnoreParens())) { |
| 1414 | if (auto *FD = dyn_cast<FieldDecl>(E->getMemberDecl())) { |
| 1415 | auto DVar = Stack->getTopDSA(FD, false); |
| 1416 | // Check if the variable has explicit DSA set and stop analysis if it |
| 1417 | // so. |
| 1418 | if (DVar.RefExpr) |
| 1419 | return; |
| 1420 | |
| 1421 | auto ELoc = E->getExprLoc(); |
| 1422 | auto DKind = Stack->getCurrentDirective(); |
| 1423 | // OpenMP [2.9.3.6, Restrictions, p.2] |
| 1424 | // A list item that appears in a reduction clause of the innermost |
| 1425 | // enclosing worksharing or parallel construct may not be accessed in |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 1426 | // an explicit task. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1427 | DVar = |
| 1428 | Stack->hasInnermostDSA(FD, MatchesAnyClause(OMPC_reduction), |
| 1429 | [](OpenMPDirectiveKind K) -> bool { |
| 1430 | return isOpenMPParallelDirective(K) || |
| 1431 | isOpenMPWorksharingDirective(K) || |
| 1432 | isOpenMPTeamsDirective(K); |
| 1433 | }, |
| 1434 | false); |
| 1435 | if (DKind == OMPD_task && DVar.CKind == OMPC_reduction) { |
| 1436 | ErrorFound = true; |
| 1437 | SemaRef.Diag(ELoc, diag::err_omp_reduction_in_task); |
| 1438 | ReportOriginalDSA(SemaRef, Stack, FD, DVar); |
| 1439 | return; |
| 1440 | } |
| 1441 | |
| 1442 | // Define implicit data-sharing attributes for task. |
| 1443 | DVar = Stack->getImplicitDSA(FD, false); |
| 1444 | if (DKind == OMPD_task && DVar.CKind != OMPC_shared) |
| 1445 | ImplicitFirstprivate.push_back(E); |
| 1446 | } |
| 1447 | } |
| 1448 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1449 | void VisitOMPExecutableDirective(OMPExecutableDirective *S) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1450 | for (auto *C : S->clauses()) { |
| 1451 | // Skip analysis of arguments of implicitly defined firstprivate clause |
| 1452 | // for task directives. |
| 1453 | if (C && (!isa<OMPFirstprivateClause>(C) || C->getLocStart().isValid())) |
| 1454 | for (auto *CC : C->children()) { |
| 1455 | if (CC) |
| 1456 | Visit(CC); |
| 1457 | } |
| 1458 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1459 | } |
| 1460 | void VisitStmt(Stmt *S) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1461 | for (auto *C : S->children()) { |
| 1462 | if (C && !isa<OMPExecutableDirective>(C)) |
| 1463 | Visit(C); |
| 1464 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1465 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1466 | |
| 1467 | bool isErrorFound() { return ErrorFound; } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1468 | ArrayRef<Expr *> getImplicitFirstprivate() { return ImplicitFirstprivate; } |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1469 | llvm::DenseMap<ValueDecl *, Expr *> &getVarsWithInheritedDSA() { |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1470 | return VarsWithInheritedDSA; |
| 1471 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1472 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1473 | DSAAttrChecker(DSAStackTy *S, Sema &SemaRef, CapturedStmt *CS) |
| 1474 | : Stack(S), SemaRef(SemaRef), ErrorFound(false), CS(CS) {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1475 | }; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1476 | } // namespace |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1477 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1478 | void Sema::ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, Scope *CurScope) { |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1479 | switch (DKind) { |
| 1480 | case OMPD_parallel: { |
| 1481 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1482 | QualType KmpInt32PtrTy = |
| 1483 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1484 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1485 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1486 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1487 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1488 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1489 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1490 | Params); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1491 | break; |
| 1492 | } |
| 1493 | case OMPD_simd: { |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1494 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1495 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1496 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1497 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1498 | Params); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1499 | break; |
| 1500 | } |
| 1501 | case OMPD_for: { |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1502 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1503 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1504 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1505 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1506 | Params); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1507 | break; |
| 1508 | } |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1509 | case OMPD_for_simd: { |
| 1510 | Sema::CapturedParamNameType Params[] = { |
| 1511 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1512 | }; |
| 1513 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1514 | Params); |
| 1515 | break; |
| 1516 | } |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 1517 | case OMPD_sections: { |
| 1518 | Sema::CapturedParamNameType Params[] = { |
| 1519 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1520 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1521 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1522 | Params); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 1523 | break; |
| 1524 | } |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1525 | case OMPD_section: { |
| 1526 | Sema::CapturedParamNameType Params[] = { |
| 1527 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1528 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1529 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1530 | Params); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1531 | break; |
| 1532 | } |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 1533 | case OMPD_single: { |
| 1534 | Sema::CapturedParamNameType Params[] = { |
| 1535 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1536 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1537 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1538 | Params); |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 1539 | break; |
| 1540 | } |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1541 | case OMPD_master: { |
| 1542 | Sema::CapturedParamNameType Params[] = { |
| 1543 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1544 | }; |
| 1545 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1546 | Params); |
| 1547 | break; |
| 1548 | } |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1549 | case OMPD_critical: { |
| 1550 | Sema::CapturedParamNameType Params[] = { |
| 1551 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1552 | }; |
| 1553 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1554 | Params); |
| 1555 | break; |
| 1556 | } |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1557 | case OMPD_parallel_for: { |
| 1558 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1559 | QualType KmpInt32PtrTy = |
| 1560 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1561 | Sema::CapturedParamNameType Params[] = { |
| 1562 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1563 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1564 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1565 | }; |
| 1566 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1567 | Params); |
| 1568 | break; |
| 1569 | } |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1570 | case OMPD_parallel_for_simd: { |
| 1571 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1572 | QualType KmpInt32PtrTy = |
| 1573 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1574 | Sema::CapturedParamNameType Params[] = { |
| 1575 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1576 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1577 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1578 | }; |
| 1579 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1580 | Params); |
| 1581 | break; |
| 1582 | } |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1583 | case OMPD_parallel_sections: { |
Alexey Bataev | 68adb7d | 2015-04-14 03:29:22 +0000 | [diff] [blame] | 1584 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1585 | QualType KmpInt32PtrTy = |
| 1586 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1587 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | 68adb7d | 2015-04-14 03:29:22 +0000 | [diff] [blame] | 1588 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1589 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1590 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1591 | }; |
| 1592 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1593 | Params); |
| 1594 | break; |
| 1595 | } |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1596 | case OMPD_task: { |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1597 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 3ae88e2 | 2015-05-22 08:56:35 +0000 | [diff] [blame] | 1598 | QualType Args[] = {Context.VoidPtrTy.withConst().withRestrict()}; |
| 1599 | FunctionProtoType::ExtProtoInfo EPI; |
| 1600 | EPI.Variadic = true; |
| 1601 | QualType CopyFnType = Context.getFunctionType(Context.VoidTy, Args, EPI); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1602 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1603 | std::make_pair(".global_tid.", KmpInt32Ty), |
| 1604 | std::make_pair(".part_id.", KmpInt32Ty), |
Alexey Bataev | 3ae88e2 | 2015-05-22 08:56:35 +0000 | [diff] [blame] | 1605 | std::make_pair(".privates.", |
| 1606 | Context.VoidPtrTy.withConst().withRestrict()), |
| 1607 | std::make_pair( |
| 1608 | ".copy_fn.", |
| 1609 | Context.getPointerType(CopyFnType).withConst().withRestrict()), |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1610 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1611 | }; |
| 1612 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1613 | Params); |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1614 | // Mark this captured region as inlined, because we don't use outlined |
| 1615 | // function directly. |
| 1616 | getCurCapturedRegion()->TheCapturedDecl->addAttr( |
| 1617 | AlwaysInlineAttr::CreateImplicit( |
| 1618 | Context, AlwaysInlineAttr::Keyword_forceinline, SourceRange())); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1619 | break; |
| 1620 | } |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1621 | case OMPD_ordered: { |
| 1622 | Sema::CapturedParamNameType Params[] = { |
| 1623 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1624 | }; |
| 1625 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1626 | Params); |
| 1627 | break; |
| 1628 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1629 | case OMPD_atomic: { |
| 1630 | Sema::CapturedParamNameType Params[] = { |
| 1631 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1632 | }; |
| 1633 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1634 | Params); |
| 1635 | break; |
| 1636 | } |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 1637 | case OMPD_target_data: |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 1638 | case OMPD_target: |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 1639 | case OMPD_target_parallel: |
| 1640 | case OMPD_target_parallel_for: { |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1641 | Sema::CapturedParamNameType Params[] = { |
| 1642 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1643 | }; |
| 1644 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1645 | Params); |
| 1646 | break; |
| 1647 | } |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1648 | case OMPD_teams: { |
| 1649 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1650 | QualType KmpInt32PtrTy = |
| 1651 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1652 | Sema::CapturedParamNameType Params[] = { |
| 1653 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1654 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1655 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1656 | }; |
| 1657 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1658 | Params); |
| 1659 | break; |
| 1660 | } |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1661 | case OMPD_taskgroup: { |
| 1662 | Sema::CapturedParamNameType Params[] = { |
| 1663 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1664 | }; |
| 1665 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1666 | Params); |
| 1667 | break; |
| 1668 | } |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1669 | case OMPD_taskloop: { |
| 1670 | Sema::CapturedParamNameType Params[] = { |
| 1671 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1672 | }; |
| 1673 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1674 | Params); |
| 1675 | break; |
| 1676 | } |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1677 | case OMPD_taskloop_simd: { |
| 1678 | Sema::CapturedParamNameType Params[] = { |
| 1679 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1680 | }; |
| 1681 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1682 | Params); |
| 1683 | break; |
| 1684 | } |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1685 | case OMPD_distribute: { |
| 1686 | Sema::CapturedParamNameType Params[] = { |
| 1687 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1688 | }; |
| 1689 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1690 | Params); |
| 1691 | break; |
| 1692 | } |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1693 | case OMPD_threadprivate: |
Alexey Bataev | ee9af45 | 2014-11-21 11:33:46 +0000 | [diff] [blame] | 1694 | case OMPD_taskyield: |
| 1695 | case OMPD_barrier: |
| 1696 | case OMPD_taskwait: |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1697 | case OMPD_cancellation_point: |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1698 | case OMPD_cancel: |
Alexey Bataev | ee9af45 | 2014-11-21 11:33:46 +0000 | [diff] [blame] | 1699 | case OMPD_flush: |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1700 | case OMPD_target_enter_data: |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1701 | case OMPD_target_exit_data: |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 1702 | case OMPD_declare_reduction: |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1703 | llvm_unreachable("OpenMP Directive is not allowed"); |
| 1704 | case OMPD_unknown: |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1705 | llvm_unreachable("Unknown OpenMP directive"); |
| 1706 | } |
| 1707 | } |
| 1708 | |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1709 | static OMPCapturedExprDecl *buildCaptureDecl(Sema &S, IdentifierInfo *Id, |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 1710 | Expr *CaptureExpr, bool WithInit) { |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 1711 | assert(CaptureExpr); |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 1712 | ASTContext &C = S.getASTContext(); |
| 1713 | Expr *Init = CaptureExpr->IgnoreImpCasts(); |
| 1714 | QualType Ty = Init->getType(); |
| 1715 | if (CaptureExpr->getObjectKind() == OK_Ordinary && CaptureExpr->isGLValue()) { |
| 1716 | if (S.getLangOpts().CPlusPlus) |
| 1717 | Ty = C.getLValueReferenceType(Ty); |
| 1718 | else { |
| 1719 | Ty = C.getPointerType(Ty); |
| 1720 | ExprResult Res = |
| 1721 | S.CreateBuiltinUnaryOp(CaptureExpr->getExprLoc(), UO_AddrOf, Init); |
| 1722 | if (!Res.isUsable()) |
| 1723 | return nullptr; |
| 1724 | Init = Res.get(); |
| 1725 | } |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 1726 | WithInit = true; |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 1727 | } |
| 1728 | auto *CED = OMPCapturedExprDecl::Create(C, S.CurContext, Id, Ty); |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 1729 | if (!WithInit) |
| 1730 | CED->addAttr(OMPCaptureNoInitAttr::CreateImplicit(C, SourceRange())); |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 1731 | S.CurContext->addHiddenDecl(CED); |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 1732 | S.AddInitializerToDecl(CED, Init, /*DirectInit=*/false, |
| 1733 | /*TypeMayContainAuto=*/true); |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1734 | return CED; |
| 1735 | } |
| 1736 | |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 1737 | static DeclRefExpr *buildCapture(Sema &S, ValueDecl *D, Expr *CaptureExpr, |
| 1738 | bool WithInit) { |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 1739 | OMPCapturedExprDecl *CD; |
| 1740 | if (auto *VD = S.IsOpenMPCapturedDecl(D)) |
| 1741 | CD = cast<OMPCapturedExprDecl>(VD); |
| 1742 | else |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 1743 | CD = buildCaptureDecl(S, D->getIdentifier(), CaptureExpr, WithInit); |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1744 | return buildDeclRefExpr(S, CD, CD->getType().getNonReferenceType(), |
| 1745 | SourceLocation()); |
| 1746 | } |
| 1747 | |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 1748 | static DeclRefExpr *buildCapture(Sema &S, Expr *CaptureExpr) { |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 1749 | auto *CD = |
| 1750 | buildCaptureDecl(S, &S.getASTContext().Idents.get(".capture_expr."), |
| 1751 | CaptureExpr, /*WithInit=*/true); |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1752 | return buildDeclRefExpr(S, CD, CD->getType().getNonReferenceType(), |
| 1753 | SourceLocation()); |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 1754 | } |
| 1755 | |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1756 | StmtResult Sema::ActOnOpenMPRegionEnd(StmtResult S, |
| 1757 | ArrayRef<OMPClause *> Clauses) { |
| 1758 | if (!S.isUsable()) { |
| 1759 | ActOnCapturedRegionError(); |
| 1760 | return StmtError(); |
| 1761 | } |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1762 | |
| 1763 | OMPOrderedClause *OC = nullptr; |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1764 | OMPScheduleClause *SC = nullptr; |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1765 | SmallVector<OMPLinearClause *, 4> LCs; |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1766 | // This is required for proper codegen. |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1767 | for (auto *Clause : Clauses) { |
Alexey Bataev | 16dc7b6 | 2015-05-20 03:46:04 +0000 | [diff] [blame] | 1768 | if (isOpenMPPrivate(Clause->getClauseKind()) || |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 1769 | Clause->getClauseKind() == OMPC_copyprivate || |
| 1770 | (getLangOpts().OpenMPUseTLS && |
| 1771 | getASTContext().getTargetInfo().isTLSSupported() && |
| 1772 | Clause->getClauseKind() == OMPC_copyin)) { |
| 1773 | DSAStack->setForceVarCapturing(Clause->getClauseKind() == OMPC_copyin); |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1774 | // Mark all variables in private list clauses as used in inner region. |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1775 | for (auto *VarRef : Clause->children()) { |
| 1776 | if (auto *E = cast_or_null<Expr>(VarRef)) { |
Alexey Bataev | 8bf6b3e | 2015-04-02 13:07:08 +0000 | [diff] [blame] | 1777 | MarkDeclarationsReferencedInExpr(E); |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1778 | } |
| 1779 | } |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 1780 | DSAStack->setForceVarCapturing(/*V=*/false); |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1781 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective())) { |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1782 | // Mark all variables in private list clauses as used in inner region. |
| 1783 | // Required for proper codegen of combined directives. |
| 1784 | // TODO: add processing for other clauses. |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1785 | if (auto *C = OMPClauseWithPreInit::get(Clause)) { |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 1786 | if (auto *DS = cast_or_null<DeclStmt>(C->getPreInitStmt())) { |
| 1787 | for (auto *D : DS->decls()) |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1788 | MarkVariableReferenced(D->getLocation(), cast<VarDecl>(D)); |
| 1789 | } |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 1790 | } |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 1791 | if (auto *C = OMPClauseWithPostUpdate::get(Clause)) { |
| 1792 | if (auto *E = C->getPostUpdateExpr()) |
| 1793 | MarkDeclarationsReferencedInExpr(E); |
| 1794 | } |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1795 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1796 | if (Clause->getClauseKind() == OMPC_schedule) |
| 1797 | SC = cast<OMPScheduleClause>(Clause); |
| 1798 | else if (Clause->getClauseKind() == OMPC_ordered) |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1799 | OC = cast<OMPOrderedClause>(Clause); |
| 1800 | else if (Clause->getClauseKind() == OMPC_linear) |
| 1801 | LCs.push_back(cast<OMPLinearClause>(Clause)); |
| 1802 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1803 | bool ErrorFound = false; |
| 1804 | // OpenMP, 2.7.1 Loop Construct, Restrictions |
| 1805 | // The nonmonotonic modifier cannot be specified if an ordered clause is |
| 1806 | // specified. |
| 1807 | if (SC && |
| 1808 | (SC->getFirstScheduleModifier() == OMPC_SCHEDULE_MODIFIER_nonmonotonic || |
| 1809 | SC->getSecondScheduleModifier() == |
| 1810 | OMPC_SCHEDULE_MODIFIER_nonmonotonic) && |
| 1811 | OC) { |
| 1812 | Diag(SC->getFirstScheduleModifier() == OMPC_SCHEDULE_MODIFIER_nonmonotonic |
| 1813 | ? SC->getFirstScheduleModifierLoc() |
| 1814 | : SC->getSecondScheduleModifierLoc(), |
| 1815 | diag::err_omp_schedule_nonmonotonic_ordered) |
| 1816 | << SourceRange(OC->getLocStart(), OC->getLocEnd()); |
| 1817 | ErrorFound = true; |
| 1818 | } |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1819 | if (!LCs.empty() && OC && OC->getNumForLoops()) { |
| 1820 | for (auto *C : LCs) { |
| 1821 | Diag(C->getLocStart(), diag::err_omp_linear_ordered) |
| 1822 | << SourceRange(OC->getLocStart(), OC->getLocEnd()); |
| 1823 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1824 | ErrorFound = true; |
| 1825 | } |
Alexey Bataev | 113438c | 2015-12-30 12:06:23 +0000 | [diff] [blame] | 1826 | if (isOpenMPWorksharingDirective(DSAStack->getCurrentDirective()) && |
| 1827 | isOpenMPSimdDirective(DSAStack->getCurrentDirective()) && OC && |
| 1828 | OC->getNumForLoops()) { |
| 1829 | Diag(OC->getLocStart(), diag::err_omp_ordered_simd) |
| 1830 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 1831 | ErrorFound = true; |
| 1832 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1833 | if (ErrorFound) { |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1834 | ActOnCapturedRegionError(); |
| 1835 | return StmtError(); |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1836 | } |
| 1837 | return ActOnCapturedRegionEnd(S.get()); |
| 1838 | } |
| 1839 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1840 | static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, |
| 1841 | OpenMPDirectiveKind CurrentRegion, |
| 1842 | const DeclarationNameInfo &CurrentName, |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1843 | OpenMPDirectiveKind CancelRegion, |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1844 | SourceLocation StartLoc) { |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1845 | // Allowed nesting of constructs |
| 1846 | // +------------------+-----------------+------------------------------------+ |
| 1847 | // | Parent directive | Child directive | Closely (!), No-Closely(+), Both(*)| |
| 1848 | // +------------------+-----------------+------------------------------------+ |
| 1849 | // | parallel | parallel | * | |
| 1850 | // | parallel | for | * | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1851 | // | parallel | for simd | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1852 | // | parallel | master | * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1853 | // | parallel | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1854 | // | parallel | simd | * | |
| 1855 | // | parallel | sections | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1856 | // | parallel | section | + | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1857 | // | parallel | single | * | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1858 | // | parallel | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1859 | // | parallel |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1860 | // | parallel |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1861 | // | parallel | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1862 | // | parallel | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1863 | // | parallel | barrier | * | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1864 | // | parallel | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1865 | // | parallel | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1866 | // | parallel | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1867 | // | parallel | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1868 | // | parallel | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1869 | // | parallel | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 1870 | // | parallel | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 1871 | // | parallel | target parallel | * | |
| 1872 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1873 | // | parallel | target enter | * | |
| 1874 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1875 | // | parallel | target exit | * | |
| 1876 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1877 | // | parallel | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1878 | // | parallel | cancellation | | |
| 1879 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1880 | // | parallel | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1881 | // | parallel | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1882 | // | parallel | taskloop simd | * | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1883 | // | parallel | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1884 | // +------------------+-----------------+------------------------------------+ |
| 1885 | // | for | parallel | * | |
| 1886 | // | for | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1887 | // | for | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1888 | // | for | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1889 | // | for | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1890 | // | for | simd | * | |
| 1891 | // | for | sections | + | |
| 1892 | // | for | section | + | |
| 1893 | // | for | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1894 | // | for | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1895 | // | for |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1896 | // | for |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1897 | // | for | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1898 | // | for | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1899 | // | for | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1900 | // | for | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1901 | // | for | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1902 | // | for | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1903 | // | for | ordered | * (if construct is ordered) | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1904 | // | for | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1905 | // | for | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 1906 | // | for | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 1907 | // | for | target parallel | * | |
| 1908 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1909 | // | for | target enter | * | |
| 1910 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1911 | // | for | target exit | * | |
| 1912 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1913 | // | for | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1914 | // | for | cancellation | | |
| 1915 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1916 | // | for | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1917 | // | for | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1918 | // | for | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1919 | // | for | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1920 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1921 | // | master | parallel | * | |
| 1922 | // | master | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1923 | // | master | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1924 | // | master | master | * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1925 | // | master | critical | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1926 | // | master | simd | * | |
| 1927 | // | master | sections | + | |
| 1928 | // | master | section | + | |
| 1929 | // | master | single | + | |
| 1930 | // | master | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1931 | // | master |parallel for simd| * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1932 | // | master |parallel sections| * | |
| 1933 | // | master | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1934 | // | master | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1935 | // | master | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1936 | // | master | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1937 | // | master | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1938 | // | master | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1939 | // | master | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1940 | // | master | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1941 | // | master | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 1942 | // | master | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 1943 | // | master | target parallel | * | |
| 1944 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1945 | // | master | target enter | * | |
| 1946 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1947 | // | master | target exit | * | |
| 1948 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1949 | // | master | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1950 | // | master | cancellation | | |
| 1951 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1952 | // | master | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1953 | // | master | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1954 | // | master | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1955 | // | master | distribute | | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1956 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1957 | // | critical | parallel | * | |
| 1958 | // | critical | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1959 | // | critical | for simd | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1960 | // | critical | master | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1961 | // | critical | critical | * (should have different names) | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1962 | // | critical | simd | * | |
| 1963 | // | critical | sections | + | |
| 1964 | // | critical | section | + | |
| 1965 | // | critical | single | + | |
| 1966 | // | critical | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1967 | // | critical |parallel for simd| * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1968 | // | critical |parallel sections| * | |
| 1969 | // | critical | task | * | |
| 1970 | // | critical | taskyield | * | |
| 1971 | // | critical | barrier | + | |
| 1972 | // | critical | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1973 | // | critical | taskgroup | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1974 | // | critical | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1975 | // | critical | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1976 | // | critical | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 1977 | // | critical | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 1978 | // | critical | target parallel | * | |
| 1979 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1980 | // | critical | target enter | * | |
| 1981 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1982 | // | critical | target exit | * | |
| 1983 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1984 | // | critical | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1985 | // | critical | cancellation | | |
| 1986 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1987 | // | critical | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1988 | // | critical | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1989 | // | critical | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1990 | // | critical | distribute | | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1991 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1992 | // | simd | parallel | | |
| 1993 | // | simd | for | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1994 | // | simd | for simd | | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1995 | // | simd | master | | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1996 | // | simd | critical | | |
Alexey Bataev | 1f09221 | 2016-02-02 04:59:52 +0000 | [diff] [blame] | 1997 | // | simd | simd | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1998 | // | simd | sections | | |
| 1999 | // | simd | section | | |
| 2000 | // | simd | single | | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2001 | // | simd | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2002 | // | simd |parallel for simd| | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2003 | // | simd |parallel sections| | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2004 | // | simd | task | | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2005 | // | simd | taskyield | | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2006 | // | simd | barrier | | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2007 | // | simd | taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2008 | // | simd | taskgroup | | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2009 | // | simd | flush | | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2010 | // | simd | ordered | + (with simd clause) | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2011 | // | simd | atomic | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2012 | // | simd | target | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2013 | // | simd | target parallel | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2014 | // | simd | target parallel | | |
| 2015 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2016 | // | simd | target enter | | |
| 2017 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2018 | // | simd | target exit | | |
| 2019 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2020 | // | simd | teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2021 | // | simd | cancellation | | |
| 2022 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2023 | // | simd | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2024 | // | simd | taskloop | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2025 | // | simd | taskloop simd | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2026 | // | simd | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2027 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2028 | // | for simd | parallel | | |
| 2029 | // | for simd | for | | |
| 2030 | // | for simd | for simd | | |
| 2031 | // | for simd | master | | |
| 2032 | // | for simd | critical | | |
Alexey Bataev | 1f09221 | 2016-02-02 04:59:52 +0000 | [diff] [blame] | 2033 | // | for simd | simd | * | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2034 | // | for simd | sections | | |
| 2035 | // | for simd | section | | |
| 2036 | // | for simd | single | | |
| 2037 | // | for simd | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2038 | // | for simd |parallel for simd| | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2039 | // | for simd |parallel sections| | |
| 2040 | // | for simd | task | | |
| 2041 | // | for simd | taskyield | | |
| 2042 | // | for simd | barrier | | |
| 2043 | // | for simd | taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2044 | // | for simd | taskgroup | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2045 | // | for simd | flush | | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2046 | // | for simd | ordered | + (with simd clause) | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2047 | // | for simd | atomic | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2048 | // | for simd | target | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2049 | // | for simd | target parallel | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2050 | // | for simd | target parallel | | |
| 2051 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2052 | // | for simd | target enter | | |
| 2053 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2054 | // | for simd | target exit | | |
| 2055 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2056 | // | for simd | teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2057 | // | for simd | cancellation | | |
| 2058 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2059 | // | for simd | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2060 | // | for simd | taskloop | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2061 | // | for simd | taskloop simd | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2062 | // | for simd | distribute | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2063 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2064 | // | parallel for simd| parallel | | |
| 2065 | // | parallel for simd| for | | |
| 2066 | // | parallel for simd| for simd | | |
| 2067 | // | parallel for simd| master | | |
| 2068 | // | parallel for simd| critical | | |
Alexey Bataev | 1f09221 | 2016-02-02 04:59:52 +0000 | [diff] [blame] | 2069 | // | parallel for simd| simd | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2070 | // | parallel for simd| sections | | |
| 2071 | // | parallel for simd| section | | |
| 2072 | // | parallel for simd| single | | |
| 2073 | // | parallel for simd| parallel for | | |
| 2074 | // | parallel for simd|parallel for simd| | |
| 2075 | // | parallel for simd|parallel sections| | |
| 2076 | // | parallel for simd| task | | |
| 2077 | // | parallel for simd| taskyield | | |
| 2078 | // | parallel for simd| barrier | | |
| 2079 | // | parallel for simd| taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2080 | // | parallel for simd| taskgroup | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2081 | // | parallel for simd| flush | | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2082 | // | parallel for simd| ordered | + (with simd clause) | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2083 | // | parallel for simd| atomic | | |
| 2084 | // | parallel for simd| target | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2085 | // | parallel for simd| target parallel | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2086 | // | parallel for simd| target parallel | | |
| 2087 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2088 | // | parallel for simd| target enter | | |
| 2089 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2090 | // | parallel for simd| target exit | | |
| 2091 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2092 | // | parallel for simd| teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2093 | // | parallel for simd| cancellation | | |
| 2094 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2095 | // | parallel for simd| cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2096 | // | parallel for simd| taskloop | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2097 | // | parallel for simd| taskloop simd | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2098 | // | parallel for simd| distribute | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2099 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2100 | // | sections | parallel | * | |
| 2101 | // | sections | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2102 | // | sections | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2103 | // | sections | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2104 | // | sections | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2105 | // | sections | simd | * | |
| 2106 | // | sections | sections | + | |
| 2107 | // | sections | section | * | |
| 2108 | // | sections | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2109 | // | sections | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2110 | // | sections |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2111 | // | sections |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2112 | // | sections | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2113 | // | sections | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2114 | // | sections | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2115 | // | sections | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2116 | // | sections | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2117 | // | sections | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2118 | // | sections | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2119 | // | sections | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2120 | // | sections | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2121 | // | sections | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2122 | // | sections | target parallel | * | |
| 2123 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2124 | // | sections | target enter | * | |
| 2125 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2126 | // | sections | target exit | * | |
| 2127 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2128 | // | sections | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2129 | // | sections | cancellation | | |
| 2130 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2131 | // | sections | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2132 | // | sections | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2133 | // | sections | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2134 | // | sections | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2135 | // +------------------+-----------------+------------------------------------+ |
| 2136 | // | section | parallel | * | |
| 2137 | // | section | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2138 | // | section | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2139 | // | section | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2140 | // | section | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2141 | // | section | simd | * | |
| 2142 | // | section | sections | + | |
| 2143 | // | section | section | + | |
| 2144 | // | section | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2145 | // | section | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2146 | // | section |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2147 | // | section |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2148 | // | section | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2149 | // | section | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2150 | // | section | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2151 | // | section | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2152 | // | section | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2153 | // | section | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2154 | // | section | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2155 | // | section | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2156 | // | section | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2157 | // | section | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2158 | // | section | target parallel | * | |
| 2159 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2160 | // | section | target enter | * | |
| 2161 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2162 | // | section | target exit | * | |
| 2163 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2164 | // | section | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2165 | // | section | cancellation | | |
| 2166 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2167 | // | section | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2168 | // | section | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2169 | // | section | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2170 | // | section | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2171 | // +------------------+-----------------+------------------------------------+ |
| 2172 | // | single | parallel | * | |
| 2173 | // | single | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2174 | // | single | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2175 | // | single | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2176 | // | single | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2177 | // | single | simd | * | |
| 2178 | // | single | sections | + | |
| 2179 | // | single | section | + | |
| 2180 | // | single | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2181 | // | single | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2182 | // | single |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2183 | // | single |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2184 | // | single | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2185 | // | single | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2186 | // | single | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2187 | // | single | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2188 | // | single | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2189 | // | single | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2190 | // | single | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2191 | // | single | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2192 | // | single | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2193 | // | single | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2194 | // | single | target parallel | * | |
| 2195 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2196 | // | single | target enter | * | |
| 2197 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2198 | // | single | target exit | * | |
| 2199 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2200 | // | single | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2201 | // | single | cancellation | | |
| 2202 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2203 | // | single | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2204 | // | single | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2205 | // | single | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2206 | // | single | distribute | | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2207 | // +------------------+-----------------+------------------------------------+ |
| 2208 | // | parallel for | parallel | * | |
| 2209 | // | parallel for | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2210 | // | parallel for | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2211 | // | parallel for | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2212 | // | parallel for | critical | * | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2213 | // | parallel for | simd | * | |
| 2214 | // | parallel for | sections | + | |
| 2215 | // | parallel for | section | + | |
| 2216 | // | parallel for | single | + | |
| 2217 | // | parallel for | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2218 | // | parallel for |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2219 | // | parallel for |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2220 | // | parallel for | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2221 | // | parallel for | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2222 | // | parallel for | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2223 | // | parallel for | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2224 | // | parallel for | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2225 | // | parallel for | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2226 | // | parallel for | ordered | * (if construct is ordered) | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2227 | // | parallel for | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2228 | // | parallel for | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2229 | // | parallel for | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2230 | // | parallel for | target parallel | * | |
| 2231 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2232 | // | parallel for | target enter | * | |
| 2233 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2234 | // | parallel for | target exit | * | |
| 2235 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2236 | // | parallel for | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2237 | // | parallel for | cancellation | | |
| 2238 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2239 | // | parallel for | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2240 | // | parallel for | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2241 | // | parallel for | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2242 | // | parallel for | distribute | | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2243 | // +------------------+-----------------+------------------------------------+ |
| 2244 | // | parallel sections| parallel | * | |
| 2245 | // | parallel sections| for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2246 | // | parallel sections| for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2247 | // | parallel sections| master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2248 | // | parallel sections| critical | + | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2249 | // | parallel sections| simd | * | |
| 2250 | // | parallel sections| sections | + | |
| 2251 | // | parallel sections| section | * | |
| 2252 | // | parallel sections| single | + | |
| 2253 | // | parallel sections| parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2254 | // | parallel sections|parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2255 | // | parallel sections|parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2256 | // | parallel sections| task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2257 | // | parallel sections| taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2258 | // | parallel sections| barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2259 | // | parallel sections| taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2260 | // | parallel sections| taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2261 | // | parallel sections| flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2262 | // | parallel sections| ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2263 | // | parallel sections| atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2264 | // | parallel sections| target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2265 | // | parallel sections| target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2266 | // | parallel sections| target parallel | * | |
| 2267 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2268 | // | parallel sections| target enter | * | |
| 2269 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2270 | // | parallel sections| target exit | * | |
| 2271 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2272 | // | parallel sections| teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2273 | // | parallel sections| cancellation | | |
| 2274 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2275 | // | parallel sections| cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2276 | // | parallel sections| taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2277 | // | parallel sections| taskloop simd | * | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2278 | // | parallel sections| distribute | | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2279 | // +------------------+-----------------+------------------------------------+ |
| 2280 | // | task | parallel | * | |
| 2281 | // | task | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2282 | // | task | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2283 | // | task | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2284 | // | task | critical | * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2285 | // | task | simd | * | |
| 2286 | // | task | sections | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2287 | // | task | section | + | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2288 | // | task | single | + | |
| 2289 | // | task | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2290 | // | task |parallel for simd| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2291 | // | task |parallel sections| * | |
| 2292 | // | task | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2293 | // | task | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2294 | // | task | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2295 | // | task | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2296 | // | task | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2297 | // | task | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2298 | // | task | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2299 | // | task | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2300 | // | task | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2301 | // | task | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2302 | // | task | target parallel | * | |
| 2303 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2304 | // | task | target enter | * | |
| 2305 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2306 | // | task | target exit | * | |
| 2307 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2308 | // | task | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2309 | // | task | cancellation | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2310 | // | | point | ! | |
| 2311 | // | task | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2312 | // | task | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2313 | // | task | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2314 | // | task | distribute | | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2315 | // +------------------+-----------------+------------------------------------+ |
| 2316 | // | ordered | parallel | * | |
| 2317 | // | ordered | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2318 | // | ordered | for simd | + | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2319 | // | ordered | master | * | |
| 2320 | // | ordered | critical | * | |
| 2321 | // | ordered | simd | * | |
| 2322 | // | ordered | sections | + | |
| 2323 | // | ordered | section | + | |
| 2324 | // | ordered | single | + | |
| 2325 | // | ordered | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2326 | // | ordered |parallel for simd| * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2327 | // | ordered |parallel sections| * | |
| 2328 | // | ordered | task | * | |
| 2329 | // | ordered | taskyield | * | |
| 2330 | // | ordered | barrier | + | |
| 2331 | // | ordered | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2332 | // | ordered | taskgroup | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2333 | // | ordered | flush | * | |
| 2334 | // | ordered | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2335 | // | ordered | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2336 | // | ordered | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2337 | // | ordered | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2338 | // | ordered | target parallel | * | |
| 2339 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2340 | // | ordered | target enter | * | |
| 2341 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2342 | // | ordered | target exit | * | |
| 2343 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2344 | // | ordered | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2345 | // | ordered | cancellation | | |
| 2346 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2347 | // | ordered | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2348 | // | ordered | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2349 | // | ordered | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2350 | // | ordered | distribute | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2351 | // +------------------+-----------------+------------------------------------+ |
| 2352 | // | atomic | parallel | | |
| 2353 | // | atomic | for | | |
| 2354 | // | atomic | for simd | | |
| 2355 | // | atomic | master | | |
| 2356 | // | atomic | critical | | |
| 2357 | // | atomic | simd | | |
| 2358 | // | atomic | sections | | |
| 2359 | // | atomic | section | | |
| 2360 | // | atomic | single | | |
| 2361 | // | atomic | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2362 | // | atomic |parallel for simd| | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2363 | // | atomic |parallel sections| | |
| 2364 | // | atomic | task | | |
| 2365 | // | atomic | taskyield | | |
| 2366 | // | atomic | barrier | | |
| 2367 | // | atomic | taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2368 | // | atomic | taskgroup | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2369 | // | atomic | flush | | |
| 2370 | // | atomic | ordered | | |
| 2371 | // | atomic | atomic | | |
| 2372 | // | atomic | target | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2373 | // | atomic | target parallel | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2374 | // | atomic | target parallel | | |
| 2375 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2376 | // | atomic | target enter | | |
| 2377 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2378 | // | atomic | target exit | | |
| 2379 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2380 | // | atomic | teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2381 | // | atomic | cancellation | | |
| 2382 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2383 | // | atomic | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2384 | // | atomic | taskloop | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2385 | // | atomic | taskloop simd | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2386 | // | atomic | distribute | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2387 | // +------------------+-----------------+------------------------------------+ |
| 2388 | // | target | parallel | * | |
| 2389 | // | target | for | * | |
| 2390 | // | target | for simd | * | |
| 2391 | // | target | master | * | |
| 2392 | // | target | critical | * | |
| 2393 | // | target | simd | * | |
| 2394 | // | target | sections | * | |
| 2395 | // | target | section | * | |
| 2396 | // | target | single | * | |
| 2397 | // | target | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2398 | // | target |parallel for simd| * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2399 | // | target |parallel sections| * | |
| 2400 | // | target | task | * | |
| 2401 | // | target | taskyield | * | |
| 2402 | // | target | barrier | * | |
| 2403 | // | target | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2404 | // | target | taskgroup | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2405 | // | target | flush | * | |
| 2406 | // | target | ordered | * | |
| 2407 | // | target | atomic | * | |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2408 | // | target | target | | |
| 2409 | // | target | target parallel | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2410 | // | target | target parallel | | |
| 2411 | // | | for | | |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2412 | // | target | target enter | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2413 | // | | data | | |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2414 | // | target | target exit | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2415 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2416 | // | target | teams | * | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2417 | // | target | cancellation | | |
| 2418 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2419 | // | target | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2420 | // | target | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2421 | // | target | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2422 | // | target | distribute | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2423 | // +------------------+-----------------+------------------------------------+ |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2424 | // | target parallel | parallel | * | |
| 2425 | // | target parallel | for | * | |
| 2426 | // | target parallel | for simd | * | |
| 2427 | // | target parallel | master | * | |
| 2428 | // | target parallel | critical | * | |
| 2429 | // | target parallel | simd | * | |
| 2430 | // | target parallel | sections | * | |
| 2431 | // | target parallel | section | * | |
| 2432 | // | target parallel | single | * | |
| 2433 | // | target parallel | parallel for | * | |
| 2434 | // | target parallel |parallel for simd| * | |
| 2435 | // | target parallel |parallel sections| * | |
| 2436 | // | target parallel | task | * | |
| 2437 | // | target parallel | taskyield | * | |
| 2438 | // | target parallel | barrier | * | |
| 2439 | // | target parallel | taskwait | * | |
| 2440 | // | target parallel | taskgroup | * | |
| 2441 | // | target parallel | flush | * | |
| 2442 | // | target parallel | ordered | * | |
| 2443 | // | target parallel | atomic | * | |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2444 | // | target parallel | target | | |
| 2445 | // | target parallel | target parallel | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2446 | // | target parallel | target parallel | | |
| 2447 | // | | for | | |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2448 | // | target parallel | target enter | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2449 | // | | data | | |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2450 | // | target parallel | target exit | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2451 | // | | data | | |
| 2452 | // | target parallel | teams | | |
| 2453 | // | target parallel | cancellation | | |
| 2454 | // | | point | ! | |
| 2455 | // | target parallel | cancel | ! | |
| 2456 | // | target parallel | taskloop | * | |
| 2457 | // | target parallel | taskloop simd | * | |
| 2458 | // | target parallel | distribute | | |
| 2459 | // +------------------+-----------------+------------------------------------+ |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2460 | // | target parallel | parallel | * | |
| 2461 | // | for | | | |
| 2462 | // | target parallel | for | * | |
| 2463 | // | for | | | |
| 2464 | // | target parallel | for simd | * | |
| 2465 | // | for | | | |
| 2466 | // | target parallel | master | * | |
| 2467 | // | for | | | |
| 2468 | // | target parallel | critical | * | |
| 2469 | // | for | | | |
| 2470 | // | target parallel | simd | * | |
| 2471 | // | for | | | |
| 2472 | // | target parallel | sections | * | |
| 2473 | // | for | | | |
| 2474 | // | target parallel | section | * | |
| 2475 | // | for | | | |
| 2476 | // | target parallel | single | * | |
| 2477 | // | for | | | |
| 2478 | // | target parallel | parallel for | * | |
| 2479 | // | for | | | |
| 2480 | // | target parallel |parallel for simd| * | |
| 2481 | // | for | | | |
| 2482 | // | target parallel |parallel sections| * | |
| 2483 | // | for | | | |
| 2484 | // | target parallel | task | * | |
| 2485 | // | for | | | |
| 2486 | // | target parallel | taskyield | * | |
| 2487 | // | for | | | |
| 2488 | // | target parallel | barrier | * | |
| 2489 | // | for | | | |
| 2490 | // | target parallel | taskwait | * | |
| 2491 | // | for | | | |
| 2492 | // | target parallel | taskgroup | * | |
| 2493 | // | for | | | |
| 2494 | // | target parallel | flush | * | |
| 2495 | // | for | | | |
| 2496 | // | target parallel | ordered | * | |
| 2497 | // | for | | | |
| 2498 | // | target parallel | atomic | * | |
| 2499 | // | for | | | |
| 2500 | // | target parallel | target | | |
| 2501 | // | for | | | |
| 2502 | // | target parallel | target parallel | | |
| 2503 | // | for | | | |
| 2504 | // | target parallel | target parallel | | |
| 2505 | // | for | for | | |
| 2506 | // | target parallel | target enter | | |
| 2507 | // | for | data | | |
| 2508 | // | target parallel | target exit | | |
| 2509 | // | for | data | | |
| 2510 | // | target parallel | teams | | |
| 2511 | // | for | | | |
| 2512 | // | target parallel | cancellation | | |
| 2513 | // | for | point | ! | |
| 2514 | // | target parallel | cancel | ! | |
| 2515 | // | for | | | |
| 2516 | // | target parallel | taskloop | * | |
| 2517 | // | for | | | |
| 2518 | // | target parallel | taskloop simd | * | |
| 2519 | // | for | | | |
| 2520 | // | target parallel | distribute | | |
| 2521 | // | for | | | |
| 2522 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2523 | // | teams | parallel | * | |
| 2524 | // | teams | for | + | |
| 2525 | // | teams | for simd | + | |
| 2526 | // | teams | master | + | |
| 2527 | // | teams | critical | + | |
| 2528 | // | teams | simd | + | |
| 2529 | // | teams | sections | + | |
| 2530 | // | teams | section | + | |
| 2531 | // | teams | single | + | |
| 2532 | // | teams | parallel for | * | |
| 2533 | // | teams |parallel for simd| * | |
| 2534 | // | teams |parallel sections| * | |
| 2535 | // | teams | task | + | |
| 2536 | // | teams | taskyield | + | |
| 2537 | // | teams | barrier | + | |
| 2538 | // | teams | taskwait | + | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2539 | // | teams | taskgroup | + | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2540 | // | teams | flush | + | |
| 2541 | // | teams | ordered | + | |
| 2542 | // | teams | atomic | + | |
| 2543 | // | teams | target | + | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2544 | // | teams | target parallel | + | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2545 | // | teams | target parallel | + | |
| 2546 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2547 | // | teams | target enter | + | |
| 2548 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2549 | // | teams | target exit | + | |
| 2550 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2551 | // | teams | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2552 | // | teams | cancellation | | |
| 2553 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2554 | // | teams | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2555 | // | teams | taskloop | + | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2556 | // | teams | taskloop simd | + | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2557 | // | teams | distribute | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2558 | // +------------------+-----------------+------------------------------------+ |
| 2559 | // | taskloop | parallel | * | |
| 2560 | // | taskloop | for | + | |
| 2561 | // | taskloop | for simd | + | |
| 2562 | // | taskloop | master | + | |
| 2563 | // | taskloop | critical | * | |
| 2564 | // | taskloop | simd | * | |
| 2565 | // | taskloop | sections | + | |
| 2566 | // | taskloop | section | + | |
| 2567 | // | taskloop | single | + | |
| 2568 | // | taskloop | parallel for | * | |
| 2569 | // | taskloop |parallel for simd| * | |
| 2570 | // | taskloop |parallel sections| * | |
| 2571 | // | taskloop | task | * | |
| 2572 | // | taskloop | taskyield | * | |
| 2573 | // | taskloop | barrier | + | |
| 2574 | // | taskloop | taskwait | * | |
| 2575 | // | taskloop | taskgroup | * | |
| 2576 | // | taskloop | flush | * | |
| 2577 | // | taskloop | ordered | + | |
| 2578 | // | taskloop | atomic | * | |
| 2579 | // | taskloop | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2580 | // | taskloop | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2581 | // | taskloop | target parallel | * | |
| 2582 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2583 | // | taskloop | target enter | * | |
| 2584 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2585 | // | taskloop | target exit | * | |
| 2586 | // | | data | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2587 | // | taskloop | teams | + | |
| 2588 | // | taskloop | cancellation | | |
| 2589 | // | | point | | |
| 2590 | // | taskloop | cancel | | |
| 2591 | // | taskloop | taskloop | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2592 | // | taskloop | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2593 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2594 | // | taskloop simd | parallel | | |
| 2595 | // | taskloop simd | for | | |
| 2596 | // | taskloop simd | for simd | | |
| 2597 | // | taskloop simd | master | | |
| 2598 | // | taskloop simd | critical | | |
Alexey Bataev | 1f09221 | 2016-02-02 04:59:52 +0000 | [diff] [blame] | 2599 | // | taskloop simd | simd | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2600 | // | taskloop simd | sections | | |
| 2601 | // | taskloop simd | section | | |
| 2602 | // | taskloop simd | single | | |
| 2603 | // | taskloop simd | parallel for | | |
| 2604 | // | taskloop simd |parallel for simd| | |
| 2605 | // | taskloop simd |parallel sections| | |
| 2606 | // | taskloop simd | task | | |
| 2607 | // | taskloop simd | taskyield | | |
| 2608 | // | taskloop simd | barrier | | |
| 2609 | // | taskloop simd | taskwait | | |
| 2610 | // | taskloop simd | taskgroup | | |
| 2611 | // | taskloop simd | flush | | |
| 2612 | // | taskloop simd | ordered | + (with simd clause) | |
| 2613 | // | taskloop simd | atomic | | |
| 2614 | // | taskloop simd | target | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2615 | // | taskloop simd | target parallel | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2616 | // | taskloop simd | target parallel | | |
| 2617 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2618 | // | taskloop simd | target enter | | |
| 2619 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2620 | // | taskloop simd | target exit | | |
| 2621 | // | | data | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2622 | // | taskloop simd | teams | | |
| 2623 | // | taskloop simd | cancellation | | |
| 2624 | // | | point | | |
| 2625 | // | taskloop simd | cancel | | |
| 2626 | // | taskloop simd | taskloop | | |
| 2627 | // | taskloop simd | taskloop simd | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2628 | // | taskloop simd | distribute | | |
| 2629 | // +------------------+-----------------+------------------------------------+ |
| 2630 | // | distribute | parallel | * | |
| 2631 | // | distribute | for | * | |
| 2632 | // | distribute | for simd | * | |
| 2633 | // | distribute | master | * | |
| 2634 | // | distribute | critical | * | |
| 2635 | // | distribute | simd | * | |
| 2636 | // | distribute | sections | * | |
| 2637 | // | distribute | section | * | |
| 2638 | // | distribute | single | * | |
| 2639 | // | distribute | parallel for | * | |
| 2640 | // | distribute |parallel for simd| * | |
| 2641 | // | distribute |parallel sections| * | |
| 2642 | // | distribute | task | * | |
| 2643 | // | distribute | taskyield | * | |
| 2644 | // | distribute | barrier | * | |
| 2645 | // | distribute | taskwait | * | |
| 2646 | // | distribute | taskgroup | * | |
| 2647 | // | distribute | flush | * | |
| 2648 | // | distribute | ordered | + | |
| 2649 | // | distribute | atomic | * | |
| 2650 | // | distribute | target | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2651 | // | distribute | target parallel | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2652 | // | distribute | target parallel | | |
| 2653 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2654 | // | distribute | target enter | | |
| 2655 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2656 | // | distribute | target exit | | |
| 2657 | // | | data | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2658 | // | distribute | teams | | |
| 2659 | // | distribute | cancellation | + | |
| 2660 | // | | point | | |
| 2661 | // | distribute | cancel | + | |
| 2662 | // | distribute | taskloop | * | |
| 2663 | // | distribute | taskloop simd | * | |
| 2664 | // | distribute | distribute | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2665 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2666 | if (Stack->getCurScope()) { |
| 2667 | auto ParentRegion = Stack->getParentDirective(); |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2668 | auto OffendingRegion = ParentRegion; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2669 | bool NestingProhibited = false; |
| 2670 | bool CloseNesting = true; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2671 | enum { |
| 2672 | NoRecommend, |
| 2673 | ShouldBeInParallelRegion, |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2674 | ShouldBeInOrderedRegion, |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2675 | ShouldBeInTargetRegion, |
| 2676 | ShouldBeInTeamsRegion |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2677 | } Recommend = NoRecommend; |
Alexey Bataev | 1f09221 | 2016-02-02 04:59:52 +0000 | [diff] [blame] | 2678 | if (isOpenMPSimdDirective(ParentRegion) && CurrentRegion != OMPD_ordered && |
| 2679 | CurrentRegion != OMPD_simd) { |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2680 | // OpenMP [2.16, Nesting of Regions] |
| 2681 | // OpenMP constructs may not be nested inside a simd region. |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2682 | // OpenMP [2.8.1,simd Construct, Restrictions] |
| 2683 | // An ordered construct with the simd clause is the only OpenMP construct |
| 2684 | // that can appear in the simd region. |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2685 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region_simd); |
| 2686 | return true; |
| 2687 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2688 | if (ParentRegion == OMPD_atomic) { |
| 2689 | // OpenMP [2.16, Nesting of Regions] |
| 2690 | // OpenMP constructs may not be nested inside an atomic region. |
| 2691 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region_atomic); |
| 2692 | return true; |
| 2693 | } |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2694 | if (CurrentRegion == OMPD_section) { |
| 2695 | // OpenMP [2.7.2, sections Construct, Restrictions] |
| 2696 | // Orphaned section directives are prohibited. That is, the section |
| 2697 | // directives must appear within the sections construct and must not be |
| 2698 | // encountered elsewhere in the sections region. |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2699 | if (ParentRegion != OMPD_sections && |
| 2700 | ParentRegion != OMPD_parallel_sections) { |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2701 | SemaRef.Diag(StartLoc, diag::err_omp_orphaned_section_directive) |
| 2702 | << (ParentRegion != OMPD_unknown) |
| 2703 | << getOpenMPDirectiveName(ParentRegion); |
| 2704 | return true; |
| 2705 | } |
| 2706 | return false; |
| 2707 | } |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2708 | // Allow some constructs to be orphaned (they could be used in functions, |
| 2709 | // called from OpenMP regions with the required preconditions). |
| 2710 | if (ParentRegion == OMPD_unknown) |
| 2711 | return false; |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2712 | if (CurrentRegion == OMPD_cancellation_point || |
| 2713 | CurrentRegion == OMPD_cancel) { |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2714 | // OpenMP [2.16, Nesting of Regions] |
| 2715 | // A cancellation point construct for which construct-type-clause is |
| 2716 | // taskgroup must be nested inside a task construct. A cancellation |
| 2717 | // point construct for which construct-type-clause is not taskgroup must |
| 2718 | // be closely nested inside an OpenMP construct that matches the type |
| 2719 | // specified in construct-type-clause. |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2720 | // A cancel construct for which construct-type-clause is taskgroup must be |
| 2721 | // nested inside a task construct. A cancel construct for which |
| 2722 | // construct-type-clause is not taskgroup must be closely nested inside an |
| 2723 | // OpenMP construct that matches the type specified in |
| 2724 | // construct-type-clause. |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2725 | NestingProhibited = |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2726 | !((CancelRegion == OMPD_parallel && |
| 2727 | (ParentRegion == OMPD_parallel || |
| 2728 | ParentRegion == OMPD_target_parallel)) || |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 2729 | (CancelRegion == OMPD_for && |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2730 | (ParentRegion == OMPD_for || ParentRegion == OMPD_parallel_for || |
| 2731 | ParentRegion == OMPD_target_parallel_for)) || |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2732 | (CancelRegion == OMPD_taskgroup && ParentRegion == OMPD_task) || |
| 2733 | (CancelRegion == OMPD_sections && |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 2734 | (ParentRegion == OMPD_section || ParentRegion == OMPD_sections || |
| 2735 | ParentRegion == OMPD_parallel_sections))); |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2736 | } else if (CurrentRegion == OMPD_master) { |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2737 | // OpenMP [2.16, Nesting of Regions] |
| 2738 | // A master region may not be closely nested inside a worksharing, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2739 | // atomic, or explicit task region. |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2740 | NestingProhibited = isOpenMPWorksharingDirective(ParentRegion) || |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2741 | ParentRegion == OMPD_task || |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2742 | isOpenMPTaskLoopDirective(ParentRegion); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2743 | } else if (CurrentRegion == OMPD_critical && CurrentName.getName()) { |
| 2744 | // OpenMP [2.16, Nesting of Regions] |
| 2745 | // A critical region may not be nested (closely or otherwise) inside a |
| 2746 | // critical region with the same name. Note that this restriction is not |
| 2747 | // sufficient to prevent deadlock. |
| 2748 | SourceLocation PreviousCriticalLoc; |
| 2749 | bool DeadLock = |
| 2750 | Stack->hasDirective([CurrentName, &PreviousCriticalLoc]( |
| 2751 | OpenMPDirectiveKind K, |
| 2752 | const DeclarationNameInfo &DNI, |
| 2753 | SourceLocation Loc) |
| 2754 | ->bool { |
| 2755 | if (K == OMPD_critical && |
| 2756 | DNI.getName() == CurrentName.getName()) { |
| 2757 | PreviousCriticalLoc = Loc; |
| 2758 | return true; |
| 2759 | } else |
| 2760 | return false; |
| 2761 | }, |
| 2762 | false /* skip top directive */); |
| 2763 | if (DeadLock) { |
| 2764 | SemaRef.Diag(StartLoc, |
| 2765 | diag::err_omp_prohibited_region_critical_same_name) |
| 2766 | << CurrentName.getName(); |
| 2767 | if (PreviousCriticalLoc.isValid()) |
| 2768 | SemaRef.Diag(PreviousCriticalLoc, |
| 2769 | diag::note_omp_previous_critical_region); |
| 2770 | return true; |
| 2771 | } |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2772 | } else if (CurrentRegion == OMPD_barrier) { |
| 2773 | // OpenMP [2.16, Nesting of Regions] |
| 2774 | // A barrier region may not be closely nested inside a worksharing, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2775 | // explicit task, critical, ordered, atomic, or master region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2776 | NestingProhibited = |
| 2777 | isOpenMPWorksharingDirective(ParentRegion) || |
| 2778 | ParentRegion == OMPD_task || ParentRegion == OMPD_master || |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2779 | ParentRegion == OMPD_critical || ParentRegion == OMPD_ordered || |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2780 | isOpenMPTaskLoopDirective(ParentRegion); |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2781 | } else if (isOpenMPWorksharingDirective(CurrentRegion) && |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2782 | !isOpenMPParallelDirective(CurrentRegion)) { |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2783 | // OpenMP [2.16, Nesting of Regions] |
| 2784 | // A worksharing region may not be closely nested inside a worksharing, |
| 2785 | // explicit task, critical, ordered, atomic, or master region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2786 | NestingProhibited = |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2787 | isOpenMPWorksharingDirective(ParentRegion) || |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2788 | ParentRegion == OMPD_task || ParentRegion == OMPD_master || |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2789 | ParentRegion == OMPD_critical || ParentRegion == OMPD_ordered || |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2790 | isOpenMPTaskLoopDirective(ParentRegion); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2791 | Recommend = ShouldBeInParallelRegion; |
| 2792 | } else if (CurrentRegion == OMPD_ordered) { |
| 2793 | // OpenMP [2.16, Nesting of Regions] |
| 2794 | // An ordered region may not be closely nested inside a critical, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2795 | // atomic, or explicit task region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2796 | // An ordered region must be closely nested inside a loop region (or |
| 2797 | // parallel loop region) with an ordered clause. |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2798 | // OpenMP [2.8.1,simd Construct, Restrictions] |
| 2799 | // An ordered construct with the simd clause is the only OpenMP construct |
| 2800 | // that can appear in the simd region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2801 | NestingProhibited = ParentRegion == OMPD_critical || |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2802 | ParentRegion == OMPD_task || |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2803 | isOpenMPTaskLoopDirective(ParentRegion) || |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2804 | !(isOpenMPSimdDirective(ParentRegion) || |
| 2805 | Stack->isParentOrderedRegion()); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2806 | Recommend = ShouldBeInOrderedRegion; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2807 | } else if (isOpenMPTeamsDirective(CurrentRegion)) { |
| 2808 | // OpenMP [2.16, Nesting of Regions] |
| 2809 | // If specified, a teams construct must be contained within a target |
| 2810 | // construct. |
| 2811 | NestingProhibited = ParentRegion != OMPD_target; |
| 2812 | Recommend = ShouldBeInTargetRegion; |
| 2813 | Stack->setParentTeamsRegionLoc(Stack->getConstructLoc()); |
| 2814 | } |
| 2815 | if (!NestingProhibited && isOpenMPTeamsDirective(ParentRegion)) { |
| 2816 | // OpenMP [2.16, Nesting of Regions] |
| 2817 | // distribute, parallel, parallel sections, parallel workshare, and the |
| 2818 | // parallel loop and parallel loop SIMD constructs are the only OpenMP |
| 2819 | // constructs that can be closely nested in the teams region. |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2820 | NestingProhibited = !isOpenMPParallelDirective(CurrentRegion) && |
| 2821 | !isOpenMPDistributeDirective(CurrentRegion); |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2822 | Recommend = ShouldBeInParallelRegion; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2823 | } |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2824 | if (!NestingProhibited && isOpenMPDistributeDirective(CurrentRegion)) { |
| 2825 | // OpenMP 4.5 [2.17 Nesting of Regions] |
| 2826 | // The region associated with the distribute construct must be strictly |
| 2827 | // nested inside a teams region |
| 2828 | NestingProhibited = !isOpenMPTeamsDirective(ParentRegion); |
| 2829 | Recommend = ShouldBeInTeamsRegion; |
| 2830 | } |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2831 | if (!NestingProhibited && |
| 2832 | (isOpenMPTargetExecutionDirective(CurrentRegion) || |
| 2833 | isOpenMPTargetDataManagementDirective(CurrentRegion))) { |
| 2834 | // OpenMP 4.5 [2.17 Nesting of Regions] |
| 2835 | // If a target, target update, target data, target enter data, or |
| 2836 | // target exit data construct is encountered during execution of a |
| 2837 | // target region, the behavior is unspecified. |
| 2838 | NestingProhibited = Stack->hasDirective( |
| 2839 | [&OffendingRegion](OpenMPDirectiveKind K, |
| 2840 | const DeclarationNameInfo &DNI, |
| 2841 | SourceLocation Loc) -> bool { |
| 2842 | if (isOpenMPTargetExecutionDirective(K)) { |
| 2843 | OffendingRegion = K; |
| 2844 | return true; |
| 2845 | } else |
| 2846 | return false; |
| 2847 | }, |
| 2848 | false /* don't skip top directive */); |
| 2849 | CloseNesting = false; |
| 2850 | } |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2851 | if (NestingProhibited) { |
| 2852 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region) |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2853 | << CloseNesting << getOpenMPDirectiveName(OffendingRegion) |
| 2854 | << Recommend << getOpenMPDirectiveName(CurrentRegion); |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2855 | return true; |
| 2856 | } |
| 2857 | } |
| 2858 | return false; |
| 2859 | } |
| 2860 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2861 | static bool checkIfClauses(Sema &S, OpenMPDirectiveKind Kind, |
| 2862 | ArrayRef<OMPClause *> Clauses, |
| 2863 | ArrayRef<OpenMPDirectiveKind> AllowedNameModifiers) { |
| 2864 | bool ErrorFound = false; |
| 2865 | unsigned NamedModifiersNumber = 0; |
| 2866 | SmallVector<const OMPIfClause *, OMPC_unknown + 1> FoundNameModifiers( |
| 2867 | OMPD_unknown + 1); |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2868 | SmallVector<SourceLocation, 4> NameModifierLoc; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2869 | for (const auto *C : Clauses) { |
| 2870 | if (const auto *IC = dyn_cast_or_null<OMPIfClause>(C)) { |
| 2871 | // At most one if clause without a directive-name-modifier can appear on |
| 2872 | // the directive. |
| 2873 | OpenMPDirectiveKind CurNM = IC->getNameModifier(); |
| 2874 | if (FoundNameModifiers[CurNM]) { |
| 2875 | S.Diag(C->getLocStart(), diag::err_omp_more_one_clause) |
| 2876 | << getOpenMPDirectiveName(Kind) << getOpenMPClauseName(OMPC_if) |
| 2877 | << (CurNM != OMPD_unknown) << getOpenMPDirectiveName(CurNM); |
| 2878 | ErrorFound = true; |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2879 | } else if (CurNM != OMPD_unknown) { |
| 2880 | NameModifierLoc.push_back(IC->getNameModifierLoc()); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2881 | ++NamedModifiersNumber; |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2882 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2883 | FoundNameModifiers[CurNM] = IC; |
| 2884 | if (CurNM == OMPD_unknown) |
| 2885 | continue; |
| 2886 | // Check if the specified name modifier is allowed for the current |
| 2887 | // directive. |
| 2888 | // At most one if clause with the particular directive-name-modifier can |
| 2889 | // appear on the directive. |
| 2890 | bool MatchFound = false; |
| 2891 | for (auto NM : AllowedNameModifiers) { |
| 2892 | if (CurNM == NM) { |
| 2893 | MatchFound = true; |
| 2894 | break; |
| 2895 | } |
| 2896 | } |
| 2897 | if (!MatchFound) { |
| 2898 | S.Diag(IC->getNameModifierLoc(), |
| 2899 | diag::err_omp_wrong_if_directive_name_modifier) |
| 2900 | << getOpenMPDirectiveName(CurNM) << getOpenMPDirectiveName(Kind); |
| 2901 | ErrorFound = true; |
| 2902 | } |
| 2903 | } |
| 2904 | } |
| 2905 | // If any if clause on the directive includes a directive-name-modifier then |
| 2906 | // all if clauses on the directive must include a directive-name-modifier. |
| 2907 | if (FoundNameModifiers[OMPD_unknown] && NamedModifiersNumber > 0) { |
| 2908 | if (NamedModifiersNumber == AllowedNameModifiers.size()) { |
| 2909 | S.Diag(FoundNameModifiers[OMPD_unknown]->getLocStart(), |
| 2910 | diag::err_omp_no_more_if_clause); |
| 2911 | } else { |
| 2912 | std::string Values; |
| 2913 | std::string Sep(", "); |
| 2914 | unsigned AllowedCnt = 0; |
| 2915 | unsigned TotalAllowedNum = |
| 2916 | AllowedNameModifiers.size() - NamedModifiersNumber; |
| 2917 | for (unsigned Cnt = 0, End = AllowedNameModifiers.size(); Cnt < End; |
| 2918 | ++Cnt) { |
| 2919 | OpenMPDirectiveKind NM = AllowedNameModifiers[Cnt]; |
| 2920 | if (!FoundNameModifiers[NM]) { |
| 2921 | Values += "'"; |
| 2922 | Values += getOpenMPDirectiveName(NM); |
| 2923 | Values += "'"; |
| 2924 | if (AllowedCnt + 2 == TotalAllowedNum) |
| 2925 | Values += " or "; |
| 2926 | else if (AllowedCnt + 1 != TotalAllowedNum) |
| 2927 | Values += Sep; |
| 2928 | ++AllowedCnt; |
| 2929 | } |
| 2930 | } |
| 2931 | S.Diag(FoundNameModifiers[OMPD_unknown]->getCondition()->getLocStart(), |
| 2932 | diag::err_omp_unnamed_if_clause) |
| 2933 | << (TotalAllowedNum > 1) << Values; |
| 2934 | } |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2935 | for (auto Loc : NameModifierLoc) { |
| 2936 | S.Diag(Loc, diag::note_omp_previous_named_if_clause); |
| 2937 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2938 | ErrorFound = true; |
| 2939 | } |
| 2940 | return ErrorFound; |
| 2941 | } |
| 2942 | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2943 | StmtResult Sema::ActOnOpenMPExecutableDirective( |
| 2944 | OpenMPDirectiveKind Kind, const DeclarationNameInfo &DirName, |
| 2945 | OpenMPDirectiveKind CancelRegion, ArrayRef<OMPClause *> Clauses, |
| 2946 | Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2947 | StmtResult Res = StmtError(); |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2948 | if (CheckNestingOfRegions(*this, DSAStack, Kind, DirName, CancelRegion, |
| 2949 | StartLoc)) |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2950 | return StmtError(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2951 | |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2952 | llvm::SmallVector<OMPClause *, 8> ClausesWithImplicit; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 2953 | llvm::DenseMap<ValueDecl *, Expr *> VarsWithInheritedDSA; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2954 | bool ErrorFound = false; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2955 | ClausesWithImplicit.append(Clauses.begin(), Clauses.end()); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2956 | if (AStmt) { |
| 2957 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 2958 | |
| 2959 | // Check default data sharing attributes for referenced variables. |
| 2960 | DSAAttrChecker DSAChecker(DSAStack, *this, cast<CapturedStmt>(AStmt)); |
| 2961 | DSAChecker.Visit(cast<CapturedStmt>(AStmt)->getCapturedStmt()); |
| 2962 | if (DSAChecker.isErrorFound()) |
| 2963 | return StmtError(); |
| 2964 | // Generate list of implicitly defined firstprivate variables. |
| 2965 | VarsWithInheritedDSA = DSAChecker.getVarsWithInheritedDSA(); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2966 | |
| 2967 | if (!DSAChecker.getImplicitFirstprivate().empty()) { |
| 2968 | if (OMPClause *Implicit = ActOnOpenMPFirstprivateClause( |
| 2969 | DSAChecker.getImplicitFirstprivate(), SourceLocation(), |
| 2970 | SourceLocation(), SourceLocation())) { |
| 2971 | ClausesWithImplicit.push_back(Implicit); |
| 2972 | ErrorFound = cast<OMPFirstprivateClause>(Implicit)->varlist_size() != |
| 2973 | DSAChecker.getImplicitFirstprivate().size(); |
| 2974 | } else |
| 2975 | ErrorFound = true; |
| 2976 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2977 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2978 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2979 | llvm::SmallVector<OpenMPDirectiveKind, 4> AllowedNameModifiers; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2980 | switch (Kind) { |
| 2981 | case OMPD_parallel: |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2982 | Res = ActOnOpenMPParallelDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2983 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2984 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2985 | break; |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 2986 | case OMPD_simd: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2987 | Res = ActOnOpenMPSimdDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc, |
| 2988 | VarsWithInheritedDSA); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 2989 | break; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2990 | case OMPD_for: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2991 | Res = ActOnOpenMPForDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc, |
| 2992 | VarsWithInheritedDSA); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2993 | break; |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2994 | case OMPD_for_simd: |
| 2995 | Res = ActOnOpenMPForSimdDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2996 | EndLoc, VarsWithInheritedDSA); |
| 2997 | break; |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 2998 | case OMPD_sections: |
| 2999 | Res = ActOnOpenMPSectionsDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3000 | EndLoc); |
| 3001 | break; |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 3002 | case OMPD_section: |
| 3003 | assert(ClausesWithImplicit.empty() && |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 3004 | "No clauses are allowed for 'omp section' directive"); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 3005 | Res = ActOnOpenMPSectionDirective(AStmt, StartLoc, EndLoc); |
| 3006 | break; |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 3007 | case OMPD_single: |
| 3008 | Res = ActOnOpenMPSingleDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3009 | EndLoc); |
| 3010 | break; |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 3011 | case OMPD_master: |
| 3012 | assert(ClausesWithImplicit.empty() && |
| 3013 | "No clauses are allowed for 'omp master' directive"); |
| 3014 | Res = ActOnOpenMPMasterDirective(AStmt, StartLoc, EndLoc); |
| 3015 | break; |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 3016 | case OMPD_critical: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 3017 | Res = ActOnOpenMPCriticalDirective(DirName, ClausesWithImplicit, AStmt, |
| 3018 | StartLoc, EndLoc); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 3019 | break; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3020 | case OMPD_parallel_for: |
| 3021 | Res = ActOnOpenMPParallelForDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3022 | EndLoc, VarsWithInheritedDSA); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3023 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3024 | break; |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 3025 | case OMPD_parallel_for_simd: |
| 3026 | Res = ActOnOpenMPParallelForSimdDirective( |
| 3027 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3028 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 3029 | break; |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 3030 | case OMPD_parallel_sections: |
| 3031 | Res = ActOnOpenMPParallelSectionsDirective(ClausesWithImplicit, AStmt, |
| 3032 | StartLoc, EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3033 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 3034 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3035 | case OMPD_task: |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 3036 | Res = |
| 3037 | ActOnOpenMPTaskDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3038 | AllowedNameModifiers.push_back(OMPD_task); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 3039 | break; |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 3040 | case OMPD_taskyield: |
| 3041 | assert(ClausesWithImplicit.empty() && |
| 3042 | "No clauses are allowed for 'omp taskyield' directive"); |
| 3043 | assert(AStmt == nullptr && |
| 3044 | "No associated statement allowed for 'omp taskyield' directive"); |
| 3045 | Res = ActOnOpenMPTaskyieldDirective(StartLoc, EndLoc); |
| 3046 | break; |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 3047 | case OMPD_barrier: |
| 3048 | assert(ClausesWithImplicit.empty() && |
| 3049 | "No clauses are allowed for 'omp barrier' directive"); |
| 3050 | assert(AStmt == nullptr && |
| 3051 | "No associated statement allowed for 'omp barrier' directive"); |
| 3052 | Res = ActOnOpenMPBarrierDirective(StartLoc, EndLoc); |
| 3053 | break; |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 3054 | case OMPD_taskwait: |
| 3055 | assert(ClausesWithImplicit.empty() && |
| 3056 | "No clauses are allowed for 'omp taskwait' directive"); |
| 3057 | assert(AStmt == nullptr && |
| 3058 | "No associated statement allowed for 'omp taskwait' directive"); |
| 3059 | Res = ActOnOpenMPTaskwaitDirective(StartLoc, EndLoc); |
| 3060 | break; |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 3061 | case OMPD_taskgroup: |
| 3062 | assert(ClausesWithImplicit.empty() && |
| 3063 | "No clauses are allowed for 'omp taskgroup' directive"); |
| 3064 | Res = ActOnOpenMPTaskgroupDirective(AStmt, StartLoc, EndLoc); |
| 3065 | break; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 3066 | case OMPD_flush: |
| 3067 | assert(AStmt == nullptr && |
| 3068 | "No associated statement allowed for 'omp flush' directive"); |
| 3069 | Res = ActOnOpenMPFlushDirective(ClausesWithImplicit, StartLoc, EndLoc); |
| 3070 | break; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 3071 | case OMPD_ordered: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 3072 | Res = ActOnOpenMPOrderedDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3073 | EndLoc); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 3074 | break; |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 3075 | case OMPD_atomic: |
| 3076 | Res = ActOnOpenMPAtomicDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3077 | EndLoc); |
| 3078 | break; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 3079 | case OMPD_teams: |
| 3080 | Res = |
| 3081 | ActOnOpenMPTeamsDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); |
| 3082 | break; |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 3083 | case OMPD_target: |
| 3084 | Res = ActOnOpenMPTargetDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3085 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3086 | AllowedNameModifiers.push_back(OMPD_target); |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 3087 | break; |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 3088 | case OMPD_target_parallel: |
| 3089 | Res = ActOnOpenMPTargetParallelDirective(ClausesWithImplicit, AStmt, |
| 3090 | StartLoc, EndLoc); |
| 3091 | AllowedNameModifiers.push_back(OMPD_target); |
| 3092 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 3093 | break; |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 3094 | case OMPD_target_parallel_for: |
| 3095 | Res = ActOnOpenMPTargetParallelForDirective( |
| 3096 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 3097 | AllowedNameModifiers.push_back(OMPD_target); |
| 3098 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 3099 | break; |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 3100 | case OMPD_cancellation_point: |
| 3101 | assert(ClausesWithImplicit.empty() && |
| 3102 | "No clauses are allowed for 'omp cancellation point' directive"); |
| 3103 | assert(AStmt == nullptr && "No associated statement allowed for 'omp " |
| 3104 | "cancellation point' directive"); |
| 3105 | Res = ActOnOpenMPCancellationPointDirective(StartLoc, EndLoc, CancelRegion); |
| 3106 | break; |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 3107 | case OMPD_cancel: |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 3108 | assert(AStmt == nullptr && |
| 3109 | "No associated statement allowed for 'omp cancel' directive"); |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 3110 | Res = ActOnOpenMPCancelDirective(ClausesWithImplicit, StartLoc, EndLoc, |
| 3111 | CancelRegion); |
| 3112 | AllowedNameModifiers.push_back(OMPD_cancel); |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 3113 | break; |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 3114 | case OMPD_target_data: |
| 3115 | Res = ActOnOpenMPTargetDataDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3116 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3117 | AllowedNameModifiers.push_back(OMPD_target_data); |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 3118 | break; |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 3119 | case OMPD_target_enter_data: |
| 3120 | Res = ActOnOpenMPTargetEnterDataDirective(ClausesWithImplicit, StartLoc, |
| 3121 | EndLoc); |
| 3122 | AllowedNameModifiers.push_back(OMPD_target_enter_data); |
| 3123 | break; |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 3124 | case OMPD_target_exit_data: |
| 3125 | Res = ActOnOpenMPTargetExitDataDirective(ClausesWithImplicit, StartLoc, |
| 3126 | EndLoc); |
| 3127 | AllowedNameModifiers.push_back(OMPD_target_exit_data); |
| 3128 | break; |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 3129 | case OMPD_taskloop: |
| 3130 | Res = ActOnOpenMPTaskLoopDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3131 | EndLoc, VarsWithInheritedDSA); |
| 3132 | AllowedNameModifiers.push_back(OMPD_taskloop); |
| 3133 | break; |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 3134 | case OMPD_taskloop_simd: |
| 3135 | Res = ActOnOpenMPTaskLoopSimdDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3136 | EndLoc, VarsWithInheritedDSA); |
| 3137 | AllowedNameModifiers.push_back(OMPD_taskloop); |
| 3138 | break; |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 3139 | case OMPD_distribute: |
| 3140 | Res = ActOnOpenMPDistributeDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3141 | EndLoc, VarsWithInheritedDSA); |
| 3142 | break; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 3143 | case OMPD_threadprivate: |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 3144 | case OMPD_declare_reduction: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3145 | llvm_unreachable("OpenMP Directive is not allowed"); |
| 3146 | case OMPD_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3147 | llvm_unreachable("Unknown OpenMP directive"); |
| 3148 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 3149 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3150 | for (auto P : VarsWithInheritedDSA) { |
| 3151 | Diag(P.second->getExprLoc(), diag::err_omp_no_dsa_for_variable) |
| 3152 | << P.first << P.second->getSourceRange(); |
| 3153 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3154 | ErrorFound = !VarsWithInheritedDSA.empty() || ErrorFound; |
| 3155 | |
| 3156 | if (!AllowedNameModifiers.empty()) |
| 3157 | ErrorFound = checkIfClauses(*this, Kind, Clauses, AllowedNameModifiers) || |
| 3158 | ErrorFound; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3159 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 3160 | if (ErrorFound) |
| 3161 | return StmtError(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3162 | return Res; |
| 3163 | } |
| 3164 | |
| 3165 | StmtResult Sema::ActOnOpenMPParallelDirective(ArrayRef<OMPClause *> Clauses, |
| 3166 | Stmt *AStmt, |
| 3167 | SourceLocation StartLoc, |
| 3168 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3169 | if (!AStmt) |
| 3170 | return StmtError(); |
| 3171 | |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 3172 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 3173 | // 1.2.2 OpenMP Language Terminology |
| 3174 | // Structured block - An executable statement with a single entry at the |
| 3175 | // top and a single exit at the bottom. |
| 3176 | // The point of exit cannot be a branch out of the structured block. |
| 3177 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 3178 | CS->getCapturedDecl()->setNothrow(); |
| 3179 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3180 | getCurFunction()->setHasBranchProtectedScope(); |
| 3181 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 3182 | return OMPParallelDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 3183 | DSAStack->isCancelRegion()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3184 | } |
| 3185 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3186 | namespace { |
| 3187 | /// \brief Helper class for checking canonical form of the OpenMP loops and |
| 3188 | /// extracting iteration space of each loop in the loop nest, that will be used |
| 3189 | /// for IR generation. |
| 3190 | class OpenMPIterationSpaceChecker { |
| 3191 | /// \brief Reference to Sema. |
| 3192 | Sema &SemaRef; |
| 3193 | /// \brief A location for diagnostics (when there is no some better location). |
| 3194 | SourceLocation DefaultLoc; |
| 3195 | /// \brief A location for diagnostics (when increment is not compatible). |
| 3196 | SourceLocation ConditionLoc; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3197 | /// \brief A source location for referring to loop init later. |
| 3198 | SourceRange InitSrcRange; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3199 | /// \brief A source location for referring to condition later. |
| 3200 | SourceRange ConditionSrcRange; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3201 | /// \brief A source location for referring to increment later. |
| 3202 | SourceRange IncrementSrcRange; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3203 | /// \brief Loop variable. |
| 3204 | VarDecl *Var; |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3205 | /// \brief Reference to loop variable. |
| 3206 | DeclRefExpr *VarRef; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3207 | /// \brief Lower bound (initializer for the var). |
| 3208 | Expr *LB; |
| 3209 | /// \brief Upper bound. |
| 3210 | Expr *UB; |
| 3211 | /// \brief Loop step (increment). |
| 3212 | Expr *Step; |
| 3213 | /// \brief This flag is true when condition is one of: |
| 3214 | /// Var < UB |
| 3215 | /// Var <= UB |
| 3216 | /// UB > Var |
| 3217 | /// UB >= Var |
| 3218 | bool TestIsLessOp; |
| 3219 | /// \brief This flag is true when condition is strict ( < or > ). |
| 3220 | bool TestIsStrictOp; |
| 3221 | /// \brief This flag is true when step is subtracted on each iteration. |
| 3222 | bool SubtractStep; |
| 3223 | |
| 3224 | public: |
| 3225 | OpenMPIterationSpaceChecker(Sema &SemaRef, SourceLocation DefaultLoc) |
| 3226 | : SemaRef(SemaRef), DefaultLoc(DefaultLoc), ConditionLoc(DefaultLoc), |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3227 | InitSrcRange(SourceRange()), ConditionSrcRange(SourceRange()), |
| 3228 | IncrementSrcRange(SourceRange()), Var(nullptr), VarRef(nullptr), |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3229 | LB(nullptr), UB(nullptr), Step(nullptr), TestIsLessOp(false), |
| 3230 | TestIsStrictOp(false), SubtractStep(false) {} |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3231 | /// \brief Check init-expr for canonical loop form and save loop counter |
| 3232 | /// variable - #Var and its initialization value - #LB. |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3233 | bool CheckInit(Stmt *S, bool EmitDiags = true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3234 | /// \brief Check test-expr for canonical form, save upper-bound (#UB), flags |
| 3235 | /// for less/greater and for strict/non-strict comparison. |
| 3236 | bool CheckCond(Expr *S); |
| 3237 | /// \brief Check incr-expr for canonical loop form and return true if it |
| 3238 | /// does not conform, otherwise save loop step (#Step). |
| 3239 | bool CheckInc(Expr *S); |
| 3240 | /// \brief Return the loop counter variable. |
| 3241 | VarDecl *GetLoopVar() const { return Var; } |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3242 | /// \brief Return the reference expression to loop counter variable. |
| 3243 | DeclRefExpr *GetLoopVarRefExpr() const { return VarRef; } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3244 | /// \brief Source range of the loop init. |
| 3245 | SourceRange GetInitSrcRange() const { return InitSrcRange; } |
| 3246 | /// \brief Source range of the loop condition. |
| 3247 | SourceRange GetConditionSrcRange() const { return ConditionSrcRange; } |
| 3248 | /// \brief Source range of the loop increment. |
| 3249 | SourceRange GetIncrementSrcRange() const { return IncrementSrcRange; } |
| 3250 | /// \brief True if the step should be subtracted. |
| 3251 | bool ShouldSubtractStep() const { return SubtractStep; } |
| 3252 | /// \brief Build the expression to calculate the number of iterations. |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3253 | Expr *BuildNumIterations(Scope *S, const bool LimitedType) const; |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3254 | /// \brief Build the precondition expression for the loops. |
| 3255 | Expr *BuildPreCond(Scope *S, Expr *Cond) const; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3256 | /// \brief Build reference expression to the counter be used for codegen. |
| 3257 | Expr *BuildCounterVar() const; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3258 | /// \brief Build reference expression to the private counter be used for |
| 3259 | /// codegen. |
| 3260 | Expr *BuildPrivateCounterVar() const; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3261 | /// \brief Build initization of the counter be used for codegen. |
| 3262 | Expr *BuildCounterInit() const; |
| 3263 | /// \brief Build step of the counter be used for codegen. |
| 3264 | Expr *BuildCounterStep() const; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3265 | /// \brief Return true if any expression is dependent. |
| 3266 | bool Dependent() const; |
| 3267 | |
| 3268 | private: |
| 3269 | /// \brief Check the right-hand side of an assignment in the increment |
| 3270 | /// expression. |
| 3271 | bool CheckIncRHS(Expr *RHS); |
| 3272 | /// \brief Helper to set loop counter variable and its initializer. |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3273 | bool SetVarAndLB(VarDecl *NewVar, DeclRefExpr *NewVarRefExpr, Expr *NewLB); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3274 | /// \brief Helper to set upper bound. |
Craig Topper | e335f25 | 2015-10-04 04:53:55 +0000 | [diff] [blame] | 3275 | bool SetUB(Expr *NewUB, bool LessOp, bool StrictOp, SourceRange SR, |
Craig Topper | 9cd5e4f | 2015-09-21 01:23:32 +0000 | [diff] [blame] | 3276 | SourceLocation SL); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3277 | /// \brief Helper to set loop increment. |
| 3278 | bool SetStep(Expr *NewStep, bool Subtract); |
| 3279 | }; |
| 3280 | |
| 3281 | bool OpenMPIterationSpaceChecker::Dependent() const { |
| 3282 | if (!Var) { |
| 3283 | assert(!LB && !UB && !Step); |
| 3284 | return false; |
| 3285 | } |
| 3286 | return Var->getType()->isDependentType() || (LB && LB->isValueDependent()) || |
| 3287 | (UB && UB->isValueDependent()) || (Step && Step->isValueDependent()); |
| 3288 | } |
| 3289 | |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3290 | template <typename T> |
| 3291 | static T *getExprAsWritten(T *E) { |
| 3292 | if (auto *ExprTemp = dyn_cast<ExprWithCleanups>(E)) |
| 3293 | E = ExprTemp->getSubExpr(); |
| 3294 | |
| 3295 | if (auto *MTE = dyn_cast<MaterializeTemporaryExpr>(E)) |
| 3296 | E = MTE->GetTemporaryExpr(); |
| 3297 | |
| 3298 | while (auto *Binder = dyn_cast<CXXBindTemporaryExpr>(E)) |
| 3299 | E = Binder->getSubExpr(); |
| 3300 | |
| 3301 | if (auto *ICE = dyn_cast<ImplicitCastExpr>(E)) |
| 3302 | E = ICE->getSubExprAsWritten(); |
| 3303 | return E->IgnoreParens(); |
| 3304 | } |
| 3305 | |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3306 | bool OpenMPIterationSpaceChecker::SetVarAndLB(VarDecl *NewVar, |
| 3307 | DeclRefExpr *NewVarRefExpr, |
| 3308 | Expr *NewLB) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3309 | // State consistency checking to ensure correct usage. |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3310 | assert(Var == nullptr && LB == nullptr && VarRef == nullptr && |
| 3311 | UB == nullptr && Step == nullptr && !TestIsLessOp && !TestIsStrictOp); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3312 | if (!NewVar || !NewLB) |
| 3313 | return true; |
| 3314 | Var = NewVar; |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3315 | VarRef = NewVarRefExpr; |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3316 | if (auto *CE = dyn_cast_or_null<CXXConstructExpr>(NewLB)) |
| 3317 | if (const CXXConstructorDecl *Ctor = CE->getConstructor()) |
Alexey Bataev | 0d08a7f | 2015-07-16 04:19:43 +0000 | [diff] [blame] | 3318 | if ((Ctor->isCopyOrMoveConstructor() || |
| 3319 | Ctor->isConvertingConstructor(/*AllowExplicit=*/false)) && |
| 3320 | CE->getNumArgs() > 0 && CE->getArg(0) != nullptr) |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3321 | NewLB = CE->getArg(0)->IgnoreParenImpCasts(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3322 | LB = NewLB; |
| 3323 | return false; |
| 3324 | } |
| 3325 | |
| 3326 | bool OpenMPIterationSpaceChecker::SetUB(Expr *NewUB, bool LessOp, bool StrictOp, |
Craig Topper | e335f25 | 2015-10-04 04:53:55 +0000 | [diff] [blame] | 3327 | SourceRange SR, SourceLocation SL) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3328 | // State consistency checking to ensure correct usage. |
| 3329 | assert(Var != nullptr && LB != nullptr && UB == nullptr && Step == nullptr && |
| 3330 | !TestIsLessOp && !TestIsStrictOp); |
| 3331 | if (!NewUB) |
| 3332 | return true; |
| 3333 | UB = NewUB; |
| 3334 | TestIsLessOp = LessOp; |
| 3335 | TestIsStrictOp = StrictOp; |
| 3336 | ConditionSrcRange = SR; |
| 3337 | ConditionLoc = SL; |
| 3338 | return false; |
| 3339 | } |
| 3340 | |
| 3341 | bool OpenMPIterationSpaceChecker::SetStep(Expr *NewStep, bool Subtract) { |
| 3342 | // State consistency checking to ensure correct usage. |
| 3343 | assert(Var != nullptr && LB != nullptr && Step == nullptr); |
| 3344 | if (!NewStep) |
| 3345 | return true; |
| 3346 | if (!NewStep->isValueDependent()) { |
| 3347 | // Check that the step is integer expression. |
| 3348 | SourceLocation StepLoc = NewStep->getLocStart(); |
| 3349 | ExprResult Val = |
| 3350 | SemaRef.PerformOpenMPImplicitIntegerConversion(StepLoc, NewStep); |
| 3351 | if (Val.isInvalid()) |
| 3352 | return true; |
| 3353 | NewStep = Val.get(); |
| 3354 | |
| 3355 | // OpenMP [2.6, Canonical Loop Form, Restrictions] |
| 3356 | // If test-expr is of form var relational-op b and relational-op is < or |
| 3357 | // <= then incr-expr must cause var to increase on each iteration of the |
| 3358 | // loop. If test-expr is of form var relational-op b and relational-op is |
| 3359 | // > or >= then incr-expr must cause var to decrease on each iteration of |
| 3360 | // the loop. |
| 3361 | // If test-expr is of form b relational-op var and relational-op is < or |
| 3362 | // <= then incr-expr must cause var to decrease on each iteration of the |
| 3363 | // loop. If test-expr is of form b relational-op var and relational-op is |
| 3364 | // > or >= then incr-expr must cause var to increase on each iteration of |
| 3365 | // the loop. |
| 3366 | llvm::APSInt Result; |
| 3367 | bool IsConstant = NewStep->isIntegerConstantExpr(Result, SemaRef.Context); |
| 3368 | bool IsUnsigned = !NewStep->getType()->hasSignedIntegerRepresentation(); |
| 3369 | bool IsConstNeg = |
| 3370 | IsConstant && Result.isSigned() && (Subtract != Result.isNegative()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3371 | bool IsConstPos = |
| 3372 | IsConstant && Result.isSigned() && (Subtract == Result.isNegative()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3373 | bool IsConstZero = IsConstant && !Result.getBoolValue(); |
| 3374 | if (UB && (IsConstZero || |
| 3375 | (TestIsLessOp ? (IsConstNeg || (IsUnsigned && Subtract)) |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3376 | : (IsConstPos || (IsUnsigned && !Subtract))))) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3377 | SemaRef.Diag(NewStep->getExprLoc(), |
| 3378 | diag::err_omp_loop_incr_not_compatible) |
| 3379 | << Var << TestIsLessOp << NewStep->getSourceRange(); |
| 3380 | SemaRef.Diag(ConditionLoc, |
| 3381 | diag::note_omp_loop_cond_requres_compatible_incr) |
| 3382 | << TestIsLessOp << ConditionSrcRange; |
| 3383 | return true; |
| 3384 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3385 | if (TestIsLessOp == Subtract) { |
| 3386 | NewStep = SemaRef.CreateBuiltinUnaryOp(NewStep->getExprLoc(), UO_Minus, |
| 3387 | NewStep).get(); |
| 3388 | Subtract = !Subtract; |
| 3389 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3390 | } |
| 3391 | |
| 3392 | Step = NewStep; |
| 3393 | SubtractStep = Subtract; |
| 3394 | return false; |
| 3395 | } |
| 3396 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3397 | bool OpenMPIterationSpaceChecker::CheckInit(Stmt *S, bool EmitDiags) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3398 | // Check init-expr for canonical loop form and save loop counter |
| 3399 | // variable - #Var and its initialization value - #LB. |
| 3400 | // OpenMP [2.6] Canonical loop form. init-expr may be one of the following: |
| 3401 | // var = lb |
| 3402 | // integer-type var = lb |
| 3403 | // random-access-iterator-type var = lb |
| 3404 | // pointer-type var = lb |
| 3405 | // |
| 3406 | if (!S) { |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3407 | if (EmitDiags) { |
| 3408 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_init); |
| 3409 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3410 | return true; |
| 3411 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3412 | InitSrcRange = S->getSourceRange(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3413 | if (Expr *E = dyn_cast<Expr>(S)) |
| 3414 | S = E->IgnoreParens(); |
| 3415 | if (auto BO = dyn_cast<BinaryOperator>(S)) { |
| 3416 | if (BO->getOpcode() == BO_Assign) |
| 3417 | if (auto DRE = dyn_cast<DeclRefExpr>(BO->getLHS()->IgnoreParens())) |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3418 | return SetVarAndLB(dyn_cast<VarDecl>(DRE->getDecl()), DRE, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3419 | BO->getRHS()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3420 | } else if (auto DS = dyn_cast<DeclStmt>(S)) { |
| 3421 | if (DS->isSingleDecl()) { |
| 3422 | if (auto Var = dyn_cast_or_null<VarDecl>(DS->getSingleDecl())) { |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3423 | if (Var->hasInit() && !Var->getType()->isReferenceType()) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3424 | // Accept non-canonical init form here but emit ext. warning. |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3425 | if (Var->getInitStyle() != VarDecl::CInit && EmitDiags) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3426 | SemaRef.Diag(S->getLocStart(), |
| 3427 | diag::ext_omp_loop_not_canonical_init) |
| 3428 | << S->getSourceRange(); |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3429 | return SetVarAndLB(Var, nullptr, Var->getInit()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3430 | } |
| 3431 | } |
| 3432 | } |
| 3433 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) |
| 3434 | if (CE->getOperator() == OO_Equal) |
| 3435 | if (auto DRE = dyn_cast<DeclRefExpr>(CE->getArg(0))) |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3436 | return SetVarAndLB(dyn_cast<VarDecl>(DRE->getDecl()), DRE, |
| 3437 | CE->getArg(1)); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3438 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3439 | if (EmitDiags) { |
| 3440 | SemaRef.Diag(S->getLocStart(), diag::err_omp_loop_not_canonical_init) |
| 3441 | << S->getSourceRange(); |
| 3442 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3443 | return true; |
| 3444 | } |
| 3445 | |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 3446 | /// \brief Ignore parenthesizes, implicit casts, copy constructor and return the |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3447 | /// variable (which may be the loop variable) if possible. |
| 3448 | static const VarDecl *GetInitVarDecl(const Expr *E) { |
| 3449 | if (!E) |
Craig Topper | 4b56692 | 2014-06-09 02:04:02 +0000 | [diff] [blame] | 3450 | return nullptr; |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3451 | E = getExprAsWritten(E); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3452 | if (auto *CE = dyn_cast_or_null<CXXConstructExpr>(E)) |
| 3453 | if (const CXXConstructorDecl *Ctor = CE->getConstructor()) |
Alexey Bataev | 0d08a7f | 2015-07-16 04:19:43 +0000 | [diff] [blame] | 3454 | if ((Ctor->isCopyOrMoveConstructor() || |
| 3455 | Ctor->isConvertingConstructor(/*AllowExplicit=*/false)) && |
| 3456 | CE->getNumArgs() > 0 && CE->getArg(0) != nullptr) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3457 | E = CE->getArg(0)->IgnoreParenImpCasts(); |
| 3458 | auto DRE = dyn_cast_or_null<DeclRefExpr>(E); |
| 3459 | if (!DRE) |
| 3460 | return nullptr; |
| 3461 | return dyn_cast<VarDecl>(DRE->getDecl()); |
| 3462 | } |
| 3463 | |
| 3464 | bool OpenMPIterationSpaceChecker::CheckCond(Expr *S) { |
| 3465 | // Check test-expr for canonical form, save upper-bound UB, flags for |
| 3466 | // less/greater and for strict/non-strict comparison. |
| 3467 | // OpenMP [2.6] Canonical loop form. Test-expr may be one of the following: |
| 3468 | // var relational-op b |
| 3469 | // b relational-op var |
| 3470 | // |
| 3471 | if (!S) { |
| 3472 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_cond) << Var; |
| 3473 | return true; |
| 3474 | } |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3475 | S = getExprAsWritten(S); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3476 | SourceLocation CondLoc = S->getLocStart(); |
| 3477 | if (auto BO = dyn_cast<BinaryOperator>(S)) { |
| 3478 | if (BO->isRelationalOp()) { |
| 3479 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 3480 | return SetUB(BO->getRHS(), |
| 3481 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_LE), |
| 3482 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_GT), |
| 3483 | BO->getSourceRange(), BO->getOperatorLoc()); |
| 3484 | if (GetInitVarDecl(BO->getRHS()) == Var) |
| 3485 | return SetUB(BO->getLHS(), |
| 3486 | (BO->getOpcode() == BO_GT || BO->getOpcode() == BO_GE), |
| 3487 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_GT), |
| 3488 | BO->getSourceRange(), BO->getOperatorLoc()); |
| 3489 | } |
| 3490 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
| 3491 | if (CE->getNumArgs() == 2) { |
| 3492 | auto Op = CE->getOperator(); |
| 3493 | switch (Op) { |
| 3494 | case OO_Greater: |
| 3495 | case OO_GreaterEqual: |
| 3496 | case OO_Less: |
| 3497 | case OO_LessEqual: |
| 3498 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 3499 | return SetUB(CE->getArg(1), Op == OO_Less || Op == OO_LessEqual, |
| 3500 | Op == OO_Less || Op == OO_Greater, CE->getSourceRange(), |
| 3501 | CE->getOperatorLoc()); |
| 3502 | if (GetInitVarDecl(CE->getArg(1)) == Var) |
| 3503 | return SetUB(CE->getArg(0), Op == OO_Greater || Op == OO_GreaterEqual, |
| 3504 | Op == OO_Less || Op == OO_Greater, CE->getSourceRange(), |
| 3505 | CE->getOperatorLoc()); |
| 3506 | break; |
| 3507 | default: |
| 3508 | break; |
| 3509 | } |
| 3510 | } |
| 3511 | } |
| 3512 | SemaRef.Diag(CondLoc, diag::err_omp_loop_not_canonical_cond) |
| 3513 | << S->getSourceRange() << Var; |
| 3514 | return true; |
| 3515 | } |
| 3516 | |
| 3517 | bool OpenMPIterationSpaceChecker::CheckIncRHS(Expr *RHS) { |
| 3518 | // RHS of canonical loop form increment can be: |
| 3519 | // var + incr |
| 3520 | // incr + var |
| 3521 | // var - incr |
| 3522 | // |
| 3523 | RHS = RHS->IgnoreParenImpCasts(); |
| 3524 | if (auto BO = dyn_cast<BinaryOperator>(RHS)) { |
| 3525 | if (BO->isAdditiveOp()) { |
| 3526 | bool IsAdd = BO->getOpcode() == BO_Add; |
| 3527 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 3528 | return SetStep(BO->getRHS(), !IsAdd); |
| 3529 | if (IsAdd && GetInitVarDecl(BO->getRHS()) == Var) |
| 3530 | return SetStep(BO->getLHS(), false); |
| 3531 | } |
| 3532 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(RHS)) { |
| 3533 | bool IsAdd = CE->getOperator() == OO_Plus; |
| 3534 | if ((IsAdd || CE->getOperator() == OO_Minus) && CE->getNumArgs() == 2) { |
| 3535 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 3536 | return SetStep(CE->getArg(1), !IsAdd); |
| 3537 | if (IsAdd && GetInitVarDecl(CE->getArg(1)) == Var) |
| 3538 | return SetStep(CE->getArg(0), false); |
| 3539 | } |
| 3540 | } |
| 3541 | SemaRef.Diag(RHS->getLocStart(), diag::err_omp_loop_not_canonical_incr) |
| 3542 | << RHS->getSourceRange() << Var; |
| 3543 | return true; |
| 3544 | } |
| 3545 | |
| 3546 | bool OpenMPIterationSpaceChecker::CheckInc(Expr *S) { |
| 3547 | // Check incr-expr for canonical loop form and return true if it |
| 3548 | // does not conform. |
| 3549 | // OpenMP [2.6] Canonical loop form. Test-expr may be one of the following: |
| 3550 | // ++var |
| 3551 | // var++ |
| 3552 | // --var |
| 3553 | // var-- |
| 3554 | // var += incr |
| 3555 | // var -= incr |
| 3556 | // var = var + incr |
| 3557 | // var = incr + var |
| 3558 | // var = var - incr |
| 3559 | // |
| 3560 | if (!S) { |
| 3561 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_incr) << Var; |
| 3562 | return true; |
| 3563 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3564 | IncrementSrcRange = S->getSourceRange(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3565 | S = S->IgnoreParens(); |
| 3566 | if (auto UO = dyn_cast<UnaryOperator>(S)) { |
| 3567 | if (UO->isIncrementDecrementOp() && GetInitVarDecl(UO->getSubExpr()) == Var) |
| 3568 | return SetStep( |
| 3569 | SemaRef.ActOnIntegerConstant(UO->getLocStart(), |
| 3570 | (UO->isDecrementOp() ? -1 : 1)).get(), |
| 3571 | false); |
| 3572 | } else if (auto BO = dyn_cast<BinaryOperator>(S)) { |
| 3573 | switch (BO->getOpcode()) { |
| 3574 | case BO_AddAssign: |
| 3575 | case BO_SubAssign: |
| 3576 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 3577 | return SetStep(BO->getRHS(), BO->getOpcode() == BO_SubAssign); |
| 3578 | break; |
| 3579 | case BO_Assign: |
| 3580 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 3581 | return CheckIncRHS(BO->getRHS()); |
| 3582 | break; |
| 3583 | default: |
| 3584 | break; |
| 3585 | } |
| 3586 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
| 3587 | switch (CE->getOperator()) { |
| 3588 | case OO_PlusPlus: |
| 3589 | case OO_MinusMinus: |
| 3590 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 3591 | return SetStep( |
| 3592 | SemaRef.ActOnIntegerConstant( |
| 3593 | CE->getLocStart(), |
| 3594 | ((CE->getOperator() == OO_MinusMinus) ? -1 : 1)).get(), |
| 3595 | false); |
| 3596 | break; |
| 3597 | case OO_PlusEqual: |
| 3598 | case OO_MinusEqual: |
| 3599 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 3600 | return SetStep(CE->getArg(1), CE->getOperator() == OO_MinusEqual); |
| 3601 | break; |
| 3602 | case OO_Equal: |
| 3603 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 3604 | return CheckIncRHS(CE->getArg(1)); |
| 3605 | break; |
| 3606 | default: |
| 3607 | break; |
| 3608 | } |
| 3609 | } |
| 3610 | SemaRef.Diag(S->getLocStart(), diag::err_omp_loop_not_canonical_incr) |
| 3611 | << S->getSourceRange() << Var; |
| 3612 | return true; |
| 3613 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3614 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3615 | namespace { |
| 3616 | // Transform variables declared in GNU statement expressions to new ones to |
| 3617 | // avoid crash on codegen. |
| 3618 | class TransformToNewDefs : public TreeTransform<TransformToNewDefs> { |
| 3619 | typedef TreeTransform<TransformToNewDefs> BaseTransform; |
| 3620 | |
| 3621 | public: |
| 3622 | TransformToNewDefs(Sema &SemaRef) : BaseTransform(SemaRef) {} |
| 3623 | |
| 3624 | Decl *TransformDefinition(SourceLocation Loc, Decl *D) { |
| 3625 | if (auto *VD = cast<VarDecl>(D)) |
| 3626 | if (!isa<ParmVarDecl>(D) && !isa<VarTemplateSpecializationDecl>(D) && |
| 3627 | !isa<ImplicitParamDecl>(D)) { |
| 3628 | auto *NewVD = VarDecl::Create( |
| 3629 | SemaRef.Context, VD->getDeclContext(), VD->getLocStart(), |
| 3630 | VD->getLocation(), VD->getIdentifier(), VD->getType(), |
| 3631 | VD->getTypeSourceInfo(), VD->getStorageClass()); |
| 3632 | NewVD->setTSCSpec(VD->getTSCSpec()); |
| 3633 | NewVD->setInit(VD->getInit()); |
| 3634 | NewVD->setInitStyle(VD->getInitStyle()); |
| 3635 | NewVD->setExceptionVariable(VD->isExceptionVariable()); |
| 3636 | NewVD->setNRVOVariable(VD->isNRVOVariable()); |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 3637 | NewVD->setCXXForRangeDecl(VD->isCXXForRangeDecl()); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3638 | NewVD->setConstexpr(VD->isConstexpr()); |
| 3639 | NewVD->setInitCapture(VD->isInitCapture()); |
| 3640 | NewVD->setPreviousDeclInSameBlockScope( |
| 3641 | VD->isPreviousDeclInSameBlockScope()); |
| 3642 | VD->getDeclContext()->addHiddenDecl(NewVD); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 3643 | if (VD->hasAttrs()) |
| 3644 | NewVD->setAttrs(VD->getAttrs()); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3645 | transformedLocalDecl(VD, NewVD); |
| 3646 | return NewVD; |
| 3647 | } |
| 3648 | return BaseTransform::TransformDefinition(Loc, D); |
| 3649 | } |
| 3650 | |
| 3651 | ExprResult TransformDeclRefExpr(DeclRefExpr *E) { |
| 3652 | if (auto *NewD = TransformDecl(E->getExprLoc(), E->getDecl())) |
| 3653 | if (E->getDecl() != NewD) { |
| 3654 | NewD->setReferenced(); |
| 3655 | NewD->markUsed(SemaRef.Context); |
| 3656 | return DeclRefExpr::Create( |
| 3657 | SemaRef.Context, E->getQualifierLoc(), E->getTemplateKeywordLoc(), |
| 3658 | cast<ValueDecl>(NewD), E->refersToEnclosingVariableOrCapture(), |
| 3659 | E->getNameInfo(), E->getType(), E->getValueKind()); |
| 3660 | } |
| 3661 | return BaseTransform::TransformDeclRefExpr(E); |
| 3662 | } |
| 3663 | }; |
| 3664 | } |
| 3665 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3666 | /// \brief Build the expression to calculate the number of iterations. |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3667 | Expr * |
| 3668 | OpenMPIterationSpaceChecker::BuildNumIterations(Scope *S, |
| 3669 | const bool LimitedType) const { |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3670 | TransformToNewDefs Transform(SemaRef); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3671 | ExprResult Diff; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3672 | auto VarType = Var->getType().getNonReferenceType(); |
| 3673 | if (VarType->isIntegerType() || VarType->isPointerType() || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3674 | SemaRef.getLangOpts().CPlusPlus) { |
| 3675 | // Upper - Lower |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3676 | auto *UBExpr = TestIsLessOp ? UB : LB; |
| 3677 | auto *LBExpr = TestIsLessOp ? LB : UB; |
| 3678 | Expr *Upper = Transform.TransformExpr(UBExpr).get(); |
| 3679 | Expr *Lower = Transform.TransformExpr(LBExpr).get(); |
| 3680 | if (!Upper || !Lower) |
| 3681 | return nullptr; |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 3682 | if (!SemaRef.Context.hasSameType(Upper->getType(), UBExpr->getType())) { |
| 3683 | Upper = SemaRef |
| 3684 | .PerformImplicitConversion(Upper, UBExpr->getType(), |
| 3685 | Sema::AA_Converting, |
| 3686 | /*AllowExplicit=*/true) |
| 3687 | .get(); |
| 3688 | } |
| 3689 | if (!SemaRef.Context.hasSameType(Lower->getType(), LBExpr->getType())) { |
| 3690 | Lower = SemaRef |
| 3691 | .PerformImplicitConversion(Lower, LBExpr->getType(), |
| 3692 | Sema::AA_Converting, |
| 3693 | /*AllowExplicit=*/true) |
| 3694 | .get(); |
| 3695 | } |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3696 | if (!Upper || !Lower) |
| 3697 | return nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3698 | |
| 3699 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Sub, Upper, Lower); |
| 3700 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3701 | if (!Diff.isUsable() && VarType->getAsCXXRecordDecl()) { |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3702 | // BuildBinOp already emitted error, this one is to point user to upper |
| 3703 | // and lower bound, and to tell what is passed to 'operator-'. |
| 3704 | SemaRef.Diag(Upper->getLocStart(), diag::err_omp_loop_diff_cxx) |
| 3705 | << Upper->getSourceRange() << Lower->getSourceRange(); |
| 3706 | return nullptr; |
| 3707 | } |
| 3708 | } |
| 3709 | |
| 3710 | if (!Diff.isUsable()) |
| 3711 | return nullptr; |
| 3712 | |
| 3713 | // Upper - Lower [- 1] |
| 3714 | if (TestIsStrictOp) |
| 3715 | Diff = SemaRef.BuildBinOp( |
| 3716 | S, DefaultLoc, BO_Sub, Diff.get(), |
| 3717 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 3718 | if (!Diff.isUsable()) |
| 3719 | return nullptr; |
| 3720 | |
| 3721 | // Upper - Lower [- 1] + Step |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 3722 | auto *StepNoImp = Step->IgnoreImplicit(); |
| 3723 | auto NewStep = Transform.TransformExpr(StepNoImp); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3724 | if (NewStep.isInvalid()) |
| 3725 | return nullptr; |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 3726 | if (!SemaRef.Context.hasSameType(NewStep.get()->getType(), |
| 3727 | StepNoImp->getType())) { |
| 3728 | NewStep = SemaRef.PerformImplicitConversion( |
| 3729 | NewStep.get(), StepNoImp->getType(), Sema::AA_Converting, |
| 3730 | /*AllowExplicit=*/true); |
| 3731 | if (NewStep.isInvalid()) |
| 3732 | return nullptr; |
| 3733 | } |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3734 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Add, Diff.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3735 | if (!Diff.isUsable()) |
| 3736 | return nullptr; |
| 3737 | |
| 3738 | // Parentheses (for dumping/debugging purposes only). |
| 3739 | Diff = SemaRef.ActOnParenExpr(DefaultLoc, DefaultLoc, Diff.get()); |
| 3740 | if (!Diff.isUsable()) |
| 3741 | return nullptr; |
| 3742 | |
| 3743 | // (Upper - Lower [- 1] + Step) / Step |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 3744 | NewStep = Transform.TransformExpr(StepNoImp); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3745 | if (NewStep.isInvalid()) |
| 3746 | return nullptr; |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 3747 | if (!SemaRef.Context.hasSameType(NewStep.get()->getType(), |
| 3748 | StepNoImp->getType())) { |
| 3749 | NewStep = SemaRef.PerformImplicitConversion( |
| 3750 | NewStep.get(), StepNoImp->getType(), Sema::AA_Converting, |
| 3751 | /*AllowExplicit=*/true); |
| 3752 | if (NewStep.isInvalid()) |
| 3753 | return nullptr; |
| 3754 | } |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3755 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Div, Diff.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3756 | if (!Diff.isUsable()) |
| 3757 | return nullptr; |
| 3758 | |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3759 | // OpenMP runtime requires 32-bit or 64-bit loop variables. |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3760 | QualType Type = Diff.get()->getType(); |
| 3761 | auto &C = SemaRef.Context; |
| 3762 | bool UseVarType = VarType->hasIntegerRepresentation() && |
| 3763 | C.getTypeSize(Type) > C.getTypeSize(VarType); |
| 3764 | if (!Type->isIntegerType() || UseVarType) { |
| 3765 | unsigned NewSize = |
| 3766 | UseVarType ? C.getTypeSize(VarType) : C.getTypeSize(Type); |
| 3767 | bool IsSigned = UseVarType ? VarType->hasSignedIntegerRepresentation() |
| 3768 | : Type->hasSignedIntegerRepresentation(); |
| 3769 | Type = C.getIntTypeForBitwidth(NewSize, IsSigned); |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 3770 | if (!SemaRef.Context.hasSameType(Diff.get()->getType(), Type)) { |
| 3771 | Diff = SemaRef.PerformImplicitConversion( |
| 3772 | Diff.get(), Type, Sema::AA_Converting, /*AllowExplicit=*/true); |
| 3773 | if (!Diff.isUsable()) |
| 3774 | return nullptr; |
| 3775 | } |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3776 | } |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3777 | if (LimitedType) { |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3778 | unsigned NewSize = (C.getTypeSize(Type) > 32) ? 64 : 32; |
| 3779 | if (NewSize != C.getTypeSize(Type)) { |
| 3780 | if (NewSize < C.getTypeSize(Type)) { |
| 3781 | assert(NewSize == 64 && "incorrect loop var size"); |
| 3782 | SemaRef.Diag(DefaultLoc, diag::warn_omp_loop_64_bit_var) |
| 3783 | << InitSrcRange << ConditionSrcRange; |
| 3784 | } |
| 3785 | QualType NewType = C.getIntTypeForBitwidth( |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3786 | NewSize, Type->hasSignedIntegerRepresentation() || |
| 3787 | C.getTypeSize(Type) < NewSize); |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 3788 | if (!SemaRef.Context.hasSameType(Diff.get()->getType(), NewType)) { |
| 3789 | Diff = SemaRef.PerformImplicitConversion(Diff.get(), NewType, |
| 3790 | Sema::AA_Converting, true); |
| 3791 | if (!Diff.isUsable()) |
| 3792 | return nullptr; |
| 3793 | } |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3794 | } |
| 3795 | } |
| 3796 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3797 | return Diff.get(); |
| 3798 | } |
| 3799 | |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3800 | Expr *OpenMPIterationSpaceChecker::BuildPreCond(Scope *S, Expr *Cond) const { |
| 3801 | // Try to build LB <op> UB, where <op> is <, >, <=, or >=. |
| 3802 | bool Suppress = SemaRef.getDiagnostics().getSuppressAllDiagnostics(); |
| 3803 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(/*Val=*/true); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3804 | TransformToNewDefs Transform(SemaRef); |
| 3805 | |
| 3806 | auto NewLB = Transform.TransformExpr(LB); |
| 3807 | auto NewUB = Transform.TransformExpr(UB); |
| 3808 | if (NewLB.isInvalid() || NewUB.isInvalid()) |
| 3809 | return Cond; |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 3810 | if (!SemaRef.Context.hasSameType(NewLB.get()->getType(), LB->getType())) { |
| 3811 | NewLB = SemaRef.PerformImplicitConversion(NewLB.get(), LB->getType(), |
| 3812 | Sema::AA_Converting, |
| 3813 | /*AllowExplicit=*/true); |
| 3814 | } |
| 3815 | if (!SemaRef.Context.hasSameType(NewUB.get()->getType(), UB->getType())) { |
| 3816 | NewUB = SemaRef.PerformImplicitConversion(NewUB.get(), UB->getType(), |
| 3817 | Sema::AA_Converting, |
| 3818 | /*AllowExplicit=*/true); |
| 3819 | } |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3820 | if (NewLB.isInvalid() || NewUB.isInvalid()) |
| 3821 | return Cond; |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3822 | auto CondExpr = SemaRef.BuildBinOp( |
| 3823 | S, DefaultLoc, TestIsLessOp ? (TestIsStrictOp ? BO_LT : BO_LE) |
| 3824 | : (TestIsStrictOp ? BO_GT : BO_GE), |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3825 | NewLB.get(), NewUB.get()); |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3826 | if (CondExpr.isUsable()) { |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 3827 | if (!SemaRef.Context.hasSameType(CondExpr.get()->getType(), |
| 3828 | SemaRef.Context.BoolTy)) |
| 3829 | CondExpr = SemaRef.PerformImplicitConversion( |
| 3830 | CondExpr.get(), SemaRef.Context.BoolTy, /*Action=*/Sema::AA_Casting, |
| 3831 | /*AllowExplicit=*/true); |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3832 | } |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3833 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(Suppress); |
| 3834 | // Otherwise use original loop conditon and evaluate it in runtime. |
| 3835 | return CondExpr.isUsable() ? CondExpr.get() : Cond; |
| 3836 | } |
| 3837 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3838 | /// \brief Build reference expression to the counter be used for codegen. |
| 3839 | Expr *OpenMPIterationSpaceChecker::BuildCounterVar() const { |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3840 | return buildDeclRefExpr(SemaRef, Var, Var->getType().getNonReferenceType(), |
| 3841 | DefaultLoc); |
| 3842 | } |
| 3843 | |
| 3844 | Expr *OpenMPIterationSpaceChecker::BuildPrivateCounterVar() const { |
| 3845 | if (Var && !Var->isInvalidDecl()) { |
| 3846 | auto Type = Var->getType().getNonReferenceType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 3847 | auto *PrivateVar = |
| 3848 | buildVarDecl(SemaRef, DefaultLoc, Type, Var->getName(), |
| 3849 | Var->hasAttrs() ? &Var->getAttrs() : nullptr); |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3850 | if (PrivateVar->isInvalidDecl()) |
| 3851 | return nullptr; |
| 3852 | return buildDeclRefExpr(SemaRef, PrivateVar, Type, DefaultLoc); |
| 3853 | } |
| 3854 | return nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3855 | } |
| 3856 | |
| 3857 | /// \brief Build initization of the counter be used for codegen. |
| 3858 | Expr *OpenMPIterationSpaceChecker::BuildCounterInit() const { return LB; } |
| 3859 | |
| 3860 | /// \brief Build step of the counter be used for codegen. |
| 3861 | Expr *OpenMPIterationSpaceChecker::BuildCounterStep() const { return Step; } |
| 3862 | |
| 3863 | /// \brief Iteration space of a single for loop. |
| 3864 | struct LoopIterationSpace { |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3865 | /// \brief Condition of the loop. |
| 3866 | Expr *PreCond; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3867 | /// \brief This expression calculates the number of iterations in the loop. |
| 3868 | /// It is always possible to calculate it before starting the loop. |
| 3869 | Expr *NumIterations; |
| 3870 | /// \brief The loop counter variable. |
| 3871 | Expr *CounterVar; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3872 | /// \brief Private loop counter variable. |
| 3873 | Expr *PrivateCounterVar; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3874 | /// \brief This is initializer for the initial value of #CounterVar. |
| 3875 | Expr *CounterInit; |
| 3876 | /// \brief This is step for the #CounterVar used to generate its update: |
| 3877 | /// #CounterVar = #CounterInit + #CounterStep * CurrentIteration. |
| 3878 | Expr *CounterStep; |
| 3879 | /// \brief Should step be subtracted? |
| 3880 | bool Subtract; |
| 3881 | /// \brief Source range of the loop init. |
| 3882 | SourceRange InitSrcRange; |
| 3883 | /// \brief Source range of the loop condition. |
| 3884 | SourceRange CondSrcRange; |
| 3885 | /// \brief Source range of the loop increment. |
| 3886 | SourceRange IncSrcRange; |
| 3887 | }; |
| 3888 | |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 3889 | } // namespace |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3890 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3891 | void Sema::ActOnOpenMPLoopInitialization(SourceLocation ForLoc, Stmt *Init) { |
| 3892 | assert(getLangOpts().OpenMP && "OpenMP is not active."); |
| 3893 | assert(Init && "Expected loop in canonical form."); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 3894 | unsigned AssociatedLoops = DSAStack->getAssociatedLoops(); |
| 3895 | if (AssociatedLoops > 0 && |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3896 | isOpenMPLoopDirective(DSAStack->getCurrentDirective())) { |
| 3897 | OpenMPIterationSpaceChecker ISC(*this, ForLoc); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 3898 | if (!ISC.CheckInit(Init, /*EmitDiags=*/false)) |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3899 | DSAStack->addLoopControlVariable(ISC.GetLoopVar()); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 3900 | DSAStack->setAssociatedLoops(AssociatedLoops - 1); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3901 | } |
| 3902 | } |
| 3903 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3904 | /// \brief Called on a for stmt to check and extract its iteration space |
| 3905 | /// for further processing (such as collapsing). |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3906 | static bool CheckOpenMPIterationSpace( |
| 3907 | OpenMPDirectiveKind DKind, Stmt *S, Sema &SemaRef, DSAStackTy &DSA, |
| 3908 | unsigned CurrentNestedLoopCount, unsigned NestedLoopCount, |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3909 | Expr *CollapseLoopCountExpr, Expr *OrderedLoopCountExpr, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 3910 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3911 | LoopIterationSpace &ResultIterSpace) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3912 | // OpenMP [2.6, Canonical Loop Form] |
| 3913 | // for (init-expr; test-expr; incr-expr) structured-block |
| 3914 | auto For = dyn_cast_or_null<ForStmt>(S); |
| 3915 | if (!For) { |
| 3916 | SemaRef.Diag(S->getLocStart(), diag::err_omp_not_for) |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3917 | << (CollapseLoopCountExpr != nullptr || OrderedLoopCountExpr != nullptr) |
| 3918 | << getOpenMPDirectiveName(DKind) << NestedLoopCount |
| 3919 | << (CurrentNestedLoopCount > 0) << CurrentNestedLoopCount; |
| 3920 | if (NestedLoopCount > 1) { |
| 3921 | if (CollapseLoopCountExpr && OrderedLoopCountExpr) |
| 3922 | SemaRef.Diag(DSA.getConstructLoc(), |
| 3923 | diag::note_omp_collapse_ordered_expr) |
| 3924 | << 2 << CollapseLoopCountExpr->getSourceRange() |
| 3925 | << OrderedLoopCountExpr->getSourceRange(); |
| 3926 | else if (CollapseLoopCountExpr) |
| 3927 | SemaRef.Diag(CollapseLoopCountExpr->getExprLoc(), |
| 3928 | diag::note_omp_collapse_ordered_expr) |
| 3929 | << 0 << CollapseLoopCountExpr->getSourceRange(); |
| 3930 | else |
| 3931 | SemaRef.Diag(OrderedLoopCountExpr->getExprLoc(), |
| 3932 | diag::note_omp_collapse_ordered_expr) |
| 3933 | << 1 << OrderedLoopCountExpr->getSourceRange(); |
| 3934 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3935 | return true; |
| 3936 | } |
| 3937 | assert(For->getBody()); |
| 3938 | |
| 3939 | OpenMPIterationSpaceChecker ISC(SemaRef, For->getForLoc()); |
| 3940 | |
| 3941 | // Check init. |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 3942 | auto Init = For->getInit(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3943 | if (ISC.CheckInit(Init)) { |
| 3944 | return true; |
| 3945 | } |
| 3946 | |
| 3947 | bool HasErrors = false; |
| 3948 | |
| 3949 | // Check loop variable's type. |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 3950 | auto Var = ISC.GetLoopVar(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3951 | |
| 3952 | // OpenMP [2.6, Canonical Loop Form] |
| 3953 | // Var is one of the following: |
| 3954 | // A variable of signed or unsigned integer type. |
| 3955 | // For C++, a variable of a random access iterator type. |
| 3956 | // For C, a variable of a pointer type. |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3957 | auto VarType = Var->getType().getNonReferenceType(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3958 | if (!VarType->isDependentType() && !VarType->isIntegerType() && |
| 3959 | !VarType->isPointerType() && |
| 3960 | !(SemaRef.getLangOpts().CPlusPlus && VarType->isOverloadableType())) { |
| 3961 | SemaRef.Diag(Init->getLocStart(), diag::err_omp_loop_variable_type) |
| 3962 | << SemaRef.getLangOpts().CPlusPlus; |
| 3963 | HasErrors = true; |
| 3964 | } |
| 3965 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3966 | // OpenMP, 2.14.1.1 Data-sharing Attribute Rules for Variables Referenced in a |
| 3967 | // Construct |
| 3968 | // The loop iteration variable(s) in the associated for-loop(s) of a for or |
| 3969 | // parallel for construct is (are) private. |
| 3970 | // The loop iteration variable in the associated for-loop of a simd construct |
| 3971 | // with just one associated for-loop is linear with a constant-linear-step |
| 3972 | // that is the increment of the associated for-loop. |
| 3973 | // Exclude loop var from the list of variables with implicitly defined data |
| 3974 | // sharing attributes. |
Benjamin Kramer | ad8e079 | 2014-10-10 15:32:48 +0000 | [diff] [blame] | 3975 | VarsWithImplicitDSA.erase(Var); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3976 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3977 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced in |
| 3978 | // a Construct, C/C++]. |
Alexey Bataev | cefffae | 2014-06-23 08:21:53 +0000 | [diff] [blame] | 3979 | // The loop iteration variable in the associated for-loop of a simd construct |
| 3980 | // with just one associated for-loop may be listed in a linear clause with a |
| 3981 | // constant-linear-step that is the increment of the associated for-loop. |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3982 | // The loop iteration variable(s) in the associated for-loop(s) of a for or |
| 3983 | // parallel for construct may be listed in a private or lastprivate clause. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 3984 | DSAStackTy::DSAVarData DVar = DSA.getTopDSA(Var, false); |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3985 | auto LoopVarRefExpr = ISC.GetLoopVarRefExpr(); |
| 3986 | // If LoopVarRefExpr is nullptr it means the corresponding loop variable is |
| 3987 | // declared in the loop and it is predetermined as a private. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3988 | auto PredeterminedCKind = |
| 3989 | isOpenMPSimdDirective(DKind) |
| 3990 | ? ((NestedLoopCount == 1) ? OMPC_linear : OMPC_lastprivate) |
| 3991 | : OMPC_private; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3992 | if (((isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown && |
Alexey Bataev | e648e80 | 2015-12-25 13:38:08 +0000 | [diff] [blame] | 3993 | DVar.CKind != PredeterminedCKind) || |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 3994 | ((isOpenMPWorksharingDirective(DKind) || DKind == OMPD_taskloop || |
Alexey Bataev | e648e80 | 2015-12-25 13:38:08 +0000 | [diff] [blame] | 3995 | isOpenMPDistributeDirective(DKind)) && |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 3996 | !isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown && |
Alexey Bataev | e648e80 | 2015-12-25 13:38:08 +0000 | [diff] [blame] | 3997 | DVar.CKind != OMPC_private && DVar.CKind != OMPC_lastprivate)) && |
| 3998 | (DVar.CKind != OMPC_private || DVar.RefExpr != nullptr)) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3999 | SemaRef.Diag(Init->getLocStart(), diag::err_omp_loop_var_dsa) |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4000 | << getOpenMPClauseName(DVar.CKind) << getOpenMPDirectiveName(DKind) |
| 4001 | << getOpenMPClauseName(PredeterminedCKind); |
Alexey Bataev | f2453a0 | 2015-05-06 07:25:08 +0000 | [diff] [blame] | 4002 | if (DVar.RefExpr == nullptr) |
| 4003 | DVar.CKind = PredeterminedCKind; |
| 4004 | ReportOriginalDSA(SemaRef, &DSA, Var, DVar, /*IsLoopIterVar=*/true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4005 | HasErrors = true; |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 4006 | } else if (LoopVarRefExpr != nullptr) { |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4007 | // Make the loop iteration variable private (for worksharing constructs), |
| 4008 | // linear (for simd directives with the only one associated loop) or |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4009 | // lastprivate (for simd directives with several collapsed or ordered |
| 4010 | // loops). |
Alexey Bataev | 9aba41c | 2014-11-14 04:08:45 +0000 | [diff] [blame] | 4011 | if (DVar.CKind == OMPC_unknown) |
| 4012 | DVar = DSA.hasDSA(Var, isOpenMPPrivate, MatchesAlways(), |
| 4013 | /*FromParent=*/false); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 4014 | DSA.addDSA(Var, LoopVarRefExpr, PredeterminedCKind); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4015 | } |
| 4016 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 4017 | assert(isOpenMPLoopDirective(DKind) && "DSA for non-loop vars"); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 4018 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4019 | // Check test-expr. |
| 4020 | HasErrors |= ISC.CheckCond(For->getCond()); |
| 4021 | |
| 4022 | // Check incr-expr. |
| 4023 | HasErrors |= ISC.CheckInc(For->getInc()); |
| 4024 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4025 | if (ISC.Dependent() || SemaRef.CurContext->isDependentContext() || HasErrors) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4026 | return HasErrors; |
| 4027 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4028 | // Build the loop's iteration space representation. |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 4029 | ResultIterSpace.PreCond = ISC.BuildPreCond(DSA.getCurScope(), For->getCond()); |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 4030 | ResultIterSpace.NumIterations = ISC.BuildNumIterations( |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 4031 | DSA.getCurScope(), (isOpenMPWorksharingDirective(DKind) || |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 4032 | isOpenMPTaskLoopDirective(DKind) || |
| 4033 | isOpenMPDistributeDirective(DKind))); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4034 | ResultIterSpace.CounterVar = ISC.BuildCounterVar(); |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 4035 | ResultIterSpace.PrivateCounterVar = ISC.BuildPrivateCounterVar(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4036 | ResultIterSpace.CounterInit = ISC.BuildCounterInit(); |
| 4037 | ResultIterSpace.CounterStep = ISC.BuildCounterStep(); |
| 4038 | ResultIterSpace.InitSrcRange = ISC.GetInitSrcRange(); |
| 4039 | ResultIterSpace.CondSrcRange = ISC.GetConditionSrcRange(); |
| 4040 | ResultIterSpace.IncSrcRange = ISC.GetIncrementSrcRange(); |
| 4041 | ResultIterSpace.Subtract = ISC.ShouldSubtractStep(); |
| 4042 | |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 4043 | HasErrors |= (ResultIterSpace.PreCond == nullptr || |
| 4044 | ResultIterSpace.NumIterations == nullptr || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4045 | ResultIterSpace.CounterVar == nullptr || |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 4046 | ResultIterSpace.PrivateCounterVar == nullptr || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4047 | ResultIterSpace.CounterInit == nullptr || |
| 4048 | ResultIterSpace.CounterStep == nullptr); |
| 4049 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4050 | return HasErrors; |
| 4051 | } |
| 4052 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4053 | /// \brief Build 'VarRef = Start. |
| 4054 | static ExprResult BuildCounterInit(Sema &SemaRef, Scope *S, SourceLocation Loc, |
| 4055 | ExprResult VarRef, ExprResult Start) { |
| 4056 | TransformToNewDefs Transform(SemaRef); |
| 4057 | // Build 'VarRef = Start. |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 4058 | auto *StartNoImp = Start.get()->IgnoreImplicit(); |
| 4059 | auto NewStart = Transform.TransformExpr(StartNoImp); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4060 | if (NewStart.isInvalid()) |
| 4061 | return ExprError(); |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 4062 | if (!SemaRef.Context.hasSameType(NewStart.get()->getType(), |
| 4063 | StartNoImp->getType())) { |
| 4064 | NewStart = SemaRef.PerformImplicitConversion( |
| 4065 | NewStart.get(), StartNoImp->getType(), Sema::AA_Converting, |
| 4066 | /*AllowExplicit=*/true); |
| 4067 | if (NewStart.isInvalid()) |
| 4068 | return ExprError(); |
| 4069 | } |
| 4070 | if (!SemaRef.Context.hasSameType(NewStart.get()->getType(), |
| 4071 | VarRef.get()->getType())) { |
| 4072 | NewStart = SemaRef.PerformImplicitConversion( |
| 4073 | NewStart.get(), VarRef.get()->getType(), Sema::AA_Converting, |
| 4074 | /*AllowExplicit=*/true); |
| 4075 | if (!NewStart.isUsable()) |
| 4076 | return ExprError(); |
| 4077 | } |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4078 | |
| 4079 | auto Init = |
| 4080 | SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), NewStart.get()); |
| 4081 | return Init; |
| 4082 | } |
| 4083 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4084 | /// \brief Build 'VarRef = Start + Iter * Step'. |
| 4085 | static ExprResult BuildCounterUpdate(Sema &SemaRef, Scope *S, |
| 4086 | SourceLocation Loc, ExprResult VarRef, |
| 4087 | ExprResult Start, ExprResult Iter, |
| 4088 | ExprResult Step, bool Subtract) { |
| 4089 | // Add parentheses (for debugging purposes only). |
| 4090 | Iter = SemaRef.ActOnParenExpr(Loc, Loc, Iter.get()); |
| 4091 | if (!VarRef.isUsable() || !Start.isUsable() || !Iter.isUsable() || |
| 4092 | !Step.isUsable()) |
| 4093 | return ExprError(); |
| 4094 | |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 4095 | auto *StepNoImp = Step.get()->IgnoreImplicit(); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4096 | TransformToNewDefs Transform(SemaRef); |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 4097 | auto NewStep = Transform.TransformExpr(StepNoImp); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4098 | if (NewStep.isInvalid()) |
| 4099 | return ExprError(); |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 4100 | if (!SemaRef.Context.hasSameType(NewStep.get()->getType(), |
| 4101 | StepNoImp->getType())) { |
| 4102 | NewStep = SemaRef.PerformImplicitConversion( |
| 4103 | NewStep.get(), StepNoImp->getType(), Sema::AA_Converting, |
| 4104 | /*AllowExplicit=*/true); |
| 4105 | if (NewStep.isInvalid()) |
| 4106 | return ExprError(); |
| 4107 | } |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4108 | ExprResult Update = |
| 4109 | SemaRef.BuildBinOp(S, Loc, BO_Mul, Iter.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4110 | if (!Update.isUsable()) |
| 4111 | return ExprError(); |
| 4112 | |
Alexey Bataev | c0214e0 | 2016-02-16 12:13:49 +0000 | [diff] [blame] | 4113 | // Try to build 'VarRef = Start, VarRef (+|-)= Iter * Step' or |
| 4114 | // 'VarRef = Start (+|-) Iter * Step'. |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 4115 | auto *StartNoImp = Start.get()->IgnoreImplicit(); |
| 4116 | auto NewStart = Transform.TransformExpr(StartNoImp); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4117 | if (NewStart.isInvalid()) |
| 4118 | return ExprError(); |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 4119 | if (!SemaRef.Context.hasSameType(NewStart.get()->getType(), |
| 4120 | StartNoImp->getType())) { |
| 4121 | NewStart = SemaRef.PerformImplicitConversion( |
| 4122 | NewStart.get(), StartNoImp->getType(), Sema::AA_Converting, |
| 4123 | /*AllowExplicit=*/true); |
| 4124 | if (NewStart.isInvalid()) |
| 4125 | return ExprError(); |
| 4126 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4127 | |
Alexey Bataev | c0214e0 | 2016-02-16 12:13:49 +0000 | [diff] [blame] | 4128 | // First attempt: try to build 'VarRef = Start, VarRef += Iter * Step'. |
| 4129 | ExprResult SavedUpdate = Update; |
| 4130 | ExprResult UpdateVal; |
| 4131 | if (VarRef.get()->getType()->isOverloadableType() || |
| 4132 | NewStart.get()->getType()->isOverloadableType() || |
| 4133 | Update.get()->getType()->isOverloadableType()) { |
| 4134 | bool Suppress = SemaRef.getDiagnostics().getSuppressAllDiagnostics(); |
| 4135 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(/*Val=*/true); |
| 4136 | Update = |
| 4137 | SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), NewStart.get()); |
| 4138 | if (Update.isUsable()) { |
| 4139 | UpdateVal = |
| 4140 | SemaRef.BuildBinOp(S, Loc, Subtract ? BO_SubAssign : BO_AddAssign, |
| 4141 | VarRef.get(), SavedUpdate.get()); |
| 4142 | if (UpdateVal.isUsable()) { |
| 4143 | Update = SemaRef.CreateBuiltinBinOp(Loc, BO_Comma, Update.get(), |
| 4144 | UpdateVal.get()); |
| 4145 | } |
| 4146 | } |
| 4147 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(Suppress); |
| 4148 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4149 | |
Alexey Bataev | c0214e0 | 2016-02-16 12:13:49 +0000 | [diff] [blame] | 4150 | // Second attempt: try to build 'VarRef = Start (+|-) Iter * Step'. |
| 4151 | if (!Update.isUsable() || !UpdateVal.isUsable()) { |
| 4152 | Update = SemaRef.BuildBinOp(S, Loc, Subtract ? BO_Sub : BO_Add, |
| 4153 | NewStart.get(), SavedUpdate.get()); |
| 4154 | if (!Update.isUsable()) |
| 4155 | return ExprError(); |
| 4156 | |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 4157 | if (!SemaRef.Context.hasSameType(Update.get()->getType(), |
| 4158 | VarRef.get()->getType())) { |
| 4159 | Update = SemaRef.PerformImplicitConversion( |
| 4160 | Update.get(), VarRef.get()->getType(), Sema::AA_Converting, true); |
| 4161 | if (!Update.isUsable()) |
| 4162 | return ExprError(); |
| 4163 | } |
Alexey Bataev | c0214e0 | 2016-02-16 12:13:49 +0000 | [diff] [blame] | 4164 | |
| 4165 | Update = SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), Update.get()); |
| 4166 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4167 | return Update; |
| 4168 | } |
| 4169 | |
| 4170 | /// \brief Convert integer expression \a E to make it have at least \a Bits |
| 4171 | /// bits. |
| 4172 | static ExprResult WidenIterationCount(unsigned Bits, Expr *E, |
| 4173 | Sema &SemaRef) { |
| 4174 | if (E == nullptr) |
| 4175 | return ExprError(); |
| 4176 | auto &C = SemaRef.Context; |
| 4177 | QualType OldType = E->getType(); |
| 4178 | unsigned HasBits = C.getTypeSize(OldType); |
| 4179 | if (HasBits >= Bits) |
| 4180 | return ExprResult(E); |
| 4181 | // OK to convert to signed, because new type has more bits than old. |
| 4182 | QualType NewType = C.getIntTypeForBitwidth(Bits, /* Signed */ true); |
| 4183 | return SemaRef.PerformImplicitConversion(E, NewType, Sema::AA_Converting, |
| 4184 | true); |
| 4185 | } |
| 4186 | |
| 4187 | /// \brief Check if the given expression \a E is a constant integer that fits |
| 4188 | /// into \a Bits bits. |
| 4189 | static bool FitsInto(unsigned Bits, bool Signed, Expr *E, Sema &SemaRef) { |
| 4190 | if (E == nullptr) |
| 4191 | return false; |
| 4192 | llvm::APSInt Result; |
| 4193 | if (E->isIntegerConstantExpr(Result, SemaRef.Context)) |
| 4194 | return Signed ? Result.isSignedIntN(Bits) : Result.isIntN(Bits); |
| 4195 | return false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4196 | } |
| 4197 | |
| 4198 | /// \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] | 4199 | /// \return Returns 0 if one of the collapsed stmts is not canonical for loop, |
| 4200 | /// number of collapsed loops otherwise. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4201 | static unsigned |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4202 | CheckOpenMPLoop(OpenMPDirectiveKind DKind, Expr *CollapseLoopCountExpr, |
| 4203 | Expr *OrderedLoopCountExpr, Stmt *AStmt, Sema &SemaRef, |
| 4204 | DSAStackTy &DSA, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 4205 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA, |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4206 | OMPLoopDirective::HelperExprs &Built) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 4207 | unsigned NestedLoopCount = 1; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4208 | if (CollapseLoopCountExpr) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 4209 | // Found 'collapse' clause - calculate collapse number. |
| 4210 | llvm::APSInt Result; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4211 | if (CollapseLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext())) |
Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 4212 | NestedLoopCount = Result.getLimitedValue(); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4213 | } |
| 4214 | if (OrderedLoopCountExpr) { |
| 4215 | // Found 'ordered' clause - calculate collapse number. |
| 4216 | llvm::APSInt Result; |
Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 4217 | if (OrderedLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext())) { |
| 4218 | if (Result.getLimitedValue() < NestedLoopCount) { |
| 4219 | SemaRef.Diag(OrderedLoopCountExpr->getExprLoc(), |
| 4220 | diag::err_omp_wrong_ordered_loop_count) |
| 4221 | << OrderedLoopCountExpr->getSourceRange(); |
| 4222 | SemaRef.Diag(CollapseLoopCountExpr->getExprLoc(), |
| 4223 | diag::note_collapse_loop_count) |
| 4224 | << CollapseLoopCountExpr->getSourceRange(); |
| 4225 | } |
| 4226 | NestedLoopCount = Result.getLimitedValue(); |
| 4227 | } |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 4228 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4229 | // This is helper routine for loop directives (e.g., 'for', 'simd', |
| 4230 | // 'for simd', etc.). |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4231 | SmallVector<LoopIterationSpace, 4> IterSpaces; |
| 4232 | IterSpaces.resize(NestedLoopCount); |
| 4233 | Stmt *CurStmt = AStmt->IgnoreContainers(/* IgnoreCaptured */ true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4234 | for (unsigned Cnt = 0; Cnt < NestedLoopCount; ++Cnt) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 4235 | if (CheckOpenMPIterationSpace(DKind, CurStmt, SemaRef, DSA, Cnt, |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4236 | NestedLoopCount, CollapseLoopCountExpr, |
| 4237 | OrderedLoopCountExpr, VarsWithImplicitDSA, |
| 4238 | IterSpaces[Cnt])) |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 4239 | return 0; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4240 | // 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] | 4241 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 4242 | // All loops associated with the construct must be perfectly nested; that |
| 4243 | // is, there must be no intervening code nor any OpenMP directive between |
| 4244 | // any two loops. |
| 4245 | CurStmt = cast<ForStmt>(CurStmt)->getBody()->IgnoreContainers(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4246 | } |
| 4247 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4248 | Built.clear(/* size */ NestedLoopCount); |
| 4249 | |
| 4250 | if (SemaRef.CurContext->isDependentContext()) |
| 4251 | return NestedLoopCount; |
| 4252 | |
| 4253 | // An example of what is generated for the following code: |
| 4254 | // |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4255 | // #pragma omp simd collapse(2) ordered(2) |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4256 | // for (i = 0; i < NI; ++i) |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4257 | // for (k = 0; k < NK; ++k) |
| 4258 | // for (j = J0; j < NJ; j+=2) { |
| 4259 | // <loop body> |
| 4260 | // } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4261 | // |
| 4262 | // We generate the code below. |
| 4263 | // Note: the loop body may be outlined in CodeGen. |
| 4264 | // Note: some counters may be C++ classes, operator- is used to find number of |
| 4265 | // iterations and operator+= to calculate counter value. |
| 4266 | // Note: decltype(NumIterations) must be integer type (in 'omp for', only i32 |
| 4267 | // or i64 is currently supported). |
| 4268 | // |
| 4269 | // #define NumIterations (NI * ((NJ - J0 - 1 + 2) / 2)) |
| 4270 | // for (int[32|64]_t IV = 0; IV < NumIterations; ++IV ) { |
| 4271 | // .local.i = IV / ((NJ - J0 - 1 + 2) / 2); |
| 4272 | // .local.j = J0 + (IV % ((NJ - J0 - 1 + 2) / 2)) * 2; |
| 4273 | // // similar updates for vars in clauses (e.g. 'linear') |
| 4274 | // <loop body (using local i and j)> |
| 4275 | // } |
| 4276 | // i = NI; // assign final values of counters |
| 4277 | // j = NJ; |
| 4278 | // |
| 4279 | |
| 4280 | // Last iteration number is (I1 * I2 * ... In) - 1, where I1, I2 ... In are |
| 4281 | // the iteration counts of the collapsed for loops. |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 4282 | // Precondition tests if there is at least one iteration (all conditions are |
| 4283 | // true). |
| 4284 | auto PreCond = ExprResult(IterSpaces[0].PreCond); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4285 | auto N0 = IterSpaces[0].NumIterations; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4286 | ExprResult LastIteration32 = WidenIterationCount( |
| 4287 | 32 /* Bits */, SemaRef.PerformImplicitConversion( |
| 4288 | N0->IgnoreImpCasts(), N0->getType(), |
| 4289 | Sema::AA_Converting, /*AllowExplicit=*/true) |
| 4290 | .get(), |
| 4291 | SemaRef); |
| 4292 | ExprResult LastIteration64 = WidenIterationCount( |
| 4293 | 64 /* Bits */, SemaRef.PerformImplicitConversion( |
| 4294 | N0->IgnoreImpCasts(), N0->getType(), |
| 4295 | Sema::AA_Converting, /*AllowExplicit=*/true) |
| 4296 | .get(), |
| 4297 | SemaRef); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4298 | |
| 4299 | if (!LastIteration32.isUsable() || !LastIteration64.isUsable()) |
| 4300 | return NestedLoopCount; |
| 4301 | |
| 4302 | auto &C = SemaRef.Context; |
| 4303 | bool AllCountsNeedLessThan32Bits = C.getTypeSize(N0->getType()) < 32; |
| 4304 | |
| 4305 | Scope *CurScope = DSA.getCurScope(); |
| 4306 | for (unsigned Cnt = 1; Cnt < NestedLoopCount; ++Cnt) { |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 4307 | if (PreCond.isUsable()) { |
| 4308 | PreCond = SemaRef.BuildBinOp(CurScope, SourceLocation(), BO_LAnd, |
| 4309 | PreCond.get(), IterSpaces[Cnt].PreCond); |
| 4310 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4311 | auto N = IterSpaces[Cnt].NumIterations; |
| 4312 | AllCountsNeedLessThan32Bits &= C.getTypeSize(N->getType()) < 32; |
| 4313 | if (LastIteration32.isUsable()) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4314 | LastIteration32 = SemaRef.BuildBinOp( |
| 4315 | CurScope, SourceLocation(), BO_Mul, LastIteration32.get(), |
| 4316 | SemaRef.PerformImplicitConversion(N->IgnoreImpCasts(), N->getType(), |
| 4317 | Sema::AA_Converting, |
| 4318 | /*AllowExplicit=*/true) |
| 4319 | .get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4320 | if (LastIteration64.isUsable()) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4321 | LastIteration64 = SemaRef.BuildBinOp( |
| 4322 | CurScope, SourceLocation(), BO_Mul, LastIteration64.get(), |
| 4323 | SemaRef.PerformImplicitConversion(N->IgnoreImpCasts(), N->getType(), |
| 4324 | Sema::AA_Converting, |
| 4325 | /*AllowExplicit=*/true) |
| 4326 | .get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4327 | } |
| 4328 | |
| 4329 | // Choose either the 32-bit or 64-bit version. |
| 4330 | ExprResult LastIteration = LastIteration64; |
| 4331 | if (LastIteration32.isUsable() && |
| 4332 | C.getTypeSize(LastIteration32.get()->getType()) == 32 && |
| 4333 | (AllCountsNeedLessThan32Bits || NestedLoopCount == 1 || |
| 4334 | FitsInto( |
| 4335 | 32 /* Bits */, |
| 4336 | LastIteration32.get()->getType()->hasSignedIntegerRepresentation(), |
| 4337 | LastIteration64.get(), SemaRef))) |
| 4338 | LastIteration = LastIteration32; |
| 4339 | |
| 4340 | if (!LastIteration.isUsable()) |
| 4341 | return 0; |
| 4342 | |
| 4343 | // Save the number of iterations. |
| 4344 | ExprResult NumIterations = LastIteration; |
| 4345 | { |
| 4346 | LastIteration = SemaRef.BuildBinOp( |
| 4347 | CurScope, SourceLocation(), BO_Sub, LastIteration.get(), |
| 4348 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 4349 | if (!LastIteration.isUsable()) |
| 4350 | return 0; |
| 4351 | } |
| 4352 | |
| 4353 | // Calculate the last iteration number beforehand instead of doing this on |
| 4354 | // each iteration. Do not do this if the number of iterations may be kfold-ed. |
| 4355 | llvm::APSInt Result; |
| 4356 | bool IsConstant = |
| 4357 | LastIteration.get()->isIntegerConstantExpr(Result, SemaRef.Context); |
| 4358 | ExprResult CalcLastIteration; |
| 4359 | if (!IsConstant) { |
| 4360 | SourceLocation SaveLoc; |
| 4361 | VarDecl *SaveVar = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4362 | buildVarDecl(SemaRef, SaveLoc, LastIteration.get()->getType(), |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4363 | ".omp.last.iteration"); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4364 | ExprResult SaveRef = buildDeclRefExpr( |
| 4365 | SemaRef, SaveVar, LastIteration.get()->getType(), SaveLoc); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4366 | CalcLastIteration = SemaRef.BuildBinOp(CurScope, SaveLoc, BO_Assign, |
| 4367 | SaveRef.get(), LastIteration.get()); |
| 4368 | LastIteration = SaveRef; |
| 4369 | |
| 4370 | // Prepare SaveRef + 1. |
| 4371 | NumIterations = SemaRef.BuildBinOp( |
| 4372 | CurScope, SaveLoc, BO_Add, SaveRef.get(), |
| 4373 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 4374 | if (!NumIterations.isUsable()) |
| 4375 | return 0; |
| 4376 | } |
| 4377 | |
| 4378 | SourceLocation InitLoc = IterSpaces[0].InitSrcRange.getBegin(); |
| 4379 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4380 | QualType VType = LastIteration.get()->getType(); |
| 4381 | // Build variables passed into runtime, nesessary for worksharing directives. |
| 4382 | ExprResult LB, UB, IL, ST, EUB; |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 4383 | if (isOpenMPWorksharingDirective(DKind) || isOpenMPTaskLoopDirective(DKind) || |
| 4384 | isOpenMPDistributeDirective(DKind)) { |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4385 | // Lower bound variable, initialized with zero. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4386 | VarDecl *LBDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.lb"); |
| 4387 | LB = buildDeclRefExpr(SemaRef, LBDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4388 | SemaRef.AddInitializerToDecl( |
| 4389 | LBDecl, SemaRef.ActOnIntegerConstant(InitLoc, 0).get(), |
| 4390 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 4391 | |
| 4392 | // Upper bound variable, initialized with last iteration number. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4393 | VarDecl *UBDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.ub"); |
| 4394 | UB = buildDeclRefExpr(SemaRef, UBDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4395 | SemaRef.AddInitializerToDecl(UBDecl, LastIteration.get(), |
| 4396 | /*DirectInit*/ false, |
| 4397 | /*TypeMayContainAuto*/ false); |
| 4398 | |
| 4399 | // A 32-bit variable-flag where runtime returns 1 for the last iteration. |
| 4400 | // This will be used to implement clause 'lastprivate'. |
| 4401 | QualType Int32Ty = SemaRef.Context.getIntTypeForBitwidth(32, true); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4402 | VarDecl *ILDecl = buildVarDecl(SemaRef, InitLoc, Int32Ty, ".omp.is_last"); |
| 4403 | IL = buildDeclRefExpr(SemaRef, ILDecl, Int32Ty, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4404 | SemaRef.AddInitializerToDecl( |
| 4405 | ILDecl, SemaRef.ActOnIntegerConstant(InitLoc, 0).get(), |
| 4406 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 4407 | |
| 4408 | // Stride variable returned by runtime (we initialize it to 1 by default). |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4409 | VarDecl *STDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.stride"); |
| 4410 | ST = buildDeclRefExpr(SemaRef, STDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4411 | SemaRef.AddInitializerToDecl( |
| 4412 | STDecl, SemaRef.ActOnIntegerConstant(InitLoc, 1).get(), |
| 4413 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 4414 | |
| 4415 | // Build expression: UB = min(UB, LastIteration) |
| 4416 | // It is nesessary for CodeGen of directives with static scheduling. |
| 4417 | ExprResult IsUBGreater = SemaRef.BuildBinOp(CurScope, InitLoc, BO_GT, |
| 4418 | UB.get(), LastIteration.get()); |
| 4419 | ExprResult CondOp = SemaRef.ActOnConditionalOp( |
| 4420 | InitLoc, InitLoc, IsUBGreater.get(), LastIteration.get(), UB.get()); |
| 4421 | EUB = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, UB.get(), |
| 4422 | CondOp.get()); |
| 4423 | EUB = SemaRef.ActOnFinishFullExpr(EUB.get()); |
| 4424 | } |
| 4425 | |
| 4426 | // Build the iteration variable and its initialization before loop. |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4427 | ExprResult IV; |
| 4428 | ExprResult Init; |
| 4429 | { |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4430 | VarDecl *IVDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.iv"); |
| 4431 | IV = buildDeclRefExpr(SemaRef, IVDecl, VType, InitLoc); |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 4432 | Expr *RHS = (isOpenMPWorksharingDirective(DKind) || |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 4433 | isOpenMPTaskLoopDirective(DKind) || |
| 4434 | isOpenMPDistributeDirective(DKind)) |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4435 | ? LB.get() |
| 4436 | : SemaRef.ActOnIntegerConstant(SourceLocation(), 0).get(); |
| 4437 | Init = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, IV.get(), RHS); |
| 4438 | Init = SemaRef.ActOnFinishFullExpr(Init.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4439 | } |
| 4440 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4441 | // Loop condition (IV < NumIterations) or (IV <= UB) for worksharing loops. |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4442 | SourceLocation CondLoc; |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4443 | ExprResult Cond = |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 4444 | (isOpenMPWorksharingDirective(DKind) || |
| 4445 | isOpenMPTaskLoopDirective(DKind) || isOpenMPDistributeDirective(DKind)) |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4446 | ? SemaRef.BuildBinOp(CurScope, CondLoc, BO_LE, IV.get(), UB.get()) |
| 4447 | : SemaRef.BuildBinOp(CurScope, CondLoc, BO_LT, IV.get(), |
| 4448 | NumIterations.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4449 | |
| 4450 | // Loop increment (IV = IV + 1) |
| 4451 | SourceLocation IncLoc; |
| 4452 | ExprResult Inc = |
| 4453 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, IV.get(), |
| 4454 | SemaRef.ActOnIntegerConstant(IncLoc, 1).get()); |
| 4455 | if (!Inc.isUsable()) |
| 4456 | return 0; |
| 4457 | Inc = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, IV.get(), Inc.get()); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4458 | Inc = SemaRef.ActOnFinishFullExpr(Inc.get()); |
| 4459 | if (!Inc.isUsable()) |
| 4460 | return 0; |
| 4461 | |
| 4462 | // Increments for worksharing loops (LB = LB + ST; UB = UB + ST). |
| 4463 | // Used for directives with static scheduling. |
| 4464 | ExprResult NextLB, NextUB; |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 4465 | if (isOpenMPWorksharingDirective(DKind) || isOpenMPTaskLoopDirective(DKind) || |
| 4466 | isOpenMPDistributeDirective(DKind)) { |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4467 | // LB + ST |
| 4468 | NextLB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, LB.get(), ST.get()); |
| 4469 | if (!NextLB.isUsable()) |
| 4470 | return 0; |
| 4471 | // LB = LB + ST |
| 4472 | NextLB = |
| 4473 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, LB.get(), NextLB.get()); |
| 4474 | NextLB = SemaRef.ActOnFinishFullExpr(NextLB.get()); |
| 4475 | if (!NextLB.isUsable()) |
| 4476 | return 0; |
| 4477 | // UB + ST |
| 4478 | NextUB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, UB.get(), ST.get()); |
| 4479 | if (!NextUB.isUsable()) |
| 4480 | return 0; |
| 4481 | // UB = UB + ST |
| 4482 | NextUB = |
| 4483 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, UB.get(), NextUB.get()); |
| 4484 | NextUB = SemaRef.ActOnFinishFullExpr(NextUB.get()); |
| 4485 | if (!NextUB.isUsable()) |
| 4486 | return 0; |
| 4487 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4488 | |
| 4489 | // Build updates and final values of the loop counters. |
| 4490 | bool HasErrors = false; |
| 4491 | Built.Counters.resize(NestedLoopCount); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4492 | Built.Inits.resize(NestedLoopCount); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4493 | Built.Updates.resize(NestedLoopCount); |
| 4494 | Built.Finals.resize(NestedLoopCount); |
| 4495 | { |
| 4496 | ExprResult Div; |
| 4497 | // Go from inner nested loop to outer. |
| 4498 | for (int Cnt = NestedLoopCount - 1; Cnt >= 0; --Cnt) { |
| 4499 | LoopIterationSpace &IS = IterSpaces[Cnt]; |
| 4500 | SourceLocation UpdLoc = IS.IncSrcRange.getBegin(); |
| 4501 | // Build: Iter = (IV / Div) % IS.NumIters |
| 4502 | // where Div is product of previous iterations' IS.NumIters. |
| 4503 | ExprResult Iter; |
| 4504 | if (Div.isUsable()) { |
| 4505 | Iter = |
| 4506 | SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Div, IV.get(), Div.get()); |
| 4507 | } else { |
| 4508 | Iter = IV; |
| 4509 | assert((Cnt == (int)NestedLoopCount - 1) && |
| 4510 | "unusable div expected on first iteration only"); |
| 4511 | } |
| 4512 | |
| 4513 | if (Cnt != 0 && Iter.isUsable()) |
| 4514 | Iter = SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Rem, Iter.get(), |
| 4515 | IS.NumIterations); |
| 4516 | if (!Iter.isUsable()) { |
| 4517 | HasErrors = true; |
| 4518 | break; |
| 4519 | } |
| 4520 | |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4521 | // Build update: IS.CounterVar(Private) = IS.Start + Iter * IS.Step |
| 4522 | auto *CounterVar = buildDeclRefExpr( |
| 4523 | SemaRef, cast<VarDecl>(cast<DeclRefExpr>(IS.CounterVar)->getDecl()), |
| 4524 | IS.CounterVar->getType(), IS.CounterVar->getExprLoc(), |
| 4525 | /*RefersToCapture=*/true); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4526 | ExprResult Init = BuildCounterInit(SemaRef, CurScope, UpdLoc, CounterVar, |
| 4527 | IS.CounterInit); |
| 4528 | if (!Init.isUsable()) { |
| 4529 | HasErrors = true; |
| 4530 | break; |
| 4531 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4532 | ExprResult Update = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4533 | BuildCounterUpdate(SemaRef, CurScope, UpdLoc, CounterVar, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4534 | IS.CounterInit, Iter, IS.CounterStep, IS.Subtract); |
| 4535 | if (!Update.isUsable()) { |
| 4536 | HasErrors = true; |
| 4537 | break; |
| 4538 | } |
| 4539 | |
| 4540 | // Build final: IS.CounterVar = IS.Start + IS.NumIters * IS.Step |
| 4541 | ExprResult Final = BuildCounterUpdate( |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4542 | SemaRef, CurScope, UpdLoc, CounterVar, IS.CounterInit, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4543 | IS.NumIterations, IS.CounterStep, IS.Subtract); |
| 4544 | if (!Final.isUsable()) { |
| 4545 | HasErrors = true; |
| 4546 | break; |
| 4547 | } |
| 4548 | |
| 4549 | // Build Div for the next iteration: Div <- Div * IS.NumIters |
| 4550 | if (Cnt != 0) { |
| 4551 | if (Div.isUnset()) |
| 4552 | Div = IS.NumIterations; |
| 4553 | else |
| 4554 | Div = SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Mul, Div.get(), |
| 4555 | IS.NumIterations); |
| 4556 | |
| 4557 | // Add parentheses (for debugging purposes only). |
| 4558 | if (Div.isUsable()) |
| 4559 | Div = SemaRef.ActOnParenExpr(UpdLoc, UpdLoc, Div.get()); |
| 4560 | if (!Div.isUsable()) { |
| 4561 | HasErrors = true; |
| 4562 | break; |
| 4563 | } |
| 4564 | } |
| 4565 | if (!Update.isUsable() || !Final.isUsable()) { |
| 4566 | HasErrors = true; |
| 4567 | break; |
| 4568 | } |
| 4569 | // Save results |
| 4570 | Built.Counters[Cnt] = IS.CounterVar; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 4571 | Built.PrivateCounters[Cnt] = IS.PrivateCounterVar; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4572 | Built.Inits[Cnt] = Init.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4573 | Built.Updates[Cnt] = Update.get(); |
| 4574 | Built.Finals[Cnt] = Final.get(); |
| 4575 | } |
| 4576 | } |
| 4577 | |
| 4578 | if (HasErrors) |
| 4579 | return 0; |
| 4580 | |
| 4581 | // Save results |
| 4582 | Built.IterationVarRef = IV.get(); |
| 4583 | Built.LastIteration = LastIteration.get(); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 4584 | Built.NumIterations = NumIterations.get(); |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 4585 | Built.CalcLastIteration = |
| 4586 | SemaRef.ActOnFinishFullExpr(CalcLastIteration.get()).get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4587 | Built.PreCond = PreCond.get(); |
| 4588 | Built.Cond = Cond.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4589 | Built.Init = Init.get(); |
| 4590 | Built.Inc = Inc.get(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4591 | Built.LB = LB.get(); |
| 4592 | Built.UB = UB.get(); |
| 4593 | Built.IL = IL.get(); |
| 4594 | Built.ST = ST.get(); |
| 4595 | Built.EUB = EUB.get(); |
| 4596 | Built.NLB = NextLB.get(); |
| 4597 | Built.NUB = NextUB.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4598 | |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 4599 | return NestedLoopCount; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4600 | } |
| 4601 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4602 | static Expr *getCollapseNumberExpr(ArrayRef<OMPClause *> Clauses) { |
Benjamin Kramer | fc600dc | 2015-08-30 15:12:28 +0000 | [diff] [blame] | 4603 | auto CollapseClauses = |
| 4604 | OMPExecutableDirective::getClausesOfKind<OMPCollapseClause>(Clauses); |
| 4605 | if (CollapseClauses.begin() != CollapseClauses.end()) |
| 4606 | return (*CollapseClauses.begin())->getNumForLoops(); |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 4607 | return nullptr; |
| 4608 | } |
| 4609 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4610 | static Expr *getOrderedNumberExpr(ArrayRef<OMPClause *> Clauses) { |
Benjamin Kramer | fc600dc | 2015-08-30 15:12:28 +0000 | [diff] [blame] | 4611 | auto OrderedClauses = |
| 4612 | OMPExecutableDirective::getClausesOfKind<OMPOrderedClause>(Clauses); |
| 4613 | if (OrderedClauses.begin() != OrderedClauses.end()) |
| 4614 | return (*OrderedClauses.begin())->getNumForLoops(); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4615 | return nullptr; |
| 4616 | } |
| 4617 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 4618 | static bool checkSimdlenSafelenValues(Sema &S, const Expr *Simdlen, |
| 4619 | const Expr *Safelen) { |
| 4620 | llvm::APSInt SimdlenRes, SafelenRes; |
| 4621 | if (Simdlen->isValueDependent() || Simdlen->isTypeDependent() || |
| 4622 | Simdlen->isInstantiationDependent() || |
| 4623 | Simdlen->containsUnexpandedParameterPack()) |
| 4624 | return false; |
| 4625 | if (Safelen->isValueDependent() || Safelen->isTypeDependent() || |
| 4626 | Safelen->isInstantiationDependent() || |
| 4627 | Safelen->containsUnexpandedParameterPack()) |
| 4628 | return false; |
| 4629 | Simdlen->EvaluateAsInt(SimdlenRes, S.Context); |
| 4630 | Safelen->EvaluateAsInt(SafelenRes, S.Context); |
| 4631 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 4632 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 4633 | // parameter must be less than or equal to the value of the safelen parameter. |
| 4634 | if (SimdlenRes > SafelenRes) { |
| 4635 | S.Diag(Simdlen->getExprLoc(), diag::err_omp_wrong_simdlen_safelen_values) |
| 4636 | << Simdlen->getSourceRange() << Safelen->getSourceRange(); |
| 4637 | return true; |
| 4638 | } |
| 4639 | return false; |
| 4640 | } |
| 4641 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4642 | StmtResult Sema::ActOnOpenMPSimdDirective( |
| 4643 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4644 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 4645 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4646 | if (!AStmt) |
| 4647 | return StmtError(); |
| 4648 | |
| 4649 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4650 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4651 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4652 | // define the nested loops number. |
| 4653 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 4654 | OMPD_simd, getCollapseNumberExpr(Clauses), getOrderedNumberExpr(Clauses), |
| 4655 | AStmt, *this, *DSAStack, VarsWithImplicitDSA, B); |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 4656 | if (NestedLoopCount == 0) |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 4657 | return StmtError(); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 4658 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4659 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 4660 | "omp simd loop exprs were not built"); |
| 4661 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 4662 | if (!CurContext->isDependentContext()) { |
| 4663 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4664 | for (auto C : Clauses) { |
| 4665 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 4666 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 4667 | B.NumIterations, *this, CurScope)) |
| 4668 | return StmtError(); |
| 4669 | } |
| 4670 | } |
| 4671 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 4672 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 4673 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 4674 | // parameter must be less than or equal to the value of the safelen parameter. |
| 4675 | OMPSafelenClause *Safelen = nullptr; |
| 4676 | OMPSimdlenClause *Simdlen = nullptr; |
| 4677 | for (auto *Clause : Clauses) { |
| 4678 | if (Clause->getClauseKind() == OMPC_safelen) |
| 4679 | Safelen = cast<OMPSafelenClause>(Clause); |
| 4680 | else if (Clause->getClauseKind() == OMPC_simdlen) |
| 4681 | Simdlen = cast<OMPSimdlenClause>(Clause); |
| 4682 | if (Safelen && Simdlen) |
| 4683 | break; |
| 4684 | } |
| 4685 | if (Simdlen && Safelen && |
| 4686 | checkSimdlenSafelenValues(*this, Simdlen->getSimdlen(), |
| 4687 | Safelen->getSafelen())) |
| 4688 | return StmtError(); |
| 4689 | |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 4690 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4691 | return OMPSimdDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| 4692 | Clauses, AStmt, B); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 4693 | } |
| 4694 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4695 | StmtResult Sema::ActOnOpenMPForDirective( |
| 4696 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4697 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 4698 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4699 | if (!AStmt) |
| 4700 | return StmtError(); |
| 4701 | |
| 4702 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4703 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4704 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4705 | // define the nested loops number. |
| 4706 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 4707 | OMPD_for, getCollapseNumberExpr(Clauses), getOrderedNumberExpr(Clauses), |
| 4708 | AStmt, *this, *DSAStack, VarsWithImplicitDSA, B); |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 4709 | if (NestedLoopCount == 0) |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4710 | return StmtError(); |
| 4711 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4712 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 4713 | "omp for loop exprs were not built"); |
| 4714 | |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 4715 | if (!CurContext->isDependentContext()) { |
| 4716 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4717 | for (auto C : Clauses) { |
| 4718 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 4719 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 4720 | B.NumIterations, *this, CurScope)) |
| 4721 | return StmtError(); |
| 4722 | } |
| 4723 | } |
| 4724 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4725 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4726 | return OMPForDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4727 | Clauses, AStmt, B, DSAStack->isCancelRegion()); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4728 | } |
| 4729 | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4730 | StmtResult Sema::ActOnOpenMPForSimdDirective( |
| 4731 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4732 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 4733 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4734 | if (!AStmt) |
| 4735 | return StmtError(); |
| 4736 | |
| 4737 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4738 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4739 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4740 | // define the nested loops number. |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4741 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4742 | CheckOpenMPLoop(OMPD_for_simd, getCollapseNumberExpr(Clauses), |
| 4743 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 4744 | VarsWithImplicitDSA, B); |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4745 | if (NestedLoopCount == 0) |
| 4746 | return StmtError(); |
| 4747 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4748 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 4749 | "omp for simd loop exprs were not built"); |
| 4750 | |
Alexey Bataev | 58e5bdb | 2015-06-18 04:45:29 +0000 | [diff] [blame] | 4751 | if (!CurContext->isDependentContext()) { |
| 4752 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4753 | for (auto C : Clauses) { |
| 4754 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 4755 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 4756 | B.NumIterations, *this, CurScope)) |
| 4757 | return StmtError(); |
| 4758 | } |
| 4759 | } |
| 4760 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 4761 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 4762 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 4763 | // parameter must be less than or equal to the value of the safelen parameter. |
| 4764 | OMPSafelenClause *Safelen = nullptr; |
| 4765 | OMPSimdlenClause *Simdlen = nullptr; |
| 4766 | for (auto *Clause : Clauses) { |
| 4767 | if (Clause->getClauseKind() == OMPC_safelen) |
| 4768 | Safelen = cast<OMPSafelenClause>(Clause); |
| 4769 | else if (Clause->getClauseKind() == OMPC_simdlen) |
| 4770 | Simdlen = cast<OMPSimdlenClause>(Clause); |
| 4771 | if (Safelen && Simdlen) |
| 4772 | break; |
| 4773 | } |
| 4774 | if (Simdlen && Safelen && |
| 4775 | checkSimdlenSafelenValues(*this, Simdlen->getSimdlen(), |
| 4776 | Safelen->getSafelen())) |
| 4777 | return StmtError(); |
| 4778 | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4779 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4780 | return OMPForSimdDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| 4781 | Clauses, AStmt, B); |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4782 | } |
| 4783 | |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4784 | StmtResult Sema::ActOnOpenMPSectionsDirective(ArrayRef<OMPClause *> Clauses, |
| 4785 | Stmt *AStmt, |
| 4786 | SourceLocation StartLoc, |
| 4787 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4788 | if (!AStmt) |
| 4789 | return StmtError(); |
| 4790 | |
| 4791 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4792 | auto BaseStmt = AStmt; |
| 4793 | while (CapturedStmt *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt)) |
| 4794 | BaseStmt = CS->getCapturedStmt(); |
| 4795 | if (auto C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) { |
| 4796 | auto S = C->children(); |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 4797 | if (S.begin() == S.end()) |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4798 | return StmtError(); |
| 4799 | // All associated statements must be '#pragma omp section' except for |
| 4800 | // the first one. |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 4801 | for (Stmt *SectionStmt : llvm::make_range(std::next(S.begin()), S.end())) { |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4802 | if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) { |
| 4803 | if (SectionStmt) |
| 4804 | Diag(SectionStmt->getLocStart(), |
| 4805 | diag::err_omp_sections_substmt_not_section); |
| 4806 | return StmtError(); |
| 4807 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4808 | cast<OMPSectionDirective>(SectionStmt) |
| 4809 | ->setHasCancel(DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4810 | } |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4811 | } else { |
| 4812 | Diag(AStmt->getLocStart(), diag::err_omp_sections_not_compound_stmt); |
| 4813 | return StmtError(); |
| 4814 | } |
| 4815 | |
| 4816 | getCurFunction()->setHasBranchProtectedScope(); |
| 4817 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4818 | return OMPSectionsDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 4819 | DSAStack->isCancelRegion()); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4820 | } |
| 4821 | |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4822 | StmtResult Sema::ActOnOpenMPSectionDirective(Stmt *AStmt, |
| 4823 | SourceLocation StartLoc, |
| 4824 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4825 | if (!AStmt) |
| 4826 | return StmtError(); |
| 4827 | |
| 4828 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4829 | |
| 4830 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4831 | DSAStack->setParentCancelRegion(DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4832 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4833 | return OMPSectionDirective::Create(Context, StartLoc, EndLoc, AStmt, |
| 4834 | DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4835 | } |
| 4836 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 4837 | StmtResult Sema::ActOnOpenMPSingleDirective(ArrayRef<OMPClause *> Clauses, |
| 4838 | Stmt *AStmt, |
| 4839 | SourceLocation StartLoc, |
| 4840 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4841 | if (!AStmt) |
| 4842 | return StmtError(); |
| 4843 | |
| 4844 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 74a05c9 | 2014-07-15 02:55:09 +0000 | [diff] [blame] | 4845 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 4846 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | 74a05c9 | 2014-07-15 02:55:09 +0000 | [diff] [blame] | 4847 | |
Alexey Bataev | 3255bf3 | 2015-01-19 05:20:46 +0000 | [diff] [blame] | 4848 | // OpenMP [2.7.3, single Construct, Restrictions] |
| 4849 | // The copyprivate clause must not be used with the nowait clause. |
| 4850 | OMPClause *Nowait = nullptr; |
| 4851 | OMPClause *Copyprivate = nullptr; |
| 4852 | for (auto *Clause : Clauses) { |
| 4853 | if (Clause->getClauseKind() == OMPC_nowait) |
| 4854 | Nowait = Clause; |
| 4855 | else if (Clause->getClauseKind() == OMPC_copyprivate) |
| 4856 | Copyprivate = Clause; |
| 4857 | if (Copyprivate && Nowait) { |
| 4858 | Diag(Copyprivate->getLocStart(), |
| 4859 | diag::err_omp_single_copyprivate_with_nowait); |
| 4860 | Diag(Nowait->getLocStart(), diag::note_omp_nowait_clause_here); |
| 4861 | return StmtError(); |
| 4862 | } |
| 4863 | } |
| 4864 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 4865 | return OMPSingleDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 4866 | } |
| 4867 | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 4868 | StmtResult Sema::ActOnOpenMPMasterDirective(Stmt *AStmt, |
| 4869 | SourceLocation StartLoc, |
| 4870 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4871 | if (!AStmt) |
| 4872 | return StmtError(); |
| 4873 | |
| 4874 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 4875 | |
| 4876 | getCurFunction()->setHasBranchProtectedScope(); |
| 4877 | |
| 4878 | return OMPMasterDirective::Create(Context, StartLoc, EndLoc, AStmt); |
| 4879 | } |
| 4880 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 4881 | StmtResult Sema::ActOnOpenMPCriticalDirective( |
| 4882 | const DeclarationNameInfo &DirName, ArrayRef<OMPClause *> Clauses, |
| 4883 | Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4884 | if (!AStmt) |
| 4885 | return StmtError(); |
| 4886 | |
| 4887 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 4888 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 4889 | bool ErrorFound = false; |
| 4890 | llvm::APSInt Hint; |
| 4891 | SourceLocation HintLoc; |
| 4892 | bool DependentHint = false; |
| 4893 | for (auto *C : Clauses) { |
| 4894 | if (C->getClauseKind() == OMPC_hint) { |
| 4895 | if (!DirName.getName()) { |
| 4896 | Diag(C->getLocStart(), diag::err_omp_hint_clause_no_name); |
| 4897 | ErrorFound = true; |
| 4898 | } |
| 4899 | Expr *E = cast<OMPHintClause>(C)->getHint(); |
| 4900 | if (E->isTypeDependent() || E->isValueDependent() || |
| 4901 | E->isInstantiationDependent()) |
| 4902 | DependentHint = true; |
| 4903 | else { |
| 4904 | Hint = E->EvaluateKnownConstInt(Context); |
| 4905 | HintLoc = C->getLocStart(); |
| 4906 | } |
| 4907 | } |
| 4908 | } |
| 4909 | if (ErrorFound) |
| 4910 | return StmtError(); |
| 4911 | auto Pair = DSAStack->getCriticalWithHint(DirName); |
| 4912 | if (Pair.first && DirName.getName() && !DependentHint) { |
| 4913 | if (llvm::APSInt::compareValues(Hint, Pair.second) != 0) { |
| 4914 | Diag(StartLoc, diag::err_omp_critical_with_hint); |
| 4915 | if (HintLoc.isValid()) { |
| 4916 | Diag(HintLoc, diag::note_omp_critical_hint_here) |
| 4917 | << 0 << Hint.toString(/*Radix=*/10, /*Signed=*/false); |
| 4918 | } else |
| 4919 | Diag(StartLoc, diag::note_omp_critical_no_hint) << 0; |
| 4920 | if (auto *C = Pair.first->getSingleClause<OMPHintClause>()) { |
| 4921 | Diag(C->getLocStart(), diag::note_omp_critical_hint_here) |
| 4922 | << 1 |
| 4923 | << C->getHint()->EvaluateKnownConstInt(Context).toString( |
| 4924 | /*Radix=*/10, /*Signed=*/false); |
| 4925 | } else |
| 4926 | Diag(Pair.first->getLocStart(), diag::note_omp_critical_no_hint) << 1; |
| 4927 | } |
| 4928 | } |
| 4929 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 4930 | getCurFunction()->setHasBranchProtectedScope(); |
| 4931 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 4932 | auto *Dir = OMPCriticalDirective::Create(Context, DirName, StartLoc, EndLoc, |
| 4933 | Clauses, AStmt); |
| 4934 | if (!Pair.first && DirName.getName() && !DependentHint) |
| 4935 | DSAStack->addCriticalWithHint(Dir, Hint); |
| 4936 | return Dir; |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 4937 | } |
| 4938 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4939 | StmtResult Sema::ActOnOpenMPParallelForDirective( |
| 4940 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4941 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 4942 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4943 | if (!AStmt) |
| 4944 | return StmtError(); |
| 4945 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4946 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 4947 | // 1.2.2 OpenMP Language Terminology |
| 4948 | // Structured block - An executable statement with a single entry at the |
| 4949 | // top and a single exit at the bottom. |
| 4950 | // The point of exit cannot be a branch out of the structured block. |
| 4951 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 4952 | CS->getCapturedDecl()->setNothrow(); |
| 4953 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4954 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4955 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4956 | // define the nested loops number. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4957 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4958 | CheckOpenMPLoop(OMPD_parallel_for, getCollapseNumberExpr(Clauses), |
| 4959 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 4960 | VarsWithImplicitDSA, B); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4961 | if (NestedLoopCount == 0) |
| 4962 | return StmtError(); |
| 4963 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4964 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 4965 | "omp parallel for loop exprs were not built"); |
| 4966 | |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 4967 | if (!CurContext->isDependentContext()) { |
| 4968 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4969 | for (auto C : Clauses) { |
| 4970 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 4971 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 4972 | B.NumIterations, *this, CurScope)) |
| 4973 | return StmtError(); |
| 4974 | } |
| 4975 | } |
| 4976 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4977 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4978 | return OMPParallelForDirective::Create(Context, StartLoc, EndLoc, |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4979 | NestedLoopCount, Clauses, AStmt, B, |
| 4980 | DSAStack->isCancelRegion()); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4981 | } |
| 4982 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4983 | StmtResult Sema::ActOnOpenMPParallelForSimdDirective( |
| 4984 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4985 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 4986 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4987 | if (!AStmt) |
| 4988 | return StmtError(); |
| 4989 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4990 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 4991 | // 1.2.2 OpenMP Language Terminology |
| 4992 | // Structured block - An executable statement with a single entry at the |
| 4993 | // top and a single exit at the bottom. |
| 4994 | // The point of exit cannot be a branch out of the structured block. |
| 4995 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 4996 | CS->getCapturedDecl()->setNothrow(); |
| 4997 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4998 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4999 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 5000 | // define the nested loops number. |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 5001 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5002 | CheckOpenMPLoop(OMPD_parallel_for_simd, getCollapseNumberExpr(Clauses), |
| 5003 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 5004 | VarsWithImplicitDSA, B); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 5005 | if (NestedLoopCount == 0) |
| 5006 | return StmtError(); |
| 5007 | |
Alexey Bataev | 3b5b5c4 | 2015-06-18 10:10:12 +0000 | [diff] [blame] | 5008 | if (!CurContext->isDependentContext()) { |
| 5009 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 5010 | for (auto C : Clauses) { |
| 5011 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 5012 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 5013 | B.NumIterations, *this, CurScope)) |
| 5014 | return StmtError(); |
| 5015 | } |
| 5016 | } |
| 5017 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 5018 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 5019 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 5020 | // parameter must be less than or equal to the value of the safelen parameter. |
| 5021 | OMPSafelenClause *Safelen = nullptr; |
| 5022 | OMPSimdlenClause *Simdlen = nullptr; |
| 5023 | for (auto *Clause : Clauses) { |
| 5024 | if (Clause->getClauseKind() == OMPC_safelen) |
| 5025 | Safelen = cast<OMPSafelenClause>(Clause); |
| 5026 | else if (Clause->getClauseKind() == OMPC_simdlen) |
| 5027 | Simdlen = cast<OMPSimdlenClause>(Clause); |
| 5028 | if (Safelen && Simdlen) |
| 5029 | break; |
| 5030 | } |
| 5031 | if (Simdlen && Safelen && |
| 5032 | checkSimdlenSafelenValues(*this, Simdlen->getSimdlen(), |
| 5033 | Safelen->getSafelen())) |
| 5034 | return StmtError(); |
| 5035 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 5036 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5037 | return OMPParallelForSimdDirective::Create( |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5038 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 5039 | } |
| 5040 | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 5041 | StmtResult |
| 5042 | Sema::ActOnOpenMPParallelSectionsDirective(ArrayRef<OMPClause *> Clauses, |
| 5043 | Stmt *AStmt, SourceLocation StartLoc, |
| 5044 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5045 | if (!AStmt) |
| 5046 | return StmtError(); |
| 5047 | |
| 5048 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 5049 | auto BaseStmt = AStmt; |
| 5050 | while (CapturedStmt *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt)) |
| 5051 | BaseStmt = CS->getCapturedStmt(); |
| 5052 | if (auto C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) { |
| 5053 | auto S = C->children(); |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 5054 | if (S.begin() == S.end()) |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 5055 | return StmtError(); |
| 5056 | // All associated statements must be '#pragma omp section' except for |
| 5057 | // the first one. |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 5058 | for (Stmt *SectionStmt : llvm::make_range(std::next(S.begin()), S.end())) { |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 5059 | if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) { |
| 5060 | if (SectionStmt) |
| 5061 | Diag(SectionStmt->getLocStart(), |
| 5062 | diag::err_omp_parallel_sections_substmt_not_section); |
| 5063 | return StmtError(); |
| 5064 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 5065 | cast<OMPSectionDirective>(SectionStmt) |
| 5066 | ->setHasCancel(DSAStack->isCancelRegion()); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 5067 | } |
| 5068 | } else { |
| 5069 | Diag(AStmt->getLocStart(), |
| 5070 | diag::err_omp_parallel_sections_not_compound_stmt); |
| 5071 | return StmtError(); |
| 5072 | } |
| 5073 | |
| 5074 | getCurFunction()->setHasBranchProtectedScope(); |
| 5075 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 5076 | return OMPParallelSectionsDirective::Create( |
| 5077 | Context, StartLoc, EndLoc, Clauses, AStmt, DSAStack->isCancelRegion()); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 5078 | } |
| 5079 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5080 | StmtResult Sema::ActOnOpenMPTaskDirective(ArrayRef<OMPClause *> Clauses, |
| 5081 | Stmt *AStmt, SourceLocation StartLoc, |
| 5082 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5083 | if (!AStmt) |
| 5084 | return StmtError(); |
| 5085 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5086 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 5087 | // 1.2.2 OpenMP Language Terminology |
| 5088 | // Structured block - An executable statement with a single entry at the |
| 5089 | // top and a single exit at the bottom. |
| 5090 | // The point of exit cannot be a branch out of the structured block. |
| 5091 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5092 | CS->getCapturedDecl()->setNothrow(); |
| 5093 | |
| 5094 | getCurFunction()->setHasBranchProtectedScope(); |
| 5095 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 5096 | return OMPTaskDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 5097 | DSAStack->isCancelRegion()); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5098 | } |
| 5099 | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 5100 | StmtResult Sema::ActOnOpenMPTaskyieldDirective(SourceLocation StartLoc, |
| 5101 | SourceLocation EndLoc) { |
| 5102 | return OMPTaskyieldDirective::Create(Context, StartLoc, EndLoc); |
| 5103 | } |
| 5104 | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 5105 | StmtResult Sema::ActOnOpenMPBarrierDirective(SourceLocation StartLoc, |
| 5106 | SourceLocation EndLoc) { |
| 5107 | return OMPBarrierDirective::Create(Context, StartLoc, EndLoc); |
| 5108 | } |
| 5109 | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 5110 | StmtResult Sema::ActOnOpenMPTaskwaitDirective(SourceLocation StartLoc, |
| 5111 | SourceLocation EndLoc) { |
| 5112 | return OMPTaskwaitDirective::Create(Context, StartLoc, EndLoc); |
| 5113 | } |
| 5114 | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 5115 | StmtResult Sema::ActOnOpenMPTaskgroupDirective(Stmt *AStmt, |
| 5116 | SourceLocation StartLoc, |
| 5117 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5118 | if (!AStmt) |
| 5119 | return StmtError(); |
| 5120 | |
| 5121 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 5122 | |
| 5123 | getCurFunction()->setHasBranchProtectedScope(); |
| 5124 | |
| 5125 | return OMPTaskgroupDirective::Create(Context, StartLoc, EndLoc, AStmt); |
| 5126 | } |
| 5127 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 5128 | StmtResult Sema::ActOnOpenMPFlushDirective(ArrayRef<OMPClause *> Clauses, |
| 5129 | SourceLocation StartLoc, |
| 5130 | SourceLocation EndLoc) { |
| 5131 | assert(Clauses.size() <= 1 && "Extra clauses in flush directive"); |
| 5132 | return OMPFlushDirective::Create(Context, StartLoc, EndLoc, Clauses); |
| 5133 | } |
| 5134 | |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5135 | StmtResult Sema::ActOnOpenMPOrderedDirective(ArrayRef<OMPClause *> Clauses, |
| 5136 | Stmt *AStmt, |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 5137 | SourceLocation StartLoc, |
| 5138 | SourceLocation EndLoc) { |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5139 | OMPClause *DependFound = nullptr; |
| 5140 | OMPClause *DependSourceClause = nullptr; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 5141 | OMPClause *DependSinkClause = nullptr; |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5142 | bool ErrorFound = false; |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5143 | OMPThreadsClause *TC = nullptr; |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5144 | OMPSIMDClause *SC = nullptr; |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5145 | for (auto *C : Clauses) { |
| 5146 | if (auto *DC = dyn_cast<OMPDependClause>(C)) { |
| 5147 | DependFound = C; |
| 5148 | if (DC->getDependencyKind() == OMPC_DEPEND_source) { |
| 5149 | if (DependSourceClause) { |
| 5150 | Diag(C->getLocStart(), diag::err_omp_more_one_clause) |
| 5151 | << getOpenMPDirectiveName(OMPD_ordered) |
| 5152 | << getOpenMPClauseName(OMPC_depend) << 2; |
| 5153 | ErrorFound = true; |
| 5154 | } else |
| 5155 | DependSourceClause = C; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 5156 | if (DependSinkClause) { |
| 5157 | Diag(C->getLocStart(), diag::err_omp_depend_sink_source_not_allowed) |
| 5158 | << 0; |
| 5159 | ErrorFound = true; |
| 5160 | } |
| 5161 | } else if (DC->getDependencyKind() == OMPC_DEPEND_sink) { |
| 5162 | if (DependSourceClause) { |
| 5163 | Diag(C->getLocStart(), diag::err_omp_depend_sink_source_not_allowed) |
| 5164 | << 1; |
| 5165 | ErrorFound = true; |
| 5166 | } |
| 5167 | DependSinkClause = C; |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5168 | } |
| 5169 | } else if (C->getClauseKind() == OMPC_threads) |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5170 | TC = cast<OMPThreadsClause>(C); |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5171 | else if (C->getClauseKind() == OMPC_simd) |
| 5172 | SC = cast<OMPSIMDClause>(C); |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5173 | } |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5174 | if (!ErrorFound && !SC && |
| 5175 | isOpenMPSimdDirective(DSAStack->getParentDirective())) { |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5176 | // OpenMP [2.8.1,simd Construct, Restrictions] |
| 5177 | // An ordered construct with the simd clause is the only OpenMP construct |
| 5178 | // that can appear in the simd region. |
| 5179 | Diag(StartLoc, diag::err_omp_prohibited_region_simd); |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5180 | ErrorFound = true; |
| 5181 | } else if (DependFound && (TC || SC)) { |
| 5182 | Diag(DependFound->getLocStart(), diag::err_omp_depend_clause_thread_simd) |
| 5183 | << getOpenMPClauseName(TC ? TC->getClauseKind() : SC->getClauseKind()); |
| 5184 | ErrorFound = true; |
| 5185 | } else if (DependFound && !DSAStack->getParentOrderedRegionParam()) { |
| 5186 | Diag(DependFound->getLocStart(), |
| 5187 | diag::err_omp_ordered_directive_without_param); |
| 5188 | ErrorFound = true; |
| 5189 | } else if (TC || Clauses.empty()) { |
| 5190 | if (auto *Param = DSAStack->getParentOrderedRegionParam()) { |
| 5191 | SourceLocation ErrLoc = TC ? TC->getLocStart() : StartLoc; |
| 5192 | Diag(ErrLoc, diag::err_omp_ordered_directive_with_param) |
| 5193 | << (TC != nullptr); |
| 5194 | Diag(Param->getLocStart(), diag::note_omp_ordered_param); |
| 5195 | ErrorFound = true; |
| 5196 | } |
| 5197 | } |
| 5198 | if ((!AStmt && !DependFound) || ErrorFound) |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5199 | return StmtError(); |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5200 | |
| 5201 | if (AStmt) { |
| 5202 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 5203 | |
| 5204 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5205 | } |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5206 | |
| 5207 | return OMPOrderedDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 5208 | } |
| 5209 | |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5210 | namespace { |
| 5211 | /// \brief Helper class for checking expression in 'omp atomic [update]' |
| 5212 | /// construct. |
| 5213 | class OpenMPAtomicUpdateChecker { |
| 5214 | /// \brief Error results for atomic update expressions. |
| 5215 | enum ExprAnalysisErrorCode { |
| 5216 | /// \brief A statement is not an expression statement. |
| 5217 | NotAnExpression, |
| 5218 | /// \brief Expression is not builtin binary or unary operation. |
| 5219 | NotABinaryOrUnaryExpression, |
| 5220 | /// \brief Unary operation is not post-/pre- increment/decrement operation. |
| 5221 | NotAnUnaryIncDecExpression, |
| 5222 | /// \brief An expression is not of scalar type. |
| 5223 | NotAScalarType, |
| 5224 | /// \brief A binary operation is not an assignment operation. |
| 5225 | NotAnAssignmentOp, |
| 5226 | /// \brief RHS part of the binary operation is not a binary expression. |
| 5227 | NotABinaryExpression, |
| 5228 | /// \brief RHS part is not additive/multiplicative/shift/biwise binary |
| 5229 | /// expression. |
| 5230 | NotABinaryOperator, |
| 5231 | /// \brief RHS binary operation does not have reference to the updated LHS |
| 5232 | /// part. |
| 5233 | NotAnUpdateExpression, |
| 5234 | /// \brief No errors is found. |
| 5235 | NoError |
| 5236 | }; |
| 5237 | /// \brief Reference to Sema. |
| 5238 | Sema &SemaRef; |
| 5239 | /// \brief A location for note diagnostics (when error is found). |
| 5240 | SourceLocation NoteLoc; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5241 | /// \brief 'x' lvalue part of the source atomic expression. |
| 5242 | Expr *X; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5243 | /// \brief 'expr' rvalue part of the source atomic expression. |
| 5244 | Expr *E; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5245 | /// \brief Helper expression of the form |
| 5246 | /// 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or |
| 5247 | /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'. |
| 5248 | Expr *UpdateExpr; |
| 5249 | /// \brief Is 'x' a LHS in a RHS part of full update expression. It is |
| 5250 | /// important for non-associative operations. |
| 5251 | bool IsXLHSInRHSPart; |
| 5252 | BinaryOperatorKind Op; |
| 5253 | SourceLocation OpLoc; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5254 | /// \brief true if the source expression is a postfix unary operation, false |
| 5255 | /// if it is a prefix unary operation. |
| 5256 | bool IsPostfixUpdate; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5257 | |
| 5258 | public: |
| 5259 | OpenMPAtomicUpdateChecker(Sema &SemaRef) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5260 | : SemaRef(SemaRef), X(nullptr), E(nullptr), UpdateExpr(nullptr), |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5261 | IsXLHSInRHSPart(false), Op(BO_PtrMemD), IsPostfixUpdate(false) {} |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5262 | /// \brief Check specified statement that it is suitable for 'atomic update' |
| 5263 | /// constructs and extract 'x', 'expr' and Operation from the original |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5264 | /// expression. If DiagId and NoteId == 0, then only check is performed |
| 5265 | /// without error notification. |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5266 | /// \param DiagId Diagnostic which should be emitted if error is found. |
| 5267 | /// \param NoteId Diagnostic note for the main error message. |
| 5268 | /// \return true if statement is not an update expression, false otherwise. |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5269 | bool checkStatement(Stmt *S, unsigned DiagId = 0, unsigned NoteId = 0); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5270 | /// \brief Return the 'x' lvalue part of the source atomic expression. |
| 5271 | Expr *getX() const { return X; } |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5272 | /// \brief Return the 'expr' rvalue part of the source atomic expression. |
| 5273 | Expr *getExpr() const { return E; } |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5274 | /// \brief Return the update expression used in calculation of the updated |
| 5275 | /// value. Always has form 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or |
| 5276 | /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'. |
| 5277 | Expr *getUpdateExpr() const { return UpdateExpr; } |
| 5278 | /// \brief Return true if 'x' is LHS in RHS part of full update expression, |
| 5279 | /// false otherwise. |
| 5280 | bool isXLHSInRHSPart() const { return IsXLHSInRHSPart; } |
| 5281 | |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5282 | /// \brief true if the source expression is a postfix unary operation, false |
| 5283 | /// if it is a prefix unary operation. |
| 5284 | bool isPostfixUpdate() const { return IsPostfixUpdate; } |
| 5285 | |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5286 | private: |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5287 | bool checkBinaryOperation(BinaryOperator *AtomicBinOp, unsigned DiagId = 0, |
| 5288 | unsigned NoteId = 0); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5289 | }; |
| 5290 | } // namespace |
| 5291 | |
| 5292 | bool OpenMPAtomicUpdateChecker::checkBinaryOperation( |
| 5293 | BinaryOperator *AtomicBinOp, unsigned DiagId, unsigned NoteId) { |
| 5294 | ExprAnalysisErrorCode ErrorFound = NoError; |
| 5295 | SourceLocation ErrorLoc, NoteLoc; |
| 5296 | SourceRange ErrorRange, NoteRange; |
| 5297 | // Allowed constructs are: |
| 5298 | // x = x binop expr; |
| 5299 | // x = expr binop x; |
| 5300 | if (AtomicBinOp->getOpcode() == BO_Assign) { |
| 5301 | X = AtomicBinOp->getLHS(); |
| 5302 | if (auto *AtomicInnerBinOp = dyn_cast<BinaryOperator>( |
| 5303 | AtomicBinOp->getRHS()->IgnoreParenImpCasts())) { |
| 5304 | if (AtomicInnerBinOp->isMultiplicativeOp() || |
| 5305 | AtomicInnerBinOp->isAdditiveOp() || AtomicInnerBinOp->isShiftOp() || |
| 5306 | AtomicInnerBinOp->isBitwiseOp()) { |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5307 | Op = AtomicInnerBinOp->getOpcode(); |
| 5308 | OpLoc = AtomicInnerBinOp->getOperatorLoc(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5309 | auto *LHS = AtomicInnerBinOp->getLHS(); |
| 5310 | auto *RHS = AtomicInnerBinOp->getRHS(); |
| 5311 | llvm::FoldingSetNodeID XId, LHSId, RHSId; |
| 5312 | X->IgnoreParenImpCasts()->Profile(XId, SemaRef.getASTContext(), |
| 5313 | /*Canonical=*/true); |
| 5314 | LHS->IgnoreParenImpCasts()->Profile(LHSId, SemaRef.getASTContext(), |
| 5315 | /*Canonical=*/true); |
| 5316 | RHS->IgnoreParenImpCasts()->Profile(RHSId, SemaRef.getASTContext(), |
| 5317 | /*Canonical=*/true); |
| 5318 | if (XId == LHSId) { |
| 5319 | E = RHS; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5320 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5321 | } else if (XId == RHSId) { |
| 5322 | E = LHS; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5323 | IsXLHSInRHSPart = false; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5324 | } else { |
| 5325 | ErrorLoc = AtomicInnerBinOp->getExprLoc(); |
| 5326 | ErrorRange = AtomicInnerBinOp->getSourceRange(); |
| 5327 | NoteLoc = X->getExprLoc(); |
| 5328 | NoteRange = X->getSourceRange(); |
| 5329 | ErrorFound = NotAnUpdateExpression; |
| 5330 | } |
| 5331 | } else { |
| 5332 | ErrorLoc = AtomicInnerBinOp->getExprLoc(); |
| 5333 | ErrorRange = AtomicInnerBinOp->getSourceRange(); |
| 5334 | NoteLoc = AtomicInnerBinOp->getOperatorLoc(); |
| 5335 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 5336 | ErrorFound = NotABinaryOperator; |
| 5337 | } |
| 5338 | } else { |
| 5339 | NoteLoc = ErrorLoc = AtomicBinOp->getRHS()->getExprLoc(); |
| 5340 | NoteRange = ErrorRange = AtomicBinOp->getRHS()->getSourceRange(); |
| 5341 | ErrorFound = NotABinaryExpression; |
| 5342 | } |
| 5343 | } else { |
| 5344 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5345 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5346 | NoteLoc = AtomicBinOp->getOperatorLoc(); |
| 5347 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 5348 | ErrorFound = NotAnAssignmentOp; |
| 5349 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5350 | if (ErrorFound != NoError && DiagId != 0 && NoteId != 0) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5351 | SemaRef.Diag(ErrorLoc, DiagId) << ErrorRange; |
| 5352 | SemaRef.Diag(NoteLoc, NoteId) << ErrorFound << NoteRange; |
| 5353 | return true; |
| 5354 | } else if (SemaRef.CurContext->isDependentContext()) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5355 | E = X = UpdateExpr = nullptr; |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5356 | return ErrorFound != NoError; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5357 | } |
| 5358 | |
| 5359 | bool OpenMPAtomicUpdateChecker::checkStatement(Stmt *S, unsigned DiagId, |
| 5360 | unsigned NoteId) { |
| 5361 | ExprAnalysisErrorCode ErrorFound = NoError; |
| 5362 | SourceLocation ErrorLoc, NoteLoc; |
| 5363 | SourceRange ErrorRange, NoteRange; |
| 5364 | // Allowed constructs are: |
| 5365 | // x++; |
| 5366 | // x--; |
| 5367 | // ++x; |
| 5368 | // --x; |
| 5369 | // x binop= expr; |
| 5370 | // x = x binop expr; |
| 5371 | // x = expr binop x; |
| 5372 | if (auto *AtomicBody = dyn_cast<Expr>(S)) { |
| 5373 | AtomicBody = AtomicBody->IgnoreParenImpCasts(); |
| 5374 | if (AtomicBody->getType()->isScalarType() || |
| 5375 | AtomicBody->isInstantiationDependent()) { |
| 5376 | if (auto *AtomicCompAssignOp = dyn_cast<CompoundAssignOperator>( |
| 5377 | AtomicBody->IgnoreParenImpCasts())) { |
| 5378 | // Check for Compound Assignment Operation |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5379 | Op = BinaryOperator::getOpForCompoundAssignment( |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5380 | AtomicCompAssignOp->getOpcode()); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5381 | OpLoc = AtomicCompAssignOp->getOperatorLoc(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5382 | E = AtomicCompAssignOp->getRHS(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5383 | X = AtomicCompAssignOp->getLHS(); |
| 5384 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5385 | } else if (auto *AtomicBinOp = dyn_cast<BinaryOperator>( |
| 5386 | AtomicBody->IgnoreParenImpCasts())) { |
| 5387 | // Check for Binary Operation |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5388 | if(checkBinaryOperation(AtomicBinOp, DiagId, NoteId)) |
| 5389 | return true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5390 | } else if (auto *AtomicUnaryOp = |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5391 | dyn_cast<UnaryOperator>(AtomicBody->IgnoreParenImpCasts())) { |
| 5392 | // Check for Unary Operation |
| 5393 | if (AtomicUnaryOp->isIncrementDecrementOp()) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5394 | IsPostfixUpdate = AtomicUnaryOp->isPostfix(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5395 | Op = AtomicUnaryOp->isIncrementOp() ? BO_Add : BO_Sub; |
| 5396 | OpLoc = AtomicUnaryOp->getOperatorLoc(); |
| 5397 | X = AtomicUnaryOp->getSubExpr(); |
| 5398 | E = SemaRef.ActOnIntegerConstant(OpLoc, /*uint64_t Val=*/1).get(); |
| 5399 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5400 | } else { |
| 5401 | ErrorFound = NotAnUnaryIncDecExpression; |
| 5402 | ErrorLoc = AtomicUnaryOp->getExprLoc(); |
| 5403 | ErrorRange = AtomicUnaryOp->getSourceRange(); |
| 5404 | NoteLoc = AtomicUnaryOp->getOperatorLoc(); |
| 5405 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 5406 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5407 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5408 | ErrorFound = NotABinaryOrUnaryExpression; |
| 5409 | NoteLoc = ErrorLoc = AtomicBody->getExprLoc(); |
| 5410 | NoteRange = ErrorRange = AtomicBody->getSourceRange(); |
| 5411 | } |
| 5412 | } else { |
| 5413 | ErrorFound = NotAScalarType; |
| 5414 | NoteLoc = ErrorLoc = AtomicBody->getLocStart(); |
| 5415 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
| 5416 | } |
| 5417 | } else { |
| 5418 | ErrorFound = NotAnExpression; |
| 5419 | NoteLoc = ErrorLoc = S->getLocStart(); |
| 5420 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
| 5421 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5422 | if (ErrorFound != NoError && DiagId != 0 && NoteId != 0) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5423 | SemaRef.Diag(ErrorLoc, DiagId) << ErrorRange; |
| 5424 | SemaRef.Diag(NoteLoc, NoteId) << ErrorFound << NoteRange; |
| 5425 | return true; |
| 5426 | } else if (SemaRef.CurContext->isDependentContext()) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5427 | E = X = UpdateExpr = nullptr; |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5428 | if (ErrorFound == NoError && E && X) { |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5429 | // Build an update expression of form 'OpaqueValueExpr(x) binop |
| 5430 | // OpaqueValueExpr(expr)' or 'OpaqueValueExpr(expr) binop |
| 5431 | // OpaqueValueExpr(x)' and then cast it to the type of the 'x' expression. |
| 5432 | auto *OVEX = new (SemaRef.getASTContext()) |
| 5433 | OpaqueValueExpr(X->getExprLoc(), X->getType(), VK_RValue); |
| 5434 | auto *OVEExpr = new (SemaRef.getASTContext()) |
| 5435 | OpaqueValueExpr(E->getExprLoc(), E->getType(), VK_RValue); |
| 5436 | auto Update = |
| 5437 | SemaRef.CreateBuiltinBinOp(OpLoc, Op, IsXLHSInRHSPart ? OVEX : OVEExpr, |
| 5438 | IsXLHSInRHSPart ? OVEExpr : OVEX); |
| 5439 | if (Update.isInvalid()) |
| 5440 | return true; |
| 5441 | Update = SemaRef.PerformImplicitConversion(Update.get(), X->getType(), |
| 5442 | Sema::AA_Casting); |
| 5443 | if (Update.isInvalid()) |
| 5444 | return true; |
| 5445 | UpdateExpr = Update.get(); |
| 5446 | } |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5447 | return ErrorFound != NoError; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5448 | } |
| 5449 | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 5450 | StmtResult Sema::ActOnOpenMPAtomicDirective(ArrayRef<OMPClause *> Clauses, |
| 5451 | Stmt *AStmt, |
| 5452 | SourceLocation StartLoc, |
| 5453 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5454 | if (!AStmt) |
| 5455 | return StmtError(); |
| 5456 | |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5457 | auto CS = cast<CapturedStmt>(AStmt); |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 5458 | // 1.2.2 OpenMP Language Terminology |
| 5459 | // Structured block - An executable statement with a single entry at the |
| 5460 | // top and a single exit at the bottom. |
| 5461 | // The point of exit cannot be a branch out of the structured block. |
| 5462 | // longjmp() and throw() must not violate the entry/exit criteria. |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5463 | OpenMPClauseKind AtomicKind = OMPC_unknown; |
| 5464 | SourceLocation AtomicKindLoc; |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5465 | for (auto *C : Clauses) { |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5466 | if (C->getClauseKind() == OMPC_read || C->getClauseKind() == OMPC_write || |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5467 | C->getClauseKind() == OMPC_update || |
| 5468 | C->getClauseKind() == OMPC_capture) { |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5469 | if (AtomicKind != OMPC_unknown) { |
| 5470 | Diag(C->getLocStart(), diag::err_omp_atomic_several_clauses) |
| 5471 | << SourceRange(C->getLocStart(), C->getLocEnd()); |
| 5472 | Diag(AtomicKindLoc, diag::note_omp_atomic_previous_clause) |
| 5473 | << getOpenMPClauseName(AtomicKind); |
| 5474 | } else { |
| 5475 | AtomicKind = C->getClauseKind(); |
| 5476 | AtomicKindLoc = C->getLocStart(); |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5477 | } |
| 5478 | } |
| 5479 | } |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5480 | |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5481 | auto Body = CS->getCapturedStmt(); |
Alexey Bataev | 10fec57 | 2015-03-11 04:48:56 +0000 | [diff] [blame] | 5482 | if (auto *EWC = dyn_cast<ExprWithCleanups>(Body)) |
| 5483 | Body = EWC->getSubExpr(); |
| 5484 | |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5485 | Expr *X = nullptr; |
| 5486 | Expr *V = nullptr; |
| 5487 | Expr *E = nullptr; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5488 | Expr *UE = nullptr; |
| 5489 | bool IsXLHSInRHSPart = false; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5490 | bool IsPostfixUpdate = false; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5491 | // OpenMP [2.12.6, atomic Construct] |
| 5492 | // In the next expressions: |
| 5493 | // * x and v (as applicable) are both l-value expressions with scalar type. |
| 5494 | // * During the execution of an atomic region, multiple syntactic |
| 5495 | // occurrences of x must designate the same storage location. |
| 5496 | // * Neither of v and expr (as applicable) may access the storage location |
| 5497 | // designated by x. |
| 5498 | // * Neither of x and expr (as applicable) may access the storage location |
| 5499 | // designated by v. |
| 5500 | // * expr is an expression with scalar type. |
| 5501 | // * binop is one of +, *, -, /, &, ^, |, <<, or >>. |
| 5502 | // * binop, binop=, ++, and -- are not overloaded operators. |
| 5503 | // * The expression x binop expr must be numerically equivalent to x binop |
| 5504 | // (expr). This requirement is satisfied if the operators in expr have |
| 5505 | // precedence greater than binop, or by using parentheses around expr or |
| 5506 | // subexpressions of expr. |
| 5507 | // * The expression expr binop x must be numerically equivalent to (expr) |
| 5508 | // binop x. This requirement is satisfied if the operators in expr have |
| 5509 | // precedence equal to or greater than binop, or by using parentheses around |
| 5510 | // expr or subexpressions of expr. |
| 5511 | // * For forms that allow multiple occurrences of x, the number of times |
| 5512 | // that x is evaluated is unspecified. |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5513 | if (AtomicKind == OMPC_read) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5514 | enum { |
| 5515 | NotAnExpression, |
| 5516 | NotAnAssignmentOp, |
| 5517 | NotAScalarType, |
| 5518 | NotAnLValue, |
| 5519 | NoError |
| 5520 | } ErrorFound = NoError; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5521 | SourceLocation ErrorLoc, NoteLoc; |
| 5522 | SourceRange ErrorRange, NoteRange; |
| 5523 | // If clause is read: |
| 5524 | // v = x; |
| 5525 | if (auto AtomicBody = dyn_cast<Expr>(Body)) { |
| 5526 | auto AtomicBinOp = |
| 5527 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 5528 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
| 5529 | X = AtomicBinOp->getRHS()->IgnoreParenImpCasts(); |
| 5530 | V = AtomicBinOp->getLHS()->IgnoreParenImpCasts(); |
| 5531 | if ((X->isInstantiationDependent() || X->getType()->isScalarType()) && |
| 5532 | (V->isInstantiationDependent() || V->getType()->isScalarType())) { |
| 5533 | if (!X->isLValue() || !V->isLValue()) { |
| 5534 | auto NotLValueExpr = X->isLValue() ? V : X; |
| 5535 | ErrorFound = NotAnLValue; |
| 5536 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5537 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5538 | NoteLoc = NotLValueExpr->getExprLoc(); |
| 5539 | NoteRange = NotLValueExpr->getSourceRange(); |
| 5540 | } |
| 5541 | } else if (!X->isInstantiationDependent() || |
| 5542 | !V->isInstantiationDependent()) { |
| 5543 | auto NotScalarExpr = |
| 5544 | (X->isInstantiationDependent() || X->getType()->isScalarType()) |
| 5545 | ? V |
| 5546 | : X; |
| 5547 | ErrorFound = NotAScalarType; |
| 5548 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5549 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5550 | NoteLoc = NotScalarExpr->getExprLoc(); |
| 5551 | NoteRange = NotScalarExpr->getSourceRange(); |
| 5552 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5553 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5554 | ErrorFound = NotAnAssignmentOp; |
| 5555 | ErrorLoc = AtomicBody->getExprLoc(); |
| 5556 | ErrorRange = AtomicBody->getSourceRange(); |
| 5557 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 5558 | : AtomicBody->getExprLoc(); |
| 5559 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 5560 | : AtomicBody->getSourceRange(); |
| 5561 | } |
| 5562 | } else { |
| 5563 | ErrorFound = NotAnExpression; |
| 5564 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 5565 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5566 | } |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5567 | if (ErrorFound != NoError) { |
| 5568 | Diag(ErrorLoc, diag::err_omp_atomic_read_not_expression_statement) |
| 5569 | << ErrorRange; |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5570 | Diag(NoteLoc, diag::note_omp_atomic_read_write) << ErrorFound |
| 5571 | << NoteRange; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5572 | return StmtError(); |
| 5573 | } else if (CurContext->isDependentContext()) |
| 5574 | V = X = nullptr; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5575 | } else if (AtomicKind == OMPC_write) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5576 | enum { |
| 5577 | NotAnExpression, |
| 5578 | NotAnAssignmentOp, |
| 5579 | NotAScalarType, |
| 5580 | NotAnLValue, |
| 5581 | NoError |
| 5582 | } ErrorFound = NoError; |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5583 | SourceLocation ErrorLoc, NoteLoc; |
| 5584 | SourceRange ErrorRange, NoteRange; |
| 5585 | // If clause is write: |
| 5586 | // x = expr; |
| 5587 | if (auto AtomicBody = dyn_cast<Expr>(Body)) { |
| 5588 | auto AtomicBinOp = |
| 5589 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 5590 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
Alexey Bataev | b832926 | 2015-02-27 06:33:30 +0000 | [diff] [blame] | 5591 | X = AtomicBinOp->getLHS(); |
| 5592 | E = AtomicBinOp->getRHS(); |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5593 | if ((X->isInstantiationDependent() || X->getType()->isScalarType()) && |
| 5594 | (E->isInstantiationDependent() || E->getType()->isScalarType())) { |
| 5595 | if (!X->isLValue()) { |
| 5596 | ErrorFound = NotAnLValue; |
| 5597 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5598 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5599 | NoteLoc = X->getExprLoc(); |
| 5600 | NoteRange = X->getSourceRange(); |
| 5601 | } |
| 5602 | } else if (!X->isInstantiationDependent() || |
| 5603 | !E->isInstantiationDependent()) { |
| 5604 | auto NotScalarExpr = |
| 5605 | (X->isInstantiationDependent() || X->getType()->isScalarType()) |
| 5606 | ? E |
| 5607 | : X; |
| 5608 | ErrorFound = NotAScalarType; |
| 5609 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5610 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5611 | NoteLoc = NotScalarExpr->getExprLoc(); |
| 5612 | NoteRange = NotScalarExpr->getSourceRange(); |
| 5613 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5614 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5615 | ErrorFound = NotAnAssignmentOp; |
| 5616 | ErrorLoc = AtomicBody->getExprLoc(); |
| 5617 | ErrorRange = AtomicBody->getSourceRange(); |
| 5618 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 5619 | : AtomicBody->getExprLoc(); |
| 5620 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 5621 | : AtomicBody->getSourceRange(); |
| 5622 | } |
| 5623 | } else { |
| 5624 | ErrorFound = NotAnExpression; |
| 5625 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 5626 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5627 | } |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5628 | if (ErrorFound != NoError) { |
| 5629 | Diag(ErrorLoc, diag::err_omp_atomic_write_not_expression_statement) |
| 5630 | << ErrorRange; |
| 5631 | Diag(NoteLoc, diag::note_omp_atomic_read_write) << ErrorFound |
| 5632 | << NoteRange; |
| 5633 | return StmtError(); |
| 5634 | } else if (CurContext->isDependentContext()) |
| 5635 | E = X = nullptr; |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5636 | } else if (AtomicKind == OMPC_update || AtomicKind == OMPC_unknown) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5637 | // If clause is update: |
| 5638 | // x++; |
| 5639 | // x--; |
| 5640 | // ++x; |
| 5641 | // --x; |
| 5642 | // x binop= expr; |
| 5643 | // x = x binop expr; |
| 5644 | // x = expr binop x; |
| 5645 | OpenMPAtomicUpdateChecker Checker(*this); |
| 5646 | if (Checker.checkStatement( |
| 5647 | Body, (AtomicKind == OMPC_update) |
| 5648 | ? diag::err_omp_atomic_update_not_expression_statement |
| 5649 | : diag::err_omp_atomic_not_expression_statement, |
| 5650 | diag::note_omp_atomic_update)) |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5651 | return StmtError(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5652 | if (!CurContext->isDependentContext()) { |
| 5653 | E = Checker.getExpr(); |
| 5654 | X = Checker.getX(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5655 | UE = Checker.getUpdateExpr(); |
| 5656 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5657 | } |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5658 | } else if (AtomicKind == OMPC_capture) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5659 | enum { |
| 5660 | NotAnAssignmentOp, |
| 5661 | NotACompoundStatement, |
| 5662 | NotTwoSubstatements, |
| 5663 | NotASpecificExpression, |
| 5664 | NoError |
| 5665 | } ErrorFound = NoError; |
| 5666 | SourceLocation ErrorLoc, NoteLoc; |
| 5667 | SourceRange ErrorRange, NoteRange; |
| 5668 | if (auto *AtomicBody = dyn_cast<Expr>(Body)) { |
| 5669 | // If clause is a capture: |
| 5670 | // v = x++; |
| 5671 | // v = x--; |
| 5672 | // v = ++x; |
| 5673 | // v = --x; |
| 5674 | // v = x binop= expr; |
| 5675 | // v = x = x binop expr; |
| 5676 | // v = x = expr binop x; |
| 5677 | auto *AtomicBinOp = |
| 5678 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 5679 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
| 5680 | V = AtomicBinOp->getLHS(); |
| 5681 | Body = AtomicBinOp->getRHS()->IgnoreParenImpCasts(); |
| 5682 | OpenMPAtomicUpdateChecker Checker(*this); |
| 5683 | if (Checker.checkStatement( |
| 5684 | Body, diag::err_omp_atomic_capture_not_expression_statement, |
| 5685 | diag::note_omp_atomic_update)) |
| 5686 | return StmtError(); |
| 5687 | E = Checker.getExpr(); |
| 5688 | X = Checker.getX(); |
| 5689 | UE = Checker.getUpdateExpr(); |
| 5690 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
| 5691 | IsPostfixUpdate = Checker.isPostfixUpdate(); |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5692 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5693 | ErrorLoc = AtomicBody->getExprLoc(); |
| 5694 | ErrorRange = AtomicBody->getSourceRange(); |
| 5695 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 5696 | : AtomicBody->getExprLoc(); |
| 5697 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 5698 | : AtomicBody->getSourceRange(); |
| 5699 | ErrorFound = NotAnAssignmentOp; |
| 5700 | } |
| 5701 | if (ErrorFound != NoError) { |
| 5702 | Diag(ErrorLoc, diag::err_omp_atomic_capture_not_expression_statement) |
| 5703 | << ErrorRange; |
| 5704 | Diag(NoteLoc, diag::note_omp_atomic_capture) << ErrorFound << NoteRange; |
| 5705 | return StmtError(); |
| 5706 | } else if (CurContext->isDependentContext()) { |
| 5707 | UE = V = E = X = nullptr; |
| 5708 | } |
| 5709 | } else { |
| 5710 | // If clause is a capture: |
| 5711 | // { v = x; x = expr; } |
| 5712 | // { v = x; x++; } |
| 5713 | // { v = x; x--; } |
| 5714 | // { v = x; ++x; } |
| 5715 | // { v = x; --x; } |
| 5716 | // { v = x; x binop= expr; } |
| 5717 | // { v = x; x = x binop expr; } |
| 5718 | // { v = x; x = expr binop x; } |
| 5719 | // { x++; v = x; } |
| 5720 | // { x--; v = x; } |
| 5721 | // { ++x; v = x; } |
| 5722 | // { --x; v = x; } |
| 5723 | // { x binop= expr; v = x; } |
| 5724 | // { x = x binop expr; v = x; } |
| 5725 | // { x = expr binop x; v = x; } |
| 5726 | if (auto *CS = dyn_cast<CompoundStmt>(Body)) { |
| 5727 | // Check that this is { expr1; expr2; } |
| 5728 | if (CS->size() == 2) { |
| 5729 | auto *First = CS->body_front(); |
| 5730 | auto *Second = CS->body_back(); |
| 5731 | if (auto *EWC = dyn_cast<ExprWithCleanups>(First)) |
| 5732 | First = EWC->getSubExpr()->IgnoreParenImpCasts(); |
| 5733 | if (auto *EWC = dyn_cast<ExprWithCleanups>(Second)) |
| 5734 | Second = EWC->getSubExpr()->IgnoreParenImpCasts(); |
| 5735 | // Need to find what subexpression is 'v' and what is 'x'. |
| 5736 | OpenMPAtomicUpdateChecker Checker(*this); |
| 5737 | bool IsUpdateExprFound = !Checker.checkStatement(Second); |
| 5738 | BinaryOperator *BinOp = nullptr; |
| 5739 | if (IsUpdateExprFound) { |
| 5740 | BinOp = dyn_cast<BinaryOperator>(First); |
| 5741 | IsUpdateExprFound = BinOp && BinOp->getOpcode() == BO_Assign; |
| 5742 | } |
| 5743 | if (IsUpdateExprFound && !CurContext->isDependentContext()) { |
| 5744 | // { v = x; x++; } |
| 5745 | // { v = x; x--; } |
| 5746 | // { v = x; ++x; } |
| 5747 | // { v = x; --x; } |
| 5748 | // { v = x; x binop= expr; } |
| 5749 | // { v = x; x = x binop expr; } |
| 5750 | // { v = x; x = expr binop x; } |
| 5751 | // Check that the first expression has form v = x. |
| 5752 | auto *PossibleX = BinOp->getRHS()->IgnoreParenImpCasts(); |
| 5753 | llvm::FoldingSetNodeID XId, PossibleXId; |
| 5754 | Checker.getX()->Profile(XId, Context, /*Canonical=*/true); |
| 5755 | PossibleX->Profile(PossibleXId, Context, /*Canonical=*/true); |
| 5756 | IsUpdateExprFound = XId == PossibleXId; |
| 5757 | if (IsUpdateExprFound) { |
| 5758 | V = BinOp->getLHS(); |
| 5759 | X = Checker.getX(); |
| 5760 | E = Checker.getExpr(); |
| 5761 | UE = Checker.getUpdateExpr(); |
| 5762 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5763 | IsPostfixUpdate = true; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5764 | } |
| 5765 | } |
| 5766 | if (!IsUpdateExprFound) { |
| 5767 | IsUpdateExprFound = !Checker.checkStatement(First); |
| 5768 | BinOp = nullptr; |
| 5769 | if (IsUpdateExprFound) { |
| 5770 | BinOp = dyn_cast<BinaryOperator>(Second); |
| 5771 | IsUpdateExprFound = BinOp && BinOp->getOpcode() == BO_Assign; |
| 5772 | } |
| 5773 | if (IsUpdateExprFound && !CurContext->isDependentContext()) { |
| 5774 | // { x++; v = x; } |
| 5775 | // { x--; v = x; } |
| 5776 | // { ++x; v = x; } |
| 5777 | // { --x; v = x; } |
| 5778 | // { x binop= expr; v = x; } |
| 5779 | // { x = x binop expr; v = x; } |
| 5780 | // { x = expr binop x; v = x; } |
| 5781 | // Check that the second expression has form v = x. |
| 5782 | auto *PossibleX = BinOp->getRHS()->IgnoreParenImpCasts(); |
| 5783 | llvm::FoldingSetNodeID XId, PossibleXId; |
| 5784 | Checker.getX()->Profile(XId, Context, /*Canonical=*/true); |
| 5785 | PossibleX->Profile(PossibleXId, Context, /*Canonical=*/true); |
| 5786 | IsUpdateExprFound = XId == PossibleXId; |
| 5787 | if (IsUpdateExprFound) { |
| 5788 | V = BinOp->getLHS(); |
| 5789 | X = Checker.getX(); |
| 5790 | E = Checker.getExpr(); |
| 5791 | UE = Checker.getUpdateExpr(); |
| 5792 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5793 | IsPostfixUpdate = false; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5794 | } |
| 5795 | } |
| 5796 | } |
| 5797 | if (!IsUpdateExprFound) { |
| 5798 | // { v = x; x = expr; } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5799 | auto *FirstExpr = dyn_cast<Expr>(First); |
| 5800 | auto *SecondExpr = dyn_cast<Expr>(Second); |
| 5801 | if (!FirstExpr || !SecondExpr || |
| 5802 | !(FirstExpr->isInstantiationDependent() || |
| 5803 | SecondExpr->isInstantiationDependent())) { |
| 5804 | auto *FirstBinOp = dyn_cast<BinaryOperator>(First); |
| 5805 | if (!FirstBinOp || FirstBinOp->getOpcode() != BO_Assign) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5806 | ErrorFound = NotAnAssignmentOp; |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5807 | NoteLoc = ErrorLoc = FirstBinOp ? FirstBinOp->getOperatorLoc() |
| 5808 | : First->getLocStart(); |
| 5809 | NoteRange = ErrorRange = FirstBinOp |
| 5810 | ? FirstBinOp->getSourceRange() |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5811 | : SourceRange(ErrorLoc, ErrorLoc); |
| 5812 | } else { |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5813 | auto *SecondBinOp = dyn_cast<BinaryOperator>(Second); |
| 5814 | if (!SecondBinOp || SecondBinOp->getOpcode() != BO_Assign) { |
| 5815 | ErrorFound = NotAnAssignmentOp; |
| 5816 | NoteLoc = ErrorLoc = SecondBinOp |
| 5817 | ? SecondBinOp->getOperatorLoc() |
| 5818 | : Second->getLocStart(); |
| 5819 | NoteRange = ErrorRange = |
| 5820 | SecondBinOp ? SecondBinOp->getSourceRange() |
| 5821 | : SourceRange(ErrorLoc, ErrorLoc); |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5822 | } else { |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5823 | auto *PossibleXRHSInFirst = |
| 5824 | FirstBinOp->getRHS()->IgnoreParenImpCasts(); |
| 5825 | auto *PossibleXLHSInSecond = |
| 5826 | SecondBinOp->getLHS()->IgnoreParenImpCasts(); |
| 5827 | llvm::FoldingSetNodeID X1Id, X2Id; |
| 5828 | PossibleXRHSInFirst->Profile(X1Id, Context, |
| 5829 | /*Canonical=*/true); |
| 5830 | PossibleXLHSInSecond->Profile(X2Id, Context, |
| 5831 | /*Canonical=*/true); |
| 5832 | IsUpdateExprFound = X1Id == X2Id; |
| 5833 | if (IsUpdateExprFound) { |
| 5834 | V = FirstBinOp->getLHS(); |
| 5835 | X = SecondBinOp->getLHS(); |
| 5836 | E = SecondBinOp->getRHS(); |
| 5837 | UE = nullptr; |
| 5838 | IsXLHSInRHSPart = false; |
| 5839 | IsPostfixUpdate = true; |
| 5840 | } else { |
| 5841 | ErrorFound = NotASpecificExpression; |
| 5842 | ErrorLoc = FirstBinOp->getExprLoc(); |
| 5843 | ErrorRange = FirstBinOp->getSourceRange(); |
| 5844 | NoteLoc = SecondBinOp->getLHS()->getExprLoc(); |
| 5845 | NoteRange = SecondBinOp->getRHS()->getSourceRange(); |
| 5846 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5847 | } |
| 5848 | } |
| 5849 | } |
| 5850 | } |
| 5851 | } else { |
| 5852 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 5853 | NoteRange = ErrorRange = |
| 5854 | SourceRange(Body->getLocStart(), Body->getLocStart()); |
| 5855 | ErrorFound = NotTwoSubstatements; |
| 5856 | } |
| 5857 | } else { |
| 5858 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 5859 | NoteRange = ErrorRange = |
| 5860 | SourceRange(Body->getLocStart(), Body->getLocStart()); |
| 5861 | ErrorFound = NotACompoundStatement; |
| 5862 | } |
| 5863 | if (ErrorFound != NoError) { |
| 5864 | Diag(ErrorLoc, diag::err_omp_atomic_capture_not_compound_statement) |
| 5865 | << ErrorRange; |
| 5866 | Diag(NoteLoc, diag::note_omp_atomic_capture) << ErrorFound << NoteRange; |
| 5867 | return StmtError(); |
| 5868 | } else if (CurContext->isDependentContext()) { |
| 5869 | UE = V = E = X = nullptr; |
| 5870 | } |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5871 | } |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5872 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 5873 | |
| 5874 | getCurFunction()->setHasBranchProtectedScope(); |
| 5875 | |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5876 | return OMPAtomicDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5877 | X, V, E, UE, IsXLHSInRHSPart, |
| 5878 | IsPostfixUpdate); |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 5879 | } |
| 5880 | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 5881 | StmtResult Sema::ActOnOpenMPTargetDirective(ArrayRef<OMPClause *> Clauses, |
| 5882 | Stmt *AStmt, |
| 5883 | SourceLocation StartLoc, |
| 5884 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5885 | if (!AStmt) |
| 5886 | return StmtError(); |
| 5887 | |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 5888 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 5889 | // 1.2.2 OpenMP Language Terminology |
| 5890 | // Structured block - An executable statement with a single entry at the |
| 5891 | // top and a single exit at the bottom. |
| 5892 | // The point of exit cannot be a branch out of the structured block. |
| 5893 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5894 | CS->getCapturedDecl()->setNothrow(); |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 5895 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 5896 | // OpenMP [2.16, Nesting of Regions] |
| 5897 | // If specified, a teams construct must be contained within a target |
| 5898 | // construct. That target construct must contain no statements or directives |
| 5899 | // outside of the teams construct. |
| 5900 | if (DSAStack->hasInnerTeamsRegion()) { |
| 5901 | auto S = AStmt->IgnoreContainers(/*IgnoreCaptured*/ true); |
| 5902 | bool OMPTeamsFound = true; |
| 5903 | if (auto *CS = dyn_cast<CompoundStmt>(S)) { |
| 5904 | auto I = CS->body_begin(); |
| 5905 | while (I != CS->body_end()) { |
| 5906 | auto OED = dyn_cast<OMPExecutableDirective>(*I); |
| 5907 | if (!OED || !isOpenMPTeamsDirective(OED->getDirectiveKind())) { |
| 5908 | OMPTeamsFound = false; |
| 5909 | break; |
| 5910 | } |
| 5911 | ++I; |
| 5912 | } |
| 5913 | assert(I != CS->body_end() && "Not found statement"); |
| 5914 | S = *I; |
| 5915 | } |
| 5916 | if (!OMPTeamsFound) { |
| 5917 | Diag(StartLoc, diag::err_omp_target_contains_not_only_teams); |
| 5918 | Diag(DSAStack->getInnerTeamsRegionLoc(), |
| 5919 | diag::note_omp_nested_teams_construct_here); |
| 5920 | Diag(S->getLocStart(), diag::note_omp_nested_statement_here) |
| 5921 | << isa<OMPExecutableDirective>(S); |
| 5922 | return StmtError(); |
| 5923 | } |
| 5924 | } |
| 5925 | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 5926 | getCurFunction()->setHasBranchProtectedScope(); |
| 5927 | |
| 5928 | return OMPTargetDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 5929 | } |
| 5930 | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 5931 | StmtResult |
| 5932 | Sema::ActOnOpenMPTargetParallelDirective(ArrayRef<OMPClause *> Clauses, |
| 5933 | Stmt *AStmt, SourceLocation StartLoc, |
| 5934 | SourceLocation EndLoc) { |
| 5935 | if (!AStmt) |
| 5936 | return StmtError(); |
| 5937 | |
| 5938 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 5939 | // 1.2.2 OpenMP Language Terminology |
| 5940 | // Structured block - An executable statement with a single entry at the |
| 5941 | // top and a single exit at the bottom. |
| 5942 | // The point of exit cannot be a branch out of the structured block. |
| 5943 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5944 | CS->getCapturedDecl()->setNothrow(); |
| 5945 | |
| 5946 | getCurFunction()->setHasBranchProtectedScope(); |
| 5947 | |
| 5948 | return OMPTargetParallelDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 5949 | AStmt); |
| 5950 | } |
| 5951 | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 5952 | StmtResult Sema::ActOnOpenMPTargetParallelForDirective( |
| 5953 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 5954 | SourceLocation EndLoc, |
| 5955 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 5956 | if (!AStmt) |
| 5957 | return StmtError(); |
| 5958 | |
| 5959 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 5960 | // 1.2.2 OpenMP Language Terminology |
| 5961 | // Structured block - An executable statement with a single entry at the |
| 5962 | // top and a single exit at the bottom. |
| 5963 | // The point of exit cannot be a branch out of the structured block. |
| 5964 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5965 | CS->getCapturedDecl()->setNothrow(); |
| 5966 | |
| 5967 | OMPLoopDirective::HelperExprs B; |
| 5968 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 5969 | // define the nested loops number. |
| 5970 | unsigned NestedLoopCount = |
| 5971 | CheckOpenMPLoop(OMPD_target_parallel_for, getCollapseNumberExpr(Clauses), |
| 5972 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 5973 | VarsWithImplicitDSA, B); |
| 5974 | if (NestedLoopCount == 0) |
| 5975 | return StmtError(); |
| 5976 | |
| 5977 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 5978 | "omp target parallel for loop exprs were not built"); |
| 5979 | |
| 5980 | if (!CurContext->isDependentContext()) { |
| 5981 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 5982 | for (auto C : Clauses) { |
| 5983 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 5984 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 5985 | B.NumIterations, *this, CurScope)) |
| 5986 | return StmtError(); |
| 5987 | } |
| 5988 | } |
| 5989 | |
| 5990 | getCurFunction()->setHasBranchProtectedScope(); |
| 5991 | return OMPTargetParallelForDirective::Create(Context, StartLoc, EndLoc, |
| 5992 | NestedLoopCount, Clauses, AStmt, |
| 5993 | B, DSAStack->isCancelRegion()); |
| 5994 | } |
| 5995 | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 5996 | /// \brief Check for existence of a map clause in the list of clauses. |
| 5997 | static bool HasMapClause(ArrayRef<OMPClause *> Clauses) { |
| 5998 | for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end(); |
| 5999 | I != E; ++I) { |
| 6000 | if (*I != nullptr && (*I)->getClauseKind() == OMPC_map) { |
| 6001 | return true; |
| 6002 | } |
| 6003 | } |
| 6004 | |
| 6005 | return false; |
| 6006 | } |
| 6007 | |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 6008 | StmtResult Sema::ActOnOpenMPTargetDataDirective(ArrayRef<OMPClause *> Clauses, |
| 6009 | Stmt *AStmt, |
| 6010 | SourceLocation StartLoc, |
| 6011 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6012 | if (!AStmt) |
| 6013 | return StmtError(); |
| 6014 | |
| 6015 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 6016 | |
Arpith Chacko Jacob | 46a04bb | 2016-01-21 19:57:55 +0000 | [diff] [blame] | 6017 | // OpenMP [2.10.1, Restrictions, p. 97] |
| 6018 | // At least one map clause must appear on the directive. |
| 6019 | if (!HasMapClause(Clauses)) { |
| 6020 | Diag(StartLoc, diag::err_omp_no_map_for_directive) << |
| 6021 | getOpenMPDirectiveName(OMPD_target_data); |
| 6022 | return StmtError(); |
| 6023 | } |
| 6024 | |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 6025 | getCurFunction()->setHasBranchProtectedScope(); |
| 6026 | |
| 6027 | return OMPTargetDataDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 6028 | AStmt); |
| 6029 | } |
| 6030 | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 6031 | StmtResult |
| 6032 | Sema::ActOnOpenMPTargetEnterDataDirective(ArrayRef<OMPClause *> Clauses, |
| 6033 | SourceLocation StartLoc, |
| 6034 | SourceLocation EndLoc) { |
| 6035 | // OpenMP [2.10.2, Restrictions, p. 99] |
| 6036 | // At least one map clause must appear on the directive. |
| 6037 | if (!HasMapClause(Clauses)) { |
| 6038 | Diag(StartLoc, diag::err_omp_no_map_for_directive) |
| 6039 | << getOpenMPDirectiveName(OMPD_target_enter_data); |
| 6040 | return StmtError(); |
| 6041 | } |
| 6042 | |
| 6043 | return OMPTargetEnterDataDirective::Create(Context, StartLoc, EndLoc, |
| 6044 | Clauses); |
| 6045 | } |
| 6046 | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 6047 | StmtResult |
| 6048 | Sema::ActOnOpenMPTargetExitDataDirective(ArrayRef<OMPClause *> Clauses, |
| 6049 | SourceLocation StartLoc, |
| 6050 | SourceLocation EndLoc) { |
| 6051 | // OpenMP [2.10.3, Restrictions, p. 102] |
| 6052 | // At least one map clause must appear on the directive. |
| 6053 | if (!HasMapClause(Clauses)) { |
| 6054 | Diag(StartLoc, diag::err_omp_no_map_for_directive) |
| 6055 | << getOpenMPDirectiveName(OMPD_target_exit_data); |
| 6056 | return StmtError(); |
| 6057 | } |
| 6058 | |
| 6059 | return OMPTargetExitDataDirective::Create(Context, StartLoc, EndLoc, Clauses); |
| 6060 | } |
| 6061 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 6062 | StmtResult Sema::ActOnOpenMPTeamsDirective(ArrayRef<OMPClause *> Clauses, |
| 6063 | Stmt *AStmt, SourceLocation StartLoc, |
| 6064 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6065 | if (!AStmt) |
| 6066 | return StmtError(); |
| 6067 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 6068 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6069 | // 1.2.2 OpenMP Language Terminology |
| 6070 | // Structured block - An executable statement with a single entry at the |
| 6071 | // top and a single exit at the bottom. |
| 6072 | // The point of exit cannot be a branch out of the structured block. |
| 6073 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6074 | CS->getCapturedDecl()->setNothrow(); |
| 6075 | |
| 6076 | getCurFunction()->setHasBranchProtectedScope(); |
| 6077 | |
| 6078 | return OMPTeamsDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 6079 | } |
| 6080 | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 6081 | StmtResult |
| 6082 | Sema::ActOnOpenMPCancellationPointDirective(SourceLocation StartLoc, |
| 6083 | SourceLocation EndLoc, |
| 6084 | OpenMPDirectiveKind CancelRegion) { |
| 6085 | if (CancelRegion != OMPD_parallel && CancelRegion != OMPD_for && |
| 6086 | CancelRegion != OMPD_sections && CancelRegion != OMPD_taskgroup) { |
| 6087 | Diag(StartLoc, diag::err_omp_wrong_cancel_region) |
| 6088 | << getOpenMPDirectiveName(CancelRegion); |
| 6089 | return StmtError(); |
| 6090 | } |
| 6091 | if (DSAStack->isParentNowaitRegion()) { |
| 6092 | Diag(StartLoc, diag::err_omp_parent_cancel_region_nowait) << 0; |
| 6093 | return StmtError(); |
| 6094 | } |
| 6095 | if (DSAStack->isParentOrderedRegion()) { |
| 6096 | Diag(StartLoc, diag::err_omp_parent_cancel_region_ordered) << 0; |
| 6097 | return StmtError(); |
| 6098 | } |
| 6099 | return OMPCancellationPointDirective::Create(Context, StartLoc, EndLoc, |
| 6100 | CancelRegion); |
| 6101 | } |
| 6102 | |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 6103 | StmtResult Sema::ActOnOpenMPCancelDirective(ArrayRef<OMPClause *> Clauses, |
| 6104 | SourceLocation StartLoc, |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 6105 | SourceLocation EndLoc, |
| 6106 | OpenMPDirectiveKind CancelRegion) { |
| 6107 | if (CancelRegion != OMPD_parallel && CancelRegion != OMPD_for && |
| 6108 | CancelRegion != OMPD_sections && CancelRegion != OMPD_taskgroup) { |
| 6109 | Diag(StartLoc, diag::err_omp_wrong_cancel_region) |
| 6110 | << getOpenMPDirectiveName(CancelRegion); |
| 6111 | return StmtError(); |
| 6112 | } |
| 6113 | if (DSAStack->isParentNowaitRegion()) { |
| 6114 | Diag(StartLoc, diag::err_omp_parent_cancel_region_nowait) << 1; |
| 6115 | return StmtError(); |
| 6116 | } |
| 6117 | if (DSAStack->isParentOrderedRegion()) { |
| 6118 | Diag(StartLoc, diag::err_omp_parent_cancel_region_ordered) << 1; |
| 6119 | return StmtError(); |
| 6120 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 6121 | DSAStack->setParentCancelRegion(/*Cancel=*/true); |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 6122 | return OMPCancelDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 6123 | CancelRegion); |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 6124 | } |
| 6125 | |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6126 | static bool checkGrainsizeNumTasksClauses(Sema &S, |
| 6127 | ArrayRef<OMPClause *> Clauses) { |
| 6128 | OMPClause *PrevClause = nullptr; |
| 6129 | bool ErrorFound = false; |
| 6130 | for (auto *C : Clauses) { |
| 6131 | if (C->getClauseKind() == OMPC_grainsize || |
| 6132 | C->getClauseKind() == OMPC_num_tasks) { |
| 6133 | if (!PrevClause) |
| 6134 | PrevClause = C; |
| 6135 | else if (PrevClause->getClauseKind() != C->getClauseKind()) { |
| 6136 | S.Diag(C->getLocStart(), |
| 6137 | diag::err_omp_grainsize_num_tasks_mutually_exclusive) |
| 6138 | << getOpenMPClauseName(C->getClauseKind()) |
| 6139 | << getOpenMPClauseName(PrevClause->getClauseKind()); |
| 6140 | S.Diag(PrevClause->getLocStart(), |
| 6141 | diag::note_omp_previous_grainsize_num_tasks) |
| 6142 | << getOpenMPClauseName(PrevClause->getClauseKind()); |
| 6143 | ErrorFound = true; |
| 6144 | } |
| 6145 | } |
| 6146 | } |
| 6147 | return ErrorFound; |
| 6148 | } |
| 6149 | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 6150 | StmtResult Sema::ActOnOpenMPTaskLoopDirective( |
| 6151 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6152 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 6153 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 6154 | if (!AStmt) |
| 6155 | return StmtError(); |
| 6156 | |
| 6157 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 6158 | OMPLoopDirective::HelperExprs B; |
| 6159 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 6160 | // define the nested loops number. |
| 6161 | unsigned NestedLoopCount = |
| 6162 | CheckOpenMPLoop(OMPD_taskloop, getCollapseNumberExpr(Clauses), |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 6163 | /*OrderedLoopCountExpr=*/nullptr, AStmt, *this, *DSAStack, |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 6164 | VarsWithImplicitDSA, B); |
| 6165 | if (NestedLoopCount == 0) |
| 6166 | return StmtError(); |
| 6167 | |
| 6168 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6169 | "omp for loop exprs were not built"); |
| 6170 | |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6171 | // OpenMP, [2.9.2 taskloop Construct, Restrictions] |
| 6172 | // The grainsize clause and num_tasks clause are mutually exclusive and may |
| 6173 | // not appear on the same taskloop directive. |
| 6174 | if (checkGrainsizeNumTasksClauses(*this, Clauses)) |
| 6175 | return StmtError(); |
| 6176 | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 6177 | getCurFunction()->setHasBranchProtectedScope(); |
| 6178 | return OMPTaskLoopDirective::Create(Context, StartLoc, EndLoc, |
| 6179 | NestedLoopCount, Clauses, AStmt, B); |
| 6180 | } |
| 6181 | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 6182 | StmtResult Sema::ActOnOpenMPTaskLoopSimdDirective( |
| 6183 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6184 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 6185 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 6186 | if (!AStmt) |
| 6187 | return StmtError(); |
| 6188 | |
| 6189 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 6190 | OMPLoopDirective::HelperExprs B; |
| 6191 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 6192 | // define the nested loops number. |
| 6193 | unsigned NestedLoopCount = |
| 6194 | CheckOpenMPLoop(OMPD_taskloop_simd, getCollapseNumberExpr(Clauses), |
| 6195 | /*OrderedLoopCountExpr=*/nullptr, AStmt, *this, *DSAStack, |
| 6196 | VarsWithImplicitDSA, B); |
| 6197 | if (NestedLoopCount == 0) |
| 6198 | return StmtError(); |
| 6199 | |
| 6200 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6201 | "omp for loop exprs were not built"); |
| 6202 | |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6203 | // OpenMP, [2.9.2 taskloop Construct, Restrictions] |
| 6204 | // The grainsize clause and num_tasks clause are mutually exclusive and may |
| 6205 | // not appear on the same taskloop directive. |
| 6206 | if (checkGrainsizeNumTasksClauses(*this, Clauses)) |
| 6207 | return StmtError(); |
| 6208 | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 6209 | getCurFunction()->setHasBranchProtectedScope(); |
| 6210 | return OMPTaskLoopSimdDirective::Create(Context, StartLoc, EndLoc, |
| 6211 | NestedLoopCount, Clauses, AStmt, B); |
| 6212 | } |
| 6213 | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 6214 | StmtResult Sema::ActOnOpenMPDistributeDirective( |
| 6215 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6216 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 6217 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 6218 | if (!AStmt) |
| 6219 | return StmtError(); |
| 6220 | |
| 6221 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 6222 | OMPLoopDirective::HelperExprs B; |
| 6223 | // In presence of clause 'collapse' with number of loops, it will |
| 6224 | // define the nested loops number. |
| 6225 | unsigned NestedLoopCount = |
| 6226 | CheckOpenMPLoop(OMPD_distribute, getCollapseNumberExpr(Clauses), |
| 6227 | nullptr /*ordered not a clause on distribute*/, AStmt, |
| 6228 | *this, *DSAStack, VarsWithImplicitDSA, B); |
| 6229 | if (NestedLoopCount == 0) |
| 6230 | return StmtError(); |
| 6231 | |
| 6232 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6233 | "omp for loop exprs were not built"); |
| 6234 | |
| 6235 | getCurFunction()->setHasBranchProtectedScope(); |
| 6236 | return OMPDistributeDirective::Create(Context, StartLoc, EndLoc, |
| 6237 | NestedLoopCount, Clauses, AStmt, B); |
| 6238 | } |
| 6239 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6240 | OMPClause *Sema::ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, Expr *Expr, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6241 | SourceLocation StartLoc, |
| 6242 | SourceLocation LParenLoc, |
| 6243 | SourceLocation EndLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6244 | OMPClause *Res = nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6245 | switch (Kind) { |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 6246 | case OMPC_final: |
| 6247 | Res = ActOnOpenMPFinalClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6248 | break; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6249 | case OMPC_num_threads: |
| 6250 | Res = ActOnOpenMPNumThreadsClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6251 | break; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6252 | case OMPC_safelen: |
| 6253 | Res = ActOnOpenMPSafelenClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6254 | break; |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 6255 | case OMPC_simdlen: |
| 6256 | Res = ActOnOpenMPSimdlenClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6257 | break; |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6258 | case OMPC_collapse: |
| 6259 | Res = ActOnOpenMPCollapseClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6260 | break; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 6261 | case OMPC_ordered: |
| 6262 | Res = ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Expr); |
| 6263 | break; |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 6264 | case OMPC_device: |
| 6265 | Res = ActOnOpenMPDeviceClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6266 | break; |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 6267 | case OMPC_num_teams: |
| 6268 | Res = ActOnOpenMPNumTeamsClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6269 | break; |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6270 | case OMPC_thread_limit: |
| 6271 | Res = ActOnOpenMPThreadLimitClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6272 | break; |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6273 | case OMPC_priority: |
| 6274 | Res = ActOnOpenMPPriorityClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6275 | break; |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 6276 | case OMPC_grainsize: |
| 6277 | Res = ActOnOpenMPGrainsizeClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6278 | break; |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6279 | case OMPC_num_tasks: |
| 6280 | Res = ActOnOpenMPNumTasksClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6281 | break; |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 6282 | case OMPC_hint: |
| 6283 | Res = ActOnOpenMPHintClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6284 | break; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6285 | case OMPC_if: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6286 | case OMPC_default: |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6287 | case OMPC_proc_bind: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6288 | case OMPC_schedule: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6289 | case OMPC_private: |
| 6290 | case OMPC_firstprivate: |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6291 | case OMPC_lastprivate: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6292 | case OMPC_shared: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6293 | case OMPC_reduction: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6294 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 6295 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6296 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6297 | case OMPC_copyprivate: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6298 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 6299 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 6300 | case OMPC_mergeable: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6301 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 6302 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6303 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6304 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6305 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6306 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 6307 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6308 | case OMPC_depend: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6309 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6310 | case OMPC_simd: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 6311 | case OMPC_map: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 6312 | case OMPC_nogroup: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 6313 | case OMPC_dist_schedule: |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 6314 | case OMPC_defaultmap: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6315 | case OMPC_unknown: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6316 | llvm_unreachable("Clause is not allowed."); |
| 6317 | } |
| 6318 | return Res; |
| 6319 | } |
| 6320 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6321 | OMPClause *Sema::ActOnOpenMPIfClause(OpenMPDirectiveKind NameModifier, |
| 6322 | Expr *Condition, SourceLocation StartLoc, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6323 | SourceLocation LParenLoc, |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6324 | SourceLocation NameModifierLoc, |
| 6325 | SourceLocation ColonLoc, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6326 | SourceLocation EndLoc) { |
| 6327 | Expr *ValExpr = Condition; |
| 6328 | if (!Condition->isValueDependent() && !Condition->isTypeDependent() && |
| 6329 | !Condition->isInstantiationDependent() && |
| 6330 | !Condition->containsUnexpandedParameterPack()) { |
| 6331 | ExprResult Val = ActOnBooleanCondition(DSAStack->getCurScope(), |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6332 | Condition->getExprLoc(), Condition); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6333 | if (Val.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6334 | return nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6335 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6336 | ValExpr = Val.get(); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6337 | } |
| 6338 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6339 | return new (Context) OMPIfClause(NameModifier, ValExpr, StartLoc, LParenLoc, |
| 6340 | NameModifierLoc, ColonLoc, EndLoc); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6341 | } |
| 6342 | |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 6343 | OMPClause *Sema::ActOnOpenMPFinalClause(Expr *Condition, |
| 6344 | SourceLocation StartLoc, |
| 6345 | SourceLocation LParenLoc, |
| 6346 | SourceLocation EndLoc) { |
| 6347 | Expr *ValExpr = Condition; |
| 6348 | if (!Condition->isValueDependent() && !Condition->isTypeDependent() && |
| 6349 | !Condition->isInstantiationDependent() && |
| 6350 | !Condition->containsUnexpandedParameterPack()) { |
| 6351 | ExprResult Val = ActOnBooleanCondition(DSAStack->getCurScope(), |
| 6352 | Condition->getExprLoc(), Condition); |
| 6353 | if (Val.isInvalid()) |
| 6354 | return nullptr; |
| 6355 | |
| 6356 | ValExpr = Val.get(); |
| 6357 | } |
| 6358 | |
| 6359 | return new (Context) OMPFinalClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 6360 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 6361 | ExprResult Sema::PerformOpenMPImplicitIntegerConversion(SourceLocation Loc, |
| 6362 | Expr *Op) { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6363 | if (!Op) |
| 6364 | return ExprError(); |
| 6365 | |
| 6366 | class IntConvertDiagnoser : public ICEConvertDiagnoser { |
| 6367 | public: |
| 6368 | IntConvertDiagnoser() |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6369 | : ICEConvertDiagnoser(/*AllowScopedEnumerations*/ false, false, true) {} |
Craig Topper | e14c0f8 | 2014-03-12 04:55:44 +0000 | [diff] [blame] | 6370 | SemaDiagnosticBuilder diagnoseNotInt(Sema &S, SourceLocation Loc, |
| 6371 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6372 | return S.Diag(Loc, diag::err_omp_not_integral) << T; |
| 6373 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6374 | SemaDiagnosticBuilder diagnoseIncomplete(Sema &S, SourceLocation Loc, |
| 6375 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6376 | return S.Diag(Loc, diag::err_omp_incomplete_type) << T; |
| 6377 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6378 | SemaDiagnosticBuilder diagnoseExplicitConv(Sema &S, SourceLocation Loc, |
| 6379 | QualType T, |
| 6380 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6381 | return S.Diag(Loc, diag::err_omp_explicit_conversion) << T << ConvTy; |
| 6382 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6383 | SemaDiagnosticBuilder noteExplicitConv(Sema &S, CXXConversionDecl *Conv, |
| 6384 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6385 | return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6386 | << ConvTy->isEnumeralType() << ConvTy; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6387 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6388 | SemaDiagnosticBuilder diagnoseAmbiguous(Sema &S, SourceLocation Loc, |
| 6389 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6390 | return S.Diag(Loc, diag::err_omp_ambiguous_conversion) << T; |
| 6391 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6392 | SemaDiagnosticBuilder noteAmbiguous(Sema &S, CXXConversionDecl *Conv, |
| 6393 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6394 | return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6395 | << ConvTy->isEnumeralType() << ConvTy; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6396 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6397 | SemaDiagnosticBuilder diagnoseConversion(Sema &, SourceLocation, QualType, |
| 6398 | QualType) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6399 | llvm_unreachable("conversion functions are permitted"); |
| 6400 | } |
| 6401 | } ConvertDiagnoser; |
| 6402 | return PerformContextualImplicitConversion(Loc, Op, ConvertDiagnoser); |
| 6403 | } |
| 6404 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6405 | static bool IsNonNegativeIntegerValue(Expr *&ValExpr, Sema &SemaRef, |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6406 | OpenMPClauseKind CKind, |
| 6407 | bool StrictlyPositive) { |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6408 | if (!ValExpr->isTypeDependent() && !ValExpr->isValueDependent() && |
| 6409 | !ValExpr->isInstantiationDependent()) { |
| 6410 | SourceLocation Loc = ValExpr->getExprLoc(); |
| 6411 | ExprResult Value = |
| 6412 | SemaRef.PerformOpenMPImplicitIntegerConversion(Loc, ValExpr); |
| 6413 | if (Value.isInvalid()) |
| 6414 | return false; |
| 6415 | |
| 6416 | ValExpr = Value.get(); |
| 6417 | // The expression must evaluate to a non-negative integer value. |
| 6418 | llvm::APSInt Result; |
| 6419 | if (ValExpr->isIntegerConstantExpr(Result, SemaRef.Context) && |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6420 | Result.isSigned() && |
| 6421 | !((!StrictlyPositive && Result.isNonNegative()) || |
| 6422 | (StrictlyPositive && Result.isStrictlyPositive()))) { |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6423 | SemaRef.Diag(Loc, diag::err_omp_negative_expression_in_clause) |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6424 | << getOpenMPClauseName(CKind) << (StrictlyPositive ? 1 : 0) |
| 6425 | << ValExpr->getSourceRange(); |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6426 | return false; |
| 6427 | } |
| 6428 | } |
| 6429 | return true; |
| 6430 | } |
| 6431 | |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6432 | OMPClause *Sema::ActOnOpenMPNumThreadsClause(Expr *NumThreads, |
| 6433 | SourceLocation StartLoc, |
| 6434 | SourceLocation LParenLoc, |
| 6435 | SourceLocation EndLoc) { |
| 6436 | Expr *ValExpr = NumThreads; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6437 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6438 | // OpenMP [2.5, Restrictions] |
| 6439 | // The num_threads expression must evaluate to a positive integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6440 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_num_threads, |
| 6441 | /*StrictlyPositive=*/true)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6442 | return nullptr; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6443 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6444 | return new (Context) |
| 6445 | OMPNumThreadsClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6446 | } |
| 6447 | |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6448 | ExprResult Sema::VerifyPositiveIntegerConstantInClause(Expr *E, |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 6449 | OpenMPClauseKind CKind, |
| 6450 | bool StrictlyPositive) { |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6451 | if (!E) |
| 6452 | return ExprError(); |
| 6453 | if (E->isValueDependent() || E->isTypeDependent() || |
| 6454 | E->isInstantiationDependent() || E->containsUnexpandedParameterPack()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6455 | return E; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6456 | llvm::APSInt Result; |
| 6457 | ExprResult ICE = VerifyIntegerConstantExpression(E, &Result); |
| 6458 | if (ICE.isInvalid()) |
| 6459 | return ExprError(); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 6460 | if ((StrictlyPositive && !Result.isStrictlyPositive()) || |
| 6461 | (!StrictlyPositive && !Result.isNonNegative())) { |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6462 | Diag(E->getExprLoc(), diag::err_omp_negative_expression_in_clause) |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 6463 | << getOpenMPClauseName(CKind) << (StrictlyPositive ? 1 : 0) |
| 6464 | << E->getSourceRange(); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6465 | return ExprError(); |
| 6466 | } |
Alexander Musman | 09184fe | 2014-09-30 05:29:28 +0000 | [diff] [blame] | 6467 | if (CKind == OMPC_aligned && !Result.isPowerOf2()) { |
| 6468 | Diag(E->getExprLoc(), diag::warn_omp_alignment_not_power_of_two) |
| 6469 | << E->getSourceRange(); |
| 6470 | return ExprError(); |
| 6471 | } |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 6472 | if (CKind == OMPC_collapse && DSAStack->getAssociatedLoops() == 1) |
| 6473 | DSAStack->setAssociatedLoops(Result.getExtValue()); |
Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 6474 | else if (CKind == OMPC_ordered) |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 6475 | DSAStack->setAssociatedLoops(Result.getExtValue()); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6476 | return ICE; |
| 6477 | } |
| 6478 | |
| 6479 | OMPClause *Sema::ActOnOpenMPSafelenClause(Expr *Len, SourceLocation StartLoc, |
| 6480 | SourceLocation LParenLoc, |
| 6481 | SourceLocation EndLoc) { |
| 6482 | // OpenMP [2.8.1, simd construct, Description] |
| 6483 | // The parameter of the safelen clause must be a constant |
| 6484 | // positive integer expression. |
| 6485 | ExprResult Safelen = VerifyPositiveIntegerConstantInClause(Len, OMPC_safelen); |
| 6486 | if (Safelen.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6487 | return nullptr; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6488 | return new (Context) |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6489 | OMPSafelenClause(Safelen.get(), StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6490 | } |
| 6491 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 6492 | OMPClause *Sema::ActOnOpenMPSimdlenClause(Expr *Len, SourceLocation StartLoc, |
| 6493 | SourceLocation LParenLoc, |
| 6494 | SourceLocation EndLoc) { |
| 6495 | // OpenMP [2.8.1, simd construct, Description] |
| 6496 | // The parameter of the simdlen clause must be a constant |
| 6497 | // positive integer expression. |
| 6498 | ExprResult Simdlen = VerifyPositiveIntegerConstantInClause(Len, OMPC_simdlen); |
| 6499 | if (Simdlen.isInvalid()) |
| 6500 | return nullptr; |
| 6501 | return new (Context) |
| 6502 | OMPSimdlenClause(Simdlen.get(), StartLoc, LParenLoc, EndLoc); |
| 6503 | } |
| 6504 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6505 | OMPClause *Sema::ActOnOpenMPCollapseClause(Expr *NumForLoops, |
| 6506 | SourceLocation StartLoc, |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6507 | SourceLocation LParenLoc, |
| 6508 | SourceLocation EndLoc) { |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6509 | // OpenMP [2.7.1, loop construct, Description] |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6510 | // OpenMP [2.8.1, simd construct, Description] |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6511 | // OpenMP [2.9.6, distribute construct, Description] |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6512 | // The parameter of the collapse clause must be a constant |
| 6513 | // positive integer expression. |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6514 | ExprResult NumForLoopsResult = |
| 6515 | VerifyPositiveIntegerConstantInClause(NumForLoops, OMPC_collapse); |
| 6516 | if (NumForLoopsResult.isInvalid()) |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6517 | return nullptr; |
| 6518 | return new (Context) |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6519 | OMPCollapseClause(NumForLoopsResult.get(), StartLoc, LParenLoc, EndLoc); |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6520 | } |
| 6521 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 6522 | OMPClause *Sema::ActOnOpenMPOrderedClause(SourceLocation StartLoc, |
| 6523 | SourceLocation EndLoc, |
| 6524 | SourceLocation LParenLoc, |
| 6525 | Expr *NumForLoops) { |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 6526 | // OpenMP [2.7.1, loop construct, Description] |
| 6527 | // OpenMP [2.8.1, simd construct, Description] |
| 6528 | // OpenMP [2.9.6, distribute construct, Description] |
| 6529 | // The parameter of the ordered clause must be a constant |
| 6530 | // positive integer expression if any. |
| 6531 | if (NumForLoops && LParenLoc.isValid()) { |
| 6532 | ExprResult NumForLoopsResult = |
| 6533 | VerifyPositiveIntegerConstantInClause(NumForLoops, OMPC_ordered); |
| 6534 | if (NumForLoopsResult.isInvalid()) |
| 6535 | return nullptr; |
| 6536 | NumForLoops = NumForLoopsResult.get(); |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6537 | } else |
| 6538 | NumForLoops = nullptr; |
| 6539 | DSAStack->setOrderedRegion(/*IsOrdered=*/true, NumForLoops); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 6540 | return new (Context) |
| 6541 | OMPOrderedClause(NumForLoops, StartLoc, LParenLoc, EndLoc); |
| 6542 | } |
| 6543 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6544 | OMPClause *Sema::ActOnOpenMPSimpleClause( |
| 6545 | OpenMPClauseKind Kind, unsigned Argument, SourceLocation ArgumentLoc, |
| 6546 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6547 | OMPClause *Res = nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6548 | switch (Kind) { |
| 6549 | case OMPC_default: |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6550 | Res = |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6551 | ActOnOpenMPDefaultClause(static_cast<OpenMPDefaultClauseKind>(Argument), |
| 6552 | ArgumentLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6553 | break; |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6554 | case OMPC_proc_bind: |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6555 | Res = ActOnOpenMPProcBindClause( |
| 6556 | static_cast<OpenMPProcBindClauseKind>(Argument), ArgumentLoc, StartLoc, |
| 6557 | LParenLoc, EndLoc); |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6558 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6559 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 6560 | case OMPC_final: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6561 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6562 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 6563 | case OMPC_simdlen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6564 | case OMPC_collapse: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6565 | case OMPC_schedule: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6566 | case OMPC_private: |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6567 | case OMPC_firstprivate: |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6568 | case OMPC_lastprivate: |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6569 | case OMPC_shared: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6570 | case OMPC_reduction: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6571 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 6572 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6573 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6574 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6575 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6576 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 6577 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 6578 | case OMPC_mergeable: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6579 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 6580 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6581 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6582 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6583 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6584 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 6585 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6586 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 6587 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6588 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6589 | case OMPC_simd: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 6590 | case OMPC_map: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 6591 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6592 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6593 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 6594 | case OMPC_grainsize: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 6595 | case OMPC_nogroup: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6596 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 6597 | case OMPC_hint: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 6598 | case OMPC_dist_schedule: |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 6599 | case OMPC_defaultmap: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6600 | case OMPC_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6601 | llvm_unreachable("Clause is not allowed."); |
| 6602 | } |
| 6603 | return Res; |
| 6604 | } |
| 6605 | |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6606 | static std::string |
| 6607 | getListOfPossibleValues(OpenMPClauseKind K, unsigned First, unsigned Last, |
| 6608 | ArrayRef<unsigned> Exclude = llvm::None) { |
| 6609 | std::string Values; |
| 6610 | unsigned Bound = Last >= 2 ? Last - 2 : 0; |
| 6611 | unsigned Skipped = Exclude.size(); |
| 6612 | auto S = Exclude.begin(), E = Exclude.end(); |
| 6613 | for (unsigned i = First; i < Last; ++i) { |
| 6614 | if (std::find(S, E, i) != E) { |
| 6615 | --Skipped; |
| 6616 | continue; |
| 6617 | } |
| 6618 | Values += "'"; |
| 6619 | Values += getOpenMPSimpleClauseTypeName(K, i); |
| 6620 | Values += "'"; |
| 6621 | if (i == Bound - Skipped) |
| 6622 | Values += " or "; |
| 6623 | else if (i != Bound + 1 - Skipped) |
| 6624 | Values += ", "; |
| 6625 | } |
| 6626 | return Values; |
| 6627 | } |
| 6628 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6629 | OMPClause *Sema::ActOnOpenMPDefaultClause(OpenMPDefaultClauseKind Kind, |
| 6630 | SourceLocation KindKwLoc, |
| 6631 | SourceLocation StartLoc, |
| 6632 | SourceLocation LParenLoc, |
| 6633 | SourceLocation EndLoc) { |
| 6634 | if (Kind == OMPC_DEFAULT_unknown) { |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 6635 | static_assert(OMPC_DEFAULT_unknown > 0, |
| 6636 | "OMPC_DEFAULT_unknown not greater than 0"); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6637 | Diag(KindKwLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6638 | << getListOfPossibleValues(OMPC_default, /*First=*/0, |
| 6639 | /*Last=*/OMPC_DEFAULT_unknown) |
| 6640 | << getOpenMPClauseName(OMPC_default); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6641 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6642 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6643 | switch (Kind) { |
| 6644 | case OMPC_DEFAULT_none: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6645 | DSAStack->setDefaultDSANone(KindKwLoc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6646 | break; |
| 6647 | case OMPC_DEFAULT_shared: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6648 | DSAStack->setDefaultDSAShared(KindKwLoc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6649 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6650 | case OMPC_DEFAULT_unknown: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6651 | llvm_unreachable("Clause kind is not allowed."); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6652 | break; |
| 6653 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6654 | return new (Context) |
| 6655 | OMPDefaultClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6656 | } |
| 6657 | |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6658 | OMPClause *Sema::ActOnOpenMPProcBindClause(OpenMPProcBindClauseKind Kind, |
| 6659 | SourceLocation KindKwLoc, |
| 6660 | SourceLocation StartLoc, |
| 6661 | SourceLocation LParenLoc, |
| 6662 | SourceLocation EndLoc) { |
| 6663 | if (Kind == OMPC_PROC_BIND_unknown) { |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6664 | Diag(KindKwLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6665 | << getListOfPossibleValues(OMPC_proc_bind, /*First=*/0, |
| 6666 | /*Last=*/OMPC_PROC_BIND_unknown) |
| 6667 | << getOpenMPClauseName(OMPC_proc_bind); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6668 | return nullptr; |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6669 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6670 | return new (Context) |
| 6671 | OMPProcBindClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6672 | } |
| 6673 | |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6674 | OMPClause *Sema::ActOnOpenMPSingleExprWithArgClause( |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6675 | OpenMPClauseKind Kind, ArrayRef<unsigned> Argument, Expr *Expr, |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6676 | SourceLocation StartLoc, SourceLocation LParenLoc, |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6677 | ArrayRef<SourceLocation> ArgumentLoc, SourceLocation DelimLoc, |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6678 | SourceLocation EndLoc) { |
| 6679 | OMPClause *Res = nullptr; |
| 6680 | switch (Kind) { |
| 6681 | case OMPC_schedule: |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6682 | enum { Modifier1, Modifier2, ScheduleKind, NumberOfElements }; |
| 6683 | assert(Argument.size() == NumberOfElements && |
| 6684 | ArgumentLoc.size() == NumberOfElements); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6685 | Res = ActOnOpenMPScheduleClause( |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6686 | static_cast<OpenMPScheduleClauseModifier>(Argument[Modifier1]), |
| 6687 | static_cast<OpenMPScheduleClauseModifier>(Argument[Modifier2]), |
| 6688 | static_cast<OpenMPScheduleClauseKind>(Argument[ScheduleKind]), Expr, |
| 6689 | StartLoc, LParenLoc, ArgumentLoc[Modifier1], ArgumentLoc[Modifier2], |
| 6690 | ArgumentLoc[ScheduleKind], DelimLoc, EndLoc); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6691 | break; |
| 6692 | case OMPC_if: |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6693 | assert(Argument.size() == 1 && ArgumentLoc.size() == 1); |
| 6694 | Res = ActOnOpenMPIfClause(static_cast<OpenMPDirectiveKind>(Argument.back()), |
| 6695 | Expr, StartLoc, LParenLoc, ArgumentLoc.back(), |
| 6696 | DelimLoc, EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6697 | break; |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 6698 | case OMPC_dist_schedule: |
| 6699 | Res = ActOnOpenMPDistScheduleClause( |
| 6700 | static_cast<OpenMPDistScheduleClauseKind>(Argument.back()), Expr, |
| 6701 | StartLoc, LParenLoc, ArgumentLoc.back(), DelimLoc, EndLoc); |
| 6702 | break; |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 6703 | case OMPC_defaultmap: |
| 6704 | enum { Modifier, DefaultmapKind }; |
| 6705 | Res = ActOnOpenMPDefaultmapClause( |
| 6706 | static_cast<OpenMPDefaultmapClauseModifier>(Argument[Modifier]), |
| 6707 | static_cast<OpenMPDefaultmapClauseKind>(Argument[DefaultmapKind]), |
| 6708 | StartLoc, LParenLoc, ArgumentLoc[Modifier], |
| 6709 | ArgumentLoc[DefaultmapKind], EndLoc); |
| 6710 | break; |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 6711 | case OMPC_final: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6712 | case OMPC_num_threads: |
| 6713 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 6714 | case OMPC_simdlen: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6715 | case OMPC_collapse: |
| 6716 | case OMPC_default: |
| 6717 | case OMPC_proc_bind: |
| 6718 | case OMPC_private: |
| 6719 | case OMPC_firstprivate: |
| 6720 | case OMPC_lastprivate: |
| 6721 | case OMPC_shared: |
| 6722 | case OMPC_reduction: |
| 6723 | case OMPC_linear: |
| 6724 | case OMPC_aligned: |
| 6725 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6726 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6727 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6728 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 6729 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 6730 | case OMPC_mergeable: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6731 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 6732 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6733 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6734 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6735 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6736 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 6737 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6738 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 6739 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6740 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6741 | case OMPC_simd: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 6742 | case OMPC_map: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 6743 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6744 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6745 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 6746 | case OMPC_grainsize: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 6747 | case OMPC_nogroup: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6748 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 6749 | case OMPC_hint: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6750 | case OMPC_unknown: |
| 6751 | llvm_unreachable("Clause is not allowed."); |
| 6752 | } |
| 6753 | return Res; |
| 6754 | } |
| 6755 | |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6756 | static bool checkScheduleModifiers(Sema &S, OpenMPScheduleClauseModifier M1, |
| 6757 | OpenMPScheduleClauseModifier M2, |
| 6758 | SourceLocation M1Loc, SourceLocation M2Loc) { |
| 6759 | if (M1 == OMPC_SCHEDULE_MODIFIER_unknown && M1Loc.isValid()) { |
| 6760 | SmallVector<unsigned, 2> Excluded; |
| 6761 | if (M2 != OMPC_SCHEDULE_MODIFIER_unknown) |
| 6762 | Excluded.push_back(M2); |
| 6763 | if (M2 == OMPC_SCHEDULE_MODIFIER_nonmonotonic) |
| 6764 | Excluded.push_back(OMPC_SCHEDULE_MODIFIER_monotonic); |
| 6765 | if (M2 == OMPC_SCHEDULE_MODIFIER_monotonic) |
| 6766 | Excluded.push_back(OMPC_SCHEDULE_MODIFIER_nonmonotonic); |
| 6767 | S.Diag(M1Loc, diag::err_omp_unexpected_clause_value) |
| 6768 | << getListOfPossibleValues(OMPC_schedule, |
| 6769 | /*First=*/OMPC_SCHEDULE_MODIFIER_unknown + 1, |
| 6770 | /*Last=*/OMPC_SCHEDULE_MODIFIER_last, |
| 6771 | Excluded) |
| 6772 | << getOpenMPClauseName(OMPC_schedule); |
| 6773 | return true; |
| 6774 | } |
| 6775 | return false; |
| 6776 | } |
| 6777 | |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6778 | OMPClause *Sema::ActOnOpenMPScheduleClause( |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6779 | OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2, |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6780 | OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6781 | SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc, |
| 6782 | SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) { |
| 6783 | if (checkScheduleModifiers(*this, M1, M2, M1Loc, M2Loc) || |
| 6784 | checkScheduleModifiers(*this, M2, M1, M2Loc, M1Loc)) |
| 6785 | return nullptr; |
| 6786 | // OpenMP, 2.7.1, Loop Construct, Restrictions |
| 6787 | // Either the monotonic modifier or the nonmonotonic modifier can be specified |
| 6788 | // but not both. |
| 6789 | if ((M1 == M2 && M1 != OMPC_SCHEDULE_MODIFIER_unknown) || |
| 6790 | (M1 == OMPC_SCHEDULE_MODIFIER_monotonic && |
| 6791 | M2 == OMPC_SCHEDULE_MODIFIER_nonmonotonic) || |
| 6792 | (M1 == OMPC_SCHEDULE_MODIFIER_nonmonotonic && |
| 6793 | M2 == OMPC_SCHEDULE_MODIFIER_monotonic)) { |
| 6794 | Diag(M2Loc, diag::err_omp_unexpected_schedule_modifier) |
| 6795 | << getOpenMPSimpleClauseTypeName(OMPC_schedule, M2) |
| 6796 | << getOpenMPSimpleClauseTypeName(OMPC_schedule, M1); |
| 6797 | return nullptr; |
| 6798 | } |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6799 | if (Kind == OMPC_SCHEDULE_unknown) { |
| 6800 | std::string Values; |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6801 | if (M1Loc.isInvalid() && M2Loc.isInvalid()) { |
| 6802 | unsigned Exclude[] = {OMPC_SCHEDULE_unknown}; |
| 6803 | Values = getListOfPossibleValues(OMPC_schedule, /*First=*/0, |
| 6804 | /*Last=*/OMPC_SCHEDULE_MODIFIER_last, |
| 6805 | Exclude); |
| 6806 | } else { |
| 6807 | Values = getListOfPossibleValues(OMPC_schedule, /*First=*/0, |
| 6808 | /*Last=*/OMPC_SCHEDULE_unknown); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6809 | } |
| 6810 | Diag(KindLoc, diag::err_omp_unexpected_clause_value) |
| 6811 | << Values << getOpenMPClauseName(OMPC_schedule); |
| 6812 | return nullptr; |
| 6813 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6814 | // OpenMP, 2.7.1, Loop Construct, Restrictions |
| 6815 | // The nonmonotonic modifier can only be specified with schedule(dynamic) or |
| 6816 | // schedule(guided). |
| 6817 | if ((M1 == OMPC_SCHEDULE_MODIFIER_nonmonotonic || |
| 6818 | M2 == OMPC_SCHEDULE_MODIFIER_nonmonotonic) && |
| 6819 | Kind != OMPC_SCHEDULE_dynamic && Kind != OMPC_SCHEDULE_guided) { |
| 6820 | Diag(M1 == OMPC_SCHEDULE_MODIFIER_nonmonotonic ? M1Loc : M2Loc, |
| 6821 | diag::err_omp_schedule_nonmonotonic_static); |
| 6822 | return nullptr; |
| 6823 | } |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6824 | Expr *ValExpr = ChunkSize; |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 6825 | Stmt *HelperValStmt = nullptr; |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6826 | if (ChunkSize) { |
| 6827 | if (!ChunkSize->isValueDependent() && !ChunkSize->isTypeDependent() && |
| 6828 | !ChunkSize->isInstantiationDependent() && |
| 6829 | !ChunkSize->containsUnexpandedParameterPack()) { |
| 6830 | SourceLocation ChunkSizeLoc = ChunkSize->getLocStart(); |
| 6831 | ExprResult Val = |
| 6832 | PerformOpenMPImplicitIntegerConversion(ChunkSizeLoc, ChunkSize); |
| 6833 | if (Val.isInvalid()) |
| 6834 | return nullptr; |
| 6835 | |
| 6836 | ValExpr = Val.get(); |
| 6837 | |
| 6838 | // OpenMP [2.7.1, Restrictions] |
| 6839 | // chunk_size must be a loop invariant integer expression with a positive |
| 6840 | // value. |
| 6841 | llvm::APSInt Result; |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 6842 | if (ValExpr->isIntegerConstantExpr(Result, Context)) { |
| 6843 | if (Result.isSigned() && !Result.isStrictlyPositive()) { |
| 6844 | Diag(ChunkSizeLoc, diag::err_omp_negative_expression_in_clause) |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6845 | << "schedule" << 1 << ChunkSize->getSourceRange(); |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 6846 | return nullptr; |
| 6847 | } |
| 6848 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective())) { |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 6849 | ValExpr = buildCapture(*this, ValExpr); |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 6850 | Decl *D = cast<DeclRefExpr>(ValExpr)->getDecl(); |
| 6851 | HelperValStmt = |
| 6852 | new (Context) DeclStmt(DeclGroupRef::Create(Context, &D, |
| 6853 | /*NumDecls=*/1), |
| 6854 | SourceLocation(), SourceLocation()); |
| 6855 | ValExpr = DefaultLvalueConversion(ValExpr).get(); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6856 | } |
| 6857 | } |
| 6858 | } |
| 6859 | |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6860 | return new (Context) |
| 6861 | OMPScheduleClause(StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc, Kind, |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 6862 | ValExpr, HelperValStmt, M1, M1Loc, M2, M2Loc); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6863 | } |
| 6864 | |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6865 | OMPClause *Sema::ActOnOpenMPClause(OpenMPClauseKind Kind, |
| 6866 | SourceLocation StartLoc, |
| 6867 | SourceLocation EndLoc) { |
| 6868 | OMPClause *Res = nullptr; |
| 6869 | switch (Kind) { |
| 6870 | case OMPC_ordered: |
| 6871 | Res = ActOnOpenMPOrderedClause(StartLoc, EndLoc); |
| 6872 | break; |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6873 | case OMPC_nowait: |
| 6874 | Res = ActOnOpenMPNowaitClause(StartLoc, EndLoc); |
| 6875 | break; |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 6876 | case OMPC_untied: |
| 6877 | Res = ActOnOpenMPUntiedClause(StartLoc, EndLoc); |
| 6878 | break; |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 6879 | case OMPC_mergeable: |
| 6880 | Res = ActOnOpenMPMergeableClause(StartLoc, EndLoc); |
| 6881 | break; |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6882 | case OMPC_read: |
| 6883 | Res = ActOnOpenMPReadClause(StartLoc, EndLoc); |
| 6884 | break; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6885 | case OMPC_write: |
| 6886 | Res = ActOnOpenMPWriteClause(StartLoc, EndLoc); |
| 6887 | break; |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6888 | case OMPC_update: |
| 6889 | Res = ActOnOpenMPUpdateClause(StartLoc, EndLoc); |
| 6890 | break; |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6891 | case OMPC_capture: |
| 6892 | Res = ActOnOpenMPCaptureClause(StartLoc, EndLoc); |
| 6893 | break; |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 6894 | case OMPC_seq_cst: |
| 6895 | Res = ActOnOpenMPSeqCstClause(StartLoc, EndLoc); |
| 6896 | break; |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6897 | case OMPC_threads: |
| 6898 | Res = ActOnOpenMPThreadsClause(StartLoc, EndLoc); |
| 6899 | break; |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6900 | case OMPC_simd: |
| 6901 | Res = ActOnOpenMPSIMDClause(StartLoc, EndLoc); |
| 6902 | break; |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 6903 | case OMPC_nogroup: |
| 6904 | Res = ActOnOpenMPNogroupClause(StartLoc, EndLoc); |
| 6905 | break; |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6906 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 6907 | case OMPC_final: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6908 | case OMPC_num_threads: |
| 6909 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 6910 | case OMPC_simdlen: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6911 | case OMPC_collapse: |
| 6912 | case OMPC_schedule: |
| 6913 | case OMPC_private: |
| 6914 | case OMPC_firstprivate: |
| 6915 | case OMPC_lastprivate: |
| 6916 | case OMPC_shared: |
| 6917 | case OMPC_reduction: |
| 6918 | case OMPC_linear: |
| 6919 | case OMPC_aligned: |
| 6920 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6921 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6922 | case OMPC_default: |
| 6923 | case OMPC_proc_bind: |
| 6924 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 6925 | case OMPC_flush: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6926 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 6927 | case OMPC_device: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 6928 | case OMPC_map: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 6929 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6930 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6931 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 6932 | case OMPC_grainsize: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6933 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 6934 | case OMPC_hint: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 6935 | case OMPC_dist_schedule: |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 6936 | case OMPC_defaultmap: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6937 | case OMPC_unknown: |
| 6938 | llvm_unreachable("Clause is not allowed."); |
| 6939 | } |
| 6940 | return Res; |
| 6941 | } |
| 6942 | |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6943 | OMPClause *Sema::ActOnOpenMPNowaitClause(SourceLocation StartLoc, |
| 6944 | SourceLocation EndLoc) { |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 6945 | DSAStack->setNowaitRegion(); |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6946 | return new (Context) OMPNowaitClause(StartLoc, EndLoc); |
| 6947 | } |
| 6948 | |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 6949 | OMPClause *Sema::ActOnOpenMPUntiedClause(SourceLocation StartLoc, |
| 6950 | SourceLocation EndLoc) { |
| 6951 | return new (Context) OMPUntiedClause(StartLoc, EndLoc); |
| 6952 | } |
| 6953 | |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 6954 | OMPClause *Sema::ActOnOpenMPMergeableClause(SourceLocation StartLoc, |
| 6955 | SourceLocation EndLoc) { |
| 6956 | return new (Context) OMPMergeableClause(StartLoc, EndLoc); |
| 6957 | } |
| 6958 | |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6959 | OMPClause *Sema::ActOnOpenMPReadClause(SourceLocation StartLoc, |
| 6960 | SourceLocation EndLoc) { |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6961 | return new (Context) OMPReadClause(StartLoc, EndLoc); |
| 6962 | } |
| 6963 | |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6964 | OMPClause *Sema::ActOnOpenMPWriteClause(SourceLocation StartLoc, |
| 6965 | SourceLocation EndLoc) { |
| 6966 | return new (Context) OMPWriteClause(StartLoc, EndLoc); |
| 6967 | } |
| 6968 | |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6969 | OMPClause *Sema::ActOnOpenMPUpdateClause(SourceLocation StartLoc, |
| 6970 | SourceLocation EndLoc) { |
| 6971 | return new (Context) OMPUpdateClause(StartLoc, EndLoc); |
| 6972 | } |
| 6973 | |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6974 | OMPClause *Sema::ActOnOpenMPCaptureClause(SourceLocation StartLoc, |
| 6975 | SourceLocation EndLoc) { |
| 6976 | return new (Context) OMPCaptureClause(StartLoc, EndLoc); |
| 6977 | } |
| 6978 | |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 6979 | OMPClause *Sema::ActOnOpenMPSeqCstClause(SourceLocation StartLoc, |
| 6980 | SourceLocation EndLoc) { |
| 6981 | return new (Context) OMPSeqCstClause(StartLoc, EndLoc); |
| 6982 | } |
| 6983 | |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6984 | OMPClause *Sema::ActOnOpenMPThreadsClause(SourceLocation StartLoc, |
| 6985 | SourceLocation EndLoc) { |
| 6986 | return new (Context) OMPThreadsClause(StartLoc, EndLoc); |
| 6987 | } |
| 6988 | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6989 | OMPClause *Sema::ActOnOpenMPSIMDClause(SourceLocation StartLoc, |
| 6990 | SourceLocation EndLoc) { |
| 6991 | return new (Context) OMPSIMDClause(StartLoc, EndLoc); |
| 6992 | } |
| 6993 | |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 6994 | OMPClause *Sema::ActOnOpenMPNogroupClause(SourceLocation StartLoc, |
| 6995 | SourceLocation EndLoc) { |
| 6996 | return new (Context) OMPNogroupClause(StartLoc, EndLoc); |
| 6997 | } |
| 6998 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6999 | OMPClause *Sema::ActOnOpenMPVarListClause( |
| 7000 | OpenMPClauseKind Kind, ArrayRef<Expr *> VarList, Expr *TailExpr, |
| 7001 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, |
| 7002 | SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 7003 | const DeclarationNameInfo &ReductionId, OpenMPDependClauseKind DepKind, |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 7004 | OpenMPLinearClauseKind LinKind, OpenMPMapClauseKind MapTypeModifier, |
| 7005 | OpenMPMapClauseKind MapType, bool IsMapTypeImplicit, |
| 7006 | SourceLocation DepLinMapLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 7007 | OMPClause *Res = nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7008 | switch (Kind) { |
| 7009 | case OMPC_private: |
| 7010 | Res = ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7011 | break; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7012 | case OMPC_firstprivate: |
| 7013 | Res = ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7014 | break; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7015 | case OMPC_lastprivate: |
| 7016 | Res = ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7017 | break; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7018 | case OMPC_shared: |
| 7019 | Res = ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7020 | break; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7021 | case OMPC_reduction: |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 7022 | Res = ActOnOpenMPReductionClause(VarList, StartLoc, LParenLoc, ColonLoc, |
| 7023 | EndLoc, ReductionIdScopeSpec, ReductionId); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7024 | break; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7025 | case OMPC_linear: |
| 7026 | Res = ActOnOpenMPLinearClause(VarList, TailExpr, StartLoc, LParenLoc, |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 7027 | LinKind, DepLinMapLoc, ColonLoc, EndLoc); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7028 | break; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 7029 | case OMPC_aligned: |
| 7030 | Res = ActOnOpenMPAlignedClause(VarList, TailExpr, StartLoc, LParenLoc, |
| 7031 | ColonLoc, EndLoc); |
| 7032 | break; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7033 | case OMPC_copyin: |
| 7034 | Res = ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7035 | break; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7036 | case OMPC_copyprivate: |
| 7037 | Res = ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7038 | break; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 7039 | case OMPC_flush: |
| 7040 | Res = ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7041 | break; |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 7042 | case OMPC_depend: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 7043 | Res = ActOnOpenMPDependClause(DepKind, DepLinMapLoc, ColonLoc, VarList, |
| 7044 | StartLoc, LParenLoc, EndLoc); |
| 7045 | break; |
| 7046 | case OMPC_map: |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 7047 | Res = ActOnOpenMPMapClause(MapTypeModifier, MapType, IsMapTypeImplicit, |
| 7048 | DepLinMapLoc, ColonLoc, VarList, StartLoc, |
| 7049 | LParenLoc, EndLoc); |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 7050 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7051 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 7052 | case OMPC_final: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7053 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 7054 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 7055 | case OMPC_simdlen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 7056 | case OMPC_collapse: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7057 | case OMPC_default: |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 7058 | case OMPC_proc_bind: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7059 | case OMPC_schedule: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7060 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 7061 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 7062 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 7063 | case OMPC_mergeable: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7064 | case OMPC_threadprivate: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 7065 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 7066 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 7067 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 7068 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 7069 | case OMPC_seq_cst: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 7070 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 7071 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 7072 | case OMPC_simd: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 7073 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7074 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 7075 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 7076 | case OMPC_grainsize: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 7077 | case OMPC_nogroup: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 7078 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 7079 | case OMPC_hint: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 7080 | case OMPC_dist_schedule: |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 7081 | case OMPC_defaultmap: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7082 | case OMPC_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7083 | llvm_unreachable("Clause is not allowed."); |
| 7084 | } |
| 7085 | return Res; |
| 7086 | } |
| 7087 | |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 7088 | ExprResult Sema::getOpenMPCapturedExpr(VarDecl *Capture, ExprValueKind VK, |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 7089 | ExprObjectKind OK, SourceLocation Loc) { |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 7090 | ExprResult Res = BuildDeclRefExpr( |
| 7091 | Capture, Capture->getType().getNonReferenceType(), VK_LValue, Loc); |
| 7092 | if (!Res.isUsable()) |
| 7093 | return ExprError(); |
| 7094 | if (OK == OK_Ordinary && !getLangOpts().CPlusPlus) { |
| 7095 | Res = CreateBuiltinUnaryOp(Loc, UO_Deref, Res.get()); |
| 7096 | if (!Res.isUsable()) |
| 7097 | return ExprError(); |
| 7098 | } |
| 7099 | if (VK != VK_LValue && Res.get()->isGLValue()) { |
| 7100 | Res = DefaultLvalueConversion(Res.get()); |
| 7101 | if (!Res.isUsable()) |
| 7102 | return ExprError(); |
| 7103 | } |
| 7104 | return Res; |
| 7105 | } |
| 7106 | |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7107 | static std::pair<ValueDecl *, bool> |
| 7108 | getPrivateItem(Sema &S, Expr *&RefExpr, SourceLocation &ELoc, |
| 7109 | SourceRange &ERange, bool AllowArraySection = false) { |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7110 | if (RefExpr->isTypeDependent() || RefExpr->isValueDependent() || |
| 7111 | RefExpr->containsUnexpandedParameterPack()) |
| 7112 | return std::make_pair(nullptr, true); |
| 7113 | |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7114 | // OpenMP [3.1, C/C++] |
| 7115 | // A list item is a variable name. |
| 7116 | // OpenMP [2.9.3.3, Restrictions, p.1] |
| 7117 | // A variable that is part of another variable (as an array or |
| 7118 | // structure element) cannot appear in a private clause. |
| 7119 | RefExpr = RefExpr->IgnoreParens(); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7120 | enum { |
| 7121 | NoArrayExpr = -1, |
| 7122 | ArraySubscript = 0, |
| 7123 | OMPArraySection = 1 |
| 7124 | } IsArrayExpr = NoArrayExpr; |
| 7125 | if (AllowArraySection) { |
| 7126 | if (auto *ASE = dyn_cast_or_null<ArraySubscriptExpr>(RefExpr)) { |
| 7127 | auto *Base = ASE->getBase()->IgnoreParenImpCasts(); |
| 7128 | while (auto *TempASE = dyn_cast<ArraySubscriptExpr>(Base)) |
| 7129 | Base = TempASE->getBase()->IgnoreParenImpCasts(); |
| 7130 | RefExpr = Base; |
| 7131 | IsArrayExpr = ArraySubscript; |
| 7132 | } else if (auto *OASE = dyn_cast_or_null<OMPArraySectionExpr>(RefExpr)) { |
| 7133 | auto *Base = OASE->getBase()->IgnoreParenImpCasts(); |
| 7134 | while (auto *TempOASE = dyn_cast<OMPArraySectionExpr>(Base)) |
| 7135 | Base = TempOASE->getBase()->IgnoreParenImpCasts(); |
| 7136 | while (auto *TempASE = dyn_cast<ArraySubscriptExpr>(Base)) |
| 7137 | Base = TempASE->getBase()->IgnoreParenImpCasts(); |
| 7138 | RefExpr = Base; |
| 7139 | IsArrayExpr = OMPArraySection; |
| 7140 | } |
| 7141 | } |
| 7142 | ELoc = RefExpr->getExprLoc(); |
| 7143 | ERange = RefExpr->getSourceRange(); |
| 7144 | RefExpr = RefExpr->IgnoreParenImpCasts(); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7145 | auto *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr); |
| 7146 | auto *ME = dyn_cast_or_null<MemberExpr>(RefExpr); |
| 7147 | if ((!DE || !isa<VarDecl>(DE->getDecl())) && |
| 7148 | (S.getCurrentThisType().isNull() || !ME || |
| 7149 | !isa<CXXThisExpr>(ME->getBase()->IgnoreParenImpCasts()) || |
| 7150 | !isa<FieldDecl>(ME->getMemberDecl()))) { |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7151 | if (IsArrayExpr != NoArrayExpr) |
| 7152 | S.Diag(ELoc, diag::err_omp_expected_base_var_name) << IsArrayExpr |
| 7153 | << ERange; |
| 7154 | else { |
| 7155 | S.Diag(ELoc, |
| 7156 | AllowArraySection |
| 7157 | ? diag::err_omp_expected_var_name_member_expr_or_array_item |
| 7158 | : diag::err_omp_expected_var_name_member_expr) |
| 7159 | << (S.getCurrentThisType().isNull() ? 0 : 1) << ERange; |
| 7160 | } |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7161 | return std::make_pair(nullptr, false); |
| 7162 | } |
| 7163 | return std::make_pair(DE ? DE->getDecl() : ME->getMemberDecl(), false); |
| 7164 | } |
| 7165 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7166 | OMPClause *Sema::ActOnOpenMPPrivateClause(ArrayRef<Expr *> VarList, |
| 7167 | SourceLocation StartLoc, |
| 7168 | SourceLocation LParenLoc, |
| 7169 | SourceLocation EndLoc) { |
| 7170 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 7171 | SmallVector<Expr *, 8> PrivateCopies; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7172 | for (auto &RefExpr : VarList) { |
| 7173 | assert(RefExpr && "NULL expr in OpenMP private clause."); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7174 | SourceLocation ELoc; |
| 7175 | SourceRange ERange; |
| 7176 | Expr *SimpleRefExpr = RefExpr; |
| 7177 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7178 | if (Res.second) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7179 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7180 | Vars.push_back(RefExpr); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 7181 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7182 | } |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7183 | ValueDecl *D = Res.first; |
| 7184 | if (!D) |
| 7185 | continue; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7186 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7187 | QualType Type = D->getType(); |
| 7188 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7189 | |
| 7190 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 7191 | // A variable that appears in a private clause must not have an incomplete |
| 7192 | // type or a reference type. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7193 | if (RequireCompleteType(ELoc, Type, diag::err_omp_private_incomplete_type)) |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7194 | continue; |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7195 | Type = Type.getNonReferenceType(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7196 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7197 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 7198 | // in a Construct] |
| 7199 | // Variables with the predetermined data-sharing attributes may not be |
| 7200 | // listed in data-sharing attributes clauses, except for the cases |
| 7201 | // listed below. For these exceptions only, listing a predetermined |
| 7202 | // variable in a data-sharing attribute clause is allowed and overrides |
| 7203 | // the variable's predetermined data-sharing attributes. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7204 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7205 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_private) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7206 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 7207 | << getOpenMPClauseName(OMPC_private); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7208 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7209 | continue; |
| 7210 | } |
| 7211 | |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7212 | // Variably modified types are not supported for tasks. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 7213 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType() && |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7214 | DSAStack->getCurrentDirective() == OMPD_task) { |
| 7215 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
| 7216 | << getOpenMPClauseName(OMPC_private) << Type |
| 7217 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 7218 | bool IsDecl = |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7219 | !VD || |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7220 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7221 | Diag(D->getLocation(), |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7222 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7223 | << D; |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7224 | continue; |
| 7225 | } |
| 7226 | |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7227 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.1] |
| 7228 | // A variable of class type (or array thereof) that appears in a private |
| 7229 | // clause requires an accessible, unambiguous default constructor for the |
| 7230 | // class type. |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 7231 | // Generate helper private variable and initialize it with the default |
| 7232 | // value. The address of the original variable is replaced by the address of |
| 7233 | // the new private variable in CodeGen. This new variable is not added to |
| 7234 | // IdResolver, so the code in the OpenMP region uses original variable for |
| 7235 | // proper diagnostics. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7236 | Type = Type.getUnqualifiedType(); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7237 | auto VDPrivate = buildVarDecl(*this, ELoc, Type, D->getName(), |
| 7238 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7239 | ActOnUninitializedDecl(VDPrivate, /*TypeMayContainAuto=*/false); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 7240 | if (VDPrivate->isInvalidDecl()) |
| 7241 | continue; |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7242 | auto VDPrivateRefExpr = buildDeclRefExpr( |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7243 | *this, VDPrivate, RefExpr->getType().getUnqualifiedType(), ELoc); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 7244 | |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 7245 | DeclRefExpr *Ref = nullptr; |
| 7246 | if (!VD) |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 7247 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false); |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 7248 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_private, Ref); |
| 7249 | Vars.push_back(VD ? RefExpr->IgnoreParens() : Ref); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 7250 | PrivateCopies.push_back(VDPrivateRefExpr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7251 | } |
| 7252 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7253 | if (Vars.empty()) |
| 7254 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7255 | |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 7256 | return OMPPrivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
| 7257 | PrivateCopies); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7258 | } |
| 7259 | |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7260 | namespace { |
| 7261 | class DiagsUninitializedSeveretyRAII { |
| 7262 | private: |
| 7263 | DiagnosticsEngine &Diags; |
| 7264 | SourceLocation SavedLoc; |
| 7265 | bool IsIgnored; |
| 7266 | |
| 7267 | public: |
| 7268 | DiagsUninitializedSeveretyRAII(DiagnosticsEngine &Diags, SourceLocation Loc, |
| 7269 | bool IsIgnored) |
| 7270 | : Diags(Diags), SavedLoc(Loc), IsIgnored(IsIgnored) { |
| 7271 | if (!IsIgnored) { |
| 7272 | Diags.setSeverity(/*Diag*/ diag::warn_uninit_self_reference_in_init, |
| 7273 | /*Map*/ diag::Severity::Ignored, Loc); |
| 7274 | } |
| 7275 | } |
| 7276 | ~DiagsUninitializedSeveretyRAII() { |
| 7277 | if (!IsIgnored) |
| 7278 | Diags.popMappings(SavedLoc); |
| 7279 | } |
| 7280 | }; |
Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 7281 | } |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7282 | |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7283 | OMPClause *Sema::ActOnOpenMPFirstprivateClause(ArrayRef<Expr *> VarList, |
| 7284 | SourceLocation StartLoc, |
| 7285 | SourceLocation LParenLoc, |
| 7286 | SourceLocation EndLoc) { |
| 7287 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7288 | SmallVector<Expr *, 8> PrivateCopies; |
| 7289 | SmallVector<Expr *, 8> Inits; |
Alexey Bataev | 417089f | 2016-02-17 13:19:37 +0000 | [diff] [blame] | 7290 | SmallVector<Decl *, 4> ExprCaptures; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7291 | bool IsImplicitClause = |
| 7292 | StartLoc.isInvalid() && LParenLoc.isInvalid() && EndLoc.isInvalid(); |
| 7293 | auto ImplicitClauseLoc = DSAStack->getConstructLoc(); |
| 7294 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7295 | for (auto &RefExpr : VarList) { |
| 7296 | assert(RefExpr && "NULL expr in OpenMP firstprivate clause."); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7297 | SourceLocation ELoc; |
| 7298 | SourceRange ERange; |
| 7299 | Expr *SimpleRefExpr = RefExpr; |
| 7300 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7301 | if (Res.second) { |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7302 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7303 | Vars.push_back(RefExpr); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7304 | PrivateCopies.push_back(nullptr); |
| 7305 | Inits.push_back(nullptr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7306 | } |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7307 | ValueDecl *D = Res.first; |
| 7308 | if (!D) |
| 7309 | continue; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7310 | |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7311 | ELoc = IsImplicitClause ? ImplicitClauseLoc : ELoc; |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7312 | QualType Type = D->getType(); |
| 7313 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7314 | |
| 7315 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 7316 | // A variable that appears in a private clause must not have an incomplete |
| 7317 | // type or a reference type. |
| 7318 | if (RequireCompleteType(ELoc, Type, |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7319 | diag::err_omp_firstprivate_incomplete_type)) |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7320 | continue; |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7321 | Type = Type.getNonReferenceType(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7322 | |
| 7323 | // OpenMP [2.9.3.4, Restrictions, C/C++, p.1] |
| 7324 | // 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] | 7325 | // clause requires an accessible, unambiguous copy constructor for the |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7326 | // class type. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7327 | auto ElemType = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7328 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7329 | // If an implicit firstprivate variable found it was checked already. |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 7330 | DSAStackTy::DSAVarData TopDVar; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7331 | if (!IsImplicitClause) { |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7332 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 7333 | TopDVar = DVar; |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7334 | bool IsConstant = ElemType.isConstant(Context); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7335 | // OpenMP [2.4.13, Data-sharing Attribute Clauses] |
| 7336 | // A list item that specifies a given variable may not appear in more |
| 7337 | // than one clause on the same directive, except that a variable may be |
| 7338 | // specified in both firstprivate and lastprivate clauses. |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7339 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_firstprivate && |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7340 | DVar.CKind != OMPC_lastprivate && DVar.RefExpr) { |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7341 | Diag(ELoc, diag::err_omp_wrong_dsa) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7342 | << getOpenMPClauseName(DVar.CKind) |
| 7343 | << getOpenMPClauseName(OMPC_firstprivate); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7344 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7345 | continue; |
| 7346 | } |
| 7347 | |
| 7348 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 7349 | // in a Construct] |
| 7350 | // Variables with the predetermined data-sharing attributes may not be |
| 7351 | // listed in data-sharing attributes clauses, except for the cases |
| 7352 | // listed below. For these exceptions only, listing a predetermined |
| 7353 | // variable in a data-sharing attribute clause is allowed and overrides |
| 7354 | // the variable's predetermined data-sharing attributes. |
| 7355 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 7356 | // in a Construct, C/C++, p.2] |
| 7357 | // Variables with const-qualified type having no mutable member may be |
| 7358 | // listed in a firstprivate clause, even if they are static data members. |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7359 | if (!(IsConstant || (VD && VD->isStaticDataMember())) && !DVar.RefExpr && |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7360 | DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared) { |
| 7361 | Diag(ELoc, diag::err_omp_wrong_dsa) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7362 | << getOpenMPClauseName(DVar.CKind) |
| 7363 | << getOpenMPClauseName(OMPC_firstprivate); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7364 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7365 | continue; |
| 7366 | } |
| 7367 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7368 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7369 | // OpenMP [2.9.3.4, Restrictions, p.2] |
| 7370 | // A list item that is private within a parallel region must not appear |
| 7371 | // in a firstprivate clause on a worksharing construct if any of the |
| 7372 | // worksharing regions arising from the worksharing construct ever bind |
| 7373 | // to any of the parallel regions arising from the parallel construct. |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 7374 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 7375 | !isOpenMPParallelDirective(CurrDir)) { |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7376 | DVar = DSAStack->getImplicitDSA(D, true); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7377 | if (DVar.CKind != OMPC_shared && |
| 7378 | (isOpenMPParallelDirective(DVar.DKind) || |
| 7379 | DVar.DKind == OMPD_unknown)) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7380 | Diag(ELoc, diag::err_omp_required_access) |
| 7381 | << getOpenMPClauseName(OMPC_firstprivate) |
| 7382 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7383 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7384 | continue; |
| 7385 | } |
| 7386 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7387 | // OpenMP [2.9.3.4, Restrictions, p.3] |
| 7388 | // A list item that appears in a reduction clause of a parallel construct |
| 7389 | // must not appear in a firstprivate clause on a worksharing or task |
| 7390 | // construct if any of the worksharing or task regions arising from the |
| 7391 | // worksharing or task construct ever bind to any of the parallel regions |
| 7392 | // arising from the parallel construct. |
| 7393 | // OpenMP [2.9.3.4, Restrictions, p.4] |
| 7394 | // A list item that appears in a reduction clause in worksharing |
| 7395 | // construct must not appear in a firstprivate clause in a task construct |
| 7396 | // encountered during execution of any of the worksharing regions arising |
| 7397 | // from the worksharing construct. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7398 | if (CurrDir == OMPD_task) { |
| 7399 | DVar = |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7400 | DSAStack->hasInnermostDSA(D, MatchesAnyClause(OMPC_reduction), |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7401 | [](OpenMPDirectiveKind K) -> bool { |
| 7402 | return isOpenMPParallelDirective(K) || |
| 7403 | isOpenMPWorksharingDirective(K); |
| 7404 | }, |
| 7405 | false); |
| 7406 | if (DVar.CKind == OMPC_reduction && |
| 7407 | (isOpenMPParallelDirective(DVar.DKind) || |
| 7408 | isOpenMPWorksharingDirective(DVar.DKind))) { |
| 7409 | Diag(ELoc, diag::err_omp_parallel_reduction_in_task_firstprivate) |
| 7410 | << getOpenMPDirectiveName(DVar.DKind); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7411 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7412 | continue; |
| 7413 | } |
| 7414 | } |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7415 | |
| 7416 | // OpenMP 4.5 [2.15.3.4, Restrictions, p.3] |
| 7417 | // A list item that is private within a teams region must not appear in a |
| 7418 | // firstprivate clause on a distribute construct if any of the distribute |
| 7419 | // regions arising from the distribute construct ever bind to any of the |
| 7420 | // teams regions arising from the teams construct. |
| 7421 | // OpenMP 4.5 [2.15.3.4, Restrictions, p.3] |
| 7422 | // A list item that appears in a reduction clause of a teams construct |
| 7423 | // must not appear in a firstprivate clause on a distribute construct if |
| 7424 | // any of the distribute regions arising from the distribute construct |
| 7425 | // ever bind to any of the teams regions arising from the teams construct. |
| 7426 | // OpenMP 4.5 [2.10.8, Distribute Construct, p.3] |
| 7427 | // A list item may appear in a firstprivate or lastprivate clause but not |
| 7428 | // both. |
| 7429 | if (CurrDir == OMPD_distribute) { |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7430 | DVar = DSAStack->hasInnermostDSA(D, MatchesAnyClause(OMPC_private), |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7431 | [](OpenMPDirectiveKind K) -> bool { |
| 7432 | return isOpenMPTeamsDirective(K); |
| 7433 | }, |
| 7434 | false); |
| 7435 | if (DVar.CKind == OMPC_private && isOpenMPTeamsDirective(DVar.DKind)) { |
| 7436 | Diag(ELoc, diag::err_omp_firstprivate_distribute_private_teams); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7437 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7438 | continue; |
| 7439 | } |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7440 | DVar = DSAStack->hasInnermostDSA(D, MatchesAnyClause(OMPC_reduction), |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7441 | [](OpenMPDirectiveKind K) -> bool { |
| 7442 | return isOpenMPTeamsDirective(K); |
| 7443 | }, |
| 7444 | false); |
| 7445 | if (DVar.CKind == OMPC_reduction && |
| 7446 | isOpenMPTeamsDirective(DVar.DKind)) { |
| 7447 | Diag(ELoc, diag::err_omp_firstprivate_distribute_in_teams_reduction); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7448 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7449 | continue; |
| 7450 | } |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7451 | DVar = DSAStack->getTopDSA(D, false); |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7452 | if (DVar.CKind == OMPC_lastprivate) { |
| 7453 | Diag(ELoc, diag::err_omp_firstprivate_and_lastprivate_in_distribute); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7454 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7455 | continue; |
| 7456 | } |
| 7457 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7458 | } |
| 7459 | |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7460 | // Variably modified types are not supported for tasks. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 7461 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType() && |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7462 | DSAStack->getCurrentDirective() == OMPD_task) { |
| 7463 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
| 7464 | << getOpenMPClauseName(OMPC_firstprivate) << Type |
| 7465 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 7466 | bool IsDecl = |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7467 | !VD || |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7468 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7469 | Diag(D->getLocation(), |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7470 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7471 | << D; |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7472 | continue; |
| 7473 | } |
| 7474 | |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7475 | Type = Type.getUnqualifiedType(); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7476 | auto VDPrivate = buildVarDecl(*this, ELoc, Type, D->getName(), |
| 7477 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7478 | // Generate helper private variable and initialize it with the value of the |
| 7479 | // original variable. The address of the original variable is replaced by |
| 7480 | // the address of the new private variable in the CodeGen. This new variable |
| 7481 | // is not added to IdResolver, so the code in the OpenMP region uses |
| 7482 | // original variable for proper diagnostics and variable capturing. |
| 7483 | Expr *VDInitRefExpr = nullptr; |
| 7484 | // For arrays generate initializer for single element and replace it by the |
| 7485 | // original array element in CodeGen. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7486 | if (Type->isArrayType()) { |
| 7487 | auto VDInit = |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7488 | buildVarDecl(*this, RefExpr->getExprLoc(), ElemType, D->getName()); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7489 | VDInitRefExpr = buildDeclRefExpr(*this, VDInit, ElemType, ELoc); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7490 | auto Init = DefaultLvalueConversion(VDInitRefExpr).get(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7491 | ElemType = ElemType.getUnqualifiedType(); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7492 | auto *VDInitTemp = buildVarDecl(*this, RefExpr->getExprLoc(), ElemType, |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7493 | ".firstprivate.temp"); |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 7494 | InitializedEntity Entity = |
| 7495 | InitializedEntity::InitializeVariable(VDInitTemp); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7496 | InitializationKind Kind = InitializationKind::CreateCopy(ELoc, ELoc); |
| 7497 | |
| 7498 | InitializationSequence InitSeq(*this, Entity, Kind, Init); |
| 7499 | ExprResult Result = InitSeq.Perform(*this, Entity, Kind, Init); |
| 7500 | if (Result.isInvalid()) |
| 7501 | VDPrivate->setInvalidDecl(); |
| 7502 | else |
| 7503 | VDPrivate->setInit(Result.getAs<Expr>()); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7504 | // Remove temp variable declaration. |
| 7505 | Context.Deallocate(VDInitTemp); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7506 | } else { |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7507 | auto *VDInit = buildVarDecl(*this, RefExpr->getExprLoc(), Type, |
| 7508 | ".firstprivate.temp"); |
| 7509 | VDInitRefExpr = buildDeclRefExpr(*this, VDInit, RefExpr->getType(), |
| 7510 | RefExpr->getExprLoc()); |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 7511 | AddInitializerToDecl(VDPrivate, |
| 7512 | DefaultLvalueConversion(VDInitRefExpr).get(), |
| 7513 | /*DirectInit=*/false, /*TypeMayContainAuto=*/false); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7514 | } |
| 7515 | if (VDPrivate->isInvalidDecl()) { |
| 7516 | if (IsImplicitClause) { |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7517 | Diag(RefExpr->getExprLoc(), |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7518 | diag::note_omp_task_predetermined_firstprivate_here); |
| 7519 | } |
| 7520 | continue; |
| 7521 | } |
| 7522 | CurContext->addDecl(VDPrivate); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7523 | auto VDPrivateRefExpr = buildDeclRefExpr( |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7524 | *this, VDPrivate, RefExpr->getType().getUnqualifiedType(), |
| 7525 | RefExpr->getExprLoc()); |
| 7526 | DeclRefExpr *Ref = nullptr; |
Alexey Bataev | 417089f | 2016-02-17 13:19:37 +0000 | [diff] [blame] | 7527 | if (!VD) { |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 7528 | if (TopDVar.CKind == OMPC_lastprivate) |
| 7529 | Ref = TopDVar.PrivateCopy; |
| 7530 | else { |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 7531 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/true); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 7532 | if (!IsOpenMPCapturedDecl(D)) |
| 7533 | ExprCaptures.push_back(Ref->getDecl()); |
| 7534 | } |
Alexey Bataev | 417089f | 2016-02-17 13:19:37 +0000 | [diff] [blame] | 7535 | } |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7536 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_firstprivate, Ref); |
| 7537 | Vars.push_back(VD ? RefExpr->IgnoreParens() : Ref); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7538 | PrivateCopies.push_back(VDPrivateRefExpr); |
| 7539 | Inits.push_back(VDInitRefExpr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7540 | } |
| 7541 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7542 | if (Vars.empty()) |
| 7543 | return nullptr; |
Alexey Bataev | 417089f | 2016-02-17 13:19:37 +0000 | [diff] [blame] | 7544 | Stmt *PreInit = nullptr; |
| 7545 | if (!ExprCaptures.empty()) { |
| 7546 | PreInit = new (Context) |
| 7547 | DeclStmt(DeclGroupRef::Create(Context, ExprCaptures.begin(), |
| 7548 | ExprCaptures.size()), |
| 7549 | SourceLocation(), SourceLocation()); |
| 7550 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7551 | |
| 7552 | return OMPFirstprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
Alexey Bataev | 417089f | 2016-02-17 13:19:37 +0000 | [diff] [blame] | 7553 | Vars, PrivateCopies, Inits, PreInit); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7554 | } |
| 7555 | |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7556 | OMPClause *Sema::ActOnOpenMPLastprivateClause(ArrayRef<Expr *> VarList, |
| 7557 | SourceLocation StartLoc, |
| 7558 | SourceLocation LParenLoc, |
| 7559 | SourceLocation EndLoc) { |
| 7560 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7561 | SmallVector<Expr *, 8> SrcExprs; |
| 7562 | SmallVector<Expr *, 8> DstExprs; |
| 7563 | SmallVector<Expr *, 8> AssignmentOps; |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 7564 | SmallVector<Decl *, 4> ExprCaptures; |
| 7565 | SmallVector<Expr *, 4> ExprPostUpdates; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7566 | for (auto &RefExpr : VarList) { |
| 7567 | assert(RefExpr && "NULL expr in OpenMP lastprivate clause."); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7568 | SourceLocation ELoc; |
| 7569 | SourceRange ERange; |
| 7570 | Expr *SimpleRefExpr = RefExpr; |
| 7571 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7572 | if (Res.second) { |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7573 | // It will be analyzed later. |
| 7574 | Vars.push_back(RefExpr); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7575 | SrcExprs.push_back(nullptr); |
| 7576 | DstExprs.push_back(nullptr); |
| 7577 | AssignmentOps.push_back(nullptr); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7578 | } |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7579 | ValueDecl *D = Res.first; |
| 7580 | if (!D) |
| 7581 | continue; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7582 | |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7583 | QualType Type = D->getType(); |
| 7584 | auto *VD = dyn_cast<VarDecl>(D); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7585 | |
| 7586 | // OpenMP [2.14.3.5, Restrictions, C/C++, p.2] |
| 7587 | // A variable that appears in a lastprivate clause must not have an |
| 7588 | // incomplete type or a reference type. |
| 7589 | if (RequireCompleteType(ELoc, Type, |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7590 | diag::err_omp_lastprivate_incomplete_type)) |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7591 | continue; |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7592 | Type = Type.getNonReferenceType(); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7593 | |
| 7594 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 7595 | // in a Construct] |
| 7596 | // Variables with the predetermined data-sharing attributes may not be |
| 7597 | // listed in data-sharing attributes clauses, except for the cases |
| 7598 | // listed below. |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7599 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7600 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_lastprivate && |
| 7601 | DVar.CKind != OMPC_firstprivate && |
| 7602 | (DVar.CKind != OMPC_private || DVar.RefExpr != nullptr)) { |
| 7603 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 7604 | << getOpenMPClauseName(DVar.CKind) |
| 7605 | << getOpenMPClauseName(OMPC_lastprivate); |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7606 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7607 | continue; |
| 7608 | } |
| 7609 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7610 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
| 7611 | // OpenMP [2.14.3.5, Restrictions, p.2] |
| 7612 | // A list item that is private within a parallel region, or that appears in |
| 7613 | // the reduction clause of a parallel construct, must not appear in a |
| 7614 | // lastprivate clause on a worksharing construct if any of the corresponding |
| 7615 | // worksharing regions ever binds to any of the corresponding parallel |
| 7616 | // regions. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7617 | DSAStackTy::DSAVarData TopDVar = DVar; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 7618 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 7619 | !isOpenMPParallelDirective(CurrDir)) { |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7620 | DVar = DSAStack->getImplicitDSA(D, true); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7621 | if (DVar.CKind != OMPC_shared) { |
| 7622 | Diag(ELoc, diag::err_omp_required_access) |
| 7623 | << getOpenMPClauseName(OMPC_lastprivate) |
| 7624 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7625 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7626 | continue; |
| 7627 | } |
| 7628 | } |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7629 | |
| 7630 | // OpenMP 4.5 [2.10.8, Distribute Construct, p.3] |
| 7631 | // A list item may appear in a firstprivate or lastprivate clause but not |
| 7632 | // both. |
| 7633 | if (CurrDir == OMPD_distribute) { |
| 7634 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
| 7635 | if (DVar.CKind == OMPC_firstprivate) { |
| 7636 | Diag(ELoc, diag::err_omp_firstprivate_and_lastprivate_in_distribute); |
| 7637 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
| 7638 | continue; |
| 7639 | } |
| 7640 | } |
| 7641 | |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7642 | // OpenMP [2.14.3.5, Restrictions, C++, p.1,2] |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7643 | // A variable of class type (or array thereof) that appears in a |
| 7644 | // lastprivate clause requires an accessible, unambiguous default |
| 7645 | // constructor for the class type, unless the list item is also specified |
| 7646 | // in a firstprivate clause. |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7647 | // A variable of class type (or array thereof) that appears in a |
| 7648 | // lastprivate clause requires an accessible, unambiguous copy assignment |
| 7649 | // operator for the class type. |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7650 | Type = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7651 | auto *SrcVD = buildVarDecl(*this, ERange.getBegin(), |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 7652 | Type.getUnqualifiedType(), ".lastprivate.src", |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7653 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 7654 | auto *PseudoSrcExpr = |
| 7655 | buildDeclRefExpr(*this, SrcVD, Type.getUnqualifiedType(), ELoc); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7656 | auto *DstVD = |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7657 | buildVarDecl(*this, ERange.getBegin(), Type, ".lastprivate.dst", |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7658 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 7659 | auto *PseudoDstExpr = buildDeclRefExpr(*this, DstVD, Type, ELoc); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7660 | // For arrays generate assignment operation for single element and replace |
| 7661 | // it by the original array element in CodeGen. |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7662 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, ELoc, BO_Assign, |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7663 | PseudoDstExpr, PseudoSrcExpr); |
| 7664 | if (AssignmentOp.isInvalid()) |
| 7665 | continue; |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7666 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), ELoc, |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7667 | /*DiscardedValue=*/true); |
| 7668 | if (AssignmentOp.isInvalid()) |
| 7669 | continue; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7670 | |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7671 | DeclRefExpr *Ref = nullptr; |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 7672 | if (!VD) { |
| 7673 | if (TopDVar.CKind == OMPC_firstprivate) |
| 7674 | Ref = TopDVar.PrivateCopy; |
| 7675 | else { |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 7676 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 7677 | if (!IsOpenMPCapturedDecl(D)) |
| 7678 | ExprCaptures.push_back(Ref->getDecl()); |
| 7679 | } |
| 7680 | if (TopDVar.CKind == OMPC_firstprivate || |
| 7681 | (!IsOpenMPCapturedDecl(D) && |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 7682 | Ref->getDecl()->hasAttr<OMPCaptureNoInitAttr>())) { |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 7683 | ExprResult RefRes = DefaultLvalueConversion(Ref); |
| 7684 | if (!RefRes.isUsable()) |
| 7685 | continue; |
| 7686 | ExprResult PostUpdateRes = |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7687 | BuildBinOp(DSAStack->getCurScope(), ELoc, BO_Assign, SimpleRefExpr, |
| 7688 | RefRes.get()); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 7689 | if (!PostUpdateRes.isUsable()) |
| 7690 | continue; |
Alexey Bataev | 78849fb | 2016-03-09 09:49:00 +0000 | [diff] [blame] | 7691 | ExprPostUpdates.push_back( |
| 7692 | IgnoredValueConversions(PostUpdateRes.get()).get()); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 7693 | } |
| 7694 | } |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7695 | if (TopDVar.CKind != OMPC_firstprivate) |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7696 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_lastprivate, Ref); |
| 7697 | Vars.push_back(VD ? RefExpr->IgnoreParens() : Ref); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7698 | SrcExprs.push_back(PseudoSrcExpr); |
| 7699 | DstExprs.push_back(PseudoDstExpr); |
| 7700 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7701 | } |
| 7702 | |
| 7703 | if (Vars.empty()) |
| 7704 | return nullptr; |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 7705 | Stmt *PreInit = nullptr; |
| 7706 | if (!ExprCaptures.empty()) { |
| 7707 | PreInit = new (Context) |
| 7708 | DeclStmt(DeclGroupRef::Create(Context, ExprCaptures.begin(), |
| 7709 | ExprCaptures.size()), |
| 7710 | SourceLocation(), SourceLocation()); |
| 7711 | } |
| 7712 | Expr *PostUpdate = nullptr; |
| 7713 | if (!ExprPostUpdates.empty()) { |
| 7714 | for (auto *E : ExprPostUpdates) { |
| 7715 | ExprResult PostUpdateRes = |
| 7716 | PostUpdate |
| 7717 | ? CreateBuiltinBinOp(SourceLocation(), BO_Comma, PostUpdate, E) |
| 7718 | : E; |
| 7719 | PostUpdate = PostUpdateRes.get(); |
| 7720 | } |
| 7721 | } |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7722 | |
| 7723 | return OMPLastprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 7724 | Vars, SrcExprs, DstExprs, AssignmentOps, |
| 7725 | PreInit, PostUpdate); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7726 | } |
| 7727 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7728 | OMPClause *Sema::ActOnOpenMPSharedClause(ArrayRef<Expr *> VarList, |
| 7729 | SourceLocation StartLoc, |
| 7730 | SourceLocation LParenLoc, |
| 7731 | SourceLocation EndLoc) { |
| 7732 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7733 | for (auto &RefExpr : VarList) { |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 7734 | assert(RefExpr && "NULL expr in OpenMP lastprivate clause."); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7735 | SourceLocation ELoc; |
| 7736 | SourceRange ERange; |
| 7737 | Expr *SimpleRefExpr = RefExpr; |
| 7738 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 7739 | if (Res.second) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7740 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7741 | Vars.push_back(RefExpr); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7742 | } |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 7743 | ValueDecl *D = Res.first; |
| 7744 | if (!D) |
| 7745 | continue; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7746 | |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 7747 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7748 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 7749 | // in a Construct] |
| 7750 | // Variables with the predetermined data-sharing attributes may not be |
| 7751 | // listed in data-sharing attributes clauses, except for the cases |
| 7752 | // listed below. For these exceptions only, listing a predetermined |
| 7753 | // variable in a data-sharing attribute clause is allowed and overrides |
| 7754 | // the variable's predetermined data-sharing attributes. |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 7755 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7756 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared && |
| 7757 | DVar.RefExpr) { |
| 7758 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 7759 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 7760 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7761 | continue; |
| 7762 | } |
| 7763 | |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 7764 | DeclRefExpr *Ref = nullptr; |
| 7765 | if (!VD) |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 7766 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/true); |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 7767 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_shared, Ref); |
| 7768 | Vars.push_back(VD ? RefExpr->IgnoreParens() : Ref); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7769 | } |
| 7770 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7771 | if (Vars.empty()) |
| 7772 | return nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7773 | |
| 7774 | return OMPSharedClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars); |
| 7775 | } |
| 7776 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7777 | namespace { |
| 7778 | class DSARefChecker : public StmtVisitor<DSARefChecker, bool> { |
| 7779 | DSAStackTy *Stack; |
| 7780 | |
| 7781 | public: |
| 7782 | bool VisitDeclRefExpr(DeclRefExpr *E) { |
| 7783 | if (VarDecl *VD = dyn_cast<VarDecl>(E->getDecl())) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7784 | DSAStackTy::DSAVarData DVar = Stack->getTopDSA(VD, false); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7785 | if (DVar.CKind == OMPC_shared && !DVar.RefExpr) |
| 7786 | return false; |
| 7787 | if (DVar.CKind != OMPC_unknown) |
| 7788 | return true; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7789 | DSAStackTy::DSAVarData DVarPrivate = |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7790 | Stack->hasDSA(VD, isOpenMPPrivate, MatchesAlways(), false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7791 | if (DVarPrivate.CKind != OMPC_unknown) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7792 | return true; |
| 7793 | return false; |
| 7794 | } |
| 7795 | return false; |
| 7796 | } |
| 7797 | bool VisitStmt(Stmt *S) { |
| 7798 | for (auto Child : S->children()) { |
| 7799 | if (Child && Visit(Child)) |
| 7800 | return true; |
| 7801 | } |
| 7802 | return false; |
| 7803 | } |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 7804 | explicit DSARefChecker(DSAStackTy *S) : Stack(S) {} |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7805 | }; |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 7806 | } // namespace |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7807 | |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7808 | namespace { |
| 7809 | // Transform MemberExpression for specified FieldDecl of current class to |
| 7810 | // DeclRefExpr to specified OMPCapturedExprDecl. |
| 7811 | class TransformExprToCaptures : public TreeTransform<TransformExprToCaptures> { |
| 7812 | typedef TreeTransform<TransformExprToCaptures> BaseTransform; |
| 7813 | ValueDecl *Field; |
| 7814 | DeclRefExpr *CapturedExpr; |
| 7815 | |
| 7816 | public: |
| 7817 | TransformExprToCaptures(Sema &SemaRef, ValueDecl *FieldDecl) |
| 7818 | : BaseTransform(SemaRef), Field(FieldDecl), CapturedExpr(nullptr) {} |
| 7819 | |
| 7820 | ExprResult TransformMemberExpr(MemberExpr *E) { |
| 7821 | if (isa<CXXThisExpr>(E->getBase()->IgnoreParenImpCasts()) && |
| 7822 | E->getMemberDecl() == Field) { |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 7823 | CapturedExpr = buildCapture(SemaRef, Field, E, /*WithInit=*/false); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7824 | return CapturedExpr; |
| 7825 | } |
| 7826 | return BaseTransform::TransformMemberExpr(E); |
| 7827 | } |
| 7828 | DeclRefExpr *getCapturedExpr() { return CapturedExpr; } |
| 7829 | }; |
| 7830 | } // namespace |
| 7831 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7832 | OMPClause *Sema::ActOnOpenMPReductionClause( |
| 7833 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, SourceLocation LParenLoc, |
| 7834 | SourceLocation ColonLoc, SourceLocation EndLoc, |
| 7835 | CXXScopeSpec &ReductionIdScopeSpec, |
| 7836 | const DeclarationNameInfo &ReductionId) { |
| 7837 | // TODO: Allow scope specification search when 'declare reduction' is |
| 7838 | // supported. |
| 7839 | assert(ReductionIdScopeSpec.isEmpty() && |
| 7840 | "No support for scoped reduction identifiers yet."); |
| 7841 | |
| 7842 | auto DN = ReductionId.getName(); |
| 7843 | auto OOK = DN.getCXXOverloadedOperator(); |
| 7844 | BinaryOperatorKind BOK = BO_Comma; |
| 7845 | |
| 7846 | // OpenMP [2.14.3.6, reduction clause] |
| 7847 | // C |
| 7848 | // reduction-identifier is either an identifier or one of the following |
| 7849 | // operators: +, -, *, &, |, ^, && and || |
| 7850 | // C++ |
| 7851 | // reduction-identifier is either an id-expression or one of the following |
| 7852 | // operators: +, -, *, &, |, ^, && and || |
| 7853 | // FIXME: Only 'min' and 'max' identifiers are supported for now. |
| 7854 | switch (OOK) { |
| 7855 | case OO_Plus: |
| 7856 | case OO_Minus: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7857 | BOK = BO_Add; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7858 | break; |
| 7859 | case OO_Star: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7860 | BOK = BO_Mul; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7861 | break; |
| 7862 | case OO_Amp: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7863 | BOK = BO_And; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7864 | break; |
| 7865 | case OO_Pipe: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7866 | BOK = BO_Or; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7867 | break; |
| 7868 | case OO_Caret: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7869 | BOK = BO_Xor; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7870 | break; |
| 7871 | case OO_AmpAmp: |
| 7872 | BOK = BO_LAnd; |
| 7873 | break; |
| 7874 | case OO_PipePipe: |
| 7875 | BOK = BO_LOr; |
| 7876 | break; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7877 | case OO_New: |
| 7878 | case OO_Delete: |
| 7879 | case OO_Array_New: |
| 7880 | case OO_Array_Delete: |
| 7881 | case OO_Slash: |
| 7882 | case OO_Percent: |
| 7883 | case OO_Tilde: |
| 7884 | case OO_Exclaim: |
| 7885 | case OO_Equal: |
| 7886 | case OO_Less: |
| 7887 | case OO_Greater: |
| 7888 | case OO_LessEqual: |
| 7889 | case OO_GreaterEqual: |
| 7890 | case OO_PlusEqual: |
| 7891 | case OO_MinusEqual: |
| 7892 | case OO_StarEqual: |
| 7893 | case OO_SlashEqual: |
| 7894 | case OO_PercentEqual: |
| 7895 | case OO_CaretEqual: |
| 7896 | case OO_AmpEqual: |
| 7897 | case OO_PipeEqual: |
| 7898 | case OO_LessLess: |
| 7899 | case OO_GreaterGreater: |
| 7900 | case OO_LessLessEqual: |
| 7901 | case OO_GreaterGreaterEqual: |
| 7902 | case OO_EqualEqual: |
| 7903 | case OO_ExclaimEqual: |
| 7904 | case OO_PlusPlus: |
| 7905 | case OO_MinusMinus: |
| 7906 | case OO_Comma: |
| 7907 | case OO_ArrowStar: |
| 7908 | case OO_Arrow: |
| 7909 | case OO_Call: |
| 7910 | case OO_Subscript: |
| 7911 | case OO_Conditional: |
Richard Smith | 9be594e | 2015-10-22 05:12:22 +0000 | [diff] [blame] | 7912 | case OO_Coawait: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7913 | case NUM_OVERLOADED_OPERATORS: |
| 7914 | llvm_unreachable("Unexpected reduction identifier"); |
| 7915 | case OO_None: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7916 | if (auto II = DN.getAsIdentifierInfo()) { |
| 7917 | if (II->isStr("max")) |
| 7918 | BOK = BO_GT; |
| 7919 | else if (II->isStr("min")) |
| 7920 | BOK = BO_LT; |
| 7921 | } |
| 7922 | break; |
| 7923 | } |
| 7924 | SourceRange ReductionIdRange; |
| 7925 | if (ReductionIdScopeSpec.isValid()) { |
| 7926 | ReductionIdRange.setBegin(ReductionIdScopeSpec.getBeginLoc()); |
| 7927 | } |
| 7928 | ReductionIdRange.setEnd(ReductionId.getEndLoc()); |
| 7929 | if (BOK == BO_Comma) { |
| 7930 | // Not allowed reduction identifier is found. |
| 7931 | Diag(ReductionId.getLocStart(), diag::err_omp_unknown_reduction_identifier) |
| 7932 | << ReductionIdRange; |
| 7933 | return nullptr; |
| 7934 | } |
| 7935 | |
| 7936 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7937 | SmallVector<Expr *, 8> Privates; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7938 | SmallVector<Expr *, 8> LHSs; |
| 7939 | SmallVector<Expr *, 8> RHSs; |
| 7940 | SmallVector<Expr *, 8> ReductionOps; |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 7941 | SmallVector<Decl *, 4> ExprCaptures; |
| 7942 | SmallVector<Expr *, 4> ExprPostUpdates; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7943 | for (auto RefExpr : VarList) { |
| 7944 | assert(RefExpr && "nullptr expr in OpenMP reduction clause."); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7945 | // OpenMP [2.1, C/C++] |
| 7946 | // A list item is a variable or array section, subject to the restrictions |
| 7947 | // specified in Section 2.4 on page 42 and in each of the sections |
| 7948 | // describing clauses and directives for which a list appears. |
| 7949 | // OpenMP [2.14.3.3, Restrictions, p.1] |
| 7950 | // A variable that is part of another variable (as an array or |
| 7951 | // structure element) cannot appear in a private clause. |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7952 | SourceLocation ELoc; |
| 7953 | SourceRange ERange; |
| 7954 | Expr *SimpleRefExpr = RefExpr; |
| 7955 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange, |
| 7956 | /*AllowArraySection=*/true); |
| 7957 | if (Res.second) { |
| 7958 | // It will be analyzed later. |
| 7959 | Vars.push_back(RefExpr); |
| 7960 | Privates.push_back(nullptr); |
| 7961 | LHSs.push_back(nullptr); |
| 7962 | RHSs.push_back(nullptr); |
| 7963 | ReductionOps.push_back(nullptr); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7964 | } |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7965 | ValueDecl *D = Res.first; |
| 7966 | if (!D) |
| 7967 | continue; |
| 7968 | |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7969 | QualType Type; |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7970 | auto *ASE = dyn_cast<ArraySubscriptExpr>(RefExpr->IgnoreParens()); |
| 7971 | auto *OASE = dyn_cast<OMPArraySectionExpr>(RefExpr->IgnoreParens()); |
| 7972 | if (ASE) |
Alexey Bataev | 31300ed | 2016-02-04 11:27:03 +0000 | [diff] [blame] | 7973 | Type = ASE->getType().getNonReferenceType(); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7974 | else if (OASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7975 | auto BaseType = OMPArraySectionExpr::getBaseOriginalType(OASE->getBase()); |
| 7976 | if (auto *ATy = BaseType->getAsArrayTypeUnsafe()) |
| 7977 | Type = ATy->getElementType(); |
| 7978 | else |
| 7979 | Type = BaseType->getPointeeType(); |
Alexey Bataev | 31300ed | 2016-02-04 11:27:03 +0000 | [diff] [blame] | 7980 | Type = Type.getNonReferenceType(); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7981 | } else |
| 7982 | Type = Context.getBaseElementType(D->getType().getNonReferenceType()); |
| 7983 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7984 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7985 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 7986 | // A variable that appears in a private clause must not have an incomplete |
| 7987 | // type or a reference type. |
| 7988 | if (RequireCompleteType(ELoc, Type, |
| 7989 | diag::err_omp_reduction_incomplete_type)) |
| 7990 | continue; |
| 7991 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7992 | // A list item that appears in a reduction clause must not be |
| 7993 | // const-qualified. |
| 7994 | if (Type.getNonReferenceType().isConstant(Context)) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7995 | Diag(ELoc, diag::err_omp_const_reduction_list_item) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7996 | << getOpenMPClauseName(OMPC_reduction) << Type << ERange; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7997 | if (!ASE && !OASE) { |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7998 | bool IsDecl = !VD || |
| 7999 | VD->isThisDeclarationADefinition(Context) == |
| 8000 | VarDecl::DeclarationOnly; |
| 8001 | Diag(D->getLocation(), |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8002 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8003 | << D; |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8004 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8005 | continue; |
| 8006 | } |
| 8007 | // OpenMP [2.9.3.6, Restrictions, C/C++, p.4] |
| 8008 | // If a list-item is a reference type then it must bind to the same object |
| 8009 | // for all threads of the team. |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8010 | if (!ASE && !OASE && VD) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8011 | VarDecl *VDDef = VD->getDefinition(); |
Alexey Bataev | 31300ed | 2016-02-04 11:27:03 +0000 | [diff] [blame] | 8012 | if (VD->getType()->isReferenceType() && VDDef) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8013 | DSARefChecker Check(DSAStack); |
| 8014 | if (Check.Visit(VDDef->getInit())) { |
| 8015 | Diag(ELoc, diag::err_omp_reduction_ref_type_arg) << ERange; |
| 8016 | Diag(VDDef->getLocation(), diag::note_defined_here) << VDDef; |
| 8017 | continue; |
| 8018 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8019 | } |
| 8020 | } |
| 8021 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
| 8022 | // The type of a list item that appears in a reduction clause must be valid |
| 8023 | // for the reduction-identifier. For a max or min reduction in C, the type |
| 8024 | // of the list item must be an allowed arithmetic data type: char, int, |
| 8025 | // float, double, or _Bool, possibly modified with long, short, signed, or |
| 8026 | // unsigned. For a max or min reduction in C++, the type of the list item |
| 8027 | // must be an allowed arithmetic data type: char, wchar_t, int, float, |
| 8028 | // double, or bool, possibly modified with long, short, signed, or unsigned. |
| 8029 | if ((BOK == BO_GT || BOK == BO_LT) && |
| 8030 | !(Type->isScalarType() || |
| 8031 | (getLangOpts().CPlusPlus && Type->isArithmeticType()))) { |
| 8032 | Diag(ELoc, diag::err_omp_clause_not_arithmetic_type_arg) |
| 8033 | << getLangOpts().CPlusPlus; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8034 | if (!ASE && !OASE) { |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8035 | bool IsDecl = !VD || |
| 8036 | VD->isThisDeclarationADefinition(Context) == |
| 8037 | VarDecl::DeclarationOnly; |
| 8038 | Diag(D->getLocation(), |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8039 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8040 | << D; |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8041 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8042 | continue; |
| 8043 | } |
| 8044 | if ((BOK == BO_OrAssign || BOK == BO_AndAssign || BOK == BO_XorAssign) && |
| 8045 | !getLangOpts().CPlusPlus && Type->isFloatingType()) { |
| 8046 | Diag(ELoc, diag::err_omp_clause_floating_type_arg); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8047 | if (!ASE && !OASE) { |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8048 | bool IsDecl = !VD || |
| 8049 | VD->isThisDeclarationADefinition(Context) == |
| 8050 | VarDecl::DeclarationOnly; |
| 8051 | Diag(D->getLocation(), |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8052 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8053 | << D; |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8054 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8055 | continue; |
| 8056 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8057 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 8058 | // in a Construct] |
| 8059 | // Variables with the predetermined data-sharing attributes may not be |
| 8060 | // listed in data-sharing attributes clauses, except for the cases |
| 8061 | // listed below. For these exceptions only, listing a predetermined |
| 8062 | // variable in a data-sharing attribute clause is allowed and overrides |
| 8063 | // the variable's predetermined data-sharing attributes. |
| 8064 | // OpenMP [2.14.3.6, Restrictions, p.3] |
| 8065 | // Any number of reduction clauses can be specified on the directive, |
| 8066 | // but a list item can appear only once in the reduction clauses for that |
| 8067 | // directive. |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8068 | DSAStackTy::DSAVarData DVar; |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8069 | DVar = DSAStack->getTopDSA(D, false); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8070 | if (DVar.CKind == OMPC_reduction) { |
| 8071 | Diag(ELoc, diag::err_omp_once_referenced) |
| 8072 | << getOpenMPClauseName(OMPC_reduction); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8073 | if (DVar.RefExpr) |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8074 | Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_referenced); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8075 | } else if (DVar.CKind != OMPC_unknown) { |
| 8076 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 8077 | << getOpenMPClauseName(DVar.CKind) |
| 8078 | << getOpenMPClauseName(OMPC_reduction); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8079 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8080 | continue; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8081 | } |
| 8082 | |
| 8083 | // OpenMP [2.14.3.6, Restrictions, p.1] |
| 8084 | // A list item that appears in a reduction clause of a worksharing |
| 8085 | // construct must be shared in the parallel regions to which any of the |
| 8086 | // worksharing regions arising from the worksharing construct bind. |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8087 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
| 8088 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 8089 | !isOpenMPParallelDirective(CurrDir)) { |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8090 | DVar = DSAStack->getImplicitDSA(D, true); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8091 | if (DVar.CKind != OMPC_shared) { |
| 8092 | Diag(ELoc, diag::err_omp_required_access) |
| 8093 | << getOpenMPClauseName(OMPC_reduction) |
| 8094 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8095 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8096 | continue; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 8097 | } |
| 8098 | } |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8099 | |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8100 | Type = Type.getNonLValueExprType(Context).getUnqualifiedType(); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8101 | auto *LHSVD = buildVarDecl(*this, ELoc, Type, ".reduction.lhs", |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8102 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 8103 | auto *RHSVD = buildVarDecl(*this, ELoc, Type, D->getName(), |
| 8104 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8105 | auto PrivateTy = Type; |
Alexey Bataev | 1189bd0 | 2016-01-26 12:20:39 +0000 | [diff] [blame] | 8106 | if (OASE || |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8107 | (!ASE && |
| 8108 | D->getType().getNonReferenceType()->isVariablyModifiedType())) { |
Alexey Bataev | 1189bd0 | 2016-01-26 12:20:39 +0000 | [diff] [blame] | 8109 | // For arays/array sections only: |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8110 | // Create pseudo array type for private copy. The size for this array will |
| 8111 | // be generated during codegen. |
| 8112 | // For array subscripts or single variables Private Ty is the same as Type |
| 8113 | // (type of the variable or single array element). |
| 8114 | PrivateTy = Context.getVariableArrayType( |
| 8115 | Type, new (Context) OpaqueValueExpr(SourceLocation(), |
| 8116 | Context.getSizeType(), VK_RValue), |
| 8117 | ArrayType::Normal, /*IndexTypeQuals=*/0, SourceRange()); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8118 | } else if (!ASE && !OASE && |
| 8119 | Context.getAsArrayType(D->getType().getNonReferenceType())) |
| 8120 | PrivateTy = D->getType().getNonReferenceType(); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8121 | // Private copy. |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8122 | auto *PrivateVD = buildVarDecl(*this, ELoc, PrivateTy, D->getName(), |
| 8123 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8124 | // Add initializer for private variable. |
| 8125 | Expr *Init = nullptr; |
| 8126 | switch (BOK) { |
| 8127 | case BO_Add: |
| 8128 | case BO_Xor: |
| 8129 | case BO_Or: |
| 8130 | case BO_LOr: |
| 8131 | // '+', '-', '^', '|', '||' reduction ops - initializer is '0'. |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8132 | if (Type->isScalarType() || Type->isAnyComplexType()) |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8133 | Init = ActOnIntegerConstant(ELoc, /*Val=*/0).get(); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8134 | break; |
| 8135 | case BO_Mul: |
| 8136 | case BO_LAnd: |
| 8137 | if (Type->isScalarType() || Type->isAnyComplexType()) { |
| 8138 | // '*' and '&&' reduction ops - initializer is '1'. |
| 8139 | Init = ActOnIntegerConstant(ELoc, /*Val=*/1).get(); |
| 8140 | } |
| 8141 | break; |
| 8142 | case BO_And: { |
| 8143 | // '&' reduction op - initializer is '~0'. |
| 8144 | QualType OrigType = Type; |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8145 | if (auto *ComplexTy = OrigType->getAs<ComplexType>()) |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8146 | Type = ComplexTy->getElementType(); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8147 | if (Type->isRealFloatingType()) { |
| 8148 | llvm::APFloat InitValue = |
| 8149 | llvm::APFloat::getAllOnesValue(Context.getTypeSize(Type), |
| 8150 | /*isIEEE=*/true); |
| 8151 | Init = FloatingLiteral::Create(Context, InitValue, /*isexact=*/true, |
| 8152 | Type, ELoc); |
| 8153 | } else if (Type->isScalarType()) { |
| 8154 | auto Size = Context.getTypeSize(Type); |
| 8155 | QualType IntTy = Context.getIntTypeForBitwidth(Size, /*Signed=*/0); |
| 8156 | llvm::APInt InitValue = llvm::APInt::getAllOnesValue(Size); |
| 8157 | Init = IntegerLiteral::Create(Context, InitValue, IntTy, ELoc); |
| 8158 | } |
| 8159 | if (Init && OrigType->isAnyComplexType()) { |
| 8160 | // Init = 0xFFFF + 0xFFFFi; |
| 8161 | auto *Im = new (Context) ImaginaryLiteral(Init, OrigType); |
| 8162 | Init = CreateBuiltinBinOp(ELoc, BO_Add, Init, Im).get(); |
| 8163 | } |
| 8164 | Type = OrigType; |
| 8165 | break; |
| 8166 | } |
| 8167 | case BO_LT: |
| 8168 | case BO_GT: { |
| 8169 | // 'min' reduction op - initializer is 'Largest representable number in |
| 8170 | // the reduction list item type'. |
| 8171 | // 'max' reduction op - initializer is 'Least representable number in |
| 8172 | // the reduction list item type'. |
| 8173 | if (Type->isIntegerType() || Type->isPointerType()) { |
| 8174 | bool IsSigned = Type->hasSignedIntegerRepresentation(); |
| 8175 | auto Size = Context.getTypeSize(Type); |
| 8176 | QualType IntTy = |
| 8177 | Context.getIntTypeForBitwidth(Size, /*Signed=*/IsSigned); |
| 8178 | llvm::APInt InitValue = |
| 8179 | (BOK != BO_LT) |
| 8180 | ? IsSigned ? llvm::APInt::getSignedMinValue(Size) |
| 8181 | : llvm::APInt::getMinValue(Size) |
| 8182 | : IsSigned ? llvm::APInt::getSignedMaxValue(Size) |
| 8183 | : llvm::APInt::getMaxValue(Size); |
| 8184 | Init = IntegerLiteral::Create(Context, InitValue, IntTy, ELoc); |
| 8185 | if (Type->isPointerType()) { |
| 8186 | // Cast to pointer type. |
| 8187 | auto CastExpr = BuildCStyleCastExpr( |
| 8188 | SourceLocation(), Context.getTrivialTypeSourceInfo(Type, ELoc), |
| 8189 | SourceLocation(), Init); |
| 8190 | if (CastExpr.isInvalid()) |
| 8191 | continue; |
| 8192 | Init = CastExpr.get(); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8193 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8194 | } else if (Type->isRealFloatingType()) { |
| 8195 | llvm::APFloat InitValue = llvm::APFloat::getLargest( |
| 8196 | Context.getFloatTypeSemantics(Type), BOK != BO_LT); |
| 8197 | Init = FloatingLiteral::Create(Context, InitValue, /*isexact=*/true, |
| 8198 | Type, ELoc); |
| 8199 | } |
| 8200 | break; |
| 8201 | } |
| 8202 | case BO_PtrMemD: |
| 8203 | case BO_PtrMemI: |
| 8204 | case BO_MulAssign: |
| 8205 | case BO_Div: |
| 8206 | case BO_Rem: |
| 8207 | case BO_Sub: |
| 8208 | case BO_Shl: |
| 8209 | case BO_Shr: |
| 8210 | case BO_LE: |
| 8211 | case BO_GE: |
| 8212 | case BO_EQ: |
| 8213 | case BO_NE: |
| 8214 | case BO_AndAssign: |
| 8215 | case BO_XorAssign: |
| 8216 | case BO_OrAssign: |
| 8217 | case BO_Assign: |
| 8218 | case BO_AddAssign: |
| 8219 | case BO_SubAssign: |
| 8220 | case BO_DivAssign: |
| 8221 | case BO_RemAssign: |
| 8222 | case BO_ShlAssign: |
| 8223 | case BO_ShrAssign: |
| 8224 | case BO_Comma: |
| 8225 | llvm_unreachable("Unexpected reduction operation"); |
| 8226 | } |
| 8227 | if (Init) { |
| 8228 | AddInitializerToDecl(RHSVD, Init, /*DirectInit=*/false, |
| 8229 | /*TypeMayContainAuto=*/false); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8230 | } else |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8231 | ActOnUninitializedDecl(RHSVD, /*TypeMayContainAuto=*/false); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8232 | if (!RHSVD->hasInit()) { |
| 8233 | Diag(ELoc, diag::err_omp_reduction_id_not_compatible) << Type |
| 8234 | << ReductionIdRange; |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8235 | bool IsDecl = |
| 8236 | !VD || |
| 8237 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 8238 | Diag(D->getLocation(), |
| 8239 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 8240 | << D; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8241 | continue; |
| 8242 | } |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8243 | // Store initializer for single element in private copy. Will be used during |
| 8244 | // codegen. |
| 8245 | PrivateVD->setInit(RHSVD->getInit()); |
| 8246 | PrivateVD->setInitStyle(RHSVD->getInitStyle()); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 8247 | auto *LHSDRE = buildDeclRefExpr(*this, LHSVD, Type, ELoc); |
| 8248 | auto *RHSDRE = buildDeclRefExpr(*this, RHSVD, Type, ELoc); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8249 | auto *PrivateDRE = buildDeclRefExpr(*this, PrivateVD, PrivateTy, ELoc); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8250 | ExprResult ReductionOp = |
| 8251 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), BOK, |
| 8252 | LHSDRE, RHSDRE); |
| 8253 | if (ReductionOp.isUsable()) { |
Alexey Bataev | 69a4779 | 2015-05-07 03:54:03 +0000 | [diff] [blame] | 8254 | if (BOK != BO_LT && BOK != BO_GT) { |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8255 | ReductionOp = |
| 8256 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), |
| 8257 | BO_Assign, LHSDRE, ReductionOp.get()); |
| 8258 | } else { |
| 8259 | auto *ConditionalOp = new (Context) ConditionalOperator( |
| 8260 | ReductionOp.get(), SourceLocation(), LHSDRE, SourceLocation(), |
| 8261 | RHSDRE, Type, VK_LValue, OK_Ordinary); |
| 8262 | ReductionOp = |
| 8263 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), |
| 8264 | BO_Assign, LHSDRE, ConditionalOp); |
| 8265 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 8266 | ReductionOp = ActOnFinishFullExpr(ReductionOp.get()); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8267 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8268 | if (ReductionOp.isInvalid()) |
| 8269 | continue; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8270 | |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8271 | DeclRefExpr *Ref = nullptr; |
| 8272 | Expr *VarsExpr = RefExpr->IgnoreParens(); |
| 8273 | if (!VD) { |
| 8274 | if (ASE || OASE) { |
| 8275 | TransformExprToCaptures RebuildToCapture(*this, D); |
| 8276 | VarsExpr = |
| 8277 | RebuildToCapture.TransformExpr(RefExpr->IgnoreParens()).get(); |
| 8278 | Ref = RebuildToCapture.getCapturedExpr(); |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 8279 | } else { |
| 8280 | VarsExpr = Ref = |
| 8281 | buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false); |
| 8282 | if (!IsOpenMPCapturedDecl(D)) { |
| 8283 | ExprCaptures.push_back(Ref->getDecl()); |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8284 | if (Ref->getDecl()->hasAttr<OMPCaptureNoInitAttr>()) { |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 8285 | ExprResult RefRes = DefaultLvalueConversion(Ref); |
| 8286 | if (!RefRes.isUsable()) |
| 8287 | continue; |
| 8288 | ExprResult PostUpdateRes = |
| 8289 | BuildBinOp(DSAStack->getCurScope(), ELoc, BO_Assign, |
| 8290 | SimpleRefExpr, RefRes.get()); |
| 8291 | if (!PostUpdateRes.isUsable()) |
| 8292 | continue; |
Alexey Bataev | 78849fb | 2016-03-09 09:49:00 +0000 | [diff] [blame] | 8293 | ExprPostUpdates.push_back( |
| 8294 | IgnoredValueConversions(PostUpdateRes.get()).get()); |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 8295 | } |
| 8296 | } |
| 8297 | } |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8298 | } |
| 8299 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_reduction, Ref); |
| 8300 | Vars.push_back(VarsExpr); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8301 | Privates.push_back(PrivateDRE); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8302 | LHSs.push_back(LHSDRE); |
| 8303 | RHSs.push_back(RHSDRE); |
| 8304 | ReductionOps.push_back(ReductionOp.get()); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8305 | } |
| 8306 | |
| 8307 | if (Vars.empty()) |
| 8308 | return nullptr; |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 8309 | Stmt *PreInit = nullptr; |
| 8310 | if (!ExprCaptures.empty()) { |
| 8311 | PreInit = new (Context) |
| 8312 | DeclStmt(DeclGroupRef::Create(Context, ExprCaptures.begin(), |
| 8313 | ExprCaptures.size()), |
| 8314 | SourceLocation(), SourceLocation()); |
| 8315 | } |
| 8316 | Expr *PostUpdate = nullptr; |
| 8317 | if (!ExprPostUpdates.empty()) { |
| 8318 | for (auto *E : ExprPostUpdates) { |
| 8319 | ExprResult PostUpdateRes = |
| 8320 | PostUpdate |
| 8321 | ? CreateBuiltinBinOp(SourceLocation(), BO_Comma, PostUpdate, E) |
| 8322 | : E; |
| 8323 | PostUpdate = PostUpdateRes.get(); |
| 8324 | } |
| 8325 | } |
| 8326 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8327 | return OMPReductionClause::Create( |
| 8328 | Context, StartLoc, LParenLoc, ColonLoc, EndLoc, Vars, |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8329 | ReductionIdScopeSpec.getWithLocInContext(Context), ReductionId, Privates, |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 8330 | LHSs, RHSs, ReductionOps, PreInit, PostUpdate); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8331 | } |
| 8332 | |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 8333 | OMPClause *Sema::ActOnOpenMPLinearClause( |
| 8334 | ArrayRef<Expr *> VarList, Expr *Step, SourceLocation StartLoc, |
| 8335 | SourceLocation LParenLoc, OpenMPLinearClauseKind LinKind, |
| 8336 | SourceLocation LinLoc, SourceLocation ColonLoc, SourceLocation EndLoc) { |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8337 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8338 | SmallVector<Expr *, 8> Privates; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8339 | SmallVector<Expr *, 8> Inits; |
Alexey Bataev | 78849fb | 2016-03-09 09:49:00 +0000 | [diff] [blame] | 8340 | SmallVector<Decl *, 4> ExprCaptures; |
| 8341 | SmallVector<Expr *, 4> ExprPostUpdates; |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 8342 | if ((!LangOpts.CPlusPlus && LinKind != OMPC_LINEAR_val) || |
| 8343 | LinKind == OMPC_LINEAR_unknown) { |
| 8344 | Diag(LinLoc, diag::err_omp_wrong_linear_modifier) << LangOpts.CPlusPlus; |
| 8345 | LinKind = OMPC_LINEAR_val; |
| 8346 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8347 | for (auto &RefExpr : VarList) { |
| 8348 | assert(RefExpr && "NULL expr in OpenMP linear clause."); |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8349 | SourceLocation ELoc; |
| 8350 | SourceRange ERange; |
| 8351 | Expr *SimpleRefExpr = RefExpr; |
| 8352 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange, |
| 8353 | /*AllowArraySection=*/false); |
| 8354 | if (Res.second) { |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8355 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8356 | Vars.push_back(RefExpr); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8357 | Privates.push_back(nullptr); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8358 | Inits.push_back(nullptr); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8359 | } |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8360 | ValueDecl *D = Res.first; |
| 8361 | if (!D) |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8362 | continue; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8363 | |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8364 | QualType Type = D->getType(); |
| 8365 | auto *VD = dyn_cast<VarDecl>(D); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8366 | |
| 8367 | // OpenMP [2.14.3.7, linear clause] |
| 8368 | // A list-item cannot appear in more than one linear clause. |
| 8369 | // A list-item that appears in a linear clause cannot appear in any |
| 8370 | // other data-sharing attribute clause. |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8371 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8372 | if (DVar.RefExpr) { |
| 8373 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 8374 | << getOpenMPClauseName(OMPC_linear); |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8375 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8376 | continue; |
| 8377 | } |
| 8378 | |
| 8379 | // A variable must not have an incomplete type or a reference type. |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8380 | if (RequireCompleteType(ELoc, Type, |
| 8381 | diag::err_omp_linear_incomplete_type)) |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8382 | continue; |
Alexey Bataev | 1185e19 | 2015-08-20 12:15:57 +0000 | [diff] [blame] | 8383 | if ((LinKind == OMPC_LINEAR_uval || LinKind == OMPC_LINEAR_ref) && |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8384 | !Type->isReferenceType()) { |
Alexey Bataev | 1185e19 | 2015-08-20 12:15:57 +0000 | [diff] [blame] | 8385 | Diag(ELoc, diag::err_omp_wrong_linear_modifier_non_reference) |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8386 | << Type << getOpenMPSimpleClauseTypeName(OMPC_linear, LinKind); |
Alexey Bataev | 1185e19 | 2015-08-20 12:15:57 +0000 | [diff] [blame] | 8387 | continue; |
| 8388 | } |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8389 | Type = Type.getNonReferenceType(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8390 | |
| 8391 | // A list item must not be const-qualified. |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8392 | if (Type.isConstant(Context)) { |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8393 | Diag(ELoc, diag::err_omp_const_variable) |
| 8394 | << getOpenMPClauseName(OMPC_linear); |
| 8395 | bool IsDecl = |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8396 | !VD || |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8397 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8398 | Diag(D->getLocation(), |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8399 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8400 | << D; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8401 | continue; |
| 8402 | } |
| 8403 | |
| 8404 | // A list item must be of integral or pointer type. |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8405 | Type = Type.getUnqualifiedType().getCanonicalType(); |
| 8406 | const auto *Ty = Type.getTypePtrOrNull(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8407 | if (!Ty || (!Ty->isDependentType() && !Ty->isIntegralType(Context) && |
| 8408 | !Ty->isPointerType())) { |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8409 | Diag(ELoc, diag::err_omp_linear_expected_int_or_ptr) << Type; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8410 | bool IsDecl = |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8411 | !VD || |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8412 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8413 | Diag(D->getLocation(), |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8414 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8415 | << D; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8416 | continue; |
| 8417 | } |
| 8418 | |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8419 | // Build private copy of original var. |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8420 | auto *Private = buildVarDecl(*this, ELoc, Type, D->getName(), |
| 8421 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 8422 | auto *PrivateRef = buildDeclRefExpr(*this, Private, Type, ELoc); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8423 | // Build var to save initial value. |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8424 | VarDecl *Init = buildVarDecl(*this, ELoc, Type, ".linear.start"); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 8425 | Expr *InitExpr; |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8426 | DeclRefExpr *Ref = nullptr; |
Alexey Bataev | 78849fb | 2016-03-09 09:49:00 +0000 | [diff] [blame] | 8427 | if (!VD) { |
| 8428 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false); |
| 8429 | if (!IsOpenMPCapturedDecl(D)) { |
| 8430 | ExprCaptures.push_back(Ref->getDecl()); |
| 8431 | if (Ref->getDecl()->hasAttr<OMPCaptureNoInitAttr>()) { |
| 8432 | ExprResult RefRes = DefaultLvalueConversion(Ref); |
| 8433 | if (!RefRes.isUsable()) |
| 8434 | continue; |
| 8435 | ExprResult PostUpdateRes = |
| 8436 | BuildBinOp(DSAStack->getCurScope(), ELoc, BO_Assign, |
| 8437 | SimpleRefExpr, RefRes.get()); |
| 8438 | if (!PostUpdateRes.isUsable()) |
| 8439 | continue; |
| 8440 | ExprPostUpdates.push_back( |
| 8441 | IgnoredValueConversions(PostUpdateRes.get()).get()); |
| 8442 | } |
| 8443 | } |
| 8444 | } |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 8445 | if (LinKind == OMPC_LINEAR_uval) |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8446 | InitExpr = VD ? VD->getInit() : SimpleRefExpr; |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 8447 | else |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8448 | InitExpr = VD ? SimpleRefExpr : Ref; |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 8449 | AddInitializerToDecl(Init, DefaultLvalueConversion(InitExpr).get(), |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8450 | /*DirectInit=*/false, /*TypeMayContainAuto=*/false); |
| 8451 | auto InitRef = buildDeclRefExpr(*this, Init, Type, ELoc); |
| 8452 | |
| 8453 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_linear, Ref); |
| 8454 | Vars.push_back(VD ? RefExpr->IgnoreParens() : Ref); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8455 | Privates.push_back(PrivateRef); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8456 | Inits.push_back(InitRef); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8457 | } |
| 8458 | |
| 8459 | if (Vars.empty()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 8460 | return nullptr; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8461 | |
| 8462 | Expr *StepExpr = Step; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8463 | Expr *CalcStepExpr = nullptr; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8464 | if (Step && !Step->isValueDependent() && !Step->isTypeDependent() && |
| 8465 | !Step->isInstantiationDependent() && |
| 8466 | !Step->containsUnexpandedParameterPack()) { |
| 8467 | SourceLocation StepLoc = Step->getLocStart(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 8468 | ExprResult Val = PerformOpenMPImplicitIntegerConversion(StepLoc, Step); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8469 | if (Val.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 8470 | return nullptr; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 8471 | StepExpr = Val.get(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8472 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8473 | // Build var to save the step value. |
| 8474 | VarDecl *SaveVar = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 8475 | buildVarDecl(*this, StepLoc, StepExpr->getType(), ".linear.step"); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8476 | ExprResult SaveRef = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 8477 | buildDeclRefExpr(*this, SaveVar, StepExpr->getType(), StepLoc); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8478 | ExprResult CalcStep = |
| 8479 | BuildBinOp(CurScope, StepLoc, BO_Assign, SaveRef.get(), StepExpr); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 8480 | CalcStep = ActOnFinishFullExpr(CalcStep.get()); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8481 | |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8482 | // Warn about zero linear step (it would be probably better specified as |
| 8483 | // making corresponding variables 'const'). |
| 8484 | llvm::APSInt Result; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8485 | bool IsConstant = StepExpr->isIntegerConstantExpr(Result, Context); |
| 8486 | if (IsConstant && !Result.isNegative() && !Result.isStrictlyPositive()) |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8487 | Diag(StepLoc, diag::warn_omp_linear_step_zero) << Vars[0] |
| 8488 | << (Vars.size() > 1); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8489 | if (!IsConstant && CalcStep.isUsable()) { |
| 8490 | // Calculate the step beforehand instead of doing this on each iteration. |
| 8491 | // (This is not used if the number of iterations may be kfold-ed). |
| 8492 | CalcStepExpr = CalcStep.get(); |
| 8493 | } |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8494 | } |
| 8495 | |
Alexey Bataev | 78849fb | 2016-03-09 09:49:00 +0000 | [diff] [blame] | 8496 | Stmt *PreInit = nullptr; |
| 8497 | if (!ExprCaptures.empty()) { |
| 8498 | PreInit = new (Context) |
| 8499 | DeclStmt(DeclGroupRef::Create(Context, ExprCaptures.begin(), |
| 8500 | ExprCaptures.size()), |
| 8501 | SourceLocation(), SourceLocation()); |
| 8502 | } |
| 8503 | Expr *PostUpdate = nullptr; |
| 8504 | if (!ExprPostUpdates.empty()) { |
| 8505 | for (auto *E : ExprPostUpdates) { |
| 8506 | ExprResult PostUpdateRes = |
| 8507 | PostUpdate |
| 8508 | ? CreateBuiltinBinOp(SourceLocation(), BO_Comma, PostUpdate, E) |
| 8509 | : E; |
| 8510 | PostUpdate = PostUpdateRes.get(); |
| 8511 | } |
| 8512 | } |
| 8513 | |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 8514 | return OMPLinearClause::Create(Context, StartLoc, LParenLoc, LinKind, LinLoc, |
| 8515 | ColonLoc, EndLoc, Vars, Privates, Inits, |
Alexey Bataev | 78849fb | 2016-03-09 09:49:00 +0000 | [diff] [blame] | 8516 | StepExpr, CalcStepExpr, PreInit, PostUpdate); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8517 | } |
| 8518 | |
| 8519 | static bool FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV, |
| 8520 | Expr *NumIterations, Sema &SemaRef, |
| 8521 | Scope *S) { |
| 8522 | // Walk the vars and build update/final expressions for the CodeGen. |
| 8523 | SmallVector<Expr *, 8> Updates; |
| 8524 | SmallVector<Expr *, 8> Finals; |
| 8525 | Expr *Step = Clause.getStep(); |
| 8526 | Expr *CalcStep = Clause.getCalcStep(); |
| 8527 | // OpenMP [2.14.3.7, linear clause] |
| 8528 | // If linear-step is not specified it is assumed to be 1. |
| 8529 | if (Step == nullptr) |
| 8530 | Step = SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get(); |
| 8531 | else if (CalcStep) |
| 8532 | Step = cast<BinaryOperator>(CalcStep)->getLHS(); |
| 8533 | bool HasErrors = false; |
| 8534 | auto CurInit = Clause.inits().begin(); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8535 | auto CurPrivate = Clause.privates().begin(); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 8536 | auto LinKind = Clause.getModifier(); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8537 | for (auto &RefExpr : Clause.varlists()) { |
| 8538 | Expr *InitExpr = *CurInit; |
| 8539 | |
| 8540 | // Build privatized reference to the current linear var. |
| 8541 | auto DE = cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 8542 | Expr *CapturedRef; |
| 8543 | if (LinKind == OMPC_LINEAR_uval) |
| 8544 | CapturedRef = cast<VarDecl>(DE->getDecl())->getInit(); |
| 8545 | else |
| 8546 | CapturedRef = |
| 8547 | buildDeclRefExpr(SemaRef, cast<VarDecl>(DE->getDecl()), |
| 8548 | DE->getType().getUnqualifiedType(), DE->getExprLoc(), |
| 8549 | /*RefersToCapture=*/true); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8550 | |
| 8551 | // Build update: Var = InitExpr + IV * Step |
| 8552 | ExprResult Update = |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8553 | BuildCounterUpdate(SemaRef, S, RefExpr->getExprLoc(), *CurPrivate, |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8554 | InitExpr, IV, Step, /* Subtract */ false); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 8555 | Update = SemaRef.ActOnFinishFullExpr(Update.get(), DE->getLocStart(), |
| 8556 | /*DiscardedValue=*/true); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8557 | |
| 8558 | // Build final: Var = InitExpr + NumIterations * Step |
| 8559 | ExprResult Final = |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8560 | BuildCounterUpdate(SemaRef, S, RefExpr->getExprLoc(), CapturedRef, |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 8561 | InitExpr, NumIterations, Step, /* Subtract */ false); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 8562 | Final = SemaRef.ActOnFinishFullExpr(Final.get(), DE->getLocStart(), |
| 8563 | /*DiscardedValue=*/true); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8564 | if (!Update.isUsable() || !Final.isUsable()) { |
| 8565 | Updates.push_back(nullptr); |
| 8566 | Finals.push_back(nullptr); |
| 8567 | HasErrors = true; |
| 8568 | } else { |
| 8569 | Updates.push_back(Update.get()); |
| 8570 | Finals.push_back(Final.get()); |
| 8571 | } |
Richard Trieu | cc3949d | 2016-02-18 22:34:54 +0000 | [diff] [blame] | 8572 | ++CurInit; |
| 8573 | ++CurPrivate; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8574 | } |
| 8575 | Clause.setUpdates(Updates); |
| 8576 | Clause.setFinals(Finals); |
| 8577 | return HasErrors; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8578 | } |
| 8579 | |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 8580 | OMPClause *Sema::ActOnOpenMPAlignedClause( |
| 8581 | ArrayRef<Expr *> VarList, Expr *Alignment, SourceLocation StartLoc, |
| 8582 | SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc) { |
| 8583 | |
| 8584 | SmallVector<Expr *, 8> Vars; |
| 8585 | for (auto &RefExpr : VarList) { |
| 8586 | assert(RefExpr && "NULL expr in OpenMP aligned clause."); |
| 8587 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 8588 | // It will be analyzed later. |
| 8589 | Vars.push_back(RefExpr); |
| 8590 | continue; |
| 8591 | } |
| 8592 | |
| 8593 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 8594 | // OpenMP [2.1, C/C++] |
| 8595 | // A list item is a variable name. |
| 8596 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
| 8597 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8598 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr) |
| 8599 | << 0 << RefExpr->getSourceRange(); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 8600 | continue; |
| 8601 | } |
| 8602 | |
| 8603 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); |
| 8604 | |
| 8605 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 8606 | // The type of list items appearing in the aligned clause must be |
| 8607 | // array, pointer, reference to array, or reference to pointer. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8608 | QualType QType = VD->getType(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8609 | QType = QType.getNonReferenceType().getUnqualifiedType().getCanonicalType(); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 8610 | const Type *Ty = QType.getTypePtrOrNull(); |
| 8611 | if (!Ty || (!Ty->isDependentType() && !Ty->isArrayType() && |
| 8612 | !Ty->isPointerType())) { |
| 8613 | Diag(ELoc, diag::err_omp_aligned_expected_array_or_ptr) |
| 8614 | << QType << getLangOpts().CPlusPlus << RefExpr->getSourceRange(); |
| 8615 | bool IsDecl = |
| 8616 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 8617 | Diag(VD->getLocation(), |
| 8618 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 8619 | << VD; |
| 8620 | continue; |
| 8621 | } |
| 8622 | |
| 8623 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 8624 | // A list-item cannot appear in more than one aligned clause. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8625 | if (Expr *PrevRef = DSAStack->addUniqueAligned(VD, DE)) { |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 8626 | Diag(ELoc, diag::err_omp_aligned_twice) << RefExpr->getSourceRange(); |
| 8627 | Diag(PrevRef->getExprLoc(), diag::note_omp_explicit_dsa) |
| 8628 | << getOpenMPClauseName(OMPC_aligned); |
| 8629 | continue; |
| 8630 | } |
| 8631 | |
| 8632 | Vars.push_back(DE); |
| 8633 | } |
| 8634 | |
| 8635 | // OpenMP [2.8.1, simd construct, Description] |
| 8636 | // The parameter of the aligned clause, alignment, must be a constant |
| 8637 | // positive integer expression. |
| 8638 | // If no optional parameter is specified, implementation-defined default |
| 8639 | // alignments for SIMD instructions on the target platforms are assumed. |
| 8640 | if (Alignment != nullptr) { |
| 8641 | ExprResult AlignResult = |
| 8642 | VerifyPositiveIntegerConstantInClause(Alignment, OMPC_aligned); |
| 8643 | if (AlignResult.isInvalid()) |
| 8644 | return nullptr; |
| 8645 | Alignment = AlignResult.get(); |
| 8646 | } |
| 8647 | if (Vars.empty()) |
| 8648 | return nullptr; |
| 8649 | |
| 8650 | return OMPAlignedClause::Create(Context, StartLoc, LParenLoc, ColonLoc, |
| 8651 | EndLoc, Vars, Alignment); |
| 8652 | } |
| 8653 | |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8654 | OMPClause *Sema::ActOnOpenMPCopyinClause(ArrayRef<Expr *> VarList, |
| 8655 | SourceLocation StartLoc, |
| 8656 | SourceLocation LParenLoc, |
| 8657 | SourceLocation EndLoc) { |
| 8658 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 8659 | SmallVector<Expr *, 8> SrcExprs; |
| 8660 | SmallVector<Expr *, 8> DstExprs; |
| 8661 | SmallVector<Expr *, 8> AssignmentOps; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8662 | for (auto &RefExpr : VarList) { |
| 8663 | assert(RefExpr && "NULL expr in OpenMP copyin clause."); |
| 8664 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8665 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8666 | Vars.push_back(RefExpr); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 8667 | SrcExprs.push_back(nullptr); |
| 8668 | DstExprs.push_back(nullptr); |
| 8669 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8670 | continue; |
| 8671 | } |
| 8672 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8673 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8674 | // OpenMP [2.1, C/C++] |
| 8675 | // A list item is a variable name. |
| 8676 | // OpenMP [2.14.4.1, Restrictions, p.1] |
| 8677 | // A list item that appears in a copyin clause must be threadprivate. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8678 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8679 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8680 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr) |
| 8681 | << 0 << RefExpr->getSourceRange(); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8682 | continue; |
| 8683 | } |
| 8684 | |
| 8685 | Decl *D = DE->getDecl(); |
| 8686 | VarDecl *VD = cast<VarDecl>(D); |
| 8687 | |
| 8688 | QualType Type = VD->getType(); |
| 8689 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 8690 | // It will be analyzed later. |
| 8691 | Vars.push_back(DE); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 8692 | SrcExprs.push_back(nullptr); |
| 8693 | DstExprs.push_back(nullptr); |
| 8694 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8695 | continue; |
| 8696 | } |
| 8697 | |
| 8698 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.1] |
| 8699 | // A list item that appears in a copyin clause must be threadprivate. |
| 8700 | if (!DSAStack->isThreadPrivate(VD)) { |
| 8701 | Diag(ELoc, diag::err_omp_required_access) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8702 | << getOpenMPClauseName(OMPC_copyin) |
| 8703 | << getOpenMPDirectiveName(OMPD_threadprivate); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8704 | continue; |
| 8705 | } |
| 8706 | |
| 8707 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.2] |
| 8708 | // A variable of class type (or array thereof) that appears in a |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 8709 | // copyin clause requires an accessible, unambiguous copy assignment |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8710 | // operator for the class type. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8711 | auto ElemType = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 8712 | auto *SrcVD = |
| 8713 | buildVarDecl(*this, DE->getLocStart(), ElemType.getUnqualifiedType(), |
| 8714 | ".copyin.src", VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 8715 | auto *PseudoSrcExpr = buildDeclRefExpr( |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8716 | *this, SrcVD, ElemType.getUnqualifiedType(), DE->getExprLoc()); |
| 8717 | auto *DstVD = |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 8718 | buildVarDecl(*this, DE->getLocStart(), ElemType, ".copyin.dst", |
| 8719 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 8720 | auto *PseudoDstExpr = |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8721 | buildDeclRefExpr(*this, DstVD, ElemType, DE->getExprLoc()); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 8722 | // For arrays generate assignment operation for single element and replace |
| 8723 | // it by the original array element in CodeGen. |
| 8724 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, DE->getExprLoc(), BO_Assign, |
| 8725 | PseudoDstExpr, PseudoSrcExpr); |
| 8726 | if (AssignmentOp.isInvalid()) |
| 8727 | continue; |
| 8728 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), DE->getExprLoc(), |
| 8729 | /*DiscardedValue=*/true); |
| 8730 | if (AssignmentOp.isInvalid()) |
| 8731 | continue; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8732 | |
| 8733 | DSAStack->addDSA(VD, DE, OMPC_copyin); |
| 8734 | Vars.push_back(DE); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 8735 | SrcExprs.push_back(PseudoSrcExpr); |
| 8736 | DstExprs.push_back(PseudoDstExpr); |
| 8737 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8738 | } |
| 8739 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8740 | if (Vars.empty()) |
| 8741 | return nullptr; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8742 | |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 8743 | return OMPCopyinClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
| 8744 | SrcExprs, DstExprs, AssignmentOps); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8745 | } |
| 8746 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8747 | OMPClause *Sema::ActOnOpenMPCopyprivateClause(ArrayRef<Expr *> VarList, |
| 8748 | SourceLocation StartLoc, |
| 8749 | SourceLocation LParenLoc, |
| 8750 | SourceLocation EndLoc) { |
| 8751 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 8752 | SmallVector<Expr *, 8> SrcExprs; |
| 8753 | SmallVector<Expr *, 8> DstExprs; |
| 8754 | SmallVector<Expr *, 8> AssignmentOps; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8755 | for (auto &RefExpr : VarList) { |
| 8756 | assert(RefExpr && "NULL expr in OpenMP copyprivate clause."); |
| 8757 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 8758 | // It will be analyzed later. |
| 8759 | Vars.push_back(RefExpr); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 8760 | SrcExprs.push_back(nullptr); |
| 8761 | DstExprs.push_back(nullptr); |
| 8762 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8763 | continue; |
| 8764 | } |
| 8765 | |
| 8766 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 8767 | // OpenMP [2.1, C/C++] |
| 8768 | // A list item is a variable name. |
| 8769 | // OpenMP [2.14.4.1, Restrictions, p.1] |
| 8770 | // A list item that appears in a copyin clause must be threadprivate. |
| 8771 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
| 8772 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8773 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr) |
| 8774 | << 0 << RefExpr->getSourceRange(); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8775 | continue; |
| 8776 | } |
| 8777 | |
| 8778 | Decl *D = DE->getDecl(); |
| 8779 | VarDecl *VD = cast<VarDecl>(D); |
| 8780 | |
| 8781 | QualType Type = VD->getType(); |
| 8782 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 8783 | // It will be analyzed later. |
| 8784 | Vars.push_back(DE); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 8785 | SrcExprs.push_back(nullptr); |
| 8786 | DstExprs.push_back(nullptr); |
| 8787 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8788 | continue; |
| 8789 | } |
| 8790 | |
| 8791 | // OpenMP [2.14.4.2, Restrictions, p.2] |
| 8792 | // A list item that appears in a copyprivate clause may not appear in a |
| 8793 | // private or firstprivate clause on the single construct. |
| 8794 | if (!DSAStack->isThreadPrivate(VD)) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 8795 | auto DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 8796 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_copyprivate && |
| 8797 | DVar.RefExpr) { |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8798 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 8799 | << getOpenMPClauseName(DVar.CKind) |
| 8800 | << getOpenMPClauseName(OMPC_copyprivate); |
| 8801 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 8802 | continue; |
| 8803 | } |
| 8804 | |
| 8805 | // OpenMP [2.11.4.2, Restrictions, p.1] |
| 8806 | // All list items that appear in a copyprivate clause must be either |
| 8807 | // threadprivate or private in the enclosing context. |
| 8808 | if (DVar.CKind == OMPC_unknown) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 8809 | DVar = DSAStack->getImplicitDSA(VD, false); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8810 | if (DVar.CKind == OMPC_shared) { |
| 8811 | Diag(ELoc, diag::err_omp_required_access) |
| 8812 | << getOpenMPClauseName(OMPC_copyprivate) |
| 8813 | << "threadprivate or private in the enclosing context"; |
| 8814 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 8815 | continue; |
| 8816 | } |
| 8817 | } |
| 8818 | } |
| 8819 | |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 8820 | // Variably modified types are not supported. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 8821 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType()) { |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 8822 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8823 | << getOpenMPClauseName(OMPC_copyprivate) << Type |
| 8824 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 8825 | bool IsDecl = |
| 8826 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 8827 | Diag(VD->getLocation(), |
| 8828 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 8829 | << VD; |
| 8830 | continue; |
| 8831 | } |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8832 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8833 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.2] |
| 8834 | // A variable of class type (or array thereof) that appears in a |
| 8835 | // copyin clause requires an accessible, unambiguous copy assignment |
| 8836 | // operator for the class type. |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8837 | Type = Context.getBaseElementType(Type.getNonReferenceType()) |
| 8838 | .getUnqualifiedType(); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 8839 | auto *SrcVD = |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 8840 | buildVarDecl(*this, DE->getLocStart(), Type, ".copyprivate.src", |
| 8841 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 8842 | auto *PseudoSrcExpr = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 8843 | buildDeclRefExpr(*this, SrcVD, Type, DE->getExprLoc()); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 8844 | auto *DstVD = |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 8845 | buildVarDecl(*this, DE->getLocStart(), Type, ".copyprivate.dst", |
| 8846 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 8847 | auto *PseudoDstExpr = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 8848 | buildDeclRefExpr(*this, DstVD, Type, DE->getExprLoc()); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 8849 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, DE->getExprLoc(), BO_Assign, |
| 8850 | PseudoDstExpr, PseudoSrcExpr); |
| 8851 | if (AssignmentOp.isInvalid()) |
| 8852 | continue; |
| 8853 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), DE->getExprLoc(), |
| 8854 | /*DiscardedValue=*/true); |
| 8855 | if (AssignmentOp.isInvalid()) |
| 8856 | continue; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8857 | |
| 8858 | // No need to mark vars as copyprivate, they are already threadprivate or |
| 8859 | // implicitly private. |
| 8860 | Vars.push_back(DE); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 8861 | SrcExprs.push_back(PseudoSrcExpr); |
| 8862 | DstExprs.push_back(PseudoDstExpr); |
| 8863 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8864 | } |
| 8865 | |
| 8866 | if (Vars.empty()) |
| 8867 | return nullptr; |
| 8868 | |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 8869 | return OMPCopyprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| 8870 | Vars, SrcExprs, DstExprs, AssignmentOps); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8871 | } |
| 8872 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 8873 | OMPClause *Sema::ActOnOpenMPFlushClause(ArrayRef<Expr *> VarList, |
| 8874 | SourceLocation StartLoc, |
| 8875 | SourceLocation LParenLoc, |
| 8876 | SourceLocation EndLoc) { |
| 8877 | if (VarList.empty()) |
| 8878 | return nullptr; |
| 8879 | |
| 8880 | return OMPFlushClause::Create(Context, StartLoc, LParenLoc, EndLoc, VarList); |
| 8881 | } |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 8882 | |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8883 | OMPClause * |
| 8884 | Sema::ActOnOpenMPDependClause(OpenMPDependClauseKind DepKind, |
| 8885 | SourceLocation DepLoc, SourceLocation ColonLoc, |
| 8886 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
| 8887 | SourceLocation LParenLoc, SourceLocation EndLoc) { |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 8888 | if (DSAStack->getCurrentDirective() == OMPD_ordered && |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 8889 | DepKind != OMPC_DEPEND_source && DepKind != OMPC_DEPEND_sink) { |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 8890 | Diag(DepLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 8891 | << "'source' or 'sink'" << getOpenMPClauseName(OMPC_depend); |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 8892 | return nullptr; |
| 8893 | } |
| 8894 | if (DSAStack->getCurrentDirective() != OMPD_ordered && |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 8895 | (DepKind == OMPC_DEPEND_unknown || DepKind == OMPC_DEPEND_source || |
| 8896 | DepKind == OMPC_DEPEND_sink)) { |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 8897 | unsigned Except[] = {OMPC_DEPEND_source, OMPC_DEPEND_sink}; |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8898 | Diag(DepLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 8899 | << getListOfPossibleValues(OMPC_depend, /*First=*/0, |
| 8900 | /*Last=*/OMPC_DEPEND_unknown, Except) |
| 8901 | << getOpenMPClauseName(OMPC_depend); |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8902 | return nullptr; |
| 8903 | } |
| 8904 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 8905 | llvm::APSInt DepCounter(/*BitWidth=*/32); |
| 8906 | llvm::APSInt TotalDepCount(/*BitWidth=*/32); |
| 8907 | if (DepKind == OMPC_DEPEND_sink) { |
| 8908 | if (auto *OrderedCountExpr = DSAStack->getParentOrderedRegionParam()) { |
| 8909 | TotalDepCount = OrderedCountExpr->EvaluateKnownConstInt(Context); |
| 8910 | TotalDepCount.setIsUnsigned(/*Val=*/true); |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8911 | } |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8912 | } |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 8913 | if ((DepKind != OMPC_DEPEND_sink && DepKind != OMPC_DEPEND_source) || |
| 8914 | DSAStack->getParentOrderedRegionParam()) { |
| 8915 | for (auto &RefExpr : VarList) { |
| 8916 | assert(RefExpr && "NULL expr in OpenMP shared clause."); |
| 8917 | if (isa<DependentScopeDeclRefExpr>(RefExpr) || |
| 8918 | (DepKind == OMPC_DEPEND_sink && CurContext->isDependentContext())) { |
| 8919 | // It will be analyzed later. |
| 8920 | Vars.push_back(RefExpr); |
| 8921 | continue; |
| 8922 | } |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8923 | |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 8924 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 8925 | auto *SimpleExpr = RefExpr->IgnoreParenCasts(); |
| 8926 | if (DepKind == OMPC_DEPEND_sink) { |
| 8927 | if (DepCounter >= TotalDepCount) { |
| 8928 | Diag(ELoc, diag::err_omp_depend_sink_unexpected_expr); |
| 8929 | continue; |
| 8930 | } |
| 8931 | ++DepCounter; |
| 8932 | // OpenMP [2.13.9, Summary] |
| 8933 | // depend(dependence-type : vec), where dependence-type is: |
| 8934 | // 'sink' and where vec is the iteration vector, which has the form: |
| 8935 | // x1 [+- d1], x2 [+- d2 ], . . . , xn [+- dn] |
| 8936 | // where n is the value specified by the ordered clause in the loop |
| 8937 | // directive, xi denotes the loop iteration variable of the i-th nested |
| 8938 | // loop associated with the loop directive, and di is a constant |
| 8939 | // non-negative integer. |
| 8940 | SimpleExpr = SimpleExpr->IgnoreImplicit(); |
| 8941 | auto *DE = dyn_cast<DeclRefExpr>(SimpleExpr); |
| 8942 | if (!DE) { |
| 8943 | OverloadedOperatorKind OOK = OO_None; |
| 8944 | SourceLocation OOLoc; |
| 8945 | Expr *LHS, *RHS; |
| 8946 | if (auto *BO = dyn_cast<BinaryOperator>(SimpleExpr)) { |
| 8947 | OOK = BinaryOperator::getOverloadedOperator(BO->getOpcode()); |
| 8948 | OOLoc = BO->getOperatorLoc(); |
| 8949 | LHS = BO->getLHS()->IgnoreParenImpCasts(); |
| 8950 | RHS = BO->getRHS()->IgnoreParenImpCasts(); |
| 8951 | } else if (auto *OCE = dyn_cast<CXXOperatorCallExpr>(SimpleExpr)) { |
| 8952 | OOK = OCE->getOperator(); |
| 8953 | OOLoc = OCE->getOperatorLoc(); |
| 8954 | LHS = OCE->getArg(/*Arg=*/0)->IgnoreParenImpCasts(); |
| 8955 | RHS = OCE->getArg(/*Arg=*/1)->IgnoreParenImpCasts(); |
| 8956 | } else if (auto *MCE = dyn_cast<CXXMemberCallExpr>(SimpleExpr)) { |
| 8957 | OOK = MCE->getMethodDecl() |
| 8958 | ->getNameInfo() |
| 8959 | .getName() |
| 8960 | .getCXXOverloadedOperator(); |
| 8961 | OOLoc = MCE->getCallee()->getExprLoc(); |
| 8962 | LHS = MCE->getImplicitObjectArgument()->IgnoreParenImpCasts(); |
| 8963 | RHS = MCE->getArg(/*Arg=*/0)->IgnoreParenImpCasts(); |
| 8964 | } else { |
| 8965 | Diag(ELoc, diag::err_omp_depend_sink_wrong_expr); |
| 8966 | continue; |
| 8967 | } |
| 8968 | DE = dyn_cast<DeclRefExpr>(LHS); |
| 8969 | if (!DE) { |
| 8970 | Diag(LHS->getExprLoc(), |
| 8971 | diag::err_omp_depend_sink_expected_loop_iteration) |
| 8972 | << DSAStack->getParentLoopControlVariable( |
| 8973 | DepCounter.getZExtValue()); |
| 8974 | continue; |
| 8975 | } |
| 8976 | if (OOK != OO_Plus && OOK != OO_Minus) { |
| 8977 | Diag(OOLoc, diag::err_omp_depend_sink_expected_plus_minus); |
| 8978 | continue; |
| 8979 | } |
| 8980 | ExprResult Res = VerifyPositiveIntegerConstantInClause( |
| 8981 | RHS, OMPC_depend, /*StrictlyPositive=*/false); |
| 8982 | if (Res.isInvalid()) |
| 8983 | continue; |
| 8984 | } |
| 8985 | auto *VD = dyn_cast<VarDecl>(DE->getDecl()); |
| 8986 | if (!CurContext->isDependentContext() && |
| 8987 | DSAStack->getParentOrderedRegionParam() && |
| 8988 | (!VD || DepCounter != DSAStack->isParentLoopControlVariable(VD))) { |
| 8989 | Diag(DE->getExprLoc(), |
| 8990 | diag::err_omp_depend_sink_expected_loop_iteration) |
| 8991 | << DSAStack->getParentLoopControlVariable( |
| 8992 | DepCounter.getZExtValue()); |
| 8993 | continue; |
| 8994 | } |
| 8995 | } else { |
| 8996 | // OpenMP [2.11.1.1, Restrictions, p.3] |
| 8997 | // A variable that is part of another variable (such as a field of a |
| 8998 | // structure) but is not an array element or an array section cannot |
| 8999 | // appear in a depend clause. |
| 9000 | auto *DE = dyn_cast<DeclRefExpr>(SimpleExpr); |
| 9001 | auto *ASE = dyn_cast<ArraySubscriptExpr>(SimpleExpr); |
| 9002 | auto *OASE = dyn_cast<OMPArraySectionExpr>(SimpleExpr); |
| 9003 | if (!RefExpr->IgnoreParenImpCasts()->isLValue() || |
| 9004 | (!ASE && !DE && !OASE) || (DE && !isa<VarDecl>(DE->getDecl())) || |
Alexey Bataev | 31300ed | 2016-02-04 11:27:03 +0000 | [diff] [blame] | 9005 | (ASE && |
| 9006 | !ASE->getBase() |
| 9007 | ->getType() |
| 9008 | .getNonReferenceType() |
| 9009 | ->isPointerType() && |
| 9010 | !ASE->getBase()->getType().getNonReferenceType()->isArrayType())) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 9011 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr_or_array_item) |
| 9012 | << 0 << RefExpr->getSourceRange(); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 9013 | continue; |
| 9014 | } |
| 9015 | } |
| 9016 | |
| 9017 | Vars.push_back(RefExpr->IgnoreParenImpCasts()); |
| 9018 | } |
| 9019 | |
| 9020 | if (!CurContext->isDependentContext() && DepKind == OMPC_DEPEND_sink && |
| 9021 | TotalDepCount > VarList.size() && |
| 9022 | DSAStack->getParentOrderedRegionParam()) { |
| 9023 | Diag(EndLoc, diag::err_omp_depend_sink_expected_loop_iteration) |
| 9024 | << DSAStack->getParentLoopControlVariable(VarList.size() + 1); |
| 9025 | } |
| 9026 | if (DepKind != OMPC_DEPEND_source && DepKind != OMPC_DEPEND_sink && |
| 9027 | Vars.empty()) |
| 9028 | return nullptr; |
| 9029 | } |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 9030 | |
| 9031 | return OMPDependClause::Create(Context, StartLoc, LParenLoc, EndLoc, DepKind, |
| 9032 | DepLoc, ColonLoc, Vars); |
| 9033 | } |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 9034 | |
| 9035 | OMPClause *Sema::ActOnOpenMPDeviceClause(Expr *Device, SourceLocation StartLoc, |
| 9036 | SourceLocation LParenLoc, |
| 9037 | SourceLocation EndLoc) { |
| 9038 | Expr *ValExpr = Device; |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 9039 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 9040 | // OpenMP [2.9.1, Restrictions] |
| 9041 | // The device expression must evaluate to a non-negative integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 9042 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_device, |
| 9043 | /*StrictlyPositive=*/false)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 9044 | return nullptr; |
| 9045 | |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 9046 | return new (Context) OMPDeviceClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 9047 | } |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9048 | |
| 9049 | static bool IsCXXRecordForMappable(Sema &SemaRef, SourceLocation Loc, |
| 9050 | DSAStackTy *Stack, CXXRecordDecl *RD) { |
| 9051 | if (!RD || RD->isInvalidDecl()) |
| 9052 | return true; |
| 9053 | |
Alexey Bataev | c9bd03d | 2015-12-17 06:55:08 +0000 | [diff] [blame] | 9054 | if (auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(RD)) |
| 9055 | if (auto *CTD = CTSD->getSpecializedTemplate()) |
| 9056 | RD = CTD->getTemplatedDecl(); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9057 | auto QTy = SemaRef.Context.getRecordType(RD); |
| 9058 | if (RD->isDynamicClass()) { |
| 9059 | SemaRef.Diag(Loc, diag::err_omp_not_mappable_type) << QTy; |
| 9060 | SemaRef.Diag(RD->getLocation(), diag::note_omp_polymorphic_in_target); |
| 9061 | return false; |
| 9062 | } |
| 9063 | auto *DC = RD; |
| 9064 | bool IsCorrect = true; |
| 9065 | for (auto *I : DC->decls()) { |
| 9066 | if (I) { |
| 9067 | if (auto *MD = dyn_cast<CXXMethodDecl>(I)) { |
| 9068 | if (MD->isStatic()) { |
| 9069 | SemaRef.Diag(Loc, diag::err_omp_not_mappable_type) << QTy; |
| 9070 | SemaRef.Diag(MD->getLocation(), |
| 9071 | diag::note_omp_static_member_in_target); |
| 9072 | IsCorrect = false; |
| 9073 | } |
| 9074 | } else if (auto *VD = dyn_cast<VarDecl>(I)) { |
| 9075 | if (VD->isStaticDataMember()) { |
| 9076 | SemaRef.Diag(Loc, diag::err_omp_not_mappable_type) << QTy; |
| 9077 | SemaRef.Diag(VD->getLocation(), |
| 9078 | diag::note_omp_static_member_in_target); |
| 9079 | IsCorrect = false; |
| 9080 | } |
| 9081 | } |
| 9082 | } |
| 9083 | } |
| 9084 | |
| 9085 | for (auto &I : RD->bases()) { |
| 9086 | if (!IsCXXRecordForMappable(SemaRef, I.getLocStart(), Stack, |
| 9087 | I.getType()->getAsCXXRecordDecl())) |
| 9088 | IsCorrect = false; |
| 9089 | } |
| 9090 | return IsCorrect; |
| 9091 | } |
| 9092 | |
| 9093 | static bool CheckTypeMappable(SourceLocation SL, SourceRange SR, Sema &SemaRef, |
| 9094 | DSAStackTy *Stack, QualType QTy) { |
| 9095 | NamedDecl *ND; |
| 9096 | if (QTy->isIncompleteType(&ND)) { |
| 9097 | SemaRef.Diag(SL, diag::err_incomplete_type) << QTy << SR; |
| 9098 | return false; |
| 9099 | } else if (CXXRecordDecl *RD = dyn_cast_or_null<CXXRecordDecl>(ND)) { |
| 9100 | if (!RD->isInvalidDecl() && |
| 9101 | !IsCXXRecordForMappable(SemaRef, SL, Stack, RD)) |
| 9102 | return false; |
| 9103 | } |
| 9104 | return true; |
| 9105 | } |
| 9106 | |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 9107 | /// \brief Return true if it can be proven that the provided array expression |
| 9108 | /// (array section or array subscript) does NOT specify the whole size of the |
| 9109 | /// array whose base type is \a BaseQTy. |
| 9110 | static bool CheckArrayExpressionDoesNotReferToWholeSize(Sema &SemaRef, |
| 9111 | const Expr *E, |
| 9112 | QualType BaseQTy) { |
| 9113 | auto *OASE = dyn_cast<OMPArraySectionExpr>(E); |
| 9114 | |
| 9115 | // If this is an array subscript, it refers to the whole size if the size of |
| 9116 | // the dimension is constant and equals 1. Also, an array section assumes the |
| 9117 | // format of an array subscript if no colon is used. |
| 9118 | if (isa<ArraySubscriptExpr>(E) || (OASE && OASE->getColonLoc().isInvalid())) { |
| 9119 | if (auto *ATy = dyn_cast<ConstantArrayType>(BaseQTy.getTypePtr())) |
| 9120 | return ATy->getSize().getSExtValue() != 1; |
| 9121 | // Size can't be evaluated statically. |
| 9122 | return false; |
| 9123 | } |
| 9124 | |
| 9125 | assert(OASE && "Expecting array section if not an array subscript."); |
| 9126 | auto *LowerBound = OASE->getLowerBound(); |
| 9127 | auto *Length = OASE->getLength(); |
| 9128 | |
| 9129 | // If there is a lower bound that does not evaluates to zero, we are not |
| 9130 | // convering the whole dimension. |
| 9131 | if (LowerBound) { |
| 9132 | llvm::APSInt ConstLowerBound; |
| 9133 | if (!LowerBound->EvaluateAsInt(ConstLowerBound, SemaRef.getASTContext())) |
| 9134 | return false; // Can't get the integer value as a constant. |
| 9135 | if (ConstLowerBound.getSExtValue()) |
| 9136 | return true; |
| 9137 | } |
| 9138 | |
| 9139 | // If we don't have a length we covering the whole dimension. |
| 9140 | if (!Length) |
| 9141 | return false; |
| 9142 | |
| 9143 | // If the base is a pointer, we don't have a way to get the size of the |
| 9144 | // pointee. |
| 9145 | if (BaseQTy->isPointerType()) |
| 9146 | return false; |
| 9147 | |
| 9148 | // We can only check if the length is the same as the size of the dimension |
| 9149 | // if we have a constant array. |
| 9150 | auto *CATy = dyn_cast<ConstantArrayType>(BaseQTy.getTypePtr()); |
| 9151 | if (!CATy) |
| 9152 | return false; |
| 9153 | |
| 9154 | llvm::APSInt ConstLength; |
| 9155 | if (!Length->EvaluateAsInt(ConstLength, SemaRef.getASTContext())) |
| 9156 | return false; // Can't get the integer value as a constant. |
| 9157 | |
| 9158 | return CATy->getSize().getSExtValue() != ConstLength.getSExtValue(); |
| 9159 | } |
| 9160 | |
| 9161 | // Return true if it can be proven that the provided array expression (array |
| 9162 | // section or array subscript) does NOT specify a single element of the array |
| 9163 | // whose base type is \a BaseQTy. |
| 9164 | static bool CheckArrayExpressionDoesNotReferToUnitySize(Sema &SemaRef, |
| 9165 | const Expr *E, |
| 9166 | QualType BaseQTy) { |
| 9167 | auto *OASE = dyn_cast<OMPArraySectionExpr>(E); |
| 9168 | |
| 9169 | // An array subscript always refer to a single element. Also, an array section |
| 9170 | // assumes the format of an array subscript if no colon is used. |
| 9171 | if (isa<ArraySubscriptExpr>(E) || (OASE && OASE->getColonLoc().isInvalid())) |
| 9172 | return false; |
| 9173 | |
| 9174 | assert(OASE && "Expecting array section if not an array subscript."); |
| 9175 | auto *Length = OASE->getLength(); |
| 9176 | |
| 9177 | // If we don't have a length we have to check if the array has unitary size |
| 9178 | // for this dimension. Also, we should always expect a length if the base type |
| 9179 | // is pointer. |
| 9180 | if (!Length) { |
| 9181 | if (auto *ATy = dyn_cast<ConstantArrayType>(BaseQTy.getTypePtr())) |
| 9182 | return ATy->getSize().getSExtValue() != 1; |
| 9183 | // We cannot assume anything. |
| 9184 | return false; |
| 9185 | } |
| 9186 | |
| 9187 | // Check if the length evaluates to 1. |
| 9188 | llvm::APSInt ConstLength; |
| 9189 | if (!Length->EvaluateAsInt(ConstLength, SemaRef.getASTContext())) |
| 9190 | return false; // Can't get the integer value as a constant. |
| 9191 | |
| 9192 | return ConstLength.getSExtValue() != 1; |
| 9193 | } |
| 9194 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9195 | // Return the expression of the base of the map clause or null if it cannot |
| 9196 | // be determined and do all the necessary checks to see if the expression is |
| 9197 | // valid as a standalone map clause expression. |
| 9198 | static Expr *CheckMapClauseExpressionBase(Sema &SemaRef, Expr *E) { |
| 9199 | SourceLocation ELoc = E->getExprLoc(); |
| 9200 | SourceRange ERange = E->getSourceRange(); |
| 9201 | |
| 9202 | // The base of elements of list in a map clause have to be either: |
| 9203 | // - a reference to variable or field. |
| 9204 | // - a member expression. |
| 9205 | // - an array expression. |
| 9206 | // |
| 9207 | // E.g. if we have the expression 'r.S.Arr[:12]', we want to retrieve the |
| 9208 | // reference to 'r'. |
| 9209 | // |
| 9210 | // If we have: |
| 9211 | // |
| 9212 | // struct SS { |
| 9213 | // Bla S; |
| 9214 | // foo() { |
| 9215 | // #pragma omp target map (S.Arr[:12]); |
| 9216 | // } |
| 9217 | // } |
| 9218 | // |
| 9219 | // We want to retrieve the member expression 'this->S'; |
| 9220 | |
| 9221 | Expr *RelevantExpr = nullptr; |
| 9222 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9223 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.2] |
| 9224 | // If a list item is an array section, it must specify contiguous storage. |
| 9225 | // |
| 9226 | // For this restriction it is sufficient that we make sure only references |
| 9227 | // to variables or fields and array expressions, and that no array sections |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 9228 | // exist except in the rightmost expression (unless they cover the whole |
| 9229 | // dimension of the array). E.g. these would be invalid: |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9230 | // |
| 9231 | // r.ArrS[3:5].Arr[6:7] |
| 9232 | // |
| 9233 | // r.ArrS[3:5].x |
| 9234 | // |
| 9235 | // but these would be valid: |
| 9236 | // r.ArrS[3].Arr[6:7] |
| 9237 | // |
| 9238 | // r.ArrS[3].x |
| 9239 | |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 9240 | bool AllowUnitySizeArraySection = true; |
| 9241 | bool AllowWholeSizeArraySection = true; |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9242 | |
Dmitry Polukhin | 644a925 | 2016-03-11 07:58:34 +0000 | [diff] [blame^] | 9243 | while (!RelevantExpr) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9244 | E = E->IgnoreParenImpCasts(); |
| 9245 | |
| 9246 | if (auto *CurE = dyn_cast<DeclRefExpr>(E)) { |
| 9247 | if (!isa<VarDecl>(CurE->getDecl())) |
| 9248 | break; |
| 9249 | |
| 9250 | RelevantExpr = CurE; |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 9251 | |
| 9252 | // If we got a reference to a declaration, we should not expect any array |
| 9253 | // section before that. |
| 9254 | AllowUnitySizeArraySection = false; |
| 9255 | AllowWholeSizeArraySection = false; |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9256 | continue; |
| 9257 | } |
| 9258 | |
| 9259 | if (auto *CurE = dyn_cast<MemberExpr>(E)) { |
| 9260 | auto *BaseE = CurE->getBase()->IgnoreParenImpCasts(); |
| 9261 | |
| 9262 | if (isa<CXXThisExpr>(BaseE)) |
| 9263 | // We found a base expression: this->Val. |
| 9264 | RelevantExpr = CurE; |
| 9265 | else |
| 9266 | E = BaseE; |
| 9267 | |
| 9268 | if (!isa<FieldDecl>(CurE->getMemberDecl())) { |
| 9269 | SemaRef.Diag(ELoc, diag::err_omp_expected_access_to_data_field) |
| 9270 | << CurE->getSourceRange(); |
| 9271 | break; |
| 9272 | } |
| 9273 | |
| 9274 | auto *FD = cast<FieldDecl>(CurE->getMemberDecl()); |
| 9275 | |
| 9276 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C/C++, p.3] |
| 9277 | // A bit-field cannot appear in a map clause. |
| 9278 | // |
| 9279 | if (FD->isBitField()) { |
| 9280 | SemaRef.Diag(ELoc, diag::err_omp_bit_fields_forbidden_in_map_clause) |
| 9281 | << CurE->getSourceRange(); |
| 9282 | break; |
| 9283 | } |
| 9284 | |
| 9285 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] |
| 9286 | // If the type of a list item is a reference to a type T then the type |
| 9287 | // will be considered to be T for all purposes of this clause. |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 9288 | QualType CurType = BaseE->getType().getNonReferenceType(); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9289 | |
| 9290 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C/C++, p.2] |
| 9291 | // A list item cannot be a variable that is a member of a structure with |
| 9292 | // a union type. |
| 9293 | // |
| 9294 | if (auto *RT = CurType->getAs<RecordType>()) |
| 9295 | if (RT->isUnionType()) { |
| 9296 | SemaRef.Diag(ELoc, diag::err_omp_union_type_not_allowed) |
| 9297 | << CurE->getSourceRange(); |
| 9298 | break; |
| 9299 | } |
| 9300 | |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 9301 | // If we got a member expression, we should not expect any array section |
| 9302 | // before that: |
| 9303 | // |
| 9304 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.7] |
| 9305 | // If a list item is an element of a structure, only the rightmost symbol |
| 9306 | // of the variable reference can be an array section. |
| 9307 | // |
| 9308 | AllowUnitySizeArraySection = false; |
| 9309 | AllowWholeSizeArraySection = false; |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9310 | continue; |
| 9311 | } |
| 9312 | |
| 9313 | if (auto *CurE = dyn_cast<ArraySubscriptExpr>(E)) { |
| 9314 | E = CurE->getBase()->IgnoreParenImpCasts(); |
| 9315 | |
| 9316 | if (!E->getType()->isAnyPointerType() && !E->getType()->isArrayType()) { |
| 9317 | SemaRef.Diag(ELoc, diag::err_omp_expected_base_var_name) |
| 9318 | << 0 << CurE->getSourceRange(); |
| 9319 | break; |
| 9320 | } |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 9321 | |
| 9322 | // If we got an array subscript that express the whole dimension we |
| 9323 | // can have any array expressions before. If it only expressing part of |
| 9324 | // the dimension, we can only have unitary-size array expressions. |
| 9325 | if (CheckArrayExpressionDoesNotReferToWholeSize(SemaRef, CurE, |
| 9326 | E->getType())) |
| 9327 | AllowWholeSizeArraySection = false; |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9328 | continue; |
| 9329 | } |
| 9330 | |
| 9331 | if (auto *CurE = dyn_cast<OMPArraySectionExpr>(E)) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9332 | E = CurE->getBase()->IgnoreParenImpCasts(); |
| 9333 | |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 9334 | auto CurType = |
| 9335 | OMPArraySectionExpr::getBaseOriginalType(E).getCanonicalType(); |
| 9336 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9337 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] |
| 9338 | // If the type of a list item is a reference to a type T then the type |
| 9339 | // will be considered to be T for all purposes of this clause. |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9340 | if (CurType->isReferenceType()) |
| 9341 | CurType = CurType->getPointeeType(); |
| 9342 | |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 9343 | bool IsPointer = CurType->isAnyPointerType(); |
| 9344 | |
| 9345 | if (!IsPointer && !CurType->isArrayType()) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9346 | SemaRef.Diag(ELoc, diag::err_omp_expected_base_var_name) |
| 9347 | << 0 << CurE->getSourceRange(); |
| 9348 | break; |
| 9349 | } |
| 9350 | |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 9351 | bool NotWhole = |
| 9352 | CheckArrayExpressionDoesNotReferToWholeSize(SemaRef, CurE, CurType); |
| 9353 | bool NotUnity = |
| 9354 | CheckArrayExpressionDoesNotReferToUnitySize(SemaRef, CurE, CurType); |
| 9355 | |
| 9356 | if (AllowWholeSizeArraySection && AllowUnitySizeArraySection) { |
| 9357 | // Any array section is currently allowed. |
| 9358 | // |
| 9359 | // If this array section refers to the whole dimension we can still |
| 9360 | // accept other array sections before this one, except if the base is a |
| 9361 | // pointer. Otherwise, only unitary sections are accepted. |
| 9362 | if (NotWhole || IsPointer) |
| 9363 | AllowWholeSizeArraySection = false; |
| 9364 | } else if ((AllowUnitySizeArraySection && NotUnity) || |
| 9365 | (AllowWholeSizeArraySection && NotWhole)) { |
| 9366 | // A unity or whole array section is not allowed and that is not |
| 9367 | // compatible with the properties of the current array section. |
| 9368 | SemaRef.Diag( |
| 9369 | ELoc, diag::err_array_section_does_not_specify_contiguous_storage) |
| 9370 | << CurE->getSourceRange(); |
| 9371 | break; |
| 9372 | } |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9373 | continue; |
| 9374 | } |
| 9375 | |
| 9376 | // If nothing else worked, this is not a valid map clause expression. |
| 9377 | SemaRef.Diag(ELoc, |
| 9378 | diag::err_omp_expected_named_var_member_or_array_expression) |
| 9379 | << ERange; |
| 9380 | break; |
| 9381 | } |
| 9382 | |
| 9383 | return RelevantExpr; |
| 9384 | } |
| 9385 | |
| 9386 | // Return true if expression E associated with value VD has conflicts with other |
| 9387 | // map information. |
| 9388 | static bool CheckMapConflicts(Sema &SemaRef, DSAStackTy *DSAS, ValueDecl *VD, |
| 9389 | Expr *E, bool CurrentRegionOnly) { |
| 9390 | assert(VD && E); |
| 9391 | |
| 9392 | // Types used to organize the components of a valid map clause. |
| 9393 | typedef std::pair<Expr *, ValueDecl *> MapExpressionComponent; |
| 9394 | typedef SmallVector<MapExpressionComponent, 4> MapExpressionComponents; |
| 9395 | |
| 9396 | // Helper to extract the components in the map clause expression E and store |
| 9397 | // them into MEC. This assumes that E is a valid map clause expression, i.e. |
| 9398 | // it has already passed the single clause checks. |
| 9399 | auto ExtractMapExpressionComponents = [](Expr *TE, |
| 9400 | MapExpressionComponents &MEC) { |
| 9401 | while (true) { |
| 9402 | TE = TE->IgnoreParenImpCasts(); |
| 9403 | |
| 9404 | if (auto *CurE = dyn_cast<DeclRefExpr>(TE)) { |
| 9405 | MEC.push_back( |
| 9406 | MapExpressionComponent(CurE, cast<VarDecl>(CurE->getDecl()))); |
| 9407 | break; |
| 9408 | } |
| 9409 | |
| 9410 | if (auto *CurE = dyn_cast<MemberExpr>(TE)) { |
| 9411 | auto *BaseE = CurE->getBase()->IgnoreParenImpCasts(); |
| 9412 | |
| 9413 | MEC.push_back(MapExpressionComponent( |
| 9414 | CurE, cast<FieldDecl>(CurE->getMemberDecl()))); |
| 9415 | if (isa<CXXThisExpr>(BaseE)) |
| 9416 | break; |
| 9417 | |
| 9418 | TE = BaseE; |
| 9419 | continue; |
| 9420 | } |
| 9421 | |
| 9422 | if (auto *CurE = dyn_cast<ArraySubscriptExpr>(TE)) { |
| 9423 | MEC.push_back(MapExpressionComponent(CurE, nullptr)); |
| 9424 | TE = CurE->getBase()->IgnoreParenImpCasts(); |
| 9425 | continue; |
| 9426 | } |
| 9427 | |
| 9428 | if (auto *CurE = dyn_cast<OMPArraySectionExpr>(TE)) { |
| 9429 | MEC.push_back(MapExpressionComponent(CurE, nullptr)); |
| 9430 | TE = CurE->getBase()->IgnoreParenImpCasts(); |
| 9431 | continue; |
| 9432 | } |
| 9433 | |
| 9434 | llvm_unreachable( |
| 9435 | "Expecting only valid map clause expressions at this point!"); |
| 9436 | } |
| 9437 | }; |
| 9438 | |
| 9439 | SourceLocation ELoc = E->getExprLoc(); |
| 9440 | SourceRange ERange = E->getSourceRange(); |
| 9441 | |
| 9442 | // In order to easily check the conflicts we need to match each component of |
| 9443 | // the expression under test with the components of the expressions that are |
| 9444 | // already in the stack. |
| 9445 | |
| 9446 | MapExpressionComponents CurComponents; |
| 9447 | ExtractMapExpressionComponents(E, CurComponents); |
| 9448 | |
| 9449 | assert(!CurComponents.empty() && "Map clause expression with no components!"); |
| 9450 | assert(CurComponents.back().second == VD && |
| 9451 | "Map clause expression with unexpected base!"); |
| 9452 | |
| 9453 | // Variables to help detecting enclosing problems in data environment nests. |
| 9454 | bool IsEnclosedByDataEnvironmentExpr = false; |
| 9455 | Expr *EnclosingExpr = nullptr; |
| 9456 | |
| 9457 | bool FoundError = |
| 9458 | DSAS->checkMapInfoForVar(VD, CurrentRegionOnly, [&](Expr *RE) -> bool { |
| 9459 | MapExpressionComponents StackComponents; |
| 9460 | ExtractMapExpressionComponents(RE, StackComponents); |
| 9461 | assert(!StackComponents.empty() && |
| 9462 | "Map clause expression with no components!"); |
| 9463 | assert(StackComponents.back().second == VD && |
| 9464 | "Map clause expression with unexpected base!"); |
| 9465 | |
| 9466 | // Expressions must start from the same base. Here we detect at which |
| 9467 | // point both expressions diverge from each other and see if we can |
| 9468 | // detect if the memory referred to both expressions is contiguous and |
| 9469 | // do not overlap. |
| 9470 | auto CI = CurComponents.rbegin(); |
| 9471 | auto CE = CurComponents.rend(); |
| 9472 | auto SI = StackComponents.rbegin(); |
| 9473 | auto SE = StackComponents.rend(); |
| 9474 | for (; CI != CE && SI != SE; ++CI, ++SI) { |
| 9475 | |
| 9476 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.3] |
| 9477 | // At most one list item can be an array item derived from a given |
| 9478 | // variable in map clauses of the same construct. |
| 9479 | if (CurrentRegionOnly && (isa<ArraySubscriptExpr>(CI->first) || |
| 9480 | isa<OMPArraySectionExpr>(CI->first)) && |
| 9481 | (isa<ArraySubscriptExpr>(SI->first) || |
| 9482 | isa<OMPArraySectionExpr>(SI->first))) { |
| 9483 | SemaRef.Diag(CI->first->getExprLoc(), |
| 9484 | diag::err_omp_multiple_array_items_in_map_clause) |
| 9485 | << CI->first->getSourceRange(); |
| 9486 | ; |
| 9487 | SemaRef.Diag(SI->first->getExprLoc(), diag::note_used_here) |
| 9488 | << SI->first->getSourceRange(); |
| 9489 | return true; |
| 9490 | } |
| 9491 | |
| 9492 | // Do both expressions have the same kind? |
| 9493 | if (CI->first->getStmtClass() != SI->first->getStmtClass()) |
| 9494 | break; |
| 9495 | |
| 9496 | // Are we dealing with different variables/fields? |
| 9497 | if (CI->second != SI->second) |
| 9498 | break; |
| 9499 | } |
| 9500 | |
| 9501 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.4] |
| 9502 | // List items of map clauses in the same construct must not share |
| 9503 | // original storage. |
| 9504 | // |
| 9505 | // If the expressions are exactly the same or one is a subset of the |
| 9506 | // other, it means they are sharing storage. |
| 9507 | if (CI == CE && SI == SE) { |
| 9508 | if (CurrentRegionOnly) { |
| 9509 | SemaRef.Diag(ELoc, diag::err_omp_map_shared_storage) << ERange; |
| 9510 | SemaRef.Diag(RE->getExprLoc(), diag::note_used_here) |
| 9511 | << RE->getSourceRange(); |
| 9512 | return true; |
| 9513 | } else { |
| 9514 | // If we find the same expression in the enclosing data environment, |
| 9515 | // that is legal. |
| 9516 | IsEnclosedByDataEnvironmentExpr = true; |
| 9517 | return false; |
| 9518 | } |
| 9519 | } |
| 9520 | |
| 9521 | QualType DerivedType = std::prev(CI)->first->getType(); |
| 9522 | SourceLocation DerivedLoc = std::prev(CI)->first->getExprLoc(); |
| 9523 | |
| 9524 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] |
| 9525 | // If the type of a list item is a reference to a type T then the type |
| 9526 | // will be considered to be T for all purposes of this clause. |
| 9527 | if (DerivedType->isReferenceType()) |
| 9528 | DerivedType = DerivedType->getPointeeType(); |
| 9529 | |
| 9530 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C/C++, p.1] |
| 9531 | // A variable for which the type is pointer and an array section |
| 9532 | // derived from that variable must not appear as list items of map |
| 9533 | // clauses of the same construct. |
| 9534 | // |
| 9535 | // Also, cover one of the cases in: |
| 9536 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.5] |
| 9537 | // If any part of the original storage of a list item has corresponding |
| 9538 | // storage in the device data environment, all of the original storage |
| 9539 | // must have corresponding storage in the device data environment. |
| 9540 | // |
| 9541 | if (DerivedType->isAnyPointerType()) { |
| 9542 | if (CI == CE || SI == SE) { |
| 9543 | SemaRef.Diag( |
| 9544 | DerivedLoc, |
| 9545 | diag::err_omp_pointer_mapped_along_with_derived_section) |
| 9546 | << DerivedLoc; |
| 9547 | } else { |
| 9548 | assert(CI != CE && SI != SE); |
| 9549 | SemaRef.Diag(DerivedLoc, diag::err_omp_same_pointer_derreferenced) |
| 9550 | << DerivedLoc; |
| 9551 | } |
| 9552 | SemaRef.Diag(RE->getExprLoc(), diag::note_used_here) |
| 9553 | << RE->getSourceRange(); |
| 9554 | return true; |
| 9555 | } |
| 9556 | |
| 9557 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.4] |
| 9558 | // List items of map clauses in the same construct must not share |
| 9559 | // original storage. |
| 9560 | // |
| 9561 | // An expression is a subset of the other. |
| 9562 | if (CurrentRegionOnly && (CI == CE || SI == SE)) { |
| 9563 | SemaRef.Diag(ELoc, diag::err_omp_map_shared_storage) << ERange; |
| 9564 | SemaRef.Diag(RE->getExprLoc(), diag::note_used_here) |
| 9565 | << RE->getSourceRange(); |
| 9566 | return true; |
| 9567 | } |
| 9568 | |
| 9569 | // The current expression uses the same base as other expression in the |
| 9570 | // data environment but does not contain it completelly. |
| 9571 | if (!CurrentRegionOnly && SI != SE) |
| 9572 | EnclosingExpr = RE; |
| 9573 | |
| 9574 | // The current expression is a subset of the expression in the data |
| 9575 | // environment. |
| 9576 | IsEnclosedByDataEnvironmentExpr |= |
| 9577 | (!CurrentRegionOnly && CI != CE && SI == SE); |
| 9578 | |
| 9579 | return false; |
| 9580 | }); |
| 9581 | |
| 9582 | if (CurrentRegionOnly) |
| 9583 | return FoundError; |
| 9584 | |
| 9585 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.5] |
| 9586 | // If any part of the original storage of a list item has corresponding |
| 9587 | // storage in the device data environment, all of the original storage must |
| 9588 | // have corresponding storage in the device data environment. |
| 9589 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.6] |
| 9590 | // If a list item is an element of a structure, and a different element of |
| 9591 | // the structure has a corresponding list item in the device data environment |
| 9592 | // prior to a task encountering the construct associated with the map clause, |
| 9593 | // then the list item must also have a correspnding list item in the device |
| 9594 | // data environment prior to the task encountering the construct. |
| 9595 | // |
| 9596 | if (EnclosingExpr && !IsEnclosedByDataEnvironmentExpr) { |
| 9597 | SemaRef.Diag(ELoc, |
| 9598 | diag::err_omp_original_storage_is_shared_and_does_not_contain) |
| 9599 | << ERange; |
| 9600 | SemaRef.Diag(EnclosingExpr->getExprLoc(), diag::note_used_here) |
| 9601 | << EnclosingExpr->getSourceRange(); |
| 9602 | return true; |
| 9603 | } |
| 9604 | |
| 9605 | return FoundError; |
| 9606 | } |
| 9607 | |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 9608 | OMPClause * |
| 9609 | Sema::ActOnOpenMPMapClause(OpenMPMapClauseKind MapTypeModifier, |
| 9610 | OpenMPMapClauseKind MapType, bool IsMapTypeImplicit, |
| 9611 | SourceLocation MapLoc, SourceLocation ColonLoc, |
| 9612 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
| 9613 | SourceLocation LParenLoc, SourceLocation EndLoc) { |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9614 | SmallVector<Expr *, 4> Vars; |
| 9615 | |
| 9616 | for (auto &RE : VarList) { |
| 9617 | assert(RE && "Null expr in omp map"); |
| 9618 | if (isa<DependentScopeDeclRefExpr>(RE)) { |
| 9619 | // It will be analyzed later. |
| 9620 | Vars.push_back(RE); |
| 9621 | continue; |
| 9622 | } |
| 9623 | SourceLocation ELoc = RE->getExprLoc(); |
| 9624 | |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9625 | auto *VE = RE->IgnoreParenLValueCasts(); |
| 9626 | |
| 9627 | if (VE->isValueDependent() || VE->isTypeDependent() || |
| 9628 | VE->isInstantiationDependent() || |
| 9629 | VE->containsUnexpandedParameterPack()) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9630 | // We can only analyze this information once the missing information is |
| 9631 | // resolved. |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9632 | Vars.push_back(RE); |
| 9633 | continue; |
| 9634 | } |
| 9635 | |
| 9636 | auto *SimpleExpr = RE->IgnoreParenCasts(); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9637 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9638 | if (!RE->IgnoreParenImpCasts()->isLValue()) { |
| 9639 | Diag(ELoc, diag::err_omp_expected_named_var_member_or_array_expression) |
| 9640 | << RE->getSourceRange(); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9641 | continue; |
| 9642 | } |
| 9643 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9644 | // Obtain the array or member expression bases if required. |
| 9645 | auto *BE = CheckMapClauseExpressionBase(*this, SimpleExpr); |
| 9646 | if (!BE) |
| 9647 | continue; |
| 9648 | |
| 9649 | // If the base is a reference to a variable, we rely on that variable for |
| 9650 | // the following checks. If it is a 'this' expression we rely on the field. |
| 9651 | ValueDecl *D = nullptr; |
| 9652 | if (auto *DRE = dyn_cast<DeclRefExpr>(BE)) { |
| 9653 | D = DRE->getDecl(); |
| 9654 | } else { |
| 9655 | auto *ME = cast<MemberExpr>(BE); |
| 9656 | assert(isa<CXXThisExpr>(ME->getBase()) && "Unexpected expression!"); |
| 9657 | D = ME->getMemberDecl(); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9658 | } |
| 9659 | assert(D && "Null decl on map clause."); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9660 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9661 | auto *VD = dyn_cast<VarDecl>(D); |
| 9662 | auto *FD = dyn_cast<FieldDecl>(D); |
| 9663 | |
| 9664 | assert((VD || FD) && "Only variables or fields are expected here!"); |
NAKAMURA Takumi | 6dcb814 | 2016-01-23 01:38:20 +0000 | [diff] [blame] | 9665 | (void)FD; |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9666 | |
| 9667 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.10] |
| 9668 | // threadprivate variables cannot appear in a map clause. |
| 9669 | if (VD && DSAStack->isThreadPrivate(VD)) { |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9670 | auto DVar = DSAStack->getTopDSA(VD, false); |
| 9671 | Diag(ELoc, diag::err_omp_threadprivate_in_map); |
| 9672 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 9673 | continue; |
| 9674 | } |
| 9675 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9676 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.9] |
| 9677 | // A list item cannot appear in both a map clause and a data-sharing |
| 9678 | // attribute clause on the same construct. |
| 9679 | // |
| 9680 | // TODO: Implement this check - it cannot currently be tested because of |
| 9681 | // missing implementation of the other data sharing clauses in target |
| 9682 | // directives. |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9683 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9684 | // Check conflicts with other map clause expressions. We check the conflicts |
| 9685 | // with the current construct separately from the enclosing data |
| 9686 | // environment, because the restrictions are different. |
| 9687 | if (CheckMapConflicts(*this, DSAStack, D, SimpleExpr, |
| 9688 | /*CurrentRegionOnly=*/true)) |
| 9689 | break; |
| 9690 | if (CheckMapConflicts(*this, DSAStack, D, SimpleExpr, |
| 9691 | /*CurrentRegionOnly=*/false)) |
| 9692 | break; |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9693 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9694 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] |
| 9695 | // If the type of a list item is a reference to a type T then the type will |
| 9696 | // be considered to be T for all purposes of this clause. |
| 9697 | QualType Type = D->getType(); |
| 9698 | if (Type->isReferenceType()) |
| 9699 | Type = Type->getPointeeType(); |
| 9700 | |
| 9701 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.9] |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9702 | // A list item must have a mappable type. |
| 9703 | if (!CheckTypeMappable(VE->getExprLoc(), VE->getSourceRange(), *this, |
| 9704 | DSAStack, Type)) |
| 9705 | continue; |
| 9706 | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 9707 | // target enter data |
| 9708 | // OpenMP [2.10.2, Restrictions, p. 99] |
| 9709 | // A map-type must be specified in all map clauses and must be either |
| 9710 | // to or alloc. |
| 9711 | OpenMPDirectiveKind DKind = DSAStack->getCurrentDirective(); |
| 9712 | if (DKind == OMPD_target_enter_data && |
| 9713 | !(MapType == OMPC_MAP_to || MapType == OMPC_MAP_alloc)) { |
| 9714 | Diag(StartLoc, diag::err_omp_invalid_map_type_for_directive) |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 9715 | << (IsMapTypeImplicit ? 1 : 0) |
| 9716 | << getOpenMPSimpleClauseTypeName(OMPC_map, MapType) |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 9717 | << getOpenMPDirectiveName(DKind); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9718 | continue; |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 9719 | } |
| 9720 | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 9721 | // target exit_data |
| 9722 | // OpenMP [2.10.3, Restrictions, p. 102] |
| 9723 | // A map-type must be specified in all map clauses and must be either |
| 9724 | // from, release, or delete. |
| 9725 | DKind = DSAStack->getCurrentDirective(); |
| 9726 | if (DKind == OMPD_target_exit_data && |
| 9727 | !(MapType == OMPC_MAP_from || MapType == OMPC_MAP_release || |
| 9728 | MapType == OMPC_MAP_delete)) { |
| 9729 | Diag(StartLoc, diag::err_omp_invalid_map_type_for_directive) |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 9730 | << (IsMapTypeImplicit ? 1 : 0) |
| 9731 | << getOpenMPSimpleClauseTypeName(OMPC_map, MapType) |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 9732 | << getOpenMPDirectiveName(DKind); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9733 | continue; |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 9734 | } |
| 9735 | |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9736 | Vars.push_back(RE); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9737 | DSAStack->addExprToVarMapInfo(D, RE); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9738 | } |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9739 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9740 | // We need to produce a map clause even if we don't have variables so that |
| 9741 | // other diagnostics related with non-existing map clauses are accurate. |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9742 | return OMPMapClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 9743 | MapTypeModifier, MapType, IsMapTypeImplicit, |
| 9744 | MapLoc); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9745 | } |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 9746 | |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 9747 | QualType Sema::ActOnOpenMPDeclareReductionType(SourceLocation TyLoc, |
| 9748 | TypeResult ParsedType) { |
| 9749 | assert(ParsedType.isUsable()); |
| 9750 | |
| 9751 | QualType ReductionType = GetTypeFromParser(ParsedType.get()); |
| 9752 | if (ReductionType.isNull()) |
| 9753 | return QualType(); |
| 9754 | |
| 9755 | // [OpenMP 4.0], 2.15 declare reduction Directive, Restrictions, C\C++ |
| 9756 | // A type name in a declare reduction directive cannot be a function type, an |
| 9757 | // array type, a reference type, or a type qualified with const, volatile or |
| 9758 | // restrict. |
| 9759 | if (ReductionType.hasQualifiers()) { |
| 9760 | Diag(TyLoc, diag::err_omp_reduction_wrong_type) << 0; |
| 9761 | return QualType(); |
| 9762 | } |
| 9763 | |
| 9764 | if (ReductionType->isFunctionType()) { |
| 9765 | Diag(TyLoc, diag::err_omp_reduction_wrong_type) << 1; |
| 9766 | return QualType(); |
| 9767 | } |
| 9768 | if (ReductionType->isReferenceType()) { |
| 9769 | Diag(TyLoc, diag::err_omp_reduction_wrong_type) << 2; |
| 9770 | return QualType(); |
| 9771 | } |
| 9772 | if (ReductionType->isArrayType()) { |
| 9773 | Diag(TyLoc, diag::err_omp_reduction_wrong_type) << 3; |
| 9774 | return QualType(); |
| 9775 | } |
| 9776 | return ReductionType; |
| 9777 | } |
| 9778 | |
| 9779 | Sema::DeclGroupPtrTy Sema::ActOnOpenMPDeclareReductionDirectiveStart( |
| 9780 | Scope *S, DeclContext *DC, DeclarationName Name, |
| 9781 | ArrayRef<std::pair<QualType, SourceLocation>> ReductionTypes, |
| 9782 | AccessSpecifier AS, Decl *PrevDeclInScope) { |
| 9783 | SmallVector<Decl *, 8> Decls; |
| 9784 | Decls.reserve(ReductionTypes.size()); |
| 9785 | |
| 9786 | LookupResult Lookup(*this, Name, SourceLocation(), LookupOMPReductionName, |
| 9787 | ForRedeclaration); |
| 9788 | // [OpenMP 4.0], 2.15 declare reduction Directive, Restrictions |
| 9789 | // A reduction-identifier may not be re-declared in the current scope for the |
| 9790 | // same type or for a type that is compatible according to the base language |
| 9791 | // rules. |
| 9792 | llvm::DenseMap<QualType, SourceLocation> PreviousRedeclTypes; |
| 9793 | OMPDeclareReductionDecl *PrevDRD = nullptr; |
| 9794 | bool InCompoundScope = true; |
| 9795 | if (S != nullptr) { |
| 9796 | // Find previous declaration with the same name not referenced in other |
| 9797 | // declarations. |
| 9798 | FunctionScopeInfo *ParentFn = getEnclosingFunction(); |
| 9799 | InCompoundScope = |
| 9800 | (ParentFn != nullptr) && !ParentFn->CompoundScopes.empty(); |
| 9801 | LookupName(Lookup, S); |
| 9802 | FilterLookupForScope(Lookup, DC, S, /*ConsiderLinkage=*/false, |
| 9803 | /*AllowInlineNamespace=*/false); |
| 9804 | llvm::DenseMap<OMPDeclareReductionDecl *, bool> UsedAsPrevious; |
| 9805 | auto Filter = Lookup.makeFilter(); |
| 9806 | while (Filter.hasNext()) { |
| 9807 | auto *PrevDecl = cast<OMPDeclareReductionDecl>(Filter.next()); |
| 9808 | if (InCompoundScope) { |
| 9809 | auto I = UsedAsPrevious.find(PrevDecl); |
| 9810 | if (I == UsedAsPrevious.end()) |
| 9811 | UsedAsPrevious[PrevDecl] = false; |
| 9812 | if (auto *D = PrevDecl->getPrevDeclInScope()) |
| 9813 | UsedAsPrevious[D] = true; |
| 9814 | } |
| 9815 | PreviousRedeclTypes[PrevDecl->getType().getCanonicalType()] = |
| 9816 | PrevDecl->getLocation(); |
| 9817 | } |
| 9818 | Filter.done(); |
| 9819 | if (InCompoundScope) { |
| 9820 | for (auto &PrevData : UsedAsPrevious) { |
| 9821 | if (!PrevData.second) { |
| 9822 | PrevDRD = PrevData.first; |
| 9823 | break; |
| 9824 | } |
| 9825 | } |
| 9826 | } |
| 9827 | } else if (PrevDeclInScope != nullptr) { |
| 9828 | auto *PrevDRDInScope = PrevDRD = |
| 9829 | cast<OMPDeclareReductionDecl>(PrevDeclInScope); |
| 9830 | do { |
| 9831 | PreviousRedeclTypes[PrevDRDInScope->getType().getCanonicalType()] = |
| 9832 | PrevDRDInScope->getLocation(); |
| 9833 | PrevDRDInScope = PrevDRDInScope->getPrevDeclInScope(); |
| 9834 | } while (PrevDRDInScope != nullptr); |
| 9835 | } |
| 9836 | for (auto &TyData : ReductionTypes) { |
| 9837 | auto I = PreviousRedeclTypes.find(TyData.first.getCanonicalType()); |
| 9838 | bool Invalid = false; |
| 9839 | if (I != PreviousRedeclTypes.end()) { |
| 9840 | Diag(TyData.second, diag::err_omp_declare_reduction_redefinition) |
| 9841 | << TyData.first; |
| 9842 | Diag(I->second, diag::note_previous_definition); |
| 9843 | Invalid = true; |
| 9844 | } |
| 9845 | PreviousRedeclTypes[TyData.first.getCanonicalType()] = TyData.second; |
| 9846 | auto *DRD = OMPDeclareReductionDecl::Create(Context, DC, TyData.second, |
| 9847 | Name, TyData.first, PrevDRD); |
| 9848 | DC->addDecl(DRD); |
| 9849 | DRD->setAccess(AS); |
| 9850 | Decls.push_back(DRD); |
| 9851 | if (Invalid) |
| 9852 | DRD->setInvalidDecl(); |
| 9853 | else |
| 9854 | PrevDRD = DRD; |
| 9855 | } |
| 9856 | |
| 9857 | return DeclGroupPtrTy::make( |
| 9858 | DeclGroupRef::Create(Context, Decls.begin(), Decls.size())); |
| 9859 | } |
| 9860 | |
| 9861 | void Sema::ActOnOpenMPDeclareReductionCombinerStart(Scope *S, Decl *D) { |
| 9862 | auto *DRD = cast<OMPDeclareReductionDecl>(D); |
| 9863 | |
| 9864 | // Enter new function scope. |
| 9865 | PushFunctionScope(); |
| 9866 | getCurFunction()->setHasBranchProtectedScope(); |
| 9867 | getCurFunction()->setHasOMPDeclareReductionCombiner(); |
| 9868 | |
| 9869 | if (S != nullptr) |
| 9870 | PushDeclContext(S, DRD); |
| 9871 | else |
| 9872 | CurContext = DRD; |
| 9873 | |
| 9874 | PushExpressionEvaluationContext(PotentiallyEvaluated); |
| 9875 | |
| 9876 | QualType ReductionType = DRD->getType(); |
| 9877 | // Create 'T omp_in;' implicit param. |
| 9878 | auto *OmpInParm = |
| 9879 | ImplicitParamDecl::Create(Context, DRD, D->getLocation(), |
| 9880 | &Context.Idents.get("omp_in"), ReductionType); |
| 9881 | // Create 'T* omp_parm;T omp_out;'. All references to 'omp_out' will |
| 9882 | // be replaced by '*omp_parm' during codegen. This required because 'omp_out' |
| 9883 | // uses semantics of argument handles by value, but it should be passed by |
| 9884 | // reference. C lang does not support references, so pass all parameters as |
| 9885 | // pointers. |
| 9886 | // Create 'T omp_out;' variable. |
| 9887 | auto *OmpOutParm = |
| 9888 | buildVarDecl(*this, D->getLocation(), ReductionType, "omp_out"); |
| 9889 | if (S != nullptr) { |
| 9890 | PushOnScopeChains(OmpInParm, S); |
| 9891 | PushOnScopeChains(OmpOutParm, S); |
| 9892 | } else { |
| 9893 | DRD->addDecl(OmpInParm); |
| 9894 | DRD->addDecl(OmpOutParm); |
| 9895 | } |
| 9896 | } |
| 9897 | |
| 9898 | void Sema::ActOnOpenMPDeclareReductionCombinerEnd(Decl *D, Expr *Combiner) { |
| 9899 | auto *DRD = cast<OMPDeclareReductionDecl>(D); |
| 9900 | DiscardCleanupsInEvaluationContext(); |
| 9901 | PopExpressionEvaluationContext(); |
| 9902 | |
| 9903 | PopDeclContext(); |
| 9904 | PopFunctionScopeInfo(); |
| 9905 | |
| 9906 | if (Combiner != nullptr) |
| 9907 | DRD->setCombiner(Combiner); |
| 9908 | else |
| 9909 | DRD->setInvalidDecl(); |
| 9910 | } |
| 9911 | |
| 9912 | void Sema::ActOnOpenMPDeclareReductionInitializerStart(Scope *S, Decl *D) { |
| 9913 | auto *DRD = cast<OMPDeclareReductionDecl>(D); |
| 9914 | |
| 9915 | // Enter new function scope. |
| 9916 | PushFunctionScope(); |
| 9917 | getCurFunction()->setHasBranchProtectedScope(); |
| 9918 | |
| 9919 | if (S != nullptr) |
| 9920 | PushDeclContext(S, DRD); |
| 9921 | else |
| 9922 | CurContext = DRD; |
| 9923 | |
| 9924 | PushExpressionEvaluationContext(PotentiallyEvaluated); |
| 9925 | |
| 9926 | QualType ReductionType = DRD->getType(); |
| 9927 | // Create 'T omp_orig;' implicit param. |
| 9928 | auto *OmpOrigParm = |
| 9929 | ImplicitParamDecl::Create(Context, DRD, D->getLocation(), |
| 9930 | &Context.Idents.get("omp_orig"), ReductionType); |
| 9931 | // Create 'T* omp_parm;T omp_priv;'. All references to 'omp_priv' will |
| 9932 | // be replaced by '*omp_parm' during codegen. This required because 'omp_priv' |
| 9933 | // uses semantics of argument handles by value, but it should be passed by |
| 9934 | // reference. C lang does not support references, so pass all parameters as |
| 9935 | // pointers. |
| 9936 | // Create 'T omp_priv;' variable. |
| 9937 | auto *OmpPrivParm = |
| 9938 | buildVarDecl(*this, D->getLocation(), ReductionType, "omp_priv"); |
| 9939 | if (S != nullptr) { |
| 9940 | PushOnScopeChains(OmpPrivParm, S); |
| 9941 | PushOnScopeChains(OmpOrigParm, S); |
| 9942 | } else { |
| 9943 | DRD->addDecl(OmpPrivParm); |
| 9944 | DRD->addDecl(OmpOrigParm); |
| 9945 | } |
| 9946 | } |
| 9947 | |
| 9948 | void Sema::ActOnOpenMPDeclareReductionInitializerEnd(Decl *D, |
| 9949 | Expr *Initializer) { |
| 9950 | auto *DRD = cast<OMPDeclareReductionDecl>(D); |
| 9951 | DiscardCleanupsInEvaluationContext(); |
| 9952 | PopExpressionEvaluationContext(); |
| 9953 | |
| 9954 | PopDeclContext(); |
| 9955 | PopFunctionScopeInfo(); |
| 9956 | |
| 9957 | if (Initializer != nullptr) |
| 9958 | DRD->setInitializer(Initializer); |
| 9959 | else |
| 9960 | DRD->setInvalidDecl(); |
| 9961 | } |
| 9962 | |
| 9963 | Sema::DeclGroupPtrTy Sema::ActOnOpenMPDeclareReductionDirectiveEnd( |
| 9964 | Scope *S, DeclGroupPtrTy DeclReductions, bool IsValid) { |
| 9965 | for (auto *D : DeclReductions.get()) { |
| 9966 | if (IsValid) { |
| 9967 | auto *DRD = cast<OMPDeclareReductionDecl>(D); |
| 9968 | if (S != nullptr) |
| 9969 | PushOnScopeChains(DRD, S, /*AddToContext=*/false); |
| 9970 | } else |
| 9971 | D->setInvalidDecl(); |
| 9972 | } |
| 9973 | return DeclReductions; |
| 9974 | } |
| 9975 | |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 9976 | OMPClause *Sema::ActOnOpenMPNumTeamsClause(Expr *NumTeams, |
| 9977 | SourceLocation StartLoc, |
| 9978 | SourceLocation LParenLoc, |
| 9979 | SourceLocation EndLoc) { |
| 9980 | Expr *ValExpr = NumTeams; |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 9981 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 9982 | // OpenMP [teams Constrcut, Restrictions] |
| 9983 | // The num_teams expression must evaluate to a positive integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 9984 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_num_teams, |
| 9985 | /*StrictlyPositive=*/true)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 9986 | return nullptr; |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 9987 | |
| 9988 | return new (Context) OMPNumTeamsClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 9989 | } |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 9990 | |
| 9991 | OMPClause *Sema::ActOnOpenMPThreadLimitClause(Expr *ThreadLimit, |
| 9992 | SourceLocation StartLoc, |
| 9993 | SourceLocation LParenLoc, |
| 9994 | SourceLocation EndLoc) { |
| 9995 | Expr *ValExpr = ThreadLimit; |
| 9996 | |
| 9997 | // OpenMP [teams Constrcut, Restrictions] |
| 9998 | // The thread_limit expression must evaluate to a positive integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 9999 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_thread_limit, |
| 10000 | /*StrictlyPositive=*/true)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 10001 | return nullptr; |
| 10002 | |
| 10003 | return new (Context) OMPThreadLimitClause(ValExpr, StartLoc, LParenLoc, |
| 10004 | EndLoc); |
| 10005 | } |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 10006 | |
| 10007 | OMPClause *Sema::ActOnOpenMPPriorityClause(Expr *Priority, |
| 10008 | SourceLocation StartLoc, |
| 10009 | SourceLocation LParenLoc, |
| 10010 | SourceLocation EndLoc) { |
| 10011 | Expr *ValExpr = Priority; |
| 10012 | |
| 10013 | // OpenMP [2.9.1, task Constrcut] |
| 10014 | // The priority-value is a non-negative numerical scalar expression. |
| 10015 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_priority, |
| 10016 | /*StrictlyPositive=*/false)) |
| 10017 | return nullptr; |
| 10018 | |
| 10019 | return new (Context) OMPPriorityClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 10020 | } |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 10021 | |
| 10022 | OMPClause *Sema::ActOnOpenMPGrainsizeClause(Expr *Grainsize, |
| 10023 | SourceLocation StartLoc, |
| 10024 | SourceLocation LParenLoc, |
| 10025 | SourceLocation EndLoc) { |
| 10026 | Expr *ValExpr = Grainsize; |
| 10027 | |
| 10028 | // OpenMP [2.9.2, taskloop Constrcut] |
| 10029 | // The parameter of the grainsize clause must be a positive integer |
| 10030 | // expression. |
| 10031 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_grainsize, |
| 10032 | /*StrictlyPositive=*/true)) |
| 10033 | return nullptr; |
| 10034 | |
| 10035 | return new (Context) OMPGrainsizeClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 10036 | } |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 10037 | |
| 10038 | OMPClause *Sema::ActOnOpenMPNumTasksClause(Expr *NumTasks, |
| 10039 | SourceLocation StartLoc, |
| 10040 | SourceLocation LParenLoc, |
| 10041 | SourceLocation EndLoc) { |
| 10042 | Expr *ValExpr = NumTasks; |
| 10043 | |
| 10044 | // OpenMP [2.9.2, taskloop Constrcut] |
| 10045 | // The parameter of the num_tasks clause must be a positive integer |
| 10046 | // expression. |
| 10047 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_num_tasks, |
| 10048 | /*StrictlyPositive=*/true)) |
| 10049 | return nullptr; |
| 10050 | |
| 10051 | return new (Context) OMPNumTasksClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 10052 | } |
| 10053 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 10054 | OMPClause *Sema::ActOnOpenMPHintClause(Expr *Hint, SourceLocation StartLoc, |
| 10055 | SourceLocation LParenLoc, |
| 10056 | SourceLocation EndLoc) { |
| 10057 | // OpenMP [2.13.2, critical construct, Description] |
| 10058 | // ... where hint-expression is an integer constant expression that evaluates |
| 10059 | // to a valid lock hint. |
| 10060 | ExprResult HintExpr = VerifyPositiveIntegerConstantInClause(Hint, OMPC_hint); |
| 10061 | if (HintExpr.isInvalid()) |
| 10062 | return nullptr; |
| 10063 | return new (Context) |
| 10064 | OMPHintClause(HintExpr.get(), StartLoc, LParenLoc, EndLoc); |
| 10065 | } |
| 10066 | |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 10067 | OMPClause *Sema::ActOnOpenMPDistScheduleClause( |
| 10068 | OpenMPDistScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, |
| 10069 | SourceLocation LParenLoc, SourceLocation KindLoc, SourceLocation CommaLoc, |
| 10070 | SourceLocation EndLoc) { |
| 10071 | if (Kind == OMPC_DIST_SCHEDULE_unknown) { |
| 10072 | std::string Values; |
| 10073 | Values += "'"; |
| 10074 | Values += getOpenMPSimpleClauseTypeName(OMPC_dist_schedule, 0); |
| 10075 | Values += "'"; |
| 10076 | Diag(KindLoc, diag::err_omp_unexpected_clause_value) |
| 10077 | << Values << getOpenMPClauseName(OMPC_dist_schedule); |
| 10078 | return nullptr; |
| 10079 | } |
| 10080 | Expr *ValExpr = ChunkSize; |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 10081 | Stmt *HelperValStmt = nullptr; |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 10082 | if (ChunkSize) { |
| 10083 | if (!ChunkSize->isValueDependent() && !ChunkSize->isTypeDependent() && |
| 10084 | !ChunkSize->isInstantiationDependent() && |
| 10085 | !ChunkSize->containsUnexpandedParameterPack()) { |
| 10086 | SourceLocation ChunkSizeLoc = ChunkSize->getLocStart(); |
| 10087 | ExprResult Val = |
| 10088 | PerformOpenMPImplicitIntegerConversion(ChunkSizeLoc, ChunkSize); |
| 10089 | if (Val.isInvalid()) |
| 10090 | return nullptr; |
| 10091 | |
| 10092 | ValExpr = Val.get(); |
| 10093 | |
| 10094 | // OpenMP [2.7.1, Restrictions] |
| 10095 | // chunk_size must be a loop invariant integer expression with a positive |
| 10096 | // value. |
| 10097 | llvm::APSInt Result; |
| 10098 | if (ValExpr->isIntegerConstantExpr(Result, Context)) { |
| 10099 | if (Result.isSigned() && !Result.isStrictlyPositive()) { |
| 10100 | Diag(ChunkSizeLoc, diag::err_omp_negative_expression_in_clause) |
| 10101 | << "dist_schedule" << ChunkSize->getSourceRange(); |
| 10102 | return nullptr; |
| 10103 | } |
| 10104 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective())) { |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 10105 | ValExpr = buildCapture(*this, ValExpr); |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 10106 | Decl *D = cast<DeclRefExpr>(ValExpr)->getDecl(); |
| 10107 | HelperValStmt = |
| 10108 | new (Context) DeclStmt(DeclGroupRef::Create(Context, &D, |
| 10109 | /*NumDecls=*/1), |
| 10110 | SourceLocation(), SourceLocation()); |
| 10111 | ValExpr = DefaultLvalueConversion(ValExpr).get(); |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 10112 | } |
| 10113 | } |
| 10114 | } |
| 10115 | |
| 10116 | return new (Context) |
| 10117 | OMPDistScheduleClause(StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc, |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 10118 | Kind, ValExpr, HelperValStmt); |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 10119 | } |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 10120 | |
| 10121 | OMPClause *Sema::ActOnOpenMPDefaultmapClause( |
| 10122 | OpenMPDefaultmapClauseModifier M, OpenMPDefaultmapClauseKind Kind, |
| 10123 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation MLoc, |
| 10124 | SourceLocation KindLoc, SourceLocation EndLoc) { |
| 10125 | // OpenMP 4.5 only supports 'defaultmap(tofrom: scalar)' |
| 10126 | if (M != OMPC_DEFAULTMAP_MODIFIER_tofrom || |
| 10127 | Kind != OMPC_DEFAULTMAP_scalar) { |
| 10128 | std::string Value; |
| 10129 | SourceLocation Loc; |
| 10130 | Value += "'"; |
| 10131 | if (M != OMPC_DEFAULTMAP_MODIFIER_tofrom) { |
| 10132 | Value += getOpenMPSimpleClauseTypeName(OMPC_defaultmap, |
| 10133 | OMPC_DEFAULTMAP_MODIFIER_tofrom); |
| 10134 | Loc = MLoc; |
| 10135 | } else { |
| 10136 | Value += getOpenMPSimpleClauseTypeName(OMPC_defaultmap, |
| 10137 | OMPC_DEFAULTMAP_scalar); |
| 10138 | Loc = KindLoc; |
| 10139 | } |
| 10140 | Value += "'"; |
| 10141 | Diag(Loc, diag::err_omp_unexpected_clause_value) |
| 10142 | << Value << getOpenMPClauseName(OMPC_defaultmap); |
| 10143 | return nullptr; |
| 10144 | } |
| 10145 | |
| 10146 | return new (Context) |
| 10147 | OMPDefaultmapClause(StartLoc, LParenLoc, MLoc, KindLoc, EndLoc, Kind, M); |
| 10148 | } |