Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1 | //===--- SemaOpenMP.cpp - Semantic Analysis for OpenMP constructs ---------===// |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | /// \file |
| 10 | /// \brief This file implements semantic analysis for OpenMP directives and |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 11 | /// clauses. |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 12 | /// |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 15 | #include "TreeTransform.h" |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 16 | #include "clang/AST/ASTContext.h" |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 17 | #include "clang/AST/ASTMutationListener.h" |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 18 | #include "clang/AST/Decl.h" |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 19 | #include "clang/AST/DeclCXX.h" |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 20 | #include "clang/AST/DeclOpenMP.h" |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 21 | #include "clang/AST/StmtCXX.h" |
| 22 | #include "clang/AST/StmtOpenMP.h" |
| 23 | #include "clang/AST/StmtVisitor.h" |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 24 | #include "clang/Basic/OpenMPKinds.h" |
Samuel Antao | f8b5012 | 2015-07-13 22:54:53 +0000 | [diff] [blame] | 25 | #include "clang/Basic/TargetInfo.h" |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 26 | #include "clang/Lex/Preprocessor.h" |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 27 | #include "clang/Sema/Initialization.h" |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 28 | #include "clang/Sema/Lookup.h" |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 29 | #include "clang/Sema/Scope.h" |
| 30 | #include "clang/Sema/ScopeInfo.h" |
Chandler Carruth | 5553d0d | 2014-01-07 11:51:46 +0000 | [diff] [blame] | 31 | #include "clang/Sema/SemaInternal.h" |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 32 | using namespace clang; |
| 33 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 34 | //===----------------------------------------------------------------------===// |
| 35 | // Stack of data-sharing attributes for variables |
| 36 | //===----------------------------------------------------------------------===// |
| 37 | |
| 38 | namespace { |
| 39 | /// \brief Default data sharing attributes, which can be applied to directive. |
| 40 | enum DefaultDataSharingAttributes { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 41 | DSA_unspecified = 0, /// \brief Data sharing attribute not specified. |
| 42 | DSA_none = 1 << 0, /// \brief Default data sharing attribute 'none'. |
| 43 | DSA_shared = 1 << 1 /// \brief Default data sharing attribute 'shared'. |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 44 | }; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 45 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 46 | template <class T> struct MatchesAny { |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 47 | explicit MatchesAny(ArrayRef<T> Arr) : Arr(std::move(Arr)) {} |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 48 | bool operator()(T Kind) { |
| 49 | for (auto KindEl : Arr) |
| 50 | if (KindEl == Kind) |
| 51 | return true; |
| 52 | return false; |
| 53 | } |
| 54 | |
| 55 | private: |
| 56 | ArrayRef<T> Arr; |
| 57 | }; |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 58 | struct MatchesAlways { |
Angel Garcia Gomez | 637d1e6 | 2015-10-20 13:23:58 +0000 | [diff] [blame] | 59 | MatchesAlways() {} |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 60 | template <class T> bool operator()(T) { return true; } |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 61 | }; |
| 62 | |
| 63 | typedef MatchesAny<OpenMPClauseKind> MatchesAnyClause; |
| 64 | typedef MatchesAny<OpenMPDirectiveKind> MatchesAnyDirective; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 65 | |
| 66 | /// \brief Stack for tracking declarations used in OpenMP directives and |
| 67 | /// clauses and their data-sharing attributes. |
| 68 | class DSAStackTy { |
| 69 | public: |
| 70 | struct DSAVarData { |
| 71 | OpenMPDirectiveKind DKind; |
| 72 | OpenMPClauseKind CKind; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 73 | Expr *RefExpr; |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 74 | DeclRefExpr *PrivateCopy; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 75 | SourceLocation ImplicitDSALoc; |
| 76 | DSAVarData() |
| 77 | : DKind(OMPD_unknown), CKind(OMPC_unknown), RefExpr(nullptr), |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 78 | PrivateCopy(nullptr), ImplicitDSALoc() {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 79 | }; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 80 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 81 | private: |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 82 | typedef SmallVector<Expr *, 4> MapInfo; |
| 83 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 84 | struct DSAInfo { |
| 85 | OpenMPClauseKind Attributes; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 86 | Expr *RefExpr; |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 87 | DeclRefExpr *PrivateCopy; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 88 | }; |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 89 | typedef llvm::DenseMap<ValueDecl *, DSAInfo> DeclSAMapTy; |
| 90 | typedef llvm::DenseMap<ValueDecl *, Expr *> AlignedMapTy; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 91 | typedef llvm::DenseMap<ValueDecl *, unsigned> LoopControlVariablesMapTy; |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 92 | typedef llvm::DenseMap<ValueDecl *, MapInfo> MappedDeclsTy; |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 93 | typedef llvm::StringMap<std::pair<OMPCriticalDirective *, llvm::APSInt>> |
| 94 | CriticalsWithHintsTy; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 95 | |
| 96 | struct SharingMapTy { |
| 97 | DeclSAMapTy SharingMap; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 98 | AlignedMapTy AlignedMap; |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 99 | MappedDeclsTy MappedDecls; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 100 | LoopControlVariablesMapTy LCVMap; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 101 | DefaultDataSharingAttributes DefaultAttr; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 102 | SourceLocation DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 103 | OpenMPDirectiveKind Directive; |
| 104 | DeclarationNameInfo DirectiveName; |
| 105 | Scope *CurScope; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 106 | SourceLocation ConstructLoc; |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 107 | /// \brief first argument (Expr *) contains optional argument of the |
| 108 | /// 'ordered' clause, the second one is true if the regions has 'ordered' |
| 109 | /// clause, false otherwise. |
| 110 | llvm::PointerIntPair<Expr *, 1, bool> OrderedRegion; |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 111 | bool NowaitRegion; |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 112 | bool CancelRegion; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 113 | unsigned AssociatedLoops; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 114 | SourceLocation InnerTeamsRegionLoc; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 115 | SharingMapTy(OpenMPDirectiveKind DKind, DeclarationNameInfo Name, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 116 | Scope *CurScope, SourceLocation Loc) |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 117 | : SharingMap(), AlignedMap(), LCVMap(), DefaultAttr(DSA_unspecified), |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 118 | Directive(DKind), DirectiveName(std::move(Name)), CurScope(CurScope), |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 119 | ConstructLoc(Loc), OrderedRegion(), NowaitRegion(false), |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 120 | CancelRegion(false), AssociatedLoops(1), InnerTeamsRegionLoc() {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 121 | SharingMapTy() |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 122 | : SharingMap(), AlignedMap(), LCVMap(), DefaultAttr(DSA_unspecified), |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 123 | Directive(OMPD_unknown), DirectiveName(), CurScope(nullptr), |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 124 | ConstructLoc(), OrderedRegion(), NowaitRegion(false), |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 125 | CancelRegion(false), AssociatedLoops(1), InnerTeamsRegionLoc() {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 126 | }; |
| 127 | |
Axel Naumann | 323862e | 2016-02-03 10:45:22 +0000 | [diff] [blame] | 128 | typedef SmallVector<SharingMapTy, 4> StackTy; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 129 | |
| 130 | /// \brief Stack of used declaration and their data-sharing attributes. |
| 131 | StackTy Stack; |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 132 | /// \brief true, if check for DSA must be from parent directive, false, if |
| 133 | /// from current directive. |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 134 | OpenMPClauseKind ClauseKindMode; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 135 | Sema &SemaRef; |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 136 | bool ForceCapturing; |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 137 | CriticalsWithHintsTy Criticals; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 138 | |
| 139 | typedef SmallVector<SharingMapTy, 8>::reverse_iterator reverse_iterator; |
| 140 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 141 | DSAVarData getDSA(StackTy::reverse_iterator Iter, ValueDecl *D); |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 142 | |
| 143 | /// \brief Checks if the variable is a local for OpenMP region. |
| 144 | bool isOpenMPLocal(VarDecl *D, StackTy::reverse_iterator Iter); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 145 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 146 | public: |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 147 | explicit DSAStackTy(Sema &S) |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 148 | : Stack(1), ClauseKindMode(OMPC_unknown), SemaRef(S), |
| 149 | ForceCapturing(false) {} |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 150 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 151 | bool isClauseParsingMode() const { return ClauseKindMode != OMPC_unknown; } |
| 152 | void setClauseParsingMode(OpenMPClauseKind K) { ClauseKindMode = K; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 153 | |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 154 | bool isForceVarCapturing() const { return ForceCapturing; } |
| 155 | void setForceVarCapturing(bool V) { ForceCapturing = V; } |
| 156 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 157 | void push(OpenMPDirectiveKind DKind, const DeclarationNameInfo &DirName, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 158 | Scope *CurScope, SourceLocation Loc) { |
| 159 | Stack.push_back(SharingMapTy(DKind, DirName, CurScope, Loc)); |
| 160 | Stack.back().DefaultAttrLoc = Loc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | void pop() { |
| 164 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty!"); |
| 165 | Stack.pop_back(); |
| 166 | } |
| 167 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 168 | void addCriticalWithHint(OMPCriticalDirective *D, llvm::APSInt Hint) { |
| 169 | Criticals[D->getDirectiveName().getAsString()] = std::make_pair(D, Hint); |
| 170 | } |
| 171 | const std::pair<OMPCriticalDirective *, llvm::APSInt> |
| 172 | getCriticalWithHint(const DeclarationNameInfo &Name) const { |
| 173 | auto I = Criticals.find(Name.getAsString()); |
| 174 | if (I != Criticals.end()) |
| 175 | return I->second; |
| 176 | return std::make_pair(nullptr, llvm::APSInt()); |
| 177 | } |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 178 | /// \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] | 179 | /// add it and return NULL; otherwise return previous occurrence's expression |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 180 | /// for diagnostics. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 181 | Expr *addUniqueAligned(ValueDecl *D, Expr *NewDE); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 182 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 183 | /// \brief Register specified variable as loop control variable. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 184 | void addLoopControlVariable(ValueDecl *D); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 185 | /// \brief Check if the specified variable is a loop control variable for |
| 186 | /// current region. |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 187 | /// \return The index of the loop control variable in the list of associated |
| 188 | /// for-loops (from outer to inner). |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 189 | unsigned isLoopControlVariable(ValueDecl *D); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 190 | /// \brief Check if the specified variable is a loop control variable for |
| 191 | /// parent region. |
| 192 | /// \return The index of the loop control variable in the list of associated |
| 193 | /// for-loops (from outer to inner). |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 194 | unsigned isParentLoopControlVariable(ValueDecl *D); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 195 | /// \brief Get the loop control variable for the I-th loop (or nullptr) in |
| 196 | /// parent directive. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 197 | ValueDecl *getParentLoopControlVariable(unsigned I); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 198 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 199 | /// \brief Adds explicit data sharing attribute to the specified declaration. |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 200 | void addDSA(ValueDecl *D, Expr *E, OpenMPClauseKind A, |
| 201 | DeclRefExpr *PrivateCopy = nullptr); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 202 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 203 | /// \brief Returns data sharing attributes from top of the stack for the |
| 204 | /// specified declaration. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 205 | DSAVarData getTopDSA(ValueDecl *D, bool FromParent); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 206 | /// \brief Returns data-sharing attributes for the specified declaration. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 207 | DSAVarData getImplicitDSA(ValueDecl *D, bool FromParent); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 208 | /// \brief Checks if the specified variables has data-sharing attributes which |
| 209 | /// match specified \a CPred predicate in any directive which matches \a DPred |
| 210 | /// predicate. |
| 211 | template <class ClausesPredicate, class DirectivesPredicate> |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 212 | DSAVarData hasDSA(ValueDecl *D, ClausesPredicate CPred, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 213 | DirectivesPredicate DPred, bool FromParent); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 214 | /// \brief Checks if the specified variables has data-sharing attributes which |
| 215 | /// match specified \a CPred predicate in any innermost directive which |
| 216 | /// matches \a DPred predicate. |
| 217 | template <class ClausesPredicate, class DirectivesPredicate> |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 218 | DSAVarData hasInnermostDSA(ValueDecl *D, ClausesPredicate CPred, |
| 219 | DirectivesPredicate DPred, bool FromParent); |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 220 | /// \brief Checks if the specified variables has explicit data-sharing |
| 221 | /// attributes which match specified \a CPred predicate at the specified |
| 222 | /// OpenMP region. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 223 | bool hasExplicitDSA(ValueDecl *D, |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 224 | const llvm::function_ref<bool(OpenMPClauseKind)> &CPred, |
| 225 | unsigned Level); |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 226 | |
| 227 | /// \brief Returns true if the directive at level \Level matches in the |
| 228 | /// specified \a DPred predicate. |
| 229 | bool hasExplicitDirective( |
| 230 | const llvm::function_ref<bool(OpenMPDirectiveKind)> &DPred, |
| 231 | unsigned Level); |
| 232 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 233 | /// \brief Finds a directive which matches specified \a DPred predicate. |
| 234 | template <class NamedDirectivesPredicate> |
| 235 | bool hasDirective(NamedDirectivesPredicate DPred, bool FromParent); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 236 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 237 | /// \brief Returns currently analyzed directive. |
| 238 | OpenMPDirectiveKind getCurrentDirective() const { |
| 239 | return Stack.back().Directive; |
| 240 | } |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 241 | /// \brief Returns parent directive. |
| 242 | OpenMPDirectiveKind getParentDirective() const { |
| 243 | if (Stack.size() > 2) |
| 244 | return Stack[Stack.size() - 2].Directive; |
| 245 | return OMPD_unknown; |
| 246 | } |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 247 | /// \brief Return the directive associated with the provided scope. |
| 248 | OpenMPDirectiveKind getDirectiveForScope(const Scope *S) const; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 249 | |
| 250 | /// \brief Set default data sharing attribute to none. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 251 | void setDefaultDSANone(SourceLocation Loc) { |
| 252 | Stack.back().DefaultAttr = DSA_none; |
| 253 | Stack.back().DefaultAttrLoc = Loc; |
| 254 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 255 | /// \brief Set default data sharing attribute to shared. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 256 | void setDefaultDSAShared(SourceLocation Loc) { |
| 257 | Stack.back().DefaultAttr = DSA_shared; |
| 258 | Stack.back().DefaultAttrLoc = Loc; |
| 259 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 260 | |
| 261 | DefaultDataSharingAttributes getDefaultDSA() const { |
| 262 | return Stack.back().DefaultAttr; |
| 263 | } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 264 | SourceLocation getDefaultDSALocation() const { |
| 265 | return Stack.back().DefaultAttrLoc; |
| 266 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 267 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 268 | /// \brief Checks if the specified variable is a threadprivate. |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 269 | bool isThreadPrivate(VarDecl *D) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 270 | DSAVarData DVar = getTopDSA(D, false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 271 | return isOpenMPThreadPrivate(DVar.CKind); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 272 | } |
| 273 | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 274 | /// \brief Marks current region as ordered (it has an 'ordered' clause). |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 275 | void setOrderedRegion(bool IsOrdered, Expr *Param) { |
| 276 | Stack.back().OrderedRegion.setInt(IsOrdered); |
| 277 | Stack.back().OrderedRegion.setPointer(Param); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 278 | } |
| 279 | /// \brief Returns true, if parent region is ordered (has associated |
| 280 | /// 'ordered' clause), false - otherwise. |
| 281 | bool isParentOrderedRegion() const { |
| 282 | if (Stack.size() > 2) |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 283 | return Stack[Stack.size() - 2].OrderedRegion.getInt(); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 284 | return false; |
| 285 | } |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 286 | /// \brief Returns optional parameter for the ordered region. |
| 287 | Expr *getParentOrderedRegionParam() const { |
| 288 | if (Stack.size() > 2) |
| 289 | return Stack[Stack.size() - 2].OrderedRegion.getPointer(); |
| 290 | return nullptr; |
| 291 | } |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 292 | /// \brief Marks current region as nowait (it has a 'nowait' clause). |
| 293 | void setNowaitRegion(bool IsNowait = true) { |
| 294 | Stack.back().NowaitRegion = IsNowait; |
| 295 | } |
| 296 | /// \brief Returns true, if parent region is nowait (has associated |
| 297 | /// 'nowait' clause), false - otherwise. |
| 298 | bool isParentNowaitRegion() const { |
| 299 | if (Stack.size() > 2) |
| 300 | return Stack[Stack.size() - 2].NowaitRegion; |
| 301 | return false; |
| 302 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 303 | /// \brief Marks parent region as cancel region. |
| 304 | void setParentCancelRegion(bool Cancel = true) { |
| 305 | if (Stack.size() > 2) |
| 306 | Stack[Stack.size() - 2].CancelRegion = |
| 307 | Stack[Stack.size() - 2].CancelRegion || Cancel; |
| 308 | } |
| 309 | /// \brief Return true if current region has inner cancel construct. |
| 310 | bool isCancelRegion() const { |
| 311 | return Stack.back().CancelRegion; |
| 312 | } |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 313 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 314 | /// \brief Set collapse value for the region. |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 315 | void setAssociatedLoops(unsigned Val) { Stack.back().AssociatedLoops = Val; } |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 316 | /// \brief Return collapse value for region. |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 317 | unsigned getAssociatedLoops() const { return Stack.back().AssociatedLoops; } |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 318 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 319 | /// \brief Marks current target region as one with closely nested teams |
| 320 | /// region. |
| 321 | void setParentTeamsRegionLoc(SourceLocation TeamsRegionLoc) { |
| 322 | if (Stack.size() > 2) |
| 323 | Stack[Stack.size() - 2].InnerTeamsRegionLoc = TeamsRegionLoc; |
| 324 | } |
| 325 | /// \brief Returns true, if current region has closely nested teams region. |
| 326 | bool hasInnerTeamsRegion() const { |
| 327 | return getInnerTeamsRegionLoc().isValid(); |
| 328 | } |
| 329 | /// \brief Returns location of the nested teams region (if any). |
| 330 | SourceLocation getInnerTeamsRegionLoc() const { |
| 331 | if (Stack.size() > 1) |
| 332 | return Stack.back().InnerTeamsRegionLoc; |
| 333 | return SourceLocation(); |
| 334 | } |
| 335 | |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 336 | Scope *getCurScope() const { return Stack.back().CurScope; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 337 | Scope *getCurScope() { return Stack.back().CurScope; } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 338 | SourceLocation getConstructLoc() { return Stack.back().ConstructLoc; } |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 339 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 340 | // Do the check specified in MapInfoCheck and return true if any issue is |
| 341 | // found. |
| 342 | template <class MapInfoCheck> |
| 343 | bool checkMapInfoForVar(ValueDecl *VD, bool CurrentRegionOnly, |
| 344 | MapInfoCheck Check) { |
| 345 | auto SI = Stack.rbegin(); |
| 346 | auto SE = Stack.rend(); |
| 347 | |
| 348 | if (SI == SE) |
| 349 | return false; |
| 350 | |
| 351 | if (CurrentRegionOnly) { |
| 352 | SE = std::next(SI); |
| 353 | } else { |
| 354 | ++SI; |
| 355 | } |
| 356 | |
| 357 | for (; SI != SE; ++SI) { |
| 358 | auto MI = SI->MappedDecls.find(VD); |
| 359 | if (MI != SI->MappedDecls.end()) { |
| 360 | for (Expr *E : MI->second) { |
| 361 | if (Check(E)) |
| 362 | return true; |
| 363 | } |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 364 | } |
| 365 | } |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 366 | return false; |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 367 | } |
| 368 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 369 | void addExprToVarMapInfo(ValueDecl *VD, Expr *E) { |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 370 | if (Stack.size() > 1) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 371 | Stack.back().MappedDecls[VD].push_back(E); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 372 | } |
| 373 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 374 | }; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 375 | bool isParallelOrTaskRegion(OpenMPDirectiveKind DKind) { |
| 376 | return isOpenMPParallelDirective(DKind) || DKind == OMPD_task || |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 377 | isOpenMPTeamsDirective(DKind) || DKind == OMPD_unknown || |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 378 | isOpenMPTaskLoopDirective(DKind); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 379 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 380 | } // namespace |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 381 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 382 | static ValueDecl *getCanonicalDecl(ValueDecl *D) { |
| 383 | auto *VD = dyn_cast<VarDecl>(D); |
| 384 | auto *FD = dyn_cast<FieldDecl>(D); |
| 385 | if (VD != nullptr) { |
| 386 | VD = VD->getCanonicalDecl(); |
| 387 | D = VD; |
| 388 | } else { |
| 389 | assert(FD); |
| 390 | FD = FD->getCanonicalDecl(); |
| 391 | D = FD; |
| 392 | } |
| 393 | return D; |
| 394 | } |
| 395 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 396 | DSAStackTy::DSAVarData DSAStackTy::getDSA(StackTy::reverse_iterator Iter, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 397 | ValueDecl *D) { |
| 398 | D = getCanonicalDecl(D); |
| 399 | auto *VD = dyn_cast<VarDecl>(D); |
| 400 | auto *FD = dyn_cast<FieldDecl>(D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 401 | DSAVarData DVar; |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 402 | if (Iter == std::prev(Stack.rend())) { |
Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 403 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 404 | // in a region but not in construct] |
| 405 | // File-scope or namespace-scope variables referenced in called routines |
| 406 | // in the region are shared unless they appear in a threadprivate |
| 407 | // directive. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 408 | if (VD && !VD->isFunctionOrMethodVarDecl() && !isa<ParmVarDecl>(D)) |
Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 409 | DVar.CKind = OMPC_shared; |
| 410 | |
| 411 | // OpenMP [2.9.1.2, Data-sharing Attribute Rules for Variables Referenced |
| 412 | // in a region but not in construct] |
| 413 | // Variables with static storage duration that are declared in called |
| 414 | // routines in the region are shared. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 415 | if (VD && VD->hasGlobalStorage()) |
| 416 | DVar.CKind = OMPC_shared; |
| 417 | |
| 418 | // Non-static data members are shared by default. |
| 419 | if (FD) |
Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 420 | DVar.CKind = OMPC_shared; |
| 421 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 422 | return DVar; |
| 423 | } |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 424 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 425 | DVar.DKind = Iter->Directive; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 426 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 427 | // in a Construct, C/C++, predetermined, p.1] |
| 428 | // Variables with automatic storage duration that are declared in a scope |
| 429 | // inside the construct are private. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 430 | if (VD && isOpenMPLocal(VD, Iter) && VD->isLocalVarDecl() && |
| 431 | (VD->getStorageClass() == SC_Auto || VD->getStorageClass() == SC_None)) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 432 | DVar.CKind = OMPC_private; |
| 433 | return DVar; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 434 | } |
| 435 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 436 | // Explicitly specified attributes and local variables with predetermined |
| 437 | // attributes. |
| 438 | if (Iter->SharingMap.count(D)) { |
| 439 | DVar.RefExpr = Iter->SharingMap[D].RefExpr; |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 440 | DVar.PrivateCopy = Iter->SharingMap[D].PrivateCopy; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 441 | DVar.CKind = Iter->SharingMap[D].Attributes; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 442 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 443 | return DVar; |
| 444 | } |
| 445 | |
| 446 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 447 | // in a Construct, C/C++, implicitly determined, p.1] |
| 448 | // In a parallel or task construct, the data-sharing attributes of these |
| 449 | // variables are determined by the default clause, if present. |
| 450 | switch (Iter->DefaultAttr) { |
| 451 | case DSA_shared: |
| 452 | DVar.CKind = OMPC_shared; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 453 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 454 | return DVar; |
| 455 | case DSA_none: |
| 456 | return DVar; |
| 457 | case DSA_unspecified: |
| 458 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 459 | // in a Construct, implicitly determined, p.2] |
| 460 | // In a parallel construct, if no default clause is present, these |
| 461 | // variables are shared. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 462 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 463 | if (isOpenMPParallelDirective(DVar.DKind) || |
| 464 | isOpenMPTeamsDirective(DVar.DKind)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 465 | DVar.CKind = OMPC_shared; |
| 466 | return DVar; |
| 467 | } |
| 468 | |
| 469 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 470 | // in a Construct, implicitly determined, p.4] |
| 471 | // In a task construct, if no default clause is present, a variable that in |
| 472 | // the enclosing context is determined to be shared by all implicit tasks |
| 473 | // bound to the current team is shared. |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 474 | if (DVar.DKind == OMPD_task) { |
| 475 | DSAVarData DVarTemp; |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 476 | for (StackTy::reverse_iterator I = std::next(Iter), EE = Stack.rend(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 477 | I != EE; ++I) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 478 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables |
| 479 | // Referenced |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 480 | // in a Construct, implicitly determined, p.6] |
| 481 | // In a task construct, if no default clause is present, a variable |
| 482 | // whose data-sharing attribute is not determined by the rules above is |
| 483 | // firstprivate. |
| 484 | DVarTemp = getDSA(I, D); |
| 485 | if (DVarTemp.CKind != OMPC_shared) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 486 | DVar.RefExpr = nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 487 | DVar.DKind = OMPD_task; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 488 | DVar.CKind = OMPC_firstprivate; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 489 | return DVar; |
| 490 | } |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 491 | if (isParallelOrTaskRegion(I->Directive)) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 492 | break; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 493 | } |
| 494 | DVar.DKind = OMPD_task; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 495 | DVar.CKind = |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 496 | (DVarTemp.CKind == OMPC_unknown) ? OMPC_firstprivate : OMPC_shared; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 497 | return DVar; |
| 498 | } |
| 499 | } |
| 500 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 501 | // in a Construct, implicitly determined, p.3] |
| 502 | // For constructs other than task, if no default clause is present, these |
| 503 | // variables inherit their data-sharing attributes from the enclosing |
| 504 | // context. |
Benjamin Kramer | 167e999 | 2014-03-02 12:20:24 +0000 | [diff] [blame] | 505 | return getDSA(std::next(Iter), D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 506 | } |
| 507 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 508 | Expr *DSAStackTy::addUniqueAligned(ValueDecl *D, Expr *NewDE) { |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 509 | assert(Stack.size() > 1 && "Data sharing attributes stack is empty"); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 510 | D = getCanonicalDecl(D); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 511 | auto It = Stack.back().AlignedMap.find(D); |
| 512 | if (It == Stack.back().AlignedMap.end()) { |
| 513 | assert(NewDE && "Unexpected nullptr expr to be added into aligned map"); |
| 514 | Stack.back().AlignedMap[D] = NewDE; |
| 515 | return nullptr; |
| 516 | } else { |
| 517 | assert(It->second && "Unexpected nullptr expr in the aligned map"); |
| 518 | return It->second; |
| 519 | } |
| 520 | return nullptr; |
| 521 | } |
| 522 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 523 | void DSAStackTy::addLoopControlVariable(ValueDecl *D) { |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 524 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 525 | D = getCanonicalDecl(D); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 526 | 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] | 527 | } |
| 528 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 529 | unsigned DSAStackTy::isLoopControlVariable(ValueDecl *D) { |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 530 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 531 | D = getCanonicalDecl(D); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 532 | return Stack.back().LCVMap.count(D) > 0 ? Stack.back().LCVMap[D] : 0; |
| 533 | } |
| 534 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 535 | unsigned DSAStackTy::isParentLoopControlVariable(ValueDecl *D) { |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 536 | assert(Stack.size() > 2 && "Data-sharing attributes stack is empty"); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 537 | D = getCanonicalDecl(D); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 538 | return Stack[Stack.size() - 2].LCVMap.count(D) > 0 |
| 539 | ? Stack[Stack.size() - 2].LCVMap[D] |
| 540 | : 0; |
| 541 | } |
| 542 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 543 | ValueDecl *DSAStackTy::getParentLoopControlVariable(unsigned I) { |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 544 | assert(Stack.size() > 2 && "Data-sharing attributes stack is empty"); |
| 545 | if (Stack[Stack.size() - 2].LCVMap.size() < I) |
| 546 | return nullptr; |
| 547 | for (auto &Pair : Stack[Stack.size() - 2].LCVMap) { |
| 548 | if (Pair.second == I) |
| 549 | return Pair.first; |
| 550 | } |
| 551 | return nullptr; |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 552 | } |
| 553 | |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 554 | void DSAStackTy::addDSA(ValueDecl *D, Expr *E, OpenMPClauseKind A, |
| 555 | DeclRefExpr *PrivateCopy) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 556 | D = getCanonicalDecl(D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 557 | if (A == OMPC_threadprivate) { |
| 558 | Stack[0].SharingMap[D].Attributes = A; |
| 559 | Stack[0].SharingMap[D].RefExpr = E; |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 560 | Stack[0].SharingMap[D].PrivateCopy = nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 561 | } else { |
| 562 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); |
| 563 | Stack.back().SharingMap[D].Attributes = A; |
| 564 | Stack.back().SharingMap[D].RefExpr = E; |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 565 | Stack.back().SharingMap[D].PrivateCopy = PrivateCopy; |
| 566 | if (PrivateCopy) |
| 567 | addDSA(PrivateCopy->getDecl(), PrivateCopy, A); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 568 | } |
| 569 | } |
| 570 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 571 | bool DSAStackTy::isOpenMPLocal(VarDecl *D, StackTy::reverse_iterator Iter) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 572 | D = D->getCanonicalDecl(); |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 573 | if (Stack.size() > 2) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 574 | reverse_iterator I = Iter, E = std::prev(Stack.rend()); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 575 | Scope *TopScope = nullptr; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 576 | while (I != E && !isParallelOrTaskRegion(I->Directive)) { |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 577 | ++I; |
| 578 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 579 | if (I == E) |
| 580 | return false; |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 581 | TopScope = I->CurScope ? I->CurScope->getParent() : nullptr; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 582 | Scope *CurScope = getCurScope(); |
| 583 | while (CurScope != TopScope && !CurScope->isDeclScope(D)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 584 | CurScope = CurScope->getParent(); |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 585 | } |
| 586 | return CurScope != TopScope; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 587 | } |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 588 | return false; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 589 | } |
| 590 | |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 591 | /// \brief Build a variable declaration for OpenMP loop iteration variable. |
| 592 | static VarDecl *buildVarDecl(Sema &SemaRef, SourceLocation Loc, QualType Type, |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 593 | StringRef Name, const AttrVec *Attrs = nullptr) { |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 594 | DeclContext *DC = SemaRef.CurContext; |
| 595 | IdentifierInfo *II = &SemaRef.PP.getIdentifierTable().get(Name); |
| 596 | TypeSourceInfo *TInfo = SemaRef.Context.getTrivialTypeSourceInfo(Type, Loc); |
| 597 | VarDecl *Decl = |
| 598 | VarDecl::Create(SemaRef.Context, DC, Loc, Loc, II, Type, TInfo, SC_None); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 599 | if (Attrs) { |
| 600 | for (specific_attr_iterator<AlignedAttr> I(Attrs->begin()), E(Attrs->end()); |
| 601 | I != E; ++I) |
| 602 | Decl->addAttr(*I); |
| 603 | } |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 604 | Decl->setImplicit(); |
| 605 | return Decl; |
| 606 | } |
| 607 | |
| 608 | static DeclRefExpr *buildDeclRefExpr(Sema &S, VarDecl *D, QualType Ty, |
| 609 | SourceLocation Loc, |
| 610 | bool RefersToCapture = false) { |
| 611 | D->setReferenced(); |
| 612 | D->markUsed(S.Context); |
| 613 | return DeclRefExpr::Create(S.getASTContext(), NestedNameSpecifierLoc(), |
| 614 | SourceLocation(), D, RefersToCapture, Loc, Ty, |
| 615 | VK_LValue); |
| 616 | } |
| 617 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 618 | DSAStackTy::DSAVarData DSAStackTy::getTopDSA(ValueDecl *D, bool FromParent) { |
| 619 | D = getCanonicalDecl(D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 620 | DSAVarData DVar; |
| 621 | |
| 622 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 623 | // in a Construct, C/C++, predetermined, p.1] |
| 624 | // Variables appearing in threadprivate directives are threadprivate. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 625 | auto *VD = dyn_cast<VarDecl>(D); |
| 626 | if ((VD && VD->getTLSKind() != VarDecl::TLS_None && |
| 627 | !(VD->hasAttr<OMPThreadPrivateDeclAttr>() && |
Samuel Antao | f8b5012 | 2015-07-13 22:54:53 +0000 | [diff] [blame] | 628 | SemaRef.getLangOpts().OpenMPUseTLS && |
| 629 | SemaRef.getASTContext().getTargetInfo().isTLSSupported())) || |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 630 | (VD && VD->getStorageClass() == SC_Register && |
| 631 | VD->hasAttr<AsmLabelAttr>() && !VD->isLocalVarDecl())) { |
| 632 | addDSA(D, buildDeclRefExpr(SemaRef, VD, D->getType().getNonReferenceType(), |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 633 | D->getLocation()), |
Alexey Bataev | f2453a0 | 2015-05-06 07:25:08 +0000 | [diff] [blame] | 634 | OMPC_threadprivate); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 635 | } |
| 636 | if (Stack[0].SharingMap.count(D)) { |
| 637 | DVar.RefExpr = Stack[0].SharingMap[D].RefExpr; |
| 638 | DVar.CKind = OMPC_threadprivate; |
| 639 | return DVar; |
| 640 | } |
| 641 | |
| 642 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
Alexey Bataev | dffa93a | 2015-12-10 08:20:58 +0000 | [diff] [blame] | 643 | // in a Construct, C/C++, predetermined, p.4] |
| 644 | // Static data members are shared. |
| 645 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 646 | // in a Construct, C/C++, predetermined, p.7] |
| 647 | // Variables with static storage duration that are declared in a scope |
| 648 | // inside the construct are shared. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 649 | if (VD && VD->isStaticDataMember()) { |
Alexey Bataev | dffa93a | 2015-12-10 08:20:58 +0000 | [diff] [blame] | 650 | DSAVarData DVarTemp = |
| 651 | hasDSA(D, isOpenMPPrivate, MatchesAlways(), FromParent); |
| 652 | if (DVarTemp.CKind != OMPC_unknown && DVarTemp.RefExpr) |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 653 | return DVar; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 654 | |
Alexey Bataev | dffa93a | 2015-12-10 08:20:58 +0000 | [diff] [blame] | 655 | DVar.CKind = OMPC_shared; |
| 656 | return DVar; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 657 | } |
| 658 | |
| 659 | QualType Type = D->getType().getNonReferenceType().getCanonicalType(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 660 | bool IsConstant = Type.isConstant(SemaRef.getASTContext()); |
| 661 | Type = SemaRef.getASTContext().getBaseElementType(Type); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 662 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 663 | // in a Construct, C/C++, predetermined, p.6] |
| 664 | // Variables with const qualified type having no mutable member are |
| 665 | // shared. |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 666 | CXXRecordDecl *RD = |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 667 | SemaRef.getLangOpts().CPlusPlus ? Type->getAsCXXRecordDecl() : nullptr; |
Alexey Bataev | c9bd03d | 2015-12-17 06:55:08 +0000 | [diff] [blame] | 668 | if (auto *CTSD = dyn_cast_or_null<ClassTemplateSpecializationDecl>(RD)) |
| 669 | if (auto *CTD = CTSD->getSpecializedTemplate()) |
| 670 | RD = CTD->getTemplatedDecl(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 671 | if (IsConstant && |
Alexey Bataev | 4bcad7f | 2016-02-10 10:50:12 +0000 | [diff] [blame] | 672 | !(SemaRef.getLangOpts().CPlusPlus && RD && RD->hasDefinition() && |
| 673 | RD->hasMutableFields())) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 674 | // Variables with const-qualified type having no mutable member may be |
| 675 | // listed in a firstprivate clause, even if they are static data members. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 676 | DSAVarData DVarTemp = hasDSA(D, MatchesAnyClause(OMPC_firstprivate), |
| 677 | MatchesAlways(), FromParent); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 678 | if (DVarTemp.CKind == OMPC_firstprivate && DVarTemp.RefExpr) |
| 679 | return DVar; |
| 680 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 681 | DVar.CKind = OMPC_shared; |
| 682 | return DVar; |
| 683 | } |
| 684 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 685 | // Explicitly specified attributes and local variables with predetermined |
| 686 | // attributes. |
Alexey Bataev | dffa93a | 2015-12-10 08:20:58 +0000 | [diff] [blame] | 687 | auto StartI = std::next(Stack.rbegin()); |
| 688 | auto EndI = std::prev(Stack.rend()); |
| 689 | if (FromParent && StartI != EndI) { |
| 690 | StartI = std::next(StartI); |
| 691 | } |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 692 | auto I = std::prev(StartI); |
| 693 | if (I->SharingMap.count(D)) { |
| 694 | DVar.RefExpr = I->SharingMap[D].RefExpr; |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 695 | DVar.PrivateCopy = I->SharingMap[D].PrivateCopy; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 696 | DVar.CKind = I->SharingMap[D].Attributes; |
| 697 | DVar.ImplicitDSALoc = I->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 698 | } |
| 699 | |
| 700 | return DVar; |
| 701 | } |
| 702 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 703 | DSAStackTy::DSAVarData DSAStackTy::getImplicitDSA(ValueDecl *D, |
| 704 | bool FromParent) { |
| 705 | D = getCanonicalDecl(D); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 706 | auto StartI = Stack.rbegin(); |
| 707 | auto EndI = std::prev(Stack.rend()); |
| 708 | if (FromParent && StartI != EndI) { |
| 709 | StartI = std::next(StartI); |
| 710 | } |
| 711 | return getDSA(StartI, D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 712 | } |
| 713 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 714 | template <class ClausesPredicate, class DirectivesPredicate> |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 715 | DSAStackTy::DSAVarData DSAStackTy::hasDSA(ValueDecl *D, ClausesPredicate CPred, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 716 | DirectivesPredicate DPred, |
| 717 | bool FromParent) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 718 | D = getCanonicalDecl(D); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 719 | auto StartI = std::next(Stack.rbegin()); |
| 720 | auto EndI = std::prev(Stack.rend()); |
| 721 | if (FromParent && StartI != EndI) { |
| 722 | StartI = std::next(StartI); |
| 723 | } |
| 724 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
| 725 | if (!DPred(I->Directive) && !isParallelOrTaskRegion(I->Directive)) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 726 | continue; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 727 | DSAVarData DVar = getDSA(I, D); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 728 | if (CPred(DVar.CKind)) |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 729 | return DVar; |
| 730 | } |
| 731 | return DSAVarData(); |
| 732 | } |
| 733 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 734 | template <class ClausesPredicate, class DirectivesPredicate> |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 735 | DSAStackTy::DSAVarData |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 736 | DSAStackTy::hasInnermostDSA(ValueDecl *D, ClausesPredicate CPred, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 737 | DirectivesPredicate DPred, bool FromParent) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 738 | D = getCanonicalDecl(D); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 739 | auto StartI = std::next(Stack.rbegin()); |
| 740 | auto EndI = std::prev(Stack.rend()); |
| 741 | if (FromParent && StartI != EndI) { |
| 742 | StartI = std::next(StartI); |
| 743 | } |
| 744 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 745 | if (!DPred(I->Directive)) |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 746 | break; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 747 | DSAVarData DVar = getDSA(I, D); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 748 | if (CPred(DVar.CKind)) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 749 | return DVar; |
| 750 | return DSAVarData(); |
| 751 | } |
| 752 | return DSAVarData(); |
| 753 | } |
| 754 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 755 | bool DSAStackTy::hasExplicitDSA( |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 756 | ValueDecl *D, const llvm::function_ref<bool(OpenMPClauseKind)> &CPred, |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 757 | unsigned Level) { |
| 758 | if (CPred(ClauseKindMode)) |
| 759 | return true; |
| 760 | if (isClauseParsingMode()) |
| 761 | ++Level; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 762 | D = getCanonicalDecl(D); |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 763 | auto StartI = Stack.rbegin(); |
| 764 | auto EndI = std::prev(Stack.rend()); |
NAKAMURA Takumi | 0332eda | 2015-06-23 10:01:20 +0000 | [diff] [blame] | 765 | if (std::distance(StartI, EndI) <= (int)Level) |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 766 | return false; |
| 767 | std::advance(StartI, Level); |
| 768 | return (StartI->SharingMap.count(D) > 0) && StartI->SharingMap[D].RefExpr && |
| 769 | CPred(StartI->SharingMap[D].Attributes); |
| 770 | } |
| 771 | |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 772 | bool DSAStackTy::hasExplicitDirective( |
| 773 | const llvm::function_ref<bool(OpenMPDirectiveKind)> &DPred, |
| 774 | unsigned Level) { |
| 775 | if (isClauseParsingMode()) |
| 776 | ++Level; |
| 777 | auto StartI = Stack.rbegin(); |
| 778 | auto EndI = std::prev(Stack.rend()); |
| 779 | if (std::distance(StartI, EndI) <= (int)Level) |
| 780 | return false; |
| 781 | std::advance(StartI, Level); |
| 782 | return DPred(StartI->Directive); |
| 783 | } |
| 784 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 785 | template <class NamedDirectivesPredicate> |
| 786 | bool DSAStackTy::hasDirective(NamedDirectivesPredicate DPred, bool FromParent) { |
| 787 | auto StartI = std::next(Stack.rbegin()); |
| 788 | auto EndI = std::prev(Stack.rend()); |
| 789 | if (FromParent && StartI != EndI) { |
| 790 | StartI = std::next(StartI); |
| 791 | } |
| 792 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
| 793 | if (DPred(I->Directive, I->DirectiveName, I->ConstructLoc)) |
| 794 | return true; |
| 795 | } |
| 796 | return false; |
| 797 | } |
| 798 | |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 799 | OpenMPDirectiveKind DSAStackTy::getDirectiveForScope(const Scope *S) const { |
| 800 | for (auto I = Stack.rbegin(), EE = Stack.rend(); I != EE; ++I) |
| 801 | if (I->CurScope == S) |
| 802 | return I->Directive; |
| 803 | return OMPD_unknown; |
| 804 | } |
| 805 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 806 | void Sema::InitDataSharingAttributesStack() { |
| 807 | VarDataSharingAttributesStack = new DSAStackTy(*this); |
| 808 | } |
| 809 | |
| 810 | #define DSAStack static_cast<DSAStackTy *>(VarDataSharingAttributesStack) |
| 811 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 812 | bool Sema::IsOpenMPCapturedByRef(ValueDecl *D, |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 813 | const CapturedRegionScopeInfo *RSI) { |
| 814 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| 815 | |
| 816 | auto &Ctx = getASTContext(); |
| 817 | bool IsByRef = true; |
| 818 | |
| 819 | // Find the directive that is associated with the provided scope. |
| 820 | auto DKind = DSAStack->getDirectiveForScope(RSI->TheScope); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 821 | auto Ty = D->getType(); |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 822 | |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 823 | if (isOpenMPTargetExecutionDirective(DKind)) { |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 824 | // This table summarizes how a given variable should be passed to the device |
| 825 | // given its type and the clauses where it appears. This table is based on |
| 826 | // the description in OpenMP 4.5 [2.10.4, target Construct] and |
| 827 | // OpenMP 4.5 [2.15.5, Data-mapping Attribute Rules and Clauses]. |
| 828 | // |
| 829 | // ========================================================================= |
| 830 | // | type | defaultmap | pvt | first | is_device_ptr | map | res. | |
| 831 | // | |(tofrom:scalar)| | pvt | | | | |
| 832 | // ========================================================================= |
| 833 | // | scl | | | | - | | bycopy| |
| 834 | // | scl | | - | x | - | - | bycopy| |
| 835 | // | scl | | x | - | - | - | null | |
| 836 | // | scl | x | | | - | | byref | |
| 837 | // | scl | x | - | x | - | - | bycopy| |
| 838 | // | scl | x | x | - | - | - | null | |
| 839 | // | scl | | - | - | - | x | byref | |
| 840 | // | scl | x | - | - | - | x | byref | |
| 841 | // |
| 842 | // | agg | n.a. | | | - | | byref | |
| 843 | // | agg | n.a. | - | x | - | - | byref | |
| 844 | // | agg | n.a. | x | - | - | - | null | |
| 845 | // | agg | n.a. | - | - | - | x | byref | |
| 846 | // | agg | n.a. | - | - | - | x[] | byref | |
| 847 | // |
| 848 | // | ptr | n.a. | | | - | | bycopy| |
| 849 | // | ptr | n.a. | - | x | - | - | bycopy| |
| 850 | // | ptr | n.a. | x | - | - | - | null | |
| 851 | // | ptr | n.a. | - | - | - | x | byref | |
| 852 | // | ptr | n.a. | - | - | - | x[] | bycopy| |
| 853 | // | ptr | n.a. | - | - | x | | bycopy| |
| 854 | // | ptr | n.a. | - | - | x | x | bycopy| |
| 855 | // | ptr | n.a. | - | - | x | x[] | bycopy| |
| 856 | // ========================================================================= |
| 857 | // Legend: |
| 858 | // scl - scalar |
| 859 | // ptr - pointer |
| 860 | // agg - aggregate |
| 861 | // x - applies |
| 862 | // - - invalid in this combination |
| 863 | // [] - mapped with an array section |
| 864 | // byref - should be mapped by reference |
| 865 | // byval - should be mapped by value |
| 866 | // null - initialize a local variable to null on the device |
| 867 | // |
| 868 | // Observations: |
| 869 | // - All scalar declarations that show up in a map clause have to be passed |
| 870 | // by reference, because they may have been mapped in the enclosing data |
| 871 | // environment. |
| 872 | // - If the scalar value does not fit the size of uintptr, it has to be |
| 873 | // passed by reference, regardless the result in the table above. |
| 874 | // - For pointers mapped by value that have either an implicit map or an |
| 875 | // array section, the runtime library may pass the NULL value to the |
| 876 | // device instead of the value passed to it by the compiler. |
| 877 | |
| 878 | // FIXME: Right now, only implicit maps are implemented. Properly mapping |
| 879 | // values requires having the map, private, and firstprivate clauses SEMA |
| 880 | // and parsing in place, which we don't yet. |
| 881 | |
| 882 | if (Ty->isReferenceType()) |
| 883 | Ty = Ty->castAs<ReferenceType>()->getPointeeType(); |
| 884 | IsByRef = !Ty->isScalarType(); |
| 885 | } |
| 886 | |
| 887 | // When passing data by value, we need to make sure it fits the uintptr size |
| 888 | // and alignment, because the runtime library only deals with uintptr types. |
| 889 | // If it does not fit the uintptr size, we need to pass the data by reference |
| 890 | // instead. |
| 891 | if (!IsByRef && |
| 892 | (Ctx.getTypeSizeInChars(Ty) > |
| 893 | Ctx.getTypeSizeInChars(Ctx.getUIntPtrType()) || |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 894 | Ctx.getDeclAlign(D) > Ctx.getTypeAlignInChars(Ctx.getUIntPtrType()))) |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 895 | IsByRef = true; |
| 896 | |
| 897 | return IsByRef; |
| 898 | } |
| 899 | |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 900 | VarDecl *Sema::IsOpenMPCapturedDecl(ValueDecl *D) { |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 901 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 902 | D = getCanonicalDecl(D); |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 903 | |
| 904 | // If we are attempting to capture a global variable in a directive with |
| 905 | // 'target' we return true so that this global is also mapped to the device. |
| 906 | // |
| 907 | // FIXME: If the declaration is enclosed in a 'declare target' directive, |
| 908 | // then it should not be captured. Therefore, an extra check has to be |
| 909 | // inserted here once support for 'declare target' is added. |
| 910 | // |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 911 | auto *VD = dyn_cast<VarDecl>(D); |
| 912 | if (VD && !VD->hasLocalStorage()) { |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 913 | if (DSAStack->getCurrentDirective() == OMPD_target && |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 914 | !DSAStack->isClauseParsingMode()) |
| 915 | return VD; |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 916 | if (DSAStack->getCurScope() && |
| 917 | DSAStack->hasDirective( |
| 918 | [](OpenMPDirectiveKind K, const DeclarationNameInfo &DNI, |
| 919 | SourceLocation Loc) -> bool { |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 920 | return isOpenMPTargetExecutionDirective(K); |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 921 | }, |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 922 | false)) |
| 923 | return VD; |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 924 | } |
| 925 | |
Alexey Bataev | 48977c3 | 2015-08-04 08:10:48 +0000 | [diff] [blame] | 926 | if (DSAStack->getCurrentDirective() != OMPD_unknown && |
| 927 | (!DSAStack->isClauseParsingMode() || |
| 928 | DSAStack->getParentDirective() != OMPD_unknown)) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 929 | if (DSAStack->isLoopControlVariable(D) || |
| 930 | (VD && VD->hasLocalStorage() && |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 931 | isParallelOrTaskRegion(DSAStack->getCurrentDirective())) || |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 932 | (VD && DSAStack->isForceVarCapturing())) |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 933 | return VD; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 934 | auto DVarPrivate = DSAStack->getTopDSA(D, DSAStack->isClauseParsingMode()); |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 935 | if (DVarPrivate.CKind != OMPC_unknown && isOpenMPPrivate(DVarPrivate.CKind)) |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 936 | return VD ? VD : cast<VarDecl>(DVarPrivate.PrivateCopy->getDecl()); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 937 | DVarPrivate = DSAStack->hasDSA(D, isOpenMPPrivate, MatchesAlways(), |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 938 | DSAStack->isClauseParsingMode()); |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 939 | if (DVarPrivate.CKind != OMPC_unknown) |
| 940 | return VD ? VD : cast<VarDecl>(DVarPrivate.PrivateCopy->getDecl()); |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 941 | } |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 942 | return nullptr; |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 943 | } |
| 944 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 945 | bool Sema::isOpenMPPrivateDecl(ValueDecl *D, unsigned Level) { |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 946 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| 947 | return DSAStack->hasExplicitDSA( |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 948 | D, [](OpenMPClauseKind K) -> bool { return K == OMPC_private; }, Level); |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 949 | } |
| 950 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 951 | bool Sema::isOpenMPTargetCapturedDecl(ValueDecl *D, unsigned Level) { |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 952 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| 953 | // Return true if the current level is no longer enclosed in a target region. |
| 954 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 955 | auto *VD = dyn_cast<VarDecl>(D); |
| 956 | return VD && !VD->hasLocalStorage() && |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 957 | DSAStack->hasExplicitDirective(isOpenMPTargetExecutionDirective, |
| 958 | Level); |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 959 | } |
| 960 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 961 | void Sema::DestroyDataSharingAttributesStack() { delete DSAStack; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 962 | |
| 963 | void Sema::StartOpenMPDSABlock(OpenMPDirectiveKind DKind, |
| 964 | const DeclarationNameInfo &DirName, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 965 | Scope *CurScope, SourceLocation Loc) { |
| 966 | DSAStack->push(DKind, DirName, CurScope, Loc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 967 | PushExpressionEvaluationContext(PotentiallyEvaluated); |
| 968 | } |
| 969 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 970 | void Sema::StartOpenMPClause(OpenMPClauseKind K) { |
| 971 | DSAStack->setClauseParsingMode(K); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 972 | } |
| 973 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 974 | void Sema::EndOpenMPClause() { |
| 975 | DSAStack->setClauseParsingMode(/*K=*/OMPC_unknown); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 976 | } |
| 977 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 978 | void Sema::EndOpenMPDSABlock(Stmt *CurDirective) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 979 | // OpenMP [2.14.3.5, Restrictions, C/C++, p.1] |
| 980 | // A variable of class type (or array thereof) that appears in a lastprivate |
| 981 | // clause requires an accessible, unambiguous default constructor for the |
| 982 | // class type, unless the list item is also specified in a firstprivate |
| 983 | // clause. |
| 984 | if (auto D = dyn_cast_or_null<OMPExecutableDirective>(CurDirective)) { |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 985 | for (auto *C : D->clauses()) { |
| 986 | if (auto *Clause = dyn_cast<OMPLastprivateClause>(C)) { |
| 987 | SmallVector<Expr *, 8> PrivateCopies; |
| 988 | for (auto *DE : Clause->varlists()) { |
| 989 | if (DE->isValueDependent() || DE->isTypeDependent()) { |
| 990 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 991 | continue; |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 992 | } |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 993 | VarDecl *VD = nullptr; |
| 994 | FieldDecl *FD = nullptr; |
| 995 | ValueDecl *D; |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 996 | auto *DRE = cast<DeclRefExpr>(DE->IgnoreParens()); |
| 997 | if (auto *OCE = dyn_cast<OMPCapturedExprDecl>(DRE->getDecl())) { |
| 998 | FD = cast<FieldDecl>( |
| 999 | cast<MemberExpr>(OCE->getInit()->IgnoreImpCasts()) |
| 1000 | ->getMemberDecl()); |
| 1001 | D = FD; |
| 1002 | } else { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1003 | VD = cast<VarDecl>(DRE->getDecl()); |
| 1004 | D = VD; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1005 | } |
| 1006 | QualType Type = D->getType().getNonReferenceType(); |
| 1007 | auto DVar = DSAStack->getTopDSA(D, false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1008 | if (DVar.CKind == OMPC_lastprivate) { |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1009 | // Generate helper private variable and initialize it with the |
| 1010 | // default value. The address of the original variable is replaced |
| 1011 | // by the address of the new private variable in CodeGen. This new |
| 1012 | // variable is not added to IdResolver, so the code in the OpenMP |
| 1013 | // region uses original variable for proper diagnostics. |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 1014 | auto *VDPrivate = buildVarDecl( |
| 1015 | *this, DE->getExprLoc(), Type.getUnqualifiedType(), |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1016 | D->getName(), D->hasAttrs() ? &D->getAttrs() : nullptr); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1017 | ActOnUninitializedDecl(VDPrivate, /*TypeMayContainAuto=*/false); |
| 1018 | if (VDPrivate->isInvalidDecl()) |
| 1019 | continue; |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 1020 | PrivateCopies.push_back(buildDeclRefExpr( |
| 1021 | *this, VDPrivate, DE->getType(), DE->getExprLoc())); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1022 | } else { |
| 1023 | // The variable is also a firstprivate, so initialization sequence |
| 1024 | // for private copy is generated already. |
| 1025 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1026 | } |
| 1027 | } |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1028 | // Set initializers to private copies if no errors were found. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1029 | if (PrivateCopies.size() == Clause->varlist_size()) |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1030 | Clause->setPrivateCopies(PrivateCopies); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1031 | } |
| 1032 | } |
| 1033 | } |
| 1034 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1035 | DSAStack->pop(); |
| 1036 | DiscardCleanupsInEvaluationContext(); |
| 1037 | PopExpressionEvaluationContext(); |
| 1038 | } |
| 1039 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 1040 | static bool FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV, |
| 1041 | Expr *NumIterations, Sema &SemaRef, |
| 1042 | Scope *S); |
| 1043 | |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1044 | namespace { |
| 1045 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1046 | class VarDeclFilterCCC : public CorrectionCandidateCallback { |
| 1047 | private: |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1048 | Sema &SemaRef; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1049 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1050 | public: |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1051 | explicit VarDeclFilterCCC(Sema &S) : SemaRef(S) {} |
Craig Topper | e14c0f8 | 2014-03-12 04:55:44 +0000 | [diff] [blame] | 1052 | bool ValidateCandidate(const TypoCorrection &Candidate) override { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1053 | NamedDecl *ND = Candidate.getCorrectionDecl(); |
| 1054 | if (VarDecl *VD = dyn_cast_or_null<VarDecl>(ND)) { |
| 1055 | return VD->hasGlobalStorage() && |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1056 | SemaRef.isDeclInScope(ND, SemaRef.getCurLexicalContext(), |
| 1057 | SemaRef.getCurScope()); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1058 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1059 | return false; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1060 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1061 | }; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1062 | } // namespace |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1063 | |
| 1064 | ExprResult Sema::ActOnOpenMPIdExpression(Scope *CurScope, |
| 1065 | CXXScopeSpec &ScopeSpec, |
| 1066 | const DeclarationNameInfo &Id) { |
| 1067 | LookupResult Lookup(*this, Id, LookupOrdinaryName); |
| 1068 | LookupParsedName(Lookup, CurScope, &ScopeSpec, true); |
| 1069 | |
| 1070 | if (Lookup.isAmbiguous()) |
| 1071 | return ExprError(); |
| 1072 | |
| 1073 | VarDecl *VD; |
| 1074 | if (!Lookup.isSingleResult()) { |
Kaelyn Takata | 89c881b | 2014-10-27 18:07:29 +0000 | [diff] [blame] | 1075 | if (TypoCorrection Corrected = CorrectTypo( |
| 1076 | Id, LookupOrdinaryName, CurScope, nullptr, |
| 1077 | llvm::make_unique<VarDeclFilterCCC>(*this), CTK_ErrorRecovery)) { |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 1078 | diagnoseTypo(Corrected, |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 1079 | PDiag(Lookup.empty() |
| 1080 | ? diag::err_undeclared_var_use_suggest |
| 1081 | : diag::err_omp_expected_var_arg_suggest) |
| 1082 | << Id.getName()); |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 1083 | VD = Corrected.getCorrectionDeclAs<VarDecl>(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1084 | } else { |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 1085 | Diag(Id.getLoc(), Lookup.empty() ? diag::err_undeclared_var_use |
| 1086 | : diag::err_omp_expected_var_arg) |
| 1087 | << Id.getName(); |
| 1088 | return ExprError(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1089 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1090 | } else { |
| 1091 | if (!(VD = Lookup.getAsSingle<VarDecl>())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1092 | Diag(Id.getLoc(), diag::err_omp_expected_var_arg) << Id.getName(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1093 | Diag(Lookup.getFoundDecl()->getLocation(), diag::note_declared_at); |
| 1094 | return ExprError(); |
| 1095 | } |
| 1096 | } |
| 1097 | Lookup.suppressDiagnostics(); |
| 1098 | |
| 1099 | // OpenMP [2.9.2, Syntax, C/C++] |
| 1100 | // Variables must be file-scope, namespace-scope, or static block-scope. |
| 1101 | if (!VD->hasGlobalStorage()) { |
| 1102 | Diag(Id.getLoc(), diag::err_omp_global_var_arg) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1103 | << getOpenMPDirectiveName(OMPD_threadprivate) << !VD->isStaticLocal(); |
| 1104 | bool IsDecl = |
| 1105 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1106 | Diag(VD->getLocation(), |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1107 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1108 | << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1109 | return ExprError(); |
| 1110 | } |
| 1111 | |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1112 | VarDecl *CanonicalVD = VD->getCanonicalDecl(); |
| 1113 | NamedDecl *ND = cast<NamedDecl>(CanonicalVD); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1114 | // OpenMP [2.9.2, Restrictions, C/C++, p.2] |
| 1115 | // A threadprivate directive for file-scope variables must appear outside |
| 1116 | // any definition or declaration. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1117 | if (CanonicalVD->getDeclContext()->isTranslationUnit() && |
| 1118 | !getCurLexicalContext()->isTranslationUnit()) { |
| 1119 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1120 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1121 | bool IsDecl = |
| 1122 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1123 | Diag(VD->getLocation(), |
| 1124 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1125 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1126 | return ExprError(); |
| 1127 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1128 | // OpenMP [2.9.2, Restrictions, C/C++, p.3] |
| 1129 | // A threadprivate directive for static class member variables must appear |
| 1130 | // in the class definition, in the same scope in which the member |
| 1131 | // variables are declared. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1132 | if (CanonicalVD->isStaticDataMember() && |
| 1133 | !CanonicalVD->getDeclContext()->Equals(getCurLexicalContext())) { |
| 1134 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1135 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1136 | bool IsDecl = |
| 1137 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1138 | Diag(VD->getLocation(), |
| 1139 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1140 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1141 | return ExprError(); |
| 1142 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1143 | // OpenMP [2.9.2, Restrictions, C/C++, p.4] |
| 1144 | // A threadprivate directive for namespace-scope variables must appear |
| 1145 | // outside any definition or declaration other than the namespace |
| 1146 | // definition itself. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1147 | if (CanonicalVD->getDeclContext()->isNamespace() && |
| 1148 | (!getCurLexicalContext()->isFileContext() || |
| 1149 | !getCurLexicalContext()->Encloses(CanonicalVD->getDeclContext()))) { |
| 1150 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1151 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1152 | bool IsDecl = |
| 1153 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1154 | Diag(VD->getLocation(), |
| 1155 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1156 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1157 | return ExprError(); |
| 1158 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1159 | // OpenMP [2.9.2, Restrictions, C/C++, p.6] |
| 1160 | // A threadprivate directive for static block-scope variables must appear |
| 1161 | // in the scope of the variable and not in a nested scope. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1162 | if (CanonicalVD->isStaticLocal() && CurScope && |
| 1163 | !isDeclInScope(ND, getCurLexicalContext(), CurScope)) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1164 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1165 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1166 | bool IsDecl = |
| 1167 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1168 | Diag(VD->getLocation(), |
| 1169 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1170 | << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1171 | return ExprError(); |
| 1172 | } |
| 1173 | |
| 1174 | // OpenMP [2.9.2, Restrictions, C/C++, p.2-6] |
| 1175 | // A threadprivate directive must lexically precede all references to any |
| 1176 | // of the variables in its list. |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 1177 | if (VD->isUsed() && !DSAStack->isThreadPrivate(VD)) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1178 | Diag(Id.getLoc(), diag::err_omp_var_used) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1179 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1180 | return ExprError(); |
| 1181 | } |
| 1182 | |
| 1183 | QualType ExprType = VD->getType().getNonReferenceType(); |
Alexey Bataev | 376b4a4 | 2016-02-09 09:41:09 +0000 | [diff] [blame] | 1184 | return DeclRefExpr::Create(Context, NestedNameSpecifierLoc(), |
| 1185 | SourceLocation(), VD, |
| 1186 | /*RefersToEnclosingVariableOrCapture=*/false, |
| 1187 | Id.getLoc(), ExprType, VK_LValue); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1188 | } |
| 1189 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1190 | Sema::DeclGroupPtrTy |
| 1191 | Sema::ActOnOpenMPThreadprivateDirective(SourceLocation Loc, |
| 1192 | ArrayRef<Expr *> VarList) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1193 | if (OMPThreadPrivateDecl *D = CheckOMPThreadPrivateDecl(Loc, VarList)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1194 | CurContext->addDecl(D); |
| 1195 | return DeclGroupPtrTy::make(DeclGroupRef(D)); |
| 1196 | } |
David Blaikie | 0403cb1 | 2016-01-15 23:43:25 +0000 | [diff] [blame] | 1197 | return nullptr; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1198 | } |
| 1199 | |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1200 | namespace { |
| 1201 | class LocalVarRefChecker : public ConstStmtVisitor<LocalVarRefChecker, bool> { |
| 1202 | Sema &SemaRef; |
| 1203 | |
| 1204 | public: |
| 1205 | bool VisitDeclRefExpr(const DeclRefExpr *E) { |
| 1206 | if (auto VD = dyn_cast<VarDecl>(E->getDecl())) { |
| 1207 | if (VD->hasLocalStorage()) { |
| 1208 | SemaRef.Diag(E->getLocStart(), |
| 1209 | diag::err_omp_local_var_in_threadprivate_init) |
| 1210 | << E->getSourceRange(); |
| 1211 | SemaRef.Diag(VD->getLocation(), diag::note_defined_here) |
| 1212 | << VD << VD->getSourceRange(); |
| 1213 | return true; |
| 1214 | } |
| 1215 | } |
| 1216 | return false; |
| 1217 | } |
| 1218 | bool VisitStmt(const Stmt *S) { |
| 1219 | for (auto Child : S->children()) { |
| 1220 | if (Child && Visit(Child)) |
| 1221 | return true; |
| 1222 | } |
| 1223 | return false; |
| 1224 | } |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 1225 | explicit LocalVarRefChecker(Sema &SemaRef) : SemaRef(SemaRef) {} |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1226 | }; |
| 1227 | } // namespace |
| 1228 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1229 | OMPThreadPrivateDecl * |
| 1230 | Sema::CheckOMPThreadPrivateDecl(SourceLocation Loc, ArrayRef<Expr *> VarList) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1231 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1232 | for (auto &RefExpr : VarList) { |
| 1233 | DeclRefExpr *DE = cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1234 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); |
| 1235 | SourceLocation ILoc = DE->getExprLoc(); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1236 | |
Alexey Bataev | 376b4a4 | 2016-02-09 09:41:09 +0000 | [diff] [blame] | 1237 | // Mark variable as used. |
| 1238 | VD->setReferenced(); |
| 1239 | VD->markUsed(Context); |
| 1240 | |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 1241 | QualType QType = VD->getType(); |
| 1242 | if (QType->isDependentType() || QType->isInstantiationDependentType()) { |
| 1243 | // It will be analyzed later. |
| 1244 | Vars.push_back(DE); |
| 1245 | continue; |
| 1246 | } |
| 1247 | |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1248 | // OpenMP [2.9.2, Restrictions, C/C++, p.10] |
| 1249 | // A threadprivate variable must not have an incomplete type. |
| 1250 | if (RequireCompleteType(ILoc, VD->getType(), |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1251 | diag::err_omp_threadprivate_incomplete_type)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1252 | continue; |
| 1253 | } |
| 1254 | |
| 1255 | // OpenMP [2.9.2, Restrictions, C/C++, p.10] |
| 1256 | // A threadprivate variable must not have a reference type. |
| 1257 | if (VD->getType()->isReferenceType()) { |
| 1258 | Diag(ILoc, diag::err_omp_ref_type_arg) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1259 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD->getType(); |
| 1260 | bool IsDecl = |
| 1261 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1262 | Diag(VD->getLocation(), |
| 1263 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1264 | << VD; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1265 | continue; |
| 1266 | } |
| 1267 | |
Samuel Antao | f8b5012 | 2015-07-13 22:54:53 +0000 | [diff] [blame] | 1268 | // Check if this is a TLS variable. If TLS is not being supported, produce |
| 1269 | // the corresponding diagnostic. |
| 1270 | if ((VD->getTLSKind() != VarDecl::TLS_None && |
| 1271 | !(VD->hasAttr<OMPThreadPrivateDeclAttr>() && |
| 1272 | getLangOpts().OpenMPUseTLS && |
| 1273 | getASTContext().getTargetInfo().isTLSSupported())) || |
Alexey Bataev | 1a8b3f1 | 2015-05-06 06:34:55 +0000 | [diff] [blame] | 1274 | (VD->getStorageClass() == SC_Register && VD->hasAttr<AsmLabelAttr>() && |
| 1275 | !VD->isLocalVarDecl())) { |
Alexey Bataev | 26a3924 | 2015-01-13 03:35:30 +0000 | [diff] [blame] | 1276 | Diag(ILoc, diag::err_omp_var_thread_local) |
| 1277 | << VD << ((VD->getTLSKind() != VarDecl::TLS_None) ? 0 : 1); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1278 | bool IsDecl = |
| 1279 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1280 | Diag(VD->getLocation(), |
| 1281 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1282 | << VD; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1283 | continue; |
| 1284 | } |
| 1285 | |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1286 | // Check if initial value of threadprivate variable reference variable with |
| 1287 | // local storage (it is not supported by runtime). |
| 1288 | if (auto Init = VD->getAnyInitializer()) { |
| 1289 | LocalVarRefChecker Checker(*this); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1290 | if (Checker.Visit(Init)) |
| 1291 | continue; |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1292 | } |
| 1293 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1294 | Vars.push_back(RefExpr); |
Alexey Bataev | d178ad4 | 2014-03-07 08:03:37 +0000 | [diff] [blame] | 1295 | DSAStack->addDSA(VD, DE, OMPC_threadprivate); |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 1296 | VD->addAttr(OMPThreadPrivateDeclAttr::CreateImplicit( |
| 1297 | Context, SourceRange(Loc, Loc))); |
| 1298 | if (auto *ML = Context.getASTMutationListener()) |
| 1299 | ML->DeclarationMarkedOpenMPThreadPrivate(VD); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1300 | } |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 1301 | OMPThreadPrivateDecl *D = nullptr; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 1302 | if (!Vars.empty()) { |
| 1303 | D = OMPThreadPrivateDecl::Create(Context, getCurLexicalContext(), Loc, |
| 1304 | Vars); |
| 1305 | D->setAccess(AS_public); |
| 1306 | } |
| 1307 | return D; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1308 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1309 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1310 | static void ReportOriginalDSA(Sema &SemaRef, DSAStackTy *Stack, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1311 | const ValueDecl *D, DSAStackTy::DSAVarData DVar, |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1312 | bool IsLoopIterVar = false) { |
| 1313 | if (DVar.RefExpr) { |
| 1314 | SemaRef.Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_explicit_dsa) |
| 1315 | << getOpenMPClauseName(DVar.CKind); |
| 1316 | return; |
| 1317 | } |
| 1318 | enum { |
| 1319 | PDSA_StaticMemberShared, |
| 1320 | PDSA_StaticLocalVarShared, |
| 1321 | PDSA_LoopIterVarPrivate, |
| 1322 | PDSA_LoopIterVarLinear, |
| 1323 | PDSA_LoopIterVarLastprivate, |
| 1324 | PDSA_ConstVarShared, |
| 1325 | PDSA_GlobalVarShared, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1326 | PDSA_TaskVarFirstprivate, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1327 | PDSA_LocalVarPrivate, |
| 1328 | PDSA_Implicit |
| 1329 | } Reason = PDSA_Implicit; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1330 | bool ReportHint = false; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1331 | auto ReportLoc = D->getLocation(); |
| 1332 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1333 | if (IsLoopIterVar) { |
| 1334 | if (DVar.CKind == OMPC_private) |
| 1335 | Reason = PDSA_LoopIterVarPrivate; |
| 1336 | else if (DVar.CKind == OMPC_lastprivate) |
| 1337 | Reason = PDSA_LoopIterVarLastprivate; |
| 1338 | else |
| 1339 | Reason = PDSA_LoopIterVarLinear; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1340 | } else if (DVar.DKind == OMPD_task && DVar.CKind == OMPC_firstprivate) { |
| 1341 | Reason = PDSA_TaskVarFirstprivate; |
| 1342 | ReportLoc = DVar.ImplicitDSALoc; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1343 | } else if (VD && VD->isStaticLocal()) |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1344 | Reason = PDSA_StaticLocalVarShared; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1345 | else if (VD && VD->isStaticDataMember()) |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1346 | Reason = PDSA_StaticMemberShared; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1347 | else if (VD && VD->isFileVarDecl()) |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1348 | Reason = PDSA_GlobalVarShared; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1349 | else if (D->getType().isConstant(SemaRef.getASTContext())) |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1350 | Reason = PDSA_ConstVarShared; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1351 | else if (VD && VD->isLocalVarDecl() && DVar.CKind == OMPC_private) { |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1352 | ReportHint = true; |
| 1353 | Reason = PDSA_LocalVarPrivate; |
| 1354 | } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1355 | if (Reason != PDSA_Implicit) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1356 | SemaRef.Diag(ReportLoc, diag::note_omp_predetermined_dsa) |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1357 | << Reason << ReportHint |
| 1358 | << getOpenMPDirectiveName(Stack->getCurrentDirective()); |
| 1359 | } else if (DVar.ImplicitDSALoc.isValid()) { |
| 1360 | SemaRef.Diag(DVar.ImplicitDSALoc, diag::note_omp_implicit_dsa) |
| 1361 | << getOpenMPClauseName(DVar.CKind); |
| 1362 | } |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1363 | } |
| 1364 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1365 | namespace { |
| 1366 | class DSAAttrChecker : public StmtVisitor<DSAAttrChecker, void> { |
| 1367 | DSAStackTy *Stack; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1368 | Sema &SemaRef; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1369 | bool ErrorFound; |
| 1370 | CapturedStmt *CS; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1371 | llvm::SmallVector<Expr *, 8> ImplicitFirstprivate; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1372 | llvm::DenseMap<ValueDecl *, Expr *> VarsWithInheritedDSA; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1373 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1374 | public: |
| 1375 | void VisitDeclRefExpr(DeclRefExpr *E) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1376 | if (auto *VD = dyn_cast<VarDecl>(E->getDecl())) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1377 | // Skip internally declared variables. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1378 | if (VD->isLocalVarDecl() && !CS->capturesVariable(VD)) |
| 1379 | return; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1380 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1381 | auto DVar = Stack->getTopDSA(VD, false); |
| 1382 | // Check if the variable has explicit DSA set and stop analysis if it so. |
| 1383 | if (DVar.RefExpr) return; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1384 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1385 | auto ELoc = E->getExprLoc(); |
| 1386 | auto DKind = Stack->getCurrentDirective(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1387 | // The default(none) clause requires that each variable that is referenced |
| 1388 | // in the construct, and does not have a predetermined data-sharing |
| 1389 | // attribute, must have its data-sharing attribute explicitly determined |
| 1390 | // by being listed in a data-sharing attribute clause. |
| 1391 | if (DVar.CKind == OMPC_unknown && Stack->getDefaultDSA() == DSA_none && |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1392 | isParallelOrTaskRegion(DKind) && |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1393 | VarsWithInheritedDSA.count(VD) == 0) { |
| 1394 | VarsWithInheritedDSA[VD] = E; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1395 | return; |
| 1396 | } |
| 1397 | |
| 1398 | // OpenMP [2.9.3.6, Restrictions, p.2] |
| 1399 | // A list item that appears in a reduction clause of the innermost |
| 1400 | // enclosing worksharing or parallel construct may not be accessed in an |
| 1401 | // explicit task. |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1402 | DVar = Stack->hasInnermostDSA(VD, MatchesAnyClause(OMPC_reduction), |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1403 | [](OpenMPDirectiveKind K) -> bool { |
| 1404 | return isOpenMPParallelDirective(K) || |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1405 | isOpenMPWorksharingDirective(K) || |
| 1406 | isOpenMPTeamsDirective(K); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1407 | }, |
| 1408 | false); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1409 | if (DKind == OMPD_task && DVar.CKind == OMPC_reduction) { |
| 1410 | ErrorFound = true; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1411 | SemaRef.Diag(ELoc, diag::err_omp_reduction_in_task); |
| 1412 | ReportOriginalDSA(SemaRef, Stack, VD, DVar); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1413 | return; |
| 1414 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1415 | |
| 1416 | // Define implicit data-sharing attributes for task. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1417 | DVar = Stack->getImplicitDSA(VD, false); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1418 | if (DKind == OMPD_task && DVar.CKind != OMPC_shared) |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1419 | ImplicitFirstprivate.push_back(E); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1420 | } |
| 1421 | } |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1422 | void VisitMemberExpr(MemberExpr *E) { |
| 1423 | if (isa<CXXThisExpr>(E->getBase()->IgnoreParens())) { |
| 1424 | if (auto *FD = dyn_cast<FieldDecl>(E->getMemberDecl())) { |
| 1425 | auto DVar = Stack->getTopDSA(FD, false); |
| 1426 | // Check if the variable has explicit DSA set and stop analysis if it |
| 1427 | // so. |
| 1428 | if (DVar.RefExpr) |
| 1429 | return; |
| 1430 | |
| 1431 | auto ELoc = E->getExprLoc(); |
| 1432 | auto DKind = Stack->getCurrentDirective(); |
| 1433 | // OpenMP [2.9.3.6, Restrictions, p.2] |
| 1434 | // A list item that appears in a reduction clause of the innermost |
| 1435 | // enclosing worksharing or parallel construct may not be accessed in |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 1436 | // an explicit task. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1437 | DVar = |
| 1438 | Stack->hasInnermostDSA(FD, MatchesAnyClause(OMPC_reduction), |
| 1439 | [](OpenMPDirectiveKind K) -> bool { |
| 1440 | return isOpenMPParallelDirective(K) || |
| 1441 | isOpenMPWorksharingDirective(K) || |
| 1442 | isOpenMPTeamsDirective(K); |
| 1443 | }, |
| 1444 | false); |
| 1445 | if (DKind == OMPD_task && DVar.CKind == OMPC_reduction) { |
| 1446 | ErrorFound = true; |
| 1447 | SemaRef.Diag(ELoc, diag::err_omp_reduction_in_task); |
| 1448 | ReportOriginalDSA(SemaRef, Stack, FD, DVar); |
| 1449 | return; |
| 1450 | } |
| 1451 | |
| 1452 | // Define implicit data-sharing attributes for task. |
| 1453 | DVar = Stack->getImplicitDSA(FD, false); |
| 1454 | if (DKind == OMPD_task && DVar.CKind != OMPC_shared) |
| 1455 | ImplicitFirstprivate.push_back(E); |
| 1456 | } |
| 1457 | } |
| 1458 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1459 | void VisitOMPExecutableDirective(OMPExecutableDirective *S) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1460 | for (auto *C : S->clauses()) { |
| 1461 | // Skip analysis of arguments of implicitly defined firstprivate clause |
| 1462 | // for task directives. |
| 1463 | if (C && (!isa<OMPFirstprivateClause>(C) || C->getLocStart().isValid())) |
| 1464 | for (auto *CC : C->children()) { |
| 1465 | if (CC) |
| 1466 | Visit(CC); |
| 1467 | } |
| 1468 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1469 | } |
| 1470 | void VisitStmt(Stmt *S) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1471 | for (auto *C : S->children()) { |
| 1472 | if (C && !isa<OMPExecutableDirective>(C)) |
| 1473 | Visit(C); |
| 1474 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1475 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1476 | |
| 1477 | bool isErrorFound() { return ErrorFound; } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1478 | ArrayRef<Expr *> getImplicitFirstprivate() { return ImplicitFirstprivate; } |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1479 | llvm::DenseMap<ValueDecl *, Expr *> &getVarsWithInheritedDSA() { |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1480 | return VarsWithInheritedDSA; |
| 1481 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1482 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1483 | DSAAttrChecker(DSAStackTy *S, Sema &SemaRef, CapturedStmt *CS) |
| 1484 | : Stack(S), SemaRef(SemaRef), ErrorFound(false), CS(CS) {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1485 | }; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1486 | } // namespace |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1487 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1488 | void Sema::ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, Scope *CurScope) { |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1489 | switch (DKind) { |
| 1490 | case OMPD_parallel: { |
| 1491 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1492 | QualType KmpInt32PtrTy = |
| 1493 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
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(".global_tid.", KmpInt32PtrTy), |
| 1496 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1497 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1498 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1499 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1500 | Params); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1501 | break; |
| 1502 | } |
| 1503 | case OMPD_simd: { |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1504 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1505 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1506 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1507 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1508 | Params); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1509 | break; |
| 1510 | } |
| 1511 | case OMPD_for: { |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1512 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1513 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1514 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1515 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1516 | Params); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1517 | break; |
| 1518 | } |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1519 | case OMPD_for_simd: { |
| 1520 | Sema::CapturedParamNameType Params[] = { |
| 1521 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1522 | }; |
| 1523 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1524 | Params); |
| 1525 | break; |
| 1526 | } |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 1527 | case OMPD_sections: { |
| 1528 | Sema::CapturedParamNameType Params[] = { |
| 1529 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1530 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1531 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1532 | Params); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 1533 | break; |
| 1534 | } |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1535 | case OMPD_section: { |
| 1536 | Sema::CapturedParamNameType Params[] = { |
| 1537 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1538 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1539 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1540 | Params); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1541 | break; |
| 1542 | } |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 1543 | case OMPD_single: { |
| 1544 | Sema::CapturedParamNameType Params[] = { |
| 1545 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1546 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1547 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1548 | Params); |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 1549 | break; |
| 1550 | } |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1551 | case OMPD_master: { |
| 1552 | Sema::CapturedParamNameType Params[] = { |
| 1553 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1554 | }; |
| 1555 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1556 | Params); |
| 1557 | break; |
| 1558 | } |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1559 | case OMPD_critical: { |
| 1560 | Sema::CapturedParamNameType Params[] = { |
| 1561 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1562 | }; |
| 1563 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1564 | Params); |
| 1565 | break; |
| 1566 | } |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1567 | case OMPD_parallel_for: { |
| 1568 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1569 | QualType KmpInt32PtrTy = |
| 1570 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1571 | Sema::CapturedParamNameType Params[] = { |
| 1572 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1573 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1574 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1575 | }; |
| 1576 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1577 | Params); |
| 1578 | break; |
| 1579 | } |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1580 | case OMPD_parallel_for_simd: { |
| 1581 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1582 | QualType KmpInt32PtrTy = |
| 1583 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1584 | Sema::CapturedParamNameType Params[] = { |
| 1585 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1586 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1587 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1588 | }; |
| 1589 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1590 | Params); |
| 1591 | break; |
| 1592 | } |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1593 | case OMPD_parallel_sections: { |
Alexey Bataev | 68adb7d | 2015-04-14 03:29:22 +0000 | [diff] [blame] | 1594 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1595 | QualType KmpInt32PtrTy = |
| 1596 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1597 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | 68adb7d | 2015-04-14 03:29:22 +0000 | [diff] [blame] | 1598 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1599 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1600 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1601 | }; |
| 1602 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1603 | Params); |
| 1604 | break; |
| 1605 | } |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1606 | case OMPD_task: { |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1607 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 3ae88e2 | 2015-05-22 08:56:35 +0000 | [diff] [blame] | 1608 | QualType Args[] = {Context.VoidPtrTy.withConst().withRestrict()}; |
| 1609 | FunctionProtoType::ExtProtoInfo EPI; |
| 1610 | EPI.Variadic = true; |
| 1611 | QualType CopyFnType = Context.getFunctionType(Context.VoidTy, Args, EPI); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1612 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1613 | std::make_pair(".global_tid.", KmpInt32Ty), |
| 1614 | std::make_pair(".part_id.", KmpInt32Ty), |
Alexey Bataev | 3ae88e2 | 2015-05-22 08:56:35 +0000 | [diff] [blame] | 1615 | std::make_pair(".privates.", |
| 1616 | Context.VoidPtrTy.withConst().withRestrict()), |
| 1617 | std::make_pair( |
| 1618 | ".copy_fn.", |
| 1619 | Context.getPointerType(CopyFnType).withConst().withRestrict()), |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1620 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1621 | }; |
| 1622 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1623 | Params); |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1624 | // Mark this captured region as inlined, because we don't use outlined |
| 1625 | // function directly. |
| 1626 | getCurCapturedRegion()->TheCapturedDecl->addAttr( |
| 1627 | AlwaysInlineAttr::CreateImplicit( |
| 1628 | Context, AlwaysInlineAttr::Keyword_forceinline, SourceRange())); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1629 | break; |
| 1630 | } |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1631 | case OMPD_ordered: { |
| 1632 | Sema::CapturedParamNameType Params[] = { |
| 1633 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1634 | }; |
| 1635 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1636 | Params); |
| 1637 | break; |
| 1638 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1639 | case OMPD_atomic: { |
| 1640 | Sema::CapturedParamNameType Params[] = { |
| 1641 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1642 | }; |
| 1643 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1644 | Params); |
| 1645 | break; |
| 1646 | } |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 1647 | case OMPD_target_data: |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 1648 | case OMPD_target: |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 1649 | case OMPD_target_parallel: |
| 1650 | case OMPD_target_parallel_for: { |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1651 | Sema::CapturedParamNameType Params[] = { |
| 1652 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1653 | }; |
| 1654 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1655 | Params); |
| 1656 | break; |
| 1657 | } |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1658 | case OMPD_teams: { |
| 1659 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1660 | QualType KmpInt32PtrTy = |
| 1661 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1662 | Sema::CapturedParamNameType Params[] = { |
| 1663 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1664 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1665 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1666 | }; |
| 1667 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1668 | Params); |
| 1669 | break; |
| 1670 | } |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1671 | case OMPD_taskgroup: { |
| 1672 | Sema::CapturedParamNameType Params[] = { |
| 1673 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1674 | }; |
| 1675 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1676 | Params); |
| 1677 | break; |
| 1678 | } |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1679 | case OMPD_taskloop: { |
| 1680 | Sema::CapturedParamNameType Params[] = { |
| 1681 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1682 | }; |
| 1683 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1684 | Params); |
| 1685 | break; |
| 1686 | } |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1687 | case OMPD_taskloop_simd: { |
| 1688 | Sema::CapturedParamNameType Params[] = { |
| 1689 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1690 | }; |
| 1691 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1692 | Params); |
| 1693 | break; |
| 1694 | } |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1695 | case OMPD_distribute: { |
| 1696 | Sema::CapturedParamNameType Params[] = { |
| 1697 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1698 | }; |
| 1699 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1700 | Params); |
| 1701 | break; |
| 1702 | } |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1703 | case OMPD_threadprivate: |
Alexey Bataev | ee9af45 | 2014-11-21 11:33:46 +0000 | [diff] [blame] | 1704 | case OMPD_taskyield: |
| 1705 | case OMPD_barrier: |
| 1706 | case OMPD_taskwait: |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1707 | case OMPD_cancellation_point: |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1708 | case OMPD_cancel: |
Alexey Bataev | ee9af45 | 2014-11-21 11:33:46 +0000 | [diff] [blame] | 1709 | case OMPD_flush: |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1710 | case OMPD_target_enter_data: |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1711 | case OMPD_target_exit_data: |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1712 | llvm_unreachable("OpenMP Directive is not allowed"); |
| 1713 | case OMPD_unknown: |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1714 | llvm_unreachable("Unknown OpenMP directive"); |
| 1715 | } |
| 1716 | } |
| 1717 | |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1718 | static OMPCapturedExprDecl *buildCaptureDecl(Sema &S, IdentifierInfo *Id, |
| 1719 | Expr *CaptureExpr) { |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 1720 | ASTContext &C = S.getASTContext(); |
| 1721 | Expr *Init = CaptureExpr->IgnoreImpCasts(); |
| 1722 | QualType Ty = Init->getType(); |
| 1723 | if (CaptureExpr->getObjectKind() == OK_Ordinary && CaptureExpr->isGLValue()) { |
| 1724 | if (S.getLangOpts().CPlusPlus) |
| 1725 | Ty = C.getLValueReferenceType(Ty); |
| 1726 | else { |
| 1727 | Ty = C.getPointerType(Ty); |
| 1728 | ExprResult Res = |
| 1729 | S.CreateBuiltinUnaryOp(CaptureExpr->getExprLoc(), UO_AddrOf, Init); |
| 1730 | if (!Res.isUsable()) |
| 1731 | return nullptr; |
| 1732 | Init = Res.get(); |
| 1733 | } |
| 1734 | } |
| 1735 | auto *CED = OMPCapturedExprDecl::Create(C, S.CurContext, Id, Ty); |
| 1736 | S.CurContext->addHiddenDecl(CED); |
| 1737 | S.AddInitializerToDecl(CED, Init, /*DirectInit=*/false, |
| 1738 | /*TypeMayContainAuto=*/true); |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1739 | return CED; |
| 1740 | } |
| 1741 | |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame^] | 1742 | static DeclRefExpr *buildCapture(Sema &S, ValueDecl *D, Expr *CaptureExpr) { |
| 1743 | OMPCapturedExprDecl *CD; |
| 1744 | if (auto *VD = S.IsOpenMPCapturedDecl(D)) |
| 1745 | CD = cast<OMPCapturedExprDecl>(VD); |
| 1746 | else |
| 1747 | CD = buildCaptureDecl(S, D->getIdentifier(), CaptureExpr); |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1748 | return buildDeclRefExpr(S, CD, CD->getType().getNonReferenceType(), |
| 1749 | SourceLocation()); |
| 1750 | } |
| 1751 | |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame^] | 1752 | static DeclRefExpr *buildCapture(Sema &S, Expr *CaptureExpr) { |
| 1753 | auto *CD = buildCaptureDecl( |
| 1754 | S, &S.getASTContext().Idents.get(".capture_expr."), CaptureExpr); |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1755 | return buildDeclRefExpr(S, CD, CD->getType().getNonReferenceType(), |
| 1756 | SourceLocation()); |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 1757 | } |
| 1758 | |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1759 | StmtResult Sema::ActOnOpenMPRegionEnd(StmtResult S, |
| 1760 | ArrayRef<OMPClause *> Clauses) { |
| 1761 | if (!S.isUsable()) { |
| 1762 | ActOnCapturedRegionError(); |
| 1763 | return StmtError(); |
| 1764 | } |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1765 | |
| 1766 | OMPOrderedClause *OC = nullptr; |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1767 | OMPScheduleClause *SC = nullptr; |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1768 | SmallVector<OMPLinearClause *, 4> LCs; |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1769 | // This is required for proper codegen. |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1770 | for (auto *Clause : Clauses) { |
Alexey Bataev | 16dc7b6 | 2015-05-20 03:46:04 +0000 | [diff] [blame] | 1771 | if (isOpenMPPrivate(Clause->getClauseKind()) || |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 1772 | Clause->getClauseKind() == OMPC_copyprivate || |
| 1773 | (getLangOpts().OpenMPUseTLS && |
| 1774 | getASTContext().getTargetInfo().isTLSSupported() && |
| 1775 | Clause->getClauseKind() == OMPC_copyin)) { |
| 1776 | DSAStack->setForceVarCapturing(Clause->getClauseKind() == OMPC_copyin); |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1777 | // Mark all variables in private list clauses as used in inner region. |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1778 | for (auto *VarRef : Clause->children()) { |
| 1779 | if (auto *E = cast_or_null<Expr>(VarRef)) { |
Alexey Bataev | 8bf6b3e | 2015-04-02 13:07:08 +0000 | [diff] [blame] | 1780 | MarkDeclarationsReferencedInExpr(E); |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1781 | } |
| 1782 | } |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 1783 | DSAStack->setForceVarCapturing(/*V=*/false); |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1784 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective())) { |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1785 | // Mark all variables in private list clauses as used in inner region. |
| 1786 | // Required for proper codegen of combined directives. |
| 1787 | // TODO: add processing for other clauses. |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1788 | if (auto *C = OMPClauseWithPreInit::get(Clause)) { |
| 1789 | if (auto *S = cast_or_null<DeclStmt>(C->getPreInitStmt())) { |
| 1790 | for (auto *D : S->decls()) |
| 1791 | MarkVariableReferenced(D->getLocation(), cast<VarDecl>(D)); |
| 1792 | } |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 1793 | } |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1794 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1795 | if (Clause->getClauseKind() == OMPC_schedule) |
| 1796 | SC = cast<OMPScheduleClause>(Clause); |
| 1797 | else if (Clause->getClauseKind() == OMPC_ordered) |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1798 | OC = cast<OMPOrderedClause>(Clause); |
| 1799 | else if (Clause->getClauseKind() == OMPC_linear) |
| 1800 | LCs.push_back(cast<OMPLinearClause>(Clause)); |
| 1801 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1802 | bool ErrorFound = false; |
| 1803 | // OpenMP, 2.7.1 Loop Construct, Restrictions |
| 1804 | // The nonmonotonic modifier cannot be specified if an ordered clause is |
| 1805 | // specified. |
| 1806 | if (SC && |
| 1807 | (SC->getFirstScheduleModifier() == OMPC_SCHEDULE_MODIFIER_nonmonotonic || |
| 1808 | SC->getSecondScheduleModifier() == |
| 1809 | OMPC_SCHEDULE_MODIFIER_nonmonotonic) && |
| 1810 | OC) { |
| 1811 | Diag(SC->getFirstScheduleModifier() == OMPC_SCHEDULE_MODIFIER_nonmonotonic |
| 1812 | ? SC->getFirstScheduleModifierLoc() |
| 1813 | : SC->getSecondScheduleModifierLoc(), |
| 1814 | diag::err_omp_schedule_nonmonotonic_ordered) |
| 1815 | << SourceRange(OC->getLocStart(), OC->getLocEnd()); |
| 1816 | ErrorFound = true; |
| 1817 | } |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1818 | if (!LCs.empty() && OC && OC->getNumForLoops()) { |
| 1819 | for (auto *C : LCs) { |
| 1820 | Diag(C->getLocStart(), diag::err_omp_linear_ordered) |
| 1821 | << SourceRange(OC->getLocStart(), OC->getLocEnd()); |
| 1822 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1823 | ErrorFound = true; |
| 1824 | } |
Alexey Bataev | 113438c | 2015-12-30 12:06:23 +0000 | [diff] [blame] | 1825 | if (isOpenMPWorksharingDirective(DSAStack->getCurrentDirective()) && |
| 1826 | isOpenMPSimdDirective(DSAStack->getCurrentDirective()) && OC && |
| 1827 | OC->getNumForLoops()) { |
| 1828 | Diag(OC->getLocStart(), diag::err_omp_ordered_simd) |
| 1829 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 1830 | ErrorFound = true; |
| 1831 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1832 | if (ErrorFound) { |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1833 | ActOnCapturedRegionError(); |
| 1834 | return StmtError(); |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1835 | } |
| 1836 | return ActOnCapturedRegionEnd(S.get()); |
| 1837 | } |
| 1838 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1839 | static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, |
| 1840 | OpenMPDirectiveKind CurrentRegion, |
| 1841 | const DeclarationNameInfo &CurrentName, |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1842 | OpenMPDirectiveKind CancelRegion, |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1843 | SourceLocation StartLoc) { |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1844 | // Allowed nesting of constructs |
| 1845 | // +------------------+-----------------+------------------------------------+ |
| 1846 | // | Parent directive | Child directive | Closely (!), No-Closely(+), Both(*)| |
| 1847 | // +------------------+-----------------+------------------------------------+ |
| 1848 | // | parallel | parallel | * | |
| 1849 | // | parallel | for | * | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1850 | // | parallel | for simd | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1851 | // | parallel | master | * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1852 | // | parallel | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1853 | // | parallel | simd | * | |
| 1854 | // | parallel | sections | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1855 | // | parallel | section | + | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1856 | // | parallel | single | * | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1857 | // | parallel | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1858 | // | parallel |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1859 | // | parallel |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1860 | // | parallel | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1861 | // | parallel | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1862 | // | parallel | barrier | * | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1863 | // | parallel | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1864 | // | parallel | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1865 | // | parallel | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1866 | // | parallel | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1867 | // | parallel | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1868 | // | parallel | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 1869 | // | parallel | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 1870 | // | parallel | target parallel | * | |
| 1871 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1872 | // | parallel | target enter | * | |
| 1873 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1874 | // | parallel | target exit | * | |
| 1875 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1876 | // | parallel | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1877 | // | parallel | cancellation | | |
| 1878 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1879 | // | parallel | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1880 | // | parallel | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1881 | // | parallel | taskloop simd | * | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1882 | // | parallel | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1883 | // +------------------+-----------------+------------------------------------+ |
| 1884 | // | for | parallel | * | |
| 1885 | // | for | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1886 | // | for | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1887 | // | for | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1888 | // | for | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1889 | // | for | simd | * | |
| 1890 | // | for | sections | + | |
| 1891 | // | for | section | + | |
| 1892 | // | for | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1893 | // | for | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1894 | // | for |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1895 | // | for |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1896 | // | for | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1897 | // | for | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1898 | // | for | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1899 | // | for | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1900 | // | for | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1901 | // | for | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1902 | // | for | ordered | * (if construct is ordered) | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1903 | // | for | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1904 | // | for | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 1905 | // | for | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 1906 | // | for | target parallel | * | |
| 1907 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1908 | // | for | target enter | * | |
| 1909 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1910 | // | for | target exit | * | |
| 1911 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1912 | // | for | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1913 | // | for | cancellation | | |
| 1914 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1915 | // | for | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1916 | // | for | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1917 | // | for | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1918 | // | for | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1919 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1920 | // | master | parallel | * | |
| 1921 | // | master | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1922 | // | master | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1923 | // | master | master | * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1924 | // | master | critical | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1925 | // | master | simd | * | |
| 1926 | // | master | sections | + | |
| 1927 | // | master | section | + | |
| 1928 | // | master | single | + | |
| 1929 | // | master | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1930 | // | master |parallel for simd| * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1931 | // | master |parallel sections| * | |
| 1932 | // | master | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1933 | // | master | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1934 | // | master | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1935 | // | master | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1936 | // | master | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1937 | // | master | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1938 | // | master | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1939 | // | master | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1940 | // | master | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 1941 | // | master | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 1942 | // | master | target parallel | * | |
| 1943 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1944 | // | master | target enter | * | |
| 1945 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1946 | // | master | target exit | * | |
| 1947 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1948 | // | master | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1949 | // | master | cancellation | | |
| 1950 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1951 | // | master | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1952 | // | master | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1953 | // | master | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1954 | // | master | distribute | | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1955 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1956 | // | critical | parallel | * | |
| 1957 | // | critical | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1958 | // | critical | for simd | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1959 | // | critical | master | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1960 | // | critical | critical | * (should have different names) | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1961 | // | critical | simd | * | |
| 1962 | // | critical | sections | + | |
| 1963 | // | critical | section | + | |
| 1964 | // | critical | single | + | |
| 1965 | // | critical | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1966 | // | critical |parallel for simd| * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1967 | // | critical |parallel sections| * | |
| 1968 | // | critical | task | * | |
| 1969 | // | critical | taskyield | * | |
| 1970 | // | critical | barrier | + | |
| 1971 | // | critical | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1972 | // | critical | taskgroup | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1973 | // | critical | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1974 | // | critical | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1975 | // | critical | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 1976 | // | critical | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 1977 | // | critical | target parallel | * | |
| 1978 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1979 | // | critical | target enter | * | |
| 1980 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1981 | // | critical | target exit | * | |
| 1982 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1983 | // | critical | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1984 | // | critical | cancellation | | |
| 1985 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1986 | // | critical | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1987 | // | critical | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1988 | // | critical | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1989 | // | critical | distribute | | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1990 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1991 | // | simd | parallel | | |
| 1992 | // | simd | for | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1993 | // | simd | for simd | | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1994 | // | simd | master | | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1995 | // | simd | critical | | |
Alexey Bataev | 1f09221 | 2016-02-02 04:59:52 +0000 | [diff] [blame] | 1996 | // | simd | simd | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1997 | // | simd | sections | | |
| 1998 | // | simd | section | | |
| 1999 | // | simd | single | | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2000 | // | simd | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2001 | // | simd |parallel for simd| | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2002 | // | simd |parallel sections| | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2003 | // | simd | task | | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2004 | // | simd | taskyield | | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2005 | // | simd | barrier | | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2006 | // | simd | taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2007 | // | simd | taskgroup | | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2008 | // | simd | flush | | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2009 | // | simd | ordered | + (with simd clause) | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2010 | // | simd | atomic | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2011 | // | simd | target | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2012 | // | simd | target parallel | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2013 | // | simd | target parallel | | |
| 2014 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2015 | // | simd | target enter | | |
| 2016 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2017 | // | simd | target exit | | |
| 2018 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2019 | // | simd | teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2020 | // | simd | cancellation | | |
| 2021 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2022 | // | simd | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2023 | // | simd | taskloop | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2024 | // | simd | taskloop simd | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2025 | // | simd | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2026 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2027 | // | for simd | parallel | | |
| 2028 | // | for simd | for | | |
| 2029 | // | for simd | for simd | | |
| 2030 | // | for simd | master | | |
| 2031 | // | for simd | critical | | |
Alexey Bataev | 1f09221 | 2016-02-02 04:59:52 +0000 | [diff] [blame] | 2032 | // | for simd | simd | * | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2033 | // | for simd | sections | | |
| 2034 | // | for simd | section | | |
| 2035 | // | for simd | single | | |
| 2036 | // | for simd | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2037 | // | for simd |parallel for simd| | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2038 | // | for simd |parallel sections| | |
| 2039 | // | for simd | task | | |
| 2040 | // | for simd | taskyield | | |
| 2041 | // | for simd | barrier | | |
| 2042 | // | for simd | taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2043 | // | for simd | taskgroup | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2044 | // | for simd | flush | | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2045 | // | for simd | ordered | + (with simd clause) | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2046 | // | for simd | atomic | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2047 | // | for simd | target | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2048 | // | for simd | target parallel | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2049 | // | for simd | target parallel | | |
| 2050 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2051 | // | for simd | target enter | | |
| 2052 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2053 | // | for simd | target exit | | |
| 2054 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2055 | // | for simd | teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2056 | // | for simd | cancellation | | |
| 2057 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2058 | // | for simd | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2059 | // | for simd | taskloop | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2060 | // | for simd | taskloop simd | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2061 | // | for simd | distribute | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2062 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2063 | // | parallel for simd| parallel | | |
| 2064 | // | parallel for simd| for | | |
| 2065 | // | parallel for simd| for simd | | |
| 2066 | // | parallel for simd| master | | |
| 2067 | // | parallel for simd| critical | | |
Alexey Bataev | 1f09221 | 2016-02-02 04:59:52 +0000 | [diff] [blame] | 2068 | // | parallel for simd| simd | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2069 | // | parallel for simd| sections | | |
| 2070 | // | parallel for simd| section | | |
| 2071 | // | parallel for simd| single | | |
| 2072 | // | parallel for simd| parallel for | | |
| 2073 | // | parallel for simd|parallel for simd| | |
| 2074 | // | parallel for simd|parallel sections| | |
| 2075 | // | parallel for simd| task | | |
| 2076 | // | parallel for simd| taskyield | | |
| 2077 | // | parallel for simd| barrier | | |
| 2078 | // | parallel for simd| taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2079 | // | parallel for simd| taskgroup | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2080 | // | parallel for simd| flush | | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2081 | // | parallel for simd| ordered | + (with simd clause) | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2082 | // | parallel for simd| atomic | | |
| 2083 | // | parallel for simd| target | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2084 | // | parallel for simd| target parallel | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2085 | // | parallel for simd| target parallel | | |
| 2086 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2087 | // | parallel for simd| target enter | | |
| 2088 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2089 | // | parallel for simd| target exit | | |
| 2090 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2091 | // | parallel for simd| teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2092 | // | parallel for simd| cancellation | | |
| 2093 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2094 | // | parallel for simd| cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2095 | // | parallel for simd| taskloop | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2096 | // | parallel for simd| taskloop simd | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2097 | // | parallel for simd| distribute | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2098 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2099 | // | sections | parallel | * | |
| 2100 | // | sections | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2101 | // | sections | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2102 | // | sections | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2103 | // | sections | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2104 | // | sections | simd | * | |
| 2105 | // | sections | sections | + | |
| 2106 | // | sections | section | * | |
| 2107 | // | sections | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2108 | // | sections | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2109 | // | sections |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2110 | // | sections |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2111 | // | sections | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2112 | // | sections | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2113 | // | sections | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2114 | // | sections | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2115 | // | sections | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2116 | // | sections | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2117 | // | sections | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2118 | // | sections | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2119 | // | sections | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2120 | // | sections | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2121 | // | sections | target parallel | * | |
| 2122 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2123 | // | sections | target enter | * | |
| 2124 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2125 | // | sections | target exit | * | |
| 2126 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2127 | // | sections | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2128 | // | sections | cancellation | | |
| 2129 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2130 | // | sections | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2131 | // | sections | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2132 | // | sections | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2133 | // | sections | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2134 | // +------------------+-----------------+------------------------------------+ |
| 2135 | // | section | parallel | * | |
| 2136 | // | section | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2137 | // | section | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2138 | // | section | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2139 | // | section | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2140 | // | section | simd | * | |
| 2141 | // | section | sections | + | |
| 2142 | // | section | section | + | |
| 2143 | // | section | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2144 | // | section | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2145 | // | section |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2146 | // | section |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2147 | // | section | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2148 | // | section | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2149 | // | section | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2150 | // | section | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2151 | // | section | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2152 | // | section | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2153 | // | section | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2154 | // | section | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2155 | // | section | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2156 | // | section | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2157 | // | section | target parallel | * | |
| 2158 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2159 | // | section | target enter | * | |
| 2160 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2161 | // | section | target exit | * | |
| 2162 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2163 | // | section | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2164 | // | section | cancellation | | |
| 2165 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2166 | // | section | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2167 | // | section | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2168 | // | section | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2169 | // | section | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2170 | // +------------------+-----------------+------------------------------------+ |
| 2171 | // | single | parallel | * | |
| 2172 | // | single | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2173 | // | single | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2174 | // | single | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2175 | // | single | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2176 | // | single | simd | * | |
| 2177 | // | single | sections | + | |
| 2178 | // | single | section | + | |
| 2179 | // | single | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2180 | // | single | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2181 | // | single |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2182 | // | single |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2183 | // | single | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2184 | // | single | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2185 | // | single | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2186 | // | single | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2187 | // | single | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2188 | // | single | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2189 | // | single | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2190 | // | single | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2191 | // | single | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2192 | // | single | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2193 | // | single | target parallel | * | |
| 2194 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2195 | // | single | target enter | * | |
| 2196 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2197 | // | single | target exit | * | |
| 2198 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2199 | // | single | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2200 | // | single | cancellation | | |
| 2201 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2202 | // | single | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2203 | // | single | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2204 | // | single | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2205 | // | single | distribute | | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2206 | // +------------------+-----------------+------------------------------------+ |
| 2207 | // | parallel for | parallel | * | |
| 2208 | // | parallel for | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2209 | // | parallel for | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2210 | // | parallel for | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2211 | // | parallel for | critical | * | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2212 | // | parallel for | simd | * | |
| 2213 | // | parallel for | sections | + | |
| 2214 | // | parallel for | section | + | |
| 2215 | // | parallel for | single | + | |
| 2216 | // | parallel for | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2217 | // | parallel for |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2218 | // | parallel for |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2219 | // | parallel for | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2220 | // | parallel for | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2221 | // | parallel for | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2222 | // | parallel for | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2223 | // | parallel for | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2224 | // | parallel for | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2225 | // | parallel for | ordered | * (if construct is ordered) | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2226 | // | parallel for | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2227 | // | parallel for | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2228 | // | parallel for | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2229 | // | parallel for | target parallel | * | |
| 2230 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2231 | // | parallel for | target enter | * | |
| 2232 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2233 | // | parallel for | target exit | * | |
| 2234 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2235 | // | parallel for | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2236 | // | parallel for | cancellation | | |
| 2237 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2238 | // | parallel for | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2239 | // | parallel for | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2240 | // | parallel for | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2241 | // | parallel for | distribute | | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2242 | // +------------------+-----------------+------------------------------------+ |
| 2243 | // | parallel sections| parallel | * | |
| 2244 | // | parallel sections| for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2245 | // | parallel sections| for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2246 | // | parallel sections| master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2247 | // | parallel sections| critical | + | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2248 | // | parallel sections| simd | * | |
| 2249 | // | parallel sections| sections | + | |
| 2250 | // | parallel sections| section | * | |
| 2251 | // | parallel sections| single | + | |
| 2252 | // | parallel sections| parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2253 | // | parallel sections|parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2254 | // | parallel sections|parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2255 | // | parallel sections| task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2256 | // | parallel sections| taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2257 | // | parallel sections| barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2258 | // | parallel sections| taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2259 | // | parallel sections| taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2260 | // | parallel sections| flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2261 | // | parallel sections| ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2262 | // | parallel sections| atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2263 | // | parallel sections| target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2264 | // | parallel sections| target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2265 | // | parallel sections| target parallel | * | |
| 2266 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2267 | // | parallel sections| target enter | * | |
| 2268 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2269 | // | parallel sections| target exit | * | |
| 2270 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2271 | // | parallel sections| teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2272 | // | parallel sections| cancellation | | |
| 2273 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2274 | // | parallel sections| cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2275 | // | parallel sections| taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2276 | // | parallel sections| taskloop simd | * | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2277 | // | parallel sections| distribute | | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2278 | // +------------------+-----------------+------------------------------------+ |
| 2279 | // | task | parallel | * | |
| 2280 | // | task | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2281 | // | task | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2282 | // | task | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2283 | // | task | critical | * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2284 | // | task | simd | * | |
| 2285 | // | task | sections | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2286 | // | task | section | + | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2287 | // | task | single | + | |
| 2288 | // | task | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2289 | // | task |parallel for simd| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2290 | // | task |parallel sections| * | |
| 2291 | // | task | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2292 | // | task | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2293 | // | task | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2294 | // | task | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2295 | // | task | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2296 | // | task | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2297 | // | task | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2298 | // | task | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2299 | // | task | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2300 | // | task | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2301 | // | task | target parallel | * | |
| 2302 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2303 | // | task | target enter | * | |
| 2304 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2305 | // | task | target exit | * | |
| 2306 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2307 | // | task | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2308 | // | task | cancellation | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2309 | // | | point | ! | |
| 2310 | // | task | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2311 | // | task | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2312 | // | task | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2313 | // | task | distribute | | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2314 | // +------------------+-----------------+------------------------------------+ |
| 2315 | // | ordered | parallel | * | |
| 2316 | // | ordered | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2317 | // | ordered | for simd | + | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2318 | // | ordered | master | * | |
| 2319 | // | ordered | critical | * | |
| 2320 | // | ordered | simd | * | |
| 2321 | // | ordered | sections | + | |
| 2322 | // | ordered | section | + | |
| 2323 | // | ordered | single | + | |
| 2324 | // | ordered | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2325 | // | ordered |parallel for simd| * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2326 | // | ordered |parallel sections| * | |
| 2327 | // | ordered | task | * | |
| 2328 | // | ordered | taskyield | * | |
| 2329 | // | ordered | barrier | + | |
| 2330 | // | ordered | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2331 | // | ordered | taskgroup | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2332 | // | ordered | flush | * | |
| 2333 | // | ordered | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2334 | // | ordered | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2335 | // | ordered | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2336 | // | ordered | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2337 | // | ordered | target parallel | * | |
| 2338 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2339 | // | ordered | target enter | * | |
| 2340 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2341 | // | ordered | target exit | * | |
| 2342 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2343 | // | ordered | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2344 | // | ordered | cancellation | | |
| 2345 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2346 | // | ordered | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2347 | // | ordered | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2348 | // | ordered | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2349 | // | ordered | distribute | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2350 | // +------------------+-----------------+------------------------------------+ |
| 2351 | // | atomic | parallel | | |
| 2352 | // | atomic | for | | |
| 2353 | // | atomic | for simd | | |
| 2354 | // | atomic | master | | |
| 2355 | // | atomic | critical | | |
| 2356 | // | atomic | simd | | |
| 2357 | // | atomic | sections | | |
| 2358 | // | atomic | section | | |
| 2359 | // | atomic | single | | |
| 2360 | // | atomic | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2361 | // | atomic |parallel for simd| | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2362 | // | atomic |parallel sections| | |
| 2363 | // | atomic | task | | |
| 2364 | // | atomic | taskyield | | |
| 2365 | // | atomic | barrier | | |
| 2366 | // | atomic | taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2367 | // | atomic | taskgroup | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2368 | // | atomic | flush | | |
| 2369 | // | atomic | ordered | | |
| 2370 | // | atomic | atomic | | |
| 2371 | // | atomic | target | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2372 | // | atomic | target parallel | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2373 | // | atomic | target parallel | | |
| 2374 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2375 | // | atomic | target enter | | |
| 2376 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2377 | // | atomic | target exit | | |
| 2378 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2379 | // | atomic | teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2380 | // | atomic | cancellation | | |
| 2381 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2382 | // | atomic | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2383 | // | atomic | taskloop | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2384 | // | atomic | taskloop simd | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2385 | // | atomic | distribute | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2386 | // +------------------+-----------------+------------------------------------+ |
| 2387 | // | target | parallel | * | |
| 2388 | // | target | for | * | |
| 2389 | // | target | for simd | * | |
| 2390 | // | target | master | * | |
| 2391 | // | target | critical | * | |
| 2392 | // | target | simd | * | |
| 2393 | // | target | sections | * | |
| 2394 | // | target | section | * | |
| 2395 | // | target | single | * | |
| 2396 | // | target | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2397 | // | target |parallel for simd| * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2398 | // | target |parallel sections| * | |
| 2399 | // | target | task | * | |
| 2400 | // | target | taskyield | * | |
| 2401 | // | target | barrier | * | |
| 2402 | // | target | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2403 | // | target | taskgroup | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2404 | // | target | flush | * | |
| 2405 | // | target | ordered | * | |
| 2406 | // | target | atomic | * | |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2407 | // | target | target | | |
| 2408 | // | target | target parallel | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2409 | // | target | target parallel | | |
| 2410 | // | | for | | |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2411 | // | target | target enter | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2412 | // | | data | | |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2413 | // | target | target exit | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2414 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2415 | // | target | teams | * | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2416 | // | target | cancellation | | |
| 2417 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2418 | // | target | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2419 | // | target | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2420 | // | target | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2421 | // | target | distribute | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2422 | // +------------------+-----------------+------------------------------------+ |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2423 | // | target parallel | parallel | * | |
| 2424 | // | target parallel | for | * | |
| 2425 | // | target parallel | for simd | * | |
| 2426 | // | target parallel | master | * | |
| 2427 | // | target parallel | critical | * | |
| 2428 | // | target parallel | simd | * | |
| 2429 | // | target parallel | sections | * | |
| 2430 | // | target parallel | section | * | |
| 2431 | // | target parallel | single | * | |
| 2432 | // | target parallel | parallel for | * | |
| 2433 | // | target parallel |parallel for simd| * | |
| 2434 | // | target parallel |parallel sections| * | |
| 2435 | // | target parallel | task | * | |
| 2436 | // | target parallel | taskyield | * | |
| 2437 | // | target parallel | barrier | * | |
| 2438 | // | target parallel | taskwait | * | |
| 2439 | // | target parallel | taskgroup | * | |
| 2440 | // | target parallel | flush | * | |
| 2441 | // | target parallel | ordered | * | |
| 2442 | // | target parallel | atomic | * | |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2443 | // | target parallel | target | | |
| 2444 | // | target parallel | target parallel | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2445 | // | target parallel | target parallel | | |
| 2446 | // | | for | | |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2447 | // | target parallel | target enter | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2448 | // | | data | | |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2449 | // | target parallel | target exit | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2450 | // | | data | | |
| 2451 | // | target parallel | teams | | |
| 2452 | // | target parallel | cancellation | | |
| 2453 | // | | point | ! | |
| 2454 | // | target parallel | cancel | ! | |
| 2455 | // | target parallel | taskloop | * | |
| 2456 | // | target parallel | taskloop simd | * | |
| 2457 | // | target parallel | distribute | | |
| 2458 | // +------------------+-----------------+------------------------------------+ |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2459 | // | target parallel | parallel | * | |
| 2460 | // | for | | | |
| 2461 | // | target parallel | for | * | |
| 2462 | // | for | | | |
| 2463 | // | target parallel | for simd | * | |
| 2464 | // | for | | | |
| 2465 | // | target parallel | master | * | |
| 2466 | // | for | | | |
| 2467 | // | target parallel | critical | * | |
| 2468 | // | for | | | |
| 2469 | // | target parallel | simd | * | |
| 2470 | // | for | | | |
| 2471 | // | target parallel | sections | * | |
| 2472 | // | for | | | |
| 2473 | // | target parallel | section | * | |
| 2474 | // | for | | | |
| 2475 | // | target parallel | single | * | |
| 2476 | // | for | | | |
| 2477 | // | target parallel | parallel for | * | |
| 2478 | // | for | | | |
| 2479 | // | target parallel |parallel for simd| * | |
| 2480 | // | for | | | |
| 2481 | // | target parallel |parallel sections| * | |
| 2482 | // | for | | | |
| 2483 | // | target parallel | task | * | |
| 2484 | // | for | | | |
| 2485 | // | target parallel | taskyield | * | |
| 2486 | // | for | | | |
| 2487 | // | target parallel | barrier | * | |
| 2488 | // | for | | | |
| 2489 | // | target parallel | taskwait | * | |
| 2490 | // | for | | | |
| 2491 | // | target parallel | taskgroup | * | |
| 2492 | // | for | | | |
| 2493 | // | target parallel | flush | * | |
| 2494 | // | for | | | |
| 2495 | // | target parallel | ordered | * | |
| 2496 | // | for | | | |
| 2497 | // | target parallel | atomic | * | |
| 2498 | // | for | | | |
| 2499 | // | target parallel | target | | |
| 2500 | // | for | | | |
| 2501 | // | target parallel | target parallel | | |
| 2502 | // | for | | | |
| 2503 | // | target parallel | target parallel | | |
| 2504 | // | for | for | | |
| 2505 | // | target parallel | target enter | | |
| 2506 | // | for | data | | |
| 2507 | // | target parallel | target exit | | |
| 2508 | // | for | data | | |
| 2509 | // | target parallel | teams | | |
| 2510 | // | for | | | |
| 2511 | // | target parallel | cancellation | | |
| 2512 | // | for | point | ! | |
| 2513 | // | target parallel | cancel | ! | |
| 2514 | // | for | | | |
| 2515 | // | target parallel | taskloop | * | |
| 2516 | // | for | | | |
| 2517 | // | target parallel | taskloop simd | * | |
| 2518 | // | for | | | |
| 2519 | // | target parallel | distribute | | |
| 2520 | // | for | | | |
| 2521 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2522 | // | teams | parallel | * | |
| 2523 | // | teams | for | + | |
| 2524 | // | teams | for simd | + | |
| 2525 | // | teams | master | + | |
| 2526 | // | teams | critical | + | |
| 2527 | // | teams | simd | + | |
| 2528 | // | teams | sections | + | |
| 2529 | // | teams | section | + | |
| 2530 | // | teams | single | + | |
| 2531 | // | teams | parallel for | * | |
| 2532 | // | teams |parallel for simd| * | |
| 2533 | // | teams |parallel sections| * | |
| 2534 | // | teams | task | + | |
| 2535 | // | teams | taskyield | + | |
| 2536 | // | teams | barrier | + | |
| 2537 | // | teams | taskwait | + | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2538 | // | teams | taskgroup | + | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2539 | // | teams | flush | + | |
| 2540 | // | teams | ordered | + | |
| 2541 | // | teams | atomic | + | |
| 2542 | // | teams | target | + | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2543 | // | teams | target parallel | + | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2544 | // | teams | target parallel | + | |
| 2545 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2546 | // | teams | target enter | + | |
| 2547 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2548 | // | teams | target exit | + | |
| 2549 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2550 | // | teams | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2551 | // | teams | cancellation | | |
| 2552 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2553 | // | teams | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2554 | // | teams | taskloop | + | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2555 | // | teams | taskloop simd | + | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2556 | // | teams | distribute | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2557 | // +------------------+-----------------+------------------------------------+ |
| 2558 | // | taskloop | parallel | * | |
| 2559 | // | taskloop | for | + | |
| 2560 | // | taskloop | for simd | + | |
| 2561 | // | taskloop | master | + | |
| 2562 | // | taskloop | critical | * | |
| 2563 | // | taskloop | simd | * | |
| 2564 | // | taskloop | sections | + | |
| 2565 | // | taskloop | section | + | |
| 2566 | // | taskloop | single | + | |
| 2567 | // | taskloop | parallel for | * | |
| 2568 | // | taskloop |parallel for simd| * | |
| 2569 | // | taskloop |parallel sections| * | |
| 2570 | // | taskloop | task | * | |
| 2571 | // | taskloop | taskyield | * | |
| 2572 | // | taskloop | barrier | + | |
| 2573 | // | taskloop | taskwait | * | |
| 2574 | // | taskloop | taskgroup | * | |
| 2575 | // | taskloop | flush | * | |
| 2576 | // | taskloop | ordered | + | |
| 2577 | // | taskloop | atomic | * | |
| 2578 | // | taskloop | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2579 | // | taskloop | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2580 | // | taskloop | target parallel | * | |
| 2581 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2582 | // | taskloop | target enter | * | |
| 2583 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2584 | // | taskloop | target exit | * | |
| 2585 | // | | data | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2586 | // | taskloop | teams | + | |
| 2587 | // | taskloop | cancellation | | |
| 2588 | // | | point | | |
| 2589 | // | taskloop | cancel | | |
| 2590 | // | taskloop | taskloop | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2591 | // | taskloop | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2592 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2593 | // | taskloop simd | parallel | | |
| 2594 | // | taskloop simd | for | | |
| 2595 | // | taskloop simd | for simd | | |
| 2596 | // | taskloop simd | master | | |
| 2597 | // | taskloop simd | critical | | |
Alexey Bataev | 1f09221 | 2016-02-02 04:59:52 +0000 | [diff] [blame] | 2598 | // | taskloop simd | simd | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2599 | // | taskloop simd | sections | | |
| 2600 | // | taskloop simd | section | | |
| 2601 | // | taskloop simd | single | | |
| 2602 | // | taskloop simd | parallel for | | |
| 2603 | // | taskloop simd |parallel for simd| | |
| 2604 | // | taskloop simd |parallel sections| | |
| 2605 | // | taskloop simd | task | | |
| 2606 | // | taskloop simd | taskyield | | |
| 2607 | // | taskloop simd | barrier | | |
| 2608 | // | taskloop simd | taskwait | | |
| 2609 | // | taskloop simd | taskgroup | | |
| 2610 | // | taskloop simd | flush | | |
| 2611 | // | taskloop simd | ordered | + (with simd clause) | |
| 2612 | // | taskloop simd | atomic | | |
| 2613 | // | taskloop simd | target | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2614 | // | taskloop simd | target parallel | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2615 | // | taskloop simd | target parallel | | |
| 2616 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2617 | // | taskloop simd | target enter | | |
| 2618 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2619 | // | taskloop simd | target exit | | |
| 2620 | // | | data | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2621 | // | taskloop simd | teams | | |
| 2622 | // | taskloop simd | cancellation | | |
| 2623 | // | | point | | |
| 2624 | // | taskloop simd | cancel | | |
| 2625 | // | taskloop simd | taskloop | | |
| 2626 | // | taskloop simd | taskloop simd | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2627 | // | taskloop simd | distribute | | |
| 2628 | // +------------------+-----------------+------------------------------------+ |
| 2629 | // | distribute | parallel | * | |
| 2630 | // | distribute | for | * | |
| 2631 | // | distribute | for simd | * | |
| 2632 | // | distribute | master | * | |
| 2633 | // | distribute | critical | * | |
| 2634 | // | distribute | simd | * | |
| 2635 | // | distribute | sections | * | |
| 2636 | // | distribute | section | * | |
| 2637 | // | distribute | single | * | |
| 2638 | // | distribute | parallel for | * | |
| 2639 | // | distribute |parallel for simd| * | |
| 2640 | // | distribute |parallel sections| * | |
| 2641 | // | distribute | task | * | |
| 2642 | // | distribute | taskyield | * | |
| 2643 | // | distribute | barrier | * | |
| 2644 | // | distribute | taskwait | * | |
| 2645 | // | distribute | taskgroup | * | |
| 2646 | // | distribute | flush | * | |
| 2647 | // | distribute | ordered | + | |
| 2648 | // | distribute | atomic | * | |
| 2649 | // | distribute | target | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2650 | // | distribute | target parallel | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2651 | // | distribute | target parallel | | |
| 2652 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2653 | // | distribute | target enter | | |
| 2654 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2655 | // | distribute | target exit | | |
| 2656 | // | | data | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2657 | // | distribute | teams | | |
| 2658 | // | distribute | cancellation | + | |
| 2659 | // | | point | | |
| 2660 | // | distribute | cancel | + | |
| 2661 | // | distribute | taskloop | * | |
| 2662 | // | distribute | taskloop simd | * | |
| 2663 | // | distribute | distribute | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2664 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2665 | if (Stack->getCurScope()) { |
| 2666 | auto ParentRegion = Stack->getParentDirective(); |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2667 | auto OffendingRegion = ParentRegion; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2668 | bool NestingProhibited = false; |
| 2669 | bool CloseNesting = true; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2670 | enum { |
| 2671 | NoRecommend, |
| 2672 | ShouldBeInParallelRegion, |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2673 | ShouldBeInOrderedRegion, |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2674 | ShouldBeInTargetRegion, |
| 2675 | ShouldBeInTeamsRegion |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2676 | } Recommend = NoRecommend; |
Alexey Bataev | 1f09221 | 2016-02-02 04:59:52 +0000 | [diff] [blame] | 2677 | if (isOpenMPSimdDirective(ParentRegion) && CurrentRegion != OMPD_ordered && |
| 2678 | CurrentRegion != OMPD_simd) { |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2679 | // OpenMP [2.16, Nesting of Regions] |
| 2680 | // OpenMP constructs may not be nested inside a simd region. |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2681 | // OpenMP [2.8.1,simd Construct, Restrictions] |
| 2682 | // An ordered construct with the simd clause is the only OpenMP construct |
| 2683 | // that can appear in the simd region. |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2684 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region_simd); |
| 2685 | return true; |
| 2686 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2687 | if (ParentRegion == OMPD_atomic) { |
| 2688 | // OpenMP [2.16, Nesting of Regions] |
| 2689 | // OpenMP constructs may not be nested inside an atomic region. |
| 2690 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region_atomic); |
| 2691 | return true; |
| 2692 | } |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2693 | if (CurrentRegion == OMPD_section) { |
| 2694 | // OpenMP [2.7.2, sections Construct, Restrictions] |
| 2695 | // Orphaned section directives are prohibited. That is, the section |
| 2696 | // directives must appear within the sections construct and must not be |
| 2697 | // encountered elsewhere in the sections region. |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2698 | if (ParentRegion != OMPD_sections && |
| 2699 | ParentRegion != OMPD_parallel_sections) { |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2700 | SemaRef.Diag(StartLoc, diag::err_omp_orphaned_section_directive) |
| 2701 | << (ParentRegion != OMPD_unknown) |
| 2702 | << getOpenMPDirectiveName(ParentRegion); |
| 2703 | return true; |
| 2704 | } |
| 2705 | return false; |
| 2706 | } |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2707 | // Allow some constructs to be orphaned (they could be used in functions, |
| 2708 | // called from OpenMP regions with the required preconditions). |
| 2709 | if (ParentRegion == OMPD_unknown) |
| 2710 | return false; |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2711 | if (CurrentRegion == OMPD_cancellation_point || |
| 2712 | CurrentRegion == OMPD_cancel) { |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2713 | // OpenMP [2.16, Nesting of Regions] |
| 2714 | // A cancellation point construct for which construct-type-clause is |
| 2715 | // taskgroup must be nested inside a task construct. A cancellation |
| 2716 | // point construct for which construct-type-clause is not taskgroup must |
| 2717 | // be closely nested inside an OpenMP construct that matches the type |
| 2718 | // specified in construct-type-clause. |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2719 | // A cancel construct for which construct-type-clause is taskgroup must be |
| 2720 | // nested inside a task construct. A cancel construct for which |
| 2721 | // construct-type-clause is not taskgroup must be closely nested inside an |
| 2722 | // OpenMP construct that matches the type specified in |
| 2723 | // construct-type-clause. |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2724 | NestingProhibited = |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2725 | !((CancelRegion == OMPD_parallel && |
| 2726 | (ParentRegion == OMPD_parallel || |
| 2727 | ParentRegion == OMPD_target_parallel)) || |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 2728 | (CancelRegion == OMPD_for && |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2729 | (ParentRegion == OMPD_for || ParentRegion == OMPD_parallel_for || |
| 2730 | ParentRegion == OMPD_target_parallel_for)) || |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2731 | (CancelRegion == OMPD_taskgroup && ParentRegion == OMPD_task) || |
| 2732 | (CancelRegion == OMPD_sections && |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 2733 | (ParentRegion == OMPD_section || ParentRegion == OMPD_sections || |
| 2734 | ParentRegion == OMPD_parallel_sections))); |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2735 | } else if (CurrentRegion == OMPD_master) { |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2736 | // OpenMP [2.16, Nesting of Regions] |
| 2737 | // A master region may not be closely nested inside a worksharing, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2738 | // atomic, or explicit task region. |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2739 | NestingProhibited = isOpenMPWorksharingDirective(ParentRegion) || |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2740 | ParentRegion == OMPD_task || |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2741 | isOpenMPTaskLoopDirective(ParentRegion); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2742 | } else if (CurrentRegion == OMPD_critical && CurrentName.getName()) { |
| 2743 | // OpenMP [2.16, Nesting of Regions] |
| 2744 | // A critical region may not be nested (closely or otherwise) inside a |
| 2745 | // critical region with the same name. Note that this restriction is not |
| 2746 | // sufficient to prevent deadlock. |
| 2747 | SourceLocation PreviousCriticalLoc; |
| 2748 | bool DeadLock = |
| 2749 | Stack->hasDirective([CurrentName, &PreviousCriticalLoc]( |
| 2750 | OpenMPDirectiveKind K, |
| 2751 | const DeclarationNameInfo &DNI, |
| 2752 | SourceLocation Loc) |
| 2753 | ->bool { |
| 2754 | if (K == OMPD_critical && |
| 2755 | DNI.getName() == CurrentName.getName()) { |
| 2756 | PreviousCriticalLoc = Loc; |
| 2757 | return true; |
| 2758 | } else |
| 2759 | return false; |
| 2760 | }, |
| 2761 | false /* skip top directive */); |
| 2762 | if (DeadLock) { |
| 2763 | SemaRef.Diag(StartLoc, |
| 2764 | diag::err_omp_prohibited_region_critical_same_name) |
| 2765 | << CurrentName.getName(); |
| 2766 | if (PreviousCriticalLoc.isValid()) |
| 2767 | SemaRef.Diag(PreviousCriticalLoc, |
| 2768 | diag::note_omp_previous_critical_region); |
| 2769 | return true; |
| 2770 | } |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2771 | } else if (CurrentRegion == OMPD_barrier) { |
| 2772 | // OpenMP [2.16, Nesting of Regions] |
| 2773 | // A barrier region may not be closely nested inside a worksharing, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2774 | // explicit task, critical, ordered, atomic, or master region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2775 | NestingProhibited = |
| 2776 | isOpenMPWorksharingDirective(ParentRegion) || |
| 2777 | ParentRegion == OMPD_task || ParentRegion == OMPD_master || |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2778 | ParentRegion == OMPD_critical || ParentRegion == OMPD_ordered || |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2779 | isOpenMPTaskLoopDirective(ParentRegion); |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2780 | } else if (isOpenMPWorksharingDirective(CurrentRegion) && |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2781 | !isOpenMPParallelDirective(CurrentRegion)) { |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2782 | // OpenMP [2.16, Nesting of Regions] |
| 2783 | // A worksharing region may not be closely nested inside a worksharing, |
| 2784 | // explicit task, critical, ordered, atomic, or master region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2785 | NestingProhibited = |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2786 | isOpenMPWorksharingDirective(ParentRegion) || |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2787 | ParentRegion == OMPD_task || ParentRegion == OMPD_master || |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2788 | ParentRegion == OMPD_critical || ParentRegion == OMPD_ordered || |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2789 | isOpenMPTaskLoopDirective(ParentRegion); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2790 | Recommend = ShouldBeInParallelRegion; |
| 2791 | } else if (CurrentRegion == OMPD_ordered) { |
| 2792 | // OpenMP [2.16, Nesting of Regions] |
| 2793 | // An ordered region may not be closely nested inside a critical, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2794 | // atomic, or explicit task region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2795 | // An ordered region must be closely nested inside a loop region (or |
| 2796 | // parallel loop region) with an ordered clause. |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2797 | // OpenMP [2.8.1,simd Construct, Restrictions] |
| 2798 | // An ordered construct with the simd clause is the only OpenMP construct |
| 2799 | // that can appear in the simd region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2800 | NestingProhibited = ParentRegion == OMPD_critical || |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2801 | ParentRegion == OMPD_task || |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2802 | isOpenMPTaskLoopDirective(ParentRegion) || |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2803 | !(isOpenMPSimdDirective(ParentRegion) || |
| 2804 | Stack->isParentOrderedRegion()); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2805 | Recommend = ShouldBeInOrderedRegion; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2806 | } else if (isOpenMPTeamsDirective(CurrentRegion)) { |
| 2807 | // OpenMP [2.16, Nesting of Regions] |
| 2808 | // If specified, a teams construct must be contained within a target |
| 2809 | // construct. |
| 2810 | NestingProhibited = ParentRegion != OMPD_target; |
| 2811 | Recommend = ShouldBeInTargetRegion; |
| 2812 | Stack->setParentTeamsRegionLoc(Stack->getConstructLoc()); |
| 2813 | } |
| 2814 | if (!NestingProhibited && isOpenMPTeamsDirective(ParentRegion)) { |
| 2815 | // OpenMP [2.16, Nesting of Regions] |
| 2816 | // distribute, parallel, parallel sections, parallel workshare, and the |
| 2817 | // parallel loop and parallel loop SIMD constructs are the only OpenMP |
| 2818 | // constructs that can be closely nested in the teams region. |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2819 | NestingProhibited = !isOpenMPParallelDirective(CurrentRegion) && |
| 2820 | !isOpenMPDistributeDirective(CurrentRegion); |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2821 | Recommend = ShouldBeInParallelRegion; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2822 | } |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2823 | if (!NestingProhibited && isOpenMPDistributeDirective(CurrentRegion)) { |
| 2824 | // OpenMP 4.5 [2.17 Nesting of Regions] |
| 2825 | // The region associated with the distribute construct must be strictly |
| 2826 | // nested inside a teams region |
| 2827 | NestingProhibited = !isOpenMPTeamsDirective(ParentRegion); |
| 2828 | Recommend = ShouldBeInTeamsRegion; |
| 2829 | } |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2830 | if (!NestingProhibited && |
| 2831 | (isOpenMPTargetExecutionDirective(CurrentRegion) || |
| 2832 | isOpenMPTargetDataManagementDirective(CurrentRegion))) { |
| 2833 | // OpenMP 4.5 [2.17 Nesting of Regions] |
| 2834 | // If a target, target update, target data, target enter data, or |
| 2835 | // target exit data construct is encountered during execution of a |
| 2836 | // target region, the behavior is unspecified. |
| 2837 | NestingProhibited = Stack->hasDirective( |
| 2838 | [&OffendingRegion](OpenMPDirectiveKind K, |
| 2839 | const DeclarationNameInfo &DNI, |
| 2840 | SourceLocation Loc) -> bool { |
| 2841 | if (isOpenMPTargetExecutionDirective(K)) { |
| 2842 | OffendingRegion = K; |
| 2843 | return true; |
| 2844 | } else |
| 2845 | return false; |
| 2846 | }, |
| 2847 | false /* don't skip top directive */); |
| 2848 | CloseNesting = false; |
| 2849 | } |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2850 | if (NestingProhibited) { |
| 2851 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region) |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2852 | << CloseNesting << getOpenMPDirectiveName(OffendingRegion) |
| 2853 | << Recommend << getOpenMPDirectiveName(CurrentRegion); |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2854 | return true; |
| 2855 | } |
| 2856 | } |
| 2857 | return false; |
| 2858 | } |
| 2859 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2860 | static bool checkIfClauses(Sema &S, OpenMPDirectiveKind Kind, |
| 2861 | ArrayRef<OMPClause *> Clauses, |
| 2862 | ArrayRef<OpenMPDirectiveKind> AllowedNameModifiers) { |
| 2863 | bool ErrorFound = false; |
| 2864 | unsigned NamedModifiersNumber = 0; |
| 2865 | SmallVector<const OMPIfClause *, OMPC_unknown + 1> FoundNameModifiers( |
| 2866 | OMPD_unknown + 1); |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2867 | SmallVector<SourceLocation, 4> NameModifierLoc; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2868 | for (const auto *C : Clauses) { |
| 2869 | if (const auto *IC = dyn_cast_or_null<OMPIfClause>(C)) { |
| 2870 | // At most one if clause without a directive-name-modifier can appear on |
| 2871 | // the directive. |
| 2872 | OpenMPDirectiveKind CurNM = IC->getNameModifier(); |
| 2873 | if (FoundNameModifiers[CurNM]) { |
| 2874 | S.Diag(C->getLocStart(), diag::err_omp_more_one_clause) |
| 2875 | << getOpenMPDirectiveName(Kind) << getOpenMPClauseName(OMPC_if) |
| 2876 | << (CurNM != OMPD_unknown) << getOpenMPDirectiveName(CurNM); |
| 2877 | ErrorFound = true; |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2878 | } else if (CurNM != OMPD_unknown) { |
| 2879 | NameModifierLoc.push_back(IC->getNameModifierLoc()); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2880 | ++NamedModifiersNumber; |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2881 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2882 | FoundNameModifiers[CurNM] = IC; |
| 2883 | if (CurNM == OMPD_unknown) |
| 2884 | continue; |
| 2885 | // Check if the specified name modifier is allowed for the current |
| 2886 | // directive. |
| 2887 | // At most one if clause with the particular directive-name-modifier can |
| 2888 | // appear on the directive. |
| 2889 | bool MatchFound = false; |
| 2890 | for (auto NM : AllowedNameModifiers) { |
| 2891 | if (CurNM == NM) { |
| 2892 | MatchFound = true; |
| 2893 | break; |
| 2894 | } |
| 2895 | } |
| 2896 | if (!MatchFound) { |
| 2897 | S.Diag(IC->getNameModifierLoc(), |
| 2898 | diag::err_omp_wrong_if_directive_name_modifier) |
| 2899 | << getOpenMPDirectiveName(CurNM) << getOpenMPDirectiveName(Kind); |
| 2900 | ErrorFound = true; |
| 2901 | } |
| 2902 | } |
| 2903 | } |
| 2904 | // If any if clause on the directive includes a directive-name-modifier then |
| 2905 | // all if clauses on the directive must include a directive-name-modifier. |
| 2906 | if (FoundNameModifiers[OMPD_unknown] && NamedModifiersNumber > 0) { |
| 2907 | if (NamedModifiersNumber == AllowedNameModifiers.size()) { |
| 2908 | S.Diag(FoundNameModifiers[OMPD_unknown]->getLocStart(), |
| 2909 | diag::err_omp_no_more_if_clause); |
| 2910 | } else { |
| 2911 | std::string Values; |
| 2912 | std::string Sep(", "); |
| 2913 | unsigned AllowedCnt = 0; |
| 2914 | unsigned TotalAllowedNum = |
| 2915 | AllowedNameModifiers.size() - NamedModifiersNumber; |
| 2916 | for (unsigned Cnt = 0, End = AllowedNameModifiers.size(); Cnt < End; |
| 2917 | ++Cnt) { |
| 2918 | OpenMPDirectiveKind NM = AllowedNameModifiers[Cnt]; |
| 2919 | if (!FoundNameModifiers[NM]) { |
| 2920 | Values += "'"; |
| 2921 | Values += getOpenMPDirectiveName(NM); |
| 2922 | Values += "'"; |
| 2923 | if (AllowedCnt + 2 == TotalAllowedNum) |
| 2924 | Values += " or "; |
| 2925 | else if (AllowedCnt + 1 != TotalAllowedNum) |
| 2926 | Values += Sep; |
| 2927 | ++AllowedCnt; |
| 2928 | } |
| 2929 | } |
| 2930 | S.Diag(FoundNameModifiers[OMPD_unknown]->getCondition()->getLocStart(), |
| 2931 | diag::err_omp_unnamed_if_clause) |
| 2932 | << (TotalAllowedNum > 1) << Values; |
| 2933 | } |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2934 | for (auto Loc : NameModifierLoc) { |
| 2935 | S.Diag(Loc, diag::note_omp_previous_named_if_clause); |
| 2936 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2937 | ErrorFound = true; |
| 2938 | } |
| 2939 | return ErrorFound; |
| 2940 | } |
| 2941 | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2942 | StmtResult Sema::ActOnOpenMPExecutableDirective( |
| 2943 | OpenMPDirectiveKind Kind, const DeclarationNameInfo &DirName, |
| 2944 | OpenMPDirectiveKind CancelRegion, ArrayRef<OMPClause *> Clauses, |
| 2945 | Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2946 | StmtResult Res = StmtError(); |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2947 | if (CheckNestingOfRegions(*this, DSAStack, Kind, DirName, CancelRegion, |
| 2948 | StartLoc)) |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2949 | return StmtError(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2950 | |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2951 | llvm::SmallVector<OMPClause *, 8> ClausesWithImplicit; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 2952 | llvm::DenseMap<ValueDecl *, Expr *> VarsWithInheritedDSA; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2953 | bool ErrorFound = false; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2954 | ClausesWithImplicit.append(Clauses.begin(), Clauses.end()); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2955 | if (AStmt) { |
| 2956 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 2957 | |
| 2958 | // Check default data sharing attributes for referenced variables. |
| 2959 | DSAAttrChecker DSAChecker(DSAStack, *this, cast<CapturedStmt>(AStmt)); |
| 2960 | DSAChecker.Visit(cast<CapturedStmt>(AStmt)->getCapturedStmt()); |
| 2961 | if (DSAChecker.isErrorFound()) |
| 2962 | return StmtError(); |
| 2963 | // Generate list of implicitly defined firstprivate variables. |
| 2964 | VarsWithInheritedDSA = DSAChecker.getVarsWithInheritedDSA(); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2965 | |
| 2966 | if (!DSAChecker.getImplicitFirstprivate().empty()) { |
| 2967 | if (OMPClause *Implicit = ActOnOpenMPFirstprivateClause( |
| 2968 | DSAChecker.getImplicitFirstprivate(), SourceLocation(), |
| 2969 | SourceLocation(), SourceLocation())) { |
| 2970 | ClausesWithImplicit.push_back(Implicit); |
| 2971 | ErrorFound = cast<OMPFirstprivateClause>(Implicit)->varlist_size() != |
| 2972 | DSAChecker.getImplicitFirstprivate().size(); |
| 2973 | } else |
| 2974 | ErrorFound = true; |
| 2975 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2976 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2977 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2978 | llvm::SmallVector<OpenMPDirectiveKind, 4> AllowedNameModifiers; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2979 | switch (Kind) { |
| 2980 | case OMPD_parallel: |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2981 | Res = ActOnOpenMPParallelDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2982 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2983 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2984 | break; |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 2985 | case OMPD_simd: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2986 | Res = ActOnOpenMPSimdDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc, |
| 2987 | VarsWithInheritedDSA); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 2988 | break; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2989 | case OMPD_for: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2990 | Res = ActOnOpenMPForDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc, |
| 2991 | VarsWithInheritedDSA); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2992 | break; |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2993 | case OMPD_for_simd: |
| 2994 | Res = ActOnOpenMPForSimdDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2995 | EndLoc, VarsWithInheritedDSA); |
| 2996 | break; |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 2997 | case OMPD_sections: |
| 2998 | Res = ActOnOpenMPSectionsDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2999 | EndLoc); |
| 3000 | break; |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 3001 | case OMPD_section: |
| 3002 | assert(ClausesWithImplicit.empty() && |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 3003 | "No clauses are allowed for 'omp section' directive"); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 3004 | Res = ActOnOpenMPSectionDirective(AStmt, StartLoc, EndLoc); |
| 3005 | break; |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 3006 | case OMPD_single: |
| 3007 | Res = ActOnOpenMPSingleDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3008 | EndLoc); |
| 3009 | break; |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 3010 | case OMPD_master: |
| 3011 | assert(ClausesWithImplicit.empty() && |
| 3012 | "No clauses are allowed for 'omp master' directive"); |
| 3013 | Res = ActOnOpenMPMasterDirective(AStmt, StartLoc, EndLoc); |
| 3014 | break; |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 3015 | case OMPD_critical: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 3016 | Res = ActOnOpenMPCriticalDirective(DirName, ClausesWithImplicit, AStmt, |
| 3017 | StartLoc, EndLoc); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 3018 | break; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3019 | case OMPD_parallel_for: |
| 3020 | Res = ActOnOpenMPParallelForDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3021 | EndLoc, VarsWithInheritedDSA); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3022 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3023 | break; |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 3024 | case OMPD_parallel_for_simd: |
| 3025 | Res = ActOnOpenMPParallelForSimdDirective( |
| 3026 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3027 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 3028 | break; |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 3029 | case OMPD_parallel_sections: |
| 3030 | Res = ActOnOpenMPParallelSectionsDirective(ClausesWithImplicit, AStmt, |
| 3031 | StartLoc, EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3032 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 3033 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3034 | case OMPD_task: |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 3035 | Res = |
| 3036 | ActOnOpenMPTaskDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3037 | AllowedNameModifiers.push_back(OMPD_task); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 3038 | break; |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 3039 | case OMPD_taskyield: |
| 3040 | assert(ClausesWithImplicit.empty() && |
| 3041 | "No clauses are allowed for 'omp taskyield' directive"); |
| 3042 | assert(AStmt == nullptr && |
| 3043 | "No associated statement allowed for 'omp taskyield' directive"); |
| 3044 | Res = ActOnOpenMPTaskyieldDirective(StartLoc, EndLoc); |
| 3045 | break; |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 3046 | case OMPD_barrier: |
| 3047 | assert(ClausesWithImplicit.empty() && |
| 3048 | "No clauses are allowed for 'omp barrier' directive"); |
| 3049 | assert(AStmt == nullptr && |
| 3050 | "No associated statement allowed for 'omp barrier' directive"); |
| 3051 | Res = ActOnOpenMPBarrierDirective(StartLoc, EndLoc); |
| 3052 | break; |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 3053 | case OMPD_taskwait: |
| 3054 | assert(ClausesWithImplicit.empty() && |
| 3055 | "No clauses are allowed for 'omp taskwait' directive"); |
| 3056 | assert(AStmt == nullptr && |
| 3057 | "No associated statement allowed for 'omp taskwait' directive"); |
| 3058 | Res = ActOnOpenMPTaskwaitDirective(StartLoc, EndLoc); |
| 3059 | break; |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 3060 | case OMPD_taskgroup: |
| 3061 | assert(ClausesWithImplicit.empty() && |
| 3062 | "No clauses are allowed for 'omp taskgroup' directive"); |
| 3063 | Res = ActOnOpenMPTaskgroupDirective(AStmt, StartLoc, EndLoc); |
| 3064 | break; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 3065 | case OMPD_flush: |
| 3066 | assert(AStmt == nullptr && |
| 3067 | "No associated statement allowed for 'omp flush' directive"); |
| 3068 | Res = ActOnOpenMPFlushDirective(ClausesWithImplicit, StartLoc, EndLoc); |
| 3069 | break; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 3070 | case OMPD_ordered: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 3071 | Res = ActOnOpenMPOrderedDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3072 | EndLoc); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 3073 | break; |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 3074 | case OMPD_atomic: |
| 3075 | Res = ActOnOpenMPAtomicDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3076 | EndLoc); |
| 3077 | break; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 3078 | case OMPD_teams: |
| 3079 | Res = |
| 3080 | ActOnOpenMPTeamsDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); |
| 3081 | break; |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 3082 | case OMPD_target: |
| 3083 | Res = ActOnOpenMPTargetDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3084 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3085 | AllowedNameModifiers.push_back(OMPD_target); |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 3086 | break; |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 3087 | case OMPD_target_parallel: |
| 3088 | Res = ActOnOpenMPTargetParallelDirective(ClausesWithImplicit, AStmt, |
| 3089 | StartLoc, EndLoc); |
| 3090 | AllowedNameModifiers.push_back(OMPD_target); |
| 3091 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 3092 | break; |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 3093 | case OMPD_target_parallel_for: |
| 3094 | Res = ActOnOpenMPTargetParallelForDirective( |
| 3095 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 3096 | AllowedNameModifiers.push_back(OMPD_target); |
| 3097 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 3098 | break; |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 3099 | case OMPD_cancellation_point: |
| 3100 | assert(ClausesWithImplicit.empty() && |
| 3101 | "No clauses are allowed for 'omp cancellation point' directive"); |
| 3102 | assert(AStmt == nullptr && "No associated statement allowed for 'omp " |
| 3103 | "cancellation point' directive"); |
| 3104 | Res = ActOnOpenMPCancellationPointDirective(StartLoc, EndLoc, CancelRegion); |
| 3105 | break; |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 3106 | case OMPD_cancel: |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 3107 | assert(AStmt == nullptr && |
| 3108 | "No associated statement allowed for 'omp cancel' directive"); |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 3109 | Res = ActOnOpenMPCancelDirective(ClausesWithImplicit, StartLoc, EndLoc, |
| 3110 | CancelRegion); |
| 3111 | AllowedNameModifiers.push_back(OMPD_cancel); |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 3112 | break; |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 3113 | case OMPD_target_data: |
| 3114 | Res = ActOnOpenMPTargetDataDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3115 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3116 | AllowedNameModifiers.push_back(OMPD_target_data); |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 3117 | break; |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 3118 | case OMPD_target_enter_data: |
| 3119 | Res = ActOnOpenMPTargetEnterDataDirective(ClausesWithImplicit, StartLoc, |
| 3120 | EndLoc); |
| 3121 | AllowedNameModifiers.push_back(OMPD_target_enter_data); |
| 3122 | break; |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 3123 | case OMPD_target_exit_data: |
| 3124 | Res = ActOnOpenMPTargetExitDataDirective(ClausesWithImplicit, StartLoc, |
| 3125 | EndLoc); |
| 3126 | AllowedNameModifiers.push_back(OMPD_target_exit_data); |
| 3127 | break; |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 3128 | case OMPD_taskloop: |
| 3129 | Res = ActOnOpenMPTaskLoopDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3130 | EndLoc, VarsWithInheritedDSA); |
| 3131 | AllowedNameModifiers.push_back(OMPD_taskloop); |
| 3132 | break; |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 3133 | case OMPD_taskloop_simd: |
| 3134 | Res = ActOnOpenMPTaskLoopSimdDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3135 | EndLoc, VarsWithInheritedDSA); |
| 3136 | AllowedNameModifiers.push_back(OMPD_taskloop); |
| 3137 | break; |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 3138 | case OMPD_distribute: |
| 3139 | Res = ActOnOpenMPDistributeDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3140 | EndLoc, VarsWithInheritedDSA); |
| 3141 | break; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 3142 | case OMPD_threadprivate: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3143 | llvm_unreachable("OpenMP Directive is not allowed"); |
| 3144 | case OMPD_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3145 | llvm_unreachable("Unknown OpenMP directive"); |
| 3146 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 3147 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3148 | for (auto P : VarsWithInheritedDSA) { |
| 3149 | Diag(P.second->getExprLoc(), diag::err_omp_no_dsa_for_variable) |
| 3150 | << P.first << P.second->getSourceRange(); |
| 3151 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3152 | ErrorFound = !VarsWithInheritedDSA.empty() || ErrorFound; |
| 3153 | |
| 3154 | if (!AllowedNameModifiers.empty()) |
| 3155 | ErrorFound = checkIfClauses(*this, Kind, Clauses, AllowedNameModifiers) || |
| 3156 | ErrorFound; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3157 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 3158 | if (ErrorFound) |
| 3159 | return StmtError(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3160 | return Res; |
| 3161 | } |
| 3162 | |
| 3163 | StmtResult Sema::ActOnOpenMPParallelDirective(ArrayRef<OMPClause *> Clauses, |
| 3164 | Stmt *AStmt, |
| 3165 | SourceLocation StartLoc, |
| 3166 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3167 | if (!AStmt) |
| 3168 | return StmtError(); |
| 3169 | |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 3170 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 3171 | // 1.2.2 OpenMP Language Terminology |
| 3172 | // Structured block - An executable statement with a single entry at the |
| 3173 | // top and a single exit at the bottom. |
| 3174 | // The point of exit cannot be a branch out of the structured block. |
| 3175 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 3176 | CS->getCapturedDecl()->setNothrow(); |
| 3177 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3178 | getCurFunction()->setHasBranchProtectedScope(); |
| 3179 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 3180 | return OMPParallelDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 3181 | DSAStack->isCancelRegion()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3182 | } |
| 3183 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3184 | namespace { |
| 3185 | /// \brief Helper class for checking canonical form of the OpenMP loops and |
| 3186 | /// extracting iteration space of each loop in the loop nest, that will be used |
| 3187 | /// for IR generation. |
| 3188 | class OpenMPIterationSpaceChecker { |
| 3189 | /// \brief Reference to Sema. |
| 3190 | Sema &SemaRef; |
| 3191 | /// \brief A location for diagnostics (when there is no some better location). |
| 3192 | SourceLocation DefaultLoc; |
| 3193 | /// \brief A location for diagnostics (when increment is not compatible). |
| 3194 | SourceLocation ConditionLoc; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3195 | /// \brief A source location for referring to loop init later. |
| 3196 | SourceRange InitSrcRange; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3197 | /// \brief A source location for referring to condition later. |
| 3198 | SourceRange ConditionSrcRange; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3199 | /// \brief A source location for referring to increment later. |
| 3200 | SourceRange IncrementSrcRange; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3201 | /// \brief Loop variable. |
| 3202 | VarDecl *Var; |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3203 | /// \brief Reference to loop variable. |
| 3204 | DeclRefExpr *VarRef; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3205 | /// \brief Lower bound (initializer for the var). |
| 3206 | Expr *LB; |
| 3207 | /// \brief Upper bound. |
| 3208 | Expr *UB; |
| 3209 | /// \brief Loop step (increment). |
| 3210 | Expr *Step; |
| 3211 | /// \brief This flag is true when condition is one of: |
| 3212 | /// Var < UB |
| 3213 | /// Var <= UB |
| 3214 | /// UB > Var |
| 3215 | /// UB >= Var |
| 3216 | bool TestIsLessOp; |
| 3217 | /// \brief This flag is true when condition is strict ( < or > ). |
| 3218 | bool TestIsStrictOp; |
| 3219 | /// \brief This flag is true when step is subtracted on each iteration. |
| 3220 | bool SubtractStep; |
| 3221 | |
| 3222 | public: |
| 3223 | OpenMPIterationSpaceChecker(Sema &SemaRef, SourceLocation DefaultLoc) |
| 3224 | : SemaRef(SemaRef), DefaultLoc(DefaultLoc), ConditionLoc(DefaultLoc), |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3225 | InitSrcRange(SourceRange()), ConditionSrcRange(SourceRange()), |
| 3226 | IncrementSrcRange(SourceRange()), Var(nullptr), VarRef(nullptr), |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3227 | LB(nullptr), UB(nullptr), Step(nullptr), TestIsLessOp(false), |
| 3228 | TestIsStrictOp(false), SubtractStep(false) {} |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3229 | /// \brief Check init-expr for canonical loop form and save loop counter |
| 3230 | /// variable - #Var and its initialization value - #LB. |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3231 | bool CheckInit(Stmt *S, bool EmitDiags = true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3232 | /// \brief Check test-expr for canonical form, save upper-bound (#UB), flags |
| 3233 | /// for less/greater and for strict/non-strict comparison. |
| 3234 | bool CheckCond(Expr *S); |
| 3235 | /// \brief Check incr-expr for canonical loop form and return true if it |
| 3236 | /// does not conform, otherwise save loop step (#Step). |
| 3237 | bool CheckInc(Expr *S); |
| 3238 | /// \brief Return the loop counter variable. |
| 3239 | VarDecl *GetLoopVar() const { return Var; } |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3240 | /// \brief Return the reference expression to loop counter variable. |
| 3241 | DeclRefExpr *GetLoopVarRefExpr() const { return VarRef; } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3242 | /// \brief Source range of the loop init. |
| 3243 | SourceRange GetInitSrcRange() const { return InitSrcRange; } |
| 3244 | /// \brief Source range of the loop condition. |
| 3245 | SourceRange GetConditionSrcRange() const { return ConditionSrcRange; } |
| 3246 | /// \brief Source range of the loop increment. |
| 3247 | SourceRange GetIncrementSrcRange() const { return IncrementSrcRange; } |
| 3248 | /// \brief True if the step should be subtracted. |
| 3249 | bool ShouldSubtractStep() const { return SubtractStep; } |
| 3250 | /// \brief Build the expression to calculate the number of iterations. |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3251 | Expr *BuildNumIterations(Scope *S, const bool LimitedType) const; |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3252 | /// \brief Build the precondition expression for the loops. |
| 3253 | Expr *BuildPreCond(Scope *S, Expr *Cond) const; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3254 | /// \brief Build reference expression to the counter be used for codegen. |
| 3255 | Expr *BuildCounterVar() const; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3256 | /// \brief Build reference expression to the private counter be used for |
| 3257 | /// codegen. |
| 3258 | Expr *BuildPrivateCounterVar() const; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3259 | /// \brief Build initization of the counter be used for codegen. |
| 3260 | Expr *BuildCounterInit() const; |
| 3261 | /// \brief Build step of the counter be used for codegen. |
| 3262 | Expr *BuildCounterStep() const; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3263 | /// \brief Return true if any expression is dependent. |
| 3264 | bool Dependent() const; |
| 3265 | |
| 3266 | private: |
| 3267 | /// \brief Check the right-hand side of an assignment in the increment |
| 3268 | /// expression. |
| 3269 | bool CheckIncRHS(Expr *RHS); |
| 3270 | /// \brief Helper to set loop counter variable and its initializer. |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3271 | bool SetVarAndLB(VarDecl *NewVar, DeclRefExpr *NewVarRefExpr, Expr *NewLB); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3272 | /// \brief Helper to set upper bound. |
Craig Topper | e335f25 | 2015-10-04 04:53:55 +0000 | [diff] [blame] | 3273 | bool SetUB(Expr *NewUB, bool LessOp, bool StrictOp, SourceRange SR, |
Craig Topper | 9cd5e4f | 2015-09-21 01:23:32 +0000 | [diff] [blame] | 3274 | SourceLocation SL); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3275 | /// \brief Helper to set loop increment. |
| 3276 | bool SetStep(Expr *NewStep, bool Subtract); |
| 3277 | }; |
| 3278 | |
| 3279 | bool OpenMPIterationSpaceChecker::Dependent() const { |
| 3280 | if (!Var) { |
| 3281 | assert(!LB && !UB && !Step); |
| 3282 | return false; |
| 3283 | } |
| 3284 | return Var->getType()->isDependentType() || (LB && LB->isValueDependent()) || |
| 3285 | (UB && UB->isValueDependent()) || (Step && Step->isValueDependent()); |
| 3286 | } |
| 3287 | |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3288 | template <typename T> |
| 3289 | static T *getExprAsWritten(T *E) { |
| 3290 | if (auto *ExprTemp = dyn_cast<ExprWithCleanups>(E)) |
| 3291 | E = ExprTemp->getSubExpr(); |
| 3292 | |
| 3293 | if (auto *MTE = dyn_cast<MaterializeTemporaryExpr>(E)) |
| 3294 | E = MTE->GetTemporaryExpr(); |
| 3295 | |
| 3296 | while (auto *Binder = dyn_cast<CXXBindTemporaryExpr>(E)) |
| 3297 | E = Binder->getSubExpr(); |
| 3298 | |
| 3299 | if (auto *ICE = dyn_cast<ImplicitCastExpr>(E)) |
| 3300 | E = ICE->getSubExprAsWritten(); |
| 3301 | return E->IgnoreParens(); |
| 3302 | } |
| 3303 | |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3304 | bool OpenMPIterationSpaceChecker::SetVarAndLB(VarDecl *NewVar, |
| 3305 | DeclRefExpr *NewVarRefExpr, |
| 3306 | Expr *NewLB) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3307 | // State consistency checking to ensure correct usage. |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3308 | assert(Var == nullptr && LB == nullptr && VarRef == nullptr && |
| 3309 | UB == nullptr && Step == nullptr && !TestIsLessOp && !TestIsStrictOp); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3310 | if (!NewVar || !NewLB) |
| 3311 | return true; |
| 3312 | Var = NewVar; |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3313 | VarRef = NewVarRefExpr; |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3314 | if (auto *CE = dyn_cast_or_null<CXXConstructExpr>(NewLB)) |
| 3315 | if (const CXXConstructorDecl *Ctor = CE->getConstructor()) |
Alexey Bataev | 0d08a7f | 2015-07-16 04:19:43 +0000 | [diff] [blame] | 3316 | if ((Ctor->isCopyOrMoveConstructor() || |
| 3317 | Ctor->isConvertingConstructor(/*AllowExplicit=*/false)) && |
| 3318 | CE->getNumArgs() > 0 && CE->getArg(0) != nullptr) |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3319 | NewLB = CE->getArg(0)->IgnoreParenImpCasts(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3320 | LB = NewLB; |
| 3321 | return false; |
| 3322 | } |
| 3323 | |
| 3324 | bool OpenMPIterationSpaceChecker::SetUB(Expr *NewUB, bool LessOp, bool StrictOp, |
Craig Topper | e335f25 | 2015-10-04 04:53:55 +0000 | [diff] [blame] | 3325 | SourceRange SR, SourceLocation SL) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3326 | // State consistency checking to ensure correct usage. |
| 3327 | assert(Var != nullptr && LB != nullptr && UB == nullptr && Step == nullptr && |
| 3328 | !TestIsLessOp && !TestIsStrictOp); |
| 3329 | if (!NewUB) |
| 3330 | return true; |
| 3331 | UB = NewUB; |
| 3332 | TestIsLessOp = LessOp; |
| 3333 | TestIsStrictOp = StrictOp; |
| 3334 | ConditionSrcRange = SR; |
| 3335 | ConditionLoc = SL; |
| 3336 | return false; |
| 3337 | } |
| 3338 | |
| 3339 | bool OpenMPIterationSpaceChecker::SetStep(Expr *NewStep, bool Subtract) { |
| 3340 | // State consistency checking to ensure correct usage. |
| 3341 | assert(Var != nullptr && LB != nullptr && Step == nullptr); |
| 3342 | if (!NewStep) |
| 3343 | return true; |
| 3344 | if (!NewStep->isValueDependent()) { |
| 3345 | // Check that the step is integer expression. |
| 3346 | SourceLocation StepLoc = NewStep->getLocStart(); |
| 3347 | ExprResult Val = |
| 3348 | SemaRef.PerformOpenMPImplicitIntegerConversion(StepLoc, NewStep); |
| 3349 | if (Val.isInvalid()) |
| 3350 | return true; |
| 3351 | NewStep = Val.get(); |
| 3352 | |
| 3353 | // OpenMP [2.6, Canonical Loop Form, Restrictions] |
| 3354 | // If test-expr is of form var relational-op b and relational-op is < or |
| 3355 | // <= then incr-expr must cause var to increase on each iteration of the |
| 3356 | // loop. If test-expr is of form var relational-op b and relational-op is |
| 3357 | // > or >= then incr-expr must cause var to decrease on each iteration of |
| 3358 | // the loop. |
| 3359 | // If test-expr is of form b relational-op var and relational-op is < or |
| 3360 | // <= then incr-expr must cause var to decrease on each iteration of the |
| 3361 | // loop. If test-expr is of form b relational-op var and relational-op is |
| 3362 | // > or >= then incr-expr must cause var to increase on each iteration of |
| 3363 | // the loop. |
| 3364 | llvm::APSInt Result; |
| 3365 | bool IsConstant = NewStep->isIntegerConstantExpr(Result, SemaRef.Context); |
| 3366 | bool IsUnsigned = !NewStep->getType()->hasSignedIntegerRepresentation(); |
| 3367 | bool IsConstNeg = |
| 3368 | IsConstant && Result.isSigned() && (Subtract != Result.isNegative()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3369 | bool IsConstPos = |
| 3370 | IsConstant && Result.isSigned() && (Subtract == Result.isNegative()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3371 | bool IsConstZero = IsConstant && !Result.getBoolValue(); |
| 3372 | if (UB && (IsConstZero || |
| 3373 | (TestIsLessOp ? (IsConstNeg || (IsUnsigned && Subtract)) |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3374 | : (IsConstPos || (IsUnsigned && !Subtract))))) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3375 | SemaRef.Diag(NewStep->getExprLoc(), |
| 3376 | diag::err_omp_loop_incr_not_compatible) |
| 3377 | << Var << TestIsLessOp << NewStep->getSourceRange(); |
| 3378 | SemaRef.Diag(ConditionLoc, |
| 3379 | diag::note_omp_loop_cond_requres_compatible_incr) |
| 3380 | << TestIsLessOp << ConditionSrcRange; |
| 3381 | return true; |
| 3382 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3383 | if (TestIsLessOp == Subtract) { |
| 3384 | NewStep = SemaRef.CreateBuiltinUnaryOp(NewStep->getExprLoc(), UO_Minus, |
| 3385 | NewStep).get(); |
| 3386 | Subtract = !Subtract; |
| 3387 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3388 | } |
| 3389 | |
| 3390 | Step = NewStep; |
| 3391 | SubtractStep = Subtract; |
| 3392 | return false; |
| 3393 | } |
| 3394 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3395 | bool OpenMPIterationSpaceChecker::CheckInit(Stmt *S, bool EmitDiags) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3396 | // Check init-expr for canonical loop form and save loop counter |
| 3397 | // variable - #Var and its initialization value - #LB. |
| 3398 | // OpenMP [2.6] Canonical loop form. init-expr may be one of the following: |
| 3399 | // var = lb |
| 3400 | // integer-type var = lb |
| 3401 | // random-access-iterator-type var = lb |
| 3402 | // pointer-type var = lb |
| 3403 | // |
| 3404 | if (!S) { |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3405 | if (EmitDiags) { |
| 3406 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_init); |
| 3407 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3408 | return true; |
| 3409 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3410 | InitSrcRange = S->getSourceRange(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3411 | if (Expr *E = dyn_cast<Expr>(S)) |
| 3412 | S = E->IgnoreParens(); |
| 3413 | if (auto BO = dyn_cast<BinaryOperator>(S)) { |
| 3414 | if (BO->getOpcode() == BO_Assign) |
| 3415 | if (auto DRE = dyn_cast<DeclRefExpr>(BO->getLHS()->IgnoreParens())) |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3416 | return SetVarAndLB(dyn_cast<VarDecl>(DRE->getDecl()), DRE, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3417 | BO->getRHS()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3418 | } else if (auto DS = dyn_cast<DeclStmt>(S)) { |
| 3419 | if (DS->isSingleDecl()) { |
| 3420 | if (auto Var = dyn_cast_or_null<VarDecl>(DS->getSingleDecl())) { |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3421 | if (Var->hasInit() && !Var->getType()->isReferenceType()) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3422 | // Accept non-canonical init form here but emit ext. warning. |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3423 | if (Var->getInitStyle() != VarDecl::CInit && EmitDiags) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3424 | SemaRef.Diag(S->getLocStart(), |
| 3425 | diag::ext_omp_loop_not_canonical_init) |
| 3426 | << S->getSourceRange(); |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3427 | return SetVarAndLB(Var, nullptr, Var->getInit()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3428 | } |
| 3429 | } |
| 3430 | } |
| 3431 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) |
| 3432 | if (CE->getOperator() == OO_Equal) |
| 3433 | if (auto DRE = dyn_cast<DeclRefExpr>(CE->getArg(0))) |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3434 | return SetVarAndLB(dyn_cast<VarDecl>(DRE->getDecl()), DRE, |
| 3435 | CE->getArg(1)); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3436 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3437 | if (EmitDiags) { |
| 3438 | SemaRef.Diag(S->getLocStart(), diag::err_omp_loop_not_canonical_init) |
| 3439 | << S->getSourceRange(); |
| 3440 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3441 | return true; |
| 3442 | } |
| 3443 | |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 3444 | /// \brief Ignore parenthesizes, implicit casts, copy constructor and return the |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3445 | /// variable (which may be the loop variable) if possible. |
| 3446 | static const VarDecl *GetInitVarDecl(const Expr *E) { |
| 3447 | if (!E) |
Craig Topper | 4b56692 | 2014-06-09 02:04:02 +0000 | [diff] [blame] | 3448 | return nullptr; |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3449 | E = getExprAsWritten(E); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3450 | if (auto *CE = dyn_cast_or_null<CXXConstructExpr>(E)) |
| 3451 | if (const CXXConstructorDecl *Ctor = CE->getConstructor()) |
Alexey Bataev | 0d08a7f | 2015-07-16 04:19:43 +0000 | [diff] [blame] | 3452 | if ((Ctor->isCopyOrMoveConstructor() || |
| 3453 | Ctor->isConvertingConstructor(/*AllowExplicit=*/false)) && |
| 3454 | CE->getNumArgs() > 0 && CE->getArg(0) != nullptr) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3455 | E = CE->getArg(0)->IgnoreParenImpCasts(); |
| 3456 | auto DRE = dyn_cast_or_null<DeclRefExpr>(E); |
| 3457 | if (!DRE) |
| 3458 | return nullptr; |
| 3459 | return dyn_cast<VarDecl>(DRE->getDecl()); |
| 3460 | } |
| 3461 | |
| 3462 | bool OpenMPIterationSpaceChecker::CheckCond(Expr *S) { |
| 3463 | // Check test-expr for canonical form, save upper-bound UB, flags for |
| 3464 | // less/greater and for strict/non-strict comparison. |
| 3465 | // OpenMP [2.6] Canonical loop form. Test-expr may be one of the following: |
| 3466 | // var relational-op b |
| 3467 | // b relational-op var |
| 3468 | // |
| 3469 | if (!S) { |
| 3470 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_cond) << Var; |
| 3471 | return true; |
| 3472 | } |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3473 | S = getExprAsWritten(S); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3474 | SourceLocation CondLoc = S->getLocStart(); |
| 3475 | if (auto BO = dyn_cast<BinaryOperator>(S)) { |
| 3476 | if (BO->isRelationalOp()) { |
| 3477 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 3478 | return SetUB(BO->getRHS(), |
| 3479 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_LE), |
| 3480 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_GT), |
| 3481 | BO->getSourceRange(), BO->getOperatorLoc()); |
| 3482 | if (GetInitVarDecl(BO->getRHS()) == Var) |
| 3483 | return SetUB(BO->getLHS(), |
| 3484 | (BO->getOpcode() == BO_GT || BO->getOpcode() == BO_GE), |
| 3485 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_GT), |
| 3486 | BO->getSourceRange(), BO->getOperatorLoc()); |
| 3487 | } |
| 3488 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
| 3489 | if (CE->getNumArgs() == 2) { |
| 3490 | auto Op = CE->getOperator(); |
| 3491 | switch (Op) { |
| 3492 | case OO_Greater: |
| 3493 | case OO_GreaterEqual: |
| 3494 | case OO_Less: |
| 3495 | case OO_LessEqual: |
| 3496 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 3497 | return SetUB(CE->getArg(1), Op == OO_Less || Op == OO_LessEqual, |
| 3498 | Op == OO_Less || Op == OO_Greater, CE->getSourceRange(), |
| 3499 | CE->getOperatorLoc()); |
| 3500 | if (GetInitVarDecl(CE->getArg(1)) == Var) |
| 3501 | return SetUB(CE->getArg(0), Op == OO_Greater || Op == OO_GreaterEqual, |
| 3502 | Op == OO_Less || Op == OO_Greater, CE->getSourceRange(), |
| 3503 | CE->getOperatorLoc()); |
| 3504 | break; |
| 3505 | default: |
| 3506 | break; |
| 3507 | } |
| 3508 | } |
| 3509 | } |
| 3510 | SemaRef.Diag(CondLoc, diag::err_omp_loop_not_canonical_cond) |
| 3511 | << S->getSourceRange() << Var; |
| 3512 | return true; |
| 3513 | } |
| 3514 | |
| 3515 | bool OpenMPIterationSpaceChecker::CheckIncRHS(Expr *RHS) { |
| 3516 | // RHS of canonical loop form increment can be: |
| 3517 | // var + incr |
| 3518 | // incr + var |
| 3519 | // var - incr |
| 3520 | // |
| 3521 | RHS = RHS->IgnoreParenImpCasts(); |
| 3522 | if (auto BO = dyn_cast<BinaryOperator>(RHS)) { |
| 3523 | if (BO->isAdditiveOp()) { |
| 3524 | bool IsAdd = BO->getOpcode() == BO_Add; |
| 3525 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 3526 | return SetStep(BO->getRHS(), !IsAdd); |
| 3527 | if (IsAdd && GetInitVarDecl(BO->getRHS()) == Var) |
| 3528 | return SetStep(BO->getLHS(), false); |
| 3529 | } |
| 3530 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(RHS)) { |
| 3531 | bool IsAdd = CE->getOperator() == OO_Plus; |
| 3532 | if ((IsAdd || CE->getOperator() == OO_Minus) && CE->getNumArgs() == 2) { |
| 3533 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 3534 | return SetStep(CE->getArg(1), !IsAdd); |
| 3535 | if (IsAdd && GetInitVarDecl(CE->getArg(1)) == Var) |
| 3536 | return SetStep(CE->getArg(0), false); |
| 3537 | } |
| 3538 | } |
| 3539 | SemaRef.Diag(RHS->getLocStart(), diag::err_omp_loop_not_canonical_incr) |
| 3540 | << RHS->getSourceRange() << Var; |
| 3541 | return true; |
| 3542 | } |
| 3543 | |
| 3544 | bool OpenMPIterationSpaceChecker::CheckInc(Expr *S) { |
| 3545 | // Check incr-expr for canonical loop form and return true if it |
| 3546 | // does not conform. |
| 3547 | // OpenMP [2.6] Canonical loop form. Test-expr may be one of the following: |
| 3548 | // ++var |
| 3549 | // var++ |
| 3550 | // --var |
| 3551 | // var-- |
| 3552 | // var += incr |
| 3553 | // var -= incr |
| 3554 | // var = var + incr |
| 3555 | // var = incr + var |
| 3556 | // var = var - incr |
| 3557 | // |
| 3558 | if (!S) { |
| 3559 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_incr) << Var; |
| 3560 | return true; |
| 3561 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3562 | IncrementSrcRange = S->getSourceRange(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3563 | S = S->IgnoreParens(); |
| 3564 | if (auto UO = dyn_cast<UnaryOperator>(S)) { |
| 3565 | if (UO->isIncrementDecrementOp() && GetInitVarDecl(UO->getSubExpr()) == Var) |
| 3566 | return SetStep( |
| 3567 | SemaRef.ActOnIntegerConstant(UO->getLocStart(), |
| 3568 | (UO->isDecrementOp() ? -1 : 1)).get(), |
| 3569 | false); |
| 3570 | } else if (auto BO = dyn_cast<BinaryOperator>(S)) { |
| 3571 | switch (BO->getOpcode()) { |
| 3572 | case BO_AddAssign: |
| 3573 | case BO_SubAssign: |
| 3574 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 3575 | return SetStep(BO->getRHS(), BO->getOpcode() == BO_SubAssign); |
| 3576 | break; |
| 3577 | case BO_Assign: |
| 3578 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 3579 | return CheckIncRHS(BO->getRHS()); |
| 3580 | break; |
| 3581 | default: |
| 3582 | break; |
| 3583 | } |
| 3584 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
| 3585 | switch (CE->getOperator()) { |
| 3586 | case OO_PlusPlus: |
| 3587 | case OO_MinusMinus: |
| 3588 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 3589 | return SetStep( |
| 3590 | SemaRef.ActOnIntegerConstant( |
| 3591 | CE->getLocStart(), |
| 3592 | ((CE->getOperator() == OO_MinusMinus) ? -1 : 1)).get(), |
| 3593 | false); |
| 3594 | break; |
| 3595 | case OO_PlusEqual: |
| 3596 | case OO_MinusEqual: |
| 3597 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 3598 | return SetStep(CE->getArg(1), CE->getOperator() == OO_MinusEqual); |
| 3599 | break; |
| 3600 | case OO_Equal: |
| 3601 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 3602 | return CheckIncRHS(CE->getArg(1)); |
| 3603 | break; |
| 3604 | default: |
| 3605 | break; |
| 3606 | } |
| 3607 | } |
| 3608 | SemaRef.Diag(S->getLocStart(), diag::err_omp_loop_not_canonical_incr) |
| 3609 | << S->getSourceRange() << Var; |
| 3610 | return true; |
| 3611 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3612 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3613 | namespace { |
| 3614 | // Transform variables declared in GNU statement expressions to new ones to |
| 3615 | // avoid crash on codegen. |
| 3616 | class TransformToNewDefs : public TreeTransform<TransformToNewDefs> { |
| 3617 | typedef TreeTransform<TransformToNewDefs> BaseTransform; |
| 3618 | |
| 3619 | public: |
| 3620 | TransformToNewDefs(Sema &SemaRef) : BaseTransform(SemaRef) {} |
| 3621 | |
| 3622 | Decl *TransformDefinition(SourceLocation Loc, Decl *D) { |
| 3623 | if (auto *VD = cast<VarDecl>(D)) |
| 3624 | if (!isa<ParmVarDecl>(D) && !isa<VarTemplateSpecializationDecl>(D) && |
| 3625 | !isa<ImplicitParamDecl>(D)) { |
| 3626 | auto *NewVD = VarDecl::Create( |
| 3627 | SemaRef.Context, VD->getDeclContext(), VD->getLocStart(), |
| 3628 | VD->getLocation(), VD->getIdentifier(), VD->getType(), |
| 3629 | VD->getTypeSourceInfo(), VD->getStorageClass()); |
| 3630 | NewVD->setTSCSpec(VD->getTSCSpec()); |
| 3631 | NewVD->setInit(VD->getInit()); |
| 3632 | NewVD->setInitStyle(VD->getInitStyle()); |
| 3633 | NewVD->setExceptionVariable(VD->isExceptionVariable()); |
| 3634 | NewVD->setNRVOVariable(VD->isNRVOVariable()); |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 3635 | NewVD->setCXXForRangeDecl(VD->isCXXForRangeDecl()); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3636 | NewVD->setConstexpr(VD->isConstexpr()); |
| 3637 | NewVD->setInitCapture(VD->isInitCapture()); |
| 3638 | NewVD->setPreviousDeclInSameBlockScope( |
| 3639 | VD->isPreviousDeclInSameBlockScope()); |
| 3640 | VD->getDeclContext()->addHiddenDecl(NewVD); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 3641 | if (VD->hasAttrs()) |
| 3642 | NewVD->setAttrs(VD->getAttrs()); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3643 | transformedLocalDecl(VD, NewVD); |
| 3644 | return NewVD; |
| 3645 | } |
| 3646 | return BaseTransform::TransformDefinition(Loc, D); |
| 3647 | } |
| 3648 | |
| 3649 | ExprResult TransformDeclRefExpr(DeclRefExpr *E) { |
| 3650 | if (auto *NewD = TransformDecl(E->getExprLoc(), E->getDecl())) |
| 3651 | if (E->getDecl() != NewD) { |
| 3652 | NewD->setReferenced(); |
| 3653 | NewD->markUsed(SemaRef.Context); |
| 3654 | return DeclRefExpr::Create( |
| 3655 | SemaRef.Context, E->getQualifierLoc(), E->getTemplateKeywordLoc(), |
| 3656 | cast<ValueDecl>(NewD), E->refersToEnclosingVariableOrCapture(), |
| 3657 | E->getNameInfo(), E->getType(), E->getValueKind()); |
| 3658 | } |
| 3659 | return BaseTransform::TransformDeclRefExpr(E); |
| 3660 | } |
| 3661 | }; |
| 3662 | } |
| 3663 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3664 | /// \brief Build the expression to calculate the number of iterations. |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3665 | Expr * |
| 3666 | OpenMPIterationSpaceChecker::BuildNumIterations(Scope *S, |
| 3667 | const bool LimitedType) const { |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3668 | TransformToNewDefs Transform(SemaRef); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3669 | ExprResult Diff; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3670 | auto VarType = Var->getType().getNonReferenceType(); |
| 3671 | if (VarType->isIntegerType() || VarType->isPointerType() || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3672 | SemaRef.getLangOpts().CPlusPlus) { |
| 3673 | // Upper - Lower |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3674 | auto *UBExpr = TestIsLessOp ? UB : LB; |
| 3675 | auto *LBExpr = TestIsLessOp ? LB : UB; |
| 3676 | Expr *Upper = Transform.TransformExpr(UBExpr).get(); |
| 3677 | Expr *Lower = Transform.TransformExpr(LBExpr).get(); |
| 3678 | if (!Upper || !Lower) |
| 3679 | return nullptr; |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 3680 | if (!SemaRef.Context.hasSameType(Upper->getType(), UBExpr->getType())) { |
| 3681 | Upper = SemaRef |
| 3682 | .PerformImplicitConversion(Upper, UBExpr->getType(), |
| 3683 | Sema::AA_Converting, |
| 3684 | /*AllowExplicit=*/true) |
| 3685 | .get(); |
| 3686 | } |
| 3687 | if (!SemaRef.Context.hasSameType(Lower->getType(), LBExpr->getType())) { |
| 3688 | Lower = SemaRef |
| 3689 | .PerformImplicitConversion(Lower, LBExpr->getType(), |
| 3690 | Sema::AA_Converting, |
| 3691 | /*AllowExplicit=*/true) |
| 3692 | .get(); |
| 3693 | } |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3694 | if (!Upper || !Lower) |
| 3695 | return nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3696 | |
| 3697 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Sub, Upper, Lower); |
| 3698 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3699 | if (!Diff.isUsable() && VarType->getAsCXXRecordDecl()) { |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3700 | // BuildBinOp already emitted error, this one is to point user to upper |
| 3701 | // and lower bound, and to tell what is passed to 'operator-'. |
| 3702 | SemaRef.Diag(Upper->getLocStart(), diag::err_omp_loop_diff_cxx) |
| 3703 | << Upper->getSourceRange() << Lower->getSourceRange(); |
| 3704 | return nullptr; |
| 3705 | } |
| 3706 | } |
| 3707 | |
| 3708 | if (!Diff.isUsable()) |
| 3709 | return nullptr; |
| 3710 | |
| 3711 | // Upper - Lower [- 1] |
| 3712 | if (TestIsStrictOp) |
| 3713 | Diff = SemaRef.BuildBinOp( |
| 3714 | S, DefaultLoc, BO_Sub, Diff.get(), |
| 3715 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 3716 | if (!Diff.isUsable()) |
| 3717 | return nullptr; |
| 3718 | |
| 3719 | // Upper - Lower [- 1] + Step |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 3720 | auto *StepNoImp = Step->IgnoreImplicit(); |
| 3721 | auto NewStep = Transform.TransformExpr(StepNoImp); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3722 | if (NewStep.isInvalid()) |
| 3723 | return nullptr; |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 3724 | if (!SemaRef.Context.hasSameType(NewStep.get()->getType(), |
| 3725 | StepNoImp->getType())) { |
| 3726 | NewStep = SemaRef.PerformImplicitConversion( |
| 3727 | NewStep.get(), StepNoImp->getType(), Sema::AA_Converting, |
| 3728 | /*AllowExplicit=*/true); |
| 3729 | if (NewStep.isInvalid()) |
| 3730 | return nullptr; |
| 3731 | } |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3732 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Add, Diff.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3733 | if (!Diff.isUsable()) |
| 3734 | return nullptr; |
| 3735 | |
| 3736 | // Parentheses (for dumping/debugging purposes only). |
| 3737 | Diff = SemaRef.ActOnParenExpr(DefaultLoc, DefaultLoc, Diff.get()); |
| 3738 | if (!Diff.isUsable()) |
| 3739 | return nullptr; |
| 3740 | |
| 3741 | // (Upper - Lower [- 1] + Step) / Step |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 3742 | NewStep = Transform.TransformExpr(StepNoImp); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3743 | if (NewStep.isInvalid()) |
| 3744 | return nullptr; |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 3745 | if (!SemaRef.Context.hasSameType(NewStep.get()->getType(), |
| 3746 | StepNoImp->getType())) { |
| 3747 | NewStep = SemaRef.PerformImplicitConversion( |
| 3748 | NewStep.get(), StepNoImp->getType(), Sema::AA_Converting, |
| 3749 | /*AllowExplicit=*/true); |
| 3750 | if (NewStep.isInvalid()) |
| 3751 | return nullptr; |
| 3752 | } |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3753 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Div, Diff.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3754 | if (!Diff.isUsable()) |
| 3755 | return nullptr; |
| 3756 | |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3757 | // OpenMP runtime requires 32-bit or 64-bit loop variables. |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3758 | QualType Type = Diff.get()->getType(); |
| 3759 | auto &C = SemaRef.Context; |
| 3760 | bool UseVarType = VarType->hasIntegerRepresentation() && |
| 3761 | C.getTypeSize(Type) > C.getTypeSize(VarType); |
| 3762 | if (!Type->isIntegerType() || UseVarType) { |
| 3763 | unsigned NewSize = |
| 3764 | UseVarType ? C.getTypeSize(VarType) : C.getTypeSize(Type); |
| 3765 | bool IsSigned = UseVarType ? VarType->hasSignedIntegerRepresentation() |
| 3766 | : Type->hasSignedIntegerRepresentation(); |
| 3767 | Type = C.getIntTypeForBitwidth(NewSize, IsSigned); |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 3768 | if (!SemaRef.Context.hasSameType(Diff.get()->getType(), Type)) { |
| 3769 | Diff = SemaRef.PerformImplicitConversion( |
| 3770 | Diff.get(), Type, Sema::AA_Converting, /*AllowExplicit=*/true); |
| 3771 | if (!Diff.isUsable()) |
| 3772 | return nullptr; |
| 3773 | } |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3774 | } |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3775 | if (LimitedType) { |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3776 | unsigned NewSize = (C.getTypeSize(Type) > 32) ? 64 : 32; |
| 3777 | if (NewSize != C.getTypeSize(Type)) { |
| 3778 | if (NewSize < C.getTypeSize(Type)) { |
| 3779 | assert(NewSize == 64 && "incorrect loop var size"); |
| 3780 | SemaRef.Diag(DefaultLoc, diag::warn_omp_loop_64_bit_var) |
| 3781 | << InitSrcRange << ConditionSrcRange; |
| 3782 | } |
| 3783 | QualType NewType = C.getIntTypeForBitwidth( |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3784 | NewSize, Type->hasSignedIntegerRepresentation() || |
| 3785 | C.getTypeSize(Type) < NewSize); |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 3786 | if (!SemaRef.Context.hasSameType(Diff.get()->getType(), NewType)) { |
| 3787 | Diff = SemaRef.PerformImplicitConversion(Diff.get(), NewType, |
| 3788 | Sema::AA_Converting, true); |
| 3789 | if (!Diff.isUsable()) |
| 3790 | return nullptr; |
| 3791 | } |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3792 | } |
| 3793 | } |
| 3794 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3795 | return Diff.get(); |
| 3796 | } |
| 3797 | |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3798 | Expr *OpenMPIterationSpaceChecker::BuildPreCond(Scope *S, Expr *Cond) const { |
| 3799 | // Try to build LB <op> UB, where <op> is <, >, <=, or >=. |
| 3800 | bool Suppress = SemaRef.getDiagnostics().getSuppressAllDiagnostics(); |
| 3801 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(/*Val=*/true); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3802 | TransformToNewDefs Transform(SemaRef); |
| 3803 | |
| 3804 | auto NewLB = Transform.TransformExpr(LB); |
| 3805 | auto NewUB = Transform.TransformExpr(UB); |
| 3806 | if (NewLB.isInvalid() || NewUB.isInvalid()) |
| 3807 | return Cond; |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 3808 | if (!SemaRef.Context.hasSameType(NewLB.get()->getType(), LB->getType())) { |
| 3809 | NewLB = SemaRef.PerformImplicitConversion(NewLB.get(), LB->getType(), |
| 3810 | Sema::AA_Converting, |
| 3811 | /*AllowExplicit=*/true); |
| 3812 | } |
| 3813 | if (!SemaRef.Context.hasSameType(NewUB.get()->getType(), UB->getType())) { |
| 3814 | NewUB = SemaRef.PerformImplicitConversion(NewUB.get(), UB->getType(), |
| 3815 | Sema::AA_Converting, |
| 3816 | /*AllowExplicit=*/true); |
| 3817 | } |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3818 | if (NewLB.isInvalid() || NewUB.isInvalid()) |
| 3819 | return Cond; |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3820 | auto CondExpr = SemaRef.BuildBinOp( |
| 3821 | S, DefaultLoc, TestIsLessOp ? (TestIsStrictOp ? BO_LT : BO_LE) |
| 3822 | : (TestIsStrictOp ? BO_GT : BO_GE), |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3823 | NewLB.get(), NewUB.get()); |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3824 | if (CondExpr.isUsable()) { |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 3825 | if (!SemaRef.Context.hasSameType(CondExpr.get()->getType(), |
| 3826 | SemaRef.Context.BoolTy)) |
| 3827 | CondExpr = SemaRef.PerformImplicitConversion( |
| 3828 | CondExpr.get(), SemaRef.Context.BoolTy, /*Action=*/Sema::AA_Casting, |
| 3829 | /*AllowExplicit=*/true); |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3830 | } |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3831 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(Suppress); |
| 3832 | // Otherwise use original loop conditon and evaluate it in runtime. |
| 3833 | return CondExpr.isUsable() ? CondExpr.get() : Cond; |
| 3834 | } |
| 3835 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3836 | /// \brief Build reference expression to the counter be used for codegen. |
| 3837 | Expr *OpenMPIterationSpaceChecker::BuildCounterVar() const { |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3838 | return buildDeclRefExpr(SemaRef, Var, Var->getType().getNonReferenceType(), |
| 3839 | DefaultLoc); |
| 3840 | } |
| 3841 | |
| 3842 | Expr *OpenMPIterationSpaceChecker::BuildPrivateCounterVar() const { |
| 3843 | if (Var && !Var->isInvalidDecl()) { |
| 3844 | auto Type = Var->getType().getNonReferenceType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 3845 | auto *PrivateVar = |
| 3846 | buildVarDecl(SemaRef, DefaultLoc, Type, Var->getName(), |
| 3847 | Var->hasAttrs() ? &Var->getAttrs() : nullptr); |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3848 | if (PrivateVar->isInvalidDecl()) |
| 3849 | return nullptr; |
| 3850 | return buildDeclRefExpr(SemaRef, PrivateVar, Type, DefaultLoc); |
| 3851 | } |
| 3852 | return nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3853 | } |
| 3854 | |
| 3855 | /// \brief Build initization of the counter be used for codegen. |
| 3856 | Expr *OpenMPIterationSpaceChecker::BuildCounterInit() const { return LB; } |
| 3857 | |
| 3858 | /// \brief Build step of the counter be used for codegen. |
| 3859 | Expr *OpenMPIterationSpaceChecker::BuildCounterStep() const { return Step; } |
| 3860 | |
| 3861 | /// \brief Iteration space of a single for loop. |
| 3862 | struct LoopIterationSpace { |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3863 | /// \brief Condition of the loop. |
| 3864 | Expr *PreCond; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3865 | /// \brief This expression calculates the number of iterations in the loop. |
| 3866 | /// It is always possible to calculate it before starting the loop. |
| 3867 | Expr *NumIterations; |
| 3868 | /// \brief The loop counter variable. |
| 3869 | Expr *CounterVar; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3870 | /// \brief Private loop counter variable. |
| 3871 | Expr *PrivateCounterVar; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3872 | /// \brief This is initializer for the initial value of #CounterVar. |
| 3873 | Expr *CounterInit; |
| 3874 | /// \brief This is step for the #CounterVar used to generate its update: |
| 3875 | /// #CounterVar = #CounterInit + #CounterStep * CurrentIteration. |
| 3876 | Expr *CounterStep; |
| 3877 | /// \brief Should step be subtracted? |
| 3878 | bool Subtract; |
| 3879 | /// \brief Source range of the loop init. |
| 3880 | SourceRange InitSrcRange; |
| 3881 | /// \brief Source range of the loop condition. |
| 3882 | SourceRange CondSrcRange; |
| 3883 | /// \brief Source range of the loop increment. |
| 3884 | SourceRange IncSrcRange; |
| 3885 | }; |
| 3886 | |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 3887 | } // namespace |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3888 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3889 | void Sema::ActOnOpenMPLoopInitialization(SourceLocation ForLoc, Stmt *Init) { |
| 3890 | assert(getLangOpts().OpenMP && "OpenMP is not active."); |
| 3891 | assert(Init && "Expected loop in canonical form."); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 3892 | unsigned AssociatedLoops = DSAStack->getAssociatedLoops(); |
| 3893 | if (AssociatedLoops > 0 && |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3894 | isOpenMPLoopDirective(DSAStack->getCurrentDirective())) { |
| 3895 | OpenMPIterationSpaceChecker ISC(*this, ForLoc); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 3896 | if (!ISC.CheckInit(Init, /*EmitDiags=*/false)) |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3897 | DSAStack->addLoopControlVariable(ISC.GetLoopVar()); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 3898 | DSAStack->setAssociatedLoops(AssociatedLoops - 1); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3899 | } |
| 3900 | } |
| 3901 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3902 | /// \brief Called on a for stmt to check and extract its iteration space |
| 3903 | /// for further processing (such as collapsing). |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3904 | static bool CheckOpenMPIterationSpace( |
| 3905 | OpenMPDirectiveKind DKind, Stmt *S, Sema &SemaRef, DSAStackTy &DSA, |
| 3906 | unsigned CurrentNestedLoopCount, unsigned NestedLoopCount, |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3907 | Expr *CollapseLoopCountExpr, Expr *OrderedLoopCountExpr, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 3908 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3909 | LoopIterationSpace &ResultIterSpace) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3910 | // OpenMP [2.6, Canonical Loop Form] |
| 3911 | // for (init-expr; test-expr; incr-expr) structured-block |
| 3912 | auto For = dyn_cast_or_null<ForStmt>(S); |
| 3913 | if (!For) { |
| 3914 | SemaRef.Diag(S->getLocStart(), diag::err_omp_not_for) |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3915 | << (CollapseLoopCountExpr != nullptr || OrderedLoopCountExpr != nullptr) |
| 3916 | << getOpenMPDirectiveName(DKind) << NestedLoopCount |
| 3917 | << (CurrentNestedLoopCount > 0) << CurrentNestedLoopCount; |
| 3918 | if (NestedLoopCount > 1) { |
| 3919 | if (CollapseLoopCountExpr && OrderedLoopCountExpr) |
| 3920 | SemaRef.Diag(DSA.getConstructLoc(), |
| 3921 | diag::note_omp_collapse_ordered_expr) |
| 3922 | << 2 << CollapseLoopCountExpr->getSourceRange() |
| 3923 | << OrderedLoopCountExpr->getSourceRange(); |
| 3924 | else if (CollapseLoopCountExpr) |
| 3925 | SemaRef.Diag(CollapseLoopCountExpr->getExprLoc(), |
| 3926 | diag::note_omp_collapse_ordered_expr) |
| 3927 | << 0 << CollapseLoopCountExpr->getSourceRange(); |
| 3928 | else |
| 3929 | SemaRef.Diag(OrderedLoopCountExpr->getExprLoc(), |
| 3930 | diag::note_omp_collapse_ordered_expr) |
| 3931 | << 1 << OrderedLoopCountExpr->getSourceRange(); |
| 3932 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3933 | return true; |
| 3934 | } |
| 3935 | assert(For->getBody()); |
| 3936 | |
| 3937 | OpenMPIterationSpaceChecker ISC(SemaRef, For->getForLoc()); |
| 3938 | |
| 3939 | // Check init. |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 3940 | auto Init = For->getInit(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3941 | if (ISC.CheckInit(Init)) { |
| 3942 | return true; |
| 3943 | } |
| 3944 | |
| 3945 | bool HasErrors = false; |
| 3946 | |
| 3947 | // Check loop variable's type. |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 3948 | auto Var = ISC.GetLoopVar(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3949 | |
| 3950 | // OpenMP [2.6, Canonical Loop Form] |
| 3951 | // Var is one of the following: |
| 3952 | // A variable of signed or unsigned integer type. |
| 3953 | // For C++, a variable of a random access iterator type. |
| 3954 | // For C, a variable of a pointer type. |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3955 | auto VarType = Var->getType().getNonReferenceType(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3956 | if (!VarType->isDependentType() && !VarType->isIntegerType() && |
| 3957 | !VarType->isPointerType() && |
| 3958 | !(SemaRef.getLangOpts().CPlusPlus && VarType->isOverloadableType())) { |
| 3959 | SemaRef.Diag(Init->getLocStart(), diag::err_omp_loop_variable_type) |
| 3960 | << SemaRef.getLangOpts().CPlusPlus; |
| 3961 | HasErrors = true; |
| 3962 | } |
| 3963 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3964 | // OpenMP, 2.14.1.1 Data-sharing Attribute Rules for Variables Referenced in a |
| 3965 | // Construct |
| 3966 | // The loop iteration variable(s) in the associated for-loop(s) of a for or |
| 3967 | // parallel for construct is (are) private. |
| 3968 | // The loop iteration variable in the associated for-loop of a simd construct |
| 3969 | // with just one associated for-loop is linear with a constant-linear-step |
| 3970 | // that is the increment of the associated for-loop. |
| 3971 | // Exclude loop var from the list of variables with implicitly defined data |
| 3972 | // sharing attributes. |
Benjamin Kramer | ad8e079 | 2014-10-10 15:32:48 +0000 | [diff] [blame] | 3973 | VarsWithImplicitDSA.erase(Var); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3974 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3975 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced in |
| 3976 | // a Construct, C/C++]. |
Alexey Bataev | cefffae | 2014-06-23 08:21:53 +0000 | [diff] [blame] | 3977 | // The loop iteration variable in the associated for-loop of a simd construct |
| 3978 | // with just one associated for-loop may be listed in a linear clause with a |
| 3979 | // constant-linear-step that is the increment of the associated for-loop. |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3980 | // The loop iteration variable(s) in the associated for-loop(s) of a for or |
| 3981 | // parallel for construct may be listed in a private or lastprivate clause. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 3982 | DSAStackTy::DSAVarData DVar = DSA.getTopDSA(Var, false); |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3983 | auto LoopVarRefExpr = ISC.GetLoopVarRefExpr(); |
| 3984 | // If LoopVarRefExpr is nullptr it means the corresponding loop variable is |
| 3985 | // declared in the loop and it is predetermined as a private. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3986 | auto PredeterminedCKind = |
| 3987 | isOpenMPSimdDirective(DKind) |
| 3988 | ? ((NestedLoopCount == 1) ? OMPC_linear : OMPC_lastprivate) |
| 3989 | : OMPC_private; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3990 | if (((isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown && |
Alexey Bataev | e648e80 | 2015-12-25 13:38:08 +0000 | [diff] [blame] | 3991 | DVar.CKind != PredeterminedCKind) || |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 3992 | ((isOpenMPWorksharingDirective(DKind) || DKind == OMPD_taskloop || |
Alexey Bataev | e648e80 | 2015-12-25 13:38:08 +0000 | [diff] [blame] | 3993 | isOpenMPDistributeDirective(DKind)) && |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 3994 | !isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown && |
Alexey Bataev | e648e80 | 2015-12-25 13:38:08 +0000 | [diff] [blame] | 3995 | DVar.CKind != OMPC_private && DVar.CKind != OMPC_lastprivate)) && |
| 3996 | (DVar.CKind != OMPC_private || DVar.RefExpr != nullptr)) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3997 | SemaRef.Diag(Init->getLocStart(), diag::err_omp_loop_var_dsa) |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3998 | << getOpenMPClauseName(DVar.CKind) << getOpenMPDirectiveName(DKind) |
| 3999 | << getOpenMPClauseName(PredeterminedCKind); |
Alexey Bataev | f2453a0 | 2015-05-06 07:25:08 +0000 | [diff] [blame] | 4000 | if (DVar.RefExpr == nullptr) |
| 4001 | DVar.CKind = PredeterminedCKind; |
| 4002 | ReportOriginalDSA(SemaRef, &DSA, Var, DVar, /*IsLoopIterVar=*/true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4003 | HasErrors = true; |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 4004 | } else if (LoopVarRefExpr != nullptr) { |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4005 | // Make the loop iteration variable private (for worksharing constructs), |
| 4006 | // linear (for simd directives with the only one associated loop) or |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4007 | // lastprivate (for simd directives with several collapsed or ordered |
| 4008 | // loops). |
Alexey Bataev | 9aba41c | 2014-11-14 04:08:45 +0000 | [diff] [blame] | 4009 | if (DVar.CKind == OMPC_unknown) |
| 4010 | DVar = DSA.hasDSA(Var, isOpenMPPrivate, MatchesAlways(), |
| 4011 | /*FromParent=*/false); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 4012 | DSA.addDSA(Var, LoopVarRefExpr, PredeterminedCKind); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4013 | } |
| 4014 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 4015 | assert(isOpenMPLoopDirective(DKind) && "DSA for non-loop vars"); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 4016 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4017 | // Check test-expr. |
| 4018 | HasErrors |= ISC.CheckCond(For->getCond()); |
| 4019 | |
| 4020 | // Check incr-expr. |
| 4021 | HasErrors |= ISC.CheckInc(For->getInc()); |
| 4022 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4023 | if (ISC.Dependent() || SemaRef.CurContext->isDependentContext() || HasErrors) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4024 | return HasErrors; |
| 4025 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4026 | // Build the loop's iteration space representation. |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 4027 | ResultIterSpace.PreCond = ISC.BuildPreCond(DSA.getCurScope(), For->getCond()); |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 4028 | ResultIterSpace.NumIterations = ISC.BuildNumIterations( |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 4029 | DSA.getCurScope(), (isOpenMPWorksharingDirective(DKind) || |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 4030 | isOpenMPTaskLoopDirective(DKind) || |
| 4031 | isOpenMPDistributeDirective(DKind))); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4032 | ResultIterSpace.CounterVar = ISC.BuildCounterVar(); |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 4033 | ResultIterSpace.PrivateCounterVar = ISC.BuildPrivateCounterVar(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4034 | ResultIterSpace.CounterInit = ISC.BuildCounterInit(); |
| 4035 | ResultIterSpace.CounterStep = ISC.BuildCounterStep(); |
| 4036 | ResultIterSpace.InitSrcRange = ISC.GetInitSrcRange(); |
| 4037 | ResultIterSpace.CondSrcRange = ISC.GetConditionSrcRange(); |
| 4038 | ResultIterSpace.IncSrcRange = ISC.GetIncrementSrcRange(); |
| 4039 | ResultIterSpace.Subtract = ISC.ShouldSubtractStep(); |
| 4040 | |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 4041 | HasErrors |= (ResultIterSpace.PreCond == nullptr || |
| 4042 | ResultIterSpace.NumIterations == nullptr || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4043 | ResultIterSpace.CounterVar == nullptr || |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 4044 | ResultIterSpace.PrivateCounterVar == nullptr || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4045 | ResultIterSpace.CounterInit == nullptr || |
| 4046 | ResultIterSpace.CounterStep == nullptr); |
| 4047 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4048 | return HasErrors; |
| 4049 | } |
| 4050 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4051 | /// \brief Build 'VarRef = Start. |
| 4052 | static ExprResult BuildCounterInit(Sema &SemaRef, Scope *S, SourceLocation Loc, |
| 4053 | ExprResult VarRef, ExprResult Start) { |
| 4054 | TransformToNewDefs Transform(SemaRef); |
| 4055 | // Build 'VarRef = Start. |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 4056 | auto *StartNoImp = Start.get()->IgnoreImplicit(); |
| 4057 | auto NewStart = Transform.TransformExpr(StartNoImp); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4058 | if (NewStart.isInvalid()) |
| 4059 | return ExprError(); |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 4060 | if (!SemaRef.Context.hasSameType(NewStart.get()->getType(), |
| 4061 | StartNoImp->getType())) { |
| 4062 | NewStart = SemaRef.PerformImplicitConversion( |
| 4063 | NewStart.get(), StartNoImp->getType(), Sema::AA_Converting, |
| 4064 | /*AllowExplicit=*/true); |
| 4065 | if (NewStart.isInvalid()) |
| 4066 | return ExprError(); |
| 4067 | } |
| 4068 | if (!SemaRef.Context.hasSameType(NewStart.get()->getType(), |
| 4069 | VarRef.get()->getType())) { |
| 4070 | NewStart = SemaRef.PerformImplicitConversion( |
| 4071 | NewStart.get(), VarRef.get()->getType(), Sema::AA_Converting, |
| 4072 | /*AllowExplicit=*/true); |
| 4073 | if (!NewStart.isUsable()) |
| 4074 | return ExprError(); |
| 4075 | } |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4076 | |
| 4077 | auto Init = |
| 4078 | SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), NewStart.get()); |
| 4079 | return Init; |
| 4080 | } |
| 4081 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4082 | /// \brief Build 'VarRef = Start + Iter * Step'. |
| 4083 | static ExprResult BuildCounterUpdate(Sema &SemaRef, Scope *S, |
| 4084 | SourceLocation Loc, ExprResult VarRef, |
| 4085 | ExprResult Start, ExprResult Iter, |
| 4086 | ExprResult Step, bool Subtract) { |
| 4087 | // Add parentheses (for debugging purposes only). |
| 4088 | Iter = SemaRef.ActOnParenExpr(Loc, Loc, Iter.get()); |
| 4089 | if (!VarRef.isUsable() || !Start.isUsable() || !Iter.isUsable() || |
| 4090 | !Step.isUsable()) |
| 4091 | return ExprError(); |
| 4092 | |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 4093 | auto *StepNoImp = Step.get()->IgnoreImplicit(); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4094 | TransformToNewDefs Transform(SemaRef); |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 4095 | auto NewStep = Transform.TransformExpr(StepNoImp); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4096 | if (NewStep.isInvalid()) |
| 4097 | return ExprError(); |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 4098 | if (!SemaRef.Context.hasSameType(NewStep.get()->getType(), |
| 4099 | StepNoImp->getType())) { |
| 4100 | NewStep = SemaRef.PerformImplicitConversion( |
| 4101 | NewStep.get(), StepNoImp->getType(), Sema::AA_Converting, |
| 4102 | /*AllowExplicit=*/true); |
| 4103 | if (NewStep.isInvalid()) |
| 4104 | return ExprError(); |
| 4105 | } |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4106 | ExprResult Update = |
| 4107 | SemaRef.BuildBinOp(S, Loc, BO_Mul, Iter.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4108 | if (!Update.isUsable()) |
| 4109 | return ExprError(); |
| 4110 | |
Alexey Bataev | c0214e0 | 2016-02-16 12:13:49 +0000 | [diff] [blame] | 4111 | // Try to build 'VarRef = Start, VarRef (+|-)= Iter * Step' or |
| 4112 | // 'VarRef = Start (+|-) Iter * Step'. |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 4113 | auto *StartNoImp = Start.get()->IgnoreImplicit(); |
| 4114 | auto NewStart = Transform.TransformExpr(StartNoImp); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4115 | if (NewStart.isInvalid()) |
| 4116 | return ExprError(); |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 4117 | if (!SemaRef.Context.hasSameType(NewStart.get()->getType(), |
| 4118 | StartNoImp->getType())) { |
| 4119 | NewStart = SemaRef.PerformImplicitConversion( |
| 4120 | NewStart.get(), StartNoImp->getType(), Sema::AA_Converting, |
| 4121 | /*AllowExplicit=*/true); |
| 4122 | if (NewStart.isInvalid()) |
| 4123 | return ExprError(); |
| 4124 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4125 | |
Alexey Bataev | c0214e0 | 2016-02-16 12:13:49 +0000 | [diff] [blame] | 4126 | // First attempt: try to build 'VarRef = Start, VarRef += Iter * Step'. |
| 4127 | ExprResult SavedUpdate = Update; |
| 4128 | ExprResult UpdateVal; |
| 4129 | if (VarRef.get()->getType()->isOverloadableType() || |
| 4130 | NewStart.get()->getType()->isOverloadableType() || |
| 4131 | Update.get()->getType()->isOverloadableType()) { |
| 4132 | bool Suppress = SemaRef.getDiagnostics().getSuppressAllDiagnostics(); |
| 4133 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(/*Val=*/true); |
| 4134 | Update = |
| 4135 | SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), NewStart.get()); |
| 4136 | if (Update.isUsable()) { |
| 4137 | UpdateVal = |
| 4138 | SemaRef.BuildBinOp(S, Loc, Subtract ? BO_SubAssign : BO_AddAssign, |
| 4139 | VarRef.get(), SavedUpdate.get()); |
| 4140 | if (UpdateVal.isUsable()) { |
| 4141 | Update = SemaRef.CreateBuiltinBinOp(Loc, BO_Comma, Update.get(), |
| 4142 | UpdateVal.get()); |
| 4143 | } |
| 4144 | } |
| 4145 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(Suppress); |
| 4146 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4147 | |
Alexey Bataev | c0214e0 | 2016-02-16 12:13:49 +0000 | [diff] [blame] | 4148 | // Second attempt: try to build 'VarRef = Start (+|-) Iter * Step'. |
| 4149 | if (!Update.isUsable() || !UpdateVal.isUsable()) { |
| 4150 | Update = SemaRef.BuildBinOp(S, Loc, Subtract ? BO_Sub : BO_Add, |
| 4151 | NewStart.get(), SavedUpdate.get()); |
| 4152 | if (!Update.isUsable()) |
| 4153 | return ExprError(); |
| 4154 | |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 4155 | if (!SemaRef.Context.hasSameType(Update.get()->getType(), |
| 4156 | VarRef.get()->getType())) { |
| 4157 | Update = SemaRef.PerformImplicitConversion( |
| 4158 | Update.get(), VarRef.get()->getType(), Sema::AA_Converting, true); |
| 4159 | if (!Update.isUsable()) |
| 4160 | return ExprError(); |
| 4161 | } |
Alexey Bataev | c0214e0 | 2016-02-16 12:13:49 +0000 | [diff] [blame] | 4162 | |
| 4163 | Update = SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), Update.get()); |
| 4164 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4165 | return Update; |
| 4166 | } |
| 4167 | |
| 4168 | /// \brief Convert integer expression \a E to make it have at least \a Bits |
| 4169 | /// bits. |
| 4170 | static ExprResult WidenIterationCount(unsigned Bits, Expr *E, |
| 4171 | Sema &SemaRef) { |
| 4172 | if (E == nullptr) |
| 4173 | return ExprError(); |
| 4174 | auto &C = SemaRef.Context; |
| 4175 | QualType OldType = E->getType(); |
| 4176 | unsigned HasBits = C.getTypeSize(OldType); |
| 4177 | if (HasBits >= Bits) |
| 4178 | return ExprResult(E); |
| 4179 | // OK to convert to signed, because new type has more bits than old. |
| 4180 | QualType NewType = C.getIntTypeForBitwidth(Bits, /* Signed */ true); |
| 4181 | return SemaRef.PerformImplicitConversion(E, NewType, Sema::AA_Converting, |
| 4182 | true); |
| 4183 | } |
| 4184 | |
| 4185 | /// \brief Check if the given expression \a E is a constant integer that fits |
| 4186 | /// into \a Bits bits. |
| 4187 | static bool FitsInto(unsigned Bits, bool Signed, Expr *E, Sema &SemaRef) { |
| 4188 | if (E == nullptr) |
| 4189 | return false; |
| 4190 | llvm::APSInt Result; |
| 4191 | if (E->isIntegerConstantExpr(Result, SemaRef.Context)) |
| 4192 | return Signed ? Result.isSignedIntN(Bits) : Result.isIntN(Bits); |
| 4193 | return false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4194 | } |
| 4195 | |
| 4196 | /// \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] | 4197 | /// \return Returns 0 if one of the collapsed stmts is not canonical for loop, |
| 4198 | /// number of collapsed loops otherwise. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4199 | static unsigned |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4200 | CheckOpenMPLoop(OpenMPDirectiveKind DKind, Expr *CollapseLoopCountExpr, |
| 4201 | Expr *OrderedLoopCountExpr, Stmt *AStmt, Sema &SemaRef, |
| 4202 | DSAStackTy &DSA, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 4203 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA, |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4204 | OMPLoopDirective::HelperExprs &Built) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 4205 | unsigned NestedLoopCount = 1; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4206 | if (CollapseLoopCountExpr) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 4207 | // Found 'collapse' clause - calculate collapse number. |
| 4208 | llvm::APSInt Result; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4209 | if (CollapseLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext())) |
Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 4210 | NestedLoopCount = Result.getLimitedValue(); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4211 | } |
| 4212 | if (OrderedLoopCountExpr) { |
| 4213 | // Found 'ordered' clause - calculate collapse number. |
| 4214 | llvm::APSInt Result; |
Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 4215 | if (OrderedLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext())) { |
| 4216 | if (Result.getLimitedValue() < NestedLoopCount) { |
| 4217 | SemaRef.Diag(OrderedLoopCountExpr->getExprLoc(), |
| 4218 | diag::err_omp_wrong_ordered_loop_count) |
| 4219 | << OrderedLoopCountExpr->getSourceRange(); |
| 4220 | SemaRef.Diag(CollapseLoopCountExpr->getExprLoc(), |
| 4221 | diag::note_collapse_loop_count) |
| 4222 | << CollapseLoopCountExpr->getSourceRange(); |
| 4223 | } |
| 4224 | NestedLoopCount = Result.getLimitedValue(); |
| 4225 | } |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 4226 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4227 | // This is helper routine for loop directives (e.g., 'for', 'simd', |
| 4228 | // 'for simd', etc.). |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4229 | SmallVector<LoopIterationSpace, 4> IterSpaces; |
| 4230 | IterSpaces.resize(NestedLoopCount); |
| 4231 | Stmt *CurStmt = AStmt->IgnoreContainers(/* IgnoreCaptured */ true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4232 | for (unsigned Cnt = 0; Cnt < NestedLoopCount; ++Cnt) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 4233 | if (CheckOpenMPIterationSpace(DKind, CurStmt, SemaRef, DSA, Cnt, |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4234 | NestedLoopCount, CollapseLoopCountExpr, |
| 4235 | OrderedLoopCountExpr, VarsWithImplicitDSA, |
| 4236 | IterSpaces[Cnt])) |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 4237 | return 0; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4238 | // 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] | 4239 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 4240 | // All loops associated with the construct must be perfectly nested; that |
| 4241 | // is, there must be no intervening code nor any OpenMP directive between |
| 4242 | // any two loops. |
| 4243 | CurStmt = cast<ForStmt>(CurStmt)->getBody()->IgnoreContainers(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4244 | } |
| 4245 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4246 | Built.clear(/* size */ NestedLoopCount); |
| 4247 | |
| 4248 | if (SemaRef.CurContext->isDependentContext()) |
| 4249 | return NestedLoopCount; |
| 4250 | |
| 4251 | // An example of what is generated for the following code: |
| 4252 | // |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4253 | // #pragma omp simd collapse(2) ordered(2) |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4254 | // for (i = 0; i < NI; ++i) |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4255 | // for (k = 0; k < NK; ++k) |
| 4256 | // for (j = J0; j < NJ; j+=2) { |
| 4257 | // <loop body> |
| 4258 | // } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4259 | // |
| 4260 | // We generate the code below. |
| 4261 | // Note: the loop body may be outlined in CodeGen. |
| 4262 | // Note: some counters may be C++ classes, operator- is used to find number of |
| 4263 | // iterations and operator+= to calculate counter value. |
| 4264 | // Note: decltype(NumIterations) must be integer type (in 'omp for', only i32 |
| 4265 | // or i64 is currently supported). |
| 4266 | // |
| 4267 | // #define NumIterations (NI * ((NJ - J0 - 1 + 2) / 2)) |
| 4268 | // for (int[32|64]_t IV = 0; IV < NumIterations; ++IV ) { |
| 4269 | // .local.i = IV / ((NJ - J0 - 1 + 2) / 2); |
| 4270 | // .local.j = J0 + (IV % ((NJ - J0 - 1 + 2) / 2)) * 2; |
| 4271 | // // similar updates for vars in clauses (e.g. 'linear') |
| 4272 | // <loop body (using local i and j)> |
| 4273 | // } |
| 4274 | // i = NI; // assign final values of counters |
| 4275 | // j = NJ; |
| 4276 | // |
| 4277 | |
| 4278 | // Last iteration number is (I1 * I2 * ... In) - 1, where I1, I2 ... In are |
| 4279 | // the iteration counts of the collapsed for loops. |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 4280 | // Precondition tests if there is at least one iteration (all conditions are |
| 4281 | // true). |
| 4282 | auto PreCond = ExprResult(IterSpaces[0].PreCond); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4283 | auto N0 = IterSpaces[0].NumIterations; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4284 | ExprResult LastIteration32 = WidenIterationCount( |
| 4285 | 32 /* Bits */, SemaRef.PerformImplicitConversion( |
| 4286 | N0->IgnoreImpCasts(), N0->getType(), |
| 4287 | Sema::AA_Converting, /*AllowExplicit=*/true) |
| 4288 | .get(), |
| 4289 | SemaRef); |
| 4290 | ExprResult LastIteration64 = WidenIterationCount( |
| 4291 | 64 /* Bits */, SemaRef.PerformImplicitConversion( |
| 4292 | N0->IgnoreImpCasts(), N0->getType(), |
| 4293 | Sema::AA_Converting, /*AllowExplicit=*/true) |
| 4294 | .get(), |
| 4295 | SemaRef); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4296 | |
| 4297 | if (!LastIteration32.isUsable() || !LastIteration64.isUsable()) |
| 4298 | return NestedLoopCount; |
| 4299 | |
| 4300 | auto &C = SemaRef.Context; |
| 4301 | bool AllCountsNeedLessThan32Bits = C.getTypeSize(N0->getType()) < 32; |
| 4302 | |
| 4303 | Scope *CurScope = DSA.getCurScope(); |
| 4304 | for (unsigned Cnt = 1; Cnt < NestedLoopCount; ++Cnt) { |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 4305 | if (PreCond.isUsable()) { |
| 4306 | PreCond = SemaRef.BuildBinOp(CurScope, SourceLocation(), BO_LAnd, |
| 4307 | PreCond.get(), IterSpaces[Cnt].PreCond); |
| 4308 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4309 | auto N = IterSpaces[Cnt].NumIterations; |
| 4310 | AllCountsNeedLessThan32Bits &= C.getTypeSize(N->getType()) < 32; |
| 4311 | if (LastIteration32.isUsable()) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4312 | LastIteration32 = SemaRef.BuildBinOp( |
| 4313 | CurScope, SourceLocation(), BO_Mul, LastIteration32.get(), |
| 4314 | SemaRef.PerformImplicitConversion(N->IgnoreImpCasts(), N->getType(), |
| 4315 | Sema::AA_Converting, |
| 4316 | /*AllowExplicit=*/true) |
| 4317 | .get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4318 | if (LastIteration64.isUsable()) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4319 | LastIteration64 = SemaRef.BuildBinOp( |
| 4320 | CurScope, SourceLocation(), BO_Mul, LastIteration64.get(), |
| 4321 | SemaRef.PerformImplicitConversion(N->IgnoreImpCasts(), N->getType(), |
| 4322 | Sema::AA_Converting, |
| 4323 | /*AllowExplicit=*/true) |
| 4324 | .get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4325 | } |
| 4326 | |
| 4327 | // Choose either the 32-bit or 64-bit version. |
| 4328 | ExprResult LastIteration = LastIteration64; |
| 4329 | if (LastIteration32.isUsable() && |
| 4330 | C.getTypeSize(LastIteration32.get()->getType()) == 32 && |
| 4331 | (AllCountsNeedLessThan32Bits || NestedLoopCount == 1 || |
| 4332 | FitsInto( |
| 4333 | 32 /* Bits */, |
| 4334 | LastIteration32.get()->getType()->hasSignedIntegerRepresentation(), |
| 4335 | LastIteration64.get(), SemaRef))) |
| 4336 | LastIteration = LastIteration32; |
| 4337 | |
| 4338 | if (!LastIteration.isUsable()) |
| 4339 | return 0; |
| 4340 | |
| 4341 | // Save the number of iterations. |
| 4342 | ExprResult NumIterations = LastIteration; |
| 4343 | { |
| 4344 | LastIteration = SemaRef.BuildBinOp( |
| 4345 | CurScope, SourceLocation(), BO_Sub, LastIteration.get(), |
| 4346 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 4347 | if (!LastIteration.isUsable()) |
| 4348 | return 0; |
| 4349 | } |
| 4350 | |
| 4351 | // Calculate the last iteration number beforehand instead of doing this on |
| 4352 | // each iteration. Do not do this if the number of iterations may be kfold-ed. |
| 4353 | llvm::APSInt Result; |
| 4354 | bool IsConstant = |
| 4355 | LastIteration.get()->isIntegerConstantExpr(Result, SemaRef.Context); |
| 4356 | ExprResult CalcLastIteration; |
| 4357 | if (!IsConstant) { |
| 4358 | SourceLocation SaveLoc; |
| 4359 | VarDecl *SaveVar = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4360 | buildVarDecl(SemaRef, SaveLoc, LastIteration.get()->getType(), |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4361 | ".omp.last.iteration"); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4362 | ExprResult SaveRef = buildDeclRefExpr( |
| 4363 | SemaRef, SaveVar, LastIteration.get()->getType(), SaveLoc); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4364 | CalcLastIteration = SemaRef.BuildBinOp(CurScope, SaveLoc, BO_Assign, |
| 4365 | SaveRef.get(), LastIteration.get()); |
| 4366 | LastIteration = SaveRef; |
| 4367 | |
| 4368 | // Prepare SaveRef + 1. |
| 4369 | NumIterations = SemaRef.BuildBinOp( |
| 4370 | CurScope, SaveLoc, BO_Add, SaveRef.get(), |
| 4371 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 4372 | if (!NumIterations.isUsable()) |
| 4373 | return 0; |
| 4374 | } |
| 4375 | |
| 4376 | SourceLocation InitLoc = IterSpaces[0].InitSrcRange.getBegin(); |
| 4377 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4378 | QualType VType = LastIteration.get()->getType(); |
| 4379 | // Build variables passed into runtime, nesessary for worksharing directives. |
| 4380 | ExprResult LB, UB, IL, ST, EUB; |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 4381 | if (isOpenMPWorksharingDirective(DKind) || isOpenMPTaskLoopDirective(DKind) || |
| 4382 | isOpenMPDistributeDirective(DKind)) { |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4383 | // Lower bound variable, initialized with zero. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4384 | VarDecl *LBDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.lb"); |
| 4385 | LB = buildDeclRefExpr(SemaRef, LBDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4386 | SemaRef.AddInitializerToDecl( |
| 4387 | LBDecl, SemaRef.ActOnIntegerConstant(InitLoc, 0).get(), |
| 4388 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 4389 | |
| 4390 | // Upper bound variable, initialized with last iteration number. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4391 | VarDecl *UBDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.ub"); |
| 4392 | UB = buildDeclRefExpr(SemaRef, UBDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4393 | SemaRef.AddInitializerToDecl(UBDecl, LastIteration.get(), |
| 4394 | /*DirectInit*/ false, |
| 4395 | /*TypeMayContainAuto*/ false); |
| 4396 | |
| 4397 | // A 32-bit variable-flag where runtime returns 1 for the last iteration. |
| 4398 | // This will be used to implement clause 'lastprivate'. |
| 4399 | QualType Int32Ty = SemaRef.Context.getIntTypeForBitwidth(32, true); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4400 | VarDecl *ILDecl = buildVarDecl(SemaRef, InitLoc, Int32Ty, ".omp.is_last"); |
| 4401 | IL = buildDeclRefExpr(SemaRef, ILDecl, Int32Ty, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4402 | SemaRef.AddInitializerToDecl( |
| 4403 | ILDecl, SemaRef.ActOnIntegerConstant(InitLoc, 0).get(), |
| 4404 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 4405 | |
| 4406 | // Stride variable returned by runtime (we initialize it to 1 by default). |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4407 | VarDecl *STDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.stride"); |
| 4408 | ST = buildDeclRefExpr(SemaRef, STDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4409 | SemaRef.AddInitializerToDecl( |
| 4410 | STDecl, SemaRef.ActOnIntegerConstant(InitLoc, 1).get(), |
| 4411 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 4412 | |
| 4413 | // Build expression: UB = min(UB, LastIteration) |
| 4414 | // It is nesessary for CodeGen of directives with static scheduling. |
| 4415 | ExprResult IsUBGreater = SemaRef.BuildBinOp(CurScope, InitLoc, BO_GT, |
| 4416 | UB.get(), LastIteration.get()); |
| 4417 | ExprResult CondOp = SemaRef.ActOnConditionalOp( |
| 4418 | InitLoc, InitLoc, IsUBGreater.get(), LastIteration.get(), UB.get()); |
| 4419 | EUB = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, UB.get(), |
| 4420 | CondOp.get()); |
| 4421 | EUB = SemaRef.ActOnFinishFullExpr(EUB.get()); |
| 4422 | } |
| 4423 | |
| 4424 | // Build the iteration variable and its initialization before loop. |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4425 | ExprResult IV; |
| 4426 | ExprResult Init; |
| 4427 | { |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4428 | VarDecl *IVDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.iv"); |
| 4429 | IV = buildDeclRefExpr(SemaRef, IVDecl, VType, InitLoc); |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 4430 | Expr *RHS = (isOpenMPWorksharingDirective(DKind) || |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 4431 | isOpenMPTaskLoopDirective(DKind) || |
| 4432 | isOpenMPDistributeDirective(DKind)) |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4433 | ? LB.get() |
| 4434 | : SemaRef.ActOnIntegerConstant(SourceLocation(), 0).get(); |
| 4435 | Init = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, IV.get(), RHS); |
| 4436 | Init = SemaRef.ActOnFinishFullExpr(Init.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4437 | } |
| 4438 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4439 | // Loop condition (IV < NumIterations) or (IV <= UB) for worksharing loops. |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4440 | SourceLocation CondLoc; |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4441 | ExprResult Cond = |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 4442 | (isOpenMPWorksharingDirective(DKind) || |
| 4443 | isOpenMPTaskLoopDirective(DKind) || isOpenMPDistributeDirective(DKind)) |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4444 | ? SemaRef.BuildBinOp(CurScope, CondLoc, BO_LE, IV.get(), UB.get()) |
| 4445 | : SemaRef.BuildBinOp(CurScope, CondLoc, BO_LT, IV.get(), |
| 4446 | NumIterations.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4447 | |
| 4448 | // Loop increment (IV = IV + 1) |
| 4449 | SourceLocation IncLoc; |
| 4450 | ExprResult Inc = |
| 4451 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, IV.get(), |
| 4452 | SemaRef.ActOnIntegerConstant(IncLoc, 1).get()); |
| 4453 | if (!Inc.isUsable()) |
| 4454 | return 0; |
| 4455 | Inc = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, IV.get(), Inc.get()); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4456 | Inc = SemaRef.ActOnFinishFullExpr(Inc.get()); |
| 4457 | if (!Inc.isUsable()) |
| 4458 | return 0; |
| 4459 | |
| 4460 | // Increments for worksharing loops (LB = LB + ST; UB = UB + ST). |
| 4461 | // Used for directives with static scheduling. |
| 4462 | ExprResult NextLB, NextUB; |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 4463 | if (isOpenMPWorksharingDirective(DKind) || isOpenMPTaskLoopDirective(DKind) || |
| 4464 | isOpenMPDistributeDirective(DKind)) { |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4465 | // LB + ST |
| 4466 | NextLB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, LB.get(), ST.get()); |
| 4467 | if (!NextLB.isUsable()) |
| 4468 | return 0; |
| 4469 | // LB = LB + ST |
| 4470 | NextLB = |
| 4471 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, LB.get(), NextLB.get()); |
| 4472 | NextLB = SemaRef.ActOnFinishFullExpr(NextLB.get()); |
| 4473 | if (!NextLB.isUsable()) |
| 4474 | return 0; |
| 4475 | // UB + ST |
| 4476 | NextUB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, UB.get(), ST.get()); |
| 4477 | if (!NextUB.isUsable()) |
| 4478 | return 0; |
| 4479 | // UB = UB + ST |
| 4480 | NextUB = |
| 4481 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, UB.get(), NextUB.get()); |
| 4482 | NextUB = SemaRef.ActOnFinishFullExpr(NextUB.get()); |
| 4483 | if (!NextUB.isUsable()) |
| 4484 | return 0; |
| 4485 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4486 | |
| 4487 | // Build updates and final values of the loop counters. |
| 4488 | bool HasErrors = false; |
| 4489 | Built.Counters.resize(NestedLoopCount); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4490 | Built.Inits.resize(NestedLoopCount); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4491 | Built.Updates.resize(NestedLoopCount); |
| 4492 | Built.Finals.resize(NestedLoopCount); |
| 4493 | { |
| 4494 | ExprResult Div; |
| 4495 | // Go from inner nested loop to outer. |
| 4496 | for (int Cnt = NestedLoopCount - 1; Cnt >= 0; --Cnt) { |
| 4497 | LoopIterationSpace &IS = IterSpaces[Cnt]; |
| 4498 | SourceLocation UpdLoc = IS.IncSrcRange.getBegin(); |
| 4499 | // Build: Iter = (IV / Div) % IS.NumIters |
| 4500 | // where Div is product of previous iterations' IS.NumIters. |
| 4501 | ExprResult Iter; |
| 4502 | if (Div.isUsable()) { |
| 4503 | Iter = |
| 4504 | SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Div, IV.get(), Div.get()); |
| 4505 | } else { |
| 4506 | Iter = IV; |
| 4507 | assert((Cnt == (int)NestedLoopCount - 1) && |
| 4508 | "unusable div expected on first iteration only"); |
| 4509 | } |
| 4510 | |
| 4511 | if (Cnt != 0 && Iter.isUsable()) |
| 4512 | Iter = SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Rem, Iter.get(), |
| 4513 | IS.NumIterations); |
| 4514 | if (!Iter.isUsable()) { |
| 4515 | HasErrors = true; |
| 4516 | break; |
| 4517 | } |
| 4518 | |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4519 | // Build update: IS.CounterVar(Private) = IS.Start + Iter * IS.Step |
| 4520 | auto *CounterVar = buildDeclRefExpr( |
| 4521 | SemaRef, cast<VarDecl>(cast<DeclRefExpr>(IS.CounterVar)->getDecl()), |
| 4522 | IS.CounterVar->getType(), IS.CounterVar->getExprLoc(), |
| 4523 | /*RefersToCapture=*/true); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4524 | ExprResult Init = BuildCounterInit(SemaRef, CurScope, UpdLoc, CounterVar, |
| 4525 | IS.CounterInit); |
| 4526 | if (!Init.isUsable()) { |
| 4527 | HasErrors = true; |
| 4528 | break; |
| 4529 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4530 | ExprResult Update = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4531 | BuildCounterUpdate(SemaRef, CurScope, UpdLoc, CounterVar, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4532 | IS.CounterInit, Iter, IS.CounterStep, IS.Subtract); |
| 4533 | if (!Update.isUsable()) { |
| 4534 | HasErrors = true; |
| 4535 | break; |
| 4536 | } |
| 4537 | |
| 4538 | // Build final: IS.CounterVar = IS.Start + IS.NumIters * IS.Step |
| 4539 | ExprResult Final = BuildCounterUpdate( |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4540 | SemaRef, CurScope, UpdLoc, CounterVar, IS.CounterInit, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4541 | IS.NumIterations, IS.CounterStep, IS.Subtract); |
| 4542 | if (!Final.isUsable()) { |
| 4543 | HasErrors = true; |
| 4544 | break; |
| 4545 | } |
| 4546 | |
| 4547 | // Build Div for the next iteration: Div <- Div * IS.NumIters |
| 4548 | if (Cnt != 0) { |
| 4549 | if (Div.isUnset()) |
| 4550 | Div = IS.NumIterations; |
| 4551 | else |
| 4552 | Div = SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Mul, Div.get(), |
| 4553 | IS.NumIterations); |
| 4554 | |
| 4555 | // Add parentheses (for debugging purposes only). |
| 4556 | if (Div.isUsable()) |
| 4557 | Div = SemaRef.ActOnParenExpr(UpdLoc, UpdLoc, Div.get()); |
| 4558 | if (!Div.isUsable()) { |
| 4559 | HasErrors = true; |
| 4560 | break; |
| 4561 | } |
| 4562 | } |
| 4563 | if (!Update.isUsable() || !Final.isUsable()) { |
| 4564 | HasErrors = true; |
| 4565 | break; |
| 4566 | } |
| 4567 | // Save results |
| 4568 | Built.Counters[Cnt] = IS.CounterVar; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 4569 | Built.PrivateCounters[Cnt] = IS.PrivateCounterVar; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4570 | Built.Inits[Cnt] = Init.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4571 | Built.Updates[Cnt] = Update.get(); |
| 4572 | Built.Finals[Cnt] = Final.get(); |
| 4573 | } |
| 4574 | } |
| 4575 | |
| 4576 | if (HasErrors) |
| 4577 | return 0; |
| 4578 | |
| 4579 | // Save results |
| 4580 | Built.IterationVarRef = IV.get(); |
| 4581 | Built.LastIteration = LastIteration.get(); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 4582 | Built.NumIterations = NumIterations.get(); |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 4583 | Built.CalcLastIteration = |
| 4584 | SemaRef.ActOnFinishFullExpr(CalcLastIteration.get()).get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4585 | Built.PreCond = PreCond.get(); |
| 4586 | Built.Cond = Cond.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4587 | Built.Init = Init.get(); |
| 4588 | Built.Inc = Inc.get(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4589 | Built.LB = LB.get(); |
| 4590 | Built.UB = UB.get(); |
| 4591 | Built.IL = IL.get(); |
| 4592 | Built.ST = ST.get(); |
| 4593 | Built.EUB = EUB.get(); |
| 4594 | Built.NLB = NextLB.get(); |
| 4595 | Built.NUB = NextUB.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4596 | |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 4597 | return NestedLoopCount; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4598 | } |
| 4599 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4600 | static Expr *getCollapseNumberExpr(ArrayRef<OMPClause *> Clauses) { |
Benjamin Kramer | fc600dc | 2015-08-30 15:12:28 +0000 | [diff] [blame] | 4601 | auto CollapseClauses = |
| 4602 | OMPExecutableDirective::getClausesOfKind<OMPCollapseClause>(Clauses); |
| 4603 | if (CollapseClauses.begin() != CollapseClauses.end()) |
| 4604 | return (*CollapseClauses.begin())->getNumForLoops(); |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 4605 | return nullptr; |
| 4606 | } |
| 4607 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4608 | static Expr *getOrderedNumberExpr(ArrayRef<OMPClause *> Clauses) { |
Benjamin Kramer | fc600dc | 2015-08-30 15:12:28 +0000 | [diff] [blame] | 4609 | auto OrderedClauses = |
| 4610 | OMPExecutableDirective::getClausesOfKind<OMPOrderedClause>(Clauses); |
| 4611 | if (OrderedClauses.begin() != OrderedClauses.end()) |
| 4612 | return (*OrderedClauses.begin())->getNumForLoops(); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4613 | return nullptr; |
| 4614 | } |
| 4615 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 4616 | static bool checkSimdlenSafelenValues(Sema &S, const Expr *Simdlen, |
| 4617 | const Expr *Safelen) { |
| 4618 | llvm::APSInt SimdlenRes, SafelenRes; |
| 4619 | if (Simdlen->isValueDependent() || Simdlen->isTypeDependent() || |
| 4620 | Simdlen->isInstantiationDependent() || |
| 4621 | Simdlen->containsUnexpandedParameterPack()) |
| 4622 | return false; |
| 4623 | if (Safelen->isValueDependent() || Safelen->isTypeDependent() || |
| 4624 | Safelen->isInstantiationDependent() || |
| 4625 | Safelen->containsUnexpandedParameterPack()) |
| 4626 | return false; |
| 4627 | Simdlen->EvaluateAsInt(SimdlenRes, S.Context); |
| 4628 | Safelen->EvaluateAsInt(SafelenRes, S.Context); |
| 4629 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 4630 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 4631 | // parameter must be less than or equal to the value of the safelen parameter. |
| 4632 | if (SimdlenRes > SafelenRes) { |
| 4633 | S.Diag(Simdlen->getExprLoc(), diag::err_omp_wrong_simdlen_safelen_values) |
| 4634 | << Simdlen->getSourceRange() << Safelen->getSourceRange(); |
| 4635 | return true; |
| 4636 | } |
| 4637 | return false; |
| 4638 | } |
| 4639 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4640 | StmtResult Sema::ActOnOpenMPSimdDirective( |
| 4641 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4642 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 4643 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4644 | if (!AStmt) |
| 4645 | return StmtError(); |
| 4646 | |
| 4647 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4648 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4649 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4650 | // define the nested loops number. |
| 4651 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 4652 | OMPD_simd, getCollapseNumberExpr(Clauses), getOrderedNumberExpr(Clauses), |
| 4653 | AStmt, *this, *DSAStack, VarsWithImplicitDSA, B); |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 4654 | if (NestedLoopCount == 0) |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 4655 | return StmtError(); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 4656 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4657 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 4658 | "omp simd loop exprs were not built"); |
| 4659 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 4660 | if (!CurContext->isDependentContext()) { |
| 4661 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4662 | for (auto C : Clauses) { |
| 4663 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 4664 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 4665 | B.NumIterations, *this, CurScope)) |
| 4666 | return StmtError(); |
| 4667 | } |
| 4668 | } |
| 4669 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 4670 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 4671 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 4672 | // parameter must be less than or equal to the value of the safelen parameter. |
| 4673 | OMPSafelenClause *Safelen = nullptr; |
| 4674 | OMPSimdlenClause *Simdlen = nullptr; |
| 4675 | for (auto *Clause : Clauses) { |
| 4676 | if (Clause->getClauseKind() == OMPC_safelen) |
| 4677 | Safelen = cast<OMPSafelenClause>(Clause); |
| 4678 | else if (Clause->getClauseKind() == OMPC_simdlen) |
| 4679 | Simdlen = cast<OMPSimdlenClause>(Clause); |
| 4680 | if (Safelen && Simdlen) |
| 4681 | break; |
| 4682 | } |
| 4683 | if (Simdlen && Safelen && |
| 4684 | checkSimdlenSafelenValues(*this, Simdlen->getSimdlen(), |
| 4685 | Safelen->getSafelen())) |
| 4686 | return StmtError(); |
| 4687 | |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 4688 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4689 | return OMPSimdDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| 4690 | Clauses, AStmt, B); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 4691 | } |
| 4692 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4693 | StmtResult Sema::ActOnOpenMPForDirective( |
| 4694 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4695 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 4696 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4697 | if (!AStmt) |
| 4698 | return StmtError(); |
| 4699 | |
| 4700 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4701 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4702 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4703 | // define the nested loops number. |
| 4704 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 4705 | OMPD_for, getCollapseNumberExpr(Clauses), getOrderedNumberExpr(Clauses), |
| 4706 | AStmt, *this, *DSAStack, VarsWithImplicitDSA, B); |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 4707 | if (NestedLoopCount == 0) |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4708 | return StmtError(); |
| 4709 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4710 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 4711 | "omp for loop exprs were not built"); |
| 4712 | |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 4713 | if (!CurContext->isDependentContext()) { |
| 4714 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4715 | for (auto C : Clauses) { |
| 4716 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 4717 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 4718 | B.NumIterations, *this, CurScope)) |
| 4719 | return StmtError(); |
| 4720 | } |
| 4721 | } |
| 4722 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4723 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4724 | return OMPForDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4725 | Clauses, AStmt, B, DSAStack->isCancelRegion()); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4726 | } |
| 4727 | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4728 | StmtResult Sema::ActOnOpenMPForSimdDirective( |
| 4729 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4730 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 4731 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4732 | if (!AStmt) |
| 4733 | return StmtError(); |
| 4734 | |
| 4735 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4736 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4737 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4738 | // define the nested loops number. |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4739 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4740 | CheckOpenMPLoop(OMPD_for_simd, getCollapseNumberExpr(Clauses), |
| 4741 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 4742 | VarsWithImplicitDSA, B); |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4743 | if (NestedLoopCount == 0) |
| 4744 | return StmtError(); |
| 4745 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4746 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 4747 | "omp for simd loop exprs were not built"); |
| 4748 | |
Alexey Bataev | 58e5bdb | 2015-06-18 04:45:29 +0000 | [diff] [blame] | 4749 | if (!CurContext->isDependentContext()) { |
| 4750 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4751 | for (auto C : Clauses) { |
| 4752 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 4753 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 4754 | B.NumIterations, *this, CurScope)) |
| 4755 | return StmtError(); |
| 4756 | } |
| 4757 | } |
| 4758 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 4759 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 4760 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 4761 | // parameter must be less than or equal to the value of the safelen parameter. |
| 4762 | OMPSafelenClause *Safelen = nullptr; |
| 4763 | OMPSimdlenClause *Simdlen = nullptr; |
| 4764 | for (auto *Clause : Clauses) { |
| 4765 | if (Clause->getClauseKind() == OMPC_safelen) |
| 4766 | Safelen = cast<OMPSafelenClause>(Clause); |
| 4767 | else if (Clause->getClauseKind() == OMPC_simdlen) |
| 4768 | Simdlen = cast<OMPSimdlenClause>(Clause); |
| 4769 | if (Safelen && Simdlen) |
| 4770 | break; |
| 4771 | } |
| 4772 | if (Simdlen && Safelen && |
| 4773 | checkSimdlenSafelenValues(*this, Simdlen->getSimdlen(), |
| 4774 | Safelen->getSafelen())) |
| 4775 | return StmtError(); |
| 4776 | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4777 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4778 | return OMPForSimdDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| 4779 | Clauses, AStmt, B); |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4780 | } |
| 4781 | |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4782 | StmtResult Sema::ActOnOpenMPSectionsDirective(ArrayRef<OMPClause *> Clauses, |
| 4783 | Stmt *AStmt, |
| 4784 | SourceLocation StartLoc, |
| 4785 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4786 | if (!AStmt) |
| 4787 | return StmtError(); |
| 4788 | |
| 4789 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4790 | auto BaseStmt = AStmt; |
| 4791 | while (CapturedStmt *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt)) |
| 4792 | BaseStmt = CS->getCapturedStmt(); |
| 4793 | if (auto C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) { |
| 4794 | auto S = C->children(); |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 4795 | if (S.begin() == S.end()) |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4796 | return StmtError(); |
| 4797 | // All associated statements must be '#pragma omp section' except for |
| 4798 | // the first one. |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 4799 | for (Stmt *SectionStmt : llvm::make_range(std::next(S.begin()), S.end())) { |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4800 | if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) { |
| 4801 | if (SectionStmt) |
| 4802 | Diag(SectionStmt->getLocStart(), |
| 4803 | diag::err_omp_sections_substmt_not_section); |
| 4804 | return StmtError(); |
| 4805 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4806 | cast<OMPSectionDirective>(SectionStmt) |
| 4807 | ->setHasCancel(DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4808 | } |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4809 | } else { |
| 4810 | Diag(AStmt->getLocStart(), diag::err_omp_sections_not_compound_stmt); |
| 4811 | return StmtError(); |
| 4812 | } |
| 4813 | |
| 4814 | getCurFunction()->setHasBranchProtectedScope(); |
| 4815 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4816 | return OMPSectionsDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 4817 | DSAStack->isCancelRegion()); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4818 | } |
| 4819 | |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4820 | StmtResult Sema::ActOnOpenMPSectionDirective(Stmt *AStmt, |
| 4821 | SourceLocation StartLoc, |
| 4822 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4823 | if (!AStmt) |
| 4824 | return StmtError(); |
| 4825 | |
| 4826 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4827 | |
| 4828 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4829 | DSAStack->setParentCancelRegion(DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4830 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4831 | return OMPSectionDirective::Create(Context, StartLoc, EndLoc, AStmt, |
| 4832 | DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4833 | } |
| 4834 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 4835 | StmtResult Sema::ActOnOpenMPSingleDirective(ArrayRef<OMPClause *> Clauses, |
| 4836 | Stmt *AStmt, |
| 4837 | SourceLocation StartLoc, |
| 4838 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4839 | if (!AStmt) |
| 4840 | return StmtError(); |
| 4841 | |
| 4842 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 74a05c9 | 2014-07-15 02:55:09 +0000 | [diff] [blame] | 4843 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 4844 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | 74a05c9 | 2014-07-15 02:55:09 +0000 | [diff] [blame] | 4845 | |
Alexey Bataev | 3255bf3 | 2015-01-19 05:20:46 +0000 | [diff] [blame] | 4846 | // OpenMP [2.7.3, single Construct, Restrictions] |
| 4847 | // The copyprivate clause must not be used with the nowait clause. |
| 4848 | OMPClause *Nowait = nullptr; |
| 4849 | OMPClause *Copyprivate = nullptr; |
| 4850 | for (auto *Clause : Clauses) { |
| 4851 | if (Clause->getClauseKind() == OMPC_nowait) |
| 4852 | Nowait = Clause; |
| 4853 | else if (Clause->getClauseKind() == OMPC_copyprivate) |
| 4854 | Copyprivate = Clause; |
| 4855 | if (Copyprivate && Nowait) { |
| 4856 | Diag(Copyprivate->getLocStart(), |
| 4857 | diag::err_omp_single_copyprivate_with_nowait); |
| 4858 | Diag(Nowait->getLocStart(), diag::note_omp_nowait_clause_here); |
| 4859 | return StmtError(); |
| 4860 | } |
| 4861 | } |
| 4862 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 4863 | return OMPSingleDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 4864 | } |
| 4865 | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 4866 | StmtResult Sema::ActOnOpenMPMasterDirective(Stmt *AStmt, |
| 4867 | SourceLocation StartLoc, |
| 4868 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4869 | if (!AStmt) |
| 4870 | return StmtError(); |
| 4871 | |
| 4872 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 4873 | |
| 4874 | getCurFunction()->setHasBranchProtectedScope(); |
| 4875 | |
| 4876 | return OMPMasterDirective::Create(Context, StartLoc, EndLoc, AStmt); |
| 4877 | } |
| 4878 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 4879 | StmtResult Sema::ActOnOpenMPCriticalDirective( |
| 4880 | const DeclarationNameInfo &DirName, ArrayRef<OMPClause *> Clauses, |
| 4881 | Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4882 | if (!AStmt) |
| 4883 | return StmtError(); |
| 4884 | |
| 4885 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 4886 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 4887 | bool ErrorFound = false; |
| 4888 | llvm::APSInt Hint; |
| 4889 | SourceLocation HintLoc; |
| 4890 | bool DependentHint = false; |
| 4891 | for (auto *C : Clauses) { |
| 4892 | if (C->getClauseKind() == OMPC_hint) { |
| 4893 | if (!DirName.getName()) { |
| 4894 | Diag(C->getLocStart(), diag::err_omp_hint_clause_no_name); |
| 4895 | ErrorFound = true; |
| 4896 | } |
| 4897 | Expr *E = cast<OMPHintClause>(C)->getHint(); |
| 4898 | if (E->isTypeDependent() || E->isValueDependent() || |
| 4899 | E->isInstantiationDependent()) |
| 4900 | DependentHint = true; |
| 4901 | else { |
| 4902 | Hint = E->EvaluateKnownConstInt(Context); |
| 4903 | HintLoc = C->getLocStart(); |
| 4904 | } |
| 4905 | } |
| 4906 | } |
| 4907 | if (ErrorFound) |
| 4908 | return StmtError(); |
| 4909 | auto Pair = DSAStack->getCriticalWithHint(DirName); |
| 4910 | if (Pair.first && DirName.getName() && !DependentHint) { |
| 4911 | if (llvm::APSInt::compareValues(Hint, Pair.second) != 0) { |
| 4912 | Diag(StartLoc, diag::err_omp_critical_with_hint); |
| 4913 | if (HintLoc.isValid()) { |
| 4914 | Diag(HintLoc, diag::note_omp_critical_hint_here) |
| 4915 | << 0 << Hint.toString(/*Radix=*/10, /*Signed=*/false); |
| 4916 | } else |
| 4917 | Diag(StartLoc, diag::note_omp_critical_no_hint) << 0; |
| 4918 | if (auto *C = Pair.first->getSingleClause<OMPHintClause>()) { |
| 4919 | Diag(C->getLocStart(), diag::note_omp_critical_hint_here) |
| 4920 | << 1 |
| 4921 | << C->getHint()->EvaluateKnownConstInt(Context).toString( |
| 4922 | /*Radix=*/10, /*Signed=*/false); |
| 4923 | } else |
| 4924 | Diag(Pair.first->getLocStart(), diag::note_omp_critical_no_hint) << 1; |
| 4925 | } |
| 4926 | } |
| 4927 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 4928 | getCurFunction()->setHasBranchProtectedScope(); |
| 4929 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 4930 | auto *Dir = OMPCriticalDirective::Create(Context, DirName, StartLoc, EndLoc, |
| 4931 | Clauses, AStmt); |
| 4932 | if (!Pair.first && DirName.getName() && !DependentHint) |
| 4933 | DSAStack->addCriticalWithHint(Dir, Hint); |
| 4934 | return Dir; |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 4935 | } |
| 4936 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4937 | StmtResult Sema::ActOnOpenMPParallelForDirective( |
| 4938 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4939 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 4940 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4941 | if (!AStmt) |
| 4942 | return StmtError(); |
| 4943 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4944 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 4945 | // 1.2.2 OpenMP Language Terminology |
| 4946 | // Structured block - An executable statement with a single entry at the |
| 4947 | // top and a single exit at the bottom. |
| 4948 | // The point of exit cannot be a branch out of the structured block. |
| 4949 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 4950 | CS->getCapturedDecl()->setNothrow(); |
| 4951 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4952 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4953 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4954 | // define the nested loops number. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4955 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4956 | CheckOpenMPLoop(OMPD_parallel_for, getCollapseNumberExpr(Clauses), |
| 4957 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 4958 | VarsWithImplicitDSA, B); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4959 | if (NestedLoopCount == 0) |
| 4960 | return StmtError(); |
| 4961 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4962 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 4963 | "omp parallel for loop exprs were not built"); |
| 4964 | |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 4965 | if (!CurContext->isDependentContext()) { |
| 4966 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4967 | for (auto C : Clauses) { |
| 4968 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 4969 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 4970 | B.NumIterations, *this, CurScope)) |
| 4971 | return StmtError(); |
| 4972 | } |
| 4973 | } |
| 4974 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4975 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4976 | return OMPParallelForDirective::Create(Context, StartLoc, EndLoc, |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4977 | NestedLoopCount, Clauses, AStmt, B, |
| 4978 | DSAStack->isCancelRegion()); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4979 | } |
| 4980 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4981 | StmtResult Sema::ActOnOpenMPParallelForSimdDirective( |
| 4982 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4983 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 4984 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4985 | if (!AStmt) |
| 4986 | return StmtError(); |
| 4987 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4988 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 4989 | // 1.2.2 OpenMP Language Terminology |
| 4990 | // Structured block - An executable statement with a single entry at the |
| 4991 | // top and a single exit at the bottom. |
| 4992 | // The point of exit cannot be a branch out of the structured block. |
| 4993 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 4994 | CS->getCapturedDecl()->setNothrow(); |
| 4995 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4996 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4997 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4998 | // define the nested loops number. |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4999 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5000 | CheckOpenMPLoop(OMPD_parallel_for_simd, getCollapseNumberExpr(Clauses), |
| 5001 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 5002 | VarsWithImplicitDSA, B); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 5003 | if (NestedLoopCount == 0) |
| 5004 | return StmtError(); |
| 5005 | |
Alexey Bataev | 3b5b5c4 | 2015-06-18 10:10:12 +0000 | [diff] [blame] | 5006 | if (!CurContext->isDependentContext()) { |
| 5007 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 5008 | for (auto C : Clauses) { |
| 5009 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 5010 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 5011 | B.NumIterations, *this, CurScope)) |
| 5012 | return StmtError(); |
| 5013 | } |
| 5014 | } |
| 5015 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 5016 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 5017 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 5018 | // parameter must be less than or equal to the value of the safelen parameter. |
| 5019 | OMPSafelenClause *Safelen = nullptr; |
| 5020 | OMPSimdlenClause *Simdlen = nullptr; |
| 5021 | for (auto *Clause : Clauses) { |
| 5022 | if (Clause->getClauseKind() == OMPC_safelen) |
| 5023 | Safelen = cast<OMPSafelenClause>(Clause); |
| 5024 | else if (Clause->getClauseKind() == OMPC_simdlen) |
| 5025 | Simdlen = cast<OMPSimdlenClause>(Clause); |
| 5026 | if (Safelen && Simdlen) |
| 5027 | break; |
| 5028 | } |
| 5029 | if (Simdlen && Safelen && |
| 5030 | checkSimdlenSafelenValues(*this, Simdlen->getSimdlen(), |
| 5031 | Safelen->getSafelen())) |
| 5032 | return StmtError(); |
| 5033 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 5034 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5035 | return OMPParallelForSimdDirective::Create( |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5036 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 5037 | } |
| 5038 | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 5039 | StmtResult |
| 5040 | Sema::ActOnOpenMPParallelSectionsDirective(ArrayRef<OMPClause *> Clauses, |
| 5041 | Stmt *AStmt, SourceLocation StartLoc, |
| 5042 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5043 | if (!AStmt) |
| 5044 | return StmtError(); |
| 5045 | |
| 5046 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 5047 | auto BaseStmt = AStmt; |
| 5048 | while (CapturedStmt *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt)) |
| 5049 | BaseStmt = CS->getCapturedStmt(); |
| 5050 | if (auto C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) { |
| 5051 | auto S = C->children(); |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 5052 | if (S.begin() == S.end()) |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 5053 | return StmtError(); |
| 5054 | // All associated statements must be '#pragma omp section' except for |
| 5055 | // the first one. |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 5056 | for (Stmt *SectionStmt : llvm::make_range(std::next(S.begin()), S.end())) { |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 5057 | if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) { |
| 5058 | if (SectionStmt) |
| 5059 | Diag(SectionStmt->getLocStart(), |
| 5060 | diag::err_omp_parallel_sections_substmt_not_section); |
| 5061 | return StmtError(); |
| 5062 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 5063 | cast<OMPSectionDirective>(SectionStmt) |
| 5064 | ->setHasCancel(DSAStack->isCancelRegion()); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 5065 | } |
| 5066 | } else { |
| 5067 | Diag(AStmt->getLocStart(), |
| 5068 | diag::err_omp_parallel_sections_not_compound_stmt); |
| 5069 | return StmtError(); |
| 5070 | } |
| 5071 | |
| 5072 | getCurFunction()->setHasBranchProtectedScope(); |
| 5073 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 5074 | return OMPParallelSectionsDirective::Create( |
| 5075 | Context, StartLoc, EndLoc, Clauses, AStmt, DSAStack->isCancelRegion()); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 5076 | } |
| 5077 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5078 | StmtResult Sema::ActOnOpenMPTaskDirective(ArrayRef<OMPClause *> Clauses, |
| 5079 | Stmt *AStmt, SourceLocation StartLoc, |
| 5080 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5081 | if (!AStmt) |
| 5082 | return StmtError(); |
| 5083 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5084 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 5085 | // 1.2.2 OpenMP Language Terminology |
| 5086 | // Structured block - An executable statement with a single entry at the |
| 5087 | // top and a single exit at the bottom. |
| 5088 | // The point of exit cannot be a branch out of the structured block. |
| 5089 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5090 | CS->getCapturedDecl()->setNothrow(); |
| 5091 | |
| 5092 | getCurFunction()->setHasBranchProtectedScope(); |
| 5093 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 5094 | return OMPTaskDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 5095 | DSAStack->isCancelRegion()); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5096 | } |
| 5097 | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 5098 | StmtResult Sema::ActOnOpenMPTaskyieldDirective(SourceLocation StartLoc, |
| 5099 | SourceLocation EndLoc) { |
| 5100 | return OMPTaskyieldDirective::Create(Context, StartLoc, EndLoc); |
| 5101 | } |
| 5102 | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 5103 | StmtResult Sema::ActOnOpenMPBarrierDirective(SourceLocation StartLoc, |
| 5104 | SourceLocation EndLoc) { |
| 5105 | return OMPBarrierDirective::Create(Context, StartLoc, EndLoc); |
| 5106 | } |
| 5107 | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 5108 | StmtResult Sema::ActOnOpenMPTaskwaitDirective(SourceLocation StartLoc, |
| 5109 | SourceLocation EndLoc) { |
| 5110 | return OMPTaskwaitDirective::Create(Context, StartLoc, EndLoc); |
| 5111 | } |
| 5112 | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 5113 | StmtResult Sema::ActOnOpenMPTaskgroupDirective(Stmt *AStmt, |
| 5114 | SourceLocation StartLoc, |
| 5115 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5116 | if (!AStmt) |
| 5117 | return StmtError(); |
| 5118 | |
| 5119 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 5120 | |
| 5121 | getCurFunction()->setHasBranchProtectedScope(); |
| 5122 | |
| 5123 | return OMPTaskgroupDirective::Create(Context, StartLoc, EndLoc, AStmt); |
| 5124 | } |
| 5125 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 5126 | StmtResult Sema::ActOnOpenMPFlushDirective(ArrayRef<OMPClause *> Clauses, |
| 5127 | SourceLocation StartLoc, |
| 5128 | SourceLocation EndLoc) { |
| 5129 | assert(Clauses.size() <= 1 && "Extra clauses in flush directive"); |
| 5130 | return OMPFlushDirective::Create(Context, StartLoc, EndLoc, Clauses); |
| 5131 | } |
| 5132 | |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5133 | StmtResult Sema::ActOnOpenMPOrderedDirective(ArrayRef<OMPClause *> Clauses, |
| 5134 | Stmt *AStmt, |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 5135 | SourceLocation StartLoc, |
| 5136 | SourceLocation EndLoc) { |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5137 | OMPClause *DependFound = nullptr; |
| 5138 | OMPClause *DependSourceClause = nullptr; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 5139 | OMPClause *DependSinkClause = nullptr; |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5140 | bool ErrorFound = false; |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5141 | OMPThreadsClause *TC = nullptr; |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5142 | OMPSIMDClause *SC = nullptr; |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5143 | for (auto *C : Clauses) { |
| 5144 | if (auto *DC = dyn_cast<OMPDependClause>(C)) { |
| 5145 | DependFound = C; |
| 5146 | if (DC->getDependencyKind() == OMPC_DEPEND_source) { |
| 5147 | if (DependSourceClause) { |
| 5148 | Diag(C->getLocStart(), diag::err_omp_more_one_clause) |
| 5149 | << getOpenMPDirectiveName(OMPD_ordered) |
| 5150 | << getOpenMPClauseName(OMPC_depend) << 2; |
| 5151 | ErrorFound = true; |
| 5152 | } else |
| 5153 | DependSourceClause = C; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 5154 | if (DependSinkClause) { |
| 5155 | Diag(C->getLocStart(), diag::err_omp_depend_sink_source_not_allowed) |
| 5156 | << 0; |
| 5157 | ErrorFound = true; |
| 5158 | } |
| 5159 | } else if (DC->getDependencyKind() == OMPC_DEPEND_sink) { |
| 5160 | if (DependSourceClause) { |
| 5161 | Diag(C->getLocStart(), diag::err_omp_depend_sink_source_not_allowed) |
| 5162 | << 1; |
| 5163 | ErrorFound = true; |
| 5164 | } |
| 5165 | DependSinkClause = C; |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5166 | } |
| 5167 | } else if (C->getClauseKind() == OMPC_threads) |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5168 | TC = cast<OMPThreadsClause>(C); |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5169 | else if (C->getClauseKind() == OMPC_simd) |
| 5170 | SC = cast<OMPSIMDClause>(C); |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5171 | } |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5172 | if (!ErrorFound && !SC && |
| 5173 | isOpenMPSimdDirective(DSAStack->getParentDirective())) { |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5174 | // OpenMP [2.8.1,simd Construct, Restrictions] |
| 5175 | // An ordered construct with the simd clause is the only OpenMP construct |
| 5176 | // that can appear in the simd region. |
| 5177 | Diag(StartLoc, diag::err_omp_prohibited_region_simd); |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5178 | ErrorFound = true; |
| 5179 | } else if (DependFound && (TC || SC)) { |
| 5180 | Diag(DependFound->getLocStart(), diag::err_omp_depend_clause_thread_simd) |
| 5181 | << getOpenMPClauseName(TC ? TC->getClauseKind() : SC->getClauseKind()); |
| 5182 | ErrorFound = true; |
| 5183 | } else if (DependFound && !DSAStack->getParentOrderedRegionParam()) { |
| 5184 | Diag(DependFound->getLocStart(), |
| 5185 | diag::err_omp_ordered_directive_without_param); |
| 5186 | ErrorFound = true; |
| 5187 | } else if (TC || Clauses.empty()) { |
| 5188 | if (auto *Param = DSAStack->getParentOrderedRegionParam()) { |
| 5189 | SourceLocation ErrLoc = TC ? TC->getLocStart() : StartLoc; |
| 5190 | Diag(ErrLoc, diag::err_omp_ordered_directive_with_param) |
| 5191 | << (TC != nullptr); |
| 5192 | Diag(Param->getLocStart(), diag::note_omp_ordered_param); |
| 5193 | ErrorFound = true; |
| 5194 | } |
| 5195 | } |
| 5196 | if ((!AStmt && !DependFound) || ErrorFound) |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5197 | return StmtError(); |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5198 | |
| 5199 | if (AStmt) { |
| 5200 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 5201 | |
| 5202 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5203 | } |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5204 | |
| 5205 | return OMPOrderedDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 5206 | } |
| 5207 | |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5208 | namespace { |
| 5209 | /// \brief Helper class for checking expression in 'omp atomic [update]' |
| 5210 | /// construct. |
| 5211 | class OpenMPAtomicUpdateChecker { |
| 5212 | /// \brief Error results for atomic update expressions. |
| 5213 | enum ExprAnalysisErrorCode { |
| 5214 | /// \brief A statement is not an expression statement. |
| 5215 | NotAnExpression, |
| 5216 | /// \brief Expression is not builtin binary or unary operation. |
| 5217 | NotABinaryOrUnaryExpression, |
| 5218 | /// \brief Unary operation is not post-/pre- increment/decrement operation. |
| 5219 | NotAnUnaryIncDecExpression, |
| 5220 | /// \brief An expression is not of scalar type. |
| 5221 | NotAScalarType, |
| 5222 | /// \brief A binary operation is not an assignment operation. |
| 5223 | NotAnAssignmentOp, |
| 5224 | /// \brief RHS part of the binary operation is not a binary expression. |
| 5225 | NotABinaryExpression, |
| 5226 | /// \brief RHS part is not additive/multiplicative/shift/biwise binary |
| 5227 | /// expression. |
| 5228 | NotABinaryOperator, |
| 5229 | /// \brief RHS binary operation does not have reference to the updated LHS |
| 5230 | /// part. |
| 5231 | NotAnUpdateExpression, |
| 5232 | /// \brief No errors is found. |
| 5233 | NoError |
| 5234 | }; |
| 5235 | /// \brief Reference to Sema. |
| 5236 | Sema &SemaRef; |
| 5237 | /// \brief A location for note diagnostics (when error is found). |
| 5238 | SourceLocation NoteLoc; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5239 | /// \brief 'x' lvalue part of the source atomic expression. |
| 5240 | Expr *X; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5241 | /// \brief 'expr' rvalue part of the source atomic expression. |
| 5242 | Expr *E; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5243 | /// \brief Helper expression of the form |
| 5244 | /// 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or |
| 5245 | /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'. |
| 5246 | Expr *UpdateExpr; |
| 5247 | /// \brief Is 'x' a LHS in a RHS part of full update expression. It is |
| 5248 | /// important for non-associative operations. |
| 5249 | bool IsXLHSInRHSPart; |
| 5250 | BinaryOperatorKind Op; |
| 5251 | SourceLocation OpLoc; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5252 | /// \brief true if the source expression is a postfix unary operation, false |
| 5253 | /// if it is a prefix unary operation. |
| 5254 | bool IsPostfixUpdate; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5255 | |
| 5256 | public: |
| 5257 | OpenMPAtomicUpdateChecker(Sema &SemaRef) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5258 | : SemaRef(SemaRef), X(nullptr), E(nullptr), UpdateExpr(nullptr), |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5259 | IsXLHSInRHSPart(false), Op(BO_PtrMemD), IsPostfixUpdate(false) {} |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5260 | /// \brief Check specified statement that it is suitable for 'atomic update' |
| 5261 | /// constructs and extract 'x', 'expr' and Operation from the original |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5262 | /// expression. If DiagId and NoteId == 0, then only check is performed |
| 5263 | /// without error notification. |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5264 | /// \param DiagId Diagnostic which should be emitted if error is found. |
| 5265 | /// \param NoteId Diagnostic note for the main error message. |
| 5266 | /// \return true if statement is not an update expression, false otherwise. |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5267 | bool checkStatement(Stmt *S, unsigned DiagId = 0, unsigned NoteId = 0); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5268 | /// \brief Return the 'x' lvalue part of the source atomic expression. |
| 5269 | Expr *getX() const { return X; } |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5270 | /// \brief Return the 'expr' rvalue part of the source atomic expression. |
| 5271 | Expr *getExpr() const { return E; } |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5272 | /// \brief Return the update expression used in calculation of the updated |
| 5273 | /// value. Always has form 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or |
| 5274 | /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'. |
| 5275 | Expr *getUpdateExpr() const { return UpdateExpr; } |
| 5276 | /// \brief Return true if 'x' is LHS in RHS part of full update expression, |
| 5277 | /// false otherwise. |
| 5278 | bool isXLHSInRHSPart() const { return IsXLHSInRHSPart; } |
| 5279 | |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5280 | /// \brief true if the source expression is a postfix unary operation, false |
| 5281 | /// if it is a prefix unary operation. |
| 5282 | bool isPostfixUpdate() const { return IsPostfixUpdate; } |
| 5283 | |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5284 | private: |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5285 | bool checkBinaryOperation(BinaryOperator *AtomicBinOp, unsigned DiagId = 0, |
| 5286 | unsigned NoteId = 0); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5287 | }; |
| 5288 | } // namespace |
| 5289 | |
| 5290 | bool OpenMPAtomicUpdateChecker::checkBinaryOperation( |
| 5291 | BinaryOperator *AtomicBinOp, unsigned DiagId, unsigned NoteId) { |
| 5292 | ExprAnalysisErrorCode ErrorFound = NoError; |
| 5293 | SourceLocation ErrorLoc, NoteLoc; |
| 5294 | SourceRange ErrorRange, NoteRange; |
| 5295 | // Allowed constructs are: |
| 5296 | // x = x binop expr; |
| 5297 | // x = expr binop x; |
| 5298 | if (AtomicBinOp->getOpcode() == BO_Assign) { |
| 5299 | X = AtomicBinOp->getLHS(); |
| 5300 | if (auto *AtomicInnerBinOp = dyn_cast<BinaryOperator>( |
| 5301 | AtomicBinOp->getRHS()->IgnoreParenImpCasts())) { |
| 5302 | if (AtomicInnerBinOp->isMultiplicativeOp() || |
| 5303 | AtomicInnerBinOp->isAdditiveOp() || AtomicInnerBinOp->isShiftOp() || |
| 5304 | AtomicInnerBinOp->isBitwiseOp()) { |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5305 | Op = AtomicInnerBinOp->getOpcode(); |
| 5306 | OpLoc = AtomicInnerBinOp->getOperatorLoc(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5307 | auto *LHS = AtomicInnerBinOp->getLHS(); |
| 5308 | auto *RHS = AtomicInnerBinOp->getRHS(); |
| 5309 | llvm::FoldingSetNodeID XId, LHSId, RHSId; |
| 5310 | X->IgnoreParenImpCasts()->Profile(XId, SemaRef.getASTContext(), |
| 5311 | /*Canonical=*/true); |
| 5312 | LHS->IgnoreParenImpCasts()->Profile(LHSId, SemaRef.getASTContext(), |
| 5313 | /*Canonical=*/true); |
| 5314 | RHS->IgnoreParenImpCasts()->Profile(RHSId, SemaRef.getASTContext(), |
| 5315 | /*Canonical=*/true); |
| 5316 | if (XId == LHSId) { |
| 5317 | E = RHS; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5318 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5319 | } else if (XId == RHSId) { |
| 5320 | E = LHS; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5321 | IsXLHSInRHSPart = false; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5322 | } else { |
| 5323 | ErrorLoc = AtomicInnerBinOp->getExprLoc(); |
| 5324 | ErrorRange = AtomicInnerBinOp->getSourceRange(); |
| 5325 | NoteLoc = X->getExprLoc(); |
| 5326 | NoteRange = X->getSourceRange(); |
| 5327 | ErrorFound = NotAnUpdateExpression; |
| 5328 | } |
| 5329 | } else { |
| 5330 | ErrorLoc = AtomicInnerBinOp->getExprLoc(); |
| 5331 | ErrorRange = AtomicInnerBinOp->getSourceRange(); |
| 5332 | NoteLoc = AtomicInnerBinOp->getOperatorLoc(); |
| 5333 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 5334 | ErrorFound = NotABinaryOperator; |
| 5335 | } |
| 5336 | } else { |
| 5337 | NoteLoc = ErrorLoc = AtomicBinOp->getRHS()->getExprLoc(); |
| 5338 | NoteRange = ErrorRange = AtomicBinOp->getRHS()->getSourceRange(); |
| 5339 | ErrorFound = NotABinaryExpression; |
| 5340 | } |
| 5341 | } else { |
| 5342 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5343 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5344 | NoteLoc = AtomicBinOp->getOperatorLoc(); |
| 5345 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 5346 | ErrorFound = NotAnAssignmentOp; |
| 5347 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5348 | if (ErrorFound != NoError && DiagId != 0 && NoteId != 0) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5349 | SemaRef.Diag(ErrorLoc, DiagId) << ErrorRange; |
| 5350 | SemaRef.Diag(NoteLoc, NoteId) << ErrorFound << NoteRange; |
| 5351 | return true; |
| 5352 | } else if (SemaRef.CurContext->isDependentContext()) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5353 | E = X = UpdateExpr = nullptr; |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5354 | return ErrorFound != NoError; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5355 | } |
| 5356 | |
| 5357 | bool OpenMPAtomicUpdateChecker::checkStatement(Stmt *S, unsigned DiagId, |
| 5358 | unsigned NoteId) { |
| 5359 | ExprAnalysisErrorCode ErrorFound = NoError; |
| 5360 | SourceLocation ErrorLoc, NoteLoc; |
| 5361 | SourceRange ErrorRange, NoteRange; |
| 5362 | // Allowed constructs are: |
| 5363 | // x++; |
| 5364 | // x--; |
| 5365 | // ++x; |
| 5366 | // --x; |
| 5367 | // x binop= expr; |
| 5368 | // x = x binop expr; |
| 5369 | // x = expr binop x; |
| 5370 | if (auto *AtomicBody = dyn_cast<Expr>(S)) { |
| 5371 | AtomicBody = AtomicBody->IgnoreParenImpCasts(); |
| 5372 | if (AtomicBody->getType()->isScalarType() || |
| 5373 | AtomicBody->isInstantiationDependent()) { |
| 5374 | if (auto *AtomicCompAssignOp = dyn_cast<CompoundAssignOperator>( |
| 5375 | AtomicBody->IgnoreParenImpCasts())) { |
| 5376 | // Check for Compound Assignment Operation |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5377 | Op = BinaryOperator::getOpForCompoundAssignment( |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5378 | AtomicCompAssignOp->getOpcode()); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5379 | OpLoc = AtomicCompAssignOp->getOperatorLoc(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5380 | E = AtomicCompAssignOp->getRHS(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5381 | X = AtomicCompAssignOp->getLHS(); |
| 5382 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5383 | } else if (auto *AtomicBinOp = dyn_cast<BinaryOperator>( |
| 5384 | AtomicBody->IgnoreParenImpCasts())) { |
| 5385 | // Check for Binary Operation |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5386 | if(checkBinaryOperation(AtomicBinOp, DiagId, NoteId)) |
| 5387 | return true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5388 | } else if (auto *AtomicUnaryOp = |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5389 | dyn_cast<UnaryOperator>(AtomicBody->IgnoreParenImpCasts())) { |
| 5390 | // Check for Unary Operation |
| 5391 | if (AtomicUnaryOp->isIncrementDecrementOp()) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5392 | IsPostfixUpdate = AtomicUnaryOp->isPostfix(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5393 | Op = AtomicUnaryOp->isIncrementOp() ? BO_Add : BO_Sub; |
| 5394 | OpLoc = AtomicUnaryOp->getOperatorLoc(); |
| 5395 | X = AtomicUnaryOp->getSubExpr(); |
| 5396 | E = SemaRef.ActOnIntegerConstant(OpLoc, /*uint64_t Val=*/1).get(); |
| 5397 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5398 | } else { |
| 5399 | ErrorFound = NotAnUnaryIncDecExpression; |
| 5400 | ErrorLoc = AtomicUnaryOp->getExprLoc(); |
| 5401 | ErrorRange = AtomicUnaryOp->getSourceRange(); |
| 5402 | NoteLoc = AtomicUnaryOp->getOperatorLoc(); |
| 5403 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 5404 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5405 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5406 | ErrorFound = NotABinaryOrUnaryExpression; |
| 5407 | NoteLoc = ErrorLoc = AtomicBody->getExprLoc(); |
| 5408 | NoteRange = ErrorRange = AtomicBody->getSourceRange(); |
| 5409 | } |
| 5410 | } else { |
| 5411 | ErrorFound = NotAScalarType; |
| 5412 | NoteLoc = ErrorLoc = AtomicBody->getLocStart(); |
| 5413 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
| 5414 | } |
| 5415 | } else { |
| 5416 | ErrorFound = NotAnExpression; |
| 5417 | NoteLoc = ErrorLoc = S->getLocStart(); |
| 5418 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
| 5419 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5420 | if (ErrorFound != NoError && DiagId != 0 && NoteId != 0) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5421 | SemaRef.Diag(ErrorLoc, DiagId) << ErrorRange; |
| 5422 | SemaRef.Diag(NoteLoc, NoteId) << ErrorFound << NoteRange; |
| 5423 | return true; |
| 5424 | } else if (SemaRef.CurContext->isDependentContext()) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5425 | E = X = UpdateExpr = nullptr; |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5426 | if (ErrorFound == NoError && E && X) { |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5427 | // Build an update expression of form 'OpaqueValueExpr(x) binop |
| 5428 | // OpaqueValueExpr(expr)' or 'OpaqueValueExpr(expr) binop |
| 5429 | // OpaqueValueExpr(x)' and then cast it to the type of the 'x' expression. |
| 5430 | auto *OVEX = new (SemaRef.getASTContext()) |
| 5431 | OpaqueValueExpr(X->getExprLoc(), X->getType(), VK_RValue); |
| 5432 | auto *OVEExpr = new (SemaRef.getASTContext()) |
| 5433 | OpaqueValueExpr(E->getExprLoc(), E->getType(), VK_RValue); |
| 5434 | auto Update = |
| 5435 | SemaRef.CreateBuiltinBinOp(OpLoc, Op, IsXLHSInRHSPart ? OVEX : OVEExpr, |
| 5436 | IsXLHSInRHSPart ? OVEExpr : OVEX); |
| 5437 | if (Update.isInvalid()) |
| 5438 | return true; |
| 5439 | Update = SemaRef.PerformImplicitConversion(Update.get(), X->getType(), |
| 5440 | Sema::AA_Casting); |
| 5441 | if (Update.isInvalid()) |
| 5442 | return true; |
| 5443 | UpdateExpr = Update.get(); |
| 5444 | } |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5445 | return ErrorFound != NoError; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5446 | } |
| 5447 | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 5448 | StmtResult Sema::ActOnOpenMPAtomicDirective(ArrayRef<OMPClause *> Clauses, |
| 5449 | Stmt *AStmt, |
| 5450 | SourceLocation StartLoc, |
| 5451 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5452 | if (!AStmt) |
| 5453 | return StmtError(); |
| 5454 | |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5455 | auto CS = cast<CapturedStmt>(AStmt); |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 5456 | // 1.2.2 OpenMP Language Terminology |
| 5457 | // Structured block - An executable statement with a single entry at the |
| 5458 | // top and a single exit at the bottom. |
| 5459 | // The point of exit cannot be a branch out of the structured block. |
| 5460 | // longjmp() and throw() must not violate the entry/exit criteria. |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5461 | OpenMPClauseKind AtomicKind = OMPC_unknown; |
| 5462 | SourceLocation AtomicKindLoc; |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5463 | for (auto *C : Clauses) { |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5464 | if (C->getClauseKind() == OMPC_read || C->getClauseKind() == OMPC_write || |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5465 | C->getClauseKind() == OMPC_update || |
| 5466 | C->getClauseKind() == OMPC_capture) { |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5467 | if (AtomicKind != OMPC_unknown) { |
| 5468 | Diag(C->getLocStart(), diag::err_omp_atomic_several_clauses) |
| 5469 | << SourceRange(C->getLocStart(), C->getLocEnd()); |
| 5470 | Diag(AtomicKindLoc, diag::note_omp_atomic_previous_clause) |
| 5471 | << getOpenMPClauseName(AtomicKind); |
| 5472 | } else { |
| 5473 | AtomicKind = C->getClauseKind(); |
| 5474 | AtomicKindLoc = C->getLocStart(); |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5475 | } |
| 5476 | } |
| 5477 | } |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5478 | |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5479 | auto Body = CS->getCapturedStmt(); |
Alexey Bataev | 10fec57 | 2015-03-11 04:48:56 +0000 | [diff] [blame] | 5480 | if (auto *EWC = dyn_cast<ExprWithCleanups>(Body)) |
| 5481 | Body = EWC->getSubExpr(); |
| 5482 | |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5483 | Expr *X = nullptr; |
| 5484 | Expr *V = nullptr; |
| 5485 | Expr *E = nullptr; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5486 | Expr *UE = nullptr; |
| 5487 | bool IsXLHSInRHSPart = false; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5488 | bool IsPostfixUpdate = false; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5489 | // OpenMP [2.12.6, atomic Construct] |
| 5490 | // In the next expressions: |
| 5491 | // * x and v (as applicable) are both l-value expressions with scalar type. |
| 5492 | // * During the execution of an atomic region, multiple syntactic |
| 5493 | // occurrences of x must designate the same storage location. |
| 5494 | // * Neither of v and expr (as applicable) may access the storage location |
| 5495 | // designated by x. |
| 5496 | // * Neither of x and expr (as applicable) may access the storage location |
| 5497 | // designated by v. |
| 5498 | // * expr is an expression with scalar type. |
| 5499 | // * binop is one of +, *, -, /, &, ^, |, <<, or >>. |
| 5500 | // * binop, binop=, ++, and -- are not overloaded operators. |
| 5501 | // * The expression x binop expr must be numerically equivalent to x binop |
| 5502 | // (expr). This requirement is satisfied if the operators in expr have |
| 5503 | // precedence greater than binop, or by using parentheses around expr or |
| 5504 | // subexpressions of expr. |
| 5505 | // * The expression expr binop x must be numerically equivalent to (expr) |
| 5506 | // binop x. This requirement is satisfied if the operators in expr have |
| 5507 | // precedence equal to or greater than binop, or by using parentheses around |
| 5508 | // expr or subexpressions of expr. |
| 5509 | // * For forms that allow multiple occurrences of x, the number of times |
| 5510 | // that x is evaluated is unspecified. |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5511 | if (AtomicKind == OMPC_read) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5512 | enum { |
| 5513 | NotAnExpression, |
| 5514 | NotAnAssignmentOp, |
| 5515 | NotAScalarType, |
| 5516 | NotAnLValue, |
| 5517 | NoError |
| 5518 | } ErrorFound = NoError; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5519 | SourceLocation ErrorLoc, NoteLoc; |
| 5520 | SourceRange ErrorRange, NoteRange; |
| 5521 | // If clause is read: |
| 5522 | // v = x; |
| 5523 | if (auto AtomicBody = dyn_cast<Expr>(Body)) { |
| 5524 | auto AtomicBinOp = |
| 5525 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 5526 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
| 5527 | X = AtomicBinOp->getRHS()->IgnoreParenImpCasts(); |
| 5528 | V = AtomicBinOp->getLHS()->IgnoreParenImpCasts(); |
| 5529 | if ((X->isInstantiationDependent() || X->getType()->isScalarType()) && |
| 5530 | (V->isInstantiationDependent() || V->getType()->isScalarType())) { |
| 5531 | if (!X->isLValue() || !V->isLValue()) { |
| 5532 | auto NotLValueExpr = X->isLValue() ? V : X; |
| 5533 | ErrorFound = NotAnLValue; |
| 5534 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5535 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5536 | NoteLoc = NotLValueExpr->getExprLoc(); |
| 5537 | NoteRange = NotLValueExpr->getSourceRange(); |
| 5538 | } |
| 5539 | } else if (!X->isInstantiationDependent() || |
| 5540 | !V->isInstantiationDependent()) { |
| 5541 | auto NotScalarExpr = |
| 5542 | (X->isInstantiationDependent() || X->getType()->isScalarType()) |
| 5543 | ? V |
| 5544 | : X; |
| 5545 | ErrorFound = NotAScalarType; |
| 5546 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5547 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5548 | NoteLoc = NotScalarExpr->getExprLoc(); |
| 5549 | NoteRange = NotScalarExpr->getSourceRange(); |
| 5550 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5551 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5552 | ErrorFound = NotAnAssignmentOp; |
| 5553 | ErrorLoc = AtomicBody->getExprLoc(); |
| 5554 | ErrorRange = AtomicBody->getSourceRange(); |
| 5555 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 5556 | : AtomicBody->getExprLoc(); |
| 5557 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 5558 | : AtomicBody->getSourceRange(); |
| 5559 | } |
| 5560 | } else { |
| 5561 | ErrorFound = NotAnExpression; |
| 5562 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 5563 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5564 | } |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5565 | if (ErrorFound != NoError) { |
| 5566 | Diag(ErrorLoc, diag::err_omp_atomic_read_not_expression_statement) |
| 5567 | << ErrorRange; |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5568 | Diag(NoteLoc, diag::note_omp_atomic_read_write) << ErrorFound |
| 5569 | << NoteRange; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5570 | return StmtError(); |
| 5571 | } else if (CurContext->isDependentContext()) |
| 5572 | V = X = nullptr; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5573 | } else if (AtomicKind == OMPC_write) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5574 | enum { |
| 5575 | NotAnExpression, |
| 5576 | NotAnAssignmentOp, |
| 5577 | NotAScalarType, |
| 5578 | NotAnLValue, |
| 5579 | NoError |
| 5580 | } ErrorFound = NoError; |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5581 | SourceLocation ErrorLoc, NoteLoc; |
| 5582 | SourceRange ErrorRange, NoteRange; |
| 5583 | // If clause is write: |
| 5584 | // x = expr; |
| 5585 | if (auto AtomicBody = dyn_cast<Expr>(Body)) { |
| 5586 | auto AtomicBinOp = |
| 5587 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 5588 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
Alexey Bataev | b832926 | 2015-02-27 06:33:30 +0000 | [diff] [blame] | 5589 | X = AtomicBinOp->getLHS(); |
| 5590 | E = AtomicBinOp->getRHS(); |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5591 | if ((X->isInstantiationDependent() || X->getType()->isScalarType()) && |
| 5592 | (E->isInstantiationDependent() || E->getType()->isScalarType())) { |
| 5593 | if (!X->isLValue()) { |
| 5594 | ErrorFound = NotAnLValue; |
| 5595 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5596 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5597 | NoteLoc = X->getExprLoc(); |
| 5598 | NoteRange = X->getSourceRange(); |
| 5599 | } |
| 5600 | } else if (!X->isInstantiationDependent() || |
| 5601 | !E->isInstantiationDependent()) { |
| 5602 | auto NotScalarExpr = |
| 5603 | (X->isInstantiationDependent() || X->getType()->isScalarType()) |
| 5604 | ? E |
| 5605 | : X; |
| 5606 | ErrorFound = NotAScalarType; |
| 5607 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5608 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5609 | NoteLoc = NotScalarExpr->getExprLoc(); |
| 5610 | NoteRange = NotScalarExpr->getSourceRange(); |
| 5611 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5612 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5613 | ErrorFound = NotAnAssignmentOp; |
| 5614 | ErrorLoc = AtomicBody->getExprLoc(); |
| 5615 | ErrorRange = AtomicBody->getSourceRange(); |
| 5616 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 5617 | : AtomicBody->getExprLoc(); |
| 5618 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 5619 | : AtomicBody->getSourceRange(); |
| 5620 | } |
| 5621 | } else { |
| 5622 | ErrorFound = NotAnExpression; |
| 5623 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 5624 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5625 | } |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5626 | if (ErrorFound != NoError) { |
| 5627 | Diag(ErrorLoc, diag::err_omp_atomic_write_not_expression_statement) |
| 5628 | << ErrorRange; |
| 5629 | Diag(NoteLoc, diag::note_omp_atomic_read_write) << ErrorFound |
| 5630 | << NoteRange; |
| 5631 | return StmtError(); |
| 5632 | } else if (CurContext->isDependentContext()) |
| 5633 | E = X = nullptr; |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5634 | } else if (AtomicKind == OMPC_update || AtomicKind == OMPC_unknown) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5635 | // If clause is update: |
| 5636 | // x++; |
| 5637 | // x--; |
| 5638 | // ++x; |
| 5639 | // --x; |
| 5640 | // x binop= expr; |
| 5641 | // x = x binop expr; |
| 5642 | // x = expr binop x; |
| 5643 | OpenMPAtomicUpdateChecker Checker(*this); |
| 5644 | if (Checker.checkStatement( |
| 5645 | Body, (AtomicKind == OMPC_update) |
| 5646 | ? diag::err_omp_atomic_update_not_expression_statement |
| 5647 | : diag::err_omp_atomic_not_expression_statement, |
| 5648 | diag::note_omp_atomic_update)) |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5649 | return StmtError(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5650 | if (!CurContext->isDependentContext()) { |
| 5651 | E = Checker.getExpr(); |
| 5652 | X = Checker.getX(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5653 | UE = Checker.getUpdateExpr(); |
| 5654 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5655 | } |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5656 | } else if (AtomicKind == OMPC_capture) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5657 | enum { |
| 5658 | NotAnAssignmentOp, |
| 5659 | NotACompoundStatement, |
| 5660 | NotTwoSubstatements, |
| 5661 | NotASpecificExpression, |
| 5662 | NoError |
| 5663 | } ErrorFound = NoError; |
| 5664 | SourceLocation ErrorLoc, NoteLoc; |
| 5665 | SourceRange ErrorRange, NoteRange; |
| 5666 | if (auto *AtomicBody = dyn_cast<Expr>(Body)) { |
| 5667 | // If clause is a capture: |
| 5668 | // v = x++; |
| 5669 | // v = x--; |
| 5670 | // v = ++x; |
| 5671 | // v = --x; |
| 5672 | // v = x binop= expr; |
| 5673 | // v = x = x binop expr; |
| 5674 | // v = x = expr binop x; |
| 5675 | auto *AtomicBinOp = |
| 5676 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 5677 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
| 5678 | V = AtomicBinOp->getLHS(); |
| 5679 | Body = AtomicBinOp->getRHS()->IgnoreParenImpCasts(); |
| 5680 | OpenMPAtomicUpdateChecker Checker(*this); |
| 5681 | if (Checker.checkStatement( |
| 5682 | Body, diag::err_omp_atomic_capture_not_expression_statement, |
| 5683 | diag::note_omp_atomic_update)) |
| 5684 | return StmtError(); |
| 5685 | E = Checker.getExpr(); |
| 5686 | X = Checker.getX(); |
| 5687 | UE = Checker.getUpdateExpr(); |
| 5688 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
| 5689 | IsPostfixUpdate = Checker.isPostfixUpdate(); |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5690 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5691 | ErrorLoc = AtomicBody->getExprLoc(); |
| 5692 | ErrorRange = AtomicBody->getSourceRange(); |
| 5693 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 5694 | : AtomicBody->getExprLoc(); |
| 5695 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 5696 | : AtomicBody->getSourceRange(); |
| 5697 | ErrorFound = NotAnAssignmentOp; |
| 5698 | } |
| 5699 | if (ErrorFound != NoError) { |
| 5700 | Diag(ErrorLoc, diag::err_omp_atomic_capture_not_expression_statement) |
| 5701 | << ErrorRange; |
| 5702 | Diag(NoteLoc, diag::note_omp_atomic_capture) << ErrorFound << NoteRange; |
| 5703 | return StmtError(); |
| 5704 | } else if (CurContext->isDependentContext()) { |
| 5705 | UE = V = E = X = nullptr; |
| 5706 | } |
| 5707 | } else { |
| 5708 | // If clause is a capture: |
| 5709 | // { v = x; x = expr; } |
| 5710 | // { v = x; x++; } |
| 5711 | // { v = x; x--; } |
| 5712 | // { v = x; ++x; } |
| 5713 | // { v = x; --x; } |
| 5714 | // { v = x; x binop= expr; } |
| 5715 | // { v = x; x = x binop expr; } |
| 5716 | // { v = x; x = expr binop x; } |
| 5717 | // { x++; v = x; } |
| 5718 | // { x--; v = x; } |
| 5719 | // { ++x; v = x; } |
| 5720 | // { --x; v = x; } |
| 5721 | // { x binop= expr; v = x; } |
| 5722 | // { x = x binop expr; v = x; } |
| 5723 | // { x = expr binop x; v = x; } |
| 5724 | if (auto *CS = dyn_cast<CompoundStmt>(Body)) { |
| 5725 | // Check that this is { expr1; expr2; } |
| 5726 | if (CS->size() == 2) { |
| 5727 | auto *First = CS->body_front(); |
| 5728 | auto *Second = CS->body_back(); |
| 5729 | if (auto *EWC = dyn_cast<ExprWithCleanups>(First)) |
| 5730 | First = EWC->getSubExpr()->IgnoreParenImpCasts(); |
| 5731 | if (auto *EWC = dyn_cast<ExprWithCleanups>(Second)) |
| 5732 | Second = EWC->getSubExpr()->IgnoreParenImpCasts(); |
| 5733 | // Need to find what subexpression is 'v' and what is 'x'. |
| 5734 | OpenMPAtomicUpdateChecker Checker(*this); |
| 5735 | bool IsUpdateExprFound = !Checker.checkStatement(Second); |
| 5736 | BinaryOperator *BinOp = nullptr; |
| 5737 | if (IsUpdateExprFound) { |
| 5738 | BinOp = dyn_cast<BinaryOperator>(First); |
| 5739 | IsUpdateExprFound = BinOp && BinOp->getOpcode() == BO_Assign; |
| 5740 | } |
| 5741 | if (IsUpdateExprFound && !CurContext->isDependentContext()) { |
| 5742 | // { v = x; x++; } |
| 5743 | // { v = x; x--; } |
| 5744 | // { v = x; ++x; } |
| 5745 | // { v = x; --x; } |
| 5746 | // { v = x; x binop= expr; } |
| 5747 | // { v = x; x = x binop expr; } |
| 5748 | // { v = x; x = expr binop x; } |
| 5749 | // Check that the first expression has form v = x. |
| 5750 | auto *PossibleX = BinOp->getRHS()->IgnoreParenImpCasts(); |
| 5751 | llvm::FoldingSetNodeID XId, PossibleXId; |
| 5752 | Checker.getX()->Profile(XId, Context, /*Canonical=*/true); |
| 5753 | PossibleX->Profile(PossibleXId, Context, /*Canonical=*/true); |
| 5754 | IsUpdateExprFound = XId == PossibleXId; |
| 5755 | if (IsUpdateExprFound) { |
| 5756 | V = BinOp->getLHS(); |
| 5757 | X = Checker.getX(); |
| 5758 | E = Checker.getExpr(); |
| 5759 | UE = Checker.getUpdateExpr(); |
| 5760 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5761 | IsPostfixUpdate = true; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5762 | } |
| 5763 | } |
| 5764 | if (!IsUpdateExprFound) { |
| 5765 | IsUpdateExprFound = !Checker.checkStatement(First); |
| 5766 | BinOp = nullptr; |
| 5767 | if (IsUpdateExprFound) { |
| 5768 | BinOp = dyn_cast<BinaryOperator>(Second); |
| 5769 | IsUpdateExprFound = BinOp && BinOp->getOpcode() == BO_Assign; |
| 5770 | } |
| 5771 | if (IsUpdateExprFound && !CurContext->isDependentContext()) { |
| 5772 | // { x++; v = x; } |
| 5773 | // { x--; v = x; } |
| 5774 | // { ++x; v = x; } |
| 5775 | // { --x; v = x; } |
| 5776 | // { x binop= expr; v = x; } |
| 5777 | // { x = x binop expr; v = x; } |
| 5778 | // { x = expr binop x; v = x; } |
| 5779 | // Check that the second expression has form v = x. |
| 5780 | auto *PossibleX = BinOp->getRHS()->IgnoreParenImpCasts(); |
| 5781 | llvm::FoldingSetNodeID XId, PossibleXId; |
| 5782 | Checker.getX()->Profile(XId, Context, /*Canonical=*/true); |
| 5783 | PossibleX->Profile(PossibleXId, Context, /*Canonical=*/true); |
| 5784 | IsUpdateExprFound = XId == PossibleXId; |
| 5785 | if (IsUpdateExprFound) { |
| 5786 | V = BinOp->getLHS(); |
| 5787 | X = Checker.getX(); |
| 5788 | E = Checker.getExpr(); |
| 5789 | UE = Checker.getUpdateExpr(); |
| 5790 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5791 | IsPostfixUpdate = false; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5792 | } |
| 5793 | } |
| 5794 | } |
| 5795 | if (!IsUpdateExprFound) { |
| 5796 | // { v = x; x = expr; } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5797 | auto *FirstExpr = dyn_cast<Expr>(First); |
| 5798 | auto *SecondExpr = dyn_cast<Expr>(Second); |
| 5799 | if (!FirstExpr || !SecondExpr || |
| 5800 | !(FirstExpr->isInstantiationDependent() || |
| 5801 | SecondExpr->isInstantiationDependent())) { |
| 5802 | auto *FirstBinOp = dyn_cast<BinaryOperator>(First); |
| 5803 | if (!FirstBinOp || FirstBinOp->getOpcode() != BO_Assign) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5804 | ErrorFound = NotAnAssignmentOp; |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5805 | NoteLoc = ErrorLoc = FirstBinOp ? FirstBinOp->getOperatorLoc() |
| 5806 | : First->getLocStart(); |
| 5807 | NoteRange = ErrorRange = FirstBinOp |
| 5808 | ? FirstBinOp->getSourceRange() |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5809 | : SourceRange(ErrorLoc, ErrorLoc); |
| 5810 | } else { |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5811 | auto *SecondBinOp = dyn_cast<BinaryOperator>(Second); |
| 5812 | if (!SecondBinOp || SecondBinOp->getOpcode() != BO_Assign) { |
| 5813 | ErrorFound = NotAnAssignmentOp; |
| 5814 | NoteLoc = ErrorLoc = SecondBinOp |
| 5815 | ? SecondBinOp->getOperatorLoc() |
| 5816 | : Second->getLocStart(); |
| 5817 | NoteRange = ErrorRange = |
| 5818 | SecondBinOp ? SecondBinOp->getSourceRange() |
| 5819 | : SourceRange(ErrorLoc, ErrorLoc); |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5820 | } else { |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5821 | auto *PossibleXRHSInFirst = |
| 5822 | FirstBinOp->getRHS()->IgnoreParenImpCasts(); |
| 5823 | auto *PossibleXLHSInSecond = |
| 5824 | SecondBinOp->getLHS()->IgnoreParenImpCasts(); |
| 5825 | llvm::FoldingSetNodeID X1Id, X2Id; |
| 5826 | PossibleXRHSInFirst->Profile(X1Id, Context, |
| 5827 | /*Canonical=*/true); |
| 5828 | PossibleXLHSInSecond->Profile(X2Id, Context, |
| 5829 | /*Canonical=*/true); |
| 5830 | IsUpdateExprFound = X1Id == X2Id; |
| 5831 | if (IsUpdateExprFound) { |
| 5832 | V = FirstBinOp->getLHS(); |
| 5833 | X = SecondBinOp->getLHS(); |
| 5834 | E = SecondBinOp->getRHS(); |
| 5835 | UE = nullptr; |
| 5836 | IsXLHSInRHSPart = false; |
| 5837 | IsPostfixUpdate = true; |
| 5838 | } else { |
| 5839 | ErrorFound = NotASpecificExpression; |
| 5840 | ErrorLoc = FirstBinOp->getExprLoc(); |
| 5841 | ErrorRange = FirstBinOp->getSourceRange(); |
| 5842 | NoteLoc = SecondBinOp->getLHS()->getExprLoc(); |
| 5843 | NoteRange = SecondBinOp->getRHS()->getSourceRange(); |
| 5844 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5845 | } |
| 5846 | } |
| 5847 | } |
| 5848 | } |
| 5849 | } else { |
| 5850 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 5851 | NoteRange = ErrorRange = |
| 5852 | SourceRange(Body->getLocStart(), Body->getLocStart()); |
| 5853 | ErrorFound = NotTwoSubstatements; |
| 5854 | } |
| 5855 | } else { |
| 5856 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 5857 | NoteRange = ErrorRange = |
| 5858 | SourceRange(Body->getLocStart(), Body->getLocStart()); |
| 5859 | ErrorFound = NotACompoundStatement; |
| 5860 | } |
| 5861 | if (ErrorFound != NoError) { |
| 5862 | Diag(ErrorLoc, diag::err_omp_atomic_capture_not_compound_statement) |
| 5863 | << ErrorRange; |
| 5864 | Diag(NoteLoc, diag::note_omp_atomic_capture) << ErrorFound << NoteRange; |
| 5865 | return StmtError(); |
| 5866 | } else if (CurContext->isDependentContext()) { |
| 5867 | UE = V = E = X = nullptr; |
| 5868 | } |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5869 | } |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5870 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 5871 | |
| 5872 | getCurFunction()->setHasBranchProtectedScope(); |
| 5873 | |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5874 | return OMPAtomicDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5875 | X, V, E, UE, IsXLHSInRHSPart, |
| 5876 | IsPostfixUpdate); |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 5877 | } |
| 5878 | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 5879 | StmtResult Sema::ActOnOpenMPTargetDirective(ArrayRef<OMPClause *> Clauses, |
| 5880 | Stmt *AStmt, |
| 5881 | SourceLocation StartLoc, |
| 5882 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5883 | if (!AStmt) |
| 5884 | return StmtError(); |
| 5885 | |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 5886 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 5887 | // 1.2.2 OpenMP Language Terminology |
| 5888 | // Structured block - An executable statement with a single entry at the |
| 5889 | // top and a single exit at the bottom. |
| 5890 | // The point of exit cannot be a branch out of the structured block. |
| 5891 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5892 | CS->getCapturedDecl()->setNothrow(); |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 5893 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 5894 | // OpenMP [2.16, Nesting of Regions] |
| 5895 | // If specified, a teams construct must be contained within a target |
| 5896 | // construct. That target construct must contain no statements or directives |
| 5897 | // outside of the teams construct. |
| 5898 | if (DSAStack->hasInnerTeamsRegion()) { |
| 5899 | auto S = AStmt->IgnoreContainers(/*IgnoreCaptured*/ true); |
| 5900 | bool OMPTeamsFound = true; |
| 5901 | if (auto *CS = dyn_cast<CompoundStmt>(S)) { |
| 5902 | auto I = CS->body_begin(); |
| 5903 | while (I != CS->body_end()) { |
| 5904 | auto OED = dyn_cast<OMPExecutableDirective>(*I); |
| 5905 | if (!OED || !isOpenMPTeamsDirective(OED->getDirectiveKind())) { |
| 5906 | OMPTeamsFound = false; |
| 5907 | break; |
| 5908 | } |
| 5909 | ++I; |
| 5910 | } |
| 5911 | assert(I != CS->body_end() && "Not found statement"); |
| 5912 | S = *I; |
| 5913 | } |
| 5914 | if (!OMPTeamsFound) { |
| 5915 | Diag(StartLoc, diag::err_omp_target_contains_not_only_teams); |
| 5916 | Diag(DSAStack->getInnerTeamsRegionLoc(), |
| 5917 | diag::note_omp_nested_teams_construct_here); |
| 5918 | Diag(S->getLocStart(), diag::note_omp_nested_statement_here) |
| 5919 | << isa<OMPExecutableDirective>(S); |
| 5920 | return StmtError(); |
| 5921 | } |
| 5922 | } |
| 5923 | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 5924 | getCurFunction()->setHasBranchProtectedScope(); |
| 5925 | |
| 5926 | return OMPTargetDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 5927 | } |
| 5928 | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 5929 | StmtResult |
| 5930 | Sema::ActOnOpenMPTargetParallelDirective(ArrayRef<OMPClause *> Clauses, |
| 5931 | Stmt *AStmt, SourceLocation StartLoc, |
| 5932 | SourceLocation EndLoc) { |
| 5933 | if (!AStmt) |
| 5934 | return StmtError(); |
| 5935 | |
| 5936 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 5937 | // 1.2.2 OpenMP Language Terminology |
| 5938 | // Structured block - An executable statement with a single entry at the |
| 5939 | // top and a single exit at the bottom. |
| 5940 | // The point of exit cannot be a branch out of the structured block. |
| 5941 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5942 | CS->getCapturedDecl()->setNothrow(); |
| 5943 | |
| 5944 | getCurFunction()->setHasBranchProtectedScope(); |
| 5945 | |
| 5946 | return OMPTargetParallelDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 5947 | AStmt); |
| 5948 | } |
| 5949 | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 5950 | StmtResult Sema::ActOnOpenMPTargetParallelForDirective( |
| 5951 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 5952 | SourceLocation EndLoc, |
| 5953 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 5954 | if (!AStmt) |
| 5955 | return StmtError(); |
| 5956 | |
| 5957 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 5958 | // 1.2.2 OpenMP Language Terminology |
| 5959 | // Structured block - An executable statement with a single entry at the |
| 5960 | // top and a single exit at the bottom. |
| 5961 | // The point of exit cannot be a branch out of the structured block. |
| 5962 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5963 | CS->getCapturedDecl()->setNothrow(); |
| 5964 | |
| 5965 | OMPLoopDirective::HelperExprs B; |
| 5966 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 5967 | // define the nested loops number. |
| 5968 | unsigned NestedLoopCount = |
| 5969 | CheckOpenMPLoop(OMPD_target_parallel_for, getCollapseNumberExpr(Clauses), |
| 5970 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 5971 | VarsWithImplicitDSA, B); |
| 5972 | if (NestedLoopCount == 0) |
| 5973 | return StmtError(); |
| 5974 | |
| 5975 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 5976 | "omp target parallel for loop exprs were not built"); |
| 5977 | |
| 5978 | if (!CurContext->isDependentContext()) { |
| 5979 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 5980 | for (auto C : Clauses) { |
| 5981 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 5982 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 5983 | B.NumIterations, *this, CurScope)) |
| 5984 | return StmtError(); |
| 5985 | } |
| 5986 | } |
| 5987 | |
| 5988 | getCurFunction()->setHasBranchProtectedScope(); |
| 5989 | return OMPTargetParallelForDirective::Create(Context, StartLoc, EndLoc, |
| 5990 | NestedLoopCount, Clauses, AStmt, |
| 5991 | B, DSAStack->isCancelRegion()); |
| 5992 | } |
| 5993 | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 5994 | /// \brief Check for existence of a map clause in the list of clauses. |
| 5995 | static bool HasMapClause(ArrayRef<OMPClause *> Clauses) { |
| 5996 | for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end(); |
| 5997 | I != E; ++I) { |
| 5998 | if (*I != nullptr && (*I)->getClauseKind() == OMPC_map) { |
| 5999 | return true; |
| 6000 | } |
| 6001 | } |
| 6002 | |
| 6003 | return false; |
| 6004 | } |
| 6005 | |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 6006 | StmtResult Sema::ActOnOpenMPTargetDataDirective(ArrayRef<OMPClause *> Clauses, |
| 6007 | Stmt *AStmt, |
| 6008 | SourceLocation StartLoc, |
| 6009 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6010 | if (!AStmt) |
| 6011 | return StmtError(); |
| 6012 | |
| 6013 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 6014 | |
Arpith Chacko Jacob | 46a04bb | 2016-01-21 19:57:55 +0000 | [diff] [blame] | 6015 | // OpenMP [2.10.1, Restrictions, p. 97] |
| 6016 | // At least one map clause must appear on the directive. |
| 6017 | if (!HasMapClause(Clauses)) { |
| 6018 | Diag(StartLoc, diag::err_omp_no_map_for_directive) << |
| 6019 | getOpenMPDirectiveName(OMPD_target_data); |
| 6020 | return StmtError(); |
| 6021 | } |
| 6022 | |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 6023 | getCurFunction()->setHasBranchProtectedScope(); |
| 6024 | |
| 6025 | return OMPTargetDataDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 6026 | AStmt); |
| 6027 | } |
| 6028 | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 6029 | StmtResult |
| 6030 | Sema::ActOnOpenMPTargetEnterDataDirective(ArrayRef<OMPClause *> Clauses, |
| 6031 | SourceLocation StartLoc, |
| 6032 | SourceLocation EndLoc) { |
| 6033 | // OpenMP [2.10.2, Restrictions, p. 99] |
| 6034 | // At least one map clause must appear on the directive. |
| 6035 | if (!HasMapClause(Clauses)) { |
| 6036 | Diag(StartLoc, diag::err_omp_no_map_for_directive) |
| 6037 | << getOpenMPDirectiveName(OMPD_target_enter_data); |
| 6038 | return StmtError(); |
| 6039 | } |
| 6040 | |
| 6041 | return OMPTargetEnterDataDirective::Create(Context, StartLoc, EndLoc, |
| 6042 | Clauses); |
| 6043 | } |
| 6044 | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 6045 | StmtResult |
| 6046 | Sema::ActOnOpenMPTargetExitDataDirective(ArrayRef<OMPClause *> Clauses, |
| 6047 | SourceLocation StartLoc, |
| 6048 | SourceLocation EndLoc) { |
| 6049 | // OpenMP [2.10.3, Restrictions, p. 102] |
| 6050 | // At least one map clause must appear on the directive. |
| 6051 | if (!HasMapClause(Clauses)) { |
| 6052 | Diag(StartLoc, diag::err_omp_no_map_for_directive) |
| 6053 | << getOpenMPDirectiveName(OMPD_target_exit_data); |
| 6054 | return StmtError(); |
| 6055 | } |
| 6056 | |
| 6057 | return OMPTargetExitDataDirective::Create(Context, StartLoc, EndLoc, Clauses); |
| 6058 | } |
| 6059 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 6060 | StmtResult Sema::ActOnOpenMPTeamsDirective(ArrayRef<OMPClause *> Clauses, |
| 6061 | Stmt *AStmt, SourceLocation StartLoc, |
| 6062 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6063 | if (!AStmt) |
| 6064 | return StmtError(); |
| 6065 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 6066 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6067 | // 1.2.2 OpenMP Language Terminology |
| 6068 | // Structured block - An executable statement with a single entry at the |
| 6069 | // top and a single exit at the bottom. |
| 6070 | // The point of exit cannot be a branch out of the structured block. |
| 6071 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6072 | CS->getCapturedDecl()->setNothrow(); |
| 6073 | |
| 6074 | getCurFunction()->setHasBranchProtectedScope(); |
| 6075 | |
| 6076 | return OMPTeamsDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 6077 | } |
| 6078 | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 6079 | StmtResult |
| 6080 | Sema::ActOnOpenMPCancellationPointDirective(SourceLocation StartLoc, |
| 6081 | SourceLocation EndLoc, |
| 6082 | OpenMPDirectiveKind CancelRegion) { |
| 6083 | if (CancelRegion != OMPD_parallel && CancelRegion != OMPD_for && |
| 6084 | CancelRegion != OMPD_sections && CancelRegion != OMPD_taskgroup) { |
| 6085 | Diag(StartLoc, diag::err_omp_wrong_cancel_region) |
| 6086 | << getOpenMPDirectiveName(CancelRegion); |
| 6087 | return StmtError(); |
| 6088 | } |
| 6089 | if (DSAStack->isParentNowaitRegion()) { |
| 6090 | Diag(StartLoc, diag::err_omp_parent_cancel_region_nowait) << 0; |
| 6091 | return StmtError(); |
| 6092 | } |
| 6093 | if (DSAStack->isParentOrderedRegion()) { |
| 6094 | Diag(StartLoc, diag::err_omp_parent_cancel_region_ordered) << 0; |
| 6095 | return StmtError(); |
| 6096 | } |
| 6097 | return OMPCancellationPointDirective::Create(Context, StartLoc, EndLoc, |
| 6098 | CancelRegion); |
| 6099 | } |
| 6100 | |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 6101 | StmtResult Sema::ActOnOpenMPCancelDirective(ArrayRef<OMPClause *> Clauses, |
| 6102 | SourceLocation StartLoc, |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 6103 | SourceLocation EndLoc, |
| 6104 | OpenMPDirectiveKind CancelRegion) { |
| 6105 | if (CancelRegion != OMPD_parallel && CancelRegion != OMPD_for && |
| 6106 | CancelRegion != OMPD_sections && CancelRegion != OMPD_taskgroup) { |
| 6107 | Diag(StartLoc, diag::err_omp_wrong_cancel_region) |
| 6108 | << getOpenMPDirectiveName(CancelRegion); |
| 6109 | return StmtError(); |
| 6110 | } |
| 6111 | if (DSAStack->isParentNowaitRegion()) { |
| 6112 | Diag(StartLoc, diag::err_omp_parent_cancel_region_nowait) << 1; |
| 6113 | return StmtError(); |
| 6114 | } |
| 6115 | if (DSAStack->isParentOrderedRegion()) { |
| 6116 | Diag(StartLoc, diag::err_omp_parent_cancel_region_ordered) << 1; |
| 6117 | return StmtError(); |
| 6118 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 6119 | DSAStack->setParentCancelRegion(/*Cancel=*/true); |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 6120 | return OMPCancelDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 6121 | CancelRegion); |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 6122 | } |
| 6123 | |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6124 | static bool checkGrainsizeNumTasksClauses(Sema &S, |
| 6125 | ArrayRef<OMPClause *> Clauses) { |
| 6126 | OMPClause *PrevClause = nullptr; |
| 6127 | bool ErrorFound = false; |
| 6128 | for (auto *C : Clauses) { |
| 6129 | if (C->getClauseKind() == OMPC_grainsize || |
| 6130 | C->getClauseKind() == OMPC_num_tasks) { |
| 6131 | if (!PrevClause) |
| 6132 | PrevClause = C; |
| 6133 | else if (PrevClause->getClauseKind() != C->getClauseKind()) { |
| 6134 | S.Diag(C->getLocStart(), |
| 6135 | diag::err_omp_grainsize_num_tasks_mutually_exclusive) |
| 6136 | << getOpenMPClauseName(C->getClauseKind()) |
| 6137 | << getOpenMPClauseName(PrevClause->getClauseKind()); |
| 6138 | S.Diag(PrevClause->getLocStart(), |
| 6139 | diag::note_omp_previous_grainsize_num_tasks) |
| 6140 | << getOpenMPClauseName(PrevClause->getClauseKind()); |
| 6141 | ErrorFound = true; |
| 6142 | } |
| 6143 | } |
| 6144 | } |
| 6145 | return ErrorFound; |
| 6146 | } |
| 6147 | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 6148 | StmtResult Sema::ActOnOpenMPTaskLoopDirective( |
| 6149 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6150 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 6151 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 6152 | if (!AStmt) |
| 6153 | return StmtError(); |
| 6154 | |
| 6155 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 6156 | OMPLoopDirective::HelperExprs B; |
| 6157 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 6158 | // define the nested loops number. |
| 6159 | unsigned NestedLoopCount = |
| 6160 | CheckOpenMPLoop(OMPD_taskloop, getCollapseNumberExpr(Clauses), |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 6161 | /*OrderedLoopCountExpr=*/nullptr, AStmt, *this, *DSAStack, |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 6162 | VarsWithImplicitDSA, B); |
| 6163 | if (NestedLoopCount == 0) |
| 6164 | return StmtError(); |
| 6165 | |
| 6166 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6167 | "omp for loop exprs were not built"); |
| 6168 | |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6169 | // OpenMP, [2.9.2 taskloop Construct, Restrictions] |
| 6170 | // The grainsize clause and num_tasks clause are mutually exclusive and may |
| 6171 | // not appear on the same taskloop directive. |
| 6172 | if (checkGrainsizeNumTasksClauses(*this, Clauses)) |
| 6173 | return StmtError(); |
| 6174 | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 6175 | getCurFunction()->setHasBranchProtectedScope(); |
| 6176 | return OMPTaskLoopDirective::Create(Context, StartLoc, EndLoc, |
| 6177 | NestedLoopCount, Clauses, AStmt, B); |
| 6178 | } |
| 6179 | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 6180 | StmtResult Sema::ActOnOpenMPTaskLoopSimdDirective( |
| 6181 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6182 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 6183 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 6184 | if (!AStmt) |
| 6185 | return StmtError(); |
| 6186 | |
| 6187 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 6188 | OMPLoopDirective::HelperExprs B; |
| 6189 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 6190 | // define the nested loops number. |
| 6191 | unsigned NestedLoopCount = |
| 6192 | CheckOpenMPLoop(OMPD_taskloop_simd, getCollapseNumberExpr(Clauses), |
| 6193 | /*OrderedLoopCountExpr=*/nullptr, AStmt, *this, *DSAStack, |
| 6194 | VarsWithImplicitDSA, B); |
| 6195 | if (NestedLoopCount == 0) |
| 6196 | return StmtError(); |
| 6197 | |
| 6198 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6199 | "omp for loop exprs were not built"); |
| 6200 | |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6201 | // OpenMP, [2.9.2 taskloop Construct, Restrictions] |
| 6202 | // The grainsize clause and num_tasks clause are mutually exclusive and may |
| 6203 | // not appear on the same taskloop directive. |
| 6204 | if (checkGrainsizeNumTasksClauses(*this, Clauses)) |
| 6205 | return StmtError(); |
| 6206 | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 6207 | getCurFunction()->setHasBranchProtectedScope(); |
| 6208 | return OMPTaskLoopSimdDirective::Create(Context, StartLoc, EndLoc, |
| 6209 | NestedLoopCount, Clauses, AStmt, B); |
| 6210 | } |
| 6211 | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 6212 | StmtResult Sema::ActOnOpenMPDistributeDirective( |
| 6213 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6214 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 6215 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 6216 | if (!AStmt) |
| 6217 | return StmtError(); |
| 6218 | |
| 6219 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 6220 | OMPLoopDirective::HelperExprs B; |
| 6221 | // In presence of clause 'collapse' with number of loops, it will |
| 6222 | // define the nested loops number. |
| 6223 | unsigned NestedLoopCount = |
| 6224 | CheckOpenMPLoop(OMPD_distribute, getCollapseNumberExpr(Clauses), |
| 6225 | nullptr /*ordered not a clause on distribute*/, AStmt, |
| 6226 | *this, *DSAStack, VarsWithImplicitDSA, B); |
| 6227 | if (NestedLoopCount == 0) |
| 6228 | return StmtError(); |
| 6229 | |
| 6230 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6231 | "omp for loop exprs were not built"); |
| 6232 | |
| 6233 | getCurFunction()->setHasBranchProtectedScope(); |
| 6234 | return OMPDistributeDirective::Create(Context, StartLoc, EndLoc, |
| 6235 | NestedLoopCount, Clauses, AStmt, B); |
| 6236 | } |
| 6237 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6238 | OMPClause *Sema::ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, Expr *Expr, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6239 | SourceLocation StartLoc, |
| 6240 | SourceLocation LParenLoc, |
| 6241 | SourceLocation EndLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6242 | OMPClause *Res = nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6243 | switch (Kind) { |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 6244 | case OMPC_final: |
| 6245 | Res = ActOnOpenMPFinalClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6246 | break; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6247 | case OMPC_num_threads: |
| 6248 | Res = ActOnOpenMPNumThreadsClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6249 | break; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6250 | case OMPC_safelen: |
| 6251 | Res = ActOnOpenMPSafelenClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6252 | break; |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 6253 | case OMPC_simdlen: |
| 6254 | Res = ActOnOpenMPSimdlenClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6255 | break; |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6256 | case OMPC_collapse: |
| 6257 | Res = ActOnOpenMPCollapseClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6258 | break; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 6259 | case OMPC_ordered: |
| 6260 | Res = ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Expr); |
| 6261 | break; |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 6262 | case OMPC_device: |
| 6263 | Res = ActOnOpenMPDeviceClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6264 | break; |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 6265 | case OMPC_num_teams: |
| 6266 | Res = ActOnOpenMPNumTeamsClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6267 | break; |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6268 | case OMPC_thread_limit: |
| 6269 | Res = ActOnOpenMPThreadLimitClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6270 | break; |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6271 | case OMPC_priority: |
| 6272 | Res = ActOnOpenMPPriorityClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6273 | break; |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 6274 | case OMPC_grainsize: |
| 6275 | Res = ActOnOpenMPGrainsizeClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6276 | break; |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6277 | case OMPC_num_tasks: |
| 6278 | Res = ActOnOpenMPNumTasksClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6279 | break; |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 6280 | case OMPC_hint: |
| 6281 | Res = ActOnOpenMPHintClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6282 | break; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6283 | case OMPC_if: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6284 | case OMPC_default: |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6285 | case OMPC_proc_bind: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6286 | case OMPC_schedule: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6287 | case OMPC_private: |
| 6288 | case OMPC_firstprivate: |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6289 | case OMPC_lastprivate: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6290 | case OMPC_shared: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6291 | case OMPC_reduction: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6292 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 6293 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6294 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6295 | case OMPC_copyprivate: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6296 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 6297 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 6298 | case OMPC_mergeable: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6299 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 6300 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6301 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6302 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6303 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6304 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 6305 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6306 | case OMPC_depend: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6307 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6308 | case OMPC_simd: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 6309 | case OMPC_map: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 6310 | case OMPC_nogroup: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 6311 | case OMPC_dist_schedule: |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 6312 | case OMPC_defaultmap: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6313 | case OMPC_unknown: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6314 | llvm_unreachable("Clause is not allowed."); |
| 6315 | } |
| 6316 | return Res; |
| 6317 | } |
| 6318 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6319 | OMPClause *Sema::ActOnOpenMPIfClause(OpenMPDirectiveKind NameModifier, |
| 6320 | Expr *Condition, SourceLocation StartLoc, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6321 | SourceLocation LParenLoc, |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6322 | SourceLocation NameModifierLoc, |
| 6323 | SourceLocation ColonLoc, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6324 | SourceLocation EndLoc) { |
| 6325 | Expr *ValExpr = Condition; |
| 6326 | if (!Condition->isValueDependent() && !Condition->isTypeDependent() && |
| 6327 | !Condition->isInstantiationDependent() && |
| 6328 | !Condition->containsUnexpandedParameterPack()) { |
| 6329 | ExprResult Val = ActOnBooleanCondition(DSAStack->getCurScope(), |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6330 | Condition->getExprLoc(), Condition); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6331 | if (Val.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6332 | return nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6333 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6334 | ValExpr = Val.get(); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6335 | } |
| 6336 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6337 | return new (Context) OMPIfClause(NameModifier, ValExpr, StartLoc, LParenLoc, |
| 6338 | NameModifierLoc, ColonLoc, EndLoc); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6339 | } |
| 6340 | |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 6341 | OMPClause *Sema::ActOnOpenMPFinalClause(Expr *Condition, |
| 6342 | SourceLocation StartLoc, |
| 6343 | SourceLocation LParenLoc, |
| 6344 | SourceLocation EndLoc) { |
| 6345 | Expr *ValExpr = Condition; |
| 6346 | if (!Condition->isValueDependent() && !Condition->isTypeDependent() && |
| 6347 | !Condition->isInstantiationDependent() && |
| 6348 | !Condition->containsUnexpandedParameterPack()) { |
| 6349 | ExprResult Val = ActOnBooleanCondition(DSAStack->getCurScope(), |
| 6350 | Condition->getExprLoc(), Condition); |
| 6351 | if (Val.isInvalid()) |
| 6352 | return nullptr; |
| 6353 | |
| 6354 | ValExpr = Val.get(); |
| 6355 | } |
| 6356 | |
| 6357 | return new (Context) OMPFinalClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 6358 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 6359 | ExprResult Sema::PerformOpenMPImplicitIntegerConversion(SourceLocation Loc, |
| 6360 | Expr *Op) { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6361 | if (!Op) |
| 6362 | return ExprError(); |
| 6363 | |
| 6364 | class IntConvertDiagnoser : public ICEConvertDiagnoser { |
| 6365 | public: |
| 6366 | IntConvertDiagnoser() |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6367 | : ICEConvertDiagnoser(/*AllowScopedEnumerations*/ false, false, true) {} |
Craig Topper | e14c0f8 | 2014-03-12 04:55:44 +0000 | [diff] [blame] | 6368 | SemaDiagnosticBuilder diagnoseNotInt(Sema &S, SourceLocation Loc, |
| 6369 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6370 | return S.Diag(Loc, diag::err_omp_not_integral) << T; |
| 6371 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6372 | SemaDiagnosticBuilder diagnoseIncomplete(Sema &S, SourceLocation Loc, |
| 6373 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6374 | return S.Diag(Loc, diag::err_omp_incomplete_type) << T; |
| 6375 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6376 | SemaDiagnosticBuilder diagnoseExplicitConv(Sema &S, SourceLocation Loc, |
| 6377 | QualType T, |
| 6378 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6379 | return S.Diag(Loc, diag::err_omp_explicit_conversion) << T << ConvTy; |
| 6380 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6381 | SemaDiagnosticBuilder noteExplicitConv(Sema &S, CXXConversionDecl *Conv, |
| 6382 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6383 | return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6384 | << ConvTy->isEnumeralType() << ConvTy; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6385 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6386 | SemaDiagnosticBuilder diagnoseAmbiguous(Sema &S, SourceLocation Loc, |
| 6387 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6388 | return S.Diag(Loc, diag::err_omp_ambiguous_conversion) << T; |
| 6389 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6390 | SemaDiagnosticBuilder noteAmbiguous(Sema &S, CXXConversionDecl *Conv, |
| 6391 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6392 | return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6393 | << ConvTy->isEnumeralType() << ConvTy; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6394 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6395 | SemaDiagnosticBuilder diagnoseConversion(Sema &, SourceLocation, QualType, |
| 6396 | QualType) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6397 | llvm_unreachable("conversion functions are permitted"); |
| 6398 | } |
| 6399 | } ConvertDiagnoser; |
| 6400 | return PerformContextualImplicitConversion(Loc, Op, ConvertDiagnoser); |
| 6401 | } |
| 6402 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6403 | static bool IsNonNegativeIntegerValue(Expr *&ValExpr, Sema &SemaRef, |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6404 | OpenMPClauseKind CKind, |
| 6405 | bool StrictlyPositive) { |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6406 | if (!ValExpr->isTypeDependent() && !ValExpr->isValueDependent() && |
| 6407 | !ValExpr->isInstantiationDependent()) { |
| 6408 | SourceLocation Loc = ValExpr->getExprLoc(); |
| 6409 | ExprResult Value = |
| 6410 | SemaRef.PerformOpenMPImplicitIntegerConversion(Loc, ValExpr); |
| 6411 | if (Value.isInvalid()) |
| 6412 | return false; |
| 6413 | |
| 6414 | ValExpr = Value.get(); |
| 6415 | // The expression must evaluate to a non-negative integer value. |
| 6416 | llvm::APSInt Result; |
| 6417 | if (ValExpr->isIntegerConstantExpr(Result, SemaRef.Context) && |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6418 | Result.isSigned() && |
| 6419 | !((!StrictlyPositive && Result.isNonNegative()) || |
| 6420 | (StrictlyPositive && Result.isStrictlyPositive()))) { |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6421 | SemaRef.Diag(Loc, diag::err_omp_negative_expression_in_clause) |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6422 | << getOpenMPClauseName(CKind) << (StrictlyPositive ? 1 : 0) |
| 6423 | << ValExpr->getSourceRange(); |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6424 | return false; |
| 6425 | } |
| 6426 | } |
| 6427 | return true; |
| 6428 | } |
| 6429 | |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6430 | OMPClause *Sema::ActOnOpenMPNumThreadsClause(Expr *NumThreads, |
| 6431 | SourceLocation StartLoc, |
| 6432 | SourceLocation LParenLoc, |
| 6433 | SourceLocation EndLoc) { |
| 6434 | Expr *ValExpr = NumThreads; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6435 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6436 | // OpenMP [2.5, Restrictions] |
| 6437 | // The num_threads expression must evaluate to a positive integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6438 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_num_threads, |
| 6439 | /*StrictlyPositive=*/true)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6440 | return nullptr; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6441 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6442 | return new (Context) |
| 6443 | OMPNumThreadsClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6444 | } |
| 6445 | |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6446 | ExprResult Sema::VerifyPositiveIntegerConstantInClause(Expr *E, |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 6447 | OpenMPClauseKind CKind, |
| 6448 | bool StrictlyPositive) { |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6449 | if (!E) |
| 6450 | return ExprError(); |
| 6451 | if (E->isValueDependent() || E->isTypeDependent() || |
| 6452 | E->isInstantiationDependent() || E->containsUnexpandedParameterPack()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6453 | return E; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6454 | llvm::APSInt Result; |
| 6455 | ExprResult ICE = VerifyIntegerConstantExpression(E, &Result); |
| 6456 | if (ICE.isInvalid()) |
| 6457 | return ExprError(); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 6458 | if ((StrictlyPositive && !Result.isStrictlyPositive()) || |
| 6459 | (!StrictlyPositive && !Result.isNonNegative())) { |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6460 | Diag(E->getExprLoc(), diag::err_omp_negative_expression_in_clause) |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 6461 | << getOpenMPClauseName(CKind) << (StrictlyPositive ? 1 : 0) |
| 6462 | << E->getSourceRange(); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6463 | return ExprError(); |
| 6464 | } |
Alexander Musman | 09184fe | 2014-09-30 05:29:28 +0000 | [diff] [blame] | 6465 | if (CKind == OMPC_aligned && !Result.isPowerOf2()) { |
| 6466 | Diag(E->getExprLoc(), diag::warn_omp_alignment_not_power_of_two) |
| 6467 | << E->getSourceRange(); |
| 6468 | return ExprError(); |
| 6469 | } |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 6470 | if (CKind == OMPC_collapse && DSAStack->getAssociatedLoops() == 1) |
| 6471 | DSAStack->setAssociatedLoops(Result.getExtValue()); |
Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 6472 | else if (CKind == OMPC_ordered) |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 6473 | DSAStack->setAssociatedLoops(Result.getExtValue()); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6474 | return ICE; |
| 6475 | } |
| 6476 | |
| 6477 | OMPClause *Sema::ActOnOpenMPSafelenClause(Expr *Len, SourceLocation StartLoc, |
| 6478 | SourceLocation LParenLoc, |
| 6479 | SourceLocation EndLoc) { |
| 6480 | // OpenMP [2.8.1, simd construct, Description] |
| 6481 | // The parameter of the safelen clause must be a constant |
| 6482 | // positive integer expression. |
| 6483 | ExprResult Safelen = VerifyPositiveIntegerConstantInClause(Len, OMPC_safelen); |
| 6484 | if (Safelen.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6485 | return nullptr; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6486 | return new (Context) |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6487 | OMPSafelenClause(Safelen.get(), StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6488 | } |
| 6489 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 6490 | OMPClause *Sema::ActOnOpenMPSimdlenClause(Expr *Len, SourceLocation StartLoc, |
| 6491 | SourceLocation LParenLoc, |
| 6492 | SourceLocation EndLoc) { |
| 6493 | // OpenMP [2.8.1, simd construct, Description] |
| 6494 | // The parameter of the simdlen clause must be a constant |
| 6495 | // positive integer expression. |
| 6496 | ExprResult Simdlen = VerifyPositiveIntegerConstantInClause(Len, OMPC_simdlen); |
| 6497 | if (Simdlen.isInvalid()) |
| 6498 | return nullptr; |
| 6499 | return new (Context) |
| 6500 | OMPSimdlenClause(Simdlen.get(), StartLoc, LParenLoc, EndLoc); |
| 6501 | } |
| 6502 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6503 | OMPClause *Sema::ActOnOpenMPCollapseClause(Expr *NumForLoops, |
| 6504 | SourceLocation StartLoc, |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6505 | SourceLocation LParenLoc, |
| 6506 | SourceLocation EndLoc) { |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6507 | // OpenMP [2.7.1, loop construct, Description] |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6508 | // OpenMP [2.8.1, simd construct, Description] |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6509 | // OpenMP [2.9.6, distribute construct, Description] |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6510 | // The parameter of the collapse clause must be a constant |
| 6511 | // positive integer expression. |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6512 | ExprResult NumForLoopsResult = |
| 6513 | VerifyPositiveIntegerConstantInClause(NumForLoops, OMPC_collapse); |
| 6514 | if (NumForLoopsResult.isInvalid()) |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6515 | return nullptr; |
| 6516 | return new (Context) |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6517 | OMPCollapseClause(NumForLoopsResult.get(), StartLoc, LParenLoc, EndLoc); |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6518 | } |
| 6519 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 6520 | OMPClause *Sema::ActOnOpenMPOrderedClause(SourceLocation StartLoc, |
| 6521 | SourceLocation EndLoc, |
| 6522 | SourceLocation LParenLoc, |
| 6523 | Expr *NumForLoops) { |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 6524 | // OpenMP [2.7.1, loop construct, Description] |
| 6525 | // OpenMP [2.8.1, simd construct, Description] |
| 6526 | // OpenMP [2.9.6, distribute construct, Description] |
| 6527 | // The parameter of the ordered clause must be a constant |
| 6528 | // positive integer expression if any. |
| 6529 | if (NumForLoops && LParenLoc.isValid()) { |
| 6530 | ExprResult NumForLoopsResult = |
| 6531 | VerifyPositiveIntegerConstantInClause(NumForLoops, OMPC_ordered); |
| 6532 | if (NumForLoopsResult.isInvalid()) |
| 6533 | return nullptr; |
| 6534 | NumForLoops = NumForLoopsResult.get(); |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6535 | } else |
| 6536 | NumForLoops = nullptr; |
| 6537 | DSAStack->setOrderedRegion(/*IsOrdered=*/true, NumForLoops); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 6538 | return new (Context) |
| 6539 | OMPOrderedClause(NumForLoops, StartLoc, LParenLoc, EndLoc); |
| 6540 | } |
| 6541 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6542 | OMPClause *Sema::ActOnOpenMPSimpleClause( |
| 6543 | OpenMPClauseKind Kind, unsigned Argument, SourceLocation ArgumentLoc, |
| 6544 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6545 | OMPClause *Res = nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6546 | switch (Kind) { |
| 6547 | case OMPC_default: |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6548 | Res = |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6549 | ActOnOpenMPDefaultClause(static_cast<OpenMPDefaultClauseKind>(Argument), |
| 6550 | ArgumentLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6551 | break; |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6552 | case OMPC_proc_bind: |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6553 | Res = ActOnOpenMPProcBindClause( |
| 6554 | static_cast<OpenMPProcBindClauseKind>(Argument), ArgumentLoc, StartLoc, |
| 6555 | LParenLoc, EndLoc); |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6556 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6557 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 6558 | case OMPC_final: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6559 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6560 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 6561 | case OMPC_simdlen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6562 | case OMPC_collapse: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6563 | case OMPC_schedule: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6564 | case OMPC_private: |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6565 | case OMPC_firstprivate: |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6566 | case OMPC_lastprivate: |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6567 | case OMPC_shared: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6568 | case OMPC_reduction: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6569 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 6570 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6571 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6572 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6573 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6574 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 6575 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 6576 | case OMPC_mergeable: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6577 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 6578 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6579 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6580 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6581 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6582 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 6583 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6584 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 6585 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6586 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6587 | case OMPC_simd: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 6588 | case OMPC_map: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 6589 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6590 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6591 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 6592 | case OMPC_grainsize: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 6593 | case OMPC_nogroup: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6594 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 6595 | case OMPC_hint: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 6596 | case OMPC_dist_schedule: |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 6597 | case OMPC_defaultmap: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6598 | case OMPC_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6599 | llvm_unreachable("Clause is not allowed."); |
| 6600 | } |
| 6601 | return Res; |
| 6602 | } |
| 6603 | |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6604 | static std::string |
| 6605 | getListOfPossibleValues(OpenMPClauseKind K, unsigned First, unsigned Last, |
| 6606 | ArrayRef<unsigned> Exclude = llvm::None) { |
| 6607 | std::string Values; |
| 6608 | unsigned Bound = Last >= 2 ? Last - 2 : 0; |
| 6609 | unsigned Skipped = Exclude.size(); |
| 6610 | auto S = Exclude.begin(), E = Exclude.end(); |
| 6611 | for (unsigned i = First; i < Last; ++i) { |
| 6612 | if (std::find(S, E, i) != E) { |
| 6613 | --Skipped; |
| 6614 | continue; |
| 6615 | } |
| 6616 | Values += "'"; |
| 6617 | Values += getOpenMPSimpleClauseTypeName(K, i); |
| 6618 | Values += "'"; |
| 6619 | if (i == Bound - Skipped) |
| 6620 | Values += " or "; |
| 6621 | else if (i != Bound + 1 - Skipped) |
| 6622 | Values += ", "; |
| 6623 | } |
| 6624 | return Values; |
| 6625 | } |
| 6626 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6627 | OMPClause *Sema::ActOnOpenMPDefaultClause(OpenMPDefaultClauseKind Kind, |
| 6628 | SourceLocation KindKwLoc, |
| 6629 | SourceLocation StartLoc, |
| 6630 | SourceLocation LParenLoc, |
| 6631 | SourceLocation EndLoc) { |
| 6632 | if (Kind == OMPC_DEFAULT_unknown) { |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 6633 | static_assert(OMPC_DEFAULT_unknown > 0, |
| 6634 | "OMPC_DEFAULT_unknown not greater than 0"); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6635 | Diag(KindKwLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6636 | << getListOfPossibleValues(OMPC_default, /*First=*/0, |
| 6637 | /*Last=*/OMPC_DEFAULT_unknown) |
| 6638 | << getOpenMPClauseName(OMPC_default); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6639 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6640 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6641 | switch (Kind) { |
| 6642 | case OMPC_DEFAULT_none: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6643 | DSAStack->setDefaultDSANone(KindKwLoc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6644 | break; |
| 6645 | case OMPC_DEFAULT_shared: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6646 | DSAStack->setDefaultDSAShared(KindKwLoc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6647 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6648 | case OMPC_DEFAULT_unknown: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6649 | llvm_unreachable("Clause kind is not allowed."); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6650 | break; |
| 6651 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6652 | return new (Context) |
| 6653 | OMPDefaultClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6654 | } |
| 6655 | |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6656 | OMPClause *Sema::ActOnOpenMPProcBindClause(OpenMPProcBindClauseKind Kind, |
| 6657 | SourceLocation KindKwLoc, |
| 6658 | SourceLocation StartLoc, |
| 6659 | SourceLocation LParenLoc, |
| 6660 | SourceLocation EndLoc) { |
| 6661 | if (Kind == OMPC_PROC_BIND_unknown) { |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6662 | Diag(KindKwLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6663 | << getListOfPossibleValues(OMPC_proc_bind, /*First=*/0, |
| 6664 | /*Last=*/OMPC_PROC_BIND_unknown) |
| 6665 | << getOpenMPClauseName(OMPC_proc_bind); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6666 | return nullptr; |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6667 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6668 | return new (Context) |
| 6669 | OMPProcBindClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6670 | } |
| 6671 | |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6672 | OMPClause *Sema::ActOnOpenMPSingleExprWithArgClause( |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6673 | OpenMPClauseKind Kind, ArrayRef<unsigned> Argument, Expr *Expr, |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6674 | SourceLocation StartLoc, SourceLocation LParenLoc, |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6675 | ArrayRef<SourceLocation> ArgumentLoc, SourceLocation DelimLoc, |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6676 | SourceLocation EndLoc) { |
| 6677 | OMPClause *Res = nullptr; |
| 6678 | switch (Kind) { |
| 6679 | case OMPC_schedule: |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6680 | enum { Modifier1, Modifier2, ScheduleKind, NumberOfElements }; |
| 6681 | assert(Argument.size() == NumberOfElements && |
| 6682 | ArgumentLoc.size() == NumberOfElements); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6683 | Res = ActOnOpenMPScheduleClause( |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6684 | static_cast<OpenMPScheduleClauseModifier>(Argument[Modifier1]), |
| 6685 | static_cast<OpenMPScheduleClauseModifier>(Argument[Modifier2]), |
| 6686 | static_cast<OpenMPScheduleClauseKind>(Argument[ScheduleKind]), Expr, |
| 6687 | StartLoc, LParenLoc, ArgumentLoc[Modifier1], ArgumentLoc[Modifier2], |
| 6688 | ArgumentLoc[ScheduleKind], DelimLoc, EndLoc); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6689 | break; |
| 6690 | case OMPC_if: |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6691 | assert(Argument.size() == 1 && ArgumentLoc.size() == 1); |
| 6692 | Res = ActOnOpenMPIfClause(static_cast<OpenMPDirectiveKind>(Argument.back()), |
| 6693 | Expr, StartLoc, LParenLoc, ArgumentLoc.back(), |
| 6694 | DelimLoc, EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6695 | break; |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 6696 | case OMPC_dist_schedule: |
| 6697 | Res = ActOnOpenMPDistScheduleClause( |
| 6698 | static_cast<OpenMPDistScheduleClauseKind>(Argument.back()), Expr, |
| 6699 | StartLoc, LParenLoc, ArgumentLoc.back(), DelimLoc, EndLoc); |
| 6700 | break; |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 6701 | case OMPC_defaultmap: |
| 6702 | enum { Modifier, DefaultmapKind }; |
| 6703 | Res = ActOnOpenMPDefaultmapClause( |
| 6704 | static_cast<OpenMPDefaultmapClauseModifier>(Argument[Modifier]), |
| 6705 | static_cast<OpenMPDefaultmapClauseKind>(Argument[DefaultmapKind]), |
| 6706 | StartLoc, LParenLoc, ArgumentLoc[Modifier], |
| 6707 | ArgumentLoc[DefaultmapKind], EndLoc); |
| 6708 | break; |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 6709 | case OMPC_final: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6710 | case OMPC_num_threads: |
| 6711 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 6712 | case OMPC_simdlen: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6713 | case OMPC_collapse: |
| 6714 | case OMPC_default: |
| 6715 | case OMPC_proc_bind: |
| 6716 | case OMPC_private: |
| 6717 | case OMPC_firstprivate: |
| 6718 | case OMPC_lastprivate: |
| 6719 | case OMPC_shared: |
| 6720 | case OMPC_reduction: |
| 6721 | case OMPC_linear: |
| 6722 | case OMPC_aligned: |
| 6723 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6724 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6725 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6726 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 6727 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 6728 | case OMPC_mergeable: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6729 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 6730 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6731 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6732 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6733 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6734 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 6735 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6736 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 6737 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6738 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6739 | case OMPC_simd: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 6740 | case OMPC_map: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 6741 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6742 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6743 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 6744 | case OMPC_grainsize: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 6745 | case OMPC_nogroup: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6746 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 6747 | case OMPC_hint: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6748 | case OMPC_unknown: |
| 6749 | llvm_unreachable("Clause is not allowed."); |
| 6750 | } |
| 6751 | return Res; |
| 6752 | } |
| 6753 | |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6754 | static bool checkScheduleModifiers(Sema &S, OpenMPScheduleClauseModifier M1, |
| 6755 | OpenMPScheduleClauseModifier M2, |
| 6756 | SourceLocation M1Loc, SourceLocation M2Loc) { |
| 6757 | if (M1 == OMPC_SCHEDULE_MODIFIER_unknown && M1Loc.isValid()) { |
| 6758 | SmallVector<unsigned, 2> Excluded; |
| 6759 | if (M2 != OMPC_SCHEDULE_MODIFIER_unknown) |
| 6760 | Excluded.push_back(M2); |
| 6761 | if (M2 == OMPC_SCHEDULE_MODIFIER_nonmonotonic) |
| 6762 | Excluded.push_back(OMPC_SCHEDULE_MODIFIER_monotonic); |
| 6763 | if (M2 == OMPC_SCHEDULE_MODIFIER_monotonic) |
| 6764 | Excluded.push_back(OMPC_SCHEDULE_MODIFIER_nonmonotonic); |
| 6765 | S.Diag(M1Loc, diag::err_omp_unexpected_clause_value) |
| 6766 | << getListOfPossibleValues(OMPC_schedule, |
| 6767 | /*First=*/OMPC_SCHEDULE_MODIFIER_unknown + 1, |
| 6768 | /*Last=*/OMPC_SCHEDULE_MODIFIER_last, |
| 6769 | Excluded) |
| 6770 | << getOpenMPClauseName(OMPC_schedule); |
| 6771 | return true; |
| 6772 | } |
| 6773 | return false; |
| 6774 | } |
| 6775 | |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6776 | OMPClause *Sema::ActOnOpenMPScheduleClause( |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6777 | OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2, |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6778 | OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6779 | SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc, |
| 6780 | SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) { |
| 6781 | if (checkScheduleModifiers(*this, M1, M2, M1Loc, M2Loc) || |
| 6782 | checkScheduleModifiers(*this, M2, M1, M2Loc, M1Loc)) |
| 6783 | return nullptr; |
| 6784 | // OpenMP, 2.7.1, Loop Construct, Restrictions |
| 6785 | // Either the monotonic modifier or the nonmonotonic modifier can be specified |
| 6786 | // but not both. |
| 6787 | if ((M1 == M2 && M1 != OMPC_SCHEDULE_MODIFIER_unknown) || |
| 6788 | (M1 == OMPC_SCHEDULE_MODIFIER_monotonic && |
| 6789 | M2 == OMPC_SCHEDULE_MODIFIER_nonmonotonic) || |
| 6790 | (M1 == OMPC_SCHEDULE_MODIFIER_nonmonotonic && |
| 6791 | M2 == OMPC_SCHEDULE_MODIFIER_monotonic)) { |
| 6792 | Diag(M2Loc, diag::err_omp_unexpected_schedule_modifier) |
| 6793 | << getOpenMPSimpleClauseTypeName(OMPC_schedule, M2) |
| 6794 | << getOpenMPSimpleClauseTypeName(OMPC_schedule, M1); |
| 6795 | return nullptr; |
| 6796 | } |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6797 | if (Kind == OMPC_SCHEDULE_unknown) { |
| 6798 | std::string Values; |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6799 | if (M1Loc.isInvalid() && M2Loc.isInvalid()) { |
| 6800 | unsigned Exclude[] = {OMPC_SCHEDULE_unknown}; |
| 6801 | Values = getListOfPossibleValues(OMPC_schedule, /*First=*/0, |
| 6802 | /*Last=*/OMPC_SCHEDULE_MODIFIER_last, |
| 6803 | Exclude); |
| 6804 | } else { |
| 6805 | Values = getListOfPossibleValues(OMPC_schedule, /*First=*/0, |
| 6806 | /*Last=*/OMPC_SCHEDULE_unknown); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6807 | } |
| 6808 | Diag(KindLoc, diag::err_omp_unexpected_clause_value) |
| 6809 | << Values << getOpenMPClauseName(OMPC_schedule); |
| 6810 | return nullptr; |
| 6811 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6812 | // OpenMP, 2.7.1, Loop Construct, Restrictions |
| 6813 | // The nonmonotonic modifier can only be specified with schedule(dynamic) or |
| 6814 | // schedule(guided). |
| 6815 | if ((M1 == OMPC_SCHEDULE_MODIFIER_nonmonotonic || |
| 6816 | M2 == OMPC_SCHEDULE_MODIFIER_nonmonotonic) && |
| 6817 | Kind != OMPC_SCHEDULE_dynamic && Kind != OMPC_SCHEDULE_guided) { |
| 6818 | Diag(M1 == OMPC_SCHEDULE_MODIFIER_nonmonotonic ? M1Loc : M2Loc, |
| 6819 | diag::err_omp_schedule_nonmonotonic_static); |
| 6820 | return nullptr; |
| 6821 | } |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6822 | Expr *ValExpr = ChunkSize; |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 6823 | Stmt *HelperValStmt = nullptr; |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6824 | if (ChunkSize) { |
| 6825 | if (!ChunkSize->isValueDependent() && !ChunkSize->isTypeDependent() && |
| 6826 | !ChunkSize->isInstantiationDependent() && |
| 6827 | !ChunkSize->containsUnexpandedParameterPack()) { |
| 6828 | SourceLocation ChunkSizeLoc = ChunkSize->getLocStart(); |
| 6829 | ExprResult Val = |
| 6830 | PerformOpenMPImplicitIntegerConversion(ChunkSizeLoc, ChunkSize); |
| 6831 | if (Val.isInvalid()) |
| 6832 | return nullptr; |
| 6833 | |
| 6834 | ValExpr = Val.get(); |
| 6835 | |
| 6836 | // OpenMP [2.7.1, Restrictions] |
| 6837 | // chunk_size must be a loop invariant integer expression with a positive |
| 6838 | // value. |
| 6839 | llvm::APSInt Result; |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 6840 | if (ValExpr->isIntegerConstantExpr(Result, Context)) { |
| 6841 | if (Result.isSigned() && !Result.isStrictlyPositive()) { |
| 6842 | Diag(ChunkSizeLoc, diag::err_omp_negative_expression_in_clause) |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6843 | << "schedule" << 1 << ChunkSize->getSourceRange(); |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 6844 | return nullptr; |
| 6845 | } |
| 6846 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective())) { |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame^] | 6847 | ValExpr = buildCapture(*this, ValExpr); |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 6848 | Decl *D = cast<DeclRefExpr>(ValExpr)->getDecl(); |
| 6849 | HelperValStmt = |
| 6850 | new (Context) DeclStmt(DeclGroupRef::Create(Context, &D, |
| 6851 | /*NumDecls=*/1), |
| 6852 | SourceLocation(), SourceLocation()); |
| 6853 | ValExpr = DefaultLvalueConversion(ValExpr).get(); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6854 | } |
| 6855 | } |
| 6856 | } |
| 6857 | |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6858 | return new (Context) |
| 6859 | OMPScheduleClause(StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc, Kind, |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 6860 | ValExpr, HelperValStmt, M1, M1Loc, M2, M2Loc); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6861 | } |
| 6862 | |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6863 | OMPClause *Sema::ActOnOpenMPClause(OpenMPClauseKind Kind, |
| 6864 | SourceLocation StartLoc, |
| 6865 | SourceLocation EndLoc) { |
| 6866 | OMPClause *Res = nullptr; |
| 6867 | switch (Kind) { |
| 6868 | case OMPC_ordered: |
| 6869 | Res = ActOnOpenMPOrderedClause(StartLoc, EndLoc); |
| 6870 | break; |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6871 | case OMPC_nowait: |
| 6872 | Res = ActOnOpenMPNowaitClause(StartLoc, EndLoc); |
| 6873 | break; |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 6874 | case OMPC_untied: |
| 6875 | Res = ActOnOpenMPUntiedClause(StartLoc, EndLoc); |
| 6876 | break; |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 6877 | case OMPC_mergeable: |
| 6878 | Res = ActOnOpenMPMergeableClause(StartLoc, EndLoc); |
| 6879 | break; |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6880 | case OMPC_read: |
| 6881 | Res = ActOnOpenMPReadClause(StartLoc, EndLoc); |
| 6882 | break; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6883 | case OMPC_write: |
| 6884 | Res = ActOnOpenMPWriteClause(StartLoc, EndLoc); |
| 6885 | break; |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6886 | case OMPC_update: |
| 6887 | Res = ActOnOpenMPUpdateClause(StartLoc, EndLoc); |
| 6888 | break; |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6889 | case OMPC_capture: |
| 6890 | Res = ActOnOpenMPCaptureClause(StartLoc, EndLoc); |
| 6891 | break; |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 6892 | case OMPC_seq_cst: |
| 6893 | Res = ActOnOpenMPSeqCstClause(StartLoc, EndLoc); |
| 6894 | break; |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6895 | case OMPC_threads: |
| 6896 | Res = ActOnOpenMPThreadsClause(StartLoc, EndLoc); |
| 6897 | break; |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6898 | case OMPC_simd: |
| 6899 | Res = ActOnOpenMPSIMDClause(StartLoc, EndLoc); |
| 6900 | break; |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 6901 | case OMPC_nogroup: |
| 6902 | Res = ActOnOpenMPNogroupClause(StartLoc, EndLoc); |
| 6903 | break; |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6904 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 6905 | case OMPC_final: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6906 | case OMPC_num_threads: |
| 6907 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 6908 | case OMPC_simdlen: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6909 | case OMPC_collapse: |
| 6910 | case OMPC_schedule: |
| 6911 | case OMPC_private: |
| 6912 | case OMPC_firstprivate: |
| 6913 | case OMPC_lastprivate: |
| 6914 | case OMPC_shared: |
| 6915 | case OMPC_reduction: |
| 6916 | case OMPC_linear: |
| 6917 | case OMPC_aligned: |
| 6918 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6919 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6920 | case OMPC_default: |
| 6921 | case OMPC_proc_bind: |
| 6922 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 6923 | case OMPC_flush: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6924 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 6925 | case OMPC_device: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 6926 | case OMPC_map: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 6927 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6928 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6929 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 6930 | case OMPC_grainsize: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6931 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 6932 | case OMPC_hint: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 6933 | case OMPC_dist_schedule: |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 6934 | case OMPC_defaultmap: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6935 | case OMPC_unknown: |
| 6936 | llvm_unreachable("Clause is not allowed."); |
| 6937 | } |
| 6938 | return Res; |
| 6939 | } |
| 6940 | |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6941 | OMPClause *Sema::ActOnOpenMPNowaitClause(SourceLocation StartLoc, |
| 6942 | SourceLocation EndLoc) { |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 6943 | DSAStack->setNowaitRegion(); |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6944 | return new (Context) OMPNowaitClause(StartLoc, EndLoc); |
| 6945 | } |
| 6946 | |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 6947 | OMPClause *Sema::ActOnOpenMPUntiedClause(SourceLocation StartLoc, |
| 6948 | SourceLocation EndLoc) { |
| 6949 | return new (Context) OMPUntiedClause(StartLoc, EndLoc); |
| 6950 | } |
| 6951 | |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 6952 | OMPClause *Sema::ActOnOpenMPMergeableClause(SourceLocation StartLoc, |
| 6953 | SourceLocation EndLoc) { |
| 6954 | return new (Context) OMPMergeableClause(StartLoc, EndLoc); |
| 6955 | } |
| 6956 | |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6957 | OMPClause *Sema::ActOnOpenMPReadClause(SourceLocation StartLoc, |
| 6958 | SourceLocation EndLoc) { |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6959 | return new (Context) OMPReadClause(StartLoc, EndLoc); |
| 6960 | } |
| 6961 | |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6962 | OMPClause *Sema::ActOnOpenMPWriteClause(SourceLocation StartLoc, |
| 6963 | SourceLocation EndLoc) { |
| 6964 | return new (Context) OMPWriteClause(StartLoc, EndLoc); |
| 6965 | } |
| 6966 | |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6967 | OMPClause *Sema::ActOnOpenMPUpdateClause(SourceLocation StartLoc, |
| 6968 | SourceLocation EndLoc) { |
| 6969 | return new (Context) OMPUpdateClause(StartLoc, EndLoc); |
| 6970 | } |
| 6971 | |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6972 | OMPClause *Sema::ActOnOpenMPCaptureClause(SourceLocation StartLoc, |
| 6973 | SourceLocation EndLoc) { |
| 6974 | return new (Context) OMPCaptureClause(StartLoc, EndLoc); |
| 6975 | } |
| 6976 | |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 6977 | OMPClause *Sema::ActOnOpenMPSeqCstClause(SourceLocation StartLoc, |
| 6978 | SourceLocation EndLoc) { |
| 6979 | return new (Context) OMPSeqCstClause(StartLoc, EndLoc); |
| 6980 | } |
| 6981 | |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6982 | OMPClause *Sema::ActOnOpenMPThreadsClause(SourceLocation StartLoc, |
| 6983 | SourceLocation EndLoc) { |
| 6984 | return new (Context) OMPThreadsClause(StartLoc, EndLoc); |
| 6985 | } |
| 6986 | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6987 | OMPClause *Sema::ActOnOpenMPSIMDClause(SourceLocation StartLoc, |
| 6988 | SourceLocation EndLoc) { |
| 6989 | return new (Context) OMPSIMDClause(StartLoc, EndLoc); |
| 6990 | } |
| 6991 | |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 6992 | OMPClause *Sema::ActOnOpenMPNogroupClause(SourceLocation StartLoc, |
| 6993 | SourceLocation EndLoc) { |
| 6994 | return new (Context) OMPNogroupClause(StartLoc, EndLoc); |
| 6995 | } |
| 6996 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6997 | OMPClause *Sema::ActOnOpenMPVarListClause( |
| 6998 | OpenMPClauseKind Kind, ArrayRef<Expr *> VarList, Expr *TailExpr, |
| 6999 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, |
| 7000 | SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 7001 | const DeclarationNameInfo &ReductionId, OpenMPDependClauseKind DepKind, |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 7002 | OpenMPLinearClauseKind LinKind, OpenMPMapClauseKind MapTypeModifier, |
| 7003 | OpenMPMapClauseKind MapType, bool IsMapTypeImplicit, |
| 7004 | SourceLocation DepLinMapLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 7005 | OMPClause *Res = nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7006 | switch (Kind) { |
| 7007 | case OMPC_private: |
| 7008 | Res = ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7009 | break; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7010 | case OMPC_firstprivate: |
| 7011 | Res = ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7012 | break; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7013 | case OMPC_lastprivate: |
| 7014 | Res = ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7015 | break; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7016 | case OMPC_shared: |
| 7017 | Res = ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7018 | break; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7019 | case OMPC_reduction: |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 7020 | Res = ActOnOpenMPReductionClause(VarList, StartLoc, LParenLoc, ColonLoc, |
| 7021 | EndLoc, ReductionIdScopeSpec, ReductionId); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7022 | break; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7023 | case OMPC_linear: |
| 7024 | Res = ActOnOpenMPLinearClause(VarList, TailExpr, StartLoc, LParenLoc, |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 7025 | LinKind, DepLinMapLoc, ColonLoc, EndLoc); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7026 | break; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 7027 | case OMPC_aligned: |
| 7028 | Res = ActOnOpenMPAlignedClause(VarList, TailExpr, StartLoc, LParenLoc, |
| 7029 | ColonLoc, EndLoc); |
| 7030 | break; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7031 | case OMPC_copyin: |
| 7032 | Res = ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7033 | break; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7034 | case OMPC_copyprivate: |
| 7035 | Res = ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7036 | break; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 7037 | case OMPC_flush: |
| 7038 | Res = ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7039 | break; |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 7040 | case OMPC_depend: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 7041 | Res = ActOnOpenMPDependClause(DepKind, DepLinMapLoc, ColonLoc, VarList, |
| 7042 | StartLoc, LParenLoc, EndLoc); |
| 7043 | break; |
| 7044 | case OMPC_map: |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 7045 | Res = ActOnOpenMPMapClause(MapTypeModifier, MapType, IsMapTypeImplicit, |
| 7046 | DepLinMapLoc, ColonLoc, VarList, StartLoc, |
| 7047 | LParenLoc, EndLoc); |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 7048 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7049 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 7050 | case OMPC_final: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7051 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 7052 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 7053 | case OMPC_simdlen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 7054 | case OMPC_collapse: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7055 | case OMPC_default: |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 7056 | case OMPC_proc_bind: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7057 | case OMPC_schedule: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7058 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 7059 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 7060 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 7061 | case OMPC_mergeable: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7062 | case OMPC_threadprivate: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 7063 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 7064 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 7065 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 7066 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 7067 | case OMPC_seq_cst: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 7068 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 7069 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 7070 | case OMPC_simd: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 7071 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7072 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 7073 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 7074 | case OMPC_grainsize: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 7075 | case OMPC_nogroup: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 7076 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 7077 | case OMPC_hint: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 7078 | case OMPC_dist_schedule: |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 7079 | case OMPC_defaultmap: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7080 | case OMPC_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7081 | llvm_unreachable("Clause is not allowed."); |
| 7082 | } |
| 7083 | return Res; |
| 7084 | } |
| 7085 | |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 7086 | ExprResult Sema::getOpenMPCapturedExpr(VarDecl *Capture, ExprValueKind VK, |
| 7087 | ExprObjectKind OK) { |
| 7088 | SourceLocation Loc = Capture->getInit()->getExprLoc(); |
| 7089 | ExprResult Res = BuildDeclRefExpr( |
| 7090 | Capture, Capture->getType().getNonReferenceType(), VK_LValue, Loc); |
| 7091 | if (!Res.isUsable()) |
| 7092 | return ExprError(); |
| 7093 | if (OK == OK_Ordinary && !getLangOpts().CPlusPlus) { |
| 7094 | Res = CreateBuiltinUnaryOp(Loc, UO_Deref, Res.get()); |
| 7095 | if (!Res.isUsable()) |
| 7096 | return ExprError(); |
| 7097 | } |
| 7098 | if (VK != VK_LValue && Res.get()->isGLValue()) { |
| 7099 | Res = DefaultLvalueConversion(Res.get()); |
| 7100 | if (!Res.isUsable()) |
| 7101 | return ExprError(); |
| 7102 | } |
| 7103 | return Res; |
| 7104 | } |
| 7105 | |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7106 | static std::pair<ValueDecl *, bool> getPrivateItem(Sema &S, Expr *RefExpr) { |
| 7107 | if (RefExpr->isTypeDependent() || RefExpr->isValueDependent() || |
| 7108 | RefExpr->containsUnexpandedParameterPack()) |
| 7109 | return std::make_pair(nullptr, true); |
| 7110 | |
| 7111 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 7112 | SourceRange SR = RefExpr->getSourceRange(); |
| 7113 | // OpenMP [3.1, C/C++] |
| 7114 | // A list item is a variable name. |
| 7115 | // OpenMP [2.9.3.3, Restrictions, p.1] |
| 7116 | // A variable that is part of another variable (as an array or |
| 7117 | // structure element) cannot appear in a private clause. |
| 7118 | RefExpr = RefExpr->IgnoreParens(); |
| 7119 | auto *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr); |
| 7120 | auto *ME = dyn_cast_or_null<MemberExpr>(RefExpr); |
| 7121 | if ((!DE || !isa<VarDecl>(DE->getDecl())) && |
| 7122 | (S.getCurrentThisType().isNull() || !ME || |
| 7123 | !isa<CXXThisExpr>(ME->getBase()->IgnoreParenImpCasts()) || |
| 7124 | !isa<FieldDecl>(ME->getMemberDecl()))) { |
| 7125 | S.Diag(ELoc, diag::err_omp_expected_var_name_member_expr) |
| 7126 | << (S.getCurrentThisType().isNull() ? 0 : 1) << SR; |
| 7127 | return std::make_pair(nullptr, false); |
| 7128 | } |
| 7129 | return std::make_pair(DE ? DE->getDecl() : ME->getMemberDecl(), false); |
| 7130 | } |
| 7131 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7132 | OMPClause *Sema::ActOnOpenMPPrivateClause(ArrayRef<Expr *> VarList, |
| 7133 | SourceLocation StartLoc, |
| 7134 | SourceLocation LParenLoc, |
| 7135 | SourceLocation EndLoc) { |
| 7136 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 7137 | SmallVector<Expr *, 8> PrivateCopies; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7138 | for (auto &RefExpr : VarList) { |
| 7139 | assert(RefExpr && "NULL expr in OpenMP private clause."); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7140 | auto Res = getPrivateItem(*this, RefExpr); |
| 7141 | if (Res.second) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7142 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7143 | Vars.push_back(RefExpr); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 7144 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7145 | } |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7146 | ValueDecl *D = Res.first; |
| 7147 | if (!D) |
| 7148 | continue; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7149 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7150 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7151 | QualType Type = D->getType(); |
| 7152 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7153 | |
| 7154 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 7155 | // A variable that appears in a private clause must not have an incomplete |
| 7156 | // type or a reference type. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7157 | if (RequireCompleteType(ELoc, Type, diag::err_omp_private_incomplete_type)) |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7158 | continue; |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7159 | Type = Type.getNonReferenceType(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7160 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7161 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 7162 | // in a Construct] |
| 7163 | // Variables with the predetermined data-sharing attributes may not be |
| 7164 | // listed in data-sharing attributes clauses, except for the cases |
| 7165 | // listed below. For these exceptions only, listing a predetermined |
| 7166 | // variable in a data-sharing attribute clause is allowed and overrides |
| 7167 | // the variable's predetermined data-sharing attributes. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7168 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7169 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_private) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7170 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 7171 | << getOpenMPClauseName(OMPC_private); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7172 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7173 | continue; |
| 7174 | } |
| 7175 | |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7176 | // Variably modified types are not supported for tasks. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 7177 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType() && |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7178 | DSAStack->getCurrentDirective() == OMPD_task) { |
| 7179 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
| 7180 | << getOpenMPClauseName(OMPC_private) << Type |
| 7181 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 7182 | bool IsDecl = |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7183 | !VD || |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7184 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7185 | Diag(D->getLocation(), |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7186 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7187 | << D; |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7188 | continue; |
| 7189 | } |
| 7190 | |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7191 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.1] |
| 7192 | // A variable of class type (or array thereof) that appears in a private |
| 7193 | // clause requires an accessible, unambiguous default constructor for the |
| 7194 | // class type. |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 7195 | // Generate helper private variable and initialize it with the default |
| 7196 | // value. The address of the original variable is replaced by the address of |
| 7197 | // the new private variable in CodeGen. This new variable is not added to |
| 7198 | // IdResolver, so the code in the OpenMP region uses original variable for |
| 7199 | // proper diagnostics. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7200 | Type = Type.getUnqualifiedType(); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7201 | auto VDPrivate = buildVarDecl(*this, ELoc, Type, D->getName(), |
| 7202 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7203 | ActOnUninitializedDecl(VDPrivate, /*TypeMayContainAuto=*/false); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 7204 | if (VDPrivate->isInvalidDecl()) |
| 7205 | continue; |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7206 | auto VDPrivateRefExpr = buildDeclRefExpr( |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7207 | *this, VDPrivate, RefExpr->getType().getUnqualifiedType(), ELoc); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 7208 | |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 7209 | DeclRefExpr *Ref = nullptr; |
| 7210 | if (!VD) |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame^] | 7211 | Ref = buildCapture(*this, D, RefExpr); |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 7212 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_private, Ref); |
| 7213 | Vars.push_back(VD ? RefExpr->IgnoreParens() : Ref); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 7214 | PrivateCopies.push_back(VDPrivateRefExpr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7215 | } |
| 7216 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7217 | if (Vars.empty()) |
| 7218 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7219 | |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 7220 | return OMPPrivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
| 7221 | PrivateCopies); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7222 | } |
| 7223 | |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7224 | namespace { |
| 7225 | class DiagsUninitializedSeveretyRAII { |
| 7226 | private: |
| 7227 | DiagnosticsEngine &Diags; |
| 7228 | SourceLocation SavedLoc; |
| 7229 | bool IsIgnored; |
| 7230 | |
| 7231 | public: |
| 7232 | DiagsUninitializedSeveretyRAII(DiagnosticsEngine &Diags, SourceLocation Loc, |
| 7233 | bool IsIgnored) |
| 7234 | : Diags(Diags), SavedLoc(Loc), IsIgnored(IsIgnored) { |
| 7235 | if (!IsIgnored) { |
| 7236 | Diags.setSeverity(/*Diag*/ diag::warn_uninit_self_reference_in_init, |
| 7237 | /*Map*/ diag::Severity::Ignored, Loc); |
| 7238 | } |
| 7239 | } |
| 7240 | ~DiagsUninitializedSeveretyRAII() { |
| 7241 | if (!IsIgnored) |
| 7242 | Diags.popMappings(SavedLoc); |
| 7243 | } |
| 7244 | }; |
Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 7245 | } |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7246 | |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7247 | OMPClause *Sema::ActOnOpenMPFirstprivateClause(ArrayRef<Expr *> VarList, |
| 7248 | SourceLocation StartLoc, |
| 7249 | SourceLocation LParenLoc, |
| 7250 | SourceLocation EndLoc) { |
| 7251 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7252 | SmallVector<Expr *, 8> PrivateCopies; |
| 7253 | SmallVector<Expr *, 8> Inits; |
Alexey Bataev | 417089f | 2016-02-17 13:19:37 +0000 | [diff] [blame] | 7254 | SmallVector<Decl *, 4> ExprCaptures; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7255 | bool IsImplicitClause = |
| 7256 | StartLoc.isInvalid() && LParenLoc.isInvalid() && EndLoc.isInvalid(); |
| 7257 | auto ImplicitClauseLoc = DSAStack->getConstructLoc(); |
| 7258 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7259 | for (auto &RefExpr : VarList) { |
| 7260 | assert(RefExpr && "NULL expr in OpenMP firstprivate clause."); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7261 | auto Res = getPrivateItem(*this, RefExpr); |
| 7262 | if (Res.second) { |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7263 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7264 | Vars.push_back(RefExpr); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7265 | PrivateCopies.push_back(nullptr); |
| 7266 | Inits.push_back(nullptr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7267 | } |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7268 | ValueDecl *D = Res.first; |
| 7269 | if (!D) |
| 7270 | continue; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7271 | |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7272 | SourceLocation ELoc = |
| 7273 | IsImplicitClause ? ImplicitClauseLoc : RefExpr->getExprLoc(); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7274 | QualType Type = D->getType(); |
| 7275 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7276 | |
| 7277 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 7278 | // A variable that appears in a private clause must not have an incomplete |
| 7279 | // type or a reference type. |
| 7280 | if (RequireCompleteType(ELoc, Type, |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7281 | diag::err_omp_firstprivate_incomplete_type)) |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7282 | continue; |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7283 | Type = Type.getNonReferenceType(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7284 | |
| 7285 | // OpenMP [2.9.3.4, Restrictions, C/C++, p.1] |
| 7286 | // 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] | 7287 | // clause requires an accessible, unambiguous copy constructor for the |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7288 | // class type. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7289 | auto ElemType = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7290 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7291 | // If an implicit firstprivate variable found it was checked already. |
| 7292 | if (!IsImplicitClause) { |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7293 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7294 | bool IsConstant = ElemType.isConstant(Context); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7295 | // OpenMP [2.4.13, Data-sharing Attribute Clauses] |
| 7296 | // A list item that specifies a given variable may not appear in more |
| 7297 | // than one clause on the same directive, except that a variable may be |
| 7298 | // specified in both firstprivate and lastprivate clauses. |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7299 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_firstprivate && |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7300 | DVar.CKind != OMPC_lastprivate && DVar.RefExpr) { |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7301 | Diag(ELoc, diag::err_omp_wrong_dsa) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7302 | << getOpenMPClauseName(DVar.CKind) |
| 7303 | << getOpenMPClauseName(OMPC_firstprivate); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7304 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7305 | continue; |
| 7306 | } |
| 7307 | |
| 7308 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 7309 | // in a Construct] |
| 7310 | // Variables with the predetermined data-sharing attributes may not be |
| 7311 | // listed in data-sharing attributes clauses, except for the cases |
| 7312 | // listed below. For these exceptions only, listing a predetermined |
| 7313 | // variable in a data-sharing attribute clause is allowed and overrides |
| 7314 | // the variable's predetermined data-sharing attributes. |
| 7315 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 7316 | // in a Construct, C/C++, p.2] |
| 7317 | // Variables with const-qualified type having no mutable member may be |
| 7318 | // listed in a firstprivate clause, even if they are static data members. |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7319 | if (!(IsConstant || (VD && VD->isStaticDataMember())) && !DVar.RefExpr && |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7320 | DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared) { |
| 7321 | Diag(ELoc, diag::err_omp_wrong_dsa) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7322 | << getOpenMPClauseName(DVar.CKind) |
| 7323 | << getOpenMPClauseName(OMPC_firstprivate); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7324 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7325 | continue; |
| 7326 | } |
| 7327 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7328 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7329 | // OpenMP [2.9.3.4, Restrictions, p.2] |
| 7330 | // A list item that is private within a parallel region must not appear |
| 7331 | // in a firstprivate clause on a worksharing construct if any of the |
| 7332 | // worksharing regions arising from the worksharing construct ever bind |
| 7333 | // to any of the parallel regions arising from the parallel construct. |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 7334 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 7335 | !isOpenMPParallelDirective(CurrDir)) { |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7336 | DVar = DSAStack->getImplicitDSA(D, true); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7337 | if (DVar.CKind != OMPC_shared && |
| 7338 | (isOpenMPParallelDirective(DVar.DKind) || |
| 7339 | DVar.DKind == OMPD_unknown)) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7340 | Diag(ELoc, diag::err_omp_required_access) |
| 7341 | << getOpenMPClauseName(OMPC_firstprivate) |
| 7342 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7343 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7344 | continue; |
| 7345 | } |
| 7346 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7347 | // OpenMP [2.9.3.4, Restrictions, p.3] |
| 7348 | // A list item that appears in a reduction clause of a parallel construct |
| 7349 | // must not appear in a firstprivate clause on a worksharing or task |
| 7350 | // construct if any of the worksharing or task regions arising from the |
| 7351 | // worksharing or task construct ever bind to any of the parallel regions |
| 7352 | // arising from the parallel construct. |
| 7353 | // OpenMP [2.9.3.4, Restrictions, p.4] |
| 7354 | // A list item that appears in a reduction clause in worksharing |
| 7355 | // construct must not appear in a firstprivate clause in a task construct |
| 7356 | // encountered during execution of any of the worksharing regions arising |
| 7357 | // from the worksharing construct. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7358 | if (CurrDir == OMPD_task) { |
| 7359 | DVar = |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7360 | DSAStack->hasInnermostDSA(D, MatchesAnyClause(OMPC_reduction), |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7361 | [](OpenMPDirectiveKind K) -> bool { |
| 7362 | return isOpenMPParallelDirective(K) || |
| 7363 | isOpenMPWorksharingDirective(K); |
| 7364 | }, |
| 7365 | false); |
| 7366 | if (DVar.CKind == OMPC_reduction && |
| 7367 | (isOpenMPParallelDirective(DVar.DKind) || |
| 7368 | isOpenMPWorksharingDirective(DVar.DKind))) { |
| 7369 | Diag(ELoc, diag::err_omp_parallel_reduction_in_task_firstprivate) |
| 7370 | << getOpenMPDirectiveName(DVar.DKind); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7371 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7372 | continue; |
| 7373 | } |
| 7374 | } |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7375 | |
| 7376 | // OpenMP 4.5 [2.15.3.4, Restrictions, p.3] |
| 7377 | // A list item that is private within a teams region must not appear in a |
| 7378 | // firstprivate clause on a distribute construct if any of the distribute |
| 7379 | // regions arising from the distribute construct ever bind to any of the |
| 7380 | // teams regions arising from the teams construct. |
| 7381 | // OpenMP 4.5 [2.15.3.4, Restrictions, p.3] |
| 7382 | // A list item that appears in a reduction clause of a teams construct |
| 7383 | // must not appear in a firstprivate clause on a distribute construct if |
| 7384 | // any of the distribute regions arising from the distribute construct |
| 7385 | // ever bind to any of the teams regions arising from the teams construct. |
| 7386 | // OpenMP 4.5 [2.10.8, Distribute Construct, p.3] |
| 7387 | // A list item may appear in a firstprivate or lastprivate clause but not |
| 7388 | // both. |
| 7389 | if (CurrDir == OMPD_distribute) { |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7390 | DVar = DSAStack->hasInnermostDSA(D, MatchesAnyClause(OMPC_private), |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7391 | [](OpenMPDirectiveKind K) -> bool { |
| 7392 | return isOpenMPTeamsDirective(K); |
| 7393 | }, |
| 7394 | false); |
| 7395 | if (DVar.CKind == OMPC_private && isOpenMPTeamsDirective(DVar.DKind)) { |
| 7396 | Diag(ELoc, diag::err_omp_firstprivate_distribute_private_teams); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7397 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7398 | continue; |
| 7399 | } |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7400 | DVar = DSAStack->hasInnermostDSA(D, MatchesAnyClause(OMPC_reduction), |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7401 | [](OpenMPDirectiveKind K) -> bool { |
| 7402 | return isOpenMPTeamsDirective(K); |
| 7403 | }, |
| 7404 | false); |
| 7405 | if (DVar.CKind == OMPC_reduction && |
| 7406 | isOpenMPTeamsDirective(DVar.DKind)) { |
| 7407 | Diag(ELoc, diag::err_omp_firstprivate_distribute_in_teams_reduction); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7408 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7409 | continue; |
| 7410 | } |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7411 | DVar = DSAStack->getTopDSA(D, false); |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7412 | if (DVar.CKind == OMPC_lastprivate) { |
| 7413 | Diag(ELoc, diag::err_omp_firstprivate_and_lastprivate_in_distribute); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7414 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7415 | continue; |
| 7416 | } |
| 7417 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7418 | } |
| 7419 | |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7420 | // Variably modified types are not supported for tasks. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 7421 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType() && |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7422 | DSAStack->getCurrentDirective() == OMPD_task) { |
| 7423 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
| 7424 | << getOpenMPClauseName(OMPC_firstprivate) << Type |
| 7425 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 7426 | bool IsDecl = |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7427 | !VD || |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7428 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7429 | Diag(D->getLocation(), |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7430 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7431 | << D; |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7432 | continue; |
| 7433 | } |
| 7434 | |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7435 | Type = Type.getUnqualifiedType(); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7436 | auto VDPrivate = buildVarDecl(*this, ELoc, Type, D->getName(), |
| 7437 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7438 | // Generate helper private variable and initialize it with the value of the |
| 7439 | // original variable. The address of the original variable is replaced by |
| 7440 | // the address of the new private variable in the CodeGen. This new variable |
| 7441 | // is not added to IdResolver, so the code in the OpenMP region uses |
| 7442 | // original variable for proper diagnostics and variable capturing. |
| 7443 | Expr *VDInitRefExpr = nullptr; |
| 7444 | // For arrays generate initializer for single element and replace it by the |
| 7445 | // original array element in CodeGen. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7446 | if (Type->isArrayType()) { |
| 7447 | auto VDInit = |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7448 | buildVarDecl(*this, RefExpr->getExprLoc(), ElemType, D->getName()); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7449 | VDInitRefExpr = buildDeclRefExpr(*this, VDInit, ElemType, ELoc); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7450 | auto Init = DefaultLvalueConversion(VDInitRefExpr).get(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7451 | ElemType = ElemType.getUnqualifiedType(); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7452 | auto *VDInitTemp = buildVarDecl(*this, RefExpr->getExprLoc(), ElemType, |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7453 | ".firstprivate.temp"); |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 7454 | InitializedEntity Entity = |
| 7455 | InitializedEntity::InitializeVariable(VDInitTemp); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7456 | InitializationKind Kind = InitializationKind::CreateCopy(ELoc, ELoc); |
| 7457 | |
| 7458 | InitializationSequence InitSeq(*this, Entity, Kind, Init); |
| 7459 | ExprResult Result = InitSeq.Perform(*this, Entity, Kind, Init); |
| 7460 | if (Result.isInvalid()) |
| 7461 | VDPrivate->setInvalidDecl(); |
| 7462 | else |
| 7463 | VDPrivate->setInit(Result.getAs<Expr>()); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7464 | // Remove temp variable declaration. |
| 7465 | Context.Deallocate(VDInitTemp); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7466 | } else { |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7467 | auto *VDInit = buildVarDecl(*this, RefExpr->getExprLoc(), Type, |
| 7468 | ".firstprivate.temp"); |
| 7469 | VDInitRefExpr = buildDeclRefExpr(*this, VDInit, RefExpr->getType(), |
| 7470 | RefExpr->getExprLoc()); |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 7471 | AddInitializerToDecl(VDPrivate, |
| 7472 | DefaultLvalueConversion(VDInitRefExpr).get(), |
| 7473 | /*DirectInit=*/false, /*TypeMayContainAuto=*/false); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7474 | } |
| 7475 | if (VDPrivate->isInvalidDecl()) { |
| 7476 | if (IsImplicitClause) { |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7477 | Diag(RefExpr->getExprLoc(), |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7478 | diag::note_omp_task_predetermined_firstprivate_here); |
| 7479 | } |
| 7480 | continue; |
| 7481 | } |
| 7482 | CurContext->addDecl(VDPrivate); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7483 | auto VDPrivateRefExpr = buildDeclRefExpr( |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7484 | *this, VDPrivate, RefExpr->getType().getUnqualifiedType(), |
| 7485 | RefExpr->getExprLoc()); |
| 7486 | DeclRefExpr *Ref = nullptr; |
Alexey Bataev | 417089f | 2016-02-17 13:19:37 +0000 | [diff] [blame] | 7487 | if (!VD) { |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame^] | 7488 | Ref = buildCapture(*this, D, RefExpr); |
Alexey Bataev | 417089f | 2016-02-17 13:19:37 +0000 | [diff] [blame] | 7489 | ExprCaptures.push_back(Ref->getDecl()); |
| 7490 | } |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7491 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_firstprivate, Ref); |
| 7492 | Vars.push_back(VD ? RefExpr->IgnoreParens() : Ref); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7493 | PrivateCopies.push_back(VDPrivateRefExpr); |
| 7494 | Inits.push_back(VDInitRefExpr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7495 | } |
| 7496 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7497 | if (Vars.empty()) |
| 7498 | return nullptr; |
Alexey Bataev | 417089f | 2016-02-17 13:19:37 +0000 | [diff] [blame] | 7499 | Stmt *PreInit = nullptr; |
| 7500 | if (!ExprCaptures.empty()) { |
| 7501 | PreInit = new (Context) |
| 7502 | DeclStmt(DeclGroupRef::Create(Context, ExprCaptures.begin(), |
| 7503 | ExprCaptures.size()), |
| 7504 | SourceLocation(), SourceLocation()); |
| 7505 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7506 | |
| 7507 | return OMPFirstprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
Alexey Bataev | 417089f | 2016-02-17 13:19:37 +0000 | [diff] [blame] | 7508 | Vars, PrivateCopies, Inits, PreInit); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7509 | } |
| 7510 | |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7511 | OMPClause *Sema::ActOnOpenMPLastprivateClause(ArrayRef<Expr *> VarList, |
| 7512 | SourceLocation StartLoc, |
| 7513 | SourceLocation LParenLoc, |
| 7514 | SourceLocation EndLoc) { |
| 7515 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7516 | SmallVector<Expr *, 8> SrcExprs; |
| 7517 | SmallVector<Expr *, 8> DstExprs; |
| 7518 | SmallVector<Expr *, 8> AssignmentOps; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7519 | for (auto &RefExpr : VarList) { |
| 7520 | assert(RefExpr && "NULL expr in OpenMP lastprivate clause."); |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7521 | auto Res = getPrivateItem(*this, RefExpr); |
| 7522 | if (Res.second) { |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7523 | // It will be analyzed later. |
| 7524 | Vars.push_back(RefExpr); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7525 | SrcExprs.push_back(nullptr); |
| 7526 | DstExprs.push_back(nullptr); |
| 7527 | AssignmentOps.push_back(nullptr); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7528 | } |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7529 | ValueDecl *D = Res.first; |
| 7530 | if (!D) |
| 7531 | continue; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7532 | |
| 7533 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7534 | QualType Type = D->getType(); |
| 7535 | auto *VD = dyn_cast<VarDecl>(D); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7536 | |
| 7537 | // OpenMP [2.14.3.5, Restrictions, C/C++, p.2] |
| 7538 | // A variable that appears in a lastprivate clause must not have an |
| 7539 | // incomplete type or a reference type. |
| 7540 | if (RequireCompleteType(ELoc, Type, |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7541 | diag::err_omp_lastprivate_incomplete_type)) |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7542 | continue; |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7543 | Type = Type.getNonReferenceType(); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7544 | |
| 7545 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 7546 | // in a Construct] |
| 7547 | // Variables with the predetermined data-sharing attributes may not be |
| 7548 | // listed in data-sharing attributes clauses, except for the cases |
| 7549 | // listed below. |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7550 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7551 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_lastprivate && |
| 7552 | DVar.CKind != OMPC_firstprivate && |
| 7553 | (DVar.CKind != OMPC_private || DVar.RefExpr != nullptr)) { |
| 7554 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 7555 | << getOpenMPClauseName(DVar.CKind) |
| 7556 | << getOpenMPClauseName(OMPC_lastprivate); |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7557 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7558 | continue; |
| 7559 | } |
| 7560 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7561 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
| 7562 | // OpenMP [2.14.3.5, Restrictions, p.2] |
| 7563 | // A list item that is private within a parallel region, or that appears in |
| 7564 | // the reduction clause of a parallel construct, must not appear in a |
| 7565 | // lastprivate clause on a worksharing construct if any of the corresponding |
| 7566 | // worksharing regions ever binds to any of the corresponding parallel |
| 7567 | // regions. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7568 | DSAStackTy::DSAVarData TopDVar = DVar; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 7569 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 7570 | !isOpenMPParallelDirective(CurrDir)) { |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7571 | DVar = DSAStack->getImplicitDSA(D, true); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7572 | if (DVar.CKind != OMPC_shared) { |
| 7573 | Diag(ELoc, diag::err_omp_required_access) |
| 7574 | << getOpenMPClauseName(OMPC_lastprivate) |
| 7575 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7576 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7577 | continue; |
| 7578 | } |
| 7579 | } |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7580 | |
| 7581 | // OpenMP 4.5 [2.10.8, Distribute Construct, p.3] |
| 7582 | // A list item may appear in a firstprivate or lastprivate clause but not |
| 7583 | // both. |
| 7584 | if (CurrDir == OMPD_distribute) { |
| 7585 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
| 7586 | if (DVar.CKind == OMPC_firstprivate) { |
| 7587 | Diag(ELoc, diag::err_omp_firstprivate_and_lastprivate_in_distribute); |
| 7588 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
| 7589 | continue; |
| 7590 | } |
| 7591 | } |
| 7592 | |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7593 | // OpenMP [2.14.3.5, Restrictions, C++, p.1,2] |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7594 | // A variable of class type (or array thereof) that appears in a |
| 7595 | // lastprivate clause requires an accessible, unambiguous default |
| 7596 | // constructor for the class type, unless the list item is also specified |
| 7597 | // in a firstprivate clause. |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7598 | // A variable of class type (or array thereof) that appears in a |
| 7599 | // lastprivate clause requires an accessible, unambiguous copy assignment |
| 7600 | // operator for the class type. |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7601 | Type = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7602 | auto *SrcVD = buildVarDecl(*this, RefExpr->getLocStart(), |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 7603 | Type.getUnqualifiedType(), ".lastprivate.src", |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7604 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 7605 | auto *PseudoSrcExpr = |
| 7606 | buildDeclRefExpr(*this, SrcVD, Type.getUnqualifiedType(), ELoc); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7607 | auto *DstVD = |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7608 | buildVarDecl(*this, RefExpr->getLocStart(), Type, ".lastprivate.dst", |
| 7609 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 7610 | auto *PseudoDstExpr = buildDeclRefExpr(*this, DstVD, Type, ELoc); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7611 | // For arrays generate assignment operation for single element and replace |
| 7612 | // it by the original array element in CodeGen. |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7613 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, ELoc, BO_Assign, |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7614 | PseudoDstExpr, PseudoSrcExpr); |
| 7615 | if (AssignmentOp.isInvalid()) |
| 7616 | continue; |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7617 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), ELoc, |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7618 | /*DiscardedValue=*/true); |
| 7619 | if (AssignmentOp.isInvalid()) |
| 7620 | continue; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7621 | |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7622 | DeclRefExpr *Ref = nullptr; |
| 7623 | if (!VD) |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame^] | 7624 | Ref = buildCapture(*this, D, RefExpr); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7625 | if (TopDVar.CKind != OMPC_firstprivate) |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7626 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_lastprivate, Ref); |
| 7627 | Vars.push_back(VD ? RefExpr->IgnoreParens() : Ref); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7628 | SrcExprs.push_back(PseudoSrcExpr); |
| 7629 | DstExprs.push_back(PseudoDstExpr); |
| 7630 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7631 | } |
| 7632 | |
| 7633 | if (Vars.empty()) |
| 7634 | return nullptr; |
| 7635 | |
| 7636 | return OMPLastprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7637 | Vars, SrcExprs, DstExprs, AssignmentOps); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7638 | } |
| 7639 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7640 | OMPClause *Sema::ActOnOpenMPSharedClause(ArrayRef<Expr *> VarList, |
| 7641 | SourceLocation StartLoc, |
| 7642 | SourceLocation LParenLoc, |
| 7643 | SourceLocation EndLoc) { |
| 7644 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7645 | for (auto &RefExpr : VarList) { |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame^] | 7646 | assert(RefExpr && "NULL expr in OpenMP lastprivate clause."); |
| 7647 | auto Res = getPrivateItem(*this, RefExpr); |
| 7648 | if (Res.second) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7649 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7650 | Vars.push_back(RefExpr); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7651 | } |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame^] | 7652 | ValueDecl *D = Res.first; |
| 7653 | if (!D) |
| 7654 | continue; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7655 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7656 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame^] | 7657 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7658 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 7659 | // in a Construct] |
| 7660 | // Variables with the predetermined data-sharing attributes may not be |
| 7661 | // listed in data-sharing attributes clauses, except for the cases |
| 7662 | // listed below. For these exceptions only, listing a predetermined |
| 7663 | // variable in a data-sharing attribute clause is allowed and overrides |
| 7664 | // the variable's predetermined data-sharing attributes. |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame^] | 7665 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7666 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared && |
| 7667 | DVar.RefExpr) { |
| 7668 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 7669 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame^] | 7670 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7671 | continue; |
| 7672 | } |
| 7673 | |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame^] | 7674 | DeclRefExpr *Ref = nullptr; |
| 7675 | if (!VD) |
| 7676 | Ref = buildCapture(*this, D, RefExpr); |
| 7677 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_shared, Ref); |
| 7678 | Vars.push_back(VD ? RefExpr->IgnoreParens() : Ref); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7679 | } |
| 7680 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7681 | if (Vars.empty()) |
| 7682 | return nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7683 | |
| 7684 | return OMPSharedClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars); |
| 7685 | } |
| 7686 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7687 | namespace { |
| 7688 | class DSARefChecker : public StmtVisitor<DSARefChecker, bool> { |
| 7689 | DSAStackTy *Stack; |
| 7690 | |
| 7691 | public: |
| 7692 | bool VisitDeclRefExpr(DeclRefExpr *E) { |
| 7693 | if (VarDecl *VD = dyn_cast<VarDecl>(E->getDecl())) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7694 | DSAStackTy::DSAVarData DVar = Stack->getTopDSA(VD, false); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7695 | if (DVar.CKind == OMPC_shared && !DVar.RefExpr) |
| 7696 | return false; |
| 7697 | if (DVar.CKind != OMPC_unknown) |
| 7698 | return true; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7699 | DSAStackTy::DSAVarData DVarPrivate = |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7700 | Stack->hasDSA(VD, isOpenMPPrivate, MatchesAlways(), false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7701 | if (DVarPrivate.CKind != OMPC_unknown) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7702 | return true; |
| 7703 | return false; |
| 7704 | } |
| 7705 | return false; |
| 7706 | } |
| 7707 | bool VisitStmt(Stmt *S) { |
| 7708 | for (auto Child : S->children()) { |
| 7709 | if (Child && Visit(Child)) |
| 7710 | return true; |
| 7711 | } |
| 7712 | return false; |
| 7713 | } |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 7714 | explicit DSARefChecker(DSAStackTy *S) : Stack(S) {} |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7715 | }; |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 7716 | } // namespace |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7717 | |
| 7718 | OMPClause *Sema::ActOnOpenMPReductionClause( |
| 7719 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, SourceLocation LParenLoc, |
| 7720 | SourceLocation ColonLoc, SourceLocation EndLoc, |
| 7721 | CXXScopeSpec &ReductionIdScopeSpec, |
| 7722 | const DeclarationNameInfo &ReductionId) { |
| 7723 | // TODO: Allow scope specification search when 'declare reduction' is |
| 7724 | // supported. |
| 7725 | assert(ReductionIdScopeSpec.isEmpty() && |
| 7726 | "No support for scoped reduction identifiers yet."); |
| 7727 | |
| 7728 | auto DN = ReductionId.getName(); |
| 7729 | auto OOK = DN.getCXXOverloadedOperator(); |
| 7730 | BinaryOperatorKind BOK = BO_Comma; |
| 7731 | |
| 7732 | // OpenMP [2.14.3.6, reduction clause] |
| 7733 | // C |
| 7734 | // reduction-identifier is either an identifier or one of the following |
| 7735 | // operators: +, -, *, &, |, ^, && and || |
| 7736 | // C++ |
| 7737 | // reduction-identifier is either an id-expression or one of the following |
| 7738 | // operators: +, -, *, &, |, ^, && and || |
| 7739 | // FIXME: Only 'min' and 'max' identifiers are supported for now. |
| 7740 | switch (OOK) { |
| 7741 | case OO_Plus: |
| 7742 | case OO_Minus: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7743 | BOK = BO_Add; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7744 | break; |
| 7745 | case OO_Star: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7746 | BOK = BO_Mul; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7747 | break; |
| 7748 | case OO_Amp: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7749 | BOK = BO_And; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7750 | break; |
| 7751 | case OO_Pipe: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7752 | BOK = BO_Or; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7753 | break; |
| 7754 | case OO_Caret: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7755 | BOK = BO_Xor; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7756 | break; |
| 7757 | case OO_AmpAmp: |
| 7758 | BOK = BO_LAnd; |
| 7759 | break; |
| 7760 | case OO_PipePipe: |
| 7761 | BOK = BO_LOr; |
| 7762 | break; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7763 | case OO_New: |
| 7764 | case OO_Delete: |
| 7765 | case OO_Array_New: |
| 7766 | case OO_Array_Delete: |
| 7767 | case OO_Slash: |
| 7768 | case OO_Percent: |
| 7769 | case OO_Tilde: |
| 7770 | case OO_Exclaim: |
| 7771 | case OO_Equal: |
| 7772 | case OO_Less: |
| 7773 | case OO_Greater: |
| 7774 | case OO_LessEqual: |
| 7775 | case OO_GreaterEqual: |
| 7776 | case OO_PlusEqual: |
| 7777 | case OO_MinusEqual: |
| 7778 | case OO_StarEqual: |
| 7779 | case OO_SlashEqual: |
| 7780 | case OO_PercentEqual: |
| 7781 | case OO_CaretEqual: |
| 7782 | case OO_AmpEqual: |
| 7783 | case OO_PipeEqual: |
| 7784 | case OO_LessLess: |
| 7785 | case OO_GreaterGreater: |
| 7786 | case OO_LessLessEqual: |
| 7787 | case OO_GreaterGreaterEqual: |
| 7788 | case OO_EqualEqual: |
| 7789 | case OO_ExclaimEqual: |
| 7790 | case OO_PlusPlus: |
| 7791 | case OO_MinusMinus: |
| 7792 | case OO_Comma: |
| 7793 | case OO_ArrowStar: |
| 7794 | case OO_Arrow: |
| 7795 | case OO_Call: |
| 7796 | case OO_Subscript: |
| 7797 | case OO_Conditional: |
Richard Smith | 9be594e | 2015-10-22 05:12:22 +0000 | [diff] [blame] | 7798 | case OO_Coawait: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7799 | case NUM_OVERLOADED_OPERATORS: |
| 7800 | llvm_unreachable("Unexpected reduction identifier"); |
| 7801 | case OO_None: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7802 | if (auto II = DN.getAsIdentifierInfo()) { |
| 7803 | if (II->isStr("max")) |
| 7804 | BOK = BO_GT; |
| 7805 | else if (II->isStr("min")) |
| 7806 | BOK = BO_LT; |
| 7807 | } |
| 7808 | break; |
| 7809 | } |
| 7810 | SourceRange ReductionIdRange; |
| 7811 | if (ReductionIdScopeSpec.isValid()) { |
| 7812 | ReductionIdRange.setBegin(ReductionIdScopeSpec.getBeginLoc()); |
| 7813 | } |
| 7814 | ReductionIdRange.setEnd(ReductionId.getEndLoc()); |
| 7815 | if (BOK == BO_Comma) { |
| 7816 | // Not allowed reduction identifier is found. |
| 7817 | Diag(ReductionId.getLocStart(), diag::err_omp_unknown_reduction_identifier) |
| 7818 | << ReductionIdRange; |
| 7819 | return nullptr; |
| 7820 | } |
| 7821 | |
| 7822 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7823 | SmallVector<Expr *, 8> Privates; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7824 | SmallVector<Expr *, 8> LHSs; |
| 7825 | SmallVector<Expr *, 8> RHSs; |
| 7826 | SmallVector<Expr *, 8> ReductionOps; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7827 | for (auto RefExpr : VarList) { |
| 7828 | assert(RefExpr && "nullptr expr in OpenMP reduction clause."); |
| 7829 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 7830 | // It will be analyzed later. |
| 7831 | Vars.push_back(RefExpr); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7832 | Privates.push_back(nullptr); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7833 | LHSs.push_back(nullptr); |
| 7834 | RHSs.push_back(nullptr); |
| 7835 | ReductionOps.push_back(nullptr); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7836 | continue; |
| 7837 | } |
| 7838 | |
| 7839 | if (RefExpr->isTypeDependent() || RefExpr->isValueDependent() || |
| 7840 | RefExpr->isInstantiationDependent() || |
| 7841 | RefExpr->containsUnexpandedParameterPack()) { |
| 7842 | // It will be analyzed later. |
| 7843 | Vars.push_back(RefExpr); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7844 | Privates.push_back(nullptr); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7845 | LHSs.push_back(nullptr); |
| 7846 | RHSs.push_back(nullptr); |
| 7847 | ReductionOps.push_back(nullptr); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7848 | continue; |
| 7849 | } |
| 7850 | |
| 7851 | auto ELoc = RefExpr->getExprLoc(); |
| 7852 | auto ERange = RefExpr->getSourceRange(); |
| 7853 | // OpenMP [2.1, C/C++] |
| 7854 | // A list item is a variable or array section, subject to the restrictions |
| 7855 | // specified in Section 2.4 on page 42 and in each of the sections |
| 7856 | // describing clauses and directives for which a list appears. |
| 7857 | // OpenMP [2.14.3.3, Restrictions, p.1] |
| 7858 | // A variable that is part of another variable (as an array or |
| 7859 | // structure element) cannot appear in a private clause. |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7860 | auto *DE = dyn_cast<DeclRefExpr>(RefExpr); |
| 7861 | auto *ASE = dyn_cast<ArraySubscriptExpr>(RefExpr); |
| 7862 | auto *OASE = dyn_cast<OMPArraySectionExpr>(RefExpr); |
| 7863 | if (!ASE && !OASE && (!DE || !isa<VarDecl>(DE->getDecl()))) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7864 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr_or_array_item) |
| 7865 | << 0 << ERange; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7866 | continue; |
| 7867 | } |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7868 | QualType Type; |
| 7869 | VarDecl *VD = nullptr; |
| 7870 | if (DE) { |
| 7871 | auto D = DE->getDecl(); |
| 7872 | VD = cast<VarDecl>(D); |
Alexey Bataev | 31300ed | 2016-02-04 11:27:03 +0000 | [diff] [blame] | 7873 | Type = Context.getBaseElementType(VD->getType().getNonReferenceType()); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7874 | } else if (ASE) { |
Alexey Bataev | 31300ed | 2016-02-04 11:27:03 +0000 | [diff] [blame] | 7875 | Type = ASE->getType().getNonReferenceType(); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7876 | auto *Base = ASE->getBase()->IgnoreParenImpCasts(); |
| 7877 | while (auto *TempASE = dyn_cast<ArraySubscriptExpr>(Base)) |
| 7878 | Base = TempASE->getBase()->IgnoreParenImpCasts(); |
| 7879 | DE = dyn_cast<DeclRefExpr>(Base); |
| 7880 | if (DE) |
| 7881 | VD = dyn_cast<VarDecl>(DE->getDecl()); |
| 7882 | if (!VD) { |
| 7883 | Diag(Base->getExprLoc(), diag::err_omp_expected_base_var_name) |
| 7884 | << 0 << Base->getSourceRange(); |
| 7885 | continue; |
| 7886 | } |
| 7887 | } else if (OASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7888 | auto BaseType = OMPArraySectionExpr::getBaseOriginalType(OASE->getBase()); |
| 7889 | if (auto *ATy = BaseType->getAsArrayTypeUnsafe()) |
| 7890 | Type = ATy->getElementType(); |
| 7891 | else |
| 7892 | Type = BaseType->getPointeeType(); |
Alexey Bataev | 31300ed | 2016-02-04 11:27:03 +0000 | [diff] [blame] | 7893 | Type = Type.getNonReferenceType(); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7894 | auto *Base = OASE->getBase()->IgnoreParenImpCasts(); |
| 7895 | while (auto *TempOASE = dyn_cast<OMPArraySectionExpr>(Base)) |
| 7896 | Base = TempOASE->getBase()->IgnoreParenImpCasts(); |
| 7897 | while (auto *TempASE = dyn_cast<ArraySubscriptExpr>(Base)) |
| 7898 | Base = TempASE->getBase()->IgnoreParenImpCasts(); |
| 7899 | DE = dyn_cast<DeclRefExpr>(Base); |
| 7900 | if (DE) |
| 7901 | VD = dyn_cast<VarDecl>(DE->getDecl()); |
| 7902 | if (!VD) { |
| 7903 | Diag(Base->getExprLoc(), diag::err_omp_expected_base_var_name) |
| 7904 | << 1 << Base->getSourceRange(); |
| 7905 | continue; |
| 7906 | } |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7907 | } |
| 7908 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7909 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 7910 | // A variable that appears in a private clause must not have an incomplete |
| 7911 | // type or a reference type. |
| 7912 | if (RequireCompleteType(ELoc, Type, |
| 7913 | diag::err_omp_reduction_incomplete_type)) |
| 7914 | continue; |
| 7915 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7916 | // A list item that appears in a reduction clause must not be |
| 7917 | // const-qualified. |
| 7918 | if (Type.getNonReferenceType().isConstant(Context)) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7919 | Diag(ELoc, diag::err_omp_const_reduction_list_item) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7920 | << getOpenMPClauseName(OMPC_reduction) << Type << ERange; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7921 | if (!ASE && !OASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7922 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 7923 | VarDecl::DeclarationOnly; |
| 7924 | Diag(VD->getLocation(), |
| 7925 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7926 | << VD; |
| 7927 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7928 | continue; |
| 7929 | } |
| 7930 | // OpenMP [2.9.3.6, Restrictions, C/C++, p.4] |
| 7931 | // If a list-item is a reference type then it must bind to the same object |
| 7932 | // for all threads of the team. |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7933 | if (!ASE && !OASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7934 | VarDecl *VDDef = VD->getDefinition(); |
Alexey Bataev | 31300ed | 2016-02-04 11:27:03 +0000 | [diff] [blame] | 7935 | if (VD->getType()->isReferenceType() && VDDef) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7936 | DSARefChecker Check(DSAStack); |
| 7937 | if (Check.Visit(VDDef->getInit())) { |
| 7938 | Diag(ELoc, diag::err_omp_reduction_ref_type_arg) << ERange; |
| 7939 | Diag(VDDef->getLocation(), diag::note_defined_here) << VDDef; |
| 7940 | continue; |
| 7941 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7942 | } |
| 7943 | } |
| 7944 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
| 7945 | // The type of a list item that appears in a reduction clause must be valid |
| 7946 | // for the reduction-identifier. For a max or min reduction in C, the type |
| 7947 | // of the list item must be an allowed arithmetic data type: char, int, |
| 7948 | // float, double, or _Bool, possibly modified with long, short, signed, or |
| 7949 | // unsigned. For a max or min reduction in C++, the type of the list item |
| 7950 | // must be an allowed arithmetic data type: char, wchar_t, int, float, |
| 7951 | // double, or bool, possibly modified with long, short, signed, or unsigned. |
| 7952 | if ((BOK == BO_GT || BOK == BO_LT) && |
| 7953 | !(Type->isScalarType() || |
| 7954 | (getLangOpts().CPlusPlus && Type->isArithmeticType()))) { |
| 7955 | Diag(ELoc, diag::err_omp_clause_not_arithmetic_type_arg) |
| 7956 | << getLangOpts().CPlusPlus; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7957 | if (!ASE && !OASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7958 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 7959 | VarDecl::DeclarationOnly; |
| 7960 | Diag(VD->getLocation(), |
| 7961 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7962 | << VD; |
| 7963 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7964 | continue; |
| 7965 | } |
| 7966 | if ((BOK == BO_OrAssign || BOK == BO_AndAssign || BOK == BO_XorAssign) && |
| 7967 | !getLangOpts().CPlusPlus && Type->isFloatingType()) { |
| 7968 | Diag(ELoc, diag::err_omp_clause_floating_type_arg); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7969 | if (!ASE && !OASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7970 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 7971 | VarDecl::DeclarationOnly; |
| 7972 | Diag(VD->getLocation(), |
| 7973 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7974 | << VD; |
| 7975 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7976 | continue; |
| 7977 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7978 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 7979 | // in a Construct] |
| 7980 | // Variables with the predetermined data-sharing attributes may not be |
| 7981 | // listed in data-sharing attributes clauses, except for the cases |
| 7982 | // listed below. For these exceptions only, listing a predetermined |
| 7983 | // variable in a data-sharing attribute clause is allowed and overrides |
| 7984 | // the variable's predetermined data-sharing attributes. |
| 7985 | // OpenMP [2.14.3.6, Restrictions, p.3] |
| 7986 | // Any number of reduction clauses can be specified on the directive, |
| 7987 | // but a list item can appear only once in the reduction clauses for that |
| 7988 | // directive. |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7989 | DSAStackTy::DSAVarData DVar; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7990 | DVar = DSAStack->getTopDSA(VD, false); |
| 7991 | if (DVar.CKind == OMPC_reduction) { |
| 7992 | Diag(ELoc, diag::err_omp_once_referenced) |
| 7993 | << getOpenMPClauseName(OMPC_reduction); |
| 7994 | if (DVar.RefExpr) { |
| 7995 | Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_referenced); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7996 | } |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7997 | } else if (DVar.CKind != OMPC_unknown) { |
| 7998 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 7999 | << getOpenMPClauseName(DVar.CKind) |
| 8000 | << getOpenMPClauseName(OMPC_reduction); |
| 8001 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 8002 | continue; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8003 | } |
| 8004 | |
| 8005 | // OpenMP [2.14.3.6, Restrictions, p.1] |
| 8006 | // A list item that appears in a reduction clause of a worksharing |
| 8007 | // construct must be shared in the parallel regions to which any of the |
| 8008 | // worksharing regions arising from the worksharing construct bind. |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8009 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
| 8010 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 8011 | !isOpenMPParallelDirective(CurrDir)) { |
| 8012 | DVar = DSAStack->getImplicitDSA(VD, true); |
| 8013 | if (DVar.CKind != OMPC_shared) { |
| 8014 | Diag(ELoc, diag::err_omp_required_access) |
| 8015 | << getOpenMPClauseName(OMPC_reduction) |
| 8016 | << getOpenMPClauseName(OMPC_shared); |
| 8017 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 8018 | continue; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 8019 | } |
| 8020 | } |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8021 | |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8022 | Type = Type.getNonLValueExprType(Context).getUnqualifiedType(); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8023 | auto *LHSVD = buildVarDecl(*this, ELoc, Type, ".reduction.lhs", |
| 8024 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
| 8025 | auto *RHSVD = buildVarDecl(*this, ELoc, Type, VD->getName(), |
| 8026 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
| 8027 | auto PrivateTy = Type; |
Alexey Bataev | 1189bd0 | 2016-01-26 12:20:39 +0000 | [diff] [blame] | 8028 | if (OASE || |
| 8029 | (DE && VD->getType().getNonReferenceType()->isVariablyModifiedType())) { |
| 8030 | // For arays/array sections only: |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8031 | // Create pseudo array type for private copy. The size for this array will |
| 8032 | // be generated during codegen. |
| 8033 | // For array subscripts or single variables Private Ty is the same as Type |
| 8034 | // (type of the variable or single array element). |
| 8035 | PrivateTy = Context.getVariableArrayType( |
| 8036 | Type, new (Context) OpaqueValueExpr(SourceLocation(), |
| 8037 | Context.getSizeType(), VK_RValue), |
| 8038 | ArrayType::Normal, /*IndexTypeQuals=*/0, SourceRange()); |
Alexey Bataev | 1189bd0 | 2016-01-26 12:20:39 +0000 | [diff] [blame] | 8039 | } else if (DE && |
| 8040 | Context.getAsArrayType(VD->getType().getNonReferenceType())) |
| 8041 | PrivateTy = VD->getType().getNonReferenceType(); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8042 | // Private copy. |
| 8043 | auto *PrivateVD = buildVarDecl(*this, ELoc, PrivateTy, VD->getName(), |
| 8044 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8045 | // Add initializer for private variable. |
| 8046 | Expr *Init = nullptr; |
| 8047 | switch (BOK) { |
| 8048 | case BO_Add: |
| 8049 | case BO_Xor: |
| 8050 | case BO_Or: |
| 8051 | case BO_LOr: |
| 8052 | // '+', '-', '^', '|', '||' reduction ops - initializer is '0'. |
| 8053 | if (Type->isScalarType() || Type->isAnyComplexType()) { |
| 8054 | Init = ActOnIntegerConstant(ELoc, /*Val=*/0).get(); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8055 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8056 | break; |
| 8057 | case BO_Mul: |
| 8058 | case BO_LAnd: |
| 8059 | if (Type->isScalarType() || Type->isAnyComplexType()) { |
| 8060 | // '*' and '&&' reduction ops - initializer is '1'. |
| 8061 | Init = ActOnIntegerConstant(ELoc, /*Val=*/1).get(); |
| 8062 | } |
| 8063 | break; |
| 8064 | case BO_And: { |
| 8065 | // '&' reduction op - initializer is '~0'. |
| 8066 | QualType OrigType = Type; |
| 8067 | if (auto *ComplexTy = OrigType->getAs<ComplexType>()) { |
| 8068 | Type = ComplexTy->getElementType(); |
| 8069 | } |
| 8070 | if (Type->isRealFloatingType()) { |
| 8071 | llvm::APFloat InitValue = |
| 8072 | llvm::APFloat::getAllOnesValue(Context.getTypeSize(Type), |
| 8073 | /*isIEEE=*/true); |
| 8074 | Init = FloatingLiteral::Create(Context, InitValue, /*isexact=*/true, |
| 8075 | Type, ELoc); |
| 8076 | } else if (Type->isScalarType()) { |
| 8077 | auto Size = Context.getTypeSize(Type); |
| 8078 | QualType IntTy = Context.getIntTypeForBitwidth(Size, /*Signed=*/0); |
| 8079 | llvm::APInt InitValue = llvm::APInt::getAllOnesValue(Size); |
| 8080 | Init = IntegerLiteral::Create(Context, InitValue, IntTy, ELoc); |
| 8081 | } |
| 8082 | if (Init && OrigType->isAnyComplexType()) { |
| 8083 | // Init = 0xFFFF + 0xFFFFi; |
| 8084 | auto *Im = new (Context) ImaginaryLiteral(Init, OrigType); |
| 8085 | Init = CreateBuiltinBinOp(ELoc, BO_Add, Init, Im).get(); |
| 8086 | } |
| 8087 | Type = OrigType; |
| 8088 | break; |
| 8089 | } |
| 8090 | case BO_LT: |
| 8091 | case BO_GT: { |
| 8092 | // 'min' reduction op - initializer is 'Largest representable number in |
| 8093 | // the reduction list item type'. |
| 8094 | // 'max' reduction op - initializer is 'Least representable number in |
| 8095 | // the reduction list item type'. |
| 8096 | if (Type->isIntegerType() || Type->isPointerType()) { |
| 8097 | bool IsSigned = Type->hasSignedIntegerRepresentation(); |
| 8098 | auto Size = Context.getTypeSize(Type); |
| 8099 | QualType IntTy = |
| 8100 | Context.getIntTypeForBitwidth(Size, /*Signed=*/IsSigned); |
| 8101 | llvm::APInt InitValue = |
| 8102 | (BOK != BO_LT) |
| 8103 | ? IsSigned ? llvm::APInt::getSignedMinValue(Size) |
| 8104 | : llvm::APInt::getMinValue(Size) |
| 8105 | : IsSigned ? llvm::APInt::getSignedMaxValue(Size) |
| 8106 | : llvm::APInt::getMaxValue(Size); |
| 8107 | Init = IntegerLiteral::Create(Context, InitValue, IntTy, ELoc); |
| 8108 | if (Type->isPointerType()) { |
| 8109 | // Cast to pointer type. |
| 8110 | auto CastExpr = BuildCStyleCastExpr( |
| 8111 | SourceLocation(), Context.getTrivialTypeSourceInfo(Type, ELoc), |
| 8112 | SourceLocation(), Init); |
| 8113 | if (CastExpr.isInvalid()) |
| 8114 | continue; |
| 8115 | Init = CastExpr.get(); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8116 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8117 | } else if (Type->isRealFloatingType()) { |
| 8118 | llvm::APFloat InitValue = llvm::APFloat::getLargest( |
| 8119 | Context.getFloatTypeSemantics(Type), BOK != BO_LT); |
| 8120 | Init = FloatingLiteral::Create(Context, InitValue, /*isexact=*/true, |
| 8121 | Type, ELoc); |
| 8122 | } |
| 8123 | break; |
| 8124 | } |
| 8125 | case BO_PtrMemD: |
| 8126 | case BO_PtrMemI: |
| 8127 | case BO_MulAssign: |
| 8128 | case BO_Div: |
| 8129 | case BO_Rem: |
| 8130 | case BO_Sub: |
| 8131 | case BO_Shl: |
| 8132 | case BO_Shr: |
| 8133 | case BO_LE: |
| 8134 | case BO_GE: |
| 8135 | case BO_EQ: |
| 8136 | case BO_NE: |
| 8137 | case BO_AndAssign: |
| 8138 | case BO_XorAssign: |
| 8139 | case BO_OrAssign: |
| 8140 | case BO_Assign: |
| 8141 | case BO_AddAssign: |
| 8142 | case BO_SubAssign: |
| 8143 | case BO_DivAssign: |
| 8144 | case BO_RemAssign: |
| 8145 | case BO_ShlAssign: |
| 8146 | case BO_ShrAssign: |
| 8147 | case BO_Comma: |
| 8148 | llvm_unreachable("Unexpected reduction operation"); |
| 8149 | } |
| 8150 | if (Init) { |
| 8151 | AddInitializerToDecl(RHSVD, Init, /*DirectInit=*/false, |
| 8152 | /*TypeMayContainAuto=*/false); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8153 | } else |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8154 | ActOnUninitializedDecl(RHSVD, /*TypeMayContainAuto=*/false); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8155 | if (!RHSVD->hasInit()) { |
| 8156 | Diag(ELoc, diag::err_omp_reduction_id_not_compatible) << Type |
| 8157 | << ReductionIdRange; |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8158 | if (VD) { |
| 8159 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 8160 | VarDecl::DeclarationOnly; |
| 8161 | Diag(VD->getLocation(), |
| 8162 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 8163 | << VD; |
| 8164 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8165 | continue; |
| 8166 | } |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8167 | // Store initializer for single element in private copy. Will be used during |
| 8168 | // codegen. |
| 8169 | PrivateVD->setInit(RHSVD->getInit()); |
| 8170 | PrivateVD->setInitStyle(RHSVD->getInitStyle()); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 8171 | auto *LHSDRE = buildDeclRefExpr(*this, LHSVD, Type, ELoc); |
| 8172 | auto *RHSDRE = buildDeclRefExpr(*this, RHSVD, Type, ELoc); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8173 | auto *PrivateDRE = buildDeclRefExpr(*this, PrivateVD, PrivateTy, ELoc); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8174 | ExprResult ReductionOp = |
| 8175 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), BOK, |
| 8176 | LHSDRE, RHSDRE); |
| 8177 | if (ReductionOp.isUsable()) { |
Alexey Bataev | 69a4779 | 2015-05-07 03:54:03 +0000 | [diff] [blame] | 8178 | if (BOK != BO_LT && BOK != BO_GT) { |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8179 | ReductionOp = |
| 8180 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), |
| 8181 | BO_Assign, LHSDRE, ReductionOp.get()); |
| 8182 | } else { |
| 8183 | auto *ConditionalOp = new (Context) ConditionalOperator( |
| 8184 | ReductionOp.get(), SourceLocation(), LHSDRE, SourceLocation(), |
| 8185 | RHSDRE, Type, VK_LValue, OK_Ordinary); |
| 8186 | ReductionOp = |
| 8187 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), |
| 8188 | BO_Assign, LHSDRE, ConditionalOp); |
| 8189 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 8190 | ReductionOp = ActOnFinishFullExpr(ReductionOp.get()); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8191 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8192 | if (ReductionOp.isInvalid()) |
| 8193 | continue; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8194 | |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8195 | DSAStack->addDSA(VD, DE, OMPC_reduction); |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8196 | Vars.push_back(RefExpr); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8197 | Privates.push_back(PrivateDRE); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8198 | LHSs.push_back(LHSDRE); |
| 8199 | RHSs.push_back(RHSDRE); |
| 8200 | ReductionOps.push_back(ReductionOp.get()); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8201 | } |
| 8202 | |
| 8203 | if (Vars.empty()) |
| 8204 | return nullptr; |
| 8205 | |
| 8206 | return OMPReductionClause::Create( |
| 8207 | Context, StartLoc, LParenLoc, ColonLoc, EndLoc, Vars, |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8208 | ReductionIdScopeSpec.getWithLocInContext(Context), ReductionId, Privates, |
| 8209 | LHSs, RHSs, ReductionOps); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8210 | } |
| 8211 | |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 8212 | OMPClause *Sema::ActOnOpenMPLinearClause( |
| 8213 | ArrayRef<Expr *> VarList, Expr *Step, SourceLocation StartLoc, |
| 8214 | SourceLocation LParenLoc, OpenMPLinearClauseKind LinKind, |
| 8215 | SourceLocation LinLoc, SourceLocation ColonLoc, SourceLocation EndLoc) { |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8216 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8217 | SmallVector<Expr *, 8> Privates; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8218 | SmallVector<Expr *, 8> Inits; |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 8219 | if ((!LangOpts.CPlusPlus && LinKind != OMPC_LINEAR_val) || |
| 8220 | LinKind == OMPC_LINEAR_unknown) { |
| 8221 | Diag(LinLoc, diag::err_omp_wrong_linear_modifier) << LangOpts.CPlusPlus; |
| 8222 | LinKind = OMPC_LINEAR_val; |
| 8223 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8224 | for (auto &RefExpr : VarList) { |
| 8225 | assert(RefExpr && "NULL expr in OpenMP linear clause."); |
| 8226 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8227 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8228 | Vars.push_back(RefExpr); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8229 | Privates.push_back(nullptr); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8230 | Inits.push_back(nullptr); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8231 | continue; |
| 8232 | } |
| 8233 | |
| 8234 | // OpenMP [2.14.3.7, linear clause] |
| 8235 | // A list item that appears in a linear clause is subject to the private |
| 8236 | // clause semantics described in Section 2.14.3.3 on page 159 except as |
| 8237 | // noted. In addition, the value of the new list item on each iteration |
| 8238 | // of the associated loop(s) corresponds to the value of the original |
| 8239 | // list item before entering the construct plus the logical number of |
| 8240 | // the iteration times linear-step. |
| 8241 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8242 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8243 | // OpenMP [2.1, C/C++] |
| 8244 | // A list item is a variable name. |
| 8245 | // OpenMP [2.14.3.3, Restrictions, p.1] |
| 8246 | // A variable that is part of another variable (as an array or |
| 8247 | // structure element) cannot appear in a private clause. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8248 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8249 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8250 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr) |
| 8251 | << 0 << RefExpr->getSourceRange(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8252 | continue; |
| 8253 | } |
| 8254 | |
| 8255 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); |
| 8256 | |
| 8257 | // OpenMP [2.14.3.7, linear clause] |
| 8258 | // A list-item cannot appear in more than one linear clause. |
| 8259 | // A list-item that appears in a linear clause cannot appear in any |
| 8260 | // other data-sharing attribute clause. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 8261 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8262 | if (DVar.RefExpr) { |
| 8263 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 8264 | << getOpenMPClauseName(OMPC_linear); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 8265 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8266 | continue; |
| 8267 | } |
| 8268 | |
| 8269 | QualType QType = VD->getType(); |
| 8270 | if (QType->isDependentType() || QType->isInstantiationDependentType()) { |
| 8271 | // It will be analyzed later. |
| 8272 | Vars.push_back(DE); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8273 | Privates.push_back(nullptr); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8274 | Inits.push_back(nullptr); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8275 | continue; |
| 8276 | } |
| 8277 | |
| 8278 | // A variable must not have an incomplete type or a reference type. |
| 8279 | if (RequireCompleteType(ELoc, QType, |
| 8280 | diag::err_omp_linear_incomplete_type)) { |
| 8281 | continue; |
| 8282 | } |
Alexey Bataev | 1185e19 | 2015-08-20 12:15:57 +0000 | [diff] [blame] | 8283 | if ((LinKind == OMPC_LINEAR_uval || LinKind == OMPC_LINEAR_ref) && |
| 8284 | !QType->isReferenceType()) { |
| 8285 | Diag(ELoc, diag::err_omp_wrong_linear_modifier_non_reference) |
| 8286 | << QType << getOpenMPSimpleClauseTypeName(OMPC_linear, LinKind); |
| 8287 | continue; |
| 8288 | } |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8289 | QType = QType.getNonReferenceType(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8290 | |
| 8291 | // A list item must not be const-qualified. |
| 8292 | if (QType.isConstant(Context)) { |
| 8293 | Diag(ELoc, diag::err_omp_const_variable) |
| 8294 | << getOpenMPClauseName(OMPC_linear); |
| 8295 | bool IsDecl = |
| 8296 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 8297 | Diag(VD->getLocation(), |
| 8298 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 8299 | << VD; |
| 8300 | continue; |
| 8301 | } |
| 8302 | |
| 8303 | // A list item must be of integral or pointer type. |
| 8304 | QType = QType.getUnqualifiedType().getCanonicalType(); |
| 8305 | const Type *Ty = QType.getTypePtrOrNull(); |
| 8306 | if (!Ty || (!Ty->isDependentType() && !Ty->isIntegralType(Context) && |
| 8307 | !Ty->isPointerType())) { |
| 8308 | Diag(ELoc, diag::err_omp_linear_expected_int_or_ptr) << QType; |
| 8309 | bool IsDecl = |
| 8310 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 8311 | Diag(VD->getLocation(), |
| 8312 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 8313 | << VD; |
| 8314 | continue; |
| 8315 | } |
| 8316 | |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8317 | // Build private copy of original var. |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 8318 | auto *Private = buildVarDecl(*this, ELoc, QType, VD->getName(), |
| 8319 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8320 | auto *PrivateRef = buildDeclRefExpr( |
| 8321 | *this, Private, DE->getType().getUnqualifiedType(), DE->getExprLoc()); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8322 | // Build var to save initial value. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8323 | VarDecl *Init = buildVarDecl(*this, ELoc, QType, ".linear.start"); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 8324 | Expr *InitExpr; |
| 8325 | if (LinKind == OMPC_LINEAR_uval) |
| 8326 | InitExpr = VD->getInit(); |
| 8327 | else |
| 8328 | InitExpr = DE; |
| 8329 | AddInitializerToDecl(Init, DefaultLvalueConversion(InitExpr).get(), |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8330 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8331 | auto InitRef = buildDeclRefExpr( |
| 8332 | *this, Init, DE->getType().getUnqualifiedType(), DE->getExprLoc()); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8333 | DSAStack->addDSA(VD, DE, OMPC_linear); |
| 8334 | Vars.push_back(DE); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8335 | Privates.push_back(PrivateRef); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8336 | Inits.push_back(InitRef); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8337 | } |
| 8338 | |
| 8339 | if (Vars.empty()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 8340 | return nullptr; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8341 | |
| 8342 | Expr *StepExpr = Step; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8343 | Expr *CalcStepExpr = nullptr; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8344 | if (Step && !Step->isValueDependent() && !Step->isTypeDependent() && |
| 8345 | !Step->isInstantiationDependent() && |
| 8346 | !Step->containsUnexpandedParameterPack()) { |
| 8347 | SourceLocation StepLoc = Step->getLocStart(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 8348 | ExprResult Val = PerformOpenMPImplicitIntegerConversion(StepLoc, Step); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8349 | if (Val.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 8350 | return nullptr; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 8351 | StepExpr = Val.get(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8352 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8353 | // Build var to save the step value. |
| 8354 | VarDecl *SaveVar = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 8355 | buildVarDecl(*this, StepLoc, StepExpr->getType(), ".linear.step"); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8356 | ExprResult SaveRef = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 8357 | buildDeclRefExpr(*this, SaveVar, StepExpr->getType(), StepLoc); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8358 | ExprResult CalcStep = |
| 8359 | BuildBinOp(CurScope, StepLoc, BO_Assign, SaveRef.get(), StepExpr); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 8360 | CalcStep = ActOnFinishFullExpr(CalcStep.get()); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8361 | |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8362 | // Warn about zero linear step (it would be probably better specified as |
| 8363 | // making corresponding variables 'const'). |
| 8364 | llvm::APSInt Result; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8365 | bool IsConstant = StepExpr->isIntegerConstantExpr(Result, Context); |
| 8366 | if (IsConstant && !Result.isNegative() && !Result.isStrictlyPositive()) |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8367 | Diag(StepLoc, diag::warn_omp_linear_step_zero) << Vars[0] |
| 8368 | << (Vars.size() > 1); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8369 | if (!IsConstant && CalcStep.isUsable()) { |
| 8370 | // Calculate the step beforehand instead of doing this on each iteration. |
| 8371 | // (This is not used if the number of iterations may be kfold-ed). |
| 8372 | CalcStepExpr = CalcStep.get(); |
| 8373 | } |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8374 | } |
| 8375 | |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 8376 | return OMPLinearClause::Create(Context, StartLoc, LParenLoc, LinKind, LinLoc, |
| 8377 | ColonLoc, EndLoc, Vars, Privates, Inits, |
| 8378 | StepExpr, CalcStepExpr); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8379 | } |
| 8380 | |
| 8381 | static bool FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV, |
| 8382 | Expr *NumIterations, Sema &SemaRef, |
| 8383 | Scope *S) { |
| 8384 | // Walk the vars and build update/final expressions for the CodeGen. |
| 8385 | SmallVector<Expr *, 8> Updates; |
| 8386 | SmallVector<Expr *, 8> Finals; |
| 8387 | Expr *Step = Clause.getStep(); |
| 8388 | Expr *CalcStep = Clause.getCalcStep(); |
| 8389 | // OpenMP [2.14.3.7, linear clause] |
| 8390 | // If linear-step is not specified it is assumed to be 1. |
| 8391 | if (Step == nullptr) |
| 8392 | Step = SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get(); |
| 8393 | else if (CalcStep) |
| 8394 | Step = cast<BinaryOperator>(CalcStep)->getLHS(); |
| 8395 | bool HasErrors = false; |
| 8396 | auto CurInit = Clause.inits().begin(); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8397 | auto CurPrivate = Clause.privates().begin(); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 8398 | auto LinKind = Clause.getModifier(); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8399 | for (auto &RefExpr : Clause.varlists()) { |
| 8400 | Expr *InitExpr = *CurInit; |
| 8401 | |
| 8402 | // Build privatized reference to the current linear var. |
| 8403 | auto DE = cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 8404 | Expr *CapturedRef; |
| 8405 | if (LinKind == OMPC_LINEAR_uval) |
| 8406 | CapturedRef = cast<VarDecl>(DE->getDecl())->getInit(); |
| 8407 | else |
| 8408 | CapturedRef = |
| 8409 | buildDeclRefExpr(SemaRef, cast<VarDecl>(DE->getDecl()), |
| 8410 | DE->getType().getUnqualifiedType(), DE->getExprLoc(), |
| 8411 | /*RefersToCapture=*/true); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8412 | |
| 8413 | // Build update: Var = InitExpr + IV * Step |
| 8414 | ExprResult Update = |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8415 | BuildCounterUpdate(SemaRef, S, RefExpr->getExprLoc(), *CurPrivate, |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8416 | InitExpr, IV, Step, /* Subtract */ false); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 8417 | Update = SemaRef.ActOnFinishFullExpr(Update.get(), DE->getLocStart(), |
| 8418 | /*DiscardedValue=*/true); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8419 | |
| 8420 | // Build final: Var = InitExpr + NumIterations * Step |
| 8421 | ExprResult Final = |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8422 | BuildCounterUpdate(SemaRef, S, RefExpr->getExprLoc(), CapturedRef, |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 8423 | InitExpr, NumIterations, Step, /* Subtract */ false); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 8424 | Final = SemaRef.ActOnFinishFullExpr(Final.get(), DE->getLocStart(), |
| 8425 | /*DiscardedValue=*/true); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8426 | if (!Update.isUsable() || !Final.isUsable()) { |
| 8427 | Updates.push_back(nullptr); |
| 8428 | Finals.push_back(nullptr); |
| 8429 | HasErrors = true; |
| 8430 | } else { |
| 8431 | Updates.push_back(Update.get()); |
| 8432 | Finals.push_back(Final.get()); |
| 8433 | } |
Richard Trieu | cc3949d | 2016-02-18 22:34:54 +0000 | [diff] [blame] | 8434 | ++CurInit; |
| 8435 | ++CurPrivate; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8436 | } |
| 8437 | Clause.setUpdates(Updates); |
| 8438 | Clause.setFinals(Finals); |
| 8439 | return HasErrors; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8440 | } |
| 8441 | |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 8442 | OMPClause *Sema::ActOnOpenMPAlignedClause( |
| 8443 | ArrayRef<Expr *> VarList, Expr *Alignment, SourceLocation StartLoc, |
| 8444 | SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc) { |
| 8445 | |
| 8446 | SmallVector<Expr *, 8> Vars; |
| 8447 | for (auto &RefExpr : VarList) { |
| 8448 | assert(RefExpr && "NULL expr in OpenMP aligned clause."); |
| 8449 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 8450 | // It will be analyzed later. |
| 8451 | Vars.push_back(RefExpr); |
| 8452 | continue; |
| 8453 | } |
| 8454 | |
| 8455 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 8456 | // OpenMP [2.1, C/C++] |
| 8457 | // A list item is a variable name. |
| 8458 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
| 8459 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8460 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr) |
| 8461 | << 0 << RefExpr->getSourceRange(); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 8462 | continue; |
| 8463 | } |
| 8464 | |
| 8465 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); |
| 8466 | |
| 8467 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 8468 | // The type of list items appearing in the aligned clause must be |
| 8469 | // array, pointer, reference to array, or reference to pointer. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8470 | QualType QType = VD->getType(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8471 | QType = QType.getNonReferenceType().getUnqualifiedType().getCanonicalType(); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 8472 | const Type *Ty = QType.getTypePtrOrNull(); |
| 8473 | if (!Ty || (!Ty->isDependentType() && !Ty->isArrayType() && |
| 8474 | !Ty->isPointerType())) { |
| 8475 | Diag(ELoc, diag::err_omp_aligned_expected_array_or_ptr) |
| 8476 | << QType << getLangOpts().CPlusPlus << RefExpr->getSourceRange(); |
| 8477 | bool IsDecl = |
| 8478 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 8479 | Diag(VD->getLocation(), |
| 8480 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 8481 | << VD; |
| 8482 | continue; |
| 8483 | } |
| 8484 | |
| 8485 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 8486 | // A list-item cannot appear in more than one aligned clause. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8487 | if (Expr *PrevRef = DSAStack->addUniqueAligned(VD, DE)) { |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 8488 | Diag(ELoc, diag::err_omp_aligned_twice) << RefExpr->getSourceRange(); |
| 8489 | Diag(PrevRef->getExprLoc(), diag::note_omp_explicit_dsa) |
| 8490 | << getOpenMPClauseName(OMPC_aligned); |
| 8491 | continue; |
| 8492 | } |
| 8493 | |
| 8494 | Vars.push_back(DE); |
| 8495 | } |
| 8496 | |
| 8497 | // OpenMP [2.8.1, simd construct, Description] |
| 8498 | // The parameter of the aligned clause, alignment, must be a constant |
| 8499 | // positive integer expression. |
| 8500 | // If no optional parameter is specified, implementation-defined default |
| 8501 | // alignments for SIMD instructions on the target platforms are assumed. |
| 8502 | if (Alignment != nullptr) { |
| 8503 | ExprResult AlignResult = |
| 8504 | VerifyPositiveIntegerConstantInClause(Alignment, OMPC_aligned); |
| 8505 | if (AlignResult.isInvalid()) |
| 8506 | return nullptr; |
| 8507 | Alignment = AlignResult.get(); |
| 8508 | } |
| 8509 | if (Vars.empty()) |
| 8510 | return nullptr; |
| 8511 | |
| 8512 | return OMPAlignedClause::Create(Context, StartLoc, LParenLoc, ColonLoc, |
| 8513 | EndLoc, Vars, Alignment); |
| 8514 | } |
| 8515 | |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8516 | OMPClause *Sema::ActOnOpenMPCopyinClause(ArrayRef<Expr *> VarList, |
| 8517 | SourceLocation StartLoc, |
| 8518 | SourceLocation LParenLoc, |
| 8519 | SourceLocation EndLoc) { |
| 8520 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 8521 | SmallVector<Expr *, 8> SrcExprs; |
| 8522 | SmallVector<Expr *, 8> DstExprs; |
| 8523 | SmallVector<Expr *, 8> AssignmentOps; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8524 | for (auto &RefExpr : VarList) { |
| 8525 | assert(RefExpr && "NULL expr in OpenMP copyin clause."); |
| 8526 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8527 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8528 | Vars.push_back(RefExpr); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 8529 | SrcExprs.push_back(nullptr); |
| 8530 | DstExprs.push_back(nullptr); |
| 8531 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8532 | continue; |
| 8533 | } |
| 8534 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8535 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8536 | // OpenMP [2.1, C/C++] |
| 8537 | // A list item is a variable name. |
| 8538 | // OpenMP [2.14.4.1, Restrictions, p.1] |
| 8539 | // A list item that appears in a copyin clause must be threadprivate. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8540 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8541 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8542 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr) |
| 8543 | << 0 << RefExpr->getSourceRange(); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8544 | continue; |
| 8545 | } |
| 8546 | |
| 8547 | Decl *D = DE->getDecl(); |
| 8548 | VarDecl *VD = cast<VarDecl>(D); |
| 8549 | |
| 8550 | QualType Type = VD->getType(); |
| 8551 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 8552 | // It will be analyzed later. |
| 8553 | Vars.push_back(DE); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 8554 | SrcExprs.push_back(nullptr); |
| 8555 | DstExprs.push_back(nullptr); |
| 8556 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8557 | continue; |
| 8558 | } |
| 8559 | |
| 8560 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.1] |
| 8561 | // A list item that appears in a copyin clause must be threadprivate. |
| 8562 | if (!DSAStack->isThreadPrivate(VD)) { |
| 8563 | Diag(ELoc, diag::err_omp_required_access) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8564 | << getOpenMPClauseName(OMPC_copyin) |
| 8565 | << getOpenMPDirectiveName(OMPD_threadprivate); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8566 | continue; |
| 8567 | } |
| 8568 | |
| 8569 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.2] |
| 8570 | // A variable of class type (or array thereof) that appears in a |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 8571 | // copyin clause requires an accessible, unambiguous copy assignment |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8572 | // operator for the class type. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8573 | auto ElemType = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 8574 | auto *SrcVD = |
| 8575 | buildVarDecl(*this, DE->getLocStart(), ElemType.getUnqualifiedType(), |
| 8576 | ".copyin.src", VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 8577 | auto *PseudoSrcExpr = buildDeclRefExpr( |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8578 | *this, SrcVD, ElemType.getUnqualifiedType(), DE->getExprLoc()); |
| 8579 | auto *DstVD = |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 8580 | buildVarDecl(*this, DE->getLocStart(), ElemType, ".copyin.dst", |
| 8581 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 8582 | auto *PseudoDstExpr = |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8583 | buildDeclRefExpr(*this, DstVD, ElemType, DE->getExprLoc()); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 8584 | // For arrays generate assignment operation for single element and replace |
| 8585 | // it by the original array element in CodeGen. |
| 8586 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, DE->getExprLoc(), BO_Assign, |
| 8587 | PseudoDstExpr, PseudoSrcExpr); |
| 8588 | if (AssignmentOp.isInvalid()) |
| 8589 | continue; |
| 8590 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), DE->getExprLoc(), |
| 8591 | /*DiscardedValue=*/true); |
| 8592 | if (AssignmentOp.isInvalid()) |
| 8593 | continue; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8594 | |
| 8595 | DSAStack->addDSA(VD, DE, OMPC_copyin); |
| 8596 | Vars.push_back(DE); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 8597 | SrcExprs.push_back(PseudoSrcExpr); |
| 8598 | DstExprs.push_back(PseudoDstExpr); |
| 8599 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8600 | } |
| 8601 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8602 | if (Vars.empty()) |
| 8603 | return nullptr; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8604 | |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 8605 | return OMPCopyinClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
| 8606 | SrcExprs, DstExprs, AssignmentOps); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8607 | } |
| 8608 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8609 | OMPClause *Sema::ActOnOpenMPCopyprivateClause(ArrayRef<Expr *> VarList, |
| 8610 | SourceLocation StartLoc, |
| 8611 | SourceLocation LParenLoc, |
| 8612 | SourceLocation EndLoc) { |
| 8613 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 8614 | SmallVector<Expr *, 8> SrcExprs; |
| 8615 | SmallVector<Expr *, 8> DstExprs; |
| 8616 | SmallVector<Expr *, 8> AssignmentOps; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8617 | for (auto &RefExpr : VarList) { |
| 8618 | assert(RefExpr && "NULL expr in OpenMP copyprivate clause."); |
| 8619 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 8620 | // It will be analyzed later. |
| 8621 | Vars.push_back(RefExpr); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 8622 | SrcExprs.push_back(nullptr); |
| 8623 | DstExprs.push_back(nullptr); |
| 8624 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8625 | continue; |
| 8626 | } |
| 8627 | |
| 8628 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 8629 | // OpenMP [2.1, C/C++] |
| 8630 | // A list item is a variable name. |
| 8631 | // OpenMP [2.14.4.1, Restrictions, p.1] |
| 8632 | // A list item that appears in a copyin clause must be threadprivate. |
| 8633 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
| 8634 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8635 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr) |
| 8636 | << 0 << RefExpr->getSourceRange(); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8637 | continue; |
| 8638 | } |
| 8639 | |
| 8640 | Decl *D = DE->getDecl(); |
| 8641 | VarDecl *VD = cast<VarDecl>(D); |
| 8642 | |
| 8643 | QualType Type = VD->getType(); |
| 8644 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 8645 | // It will be analyzed later. |
| 8646 | Vars.push_back(DE); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 8647 | SrcExprs.push_back(nullptr); |
| 8648 | DstExprs.push_back(nullptr); |
| 8649 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8650 | continue; |
| 8651 | } |
| 8652 | |
| 8653 | // OpenMP [2.14.4.2, Restrictions, p.2] |
| 8654 | // A list item that appears in a copyprivate clause may not appear in a |
| 8655 | // private or firstprivate clause on the single construct. |
| 8656 | if (!DSAStack->isThreadPrivate(VD)) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 8657 | auto DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 8658 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_copyprivate && |
| 8659 | DVar.RefExpr) { |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8660 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 8661 | << getOpenMPClauseName(DVar.CKind) |
| 8662 | << getOpenMPClauseName(OMPC_copyprivate); |
| 8663 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 8664 | continue; |
| 8665 | } |
| 8666 | |
| 8667 | // OpenMP [2.11.4.2, Restrictions, p.1] |
| 8668 | // All list items that appear in a copyprivate clause must be either |
| 8669 | // threadprivate or private in the enclosing context. |
| 8670 | if (DVar.CKind == OMPC_unknown) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 8671 | DVar = DSAStack->getImplicitDSA(VD, false); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8672 | if (DVar.CKind == OMPC_shared) { |
| 8673 | Diag(ELoc, diag::err_omp_required_access) |
| 8674 | << getOpenMPClauseName(OMPC_copyprivate) |
| 8675 | << "threadprivate or private in the enclosing context"; |
| 8676 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 8677 | continue; |
| 8678 | } |
| 8679 | } |
| 8680 | } |
| 8681 | |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 8682 | // Variably modified types are not supported. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 8683 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType()) { |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 8684 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8685 | << getOpenMPClauseName(OMPC_copyprivate) << Type |
| 8686 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 8687 | bool IsDecl = |
| 8688 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 8689 | Diag(VD->getLocation(), |
| 8690 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 8691 | << VD; |
| 8692 | continue; |
| 8693 | } |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8694 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8695 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.2] |
| 8696 | // A variable of class type (or array thereof) that appears in a |
| 8697 | // copyin clause requires an accessible, unambiguous copy assignment |
| 8698 | // operator for the class type. |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8699 | Type = Context.getBaseElementType(Type.getNonReferenceType()) |
| 8700 | .getUnqualifiedType(); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 8701 | auto *SrcVD = |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 8702 | buildVarDecl(*this, DE->getLocStart(), Type, ".copyprivate.src", |
| 8703 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 8704 | auto *PseudoSrcExpr = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 8705 | buildDeclRefExpr(*this, SrcVD, Type, DE->getExprLoc()); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 8706 | auto *DstVD = |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 8707 | buildVarDecl(*this, DE->getLocStart(), Type, ".copyprivate.dst", |
| 8708 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 8709 | auto *PseudoDstExpr = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 8710 | buildDeclRefExpr(*this, DstVD, Type, DE->getExprLoc()); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 8711 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, DE->getExprLoc(), BO_Assign, |
| 8712 | PseudoDstExpr, PseudoSrcExpr); |
| 8713 | if (AssignmentOp.isInvalid()) |
| 8714 | continue; |
| 8715 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), DE->getExprLoc(), |
| 8716 | /*DiscardedValue=*/true); |
| 8717 | if (AssignmentOp.isInvalid()) |
| 8718 | continue; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8719 | |
| 8720 | // No need to mark vars as copyprivate, they are already threadprivate or |
| 8721 | // implicitly private. |
| 8722 | Vars.push_back(DE); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 8723 | SrcExprs.push_back(PseudoSrcExpr); |
| 8724 | DstExprs.push_back(PseudoDstExpr); |
| 8725 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8726 | } |
| 8727 | |
| 8728 | if (Vars.empty()) |
| 8729 | return nullptr; |
| 8730 | |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 8731 | return OMPCopyprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| 8732 | Vars, SrcExprs, DstExprs, AssignmentOps); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8733 | } |
| 8734 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 8735 | OMPClause *Sema::ActOnOpenMPFlushClause(ArrayRef<Expr *> VarList, |
| 8736 | SourceLocation StartLoc, |
| 8737 | SourceLocation LParenLoc, |
| 8738 | SourceLocation EndLoc) { |
| 8739 | if (VarList.empty()) |
| 8740 | return nullptr; |
| 8741 | |
| 8742 | return OMPFlushClause::Create(Context, StartLoc, LParenLoc, EndLoc, VarList); |
| 8743 | } |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 8744 | |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8745 | OMPClause * |
| 8746 | Sema::ActOnOpenMPDependClause(OpenMPDependClauseKind DepKind, |
| 8747 | SourceLocation DepLoc, SourceLocation ColonLoc, |
| 8748 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
| 8749 | SourceLocation LParenLoc, SourceLocation EndLoc) { |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 8750 | if (DSAStack->getCurrentDirective() == OMPD_ordered && |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 8751 | DepKind != OMPC_DEPEND_source && DepKind != OMPC_DEPEND_sink) { |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 8752 | Diag(DepLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 8753 | << "'source' or 'sink'" << getOpenMPClauseName(OMPC_depend); |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 8754 | return nullptr; |
| 8755 | } |
| 8756 | if (DSAStack->getCurrentDirective() != OMPD_ordered && |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 8757 | (DepKind == OMPC_DEPEND_unknown || DepKind == OMPC_DEPEND_source || |
| 8758 | DepKind == OMPC_DEPEND_sink)) { |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 8759 | unsigned Except[] = {OMPC_DEPEND_source, OMPC_DEPEND_sink}; |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8760 | Diag(DepLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 8761 | << getListOfPossibleValues(OMPC_depend, /*First=*/0, |
| 8762 | /*Last=*/OMPC_DEPEND_unknown, Except) |
| 8763 | << getOpenMPClauseName(OMPC_depend); |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8764 | return nullptr; |
| 8765 | } |
| 8766 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 8767 | llvm::APSInt DepCounter(/*BitWidth=*/32); |
| 8768 | llvm::APSInt TotalDepCount(/*BitWidth=*/32); |
| 8769 | if (DepKind == OMPC_DEPEND_sink) { |
| 8770 | if (auto *OrderedCountExpr = DSAStack->getParentOrderedRegionParam()) { |
| 8771 | TotalDepCount = OrderedCountExpr->EvaluateKnownConstInt(Context); |
| 8772 | TotalDepCount.setIsUnsigned(/*Val=*/true); |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8773 | } |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8774 | } |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 8775 | if ((DepKind != OMPC_DEPEND_sink && DepKind != OMPC_DEPEND_source) || |
| 8776 | DSAStack->getParentOrderedRegionParam()) { |
| 8777 | for (auto &RefExpr : VarList) { |
| 8778 | assert(RefExpr && "NULL expr in OpenMP shared clause."); |
| 8779 | if (isa<DependentScopeDeclRefExpr>(RefExpr) || |
| 8780 | (DepKind == OMPC_DEPEND_sink && CurContext->isDependentContext())) { |
| 8781 | // It will be analyzed later. |
| 8782 | Vars.push_back(RefExpr); |
| 8783 | continue; |
| 8784 | } |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8785 | |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 8786 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 8787 | auto *SimpleExpr = RefExpr->IgnoreParenCasts(); |
| 8788 | if (DepKind == OMPC_DEPEND_sink) { |
| 8789 | if (DepCounter >= TotalDepCount) { |
| 8790 | Diag(ELoc, diag::err_omp_depend_sink_unexpected_expr); |
| 8791 | continue; |
| 8792 | } |
| 8793 | ++DepCounter; |
| 8794 | // OpenMP [2.13.9, Summary] |
| 8795 | // depend(dependence-type : vec), where dependence-type is: |
| 8796 | // 'sink' and where vec is the iteration vector, which has the form: |
| 8797 | // x1 [+- d1], x2 [+- d2 ], . . . , xn [+- dn] |
| 8798 | // where n is the value specified by the ordered clause in the loop |
| 8799 | // directive, xi denotes the loop iteration variable of the i-th nested |
| 8800 | // loop associated with the loop directive, and di is a constant |
| 8801 | // non-negative integer. |
| 8802 | SimpleExpr = SimpleExpr->IgnoreImplicit(); |
| 8803 | auto *DE = dyn_cast<DeclRefExpr>(SimpleExpr); |
| 8804 | if (!DE) { |
| 8805 | OverloadedOperatorKind OOK = OO_None; |
| 8806 | SourceLocation OOLoc; |
| 8807 | Expr *LHS, *RHS; |
| 8808 | if (auto *BO = dyn_cast<BinaryOperator>(SimpleExpr)) { |
| 8809 | OOK = BinaryOperator::getOverloadedOperator(BO->getOpcode()); |
| 8810 | OOLoc = BO->getOperatorLoc(); |
| 8811 | LHS = BO->getLHS()->IgnoreParenImpCasts(); |
| 8812 | RHS = BO->getRHS()->IgnoreParenImpCasts(); |
| 8813 | } else if (auto *OCE = dyn_cast<CXXOperatorCallExpr>(SimpleExpr)) { |
| 8814 | OOK = OCE->getOperator(); |
| 8815 | OOLoc = OCE->getOperatorLoc(); |
| 8816 | LHS = OCE->getArg(/*Arg=*/0)->IgnoreParenImpCasts(); |
| 8817 | RHS = OCE->getArg(/*Arg=*/1)->IgnoreParenImpCasts(); |
| 8818 | } else if (auto *MCE = dyn_cast<CXXMemberCallExpr>(SimpleExpr)) { |
| 8819 | OOK = MCE->getMethodDecl() |
| 8820 | ->getNameInfo() |
| 8821 | .getName() |
| 8822 | .getCXXOverloadedOperator(); |
| 8823 | OOLoc = MCE->getCallee()->getExprLoc(); |
| 8824 | LHS = MCE->getImplicitObjectArgument()->IgnoreParenImpCasts(); |
| 8825 | RHS = MCE->getArg(/*Arg=*/0)->IgnoreParenImpCasts(); |
| 8826 | } else { |
| 8827 | Diag(ELoc, diag::err_omp_depend_sink_wrong_expr); |
| 8828 | continue; |
| 8829 | } |
| 8830 | DE = dyn_cast<DeclRefExpr>(LHS); |
| 8831 | if (!DE) { |
| 8832 | Diag(LHS->getExprLoc(), |
| 8833 | diag::err_omp_depend_sink_expected_loop_iteration) |
| 8834 | << DSAStack->getParentLoopControlVariable( |
| 8835 | DepCounter.getZExtValue()); |
| 8836 | continue; |
| 8837 | } |
| 8838 | if (OOK != OO_Plus && OOK != OO_Minus) { |
| 8839 | Diag(OOLoc, diag::err_omp_depend_sink_expected_plus_minus); |
| 8840 | continue; |
| 8841 | } |
| 8842 | ExprResult Res = VerifyPositiveIntegerConstantInClause( |
| 8843 | RHS, OMPC_depend, /*StrictlyPositive=*/false); |
| 8844 | if (Res.isInvalid()) |
| 8845 | continue; |
| 8846 | } |
| 8847 | auto *VD = dyn_cast<VarDecl>(DE->getDecl()); |
| 8848 | if (!CurContext->isDependentContext() && |
| 8849 | DSAStack->getParentOrderedRegionParam() && |
| 8850 | (!VD || DepCounter != DSAStack->isParentLoopControlVariable(VD))) { |
| 8851 | Diag(DE->getExprLoc(), |
| 8852 | diag::err_omp_depend_sink_expected_loop_iteration) |
| 8853 | << DSAStack->getParentLoopControlVariable( |
| 8854 | DepCounter.getZExtValue()); |
| 8855 | continue; |
| 8856 | } |
| 8857 | } else { |
| 8858 | // OpenMP [2.11.1.1, Restrictions, p.3] |
| 8859 | // A variable that is part of another variable (such as a field of a |
| 8860 | // structure) but is not an array element or an array section cannot |
| 8861 | // appear in a depend clause. |
| 8862 | auto *DE = dyn_cast<DeclRefExpr>(SimpleExpr); |
| 8863 | auto *ASE = dyn_cast<ArraySubscriptExpr>(SimpleExpr); |
| 8864 | auto *OASE = dyn_cast<OMPArraySectionExpr>(SimpleExpr); |
| 8865 | if (!RefExpr->IgnoreParenImpCasts()->isLValue() || |
| 8866 | (!ASE && !DE && !OASE) || (DE && !isa<VarDecl>(DE->getDecl())) || |
Alexey Bataev | 31300ed | 2016-02-04 11:27:03 +0000 | [diff] [blame] | 8867 | (ASE && |
| 8868 | !ASE->getBase() |
| 8869 | ->getType() |
| 8870 | .getNonReferenceType() |
| 8871 | ->isPointerType() && |
| 8872 | !ASE->getBase()->getType().getNonReferenceType()->isArrayType())) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8873 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr_or_array_item) |
| 8874 | << 0 << RefExpr->getSourceRange(); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 8875 | continue; |
| 8876 | } |
| 8877 | } |
| 8878 | |
| 8879 | Vars.push_back(RefExpr->IgnoreParenImpCasts()); |
| 8880 | } |
| 8881 | |
| 8882 | if (!CurContext->isDependentContext() && DepKind == OMPC_DEPEND_sink && |
| 8883 | TotalDepCount > VarList.size() && |
| 8884 | DSAStack->getParentOrderedRegionParam()) { |
| 8885 | Diag(EndLoc, diag::err_omp_depend_sink_expected_loop_iteration) |
| 8886 | << DSAStack->getParentLoopControlVariable(VarList.size() + 1); |
| 8887 | } |
| 8888 | if (DepKind != OMPC_DEPEND_source && DepKind != OMPC_DEPEND_sink && |
| 8889 | Vars.empty()) |
| 8890 | return nullptr; |
| 8891 | } |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8892 | |
| 8893 | return OMPDependClause::Create(Context, StartLoc, LParenLoc, EndLoc, DepKind, |
| 8894 | DepLoc, ColonLoc, Vars); |
| 8895 | } |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 8896 | |
| 8897 | OMPClause *Sema::ActOnOpenMPDeviceClause(Expr *Device, SourceLocation StartLoc, |
| 8898 | SourceLocation LParenLoc, |
| 8899 | SourceLocation EndLoc) { |
| 8900 | Expr *ValExpr = Device; |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 8901 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 8902 | // OpenMP [2.9.1, Restrictions] |
| 8903 | // The device expression must evaluate to a non-negative integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 8904 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_device, |
| 8905 | /*StrictlyPositive=*/false)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 8906 | return nullptr; |
| 8907 | |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 8908 | return new (Context) OMPDeviceClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 8909 | } |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 8910 | |
| 8911 | static bool IsCXXRecordForMappable(Sema &SemaRef, SourceLocation Loc, |
| 8912 | DSAStackTy *Stack, CXXRecordDecl *RD) { |
| 8913 | if (!RD || RD->isInvalidDecl()) |
| 8914 | return true; |
| 8915 | |
Alexey Bataev | c9bd03d | 2015-12-17 06:55:08 +0000 | [diff] [blame] | 8916 | if (auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(RD)) |
| 8917 | if (auto *CTD = CTSD->getSpecializedTemplate()) |
| 8918 | RD = CTD->getTemplatedDecl(); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 8919 | auto QTy = SemaRef.Context.getRecordType(RD); |
| 8920 | if (RD->isDynamicClass()) { |
| 8921 | SemaRef.Diag(Loc, diag::err_omp_not_mappable_type) << QTy; |
| 8922 | SemaRef.Diag(RD->getLocation(), diag::note_omp_polymorphic_in_target); |
| 8923 | return false; |
| 8924 | } |
| 8925 | auto *DC = RD; |
| 8926 | bool IsCorrect = true; |
| 8927 | for (auto *I : DC->decls()) { |
| 8928 | if (I) { |
| 8929 | if (auto *MD = dyn_cast<CXXMethodDecl>(I)) { |
| 8930 | if (MD->isStatic()) { |
| 8931 | SemaRef.Diag(Loc, diag::err_omp_not_mappable_type) << QTy; |
| 8932 | SemaRef.Diag(MD->getLocation(), |
| 8933 | diag::note_omp_static_member_in_target); |
| 8934 | IsCorrect = false; |
| 8935 | } |
| 8936 | } else if (auto *VD = dyn_cast<VarDecl>(I)) { |
| 8937 | if (VD->isStaticDataMember()) { |
| 8938 | SemaRef.Diag(Loc, diag::err_omp_not_mappable_type) << QTy; |
| 8939 | SemaRef.Diag(VD->getLocation(), |
| 8940 | diag::note_omp_static_member_in_target); |
| 8941 | IsCorrect = false; |
| 8942 | } |
| 8943 | } |
| 8944 | } |
| 8945 | } |
| 8946 | |
| 8947 | for (auto &I : RD->bases()) { |
| 8948 | if (!IsCXXRecordForMappable(SemaRef, I.getLocStart(), Stack, |
| 8949 | I.getType()->getAsCXXRecordDecl())) |
| 8950 | IsCorrect = false; |
| 8951 | } |
| 8952 | return IsCorrect; |
| 8953 | } |
| 8954 | |
| 8955 | static bool CheckTypeMappable(SourceLocation SL, SourceRange SR, Sema &SemaRef, |
| 8956 | DSAStackTy *Stack, QualType QTy) { |
| 8957 | NamedDecl *ND; |
| 8958 | if (QTy->isIncompleteType(&ND)) { |
| 8959 | SemaRef.Diag(SL, diag::err_incomplete_type) << QTy << SR; |
| 8960 | return false; |
| 8961 | } else if (CXXRecordDecl *RD = dyn_cast_or_null<CXXRecordDecl>(ND)) { |
| 8962 | if (!RD->isInvalidDecl() && |
| 8963 | !IsCXXRecordForMappable(SemaRef, SL, Stack, RD)) |
| 8964 | return false; |
| 8965 | } |
| 8966 | return true; |
| 8967 | } |
| 8968 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 8969 | // Return the expression of the base of the map clause or null if it cannot |
| 8970 | // be determined and do all the necessary checks to see if the expression is |
| 8971 | // valid as a standalone map clause expression. |
| 8972 | static Expr *CheckMapClauseExpressionBase(Sema &SemaRef, Expr *E) { |
| 8973 | SourceLocation ELoc = E->getExprLoc(); |
| 8974 | SourceRange ERange = E->getSourceRange(); |
| 8975 | |
| 8976 | // The base of elements of list in a map clause have to be either: |
| 8977 | // - a reference to variable or field. |
| 8978 | // - a member expression. |
| 8979 | // - an array expression. |
| 8980 | // |
| 8981 | // E.g. if we have the expression 'r.S.Arr[:12]', we want to retrieve the |
| 8982 | // reference to 'r'. |
| 8983 | // |
| 8984 | // If we have: |
| 8985 | // |
| 8986 | // struct SS { |
| 8987 | // Bla S; |
| 8988 | // foo() { |
| 8989 | // #pragma omp target map (S.Arr[:12]); |
| 8990 | // } |
| 8991 | // } |
| 8992 | // |
| 8993 | // We want to retrieve the member expression 'this->S'; |
| 8994 | |
| 8995 | Expr *RelevantExpr = nullptr; |
| 8996 | |
| 8997 | // Flags to help capture some memory |
| 8998 | |
| 8999 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.2] |
| 9000 | // If a list item is an array section, it must specify contiguous storage. |
| 9001 | // |
| 9002 | // For this restriction it is sufficient that we make sure only references |
| 9003 | // to variables or fields and array expressions, and that no array sections |
| 9004 | // exist except in the rightmost expression. E.g. these would be invalid: |
| 9005 | // |
| 9006 | // r.ArrS[3:5].Arr[6:7] |
| 9007 | // |
| 9008 | // r.ArrS[3:5].x |
| 9009 | // |
| 9010 | // but these would be valid: |
| 9011 | // r.ArrS[3].Arr[6:7] |
| 9012 | // |
| 9013 | // r.ArrS[3].x |
| 9014 | |
| 9015 | bool IsRightMostExpression = true; |
| 9016 | |
| 9017 | while (!RelevantExpr) { |
| 9018 | auto AllowArraySection = IsRightMostExpression; |
| 9019 | IsRightMostExpression = false; |
| 9020 | |
| 9021 | E = E->IgnoreParenImpCasts(); |
| 9022 | |
| 9023 | if (auto *CurE = dyn_cast<DeclRefExpr>(E)) { |
| 9024 | if (!isa<VarDecl>(CurE->getDecl())) |
| 9025 | break; |
| 9026 | |
| 9027 | RelevantExpr = CurE; |
| 9028 | continue; |
| 9029 | } |
| 9030 | |
| 9031 | if (auto *CurE = dyn_cast<MemberExpr>(E)) { |
| 9032 | auto *BaseE = CurE->getBase()->IgnoreParenImpCasts(); |
| 9033 | |
| 9034 | if (isa<CXXThisExpr>(BaseE)) |
| 9035 | // We found a base expression: this->Val. |
| 9036 | RelevantExpr = CurE; |
| 9037 | else |
| 9038 | E = BaseE; |
| 9039 | |
| 9040 | if (!isa<FieldDecl>(CurE->getMemberDecl())) { |
| 9041 | SemaRef.Diag(ELoc, diag::err_omp_expected_access_to_data_field) |
| 9042 | << CurE->getSourceRange(); |
| 9043 | break; |
| 9044 | } |
| 9045 | |
| 9046 | auto *FD = cast<FieldDecl>(CurE->getMemberDecl()); |
| 9047 | |
| 9048 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C/C++, p.3] |
| 9049 | // A bit-field cannot appear in a map clause. |
| 9050 | // |
| 9051 | if (FD->isBitField()) { |
| 9052 | SemaRef.Diag(ELoc, diag::err_omp_bit_fields_forbidden_in_map_clause) |
| 9053 | << CurE->getSourceRange(); |
| 9054 | break; |
| 9055 | } |
| 9056 | |
| 9057 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] |
| 9058 | // If the type of a list item is a reference to a type T then the type |
| 9059 | // will be considered to be T for all purposes of this clause. |
| 9060 | QualType CurType = BaseE->getType(); |
| 9061 | if (CurType->isReferenceType()) |
| 9062 | CurType = CurType->getPointeeType(); |
| 9063 | |
| 9064 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C/C++, p.2] |
| 9065 | // A list item cannot be a variable that is a member of a structure with |
| 9066 | // a union type. |
| 9067 | // |
| 9068 | if (auto *RT = CurType->getAs<RecordType>()) |
| 9069 | if (RT->isUnionType()) { |
| 9070 | SemaRef.Diag(ELoc, diag::err_omp_union_type_not_allowed) |
| 9071 | << CurE->getSourceRange(); |
| 9072 | break; |
| 9073 | } |
| 9074 | |
| 9075 | continue; |
| 9076 | } |
| 9077 | |
| 9078 | if (auto *CurE = dyn_cast<ArraySubscriptExpr>(E)) { |
| 9079 | E = CurE->getBase()->IgnoreParenImpCasts(); |
| 9080 | |
| 9081 | if (!E->getType()->isAnyPointerType() && !E->getType()->isArrayType()) { |
| 9082 | SemaRef.Diag(ELoc, diag::err_omp_expected_base_var_name) |
| 9083 | << 0 << CurE->getSourceRange(); |
| 9084 | break; |
| 9085 | } |
| 9086 | continue; |
| 9087 | } |
| 9088 | |
| 9089 | if (auto *CurE = dyn_cast<OMPArraySectionExpr>(E)) { |
| 9090 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.7] |
| 9091 | // If a list item is an element of a structure, only the rightmost symbol |
| 9092 | // of the variable reference can be an array section. |
| 9093 | // |
| 9094 | if (!AllowArraySection) { |
| 9095 | SemaRef.Diag(ELoc, diag::err_omp_array_section_in_rightmost_expression) |
| 9096 | << CurE->getSourceRange(); |
| 9097 | break; |
| 9098 | } |
| 9099 | |
| 9100 | E = CurE->getBase()->IgnoreParenImpCasts(); |
| 9101 | |
| 9102 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] |
| 9103 | // If the type of a list item is a reference to a type T then the type |
| 9104 | // will be considered to be T for all purposes of this clause. |
| 9105 | QualType CurType = E->getType(); |
| 9106 | if (CurType->isReferenceType()) |
| 9107 | CurType = CurType->getPointeeType(); |
| 9108 | |
| 9109 | if (!CurType->isAnyPointerType() && !CurType->isArrayType()) { |
| 9110 | SemaRef.Diag(ELoc, diag::err_omp_expected_base_var_name) |
| 9111 | << 0 << CurE->getSourceRange(); |
| 9112 | break; |
| 9113 | } |
| 9114 | |
| 9115 | continue; |
| 9116 | } |
| 9117 | |
| 9118 | // If nothing else worked, this is not a valid map clause expression. |
| 9119 | SemaRef.Diag(ELoc, |
| 9120 | diag::err_omp_expected_named_var_member_or_array_expression) |
| 9121 | << ERange; |
| 9122 | break; |
| 9123 | } |
| 9124 | |
| 9125 | return RelevantExpr; |
| 9126 | } |
| 9127 | |
| 9128 | // Return true if expression E associated with value VD has conflicts with other |
| 9129 | // map information. |
| 9130 | static bool CheckMapConflicts(Sema &SemaRef, DSAStackTy *DSAS, ValueDecl *VD, |
| 9131 | Expr *E, bool CurrentRegionOnly) { |
| 9132 | assert(VD && E); |
| 9133 | |
| 9134 | // Types used to organize the components of a valid map clause. |
| 9135 | typedef std::pair<Expr *, ValueDecl *> MapExpressionComponent; |
| 9136 | typedef SmallVector<MapExpressionComponent, 4> MapExpressionComponents; |
| 9137 | |
| 9138 | // Helper to extract the components in the map clause expression E and store |
| 9139 | // them into MEC. This assumes that E is a valid map clause expression, i.e. |
| 9140 | // it has already passed the single clause checks. |
| 9141 | auto ExtractMapExpressionComponents = [](Expr *TE, |
| 9142 | MapExpressionComponents &MEC) { |
| 9143 | while (true) { |
| 9144 | TE = TE->IgnoreParenImpCasts(); |
| 9145 | |
| 9146 | if (auto *CurE = dyn_cast<DeclRefExpr>(TE)) { |
| 9147 | MEC.push_back( |
| 9148 | MapExpressionComponent(CurE, cast<VarDecl>(CurE->getDecl()))); |
| 9149 | break; |
| 9150 | } |
| 9151 | |
| 9152 | if (auto *CurE = dyn_cast<MemberExpr>(TE)) { |
| 9153 | auto *BaseE = CurE->getBase()->IgnoreParenImpCasts(); |
| 9154 | |
| 9155 | MEC.push_back(MapExpressionComponent( |
| 9156 | CurE, cast<FieldDecl>(CurE->getMemberDecl()))); |
| 9157 | if (isa<CXXThisExpr>(BaseE)) |
| 9158 | break; |
| 9159 | |
| 9160 | TE = BaseE; |
| 9161 | continue; |
| 9162 | } |
| 9163 | |
| 9164 | if (auto *CurE = dyn_cast<ArraySubscriptExpr>(TE)) { |
| 9165 | MEC.push_back(MapExpressionComponent(CurE, nullptr)); |
| 9166 | TE = CurE->getBase()->IgnoreParenImpCasts(); |
| 9167 | continue; |
| 9168 | } |
| 9169 | |
| 9170 | if (auto *CurE = dyn_cast<OMPArraySectionExpr>(TE)) { |
| 9171 | MEC.push_back(MapExpressionComponent(CurE, nullptr)); |
| 9172 | TE = CurE->getBase()->IgnoreParenImpCasts(); |
| 9173 | continue; |
| 9174 | } |
| 9175 | |
| 9176 | llvm_unreachable( |
| 9177 | "Expecting only valid map clause expressions at this point!"); |
| 9178 | } |
| 9179 | }; |
| 9180 | |
| 9181 | SourceLocation ELoc = E->getExprLoc(); |
| 9182 | SourceRange ERange = E->getSourceRange(); |
| 9183 | |
| 9184 | // In order to easily check the conflicts we need to match each component of |
| 9185 | // the expression under test with the components of the expressions that are |
| 9186 | // already in the stack. |
| 9187 | |
| 9188 | MapExpressionComponents CurComponents; |
| 9189 | ExtractMapExpressionComponents(E, CurComponents); |
| 9190 | |
| 9191 | assert(!CurComponents.empty() && "Map clause expression with no components!"); |
| 9192 | assert(CurComponents.back().second == VD && |
| 9193 | "Map clause expression with unexpected base!"); |
| 9194 | |
| 9195 | // Variables to help detecting enclosing problems in data environment nests. |
| 9196 | bool IsEnclosedByDataEnvironmentExpr = false; |
| 9197 | Expr *EnclosingExpr = nullptr; |
| 9198 | |
| 9199 | bool FoundError = |
| 9200 | DSAS->checkMapInfoForVar(VD, CurrentRegionOnly, [&](Expr *RE) -> bool { |
| 9201 | MapExpressionComponents StackComponents; |
| 9202 | ExtractMapExpressionComponents(RE, StackComponents); |
| 9203 | assert(!StackComponents.empty() && |
| 9204 | "Map clause expression with no components!"); |
| 9205 | assert(StackComponents.back().second == VD && |
| 9206 | "Map clause expression with unexpected base!"); |
| 9207 | |
| 9208 | // Expressions must start from the same base. Here we detect at which |
| 9209 | // point both expressions diverge from each other and see if we can |
| 9210 | // detect if the memory referred to both expressions is contiguous and |
| 9211 | // do not overlap. |
| 9212 | auto CI = CurComponents.rbegin(); |
| 9213 | auto CE = CurComponents.rend(); |
| 9214 | auto SI = StackComponents.rbegin(); |
| 9215 | auto SE = StackComponents.rend(); |
| 9216 | for (; CI != CE && SI != SE; ++CI, ++SI) { |
| 9217 | |
| 9218 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.3] |
| 9219 | // At most one list item can be an array item derived from a given |
| 9220 | // variable in map clauses of the same construct. |
| 9221 | if (CurrentRegionOnly && (isa<ArraySubscriptExpr>(CI->first) || |
| 9222 | isa<OMPArraySectionExpr>(CI->first)) && |
| 9223 | (isa<ArraySubscriptExpr>(SI->first) || |
| 9224 | isa<OMPArraySectionExpr>(SI->first))) { |
| 9225 | SemaRef.Diag(CI->first->getExprLoc(), |
| 9226 | diag::err_omp_multiple_array_items_in_map_clause) |
| 9227 | << CI->first->getSourceRange(); |
| 9228 | ; |
| 9229 | SemaRef.Diag(SI->first->getExprLoc(), diag::note_used_here) |
| 9230 | << SI->first->getSourceRange(); |
| 9231 | return true; |
| 9232 | } |
| 9233 | |
| 9234 | // Do both expressions have the same kind? |
| 9235 | if (CI->first->getStmtClass() != SI->first->getStmtClass()) |
| 9236 | break; |
| 9237 | |
| 9238 | // Are we dealing with different variables/fields? |
| 9239 | if (CI->second != SI->second) |
| 9240 | break; |
| 9241 | } |
| 9242 | |
| 9243 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.4] |
| 9244 | // List items of map clauses in the same construct must not share |
| 9245 | // original storage. |
| 9246 | // |
| 9247 | // If the expressions are exactly the same or one is a subset of the |
| 9248 | // other, it means they are sharing storage. |
| 9249 | if (CI == CE && SI == SE) { |
| 9250 | if (CurrentRegionOnly) { |
| 9251 | SemaRef.Diag(ELoc, diag::err_omp_map_shared_storage) << ERange; |
| 9252 | SemaRef.Diag(RE->getExprLoc(), diag::note_used_here) |
| 9253 | << RE->getSourceRange(); |
| 9254 | return true; |
| 9255 | } else { |
| 9256 | // If we find the same expression in the enclosing data environment, |
| 9257 | // that is legal. |
| 9258 | IsEnclosedByDataEnvironmentExpr = true; |
| 9259 | return false; |
| 9260 | } |
| 9261 | } |
| 9262 | |
| 9263 | QualType DerivedType = std::prev(CI)->first->getType(); |
| 9264 | SourceLocation DerivedLoc = std::prev(CI)->first->getExprLoc(); |
| 9265 | |
| 9266 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] |
| 9267 | // If the type of a list item is a reference to a type T then the type |
| 9268 | // will be considered to be T for all purposes of this clause. |
| 9269 | if (DerivedType->isReferenceType()) |
| 9270 | DerivedType = DerivedType->getPointeeType(); |
| 9271 | |
| 9272 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C/C++, p.1] |
| 9273 | // A variable for which the type is pointer and an array section |
| 9274 | // derived from that variable must not appear as list items of map |
| 9275 | // clauses of the same construct. |
| 9276 | // |
| 9277 | // Also, cover one of the cases in: |
| 9278 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.5] |
| 9279 | // If any part of the original storage of a list item has corresponding |
| 9280 | // storage in the device data environment, all of the original storage |
| 9281 | // must have corresponding storage in the device data environment. |
| 9282 | // |
| 9283 | if (DerivedType->isAnyPointerType()) { |
| 9284 | if (CI == CE || SI == SE) { |
| 9285 | SemaRef.Diag( |
| 9286 | DerivedLoc, |
| 9287 | diag::err_omp_pointer_mapped_along_with_derived_section) |
| 9288 | << DerivedLoc; |
| 9289 | } else { |
| 9290 | assert(CI != CE && SI != SE); |
| 9291 | SemaRef.Diag(DerivedLoc, diag::err_omp_same_pointer_derreferenced) |
| 9292 | << DerivedLoc; |
| 9293 | } |
| 9294 | SemaRef.Diag(RE->getExprLoc(), diag::note_used_here) |
| 9295 | << RE->getSourceRange(); |
| 9296 | return true; |
| 9297 | } |
| 9298 | |
| 9299 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.4] |
| 9300 | // List items of map clauses in the same construct must not share |
| 9301 | // original storage. |
| 9302 | // |
| 9303 | // An expression is a subset of the other. |
| 9304 | if (CurrentRegionOnly && (CI == CE || SI == SE)) { |
| 9305 | SemaRef.Diag(ELoc, diag::err_omp_map_shared_storage) << ERange; |
| 9306 | SemaRef.Diag(RE->getExprLoc(), diag::note_used_here) |
| 9307 | << RE->getSourceRange(); |
| 9308 | return true; |
| 9309 | } |
| 9310 | |
| 9311 | // The current expression uses the same base as other expression in the |
| 9312 | // data environment but does not contain it completelly. |
| 9313 | if (!CurrentRegionOnly && SI != SE) |
| 9314 | EnclosingExpr = RE; |
| 9315 | |
| 9316 | // The current expression is a subset of the expression in the data |
| 9317 | // environment. |
| 9318 | IsEnclosedByDataEnvironmentExpr |= |
| 9319 | (!CurrentRegionOnly && CI != CE && SI == SE); |
| 9320 | |
| 9321 | return false; |
| 9322 | }); |
| 9323 | |
| 9324 | if (CurrentRegionOnly) |
| 9325 | return FoundError; |
| 9326 | |
| 9327 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.5] |
| 9328 | // If any part of the original storage of a list item has corresponding |
| 9329 | // storage in the device data environment, all of the original storage must |
| 9330 | // have corresponding storage in the device data environment. |
| 9331 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.6] |
| 9332 | // If a list item is an element of a structure, and a different element of |
| 9333 | // the structure has a corresponding list item in the device data environment |
| 9334 | // prior to a task encountering the construct associated with the map clause, |
| 9335 | // then the list item must also have a correspnding list item in the device |
| 9336 | // data environment prior to the task encountering the construct. |
| 9337 | // |
| 9338 | if (EnclosingExpr && !IsEnclosedByDataEnvironmentExpr) { |
| 9339 | SemaRef.Diag(ELoc, |
| 9340 | diag::err_omp_original_storage_is_shared_and_does_not_contain) |
| 9341 | << ERange; |
| 9342 | SemaRef.Diag(EnclosingExpr->getExprLoc(), diag::note_used_here) |
| 9343 | << EnclosingExpr->getSourceRange(); |
| 9344 | return true; |
| 9345 | } |
| 9346 | |
| 9347 | return FoundError; |
| 9348 | } |
| 9349 | |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 9350 | OMPClause * |
| 9351 | Sema::ActOnOpenMPMapClause(OpenMPMapClauseKind MapTypeModifier, |
| 9352 | OpenMPMapClauseKind MapType, bool IsMapTypeImplicit, |
| 9353 | SourceLocation MapLoc, SourceLocation ColonLoc, |
| 9354 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
| 9355 | SourceLocation LParenLoc, SourceLocation EndLoc) { |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9356 | SmallVector<Expr *, 4> Vars; |
| 9357 | |
| 9358 | for (auto &RE : VarList) { |
| 9359 | assert(RE && "Null expr in omp map"); |
| 9360 | if (isa<DependentScopeDeclRefExpr>(RE)) { |
| 9361 | // It will be analyzed later. |
| 9362 | Vars.push_back(RE); |
| 9363 | continue; |
| 9364 | } |
| 9365 | SourceLocation ELoc = RE->getExprLoc(); |
| 9366 | |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9367 | auto *VE = RE->IgnoreParenLValueCasts(); |
| 9368 | |
| 9369 | if (VE->isValueDependent() || VE->isTypeDependent() || |
| 9370 | VE->isInstantiationDependent() || |
| 9371 | VE->containsUnexpandedParameterPack()) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9372 | // We can only analyze this information once the missing information is |
| 9373 | // resolved. |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9374 | Vars.push_back(RE); |
| 9375 | continue; |
| 9376 | } |
| 9377 | |
| 9378 | auto *SimpleExpr = RE->IgnoreParenCasts(); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9379 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9380 | if (!RE->IgnoreParenImpCasts()->isLValue()) { |
| 9381 | Diag(ELoc, diag::err_omp_expected_named_var_member_or_array_expression) |
| 9382 | << RE->getSourceRange(); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9383 | continue; |
| 9384 | } |
| 9385 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9386 | // Obtain the array or member expression bases if required. |
| 9387 | auto *BE = CheckMapClauseExpressionBase(*this, SimpleExpr); |
| 9388 | if (!BE) |
| 9389 | continue; |
| 9390 | |
| 9391 | // If the base is a reference to a variable, we rely on that variable for |
| 9392 | // the following checks. If it is a 'this' expression we rely on the field. |
| 9393 | ValueDecl *D = nullptr; |
| 9394 | if (auto *DRE = dyn_cast<DeclRefExpr>(BE)) { |
| 9395 | D = DRE->getDecl(); |
| 9396 | } else { |
| 9397 | auto *ME = cast<MemberExpr>(BE); |
| 9398 | assert(isa<CXXThisExpr>(ME->getBase()) && "Unexpected expression!"); |
| 9399 | D = ME->getMemberDecl(); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9400 | } |
| 9401 | assert(D && "Null decl on map clause."); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9402 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9403 | auto *VD = dyn_cast<VarDecl>(D); |
| 9404 | auto *FD = dyn_cast<FieldDecl>(D); |
| 9405 | |
| 9406 | assert((VD || FD) && "Only variables or fields are expected here!"); |
NAKAMURA Takumi | 6dcb814 | 2016-01-23 01:38:20 +0000 | [diff] [blame] | 9407 | (void)FD; |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9408 | |
| 9409 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.10] |
| 9410 | // threadprivate variables cannot appear in a map clause. |
| 9411 | if (VD && DSAStack->isThreadPrivate(VD)) { |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9412 | auto DVar = DSAStack->getTopDSA(VD, false); |
| 9413 | Diag(ELoc, diag::err_omp_threadprivate_in_map); |
| 9414 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 9415 | continue; |
| 9416 | } |
| 9417 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9418 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.9] |
| 9419 | // A list item cannot appear in both a map clause and a data-sharing |
| 9420 | // attribute clause on the same construct. |
| 9421 | // |
| 9422 | // TODO: Implement this check - it cannot currently be tested because of |
| 9423 | // missing implementation of the other data sharing clauses in target |
| 9424 | // directives. |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9425 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9426 | // Check conflicts with other map clause expressions. We check the conflicts |
| 9427 | // with the current construct separately from the enclosing data |
| 9428 | // environment, because the restrictions are different. |
| 9429 | if (CheckMapConflicts(*this, DSAStack, D, SimpleExpr, |
| 9430 | /*CurrentRegionOnly=*/true)) |
| 9431 | break; |
| 9432 | if (CheckMapConflicts(*this, DSAStack, D, SimpleExpr, |
| 9433 | /*CurrentRegionOnly=*/false)) |
| 9434 | break; |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9435 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9436 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] |
| 9437 | // If the type of a list item is a reference to a type T then the type will |
| 9438 | // be considered to be T for all purposes of this clause. |
| 9439 | QualType Type = D->getType(); |
| 9440 | if (Type->isReferenceType()) |
| 9441 | Type = Type->getPointeeType(); |
| 9442 | |
| 9443 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.9] |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9444 | // A list item must have a mappable type. |
| 9445 | if (!CheckTypeMappable(VE->getExprLoc(), VE->getSourceRange(), *this, |
| 9446 | DSAStack, Type)) |
| 9447 | continue; |
| 9448 | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 9449 | // target enter data |
| 9450 | // OpenMP [2.10.2, Restrictions, p. 99] |
| 9451 | // A map-type must be specified in all map clauses and must be either |
| 9452 | // to or alloc. |
| 9453 | OpenMPDirectiveKind DKind = DSAStack->getCurrentDirective(); |
| 9454 | if (DKind == OMPD_target_enter_data && |
| 9455 | !(MapType == OMPC_MAP_to || MapType == OMPC_MAP_alloc)) { |
| 9456 | Diag(StartLoc, diag::err_omp_invalid_map_type_for_directive) |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 9457 | << (IsMapTypeImplicit ? 1 : 0) |
| 9458 | << getOpenMPSimpleClauseTypeName(OMPC_map, MapType) |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 9459 | << getOpenMPDirectiveName(DKind); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9460 | continue; |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 9461 | } |
| 9462 | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 9463 | // target exit_data |
| 9464 | // OpenMP [2.10.3, Restrictions, p. 102] |
| 9465 | // A map-type must be specified in all map clauses and must be either |
| 9466 | // from, release, or delete. |
| 9467 | DKind = DSAStack->getCurrentDirective(); |
| 9468 | if (DKind == OMPD_target_exit_data && |
| 9469 | !(MapType == OMPC_MAP_from || MapType == OMPC_MAP_release || |
| 9470 | MapType == OMPC_MAP_delete)) { |
| 9471 | Diag(StartLoc, diag::err_omp_invalid_map_type_for_directive) |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 9472 | << (IsMapTypeImplicit ? 1 : 0) |
| 9473 | << getOpenMPSimpleClauseTypeName(OMPC_map, MapType) |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 9474 | << getOpenMPDirectiveName(DKind); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9475 | continue; |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 9476 | } |
| 9477 | |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9478 | Vars.push_back(RE); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9479 | DSAStack->addExprToVarMapInfo(D, RE); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9480 | } |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9481 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9482 | // We need to produce a map clause even if we don't have variables so that |
| 9483 | // other diagnostics related with non-existing map clauses are accurate. |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9484 | return OMPMapClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 9485 | MapTypeModifier, MapType, IsMapTypeImplicit, |
| 9486 | MapLoc); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9487 | } |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 9488 | |
| 9489 | OMPClause *Sema::ActOnOpenMPNumTeamsClause(Expr *NumTeams, |
| 9490 | SourceLocation StartLoc, |
| 9491 | SourceLocation LParenLoc, |
| 9492 | SourceLocation EndLoc) { |
| 9493 | Expr *ValExpr = NumTeams; |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 9494 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 9495 | // OpenMP [teams Constrcut, Restrictions] |
| 9496 | // The num_teams expression must evaluate to a positive integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 9497 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_num_teams, |
| 9498 | /*StrictlyPositive=*/true)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 9499 | return nullptr; |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 9500 | |
| 9501 | return new (Context) OMPNumTeamsClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 9502 | } |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 9503 | |
| 9504 | OMPClause *Sema::ActOnOpenMPThreadLimitClause(Expr *ThreadLimit, |
| 9505 | SourceLocation StartLoc, |
| 9506 | SourceLocation LParenLoc, |
| 9507 | SourceLocation EndLoc) { |
| 9508 | Expr *ValExpr = ThreadLimit; |
| 9509 | |
| 9510 | // OpenMP [teams Constrcut, Restrictions] |
| 9511 | // The thread_limit expression must evaluate to a positive integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 9512 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_thread_limit, |
| 9513 | /*StrictlyPositive=*/true)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 9514 | return nullptr; |
| 9515 | |
| 9516 | return new (Context) OMPThreadLimitClause(ValExpr, StartLoc, LParenLoc, |
| 9517 | EndLoc); |
| 9518 | } |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 9519 | |
| 9520 | OMPClause *Sema::ActOnOpenMPPriorityClause(Expr *Priority, |
| 9521 | SourceLocation StartLoc, |
| 9522 | SourceLocation LParenLoc, |
| 9523 | SourceLocation EndLoc) { |
| 9524 | Expr *ValExpr = Priority; |
| 9525 | |
| 9526 | // OpenMP [2.9.1, task Constrcut] |
| 9527 | // The priority-value is a non-negative numerical scalar expression. |
| 9528 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_priority, |
| 9529 | /*StrictlyPositive=*/false)) |
| 9530 | return nullptr; |
| 9531 | |
| 9532 | return new (Context) OMPPriorityClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 9533 | } |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 9534 | |
| 9535 | OMPClause *Sema::ActOnOpenMPGrainsizeClause(Expr *Grainsize, |
| 9536 | SourceLocation StartLoc, |
| 9537 | SourceLocation LParenLoc, |
| 9538 | SourceLocation EndLoc) { |
| 9539 | Expr *ValExpr = Grainsize; |
| 9540 | |
| 9541 | // OpenMP [2.9.2, taskloop Constrcut] |
| 9542 | // The parameter of the grainsize clause must be a positive integer |
| 9543 | // expression. |
| 9544 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_grainsize, |
| 9545 | /*StrictlyPositive=*/true)) |
| 9546 | return nullptr; |
| 9547 | |
| 9548 | return new (Context) OMPGrainsizeClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 9549 | } |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 9550 | |
| 9551 | OMPClause *Sema::ActOnOpenMPNumTasksClause(Expr *NumTasks, |
| 9552 | SourceLocation StartLoc, |
| 9553 | SourceLocation LParenLoc, |
| 9554 | SourceLocation EndLoc) { |
| 9555 | Expr *ValExpr = NumTasks; |
| 9556 | |
| 9557 | // OpenMP [2.9.2, taskloop Constrcut] |
| 9558 | // The parameter of the num_tasks clause must be a positive integer |
| 9559 | // expression. |
| 9560 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_num_tasks, |
| 9561 | /*StrictlyPositive=*/true)) |
| 9562 | return nullptr; |
| 9563 | |
| 9564 | return new (Context) OMPNumTasksClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 9565 | } |
| 9566 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 9567 | OMPClause *Sema::ActOnOpenMPHintClause(Expr *Hint, SourceLocation StartLoc, |
| 9568 | SourceLocation LParenLoc, |
| 9569 | SourceLocation EndLoc) { |
| 9570 | // OpenMP [2.13.2, critical construct, Description] |
| 9571 | // ... where hint-expression is an integer constant expression that evaluates |
| 9572 | // to a valid lock hint. |
| 9573 | ExprResult HintExpr = VerifyPositiveIntegerConstantInClause(Hint, OMPC_hint); |
| 9574 | if (HintExpr.isInvalid()) |
| 9575 | return nullptr; |
| 9576 | return new (Context) |
| 9577 | OMPHintClause(HintExpr.get(), StartLoc, LParenLoc, EndLoc); |
| 9578 | } |
| 9579 | |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 9580 | OMPClause *Sema::ActOnOpenMPDistScheduleClause( |
| 9581 | OpenMPDistScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, |
| 9582 | SourceLocation LParenLoc, SourceLocation KindLoc, SourceLocation CommaLoc, |
| 9583 | SourceLocation EndLoc) { |
| 9584 | if (Kind == OMPC_DIST_SCHEDULE_unknown) { |
| 9585 | std::string Values; |
| 9586 | Values += "'"; |
| 9587 | Values += getOpenMPSimpleClauseTypeName(OMPC_dist_schedule, 0); |
| 9588 | Values += "'"; |
| 9589 | Diag(KindLoc, diag::err_omp_unexpected_clause_value) |
| 9590 | << Values << getOpenMPClauseName(OMPC_dist_schedule); |
| 9591 | return nullptr; |
| 9592 | } |
| 9593 | Expr *ValExpr = ChunkSize; |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 9594 | Stmt *HelperValStmt = nullptr; |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 9595 | if (ChunkSize) { |
| 9596 | if (!ChunkSize->isValueDependent() && !ChunkSize->isTypeDependent() && |
| 9597 | !ChunkSize->isInstantiationDependent() && |
| 9598 | !ChunkSize->containsUnexpandedParameterPack()) { |
| 9599 | SourceLocation ChunkSizeLoc = ChunkSize->getLocStart(); |
| 9600 | ExprResult Val = |
| 9601 | PerformOpenMPImplicitIntegerConversion(ChunkSizeLoc, ChunkSize); |
| 9602 | if (Val.isInvalid()) |
| 9603 | return nullptr; |
| 9604 | |
| 9605 | ValExpr = Val.get(); |
| 9606 | |
| 9607 | // OpenMP [2.7.1, Restrictions] |
| 9608 | // chunk_size must be a loop invariant integer expression with a positive |
| 9609 | // value. |
| 9610 | llvm::APSInt Result; |
| 9611 | if (ValExpr->isIntegerConstantExpr(Result, Context)) { |
| 9612 | if (Result.isSigned() && !Result.isStrictlyPositive()) { |
| 9613 | Diag(ChunkSizeLoc, diag::err_omp_negative_expression_in_clause) |
| 9614 | << "dist_schedule" << ChunkSize->getSourceRange(); |
| 9615 | return nullptr; |
| 9616 | } |
| 9617 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective())) { |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame^] | 9618 | ValExpr = buildCapture(*this, ValExpr); |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 9619 | Decl *D = cast<DeclRefExpr>(ValExpr)->getDecl(); |
| 9620 | HelperValStmt = |
| 9621 | new (Context) DeclStmt(DeclGroupRef::Create(Context, &D, |
| 9622 | /*NumDecls=*/1), |
| 9623 | SourceLocation(), SourceLocation()); |
| 9624 | ValExpr = DefaultLvalueConversion(ValExpr).get(); |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 9625 | } |
| 9626 | } |
| 9627 | } |
| 9628 | |
| 9629 | return new (Context) |
| 9630 | OMPDistScheduleClause(StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc, |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 9631 | Kind, ValExpr, HelperValStmt); |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 9632 | } |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 9633 | |
| 9634 | OMPClause *Sema::ActOnOpenMPDefaultmapClause( |
| 9635 | OpenMPDefaultmapClauseModifier M, OpenMPDefaultmapClauseKind Kind, |
| 9636 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation MLoc, |
| 9637 | SourceLocation KindLoc, SourceLocation EndLoc) { |
| 9638 | // OpenMP 4.5 only supports 'defaultmap(tofrom: scalar)' |
| 9639 | if (M != OMPC_DEFAULTMAP_MODIFIER_tofrom || |
| 9640 | Kind != OMPC_DEFAULTMAP_scalar) { |
| 9641 | std::string Value; |
| 9642 | SourceLocation Loc; |
| 9643 | Value += "'"; |
| 9644 | if (M != OMPC_DEFAULTMAP_MODIFIER_tofrom) { |
| 9645 | Value += getOpenMPSimpleClauseTypeName(OMPC_defaultmap, |
| 9646 | OMPC_DEFAULTMAP_MODIFIER_tofrom); |
| 9647 | Loc = MLoc; |
| 9648 | } else { |
| 9649 | Value += getOpenMPSimpleClauseTypeName(OMPC_defaultmap, |
| 9650 | OMPC_DEFAULTMAP_scalar); |
| 9651 | Loc = KindLoc; |
| 9652 | } |
| 9653 | Value += "'"; |
| 9654 | Diag(Loc, diag::err_omp_unexpected_clause_value) |
| 9655 | << Value << getOpenMPClauseName(OMPC_defaultmap); |
| 9656 | return nullptr; |
| 9657 | } |
| 9658 | |
| 9659 | return new (Context) |
| 9660 | OMPDefaultmapClause(StartLoc, LParenLoc, MLoc, KindLoc, EndLoc, Kind, M); |
| 9661 | } |