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 | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 18 | #include "clang/AST/CXXInheritance.h" |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 19 | #include "clang/AST/Decl.h" |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 20 | #include "clang/AST/DeclCXX.h" |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 21 | #include "clang/AST/DeclOpenMP.h" |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 22 | #include "clang/AST/StmtCXX.h" |
| 23 | #include "clang/AST/StmtOpenMP.h" |
| 24 | #include "clang/AST/StmtVisitor.h" |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 25 | #include "clang/AST/TypeOrdering.h" |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 26 | #include "clang/Basic/OpenMPKinds.h" |
Samuel Antao | f8b5012 | 2015-07-13 22:54:53 +0000 | [diff] [blame] | 27 | #include "clang/Basic/TargetInfo.h" |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 28 | #include "clang/Lex/Preprocessor.h" |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 29 | #include "clang/Sema/Initialization.h" |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 30 | #include "clang/Sema/Lookup.h" |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 31 | #include "clang/Sema/Scope.h" |
| 32 | #include "clang/Sema/ScopeInfo.h" |
Chandler Carruth | 5553d0d | 2014-01-07 11:51:46 +0000 | [diff] [blame] | 33 | #include "clang/Sema/SemaInternal.h" |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 34 | using namespace clang; |
| 35 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 36 | //===----------------------------------------------------------------------===// |
| 37 | // Stack of data-sharing attributes for variables |
| 38 | //===----------------------------------------------------------------------===// |
| 39 | |
| 40 | namespace { |
| 41 | /// \brief Default data sharing attributes, which can be applied to directive. |
| 42 | enum DefaultDataSharingAttributes { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 43 | DSA_unspecified = 0, /// \brief Data sharing attribute not specified. |
| 44 | DSA_none = 1 << 0, /// \brief Default data sharing attribute 'none'. |
| 45 | DSA_shared = 1 << 1 /// \brief Default data sharing attribute 'shared'. |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 46 | }; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 47 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 48 | template <class T> struct MatchesAny { |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 49 | explicit MatchesAny(ArrayRef<T> Arr) : Arr(std::move(Arr)) {} |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 50 | bool operator()(T Kind) { |
| 51 | for (auto KindEl : Arr) |
| 52 | if (KindEl == Kind) |
| 53 | return true; |
| 54 | return false; |
| 55 | } |
| 56 | |
| 57 | private: |
| 58 | ArrayRef<T> Arr; |
| 59 | }; |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 60 | struct MatchesAlways { |
Angel Garcia Gomez | 637d1e6 | 2015-10-20 13:23:58 +0000 | [diff] [blame] | 61 | MatchesAlways() {} |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 62 | template <class T> bool operator()(T) { return true; } |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 63 | }; |
| 64 | |
| 65 | typedef MatchesAny<OpenMPClauseKind> MatchesAnyClause; |
| 66 | typedef MatchesAny<OpenMPDirectiveKind> MatchesAnyDirective; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 67 | |
| 68 | /// \brief Stack for tracking declarations used in OpenMP directives and |
| 69 | /// clauses and their data-sharing attributes. |
| 70 | class DSAStackTy { |
| 71 | public: |
| 72 | struct DSAVarData { |
| 73 | OpenMPDirectiveKind DKind; |
| 74 | OpenMPClauseKind CKind; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 75 | Expr *RefExpr; |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 76 | DeclRefExpr *PrivateCopy; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 77 | SourceLocation ImplicitDSALoc; |
| 78 | DSAVarData() |
| 79 | : DKind(OMPD_unknown), CKind(OMPC_unknown), RefExpr(nullptr), |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 80 | PrivateCopy(nullptr), ImplicitDSALoc() {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 81 | }; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 82 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 83 | private: |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 84 | typedef SmallVector<Expr *, 4> MapInfo; |
| 85 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 86 | struct DSAInfo { |
| 87 | OpenMPClauseKind Attributes; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 88 | Expr *RefExpr; |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 89 | DeclRefExpr *PrivateCopy; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 90 | }; |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 91 | typedef llvm::DenseMap<ValueDecl *, DSAInfo> DeclSAMapTy; |
| 92 | typedef llvm::DenseMap<ValueDecl *, Expr *> AlignedMapTy; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 93 | typedef llvm::DenseMap<ValueDecl *, unsigned> LoopControlVariablesMapTy; |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 94 | typedef llvm::DenseMap<ValueDecl *, MapInfo> MappedDeclsTy; |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 95 | typedef llvm::StringMap<std::pair<OMPCriticalDirective *, llvm::APSInt>> |
| 96 | CriticalsWithHintsTy; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 97 | |
| 98 | struct SharingMapTy { |
| 99 | DeclSAMapTy SharingMap; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 100 | AlignedMapTy AlignedMap; |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 101 | MappedDeclsTy MappedDecls; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 102 | LoopControlVariablesMapTy LCVMap; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 103 | DefaultDataSharingAttributes DefaultAttr; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 104 | SourceLocation DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 105 | OpenMPDirectiveKind Directive; |
| 106 | DeclarationNameInfo DirectiveName; |
| 107 | Scope *CurScope; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 108 | SourceLocation ConstructLoc; |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 109 | /// \brief first argument (Expr *) contains optional argument of the |
| 110 | /// 'ordered' clause, the second one is true if the regions has 'ordered' |
| 111 | /// clause, false otherwise. |
| 112 | llvm::PointerIntPair<Expr *, 1, bool> OrderedRegion; |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 113 | bool NowaitRegion; |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 114 | bool CancelRegion; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 115 | unsigned AssociatedLoops; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 116 | SourceLocation InnerTeamsRegionLoc; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 117 | SharingMapTy(OpenMPDirectiveKind DKind, DeclarationNameInfo Name, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 118 | Scope *CurScope, SourceLocation Loc) |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 119 | : SharingMap(), AlignedMap(), LCVMap(), DefaultAttr(DSA_unspecified), |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 120 | Directive(DKind), DirectiveName(std::move(Name)), CurScope(CurScope), |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 121 | ConstructLoc(Loc), OrderedRegion(), NowaitRegion(false), |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 122 | CancelRegion(false), AssociatedLoops(1), InnerTeamsRegionLoc() {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 123 | SharingMapTy() |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 124 | : SharingMap(), AlignedMap(), LCVMap(), DefaultAttr(DSA_unspecified), |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 125 | Directive(OMPD_unknown), DirectiveName(), CurScope(nullptr), |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 126 | ConstructLoc(), OrderedRegion(), NowaitRegion(false), |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 127 | CancelRegion(false), AssociatedLoops(1), InnerTeamsRegionLoc() {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 128 | }; |
| 129 | |
Axel Naumann | 323862e | 2016-02-03 10:45:22 +0000 | [diff] [blame] | 130 | typedef SmallVector<SharingMapTy, 4> StackTy; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 131 | |
| 132 | /// \brief Stack of used declaration and their data-sharing attributes. |
| 133 | StackTy Stack; |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 134 | /// \brief true, if check for DSA must be from parent directive, false, if |
| 135 | /// from current directive. |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 136 | OpenMPClauseKind ClauseKindMode; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 137 | Sema &SemaRef; |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 138 | bool ForceCapturing; |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 139 | CriticalsWithHintsTy Criticals; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 140 | |
| 141 | typedef SmallVector<SharingMapTy, 8>::reverse_iterator reverse_iterator; |
| 142 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 143 | DSAVarData getDSA(StackTy::reverse_iterator Iter, ValueDecl *D); |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 144 | |
| 145 | /// \brief Checks if the variable is a local for OpenMP region. |
| 146 | bool isOpenMPLocal(VarDecl *D, StackTy::reverse_iterator Iter); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 147 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 148 | public: |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 149 | explicit DSAStackTy(Sema &S) |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 150 | : Stack(1), ClauseKindMode(OMPC_unknown), SemaRef(S), |
| 151 | ForceCapturing(false) {} |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 152 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 153 | bool isClauseParsingMode() const { return ClauseKindMode != OMPC_unknown; } |
| 154 | void setClauseParsingMode(OpenMPClauseKind K) { ClauseKindMode = K; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 155 | |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 156 | bool isForceVarCapturing() const { return ForceCapturing; } |
| 157 | void setForceVarCapturing(bool V) { ForceCapturing = V; } |
| 158 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 159 | void push(OpenMPDirectiveKind DKind, const DeclarationNameInfo &DirName, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 160 | Scope *CurScope, SourceLocation Loc) { |
| 161 | Stack.push_back(SharingMapTy(DKind, DirName, CurScope, Loc)); |
| 162 | Stack.back().DefaultAttrLoc = Loc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | void pop() { |
| 166 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty!"); |
| 167 | Stack.pop_back(); |
| 168 | } |
| 169 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 170 | void addCriticalWithHint(OMPCriticalDirective *D, llvm::APSInt Hint) { |
| 171 | Criticals[D->getDirectiveName().getAsString()] = std::make_pair(D, Hint); |
| 172 | } |
| 173 | const std::pair<OMPCriticalDirective *, llvm::APSInt> |
| 174 | getCriticalWithHint(const DeclarationNameInfo &Name) const { |
| 175 | auto I = Criticals.find(Name.getAsString()); |
| 176 | if (I != Criticals.end()) |
| 177 | return I->second; |
| 178 | return std::make_pair(nullptr, llvm::APSInt()); |
| 179 | } |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 180 | /// \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] | 181 | /// add it and return NULL; otherwise return previous occurrence's expression |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 182 | /// for diagnostics. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 183 | Expr *addUniqueAligned(ValueDecl *D, Expr *NewDE); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 184 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 185 | /// \brief Register specified variable as loop control variable. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 186 | void addLoopControlVariable(ValueDecl *D); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 187 | /// \brief Check if the specified variable is a loop control variable for |
| 188 | /// current region. |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 189 | /// \return The index of the loop control variable in the list of associated |
| 190 | /// for-loops (from outer to inner). |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 191 | unsigned isLoopControlVariable(ValueDecl *D); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 192 | /// \brief Check if the specified variable is a loop control variable for |
| 193 | /// parent region. |
| 194 | /// \return The index of the loop control variable in the list of associated |
| 195 | /// for-loops (from outer to inner). |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 196 | unsigned isParentLoopControlVariable(ValueDecl *D); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 197 | /// \brief Get the loop control variable for the I-th loop (or nullptr) in |
| 198 | /// parent directive. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 199 | ValueDecl *getParentLoopControlVariable(unsigned I); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 200 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 201 | /// \brief Adds explicit data sharing attribute to the specified declaration. |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 202 | void addDSA(ValueDecl *D, Expr *E, OpenMPClauseKind A, |
| 203 | DeclRefExpr *PrivateCopy = nullptr); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 204 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 205 | /// \brief Returns data sharing attributes from top of the stack for the |
| 206 | /// specified declaration. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 207 | DSAVarData getTopDSA(ValueDecl *D, bool FromParent); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 208 | /// \brief Returns data-sharing attributes for the specified declaration. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 209 | DSAVarData getImplicitDSA(ValueDecl *D, bool FromParent); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 210 | /// \brief Checks if the specified variables has data-sharing attributes which |
| 211 | /// match specified \a CPred predicate in any directive which matches \a DPred |
| 212 | /// predicate. |
| 213 | template <class ClausesPredicate, class DirectivesPredicate> |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 214 | DSAVarData hasDSA(ValueDecl *D, ClausesPredicate CPred, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 215 | DirectivesPredicate DPred, bool FromParent); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 216 | /// \brief Checks if the specified variables has data-sharing attributes which |
| 217 | /// match specified \a CPred predicate in any innermost directive which |
| 218 | /// matches \a DPred predicate. |
| 219 | template <class ClausesPredicate, class DirectivesPredicate> |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 220 | DSAVarData hasInnermostDSA(ValueDecl *D, ClausesPredicate CPred, |
| 221 | DirectivesPredicate DPred, bool FromParent); |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 222 | /// \brief Checks if the specified variables has explicit data-sharing |
| 223 | /// attributes which match specified \a CPred predicate at the specified |
| 224 | /// OpenMP region. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 225 | bool hasExplicitDSA(ValueDecl *D, |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 226 | const llvm::function_ref<bool(OpenMPClauseKind)> &CPred, |
| 227 | unsigned Level); |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 228 | |
| 229 | /// \brief Returns true if the directive at level \Level matches in the |
| 230 | /// specified \a DPred predicate. |
| 231 | bool hasExplicitDirective( |
| 232 | const llvm::function_ref<bool(OpenMPDirectiveKind)> &DPred, |
| 233 | unsigned Level); |
| 234 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 235 | /// \brief Finds a directive which matches specified \a DPred predicate. |
| 236 | template <class NamedDirectivesPredicate> |
| 237 | bool hasDirective(NamedDirectivesPredicate DPred, bool FromParent); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 238 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 239 | /// \brief Returns currently analyzed directive. |
| 240 | OpenMPDirectiveKind getCurrentDirective() const { |
| 241 | return Stack.back().Directive; |
| 242 | } |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 243 | /// \brief Returns parent directive. |
| 244 | OpenMPDirectiveKind getParentDirective() const { |
| 245 | if (Stack.size() > 2) |
| 246 | return Stack[Stack.size() - 2].Directive; |
| 247 | return OMPD_unknown; |
| 248 | } |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 249 | /// \brief Return the directive associated with the provided scope. |
| 250 | OpenMPDirectiveKind getDirectiveForScope(const Scope *S) const; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 251 | |
| 252 | /// \brief Set default data sharing attribute to none. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 253 | void setDefaultDSANone(SourceLocation Loc) { |
| 254 | Stack.back().DefaultAttr = DSA_none; |
| 255 | Stack.back().DefaultAttrLoc = Loc; |
| 256 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 257 | /// \brief Set default data sharing attribute to shared. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 258 | void setDefaultDSAShared(SourceLocation Loc) { |
| 259 | Stack.back().DefaultAttr = DSA_shared; |
| 260 | Stack.back().DefaultAttrLoc = Loc; |
| 261 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 262 | |
| 263 | DefaultDataSharingAttributes getDefaultDSA() const { |
| 264 | return Stack.back().DefaultAttr; |
| 265 | } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 266 | SourceLocation getDefaultDSALocation() const { |
| 267 | return Stack.back().DefaultAttrLoc; |
| 268 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 269 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 270 | /// \brief Checks if the specified variable is a threadprivate. |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 271 | bool isThreadPrivate(VarDecl *D) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 272 | DSAVarData DVar = getTopDSA(D, false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 273 | return isOpenMPThreadPrivate(DVar.CKind); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 274 | } |
| 275 | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 276 | /// \brief Marks current region as ordered (it has an 'ordered' clause). |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 277 | void setOrderedRegion(bool IsOrdered, Expr *Param) { |
| 278 | Stack.back().OrderedRegion.setInt(IsOrdered); |
| 279 | Stack.back().OrderedRegion.setPointer(Param); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 280 | } |
| 281 | /// \brief Returns true, if parent region is ordered (has associated |
| 282 | /// 'ordered' clause), false - otherwise. |
| 283 | bool isParentOrderedRegion() const { |
| 284 | if (Stack.size() > 2) |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 285 | return Stack[Stack.size() - 2].OrderedRegion.getInt(); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 286 | return false; |
| 287 | } |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 288 | /// \brief Returns optional parameter for the ordered region. |
| 289 | Expr *getParentOrderedRegionParam() const { |
| 290 | if (Stack.size() > 2) |
| 291 | return Stack[Stack.size() - 2].OrderedRegion.getPointer(); |
| 292 | return nullptr; |
| 293 | } |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 294 | /// \brief Marks current region as nowait (it has a 'nowait' clause). |
| 295 | void setNowaitRegion(bool IsNowait = true) { |
| 296 | Stack.back().NowaitRegion = IsNowait; |
| 297 | } |
| 298 | /// \brief Returns true, if parent region is nowait (has associated |
| 299 | /// 'nowait' clause), false - otherwise. |
| 300 | bool isParentNowaitRegion() const { |
| 301 | if (Stack.size() > 2) |
| 302 | return Stack[Stack.size() - 2].NowaitRegion; |
| 303 | return false; |
| 304 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 305 | /// \brief Marks parent region as cancel region. |
| 306 | void setParentCancelRegion(bool Cancel = true) { |
| 307 | if (Stack.size() > 2) |
| 308 | Stack[Stack.size() - 2].CancelRegion = |
| 309 | Stack[Stack.size() - 2].CancelRegion || Cancel; |
| 310 | } |
| 311 | /// \brief Return true if current region has inner cancel construct. |
| 312 | bool isCancelRegion() const { |
| 313 | return Stack.back().CancelRegion; |
| 314 | } |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 315 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 316 | /// \brief Set collapse value for the region. |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 317 | void setAssociatedLoops(unsigned Val) { Stack.back().AssociatedLoops = Val; } |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 318 | /// \brief Return collapse value for region. |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 319 | unsigned getAssociatedLoops() const { return Stack.back().AssociatedLoops; } |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 320 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 321 | /// \brief Marks current target region as one with closely nested teams |
| 322 | /// region. |
| 323 | void setParentTeamsRegionLoc(SourceLocation TeamsRegionLoc) { |
| 324 | if (Stack.size() > 2) |
| 325 | Stack[Stack.size() - 2].InnerTeamsRegionLoc = TeamsRegionLoc; |
| 326 | } |
| 327 | /// \brief Returns true, if current region has closely nested teams region. |
| 328 | bool hasInnerTeamsRegion() const { |
| 329 | return getInnerTeamsRegionLoc().isValid(); |
| 330 | } |
| 331 | /// \brief Returns location of the nested teams region (if any). |
| 332 | SourceLocation getInnerTeamsRegionLoc() const { |
| 333 | if (Stack.size() > 1) |
| 334 | return Stack.back().InnerTeamsRegionLoc; |
| 335 | return SourceLocation(); |
| 336 | } |
| 337 | |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 338 | Scope *getCurScope() const { return Stack.back().CurScope; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 339 | Scope *getCurScope() { return Stack.back().CurScope; } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 340 | SourceLocation getConstructLoc() { return Stack.back().ConstructLoc; } |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 341 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 342 | // Do the check specified in MapInfoCheck and return true if any issue is |
| 343 | // found. |
| 344 | template <class MapInfoCheck> |
| 345 | bool checkMapInfoForVar(ValueDecl *VD, bool CurrentRegionOnly, |
| 346 | MapInfoCheck Check) { |
| 347 | auto SI = Stack.rbegin(); |
| 348 | auto SE = Stack.rend(); |
| 349 | |
| 350 | if (SI == SE) |
| 351 | return false; |
| 352 | |
| 353 | if (CurrentRegionOnly) { |
| 354 | SE = std::next(SI); |
| 355 | } else { |
| 356 | ++SI; |
| 357 | } |
| 358 | |
| 359 | for (; SI != SE; ++SI) { |
| 360 | auto MI = SI->MappedDecls.find(VD); |
| 361 | if (MI != SI->MappedDecls.end()) { |
| 362 | for (Expr *E : MI->second) { |
| 363 | if (Check(E)) |
| 364 | return true; |
| 365 | } |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 366 | } |
| 367 | } |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 368 | return false; |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 369 | } |
| 370 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 371 | void addExprToVarMapInfo(ValueDecl *VD, Expr *E) { |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 372 | if (Stack.size() > 1) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 373 | Stack.back().MappedDecls[VD].push_back(E); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 374 | } |
| 375 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 376 | }; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 377 | bool isParallelOrTaskRegion(OpenMPDirectiveKind DKind) { |
| 378 | return isOpenMPParallelDirective(DKind) || DKind == OMPD_task || |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 379 | isOpenMPTeamsDirective(DKind) || DKind == OMPD_unknown || |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 380 | isOpenMPTaskLoopDirective(DKind); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 381 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 382 | } // namespace |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 383 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 384 | static ValueDecl *getCanonicalDecl(ValueDecl *D) { |
| 385 | auto *VD = dyn_cast<VarDecl>(D); |
| 386 | auto *FD = dyn_cast<FieldDecl>(D); |
| 387 | if (VD != nullptr) { |
| 388 | VD = VD->getCanonicalDecl(); |
| 389 | D = VD; |
| 390 | } else { |
| 391 | assert(FD); |
| 392 | FD = FD->getCanonicalDecl(); |
| 393 | D = FD; |
| 394 | } |
| 395 | return D; |
| 396 | } |
| 397 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 398 | DSAStackTy::DSAVarData DSAStackTy::getDSA(StackTy::reverse_iterator Iter, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 399 | ValueDecl *D) { |
| 400 | D = getCanonicalDecl(D); |
| 401 | auto *VD = dyn_cast<VarDecl>(D); |
| 402 | auto *FD = dyn_cast<FieldDecl>(D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 403 | DSAVarData DVar; |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 404 | if (Iter == std::prev(Stack.rend())) { |
Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 405 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 406 | // in a region but not in construct] |
| 407 | // File-scope or namespace-scope variables referenced in called routines |
| 408 | // in the region are shared unless they appear in a threadprivate |
| 409 | // directive. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 410 | if (VD && !VD->isFunctionOrMethodVarDecl() && !isa<ParmVarDecl>(D)) |
Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 411 | DVar.CKind = OMPC_shared; |
| 412 | |
| 413 | // OpenMP [2.9.1.2, Data-sharing Attribute Rules for Variables Referenced |
| 414 | // in a region but not in construct] |
| 415 | // Variables with static storage duration that are declared in called |
| 416 | // routines in the region are shared. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 417 | if (VD && VD->hasGlobalStorage()) |
| 418 | DVar.CKind = OMPC_shared; |
| 419 | |
| 420 | // Non-static data members are shared by default. |
| 421 | if (FD) |
Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 422 | DVar.CKind = OMPC_shared; |
| 423 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 424 | return DVar; |
| 425 | } |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 426 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 427 | DVar.DKind = Iter->Directive; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 428 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 429 | // in a Construct, C/C++, predetermined, p.1] |
| 430 | // Variables with automatic storage duration that are declared in a scope |
| 431 | // inside the construct are private. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 432 | if (VD && isOpenMPLocal(VD, Iter) && VD->isLocalVarDecl() && |
| 433 | (VD->getStorageClass() == SC_Auto || VD->getStorageClass() == SC_None)) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 434 | DVar.CKind = OMPC_private; |
| 435 | return DVar; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 436 | } |
| 437 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 438 | // Explicitly specified attributes and local variables with predetermined |
| 439 | // attributes. |
| 440 | if (Iter->SharingMap.count(D)) { |
| 441 | DVar.RefExpr = Iter->SharingMap[D].RefExpr; |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 442 | DVar.PrivateCopy = Iter->SharingMap[D].PrivateCopy; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 443 | DVar.CKind = Iter->SharingMap[D].Attributes; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 444 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 445 | return DVar; |
| 446 | } |
| 447 | |
| 448 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 449 | // in a Construct, C/C++, implicitly determined, p.1] |
| 450 | // In a parallel or task construct, the data-sharing attributes of these |
| 451 | // variables are determined by the default clause, if present. |
| 452 | switch (Iter->DefaultAttr) { |
| 453 | case DSA_shared: |
| 454 | DVar.CKind = OMPC_shared; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 455 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 456 | return DVar; |
| 457 | case DSA_none: |
| 458 | return DVar; |
| 459 | case DSA_unspecified: |
| 460 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 461 | // in a Construct, implicitly determined, p.2] |
| 462 | // In a parallel construct, if no default clause is present, these |
| 463 | // variables are shared. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 464 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 465 | if (isOpenMPParallelDirective(DVar.DKind) || |
| 466 | isOpenMPTeamsDirective(DVar.DKind)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 467 | DVar.CKind = OMPC_shared; |
| 468 | return DVar; |
| 469 | } |
| 470 | |
| 471 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 472 | // in a Construct, implicitly determined, p.4] |
| 473 | // In a task construct, if no default clause is present, a variable that in |
| 474 | // the enclosing context is determined to be shared by all implicit tasks |
| 475 | // bound to the current team is shared. |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 476 | if (DVar.DKind == OMPD_task) { |
| 477 | DSAVarData DVarTemp; |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 478 | for (StackTy::reverse_iterator I = std::next(Iter), EE = Stack.rend(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 479 | I != EE; ++I) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 480 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables |
| 481 | // Referenced |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 482 | // in a Construct, implicitly determined, p.6] |
| 483 | // In a task construct, if no default clause is present, a variable |
| 484 | // whose data-sharing attribute is not determined by the rules above is |
| 485 | // firstprivate. |
| 486 | DVarTemp = getDSA(I, D); |
| 487 | if (DVarTemp.CKind != OMPC_shared) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 488 | DVar.RefExpr = nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 489 | DVar.DKind = OMPD_task; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 490 | DVar.CKind = OMPC_firstprivate; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 491 | return DVar; |
| 492 | } |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 493 | if (isParallelOrTaskRegion(I->Directive)) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 494 | break; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 495 | } |
| 496 | DVar.DKind = OMPD_task; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 497 | DVar.CKind = |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 498 | (DVarTemp.CKind == OMPC_unknown) ? OMPC_firstprivate : OMPC_shared; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 499 | return DVar; |
| 500 | } |
| 501 | } |
| 502 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 503 | // in a Construct, implicitly determined, p.3] |
| 504 | // For constructs other than task, if no default clause is present, these |
| 505 | // variables inherit their data-sharing attributes from the enclosing |
| 506 | // context. |
Benjamin Kramer | 167e999 | 2014-03-02 12:20:24 +0000 | [diff] [blame] | 507 | return getDSA(std::next(Iter), D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 508 | } |
| 509 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 510 | Expr *DSAStackTy::addUniqueAligned(ValueDecl *D, Expr *NewDE) { |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 511 | assert(Stack.size() > 1 && "Data sharing attributes stack is empty"); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 512 | D = getCanonicalDecl(D); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 513 | auto It = Stack.back().AlignedMap.find(D); |
| 514 | if (It == Stack.back().AlignedMap.end()) { |
| 515 | assert(NewDE && "Unexpected nullptr expr to be added into aligned map"); |
| 516 | Stack.back().AlignedMap[D] = NewDE; |
| 517 | return nullptr; |
| 518 | } else { |
| 519 | assert(It->second && "Unexpected nullptr expr in the aligned map"); |
| 520 | return It->second; |
| 521 | } |
| 522 | return nullptr; |
| 523 | } |
| 524 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 525 | void DSAStackTy::addLoopControlVariable(ValueDecl *D) { |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 526 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 527 | D = getCanonicalDecl(D); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 528 | 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] | 529 | } |
| 530 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 531 | unsigned DSAStackTy::isLoopControlVariable(ValueDecl *D) { |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 532 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 533 | D = getCanonicalDecl(D); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 534 | return Stack.back().LCVMap.count(D) > 0 ? Stack.back().LCVMap[D] : 0; |
| 535 | } |
| 536 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 537 | unsigned DSAStackTy::isParentLoopControlVariable(ValueDecl *D) { |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 538 | assert(Stack.size() > 2 && "Data-sharing attributes stack is empty"); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 539 | D = getCanonicalDecl(D); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 540 | return Stack[Stack.size() - 2].LCVMap.count(D) > 0 |
| 541 | ? Stack[Stack.size() - 2].LCVMap[D] |
| 542 | : 0; |
| 543 | } |
| 544 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 545 | ValueDecl *DSAStackTy::getParentLoopControlVariable(unsigned I) { |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 546 | assert(Stack.size() > 2 && "Data-sharing attributes stack is empty"); |
| 547 | if (Stack[Stack.size() - 2].LCVMap.size() < I) |
| 548 | return nullptr; |
| 549 | for (auto &Pair : Stack[Stack.size() - 2].LCVMap) { |
| 550 | if (Pair.second == I) |
| 551 | return Pair.first; |
| 552 | } |
| 553 | return nullptr; |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 554 | } |
| 555 | |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 556 | void DSAStackTy::addDSA(ValueDecl *D, Expr *E, OpenMPClauseKind A, |
| 557 | DeclRefExpr *PrivateCopy) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 558 | D = getCanonicalDecl(D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 559 | if (A == OMPC_threadprivate) { |
| 560 | Stack[0].SharingMap[D].Attributes = A; |
| 561 | Stack[0].SharingMap[D].RefExpr = E; |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 562 | Stack[0].SharingMap[D].PrivateCopy = nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 563 | } else { |
| 564 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); |
| 565 | Stack.back().SharingMap[D].Attributes = A; |
| 566 | Stack.back().SharingMap[D].RefExpr = E; |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 567 | Stack.back().SharingMap[D].PrivateCopy = PrivateCopy; |
| 568 | if (PrivateCopy) |
| 569 | addDSA(PrivateCopy->getDecl(), PrivateCopy, A); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 570 | } |
| 571 | } |
| 572 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 573 | bool DSAStackTy::isOpenMPLocal(VarDecl *D, StackTy::reverse_iterator Iter) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 574 | D = D->getCanonicalDecl(); |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 575 | if (Stack.size() > 2) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 576 | reverse_iterator I = Iter, E = std::prev(Stack.rend()); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 577 | Scope *TopScope = nullptr; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 578 | while (I != E && !isParallelOrTaskRegion(I->Directive)) { |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 579 | ++I; |
| 580 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 581 | if (I == E) |
| 582 | return false; |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 583 | TopScope = I->CurScope ? I->CurScope->getParent() : nullptr; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 584 | Scope *CurScope = getCurScope(); |
| 585 | while (CurScope != TopScope && !CurScope->isDeclScope(D)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 586 | CurScope = CurScope->getParent(); |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 587 | } |
| 588 | return CurScope != TopScope; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 589 | } |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 590 | return false; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 591 | } |
| 592 | |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 593 | /// \brief Build a variable declaration for OpenMP loop iteration variable. |
| 594 | static VarDecl *buildVarDecl(Sema &SemaRef, SourceLocation Loc, QualType Type, |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 595 | StringRef Name, const AttrVec *Attrs = nullptr) { |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 596 | DeclContext *DC = SemaRef.CurContext; |
| 597 | IdentifierInfo *II = &SemaRef.PP.getIdentifierTable().get(Name); |
| 598 | TypeSourceInfo *TInfo = SemaRef.Context.getTrivialTypeSourceInfo(Type, Loc); |
| 599 | VarDecl *Decl = |
| 600 | VarDecl::Create(SemaRef.Context, DC, Loc, Loc, II, Type, TInfo, SC_None); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 601 | if (Attrs) { |
| 602 | for (specific_attr_iterator<AlignedAttr> I(Attrs->begin()), E(Attrs->end()); |
| 603 | I != E; ++I) |
| 604 | Decl->addAttr(*I); |
| 605 | } |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 606 | Decl->setImplicit(); |
| 607 | return Decl; |
| 608 | } |
| 609 | |
| 610 | static DeclRefExpr *buildDeclRefExpr(Sema &S, VarDecl *D, QualType Ty, |
| 611 | SourceLocation Loc, |
| 612 | bool RefersToCapture = false) { |
| 613 | D->setReferenced(); |
| 614 | D->markUsed(S.Context); |
| 615 | return DeclRefExpr::Create(S.getASTContext(), NestedNameSpecifierLoc(), |
| 616 | SourceLocation(), D, RefersToCapture, Loc, Ty, |
| 617 | VK_LValue); |
| 618 | } |
| 619 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 620 | DSAStackTy::DSAVarData DSAStackTy::getTopDSA(ValueDecl *D, bool FromParent) { |
| 621 | D = getCanonicalDecl(D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 622 | DSAVarData DVar; |
| 623 | |
| 624 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 625 | // in a Construct, C/C++, predetermined, p.1] |
| 626 | // Variables appearing in threadprivate directives are threadprivate. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 627 | auto *VD = dyn_cast<VarDecl>(D); |
| 628 | if ((VD && VD->getTLSKind() != VarDecl::TLS_None && |
| 629 | !(VD->hasAttr<OMPThreadPrivateDeclAttr>() && |
Samuel Antao | f8b5012 | 2015-07-13 22:54:53 +0000 | [diff] [blame] | 630 | SemaRef.getLangOpts().OpenMPUseTLS && |
| 631 | SemaRef.getASTContext().getTargetInfo().isTLSSupported())) || |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 632 | (VD && VD->getStorageClass() == SC_Register && |
| 633 | VD->hasAttr<AsmLabelAttr>() && !VD->isLocalVarDecl())) { |
| 634 | addDSA(D, buildDeclRefExpr(SemaRef, VD, D->getType().getNonReferenceType(), |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 635 | D->getLocation()), |
Alexey Bataev | f2453a0 | 2015-05-06 07:25:08 +0000 | [diff] [blame] | 636 | OMPC_threadprivate); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 637 | } |
| 638 | if (Stack[0].SharingMap.count(D)) { |
| 639 | DVar.RefExpr = Stack[0].SharingMap[D].RefExpr; |
| 640 | DVar.CKind = OMPC_threadprivate; |
| 641 | return DVar; |
| 642 | } |
| 643 | |
| 644 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
Alexey Bataev | dffa93a | 2015-12-10 08:20:58 +0000 | [diff] [blame] | 645 | // in a Construct, C/C++, predetermined, p.4] |
| 646 | // Static data members are shared. |
| 647 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 648 | // in a Construct, C/C++, predetermined, p.7] |
| 649 | // Variables with static storage duration that are declared in a scope |
| 650 | // inside the construct are shared. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 651 | if (VD && VD->isStaticDataMember()) { |
Alexey Bataev | dffa93a | 2015-12-10 08:20:58 +0000 | [diff] [blame] | 652 | DSAVarData DVarTemp = |
| 653 | hasDSA(D, isOpenMPPrivate, MatchesAlways(), FromParent); |
| 654 | if (DVarTemp.CKind != OMPC_unknown && DVarTemp.RefExpr) |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 655 | return DVar; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 656 | |
Alexey Bataev | dffa93a | 2015-12-10 08:20:58 +0000 | [diff] [blame] | 657 | DVar.CKind = OMPC_shared; |
| 658 | return DVar; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 659 | } |
| 660 | |
| 661 | QualType Type = D->getType().getNonReferenceType().getCanonicalType(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 662 | bool IsConstant = Type.isConstant(SemaRef.getASTContext()); |
| 663 | Type = SemaRef.getASTContext().getBaseElementType(Type); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 664 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 665 | // in a Construct, C/C++, predetermined, p.6] |
| 666 | // Variables with const qualified type having no mutable member are |
| 667 | // shared. |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 668 | CXXRecordDecl *RD = |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 669 | SemaRef.getLangOpts().CPlusPlus ? Type->getAsCXXRecordDecl() : nullptr; |
Alexey Bataev | c9bd03d | 2015-12-17 06:55:08 +0000 | [diff] [blame] | 670 | if (auto *CTSD = dyn_cast_or_null<ClassTemplateSpecializationDecl>(RD)) |
| 671 | if (auto *CTD = CTSD->getSpecializedTemplate()) |
| 672 | RD = CTD->getTemplatedDecl(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 673 | if (IsConstant && |
Alexey Bataev | 4bcad7f | 2016-02-10 10:50:12 +0000 | [diff] [blame] | 674 | !(SemaRef.getLangOpts().CPlusPlus && RD && RD->hasDefinition() && |
| 675 | RD->hasMutableFields())) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 676 | // Variables with const-qualified type having no mutable member may be |
| 677 | // listed in a firstprivate clause, even if they are static data members. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 678 | DSAVarData DVarTemp = hasDSA(D, MatchesAnyClause(OMPC_firstprivate), |
| 679 | MatchesAlways(), FromParent); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 680 | if (DVarTemp.CKind == OMPC_firstprivate && DVarTemp.RefExpr) |
| 681 | return DVar; |
| 682 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 683 | DVar.CKind = OMPC_shared; |
| 684 | return DVar; |
| 685 | } |
| 686 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 687 | // Explicitly specified attributes and local variables with predetermined |
| 688 | // attributes. |
Alexey Bataev | dffa93a | 2015-12-10 08:20:58 +0000 | [diff] [blame] | 689 | auto StartI = std::next(Stack.rbegin()); |
| 690 | auto EndI = std::prev(Stack.rend()); |
| 691 | if (FromParent && StartI != EndI) { |
| 692 | StartI = std::next(StartI); |
| 693 | } |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 694 | auto I = std::prev(StartI); |
| 695 | if (I->SharingMap.count(D)) { |
| 696 | DVar.RefExpr = I->SharingMap[D].RefExpr; |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 697 | DVar.PrivateCopy = I->SharingMap[D].PrivateCopy; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 698 | DVar.CKind = I->SharingMap[D].Attributes; |
| 699 | DVar.ImplicitDSALoc = I->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 700 | } |
| 701 | |
| 702 | return DVar; |
| 703 | } |
| 704 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 705 | DSAStackTy::DSAVarData DSAStackTy::getImplicitDSA(ValueDecl *D, |
| 706 | bool FromParent) { |
| 707 | D = getCanonicalDecl(D); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 708 | auto StartI = Stack.rbegin(); |
| 709 | auto EndI = std::prev(Stack.rend()); |
| 710 | if (FromParent && StartI != EndI) { |
| 711 | StartI = std::next(StartI); |
| 712 | } |
| 713 | return getDSA(StartI, D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 714 | } |
| 715 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 716 | template <class ClausesPredicate, class DirectivesPredicate> |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 717 | DSAStackTy::DSAVarData DSAStackTy::hasDSA(ValueDecl *D, ClausesPredicate CPred, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 718 | DirectivesPredicate DPred, |
| 719 | bool FromParent) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 720 | D = getCanonicalDecl(D); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 721 | auto StartI = std::next(Stack.rbegin()); |
| 722 | auto EndI = std::prev(Stack.rend()); |
| 723 | if (FromParent && StartI != EndI) { |
| 724 | StartI = std::next(StartI); |
| 725 | } |
| 726 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
| 727 | if (!DPred(I->Directive) && !isParallelOrTaskRegion(I->Directive)) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 728 | continue; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 729 | DSAVarData DVar = getDSA(I, D); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 730 | if (CPred(DVar.CKind)) |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 731 | return DVar; |
| 732 | } |
| 733 | return DSAVarData(); |
| 734 | } |
| 735 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 736 | template <class ClausesPredicate, class DirectivesPredicate> |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 737 | DSAStackTy::DSAVarData |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 738 | DSAStackTy::hasInnermostDSA(ValueDecl *D, ClausesPredicate CPred, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 739 | DirectivesPredicate DPred, bool FromParent) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 740 | D = getCanonicalDecl(D); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 741 | auto StartI = std::next(Stack.rbegin()); |
| 742 | auto EndI = std::prev(Stack.rend()); |
| 743 | if (FromParent && StartI != EndI) { |
| 744 | StartI = std::next(StartI); |
| 745 | } |
| 746 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 747 | if (!DPred(I->Directive)) |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 748 | break; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 749 | DSAVarData DVar = getDSA(I, D); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 750 | if (CPred(DVar.CKind)) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 751 | return DVar; |
| 752 | return DSAVarData(); |
| 753 | } |
| 754 | return DSAVarData(); |
| 755 | } |
| 756 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 757 | bool DSAStackTy::hasExplicitDSA( |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 758 | ValueDecl *D, const llvm::function_ref<bool(OpenMPClauseKind)> &CPred, |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 759 | unsigned Level) { |
| 760 | if (CPred(ClauseKindMode)) |
| 761 | return true; |
| 762 | if (isClauseParsingMode()) |
| 763 | ++Level; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 764 | D = getCanonicalDecl(D); |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 765 | auto StartI = Stack.rbegin(); |
| 766 | auto EndI = std::prev(Stack.rend()); |
NAKAMURA Takumi | 0332eda | 2015-06-23 10:01:20 +0000 | [diff] [blame] | 767 | if (std::distance(StartI, EndI) <= (int)Level) |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 768 | return false; |
| 769 | std::advance(StartI, Level); |
| 770 | return (StartI->SharingMap.count(D) > 0) && StartI->SharingMap[D].RefExpr && |
| 771 | CPred(StartI->SharingMap[D].Attributes); |
| 772 | } |
| 773 | |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 774 | bool DSAStackTy::hasExplicitDirective( |
| 775 | const llvm::function_ref<bool(OpenMPDirectiveKind)> &DPred, |
| 776 | unsigned Level) { |
| 777 | if (isClauseParsingMode()) |
| 778 | ++Level; |
| 779 | auto StartI = Stack.rbegin(); |
| 780 | auto EndI = std::prev(Stack.rend()); |
| 781 | if (std::distance(StartI, EndI) <= (int)Level) |
| 782 | return false; |
| 783 | std::advance(StartI, Level); |
| 784 | return DPred(StartI->Directive); |
| 785 | } |
| 786 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 787 | template <class NamedDirectivesPredicate> |
| 788 | bool DSAStackTy::hasDirective(NamedDirectivesPredicate DPred, bool FromParent) { |
| 789 | auto StartI = std::next(Stack.rbegin()); |
| 790 | auto EndI = std::prev(Stack.rend()); |
| 791 | if (FromParent && StartI != EndI) { |
| 792 | StartI = std::next(StartI); |
| 793 | } |
| 794 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
| 795 | if (DPred(I->Directive, I->DirectiveName, I->ConstructLoc)) |
| 796 | return true; |
| 797 | } |
| 798 | return false; |
| 799 | } |
| 800 | |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 801 | OpenMPDirectiveKind DSAStackTy::getDirectiveForScope(const Scope *S) const { |
| 802 | for (auto I = Stack.rbegin(), EE = Stack.rend(); I != EE; ++I) |
| 803 | if (I->CurScope == S) |
| 804 | return I->Directive; |
| 805 | return OMPD_unknown; |
| 806 | } |
| 807 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 808 | void Sema::InitDataSharingAttributesStack() { |
| 809 | VarDataSharingAttributesStack = new DSAStackTy(*this); |
| 810 | } |
| 811 | |
| 812 | #define DSAStack static_cast<DSAStackTy *>(VarDataSharingAttributesStack) |
| 813 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 814 | bool Sema::IsOpenMPCapturedByRef(ValueDecl *D, |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 815 | const CapturedRegionScopeInfo *RSI) { |
| 816 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| 817 | |
| 818 | auto &Ctx = getASTContext(); |
| 819 | bool IsByRef = true; |
| 820 | |
| 821 | // Find the directive that is associated with the provided scope. |
| 822 | auto DKind = DSAStack->getDirectiveForScope(RSI->TheScope); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 823 | auto Ty = D->getType(); |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 824 | |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 825 | if (isOpenMPTargetExecutionDirective(DKind)) { |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 826 | // This table summarizes how a given variable should be passed to the device |
| 827 | // given its type and the clauses where it appears. This table is based on |
| 828 | // the description in OpenMP 4.5 [2.10.4, target Construct] and |
| 829 | // OpenMP 4.5 [2.15.5, Data-mapping Attribute Rules and Clauses]. |
| 830 | // |
| 831 | // ========================================================================= |
| 832 | // | type | defaultmap | pvt | first | is_device_ptr | map | res. | |
| 833 | // | |(tofrom:scalar)| | pvt | | | | |
| 834 | // ========================================================================= |
| 835 | // | scl | | | | - | | bycopy| |
| 836 | // | scl | | - | x | - | - | bycopy| |
| 837 | // | scl | | x | - | - | - | null | |
| 838 | // | scl | x | | | - | | byref | |
| 839 | // | scl | x | - | x | - | - | bycopy| |
| 840 | // | scl | x | x | - | - | - | null | |
| 841 | // | scl | | - | - | - | x | byref | |
| 842 | // | scl | x | - | - | - | x | byref | |
| 843 | // |
| 844 | // | agg | n.a. | | | - | | byref | |
| 845 | // | agg | n.a. | - | x | - | - | byref | |
| 846 | // | agg | n.a. | x | - | - | - | null | |
| 847 | // | agg | n.a. | - | - | - | x | byref | |
| 848 | // | agg | n.a. | - | - | - | x[] | byref | |
| 849 | // |
| 850 | // | ptr | n.a. | | | - | | bycopy| |
| 851 | // | ptr | n.a. | - | x | - | - | bycopy| |
| 852 | // | ptr | n.a. | x | - | - | - | null | |
| 853 | // | ptr | n.a. | - | - | - | x | byref | |
| 854 | // | ptr | n.a. | - | - | - | x[] | bycopy| |
| 855 | // | ptr | n.a. | - | - | x | | bycopy| |
| 856 | // | ptr | n.a. | - | - | x | x | bycopy| |
| 857 | // | ptr | n.a. | - | - | x | x[] | bycopy| |
| 858 | // ========================================================================= |
| 859 | // Legend: |
| 860 | // scl - scalar |
| 861 | // ptr - pointer |
| 862 | // agg - aggregate |
| 863 | // x - applies |
| 864 | // - - invalid in this combination |
| 865 | // [] - mapped with an array section |
| 866 | // byref - should be mapped by reference |
| 867 | // byval - should be mapped by value |
| 868 | // null - initialize a local variable to null on the device |
| 869 | // |
| 870 | // Observations: |
| 871 | // - All scalar declarations that show up in a map clause have to be passed |
| 872 | // by reference, because they may have been mapped in the enclosing data |
| 873 | // environment. |
| 874 | // - If the scalar value does not fit the size of uintptr, it has to be |
| 875 | // passed by reference, regardless the result in the table above. |
| 876 | // - For pointers mapped by value that have either an implicit map or an |
| 877 | // array section, the runtime library may pass the NULL value to the |
| 878 | // device instead of the value passed to it by the compiler. |
| 879 | |
| 880 | // FIXME: Right now, only implicit maps are implemented. Properly mapping |
| 881 | // values requires having the map, private, and firstprivate clauses SEMA |
| 882 | // and parsing in place, which we don't yet. |
| 883 | |
| 884 | if (Ty->isReferenceType()) |
| 885 | Ty = Ty->castAs<ReferenceType>()->getPointeeType(); |
| 886 | IsByRef = !Ty->isScalarType(); |
| 887 | } |
| 888 | |
| 889 | // When passing data by value, we need to make sure it fits the uintptr size |
| 890 | // and alignment, because the runtime library only deals with uintptr types. |
| 891 | // If it does not fit the uintptr size, we need to pass the data by reference |
| 892 | // instead. |
| 893 | if (!IsByRef && |
| 894 | (Ctx.getTypeSizeInChars(Ty) > |
| 895 | Ctx.getTypeSizeInChars(Ctx.getUIntPtrType()) || |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 896 | Ctx.getDeclAlign(D) > Ctx.getTypeAlignInChars(Ctx.getUIntPtrType()))) |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 897 | IsByRef = true; |
| 898 | |
| 899 | return IsByRef; |
| 900 | } |
| 901 | |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 902 | VarDecl *Sema::IsOpenMPCapturedDecl(ValueDecl *D) { |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 903 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 904 | D = getCanonicalDecl(D); |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 905 | |
| 906 | // If we are attempting to capture a global variable in a directive with |
| 907 | // 'target' we return true so that this global is also mapped to the device. |
| 908 | // |
| 909 | // FIXME: If the declaration is enclosed in a 'declare target' directive, |
| 910 | // then it should not be captured. Therefore, an extra check has to be |
| 911 | // inserted here once support for 'declare target' is added. |
| 912 | // |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 913 | auto *VD = dyn_cast<VarDecl>(D); |
| 914 | if (VD && !VD->hasLocalStorage()) { |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 915 | if (DSAStack->getCurrentDirective() == OMPD_target && |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 916 | !DSAStack->isClauseParsingMode()) |
| 917 | return VD; |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 918 | if (DSAStack->getCurScope() && |
| 919 | DSAStack->hasDirective( |
| 920 | [](OpenMPDirectiveKind K, const DeclarationNameInfo &DNI, |
| 921 | SourceLocation Loc) -> bool { |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 922 | return isOpenMPTargetExecutionDirective(K); |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 923 | }, |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 924 | false)) |
| 925 | return VD; |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 926 | } |
| 927 | |
Alexey Bataev | 48977c3 | 2015-08-04 08:10:48 +0000 | [diff] [blame] | 928 | if (DSAStack->getCurrentDirective() != OMPD_unknown && |
| 929 | (!DSAStack->isClauseParsingMode() || |
| 930 | DSAStack->getParentDirective() != OMPD_unknown)) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 931 | if (DSAStack->isLoopControlVariable(D) || |
| 932 | (VD && VD->hasLocalStorage() && |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 933 | isParallelOrTaskRegion(DSAStack->getCurrentDirective())) || |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 934 | (VD && DSAStack->isForceVarCapturing())) |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 935 | return VD; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 936 | auto DVarPrivate = DSAStack->getTopDSA(D, DSAStack->isClauseParsingMode()); |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 937 | if (DVarPrivate.CKind != OMPC_unknown && isOpenMPPrivate(DVarPrivate.CKind)) |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 938 | return VD ? VD : cast<VarDecl>(DVarPrivate.PrivateCopy->getDecl()); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 939 | DVarPrivate = DSAStack->hasDSA(D, isOpenMPPrivate, MatchesAlways(), |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 940 | DSAStack->isClauseParsingMode()); |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 941 | if (DVarPrivate.CKind != OMPC_unknown) |
| 942 | return VD ? VD : cast<VarDecl>(DVarPrivate.PrivateCopy->getDecl()); |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 943 | } |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 944 | return nullptr; |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 945 | } |
| 946 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 947 | bool Sema::isOpenMPPrivateDecl(ValueDecl *D, unsigned Level) { |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 948 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| 949 | return DSAStack->hasExplicitDSA( |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 950 | D, [](OpenMPClauseKind K) -> bool { return K == OMPC_private; }, Level); |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 951 | } |
| 952 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 953 | bool Sema::isOpenMPTargetCapturedDecl(ValueDecl *D, unsigned Level) { |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 954 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| 955 | // Return true if the current level is no longer enclosed in a target region. |
| 956 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 957 | auto *VD = dyn_cast<VarDecl>(D); |
| 958 | return VD && !VD->hasLocalStorage() && |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 959 | DSAStack->hasExplicitDirective(isOpenMPTargetExecutionDirective, |
| 960 | Level); |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 961 | } |
| 962 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 963 | void Sema::DestroyDataSharingAttributesStack() { delete DSAStack; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 964 | |
| 965 | void Sema::StartOpenMPDSABlock(OpenMPDirectiveKind DKind, |
| 966 | const DeclarationNameInfo &DirName, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 967 | Scope *CurScope, SourceLocation Loc) { |
| 968 | DSAStack->push(DKind, DirName, CurScope, Loc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 969 | PushExpressionEvaluationContext(PotentiallyEvaluated); |
| 970 | } |
| 971 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 972 | void Sema::StartOpenMPClause(OpenMPClauseKind K) { |
| 973 | DSAStack->setClauseParsingMode(K); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 974 | } |
| 975 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 976 | void Sema::EndOpenMPClause() { |
| 977 | DSAStack->setClauseParsingMode(/*K=*/OMPC_unknown); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 978 | } |
| 979 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 980 | void Sema::EndOpenMPDSABlock(Stmt *CurDirective) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 981 | // OpenMP [2.14.3.5, Restrictions, C/C++, p.1] |
| 982 | // A variable of class type (or array thereof) that appears in a lastprivate |
| 983 | // clause requires an accessible, unambiguous default constructor for the |
| 984 | // class type, unless the list item is also specified in a firstprivate |
| 985 | // clause. |
| 986 | if (auto D = dyn_cast_or_null<OMPExecutableDirective>(CurDirective)) { |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 987 | for (auto *C : D->clauses()) { |
| 988 | if (auto *Clause = dyn_cast<OMPLastprivateClause>(C)) { |
| 989 | SmallVector<Expr *, 8> PrivateCopies; |
| 990 | for (auto *DE : Clause->varlists()) { |
| 991 | if (DE->isValueDependent() || DE->isTypeDependent()) { |
| 992 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 993 | continue; |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 994 | } |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 995 | auto *DRE = cast<DeclRefExpr>(DE->IgnoreParens()); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 996 | VarDecl *VD = cast<VarDecl>(DRE->getDecl()); |
| 997 | QualType Type = VD->getType().getNonReferenceType(); |
| 998 | auto DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 999 | if (DVar.CKind == OMPC_lastprivate) { |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1000 | // Generate helper private variable and initialize it with the |
| 1001 | // default value. The address of the original variable is replaced |
| 1002 | // by the address of the new private variable in CodeGen. This new |
| 1003 | // variable is not added to IdResolver, so the code in the OpenMP |
| 1004 | // region uses original variable for proper diagnostics. |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 1005 | auto *VDPrivate = buildVarDecl( |
| 1006 | *this, DE->getExprLoc(), Type.getUnqualifiedType(), |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 1007 | VD->getName(), VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1008 | ActOnUninitializedDecl(VDPrivate, /*TypeMayContainAuto=*/false); |
| 1009 | if (VDPrivate->isInvalidDecl()) |
| 1010 | continue; |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 1011 | PrivateCopies.push_back(buildDeclRefExpr( |
| 1012 | *this, VDPrivate, DE->getType(), DE->getExprLoc())); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1013 | } else { |
| 1014 | // The variable is also a firstprivate, so initialization sequence |
| 1015 | // for private copy is generated already. |
| 1016 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1017 | } |
| 1018 | } |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1019 | // Set initializers to private copies if no errors were found. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1020 | if (PrivateCopies.size() == Clause->varlist_size()) |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1021 | Clause->setPrivateCopies(PrivateCopies); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1022 | } |
| 1023 | } |
| 1024 | } |
| 1025 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1026 | DSAStack->pop(); |
| 1027 | DiscardCleanupsInEvaluationContext(); |
| 1028 | PopExpressionEvaluationContext(); |
| 1029 | } |
| 1030 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 1031 | static bool |
| 1032 | FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV, |
| 1033 | Expr *NumIterations, Sema &SemaRef, Scope *S); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 1034 | |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1035 | namespace { |
| 1036 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1037 | class VarDeclFilterCCC : public CorrectionCandidateCallback { |
| 1038 | private: |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1039 | Sema &SemaRef; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1040 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1041 | public: |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1042 | explicit VarDeclFilterCCC(Sema &S) : SemaRef(S) {} |
Craig Topper | e14c0f8 | 2014-03-12 04:55:44 +0000 | [diff] [blame] | 1043 | bool ValidateCandidate(const TypoCorrection &Candidate) override { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1044 | NamedDecl *ND = Candidate.getCorrectionDecl(); |
| 1045 | if (VarDecl *VD = dyn_cast_or_null<VarDecl>(ND)) { |
| 1046 | return VD->hasGlobalStorage() && |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1047 | SemaRef.isDeclInScope(ND, SemaRef.getCurLexicalContext(), |
| 1048 | SemaRef.getCurScope()); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1049 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1050 | return false; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1051 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1052 | }; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1053 | } // namespace |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1054 | |
| 1055 | ExprResult Sema::ActOnOpenMPIdExpression(Scope *CurScope, |
| 1056 | CXXScopeSpec &ScopeSpec, |
| 1057 | const DeclarationNameInfo &Id) { |
| 1058 | LookupResult Lookup(*this, Id, LookupOrdinaryName); |
| 1059 | LookupParsedName(Lookup, CurScope, &ScopeSpec, true); |
| 1060 | |
| 1061 | if (Lookup.isAmbiguous()) |
| 1062 | return ExprError(); |
| 1063 | |
| 1064 | VarDecl *VD; |
| 1065 | if (!Lookup.isSingleResult()) { |
Kaelyn Takata | 89c881b | 2014-10-27 18:07:29 +0000 | [diff] [blame] | 1066 | if (TypoCorrection Corrected = CorrectTypo( |
| 1067 | Id, LookupOrdinaryName, CurScope, nullptr, |
| 1068 | llvm::make_unique<VarDeclFilterCCC>(*this), CTK_ErrorRecovery)) { |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 1069 | diagnoseTypo(Corrected, |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 1070 | PDiag(Lookup.empty() |
| 1071 | ? diag::err_undeclared_var_use_suggest |
| 1072 | : diag::err_omp_expected_var_arg_suggest) |
| 1073 | << Id.getName()); |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 1074 | VD = Corrected.getCorrectionDeclAs<VarDecl>(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1075 | } else { |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 1076 | Diag(Id.getLoc(), Lookup.empty() ? diag::err_undeclared_var_use |
| 1077 | : diag::err_omp_expected_var_arg) |
| 1078 | << Id.getName(); |
| 1079 | return ExprError(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1080 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1081 | } else { |
| 1082 | if (!(VD = Lookup.getAsSingle<VarDecl>())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1083 | Diag(Id.getLoc(), diag::err_omp_expected_var_arg) << Id.getName(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1084 | Diag(Lookup.getFoundDecl()->getLocation(), diag::note_declared_at); |
| 1085 | return ExprError(); |
| 1086 | } |
| 1087 | } |
| 1088 | Lookup.suppressDiagnostics(); |
| 1089 | |
| 1090 | // OpenMP [2.9.2, Syntax, C/C++] |
| 1091 | // Variables must be file-scope, namespace-scope, or static block-scope. |
| 1092 | if (!VD->hasGlobalStorage()) { |
| 1093 | Diag(Id.getLoc(), diag::err_omp_global_var_arg) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1094 | << getOpenMPDirectiveName(OMPD_threadprivate) << !VD->isStaticLocal(); |
| 1095 | bool IsDecl = |
| 1096 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1097 | Diag(VD->getLocation(), |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1098 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1099 | << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1100 | return ExprError(); |
| 1101 | } |
| 1102 | |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1103 | VarDecl *CanonicalVD = VD->getCanonicalDecl(); |
| 1104 | NamedDecl *ND = cast<NamedDecl>(CanonicalVD); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1105 | // OpenMP [2.9.2, Restrictions, C/C++, p.2] |
| 1106 | // A threadprivate directive for file-scope variables must appear outside |
| 1107 | // any definition or declaration. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1108 | if (CanonicalVD->getDeclContext()->isTranslationUnit() && |
| 1109 | !getCurLexicalContext()->isTranslationUnit()) { |
| 1110 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1111 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1112 | bool IsDecl = |
| 1113 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1114 | Diag(VD->getLocation(), |
| 1115 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1116 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1117 | return ExprError(); |
| 1118 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1119 | // OpenMP [2.9.2, Restrictions, C/C++, p.3] |
| 1120 | // A threadprivate directive for static class member variables must appear |
| 1121 | // in the class definition, in the same scope in which the member |
| 1122 | // variables are declared. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1123 | if (CanonicalVD->isStaticDataMember() && |
| 1124 | !CanonicalVD->getDeclContext()->Equals(getCurLexicalContext())) { |
| 1125 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1126 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1127 | bool IsDecl = |
| 1128 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1129 | Diag(VD->getLocation(), |
| 1130 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1131 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1132 | return ExprError(); |
| 1133 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1134 | // OpenMP [2.9.2, Restrictions, C/C++, p.4] |
| 1135 | // A threadprivate directive for namespace-scope variables must appear |
| 1136 | // outside any definition or declaration other than the namespace |
| 1137 | // definition itself. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1138 | if (CanonicalVD->getDeclContext()->isNamespace() && |
| 1139 | (!getCurLexicalContext()->isFileContext() || |
| 1140 | !getCurLexicalContext()->Encloses(CanonicalVD->getDeclContext()))) { |
| 1141 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1142 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1143 | bool IsDecl = |
| 1144 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1145 | Diag(VD->getLocation(), |
| 1146 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1147 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1148 | return ExprError(); |
| 1149 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1150 | // OpenMP [2.9.2, Restrictions, C/C++, p.6] |
| 1151 | // A threadprivate directive for static block-scope variables must appear |
| 1152 | // in the scope of the variable and not in a nested scope. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1153 | if (CanonicalVD->isStaticLocal() && CurScope && |
| 1154 | !isDeclInScope(ND, getCurLexicalContext(), CurScope)) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1155 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1156 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1157 | bool IsDecl = |
| 1158 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1159 | Diag(VD->getLocation(), |
| 1160 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1161 | << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1162 | return ExprError(); |
| 1163 | } |
| 1164 | |
| 1165 | // OpenMP [2.9.2, Restrictions, C/C++, p.2-6] |
| 1166 | // A threadprivate directive must lexically precede all references to any |
| 1167 | // of the variables in its list. |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 1168 | if (VD->isUsed() && !DSAStack->isThreadPrivate(VD)) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1169 | Diag(Id.getLoc(), diag::err_omp_var_used) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1170 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1171 | return ExprError(); |
| 1172 | } |
| 1173 | |
| 1174 | QualType ExprType = VD->getType().getNonReferenceType(); |
Alexey Bataev | 376b4a4 | 2016-02-09 09:41:09 +0000 | [diff] [blame] | 1175 | return DeclRefExpr::Create(Context, NestedNameSpecifierLoc(), |
| 1176 | SourceLocation(), VD, |
| 1177 | /*RefersToEnclosingVariableOrCapture=*/false, |
| 1178 | Id.getLoc(), ExprType, VK_LValue); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1179 | } |
| 1180 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1181 | Sema::DeclGroupPtrTy |
| 1182 | Sema::ActOnOpenMPThreadprivateDirective(SourceLocation Loc, |
| 1183 | ArrayRef<Expr *> VarList) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1184 | if (OMPThreadPrivateDecl *D = CheckOMPThreadPrivateDecl(Loc, VarList)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1185 | CurContext->addDecl(D); |
| 1186 | return DeclGroupPtrTy::make(DeclGroupRef(D)); |
| 1187 | } |
David Blaikie | 0403cb1 | 2016-01-15 23:43:25 +0000 | [diff] [blame] | 1188 | return nullptr; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1189 | } |
| 1190 | |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1191 | namespace { |
| 1192 | class LocalVarRefChecker : public ConstStmtVisitor<LocalVarRefChecker, bool> { |
| 1193 | Sema &SemaRef; |
| 1194 | |
| 1195 | public: |
| 1196 | bool VisitDeclRefExpr(const DeclRefExpr *E) { |
| 1197 | if (auto VD = dyn_cast<VarDecl>(E->getDecl())) { |
| 1198 | if (VD->hasLocalStorage()) { |
| 1199 | SemaRef.Diag(E->getLocStart(), |
| 1200 | diag::err_omp_local_var_in_threadprivate_init) |
| 1201 | << E->getSourceRange(); |
| 1202 | SemaRef.Diag(VD->getLocation(), diag::note_defined_here) |
| 1203 | << VD << VD->getSourceRange(); |
| 1204 | return true; |
| 1205 | } |
| 1206 | } |
| 1207 | return false; |
| 1208 | } |
| 1209 | bool VisitStmt(const Stmt *S) { |
| 1210 | for (auto Child : S->children()) { |
| 1211 | if (Child && Visit(Child)) |
| 1212 | return true; |
| 1213 | } |
| 1214 | return false; |
| 1215 | } |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 1216 | explicit LocalVarRefChecker(Sema &SemaRef) : SemaRef(SemaRef) {} |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1217 | }; |
| 1218 | } // namespace |
| 1219 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1220 | OMPThreadPrivateDecl * |
| 1221 | Sema::CheckOMPThreadPrivateDecl(SourceLocation Loc, ArrayRef<Expr *> VarList) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1222 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1223 | for (auto &RefExpr : VarList) { |
| 1224 | DeclRefExpr *DE = cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1225 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); |
| 1226 | SourceLocation ILoc = DE->getExprLoc(); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1227 | |
Alexey Bataev | 376b4a4 | 2016-02-09 09:41:09 +0000 | [diff] [blame] | 1228 | // Mark variable as used. |
| 1229 | VD->setReferenced(); |
| 1230 | VD->markUsed(Context); |
| 1231 | |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 1232 | QualType QType = VD->getType(); |
| 1233 | if (QType->isDependentType() || QType->isInstantiationDependentType()) { |
| 1234 | // It will be analyzed later. |
| 1235 | Vars.push_back(DE); |
| 1236 | continue; |
| 1237 | } |
| 1238 | |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1239 | // OpenMP [2.9.2, Restrictions, C/C++, p.10] |
| 1240 | // A threadprivate variable must not have an incomplete type. |
| 1241 | if (RequireCompleteType(ILoc, VD->getType(), |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1242 | diag::err_omp_threadprivate_incomplete_type)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1243 | continue; |
| 1244 | } |
| 1245 | |
| 1246 | // OpenMP [2.9.2, Restrictions, C/C++, p.10] |
| 1247 | // A threadprivate variable must not have a reference type. |
| 1248 | if (VD->getType()->isReferenceType()) { |
| 1249 | Diag(ILoc, diag::err_omp_ref_type_arg) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1250 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD->getType(); |
| 1251 | bool IsDecl = |
| 1252 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1253 | Diag(VD->getLocation(), |
| 1254 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1255 | << VD; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1256 | continue; |
| 1257 | } |
| 1258 | |
Samuel Antao | f8b5012 | 2015-07-13 22:54:53 +0000 | [diff] [blame] | 1259 | // Check if this is a TLS variable. If TLS is not being supported, produce |
| 1260 | // the corresponding diagnostic. |
| 1261 | if ((VD->getTLSKind() != VarDecl::TLS_None && |
| 1262 | !(VD->hasAttr<OMPThreadPrivateDeclAttr>() && |
| 1263 | getLangOpts().OpenMPUseTLS && |
| 1264 | getASTContext().getTargetInfo().isTLSSupported())) || |
Alexey Bataev | 1a8b3f1 | 2015-05-06 06:34:55 +0000 | [diff] [blame] | 1265 | (VD->getStorageClass() == SC_Register && VD->hasAttr<AsmLabelAttr>() && |
| 1266 | !VD->isLocalVarDecl())) { |
Alexey Bataev | 26a3924 | 2015-01-13 03:35:30 +0000 | [diff] [blame] | 1267 | Diag(ILoc, diag::err_omp_var_thread_local) |
| 1268 | << VD << ((VD->getTLSKind() != VarDecl::TLS_None) ? 0 : 1); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1269 | bool IsDecl = |
| 1270 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1271 | Diag(VD->getLocation(), |
| 1272 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1273 | << VD; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1274 | continue; |
| 1275 | } |
| 1276 | |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1277 | // Check if initial value of threadprivate variable reference variable with |
| 1278 | // local storage (it is not supported by runtime). |
| 1279 | if (auto Init = VD->getAnyInitializer()) { |
| 1280 | LocalVarRefChecker Checker(*this); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1281 | if (Checker.Visit(Init)) |
| 1282 | continue; |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1283 | } |
| 1284 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1285 | Vars.push_back(RefExpr); |
Alexey Bataev | d178ad4 | 2014-03-07 08:03:37 +0000 | [diff] [blame] | 1286 | DSAStack->addDSA(VD, DE, OMPC_threadprivate); |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 1287 | VD->addAttr(OMPThreadPrivateDeclAttr::CreateImplicit( |
| 1288 | Context, SourceRange(Loc, Loc))); |
| 1289 | if (auto *ML = Context.getASTMutationListener()) |
| 1290 | ML->DeclarationMarkedOpenMPThreadPrivate(VD); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1291 | } |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 1292 | OMPThreadPrivateDecl *D = nullptr; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 1293 | if (!Vars.empty()) { |
| 1294 | D = OMPThreadPrivateDecl::Create(Context, getCurLexicalContext(), Loc, |
| 1295 | Vars); |
| 1296 | D->setAccess(AS_public); |
| 1297 | } |
| 1298 | return D; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1299 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1300 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1301 | static void ReportOriginalDSA(Sema &SemaRef, DSAStackTy *Stack, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1302 | const ValueDecl *D, DSAStackTy::DSAVarData DVar, |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1303 | bool IsLoopIterVar = false) { |
| 1304 | if (DVar.RefExpr) { |
| 1305 | SemaRef.Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_explicit_dsa) |
| 1306 | << getOpenMPClauseName(DVar.CKind); |
| 1307 | return; |
| 1308 | } |
| 1309 | enum { |
| 1310 | PDSA_StaticMemberShared, |
| 1311 | PDSA_StaticLocalVarShared, |
| 1312 | PDSA_LoopIterVarPrivate, |
| 1313 | PDSA_LoopIterVarLinear, |
| 1314 | PDSA_LoopIterVarLastprivate, |
| 1315 | PDSA_ConstVarShared, |
| 1316 | PDSA_GlobalVarShared, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1317 | PDSA_TaskVarFirstprivate, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1318 | PDSA_LocalVarPrivate, |
| 1319 | PDSA_Implicit |
| 1320 | } Reason = PDSA_Implicit; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1321 | bool ReportHint = false; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1322 | auto ReportLoc = D->getLocation(); |
| 1323 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1324 | if (IsLoopIterVar) { |
| 1325 | if (DVar.CKind == OMPC_private) |
| 1326 | Reason = PDSA_LoopIterVarPrivate; |
| 1327 | else if (DVar.CKind == OMPC_lastprivate) |
| 1328 | Reason = PDSA_LoopIterVarLastprivate; |
| 1329 | else |
| 1330 | Reason = PDSA_LoopIterVarLinear; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1331 | } else if (DVar.DKind == OMPD_task && DVar.CKind == OMPC_firstprivate) { |
| 1332 | Reason = PDSA_TaskVarFirstprivate; |
| 1333 | ReportLoc = DVar.ImplicitDSALoc; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1334 | } else if (VD && VD->isStaticLocal()) |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1335 | Reason = PDSA_StaticLocalVarShared; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1336 | else if (VD && VD->isStaticDataMember()) |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1337 | Reason = PDSA_StaticMemberShared; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1338 | else if (VD && VD->isFileVarDecl()) |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1339 | Reason = PDSA_GlobalVarShared; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1340 | else if (D->getType().isConstant(SemaRef.getASTContext())) |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1341 | Reason = PDSA_ConstVarShared; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1342 | else if (VD && VD->isLocalVarDecl() && DVar.CKind == OMPC_private) { |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1343 | ReportHint = true; |
| 1344 | Reason = PDSA_LocalVarPrivate; |
| 1345 | } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1346 | if (Reason != PDSA_Implicit) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1347 | SemaRef.Diag(ReportLoc, diag::note_omp_predetermined_dsa) |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1348 | << Reason << ReportHint |
| 1349 | << getOpenMPDirectiveName(Stack->getCurrentDirective()); |
| 1350 | } else if (DVar.ImplicitDSALoc.isValid()) { |
| 1351 | SemaRef.Diag(DVar.ImplicitDSALoc, diag::note_omp_implicit_dsa) |
| 1352 | << getOpenMPClauseName(DVar.CKind); |
| 1353 | } |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1354 | } |
| 1355 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1356 | namespace { |
| 1357 | class DSAAttrChecker : public StmtVisitor<DSAAttrChecker, void> { |
| 1358 | DSAStackTy *Stack; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1359 | Sema &SemaRef; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1360 | bool ErrorFound; |
| 1361 | CapturedStmt *CS; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1362 | llvm::SmallVector<Expr *, 8> ImplicitFirstprivate; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1363 | llvm::DenseMap<ValueDecl *, Expr *> VarsWithInheritedDSA; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1364 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1365 | public: |
| 1366 | void VisitDeclRefExpr(DeclRefExpr *E) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1367 | if (auto *VD = dyn_cast<VarDecl>(E->getDecl())) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1368 | // Skip internally declared variables. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1369 | if (VD->isLocalVarDecl() && !CS->capturesVariable(VD)) |
| 1370 | return; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1371 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1372 | auto DVar = Stack->getTopDSA(VD, false); |
| 1373 | // Check if the variable has explicit DSA set and stop analysis if it so. |
| 1374 | if (DVar.RefExpr) return; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1375 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1376 | auto ELoc = E->getExprLoc(); |
| 1377 | auto DKind = Stack->getCurrentDirective(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1378 | // The default(none) clause requires that each variable that is referenced |
| 1379 | // in the construct, and does not have a predetermined data-sharing |
| 1380 | // attribute, must have its data-sharing attribute explicitly determined |
| 1381 | // by being listed in a data-sharing attribute clause. |
| 1382 | if (DVar.CKind == OMPC_unknown && Stack->getDefaultDSA() == DSA_none && |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1383 | isParallelOrTaskRegion(DKind) && |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1384 | VarsWithInheritedDSA.count(VD) == 0) { |
| 1385 | VarsWithInheritedDSA[VD] = E; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1386 | return; |
| 1387 | } |
| 1388 | |
| 1389 | // OpenMP [2.9.3.6, Restrictions, p.2] |
| 1390 | // A list item that appears in a reduction clause of the innermost |
| 1391 | // enclosing worksharing or parallel construct may not be accessed in an |
| 1392 | // explicit task. |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1393 | DVar = Stack->hasInnermostDSA(VD, MatchesAnyClause(OMPC_reduction), |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1394 | [](OpenMPDirectiveKind K) -> bool { |
| 1395 | return isOpenMPParallelDirective(K) || |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1396 | isOpenMPWorksharingDirective(K) || |
| 1397 | isOpenMPTeamsDirective(K); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1398 | }, |
| 1399 | false); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1400 | if (DKind == OMPD_task && DVar.CKind == OMPC_reduction) { |
| 1401 | ErrorFound = true; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1402 | SemaRef.Diag(ELoc, diag::err_omp_reduction_in_task); |
| 1403 | ReportOriginalDSA(SemaRef, Stack, VD, DVar); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1404 | return; |
| 1405 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1406 | |
| 1407 | // Define implicit data-sharing attributes for task. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1408 | DVar = Stack->getImplicitDSA(VD, false); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1409 | if (DKind == OMPD_task && DVar.CKind != OMPC_shared) |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1410 | ImplicitFirstprivate.push_back(E); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1411 | } |
| 1412 | } |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1413 | void VisitMemberExpr(MemberExpr *E) { |
| 1414 | if (isa<CXXThisExpr>(E->getBase()->IgnoreParens())) { |
| 1415 | if (auto *FD = dyn_cast<FieldDecl>(E->getMemberDecl())) { |
| 1416 | auto DVar = Stack->getTopDSA(FD, false); |
| 1417 | // Check if the variable has explicit DSA set and stop analysis if it |
| 1418 | // so. |
| 1419 | if (DVar.RefExpr) |
| 1420 | return; |
| 1421 | |
| 1422 | auto ELoc = E->getExprLoc(); |
| 1423 | auto DKind = Stack->getCurrentDirective(); |
| 1424 | // OpenMP [2.9.3.6, Restrictions, p.2] |
| 1425 | // A list item that appears in a reduction clause of the innermost |
| 1426 | // enclosing worksharing or parallel construct may not be accessed in |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 1427 | // an explicit task. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1428 | DVar = |
| 1429 | Stack->hasInnermostDSA(FD, MatchesAnyClause(OMPC_reduction), |
| 1430 | [](OpenMPDirectiveKind K) -> bool { |
| 1431 | return isOpenMPParallelDirective(K) || |
| 1432 | isOpenMPWorksharingDirective(K) || |
| 1433 | isOpenMPTeamsDirective(K); |
| 1434 | }, |
| 1435 | false); |
| 1436 | if (DKind == OMPD_task && DVar.CKind == OMPC_reduction) { |
| 1437 | ErrorFound = true; |
| 1438 | SemaRef.Diag(ELoc, diag::err_omp_reduction_in_task); |
| 1439 | ReportOriginalDSA(SemaRef, Stack, FD, DVar); |
| 1440 | return; |
| 1441 | } |
| 1442 | |
| 1443 | // Define implicit data-sharing attributes for task. |
| 1444 | DVar = Stack->getImplicitDSA(FD, false); |
| 1445 | if (DKind == OMPD_task && DVar.CKind != OMPC_shared) |
| 1446 | ImplicitFirstprivate.push_back(E); |
| 1447 | } |
| 1448 | } |
| 1449 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1450 | void VisitOMPExecutableDirective(OMPExecutableDirective *S) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1451 | for (auto *C : S->clauses()) { |
| 1452 | // Skip analysis of arguments of implicitly defined firstprivate clause |
| 1453 | // for task directives. |
| 1454 | if (C && (!isa<OMPFirstprivateClause>(C) || C->getLocStart().isValid())) |
| 1455 | for (auto *CC : C->children()) { |
| 1456 | if (CC) |
| 1457 | Visit(CC); |
| 1458 | } |
| 1459 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1460 | } |
| 1461 | void VisitStmt(Stmt *S) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1462 | for (auto *C : S->children()) { |
| 1463 | if (C && !isa<OMPExecutableDirective>(C)) |
| 1464 | Visit(C); |
| 1465 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1466 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1467 | |
| 1468 | bool isErrorFound() { return ErrorFound; } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1469 | ArrayRef<Expr *> getImplicitFirstprivate() { return ImplicitFirstprivate; } |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1470 | llvm::DenseMap<ValueDecl *, Expr *> &getVarsWithInheritedDSA() { |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1471 | return VarsWithInheritedDSA; |
| 1472 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1473 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1474 | DSAAttrChecker(DSAStackTy *S, Sema &SemaRef, CapturedStmt *CS) |
| 1475 | : Stack(S), SemaRef(SemaRef), ErrorFound(false), CS(CS) {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1476 | }; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1477 | } // namespace |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1478 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1479 | void Sema::ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, Scope *CurScope) { |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1480 | switch (DKind) { |
| 1481 | case OMPD_parallel: { |
| 1482 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1483 | QualType KmpInt32PtrTy = |
| 1484 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1485 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1486 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1487 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1488 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1489 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1490 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1491 | Params); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1492 | break; |
| 1493 | } |
| 1494 | case OMPD_simd: { |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1495 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1496 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1497 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1498 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1499 | Params); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1500 | break; |
| 1501 | } |
| 1502 | case OMPD_for: { |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1503 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1504 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1505 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1506 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1507 | Params); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1508 | break; |
| 1509 | } |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1510 | case OMPD_for_simd: { |
| 1511 | Sema::CapturedParamNameType Params[] = { |
| 1512 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1513 | }; |
| 1514 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1515 | Params); |
| 1516 | break; |
| 1517 | } |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 1518 | case OMPD_sections: { |
| 1519 | Sema::CapturedParamNameType Params[] = { |
| 1520 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1521 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1522 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1523 | Params); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 1524 | break; |
| 1525 | } |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1526 | case OMPD_section: { |
| 1527 | Sema::CapturedParamNameType Params[] = { |
| 1528 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1529 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1530 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1531 | Params); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1532 | break; |
| 1533 | } |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 1534 | case OMPD_single: { |
| 1535 | Sema::CapturedParamNameType Params[] = { |
| 1536 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1537 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1538 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1539 | Params); |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 1540 | break; |
| 1541 | } |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1542 | case OMPD_master: { |
| 1543 | Sema::CapturedParamNameType Params[] = { |
| 1544 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1545 | }; |
| 1546 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1547 | Params); |
| 1548 | break; |
| 1549 | } |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1550 | case OMPD_critical: { |
| 1551 | Sema::CapturedParamNameType Params[] = { |
| 1552 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1553 | }; |
| 1554 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1555 | Params); |
| 1556 | break; |
| 1557 | } |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1558 | case OMPD_parallel_for: { |
| 1559 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1560 | QualType KmpInt32PtrTy = |
| 1561 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1562 | Sema::CapturedParamNameType Params[] = { |
| 1563 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1564 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1565 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1566 | }; |
| 1567 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1568 | Params); |
| 1569 | break; |
| 1570 | } |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1571 | case OMPD_parallel_for_simd: { |
| 1572 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1573 | QualType KmpInt32PtrTy = |
| 1574 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1575 | Sema::CapturedParamNameType Params[] = { |
| 1576 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1577 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1578 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1579 | }; |
| 1580 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1581 | Params); |
| 1582 | break; |
| 1583 | } |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1584 | case OMPD_parallel_sections: { |
Alexey Bataev | 68adb7d | 2015-04-14 03:29:22 +0000 | [diff] [blame] | 1585 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1586 | QualType KmpInt32PtrTy = |
| 1587 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1588 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | 68adb7d | 2015-04-14 03:29:22 +0000 | [diff] [blame] | 1589 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1590 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1591 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1592 | }; |
| 1593 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1594 | Params); |
| 1595 | break; |
| 1596 | } |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1597 | case OMPD_task: { |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1598 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 3ae88e2 | 2015-05-22 08:56:35 +0000 | [diff] [blame] | 1599 | QualType Args[] = {Context.VoidPtrTy.withConst().withRestrict()}; |
| 1600 | FunctionProtoType::ExtProtoInfo EPI; |
| 1601 | EPI.Variadic = true; |
| 1602 | QualType CopyFnType = Context.getFunctionType(Context.VoidTy, Args, EPI); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1603 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1604 | std::make_pair(".global_tid.", KmpInt32Ty), |
| 1605 | std::make_pair(".part_id.", KmpInt32Ty), |
Alexey Bataev | 3ae88e2 | 2015-05-22 08:56:35 +0000 | [diff] [blame] | 1606 | std::make_pair(".privates.", |
| 1607 | Context.VoidPtrTy.withConst().withRestrict()), |
| 1608 | std::make_pair( |
| 1609 | ".copy_fn.", |
| 1610 | Context.getPointerType(CopyFnType).withConst().withRestrict()), |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1611 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1612 | }; |
| 1613 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1614 | Params); |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1615 | // Mark this captured region as inlined, because we don't use outlined |
| 1616 | // function directly. |
| 1617 | getCurCapturedRegion()->TheCapturedDecl->addAttr( |
| 1618 | AlwaysInlineAttr::CreateImplicit( |
| 1619 | Context, AlwaysInlineAttr::Keyword_forceinline, SourceRange())); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1620 | break; |
| 1621 | } |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1622 | case OMPD_ordered: { |
| 1623 | Sema::CapturedParamNameType Params[] = { |
| 1624 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1625 | }; |
| 1626 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1627 | Params); |
| 1628 | break; |
| 1629 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1630 | case OMPD_atomic: { |
| 1631 | Sema::CapturedParamNameType Params[] = { |
| 1632 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1633 | }; |
| 1634 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1635 | Params); |
| 1636 | break; |
| 1637 | } |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 1638 | case OMPD_target_data: |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 1639 | case OMPD_target: |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 1640 | case OMPD_target_parallel: |
| 1641 | case OMPD_target_parallel_for: { |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1642 | Sema::CapturedParamNameType Params[] = { |
| 1643 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1644 | }; |
| 1645 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1646 | Params); |
| 1647 | break; |
| 1648 | } |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1649 | case OMPD_teams: { |
| 1650 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1651 | QualType KmpInt32PtrTy = |
| 1652 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1653 | Sema::CapturedParamNameType Params[] = { |
| 1654 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1655 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1656 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1657 | }; |
| 1658 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1659 | Params); |
| 1660 | break; |
| 1661 | } |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1662 | case OMPD_taskgroup: { |
| 1663 | Sema::CapturedParamNameType Params[] = { |
| 1664 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1665 | }; |
| 1666 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1667 | Params); |
| 1668 | break; |
| 1669 | } |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1670 | case OMPD_taskloop: { |
| 1671 | Sema::CapturedParamNameType Params[] = { |
| 1672 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1673 | }; |
| 1674 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1675 | Params); |
| 1676 | break; |
| 1677 | } |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1678 | case OMPD_taskloop_simd: { |
| 1679 | Sema::CapturedParamNameType Params[] = { |
| 1680 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1681 | }; |
| 1682 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1683 | Params); |
| 1684 | break; |
| 1685 | } |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1686 | case OMPD_distribute: { |
| 1687 | Sema::CapturedParamNameType Params[] = { |
| 1688 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1689 | }; |
| 1690 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1691 | Params); |
| 1692 | break; |
| 1693 | } |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1694 | case OMPD_threadprivate: |
Alexey Bataev | ee9af45 | 2014-11-21 11:33:46 +0000 | [diff] [blame] | 1695 | case OMPD_taskyield: |
| 1696 | case OMPD_barrier: |
| 1697 | case OMPD_taskwait: |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1698 | case OMPD_cancellation_point: |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1699 | case OMPD_cancel: |
Alexey Bataev | ee9af45 | 2014-11-21 11:33:46 +0000 | [diff] [blame] | 1700 | case OMPD_flush: |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1701 | case OMPD_target_enter_data: |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1702 | case OMPD_target_exit_data: |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 1703 | case OMPD_declare_reduction: |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1704 | llvm_unreachable("OpenMP Directive is not allowed"); |
| 1705 | case OMPD_unknown: |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1706 | llvm_unreachable("Unknown OpenMP directive"); |
| 1707 | } |
| 1708 | } |
| 1709 | |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1710 | static OMPCapturedExprDecl *buildCaptureDecl(Sema &S, IdentifierInfo *Id, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 1711 | Expr *CaptureExpr, bool WithInit, |
| 1712 | bool AsExpression) { |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 1713 | assert(CaptureExpr); |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 1714 | ASTContext &C = S.getASTContext(); |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 1715 | Expr *Init = AsExpression ? CaptureExpr : CaptureExpr->IgnoreImpCasts(); |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 1716 | QualType Ty = Init->getType(); |
| 1717 | if (CaptureExpr->getObjectKind() == OK_Ordinary && CaptureExpr->isGLValue()) { |
| 1718 | if (S.getLangOpts().CPlusPlus) |
| 1719 | Ty = C.getLValueReferenceType(Ty); |
| 1720 | else { |
| 1721 | Ty = C.getPointerType(Ty); |
| 1722 | ExprResult Res = |
| 1723 | S.CreateBuiltinUnaryOp(CaptureExpr->getExprLoc(), UO_AddrOf, Init); |
| 1724 | if (!Res.isUsable()) |
| 1725 | return nullptr; |
| 1726 | Init = Res.get(); |
| 1727 | } |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 1728 | WithInit = true; |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 1729 | } |
| 1730 | auto *CED = OMPCapturedExprDecl::Create(C, S.CurContext, Id, Ty); |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 1731 | if (!WithInit) |
| 1732 | CED->addAttr(OMPCaptureNoInitAttr::CreateImplicit(C, SourceRange())); |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 1733 | S.CurContext->addHiddenDecl(CED); |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 1734 | S.AddInitializerToDecl(CED, Init, /*DirectInit=*/false, |
| 1735 | /*TypeMayContainAuto=*/true); |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1736 | return CED; |
| 1737 | } |
| 1738 | |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 1739 | static DeclRefExpr *buildCapture(Sema &S, ValueDecl *D, Expr *CaptureExpr, |
| 1740 | bool WithInit) { |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 1741 | OMPCapturedExprDecl *CD; |
| 1742 | if (auto *VD = S.IsOpenMPCapturedDecl(D)) |
| 1743 | CD = cast<OMPCapturedExprDecl>(VD); |
| 1744 | else |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 1745 | CD = buildCaptureDecl(S, D->getIdentifier(), CaptureExpr, WithInit, |
| 1746 | /*AsExpression=*/false); |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1747 | return buildDeclRefExpr(S, CD, CD->getType().getNonReferenceType(), |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 1748 | CaptureExpr->getExprLoc()); |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1749 | } |
| 1750 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 1751 | static ExprResult buildCapture(Sema &S, Expr *CaptureExpr, DeclRefExpr *&Ref) { |
| 1752 | if (!Ref) { |
| 1753 | auto *CD = |
| 1754 | buildCaptureDecl(S, &S.getASTContext().Idents.get(".capture_expr."), |
| 1755 | CaptureExpr, /*WithInit=*/true, /*AsExpression=*/true); |
| 1756 | Ref = buildDeclRefExpr(S, CD, CD->getType().getNonReferenceType(), |
| 1757 | CaptureExpr->getExprLoc()); |
| 1758 | } |
| 1759 | ExprResult Res = Ref; |
| 1760 | if (!S.getLangOpts().CPlusPlus && |
| 1761 | CaptureExpr->getObjectKind() == OK_Ordinary && CaptureExpr->isGLValue() && |
| 1762 | Ref->getType()->isPointerType()) |
| 1763 | Res = S.CreateBuiltinUnaryOp(CaptureExpr->getExprLoc(), UO_Deref, Ref); |
| 1764 | if (!Res.isUsable()) |
| 1765 | return ExprError(); |
| 1766 | return CaptureExpr->isGLValue() ? Res : S.DefaultLvalueConversion(Res.get()); |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 1767 | } |
| 1768 | |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1769 | StmtResult Sema::ActOnOpenMPRegionEnd(StmtResult S, |
| 1770 | ArrayRef<OMPClause *> Clauses) { |
| 1771 | if (!S.isUsable()) { |
| 1772 | ActOnCapturedRegionError(); |
| 1773 | return StmtError(); |
| 1774 | } |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1775 | |
| 1776 | OMPOrderedClause *OC = nullptr; |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1777 | OMPScheduleClause *SC = nullptr; |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1778 | SmallVector<OMPLinearClause *, 4> LCs; |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1779 | // This is required for proper codegen. |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1780 | for (auto *Clause : Clauses) { |
Alexey Bataev | 16dc7b6 | 2015-05-20 03:46:04 +0000 | [diff] [blame] | 1781 | if (isOpenMPPrivate(Clause->getClauseKind()) || |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 1782 | Clause->getClauseKind() == OMPC_copyprivate || |
| 1783 | (getLangOpts().OpenMPUseTLS && |
| 1784 | getASTContext().getTargetInfo().isTLSSupported() && |
| 1785 | Clause->getClauseKind() == OMPC_copyin)) { |
| 1786 | DSAStack->setForceVarCapturing(Clause->getClauseKind() == OMPC_copyin); |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1787 | // Mark all variables in private list clauses as used in inner region. |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1788 | for (auto *VarRef : Clause->children()) { |
| 1789 | if (auto *E = cast_or_null<Expr>(VarRef)) { |
Alexey Bataev | 8bf6b3e | 2015-04-02 13:07:08 +0000 | [diff] [blame] | 1790 | MarkDeclarationsReferencedInExpr(E); |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1791 | } |
| 1792 | } |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 1793 | DSAStack->setForceVarCapturing(/*V=*/false); |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1794 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective())) { |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1795 | // Mark all variables in private list clauses as used in inner region. |
| 1796 | // Required for proper codegen of combined directives. |
| 1797 | // TODO: add processing for other clauses. |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1798 | if (auto *C = OMPClauseWithPreInit::get(Clause)) { |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 1799 | if (auto *DS = cast_or_null<DeclStmt>(C->getPreInitStmt())) { |
| 1800 | for (auto *D : DS->decls()) |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1801 | MarkVariableReferenced(D->getLocation(), cast<VarDecl>(D)); |
| 1802 | } |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 1803 | } |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 1804 | if (auto *C = OMPClauseWithPostUpdate::get(Clause)) { |
| 1805 | if (auto *E = C->getPostUpdateExpr()) |
| 1806 | MarkDeclarationsReferencedInExpr(E); |
| 1807 | } |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1808 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1809 | if (Clause->getClauseKind() == OMPC_schedule) |
| 1810 | SC = cast<OMPScheduleClause>(Clause); |
| 1811 | else if (Clause->getClauseKind() == OMPC_ordered) |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1812 | OC = cast<OMPOrderedClause>(Clause); |
| 1813 | else if (Clause->getClauseKind() == OMPC_linear) |
| 1814 | LCs.push_back(cast<OMPLinearClause>(Clause)); |
| 1815 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1816 | bool ErrorFound = false; |
| 1817 | // OpenMP, 2.7.1 Loop Construct, Restrictions |
| 1818 | // The nonmonotonic modifier cannot be specified if an ordered clause is |
| 1819 | // specified. |
| 1820 | if (SC && |
| 1821 | (SC->getFirstScheduleModifier() == OMPC_SCHEDULE_MODIFIER_nonmonotonic || |
| 1822 | SC->getSecondScheduleModifier() == |
| 1823 | OMPC_SCHEDULE_MODIFIER_nonmonotonic) && |
| 1824 | OC) { |
| 1825 | Diag(SC->getFirstScheduleModifier() == OMPC_SCHEDULE_MODIFIER_nonmonotonic |
| 1826 | ? SC->getFirstScheduleModifierLoc() |
| 1827 | : SC->getSecondScheduleModifierLoc(), |
| 1828 | diag::err_omp_schedule_nonmonotonic_ordered) |
| 1829 | << SourceRange(OC->getLocStart(), OC->getLocEnd()); |
| 1830 | ErrorFound = true; |
| 1831 | } |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1832 | if (!LCs.empty() && OC && OC->getNumForLoops()) { |
| 1833 | for (auto *C : LCs) { |
| 1834 | Diag(C->getLocStart(), diag::err_omp_linear_ordered) |
| 1835 | << SourceRange(OC->getLocStart(), OC->getLocEnd()); |
| 1836 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1837 | ErrorFound = true; |
| 1838 | } |
Alexey Bataev | 113438c | 2015-12-30 12:06:23 +0000 | [diff] [blame] | 1839 | if (isOpenMPWorksharingDirective(DSAStack->getCurrentDirective()) && |
| 1840 | isOpenMPSimdDirective(DSAStack->getCurrentDirective()) && OC && |
| 1841 | OC->getNumForLoops()) { |
| 1842 | Diag(OC->getLocStart(), diag::err_omp_ordered_simd) |
| 1843 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 1844 | ErrorFound = true; |
| 1845 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1846 | if (ErrorFound) { |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1847 | ActOnCapturedRegionError(); |
| 1848 | return StmtError(); |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1849 | } |
| 1850 | return ActOnCapturedRegionEnd(S.get()); |
| 1851 | } |
| 1852 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1853 | static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, |
| 1854 | OpenMPDirectiveKind CurrentRegion, |
| 1855 | const DeclarationNameInfo &CurrentName, |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1856 | OpenMPDirectiveKind CancelRegion, |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1857 | SourceLocation StartLoc) { |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1858 | // Allowed nesting of constructs |
| 1859 | // +------------------+-----------------+------------------------------------+ |
| 1860 | // | Parent directive | Child directive | Closely (!), No-Closely(+), Both(*)| |
| 1861 | // +------------------+-----------------+------------------------------------+ |
| 1862 | // | parallel | parallel | * | |
| 1863 | // | parallel | for | * | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1864 | // | parallel | for simd | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1865 | // | parallel | master | * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1866 | // | parallel | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1867 | // | parallel | simd | * | |
| 1868 | // | parallel | sections | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1869 | // | parallel | section | + | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1870 | // | parallel | single | * | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1871 | // | parallel | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1872 | // | parallel |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1873 | // | parallel |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1874 | // | parallel | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1875 | // | parallel | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1876 | // | parallel | barrier | * | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1877 | // | parallel | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1878 | // | parallel | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1879 | // | parallel | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1880 | // | parallel | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1881 | // | parallel | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1882 | // | parallel | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 1883 | // | parallel | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 1884 | // | parallel | target parallel | * | |
| 1885 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1886 | // | parallel | target enter | * | |
| 1887 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1888 | // | parallel | target exit | * | |
| 1889 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1890 | // | parallel | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1891 | // | parallel | cancellation | | |
| 1892 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1893 | // | parallel | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1894 | // | parallel | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1895 | // | parallel | taskloop simd | * | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1896 | // | parallel | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1897 | // +------------------+-----------------+------------------------------------+ |
| 1898 | // | for | parallel | * | |
| 1899 | // | for | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1900 | // | for | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1901 | // | for | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1902 | // | for | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1903 | // | for | simd | * | |
| 1904 | // | for | sections | + | |
| 1905 | // | for | section | + | |
| 1906 | // | for | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1907 | // | for | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1908 | // | for |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1909 | // | for |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1910 | // | for | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1911 | // | for | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1912 | // | for | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1913 | // | for | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1914 | // | for | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1915 | // | for | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1916 | // | for | ordered | * (if construct is ordered) | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1917 | // | for | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1918 | // | for | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 1919 | // | for | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 1920 | // | for | target parallel | * | |
| 1921 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1922 | // | for | target enter | * | |
| 1923 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1924 | // | for | target exit | * | |
| 1925 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1926 | // | for | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1927 | // | for | cancellation | | |
| 1928 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1929 | // | for | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1930 | // | for | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1931 | // | for | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1932 | // | for | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1933 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1934 | // | master | parallel | * | |
| 1935 | // | master | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1936 | // | master | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1937 | // | master | master | * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1938 | // | master | critical | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1939 | // | master | simd | * | |
| 1940 | // | master | sections | + | |
| 1941 | // | master | section | + | |
| 1942 | // | master | single | + | |
| 1943 | // | master | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1944 | // | master |parallel for simd| * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1945 | // | master |parallel sections| * | |
| 1946 | // | master | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1947 | // | master | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1948 | // | master | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1949 | // | master | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1950 | // | master | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1951 | // | master | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1952 | // | master | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1953 | // | master | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1954 | // | master | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 1955 | // | master | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 1956 | // | master | target parallel | * | |
| 1957 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1958 | // | master | target enter | * | |
| 1959 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1960 | // | master | target exit | * | |
| 1961 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1962 | // | master | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1963 | // | master | cancellation | | |
| 1964 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1965 | // | master | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1966 | // | master | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1967 | // | master | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1968 | // | master | distribute | | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1969 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1970 | // | critical | parallel | * | |
| 1971 | // | critical | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1972 | // | critical | for simd | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1973 | // | critical | master | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1974 | // | critical | critical | * (should have different names) | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1975 | // | critical | simd | * | |
| 1976 | // | critical | sections | + | |
| 1977 | // | critical | section | + | |
| 1978 | // | critical | single | + | |
| 1979 | // | critical | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1980 | // | critical |parallel for simd| * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1981 | // | critical |parallel sections| * | |
| 1982 | // | critical | task | * | |
| 1983 | // | critical | taskyield | * | |
| 1984 | // | critical | barrier | + | |
| 1985 | // | critical | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1986 | // | critical | taskgroup | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1987 | // | critical | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1988 | // | critical | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1989 | // | critical | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 1990 | // | critical | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 1991 | // | critical | target parallel | * | |
| 1992 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1993 | // | critical | target enter | * | |
| 1994 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1995 | // | critical | target exit | * | |
| 1996 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1997 | // | critical | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1998 | // | critical | cancellation | | |
| 1999 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2000 | // | critical | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2001 | // | critical | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2002 | // | critical | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2003 | // | critical | distribute | | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2004 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2005 | // | simd | parallel | | |
| 2006 | // | simd | for | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2007 | // | simd | for simd | | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2008 | // | simd | master | | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2009 | // | simd | critical | | |
Alexey Bataev | 1f09221 | 2016-02-02 04:59:52 +0000 | [diff] [blame] | 2010 | // | simd | simd | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2011 | // | simd | sections | | |
| 2012 | // | simd | section | | |
| 2013 | // | simd | single | | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2014 | // | simd | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2015 | // | simd |parallel for simd| | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2016 | // | simd |parallel sections| | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2017 | // | simd | task | | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2018 | // | simd | taskyield | | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2019 | // | simd | barrier | | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2020 | // | simd | taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2021 | // | simd | taskgroup | | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2022 | // | simd | flush | | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2023 | // | simd | ordered | + (with simd clause) | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2024 | // | simd | atomic | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2025 | // | simd | target | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2026 | // | simd | target parallel | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2027 | // | simd | target parallel | | |
| 2028 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2029 | // | simd | target enter | | |
| 2030 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2031 | // | simd | target exit | | |
| 2032 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2033 | // | simd | teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2034 | // | simd | cancellation | | |
| 2035 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2036 | // | simd | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2037 | // | simd | taskloop | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2038 | // | simd | taskloop simd | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2039 | // | simd | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2040 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2041 | // | for simd | parallel | | |
| 2042 | // | for simd | for | | |
| 2043 | // | for simd | for simd | | |
| 2044 | // | for simd | master | | |
| 2045 | // | for simd | critical | | |
Alexey Bataev | 1f09221 | 2016-02-02 04:59:52 +0000 | [diff] [blame] | 2046 | // | for simd | simd | * | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2047 | // | for simd | sections | | |
| 2048 | // | for simd | section | | |
| 2049 | // | for simd | single | | |
| 2050 | // | for simd | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2051 | // | for simd |parallel for simd| | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2052 | // | for simd |parallel sections| | |
| 2053 | // | for simd | task | | |
| 2054 | // | for simd | taskyield | | |
| 2055 | // | for simd | barrier | | |
| 2056 | // | for simd | taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2057 | // | for simd | taskgroup | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2058 | // | for simd | flush | | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2059 | // | for simd | ordered | + (with simd clause) | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2060 | // | for simd | atomic | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2061 | // | for simd | target | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2062 | // | for simd | target parallel | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2063 | // | for simd | target parallel | | |
| 2064 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2065 | // | for simd | target enter | | |
| 2066 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2067 | // | for simd | target exit | | |
| 2068 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2069 | // | for simd | teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2070 | // | for simd | cancellation | | |
| 2071 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2072 | // | for simd | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2073 | // | for simd | taskloop | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2074 | // | for simd | taskloop simd | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2075 | // | for simd | distribute | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2076 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2077 | // | parallel for simd| parallel | | |
| 2078 | // | parallel for simd| for | | |
| 2079 | // | parallel for simd| for simd | | |
| 2080 | // | parallel for simd| master | | |
| 2081 | // | parallel for simd| critical | | |
Alexey Bataev | 1f09221 | 2016-02-02 04:59:52 +0000 | [diff] [blame] | 2082 | // | parallel for simd| simd | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2083 | // | parallel for simd| sections | | |
| 2084 | // | parallel for simd| section | | |
| 2085 | // | parallel for simd| single | | |
| 2086 | // | parallel for simd| parallel for | | |
| 2087 | // | parallel for simd|parallel for simd| | |
| 2088 | // | parallel for simd|parallel sections| | |
| 2089 | // | parallel for simd| task | | |
| 2090 | // | parallel for simd| taskyield | | |
| 2091 | // | parallel for simd| barrier | | |
| 2092 | // | parallel for simd| taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2093 | // | parallel for simd| taskgroup | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2094 | // | parallel for simd| flush | | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2095 | // | parallel for simd| ordered | + (with simd clause) | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2096 | // | parallel for simd| atomic | | |
| 2097 | // | parallel for simd| target | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2098 | // | parallel for simd| target parallel | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2099 | // | parallel for simd| target parallel | | |
| 2100 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2101 | // | parallel for simd| target enter | | |
| 2102 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2103 | // | parallel for simd| target exit | | |
| 2104 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2105 | // | parallel for simd| teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2106 | // | parallel for simd| cancellation | | |
| 2107 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2108 | // | parallel for simd| cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2109 | // | parallel for simd| taskloop | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2110 | // | parallel for simd| taskloop simd | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2111 | // | parallel for simd| distribute | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2112 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2113 | // | sections | parallel | * | |
| 2114 | // | sections | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2115 | // | sections | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2116 | // | sections | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2117 | // | sections | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2118 | // | sections | simd | * | |
| 2119 | // | sections | sections | + | |
| 2120 | // | sections | section | * | |
| 2121 | // | sections | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2122 | // | sections | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2123 | // | sections |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2124 | // | sections |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2125 | // | sections | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2126 | // | sections | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2127 | // | sections | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2128 | // | sections | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2129 | // | sections | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2130 | // | sections | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2131 | // | sections | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2132 | // | sections | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2133 | // | sections | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2134 | // | sections | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2135 | // | sections | target parallel | * | |
| 2136 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2137 | // | sections | target enter | * | |
| 2138 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2139 | // | sections | target exit | * | |
| 2140 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2141 | // | sections | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2142 | // | sections | cancellation | | |
| 2143 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2144 | // | sections | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2145 | // | sections | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2146 | // | sections | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2147 | // | sections | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2148 | // +------------------+-----------------+------------------------------------+ |
| 2149 | // | section | parallel | * | |
| 2150 | // | section | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2151 | // | section | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2152 | // | section | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2153 | // | section | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2154 | // | section | simd | * | |
| 2155 | // | section | sections | + | |
| 2156 | // | section | section | + | |
| 2157 | // | section | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2158 | // | section | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2159 | // | section |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2160 | // | section |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2161 | // | section | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2162 | // | section | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2163 | // | section | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2164 | // | section | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2165 | // | section | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2166 | // | section | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2167 | // | section | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2168 | // | section | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2169 | // | section | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2170 | // | section | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2171 | // | section | target parallel | * | |
| 2172 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2173 | // | section | target enter | * | |
| 2174 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2175 | // | section | target exit | * | |
| 2176 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2177 | // | section | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2178 | // | section | cancellation | | |
| 2179 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2180 | // | section | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2181 | // | section | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2182 | // | section | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2183 | // | section | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2184 | // +------------------+-----------------+------------------------------------+ |
| 2185 | // | single | parallel | * | |
| 2186 | // | single | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2187 | // | single | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2188 | // | single | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2189 | // | single | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2190 | // | single | simd | * | |
| 2191 | // | single | sections | + | |
| 2192 | // | single | section | + | |
| 2193 | // | single | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2194 | // | single | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2195 | // | single |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2196 | // | single |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2197 | // | single | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2198 | // | single | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2199 | // | single | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2200 | // | single | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2201 | // | single | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2202 | // | single | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2203 | // | single | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2204 | // | single | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2205 | // | single | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2206 | // | single | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2207 | // | single | target parallel | * | |
| 2208 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2209 | // | single | target enter | * | |
| 2210 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2211 | // | single | target exit | * | |
| 2212 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2213 | // | single | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2214 | // | single | cancellation | | |
| 2215 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2216 | // | single | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2217 | // | single | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2218 | // | single | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2219 | // | single | distribute | | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2220 | // +------------------+-----------------+------------------------------------+ |
| 2221 | // | parallel for | parallel | * | |
| 2222 | // | parallel for | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2223 | // | parallel for | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2224 | // | parallel for | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2225 | // | parallel for | critical | * | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2226 | // | parallel for | simd | * | |
| 2227 | // | parallel for | sections | + | |
| 2228 | // | parallel for | section | + | |
| 2229 | // | parallel for | single | + | |
| 2230 | // | parallel for | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2231 | // | parallel for |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2232 | // | parallel for |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2233 | // | parallel for | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2234 | // | parallel for | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2235 | // | parallel for | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2236 | // | parallel for | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2237 | // | parallel for | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2238 | // | parallel for | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2239 | // | parallel for | ordered | * (if construct is ordered) | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2240 | // | parallel for | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2241 | // | parallel for | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2242 | // | parallel for | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2243 | // | parallel for | target parallel | * | |
| 2244 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2245 | // | parallel for | target enter | * | |
| 2246 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2247 | // | parallel for | target exit | * | |
| 2248 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2249 | // | parallel for | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2250 | // | parallel for | cancellation | | |
| 2251 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2252 | // | parallel for | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2253 | // | parallel for | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2254 | // | parallel for | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2255 | // | parallel for | distribute | | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2256 | // +------------------+-----------------+------------------------------------+ |
| 2257 | // | parallel sections| parallel | * | |
| 2258 | // | parallel sections| for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2259 | // | parallel sections| for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2260 | // | parallel sections| master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2261 | // | parallel sections| critical | + | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2262 | // | parallel sections| simd | * | |
| 2263 | // | parallel sections| sections | + | |
| 2264 | // | parallel sections| section | * | |
| 2265 | // | parallel sections| single | + | |
| 2266 | // | parallel sections| parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2267 | // | parallel sections|parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2268 | // | parallel sections|parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2269 | // | parallel sections| task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2270 | // | parallel sections| taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2271 | // | parallel sections| barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2272 | // | parallel sections| taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2273 | // | parallel sections| taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2274 | // | parallel sections| flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2275 | // | parallel sections| ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2276 | // | parallel sections| atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2277 | // | parallel sections| target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2278 | // | parallel sections| target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2279 | // | parallel sections| target parallel | * | |
| 2280 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2281 | // | parallel sections| target enter | * | |
| 2282 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2283 | // | parallel sections| target exit | * | |
| 2284 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2285 | // | parallel sections| teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2286 | // | parallel sections| cancellation | | |
| 2287 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2288 | // | parallel sections| cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2289 | // | parallel sections| taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2290 | // | parallel sections| taskloop simd | * | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2291 | // | parallel sections| distribute | | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2292 | // +------------------+-----------------+------------------------------------+ |
| 2293 | // | task | parallel | * | |
| 2294 | // | task | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2295 | // | task | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2296 | // | task | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2297 | // | task | critical | * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2298 | // | task | simd | * | |
| 2299 | // | task | sections | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2300 | // | task | section | + | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2301 | // | task | single | + | |
| 2302 | // | task | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2303 | // | task |parallel for simd| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2304 | // | task |parallel sections| * | |
| 2305 | // | task | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2306 | // | task | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2307 | // | task | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2308 | // | task | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2309 | // | task | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2310 | // | task | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2311 | // | task | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2312 | // | task | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2313 | // | task | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2314 | // | task | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2315 | // | task | target parallel | * | |
| 2316 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2317 | // | task | target enter | * | |
| 2318 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2319 | // | task | target exit | * | |
| 2320 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2321 | // | task | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2322 | // | task | cancellation | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2323 | // | | point | ! | |
| 2324 | // | task | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2325 | // | task | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2326 | // | task | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2327 | // | task | distribute | | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2328 | // +------------------+-----------------+------------------------------------+ |
| 2329 | // | ordered | parallel | * | |
| 2330 | // | ordered | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2331 | // | ordered | for simd | + | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2332 | // | ordered | master | * | |
| 2333 | // | ordered | critical | * | |
| 2334 | // | ordered | simd | * | |
| 2335 | // | ordered | sections | + | |
| 2336 | // | ordered | section | + | |
| 2337 | // | ordered | single | + | |
| 2338 | // | ordered | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2339 | // | ordered |parallel for simd| * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2340 | // | ordered |parallel sections| * | |
| 2341 | // | ordered | task | * | |
| 2342 | // | ordered | taskyield | * | |
| 2343 | // | ordered | barrier | + | |
| 2344 | // | ordered | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2345 | // | ordered | taskgroup | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2346 | // | ordered | flush | * | |
| 2347 | // | ordered | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2348 | // | ordered | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2349 | // | ordered | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2350 | // | ordered | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2351 | // | ordered | target parallel | * | |
| 2352 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2353 | // | ordered | target enter | * | |
| 2354 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2355 | // | ordered | target exit | * | |
| 2356 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2357 | // | ordered | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2358 | // | ordered | cancellation | | |
| 2359 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2360 | // | ordered | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2361 | // | ordered | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2362 | // | ordered | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2363 | // | ordered | distribute | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2364 | // +------------------+-----------------+------------------------------------+ |
| 2365 | // | atomic | parallel | | |
| 2366 | // | atomic | for | | |
| 2367 | // | atomic | for simd | | |
| 2368 | // | atomic | master | | |
| 2369 | // | atomic | critical | | |
| 2370 | // | atomic | simd | | |
| 2371 | // | atomic | sections | | |
| 2372 | // | atomic | section | | |
| 2373 | // | atomic | single | | |
| 2374 | // | atomic | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2375 | // | atomic |parallel for simd| | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2376 | // | atomic |parallel sections| | |
| 2377 | // | atomic | task | | |
| 2378 | // | atomic | taskyield | | |
| 2379 | // | atomic | barrier | | |
| 2380 | // | atomic | taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2381 | // | atomic | taskgroup | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2382 | // | atomic | flush | | |
| 2383 | // | atomic | ordered | | |
| 2384 | // | atomic | atomic | | |
| 2385 | // | atomic | target | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2386 | // | atomic | target parallel | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2387 | // | atomic | target parallel | | |
| 2388 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2389 | // | atomic | target enter | | |
| 2390 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2391 | // | atomic | target exit | | |
| 2392 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2393 | // | atomic | teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2394 | // | atomic | cancellation | | |
| 2395 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2396 | // | atomic | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2397 | // | atomic | taskloop | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2398 | // | atomic | taskloop simd | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2399 | // | atomic | distribute | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2400 | // +------------------+-----------------+------------------------------------+ |
| 2401 | // | target | parallel | * | |
| 2402 | // | target | for | * | |
| 2403 | // | target | for simd | * | |
| 2404 | // | target | master | * | |
| 2405 | // | target | critical | * | |
| 2406 | // | target | simd | * | |
| 2407 | // | target | sections | * | |
| 2408 | // | target | section | * | |
| 2409 | // | target | single | * | |
| 2410 | // | target | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2411 | // | target |parallel for simd| * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2412 | // | target |parallel sections| * | |
| 2413 | // | target | task | * | |
| 2414 | // | target | taskyield | * | |
| 2415 | // | target | barrier | * | |
| 2416 | // | target | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2417 | // | target | taskgroup | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2418 | // | target | flush | * | |
| 2419 | // | target | ordered | * | |
| 2420 | // | target | atomic | * | |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2421 | // | target | target | | |
| 2422 | // | target | target parallel | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2423 | // | target | target parallel | | |
| 2424 | // | | for | | |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2425 | // | target | target enter | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2426 | // | | data | | |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2427 | // | target | target exit | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2428 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2429 | // | target | teams | * | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2430 | // | target | cancellation | | |
| 2431 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2432 | // | target | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2433 | // | target | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2434 | // | target | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2435 | // | target | distribute | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2436 | // +------------------+-----------------+------------------------------------+ |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2437 | // | target parallel | parallel | * | |
| 2438 | // | target parallel | for | * | |
| 2439 | // | target parallel | for simd | * | |
| 2440 | // | target parallel | master | * | |
| 2441 | // | target parallel | critical | * | |
| 2442 | // | target parallel | simd | * | |
| 2443 | // | target parallel | sections | * | |
| 2444 | // | target parallel | section | * | |
| 2445 | // | target parallel | single | * | |
| 2446 | // | target parallel | parallel for | * | |
| 2447 | // | target parallel |parallel for simd| * | |
| 2448 | // | target parallel |parallel sections| * | |
| 2449 | // | target parallel | task | * | |
| 2450 | // | target parallel | taskyield | * | |
| 2451 | // | target parallel | barrier | * | |
| 2452 | // | target parallel | taskwait | * | |
| 2453 | // | target parallel | taskgroup | * | |
| 2454 | // | target parallel | flush | * | |
| 2455 | // | target parallel | ordered | * | |
| 2456 | // | target parallel | atomic | * | |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2457 | // | target parallel | target | | |
| 2458 | // | target parallel | target parallel | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2459 | // | target parallel | target parallel | | |
| 2460 | // | | for | | |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2461 | // | target parallel | target enter | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2462 | // | | data | | |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2463 | // | target parallel | target exit | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2464 | // | | data | | |
| 2465 | // | target parallel | teams | | |
| 2466 | // | target parallel | cancellation | | |
| 2467 | // | | point | ! | |
| 2468 | // | target parallel | cancel | ! | |
| 2469 | // | target parallel | taskloop | * | |
| 2470 | // | target parallel | taskloop simd | * | |
| 2471 | // | target parallel | distribute | | |
| 2472 | // +------------------+-----------------+------------------------------------+ |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2473 | // | target parallel | parallel | * | |
| 2474 | // | for | | | |
| 2475 | // | target parallel | for | * | |
| 2476 | // | for | | | |
| 2477 | // | target parallel | for simd | * | |
| 2478 | // | for | | | |
| 2479 | // | target parallel | master | * | |
| 2480 | // | for | | | |
| 2481 | // | target parallel | critical | * | |
| 2482 | // | for | | | |
| 2483 | // | target parallel | simd | * | |
| 2484 | // | for | | | |
| 2485 | // | target parallel | sections | * | |
| 2486 | // | for | | | |
| 2487 | // | target parallel | section | * | |
| 2488 | // | for | | | |
| 2489 | // | target parallel | single | * | |
| 2490 | // | for | | | |
| 2491 | // | target parallel | parallel for | * | |
| 2492 | // | for | | | |
| 2493 | // | target parallel |parallel for simd| * | |
| 2494 | // | for | | | |
| 2495 | // | target parallel |parallel sections| * | |
| 2496 | // | for | | | |
| 2497 | // | target parallel | task | * | |
| 2498 | // | for | | | |
| 2499 | // | target parallel | taskyield | * | |
| 2500 | // | for | | | |
| 2501 | // | target parallel | barrier | * | |
| 2502 | // | for | | | |
| 2503 | // | target parallel | taskwait | * | |
| 2504 | // | for | | | |
| 2505 | // | target parallel | taskgroup | * | |
| 2506 | // | for | | | |
| 2507 | // | target parallel | flush | * | |
| 2508 | // | for | | | |
| 2509 | // | target parallel | ordered | * | |
| 2510 | // | for | | | |
| 2511 | // | target parallel | atomic | * | |
| 2512 | // | for | | | |
| 2513 | // | target parallel | target | | |
| 2514 | // | for | | | |
| 2515 | // | target parallel | target parallel | | |
| 2516 | // | for | | | |
| 2517 | // | target parallel | target parallel | | |
| 2518 | // | for | for | | |
| 2519 | // | target parallel | target enter | | |
| 2520 | // | for | data | | |
| 2521 | // | target parallel | target exit | | |
| 2522 | // | for | data | | |
| 2523 | // | target parallel | teams | | |
| 2524 | // | for | | | |
| 2525 | // | target parallel | cancellation | | |
| 2526 | // | for | point | ! | |
| 2527 | // | target parallel | cancel | ! | |
| 2528 | // | for | | | |
| 2529 | // | target parallel | taskloop | * | |
| 2530 | // | for | | | |
| 2531 | // | target parallel | taskloop simd | * | |
| 2532 | // | for | | | |
| 2533 | // | target parallel | distribute | | |
| 2534 | // | for | | | |
| 2535 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2536 | // | teams | parallel | * | |
| 2537 | // | teams | for | + | |
| 2538 | // | teams | for simd | + | |
| 2539 | // | teams | master | + | |
| 2540 | // | teams | critical | + | |
| 2541 | // | teams | simd | + | |
| 2542 | // | teams | sections | + | |
| 2543 | // | teams | section | + | |
| 2544 | // | teams | single | + | |
| 2545 | // | teams | parallel for | * | |
| 2546 | // | teams |parallel for simd| * | |
| 2547 | // | teams |parallel sections| * | |
| 2548 | // | teams | task | + | |
| 2549 | // | teams | taskyield | + | |
| 2550 | // | teams | barrier | + | |
| 2551 | // | teams | taskwait | + | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2552 | // | teams | taskgroup | + | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2553 | // | teams | flush | + | |
| 2554 | // | teams | ordered | + | |
| 2555 | // | teams | atomic | + | |
| 2556 | // | teams | target | + | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2557 | // | teams | target parallel | + | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2558 | // | teams | target parallel | + | |
| 2559 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2560 | // | teams | target enter | + | |
| 2561 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2562 | // | teams | target exit | + | |
| 2563 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2564 | // | teams | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2565 | // | teams | cancellation | | |
| 2566 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2567 | // | teams | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2568 | // | teams | taskloop | + | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2569 | // | teams | taskloop simd | + | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2570 | // | teams | distribute | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2571 | // +------------------+-----------------+------------------------------------+ |
| 2572 | // | taskloop | parallel | * | |
| 2573 | // | taskloop | for | + | |
| 2574 | // | taskloop | for simd | + | |
| 2575 | // | taskloop | master | + | |
| 2576 | // | taskloop | critical | * | |
| 2577 | // | taskloop | simd | * | |
| 2578 | // | taskloop | sections | + | |
| 2579 | // | taskloop | section | + | |
| 2580 | // | taskloop | single | + | |
| 2581 | // | taskloop | parallel for | * | |
| 2582 | // | taskloop |parallel for simd| * | |
| 2583 | // | taskloop |parallel sections| * | |
| 2584 | // | taskloop | task | * | |
| 2585 | // | taskloop | taskyield | * | |
| 2586 | // | taskloop | barrier | + | |
| 2587 | // | taskloop | taskwait | * | |
| 2588 | // | taskloop | taskgroup | * | |
| 2589 | // | taskloop | flush | * | |
| 2590 | // | taskloop | ordered | + | |
| 2591 | // | taskloop | atomic | * | |
| 2592 | // | taskloop | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2593 | // | taskloop | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2594 | // | taskloop | target parallel | * | |
| 2595 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2596 | // | taskloop | target enter | * | |
| 2597 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2598 | // | taskloop | target exit | * | |
| 2599 | // | | data | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2600 | // | taskloop | teams | + | |
| 2601 | // | taskloop | cancellation | | |
| 2602 | // | | point | | |
| 2603 | // | taskloop | cancel | | |
| 2604 | // | taskloop | taskloop | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2605 | // | taskloop | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2606 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2607 | // | taskloop simd | parallel | | |
| 2608 | // | taskloop simd | for | | |
| 2609 | // | taskloop simd | for simd | | |
| 2610 | // | taskloop simd | master | | |
| 2611 | // | taskloop simd | critical | | |
Alexey Bataev | 1f09221 | 2016-02-02 04:59:52 +0000 | [diff] [blame] | 2612 | // | taskloop simd | simd | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2613 | // | taskloop simd | sections | | |
| 2614 | // | taskloop simd | section | | |
| 2615 | // | taskloop simd | single | | |
| 2616 | // | taskloop simd | parallel for | | |
| 2617 | // | taskloop simd |parallel for simd| | |
| 2618 | // | taskloop simd |parallel sections| | |
| 2619 | // | taskloop simd | task | | |
| 2620 | // | taskloop simd | taskyield | | |
| 2621 | // | taskloop simd | barrier | | |
| 2622 | // | taskloop simd | taskwait | | |
| 2623 | // | taskloop simd | taskgroup | | |
| 2624 | // | taskloop simd | flush | | |
| 2625 | // | taskloop simd | ordered | + (with simd clause) | |
| 2626 | // | taskloop simd | atomic | | |
| 2627 | // | taskloop simd | target | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2628 | // | taskloop simd | target parallel | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2629 | // | taskloop simd | target parallel | | |
| 2630 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2631 | // | taskloop simd | target enter | | |
| 2632 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2633 | // | taskloop simd | target exit | | |
| 2634 | // | | data | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2635 | // | taskloop simd | teams | | |
| 2636 | // | taskloop simd | cancellation | | |
| 2637 | // | | point | | |
| 2638 | // | taskloop simd | cancel | | |
| 2639 | // | taskloop simd | taskloop | | |
| 2640 | // | taskloop simd | taskloop simd | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2641 | // | taskloop simd | distribute | | |
| 2642 | // +------------------+-----------------+------------------------------------+ |
| 2643 | // | distribute | parallel | * | |
| 2644 | // | distribute | for | * | |
| 2645 | // | distribute | for simd | * | |
| 2646 | // | distribute | master | * | |
| 2647 | // | distribute | critical | * | |
| 2648 | // | distribute | simd | * | |
| 2649 | // | distribute | sections | * | |
| 2650 | // | distribute | section | * | |
| 2651 | // | distribute | single | * | |
| 2652 | // | distribute | parallel for | * | |
| 2653 | // | distribute |parallel for simd| * | |
| 2654 | // | distribute |parallel sections| * | |
| 2655 | // | distribute | task | * | |
| 2656 | // | distribute | taskyield | * | |
| 2657 | // | distribute | barrier | * | |
| 2658 | // | distribute | taskwait | * | |
| 2659 | // | distribute | taskgroup | * | |
| 2660 | // | distribute | flush | * | |
| 2661 | // | distribute | ordered | + | |
| 2662 | // | distribute | atomic | * | |
| 2663 | // | distribute | target | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2664 | // | distribute | target parallel | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2665 | // | distribute | target parallel | | |
| 2666 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2667 | // | distribute | target enter | | |
| 2668 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2669 | // | distribute | target exit | | |
| 2670 | // | | data | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2671 | // | distribute | teams | | |
| 2672 | // | distribute | cancellation | + | |
| 2673 | // | | point | | |
| 2674 | // | distribute | cancel | + | |
| 2675 | // | distribute | taskloop | * | |
| 2676 | // | distribute | taskloop simd | * | |
| 2677 | // | distribute | distribute | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2678 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2679 | if (Stack->getCurScope()) { |
| 2680 | auto ParentRegion = Stack->getParentDirective(); |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2681 | auto OffendingRegion = ParentRegion; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2682 | bool NestingProhibited = false; |
| 2683 | bool CloseNesting = true; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2684 | enum { |
| 2685 | NoRecommend, |
| 2686 | ShouldBeInParallelRegion, |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2687 | ShouldBeInOrderedRegion, |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2688 | ShouldBeInTargetRegion, |
| 2689 | ShouldBeInTeamsRegion |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2690 | } Recommend = NoRecommend; |
Alexey Bataev | 1f09221 | 2016-02-02 04:59:52 +0000 | [diff] [blame] | 2691 | if (isOpenMPSimdDirective(ParentRegion) && CurrentRegion != OMPD_ordered && |
| 2692 | CurrentRegion != OMPD_simd) { |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2693 | // OpenMP [2.16, Nesting of Regions] |
| 2694 | // OpenMP constructs may not be nested inside a simd region. |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2695 | // OpenMP [2.8.1,simd Construct, Restrictions] |
| 2696 | // An ordered construct with the simd clause is the only OpenMP construct |
| 2697 | // that can appear in the simd region. |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2698 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region_simd); |
| 2699 | return true; |
| 2700 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2701 | if (ParentRegion == OMPD_atomic) { |
| 2702 | // OpenMP [2.16, Nesting of Regions] |
| 2703 | // OpenMP constructs may not be nested inside an atomic region. |
| 2704 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region_atomic); |
| 2705 | return true; |
| 2706 | } |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2707 | if (CurrentRegion == OMPD_section) { |
| 2708 | // OpenMP [2.7.2, sections Construct, Restrictions] |
| 2709 | // Orphaned section directives are prohibited. That is, the section |
| 2710 | // directives must appear within the sections construct and must not be |
| 2711 | // encountered elsewhere in the sections region. |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2712 | if (ParentRegion != OMPD_sections && |
| 2713 | ParentRegion != OMPD_parallel_sections) { |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2714 | SemaRef.Diag(StartLoc, diag::err_omp_orphaned_section_directive) |
| 2715 | << (ParentRegion != OMPD_unknown) |
| 2716 | << getOpenMPDirectiveName(ParentRegion); |
| 2717 | return true; |
| 2718 | } |
| 2719 | return false; |
| 2720 | } |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2721 | // Allow some constructs to be orphaned (they could be used in functions, |
| 2722 | // called from OpenMP regions with the required preconditions). |
| 2723 | if (ParentRegion == OMPD_unknown) |
| 2724 | return false; |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2725 | if (CurrentRegion == OMPD_cancellation_point || |
| 2726 | CurrentRegion == OMPD_cancel) { |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2727 | // OpenMP [2.16, Nesting of Regions] |
| 2728 | // A cancellation point construct for which construct-type-clause is |
| 2729 | // taskgroup must be nested inside a task construct. A cancellation |
| 2730 | // point construct for which construct-type-clause is not taskgroup must |
| 2731 | // be closely nested inside an OpenMP construct that matches the type |
| 2732 | // specified in construct-type-clause. |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2733 | // A cancel construct for which construct-type-clause is taskgroup must be |
| 2734 | // nested inside a task construct. A cancel construct for which |
| 2735 | // construct-type-clause is not taskgroup must be closely nested inside an |
| 2736 | // OpenMP construct that matches the type specified in |
| 2737 | // construct-type-clause. |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2738 | NestingProhibited = |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2739 | !((CancelRegion == OMPD_parallel && |
| 2740 | (ParentRegion == OMPD_parallel || |
| 2741 | ParentRegion == OMPD_target_parallel)) || |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 2742 | (CancelRegion == OMPD_for && |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2743 | (ParentRegion == OMPD_for || ParentRegion == OMPD_parallel_for || |
| 2744 | ParentRegion == OMPD_target_parallel_for)) || |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2745 | (CancelRegion == OMPD_taskgroup && ParentRegion == OMPD_task) || |
| 2746 | (CancelRegion == OMPD_sections && |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 2747 | (ParentRegion == OMPD_section || ParentRegion == OMPD_sections || |
| 2748 | ParentRegion == OMPD_parallel_sections))); |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2749 | } else if (CurrentRegion == OMPD_master) { |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2750 | // OpenMP [2.16, Nesting of Regions] |
| 2751 | // A master region may not be closely nested inside a worksharing, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2752 | // atomic, or explicit task region. |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2753 | NestingProhibited = isOpenMPWorksharingDirective(ParentRegion) || |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2754 | ParentRegion == OMPD_task || |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2755 | isOpenMPTaskLoopDirective(ParentRegion); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2756 | } else if (CurrentRegion == OMPD_critical && CurrentName.getName()) { |
| 2757 | // OpenMP [2.16, Nesting of Regions] |
| 2758 | // A critical region may not be nested (closely or otherwise) inside a |
| 2759 | // critical region with the same name. Note that this restriction is not |
| 2760 | // sufficient to prevent deadlock. |
| 2761 | SourceLocation PreviousCriticalLoc; |
| 2762 | bool DeadLock = |
| 2763 | Stack->hasDirective([CurrentName, &PreviousCriticalLoc]( |
| 2764 | OpenMPDirectiveKind K, |
| 2765 | const DeclarationNameInfo &DNI, |
| 2766 | SourceLocation Loc) |
| 2767 | ->bool { |
| 2768 | if (K == OMPD_critical && |
| 2769 | DNI.getName() == CurrentName.getName()) { |
| 2770 | PreviousCriticalLoc = Loc; |
| 2771 | return true; |
| 2772 | } else |
| 2773 | return false; |
| 2774 | }, |
| 2775 | false /* skip top directive */); |
| 2776 | if (DeadLock) { |
| 2777 | SemaRef.Diag(StartLoc, |
| 2778 | diag::err_omp_prohibited_region_critical_same_name) |
| 2779 | << CurrentName.getName(); |
| 2780 | if (PreviousCriticalLoc.isValid()) |
| 2781 | SemaRef.Diag(PreviousCriticalLoc, |
| 2782 | diag::note_omp_previous_critical_region); |
| 2783 | return true; |
| 2784 | } |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2785 | } else if (CurrentRegion == OMPD_barrier) { |
| 2786 | // OpenMP [2.16, Nesting of Regions] |
| 2787 | // A barrier region may not be closely nested inside a worksharing, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2788 | // explicit task, critical, ordered, atomic, or master region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2789 | NestingProhibited = |
| 2790 | isOpenMPWorksharingDirective(ParentRegion) || |
| 2791 | ParentRegion == OMPD_task || ParentRegion == OMPD_master || |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2792 | ParentRegion == OMPD_critical || ParentRegion == OMPD_ordered || |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2793 | isOpenMPTaskLoopDirective(ParentRegion); |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2794 | } else if (isOpenMPWorksharingDirective(CurrentRegion) && |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2795 | !isOpenMPParallelDirective(CurrentRegion)) { |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2796 | // OpenMP [2.16, Nesting of Regions] |
| 2797 | // A worksharing region may not be closely nested inside a worksharing, |
| 2798 | // explicit task, critical, ordered, atomic, or master region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2799 | NestingProhibited = |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2800 | isOpenMPWorksharingDirective(ParentRegion) || |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2801 | ParentRegion == OMPD_task || ParentRegion == OMPD_master || |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2802 | ParentRegion == OMPD_critical || ParentRegion == OMPD_ordered || |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2803 | isOpenMPTaskLoopDirective(ParentRegion); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2804 | Recommend = ShouldBeInParallelRegion; |
| 2805 | } else if (CurrentRegion == OMPD_ordered) { |
| 2806 | // OpenMP [2.16, Nesting of Regions] |
| 2807 | // An ordered region may not be closely nested inside a critical, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2808 | // atomic, or explicit task region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2809 | // An ordered region must be closely nested inside a loop region (or |
| 2810 | // parallel loop region) with an ordered clause. |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2811 | // OpenMP [2.8.1,simd Construct, Restrictions] |
| 2812 | // An ordered construct with the simd clause is the only OpenMP construct |
| 2813 | // that can appear in the simd region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2814 | NestingProhibited = ParentRegion == OMPD_critical || |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2815 | ParentRegion == OMPD_task || |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2816 | isOpenMPTaskLoopDirective(ParentRegion) || |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2817 | !(isOpenMPSimdDirective(ParentRegion) || |
| 2818 | Stack->isParentOrderedRegion()); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2819 | Recommend = ShouldBeInOrderedRegion; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2820 | } else if (isOpenMPTeamsDirective(CurrentRegion)) { |
| 2821 | // OpenMP [2.16, Nesting of Regions] |
| 2822 | // If specified, a teams construct must be contained within a target |
| 2823 | // construct. |
| 2824 | NestingProhibited = ParentRegion != OMPD_target; |
| 2825 | Recommend = ShouldBeInTargetRegion; |
| 2826 | Stack->setParentTeamsRegionLoc(Stack->getConstructLoc()); |
| 2827 | } |
| 2828 | if (!NestingProhibited && isOpenMPTeamsDirective(ParentRegion)) { |
| 2829 | // OpenMP [2.16, Nesting of Regions] |
| 2830 | // distribute, parallel, parallel sections, parallel workshare, and the |
| 2831 | // parallel loop and parallel loop SIMD constructs are the only OpenMP |
| 2832 | // constructs that can be closely nested in the teams region. |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2833 | NestingProhibited = !isOpenMPParallelDirective(CurrentRegion) && |
| 2834 | !isOpenMPDistributeDirective(CurrentRegion); |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2835 | Recommend = ShouldBeInParallelRegion; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2836 | } |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2837 | if (!NestingProhibited && isOpenMPDistributeDirective(CurrentRegion)) { |
| 2838 | // OpenMP 4.5 [2.17 Nesting of Regions] |
| 2839 | // The region associated with the distribute construct must be strictly |
| 2840 | // nested inside a teams region |
| 2841 | NestingProhibited = !isOpenMPTeamsDirective(ParentRegion); |
| 2842 | Recommend = ShouldBeInTeamsRegion; |
| 2843 | } |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2844 | if (!NestingProhibited && |
| 2845 | (isOpenMPTargetExecutionDirective(CurrentRegion) || |
| 2846 | isOpenMPTargetDataManagementDirective(CurrentRegion))) { |
| 2847 | // OpenMP 4.5 [2.17 Nesting of Regions] |
| 2848 | // If a target, target update, target data, target enter data, or |
| 2849 | // target exit data construct is encountered during execution of a |
| 2850 | // target region, the behavior is unspecified. |
| 2851 | NestingProhibited = Stack->hasDirective( |
| 2852 | [&OffendingRegion](OpenMPDirectiveKind K, |
| 2853 | const DeclarationNameInfo &DNI, |
| 2854 | SourceLocation Loc) -> bool { |
| 2855 | if (isOpenMPTargetExecutionDirective(K)) { |
| 2856 | OffendingRegion = K; |
| 2857 | return true; |
| 2858 | } else |
| 2859 | return false; |
| 2860 | }, |
| 2861 | false /* don't skip top directive */); |
| 2862 | CloseNesting = false; |
| 2863 | } |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2864 | if (NestingProhibited) { |
| 2865 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region) |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2866 | << CloseNesting << getOpenMPDirectiveName(OffendingRegion) |
| 2867 | << Recommend << getOpenMPDirectiveName(CurrentRegion); |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2868 | return true; |
| 2869 | } |
| 2870 | } |
| 2871 | return false; |
| 2872 | } |
| 2873 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2874 | static bool checkIfClauses(Sema &S, OpenMPDirectiveKind Kind, |
| 2875 | ArrayRef<OMPClause *> Clauses, |
| 2876 | ArrayRef<OpenMPDirectiveKind> AllowedNameModifiers) { |
| 2877 | bool ErrorFound = false; |
| 2878 | unsigned NamedModifiersNumber = 0; |
| 2879 | SmallVector<const OMPIfClause *, OMPC_unknown + 1> FoundNameModifiers( |
| 2880 | OMPD_unknown + 1); |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2881 | SmallVector<SourceLocation, 4> NameModifierLoc; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2882 | for (const auto *C : Clauses) { |
| 2883 | if (const auto *IC = dyn_cast_or_null<OMPIfClause>(C)) { |
| 2884 | // At most one if clause without a directive-name-modifier can appear on |
| 2885 | // the directive. |
| 2886 | OpenMPDirectiveKind CurNM = IC->getNameModifier(); |
| 2887 | if (FoundNameModifiers[CurNM]) { |
| 2888 | S.Diag(C->getLocStart(), diag::err_omp_more_one_clause) |
| 2889 | << getOpenMPDirectiveName(Kind) << getOpenMPClauseName(OMPC_if) |
| 2890 | << (CurNM != OMPD_unknown) << getOpenMPDirectiveName(CurNM); |
| 2891 | ErrorFound = true; |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2892 | } else if (CurNM != OMPD_unknown) { |
| 2893 | NameModifierLoc.push_back(IC->getNameModifierLoc()); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2894 | ++NamedModifiersNumber; |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2895 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2896 | FoundNameModifiers[CurNM] = IC; |
| 2897 | if (CurNM == OMPD_unknown) |
| 2898 | continue; |
| 2899 | // Check if the specified name modifier is allowed for the current |
| 2900 | // directive. |
| 2901 | // At most one if clause with the particular directive-name-modifier can |
| 2902 | // appear on the directive. |
| 2903 | bool MatchFound = false; |
| 2904 | for (auto NM : AllowedNameModifiers) { |
| 2905 | if (CurNM == NM) { |
| 2906 | MatchFound = true; |
| 2907 | break; |
| 2908 | } |
| 2909 | } |
| 2910 | if (!MatchFound) { |
| 2911 | S.Diag(IC->getNameModifierLoc(), |
| 2912 | diag::err_omp_wrong_if_directive_name_modifier) |
| 2913 | << getOpenMPDirectiveName(CurNM) << getOpenMPDirectiveName(Kind); |
| 2914 | ErrorFound = true; |
| 2915 | } |
| 2916 | } |
| 2917 | } |
| 2918 | // If any if clause on the directive includes a directive-name-modifier then |
| 2919 | // all if clauses on the directive must include a directive-name-modifier. |
| 2920 | if (FoundNameModifiers[OMPD_unknown] && NamedModifiersNumber > 0) { |
| 2921 | if (NamedModifiersNumber == AllowedNameModifiers.size()) { |
| 2922 | S.Diag(FoundNameModifiers[OMPD_unknown]->getLocStart(), |
| 2923 | diag::err_omp_no_more_if_clause); |
| 2924 | } else { |
| 2925 | std::string Values; |
| 2926 | std::string Sep(", "); |
| 2927 | unsigned AllowedCnt = 0; |
| 2928 | unsigned TotalAllowedNum = |
| 2929 | AllowedNameModifiers.size() - NamedModifiersNumber; |
| 2930 | for (unsigned Cnt = 0, End = AllowedNameModifiers.size(); Cnt < End; |
| 2931 | ++Cnt) { |
| 2932 | OpenMPDirectiveKind NM = AllowedNameModifiers[Cnt]; |
| 2933 | if (!FoundNameModifiers[NM]) { |
| 2934 | Values += "'"; |
| 2935 | Values += getOpenMPDirectiveName(NM); |
| 2936 | Values += "'"; |
| 2937 | if (AllowedCnt + 2 == TotalAllowedNum) |
| 2938 | Values += " or "; |
| 2939 | else if (AllowedCnt + 1 != TotalAllowedNum) |
| 2940 | Values += Sep; |
| 2941 | ++AllowedCnt; |
| 2942 | } |
| 2943 | } |
| 2944 | S.Diag(FoundNameModifiers[OMPD_unknown]->getCondition()->getLocStart(), |
| 2945 | diag::err_omp_unnamed_if_clause) |
| 2946 | << (TotalAllowedNum > 1) << Values; |
| 2947 | } |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2948 | for (auto Loc : NameModifierLoc) { |
| 2949 | S.Diag(Loc, diag::note_omp_previous_named_if_clause); |
| 2950 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2951 | ErrorFound = true; |
| 2952 | } |
| 2953 | return ErrorFound; |
| 2954 | } |
| 2955 | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2956 | StmtResult Sema::ActOnOpenMPExecutableDirective( |
| 2957 | OpenMPDirectiveKind Kind, const DeclarationNameInfo &DirName, |
| 2958 | OpenMPDirectiveKind CancelRegion, ArrayRef<OMPClause *> Clauses, |
| 2959 | Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2960 | StmtResult Res = StmtError(); |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2961 | if (CheckNestingOfRegions(*this, DSAStack, Kind, DirName, CancelRegion, |
| 2962 | StartLoc)) |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2963 | return StmtError(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2964 | |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2965 | llvm::SmallVector<OMPClause *, 8> ClausesWithImplicit; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 2966 | llvm::DenseMap<ValueDecl *, Expr *> VarsWithInheritedDSA; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2967 | bool ErrorFound = false; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2968 | ClausesWithImplicit.append(Clauses.begin(), Clauses.end()); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2969 | if (AStmt) { |
| 2970 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 2971 | |
| 2972 | // Check default data sharing attributes for referenced variables. |
| 2973 | DSAAttrChecker DSAChecker(DSAStack, *this, cast<CapturedStmt>(AStmt)); |
| 2974 | DSAChecker.Visit(cast<CapturedStmt>(AStmt)->getCapturedStmt()); |
| 2975 | if (DSAChecker.isErrorFound()) |
| 2976 | return StmtError(); |
| 2977 | // Generate list of implicitly defined firstprivate variables. |
| 2978 | VarsWithInheritedDSA = DSAChecker.getVarsWithInheritedDSA(); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2979 | |
| 2980 | if (!DSAChecker.getImplicitFirstprivate().empty()) { |
| 2981 | if (OMPClause *Implicit = ActOnOpenMPFirstprivateClause( |
| 2982 | DSAChecker.getImplicitFirstprivate(), SourceLocation(), |
| 2983 | SourceLocation(), SourceLocation())) { |
| 2984 | ClausesWithImplicit.push_back(Implicit); |
| 2985 | ErrorFound = cast<OMPFirstprivateClause>(Implicit)->varlist_size() != |
| 2986 | DSAChecker.getImplicitFirstprivate().size(); |
| 2987 | } else |
| 2988 | ErrorFound = true; |
| 2989 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2990 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2991 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2992 | llvm::SmallVector<OpenMPDirectiveKind, 4> AllowedNameModifiers; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2993 | switch (Kind) { |
| 2994 | case OMPD_parallel: |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2995 | Res = ActOnOpenMPParallelDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2996 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2997 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2998 | break; |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 2999 | case OMPD_simd: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3000 | Res = ActOnOpenMPSimdDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc, |
| 3001 | VarsWithInheritedDSA); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 3002 | break; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3003 | case OMPD_for: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3004 | Res = ActOnOpenMPForDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc, |
| 3005 | VarsWithInheritedDSA); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3006 | break; |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 3007 | case OMPD_for_simd: |
| 3008 | Res = ActOnOpenMPForSimdDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3009 | EndLoc, VarsWithInheritedDSA); |
| 3010 | break; |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 3011 | case OMPD_sections: |
| 3012 | Res = ActOnOpenMPSectionsDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3013 | EndLoc); |
| 3014 | break; |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 3015 | case OMPD_section: |
| 3016 | assert(ClausesWithImplicit.empty() && |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 3017 | "No clauses are allowed for 'omp section' directive"); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 3018 | Res = ActOnOpenMPSectionDirective(AStmt, StartLoc, EndLoc); |
| 3019 | break; |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 3020 | case OMPD_single: |
| 3021 | Res = ActOnOpenMPSingleDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3022 | EndLoc); |
| 3023 | break; |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 3024 | case OMPD_master: |
| 3025 | assert(ClausesWithImplicit.empty() && |
| 3026 | "No clauses are allowed for 'omp master' directive"); |
| 3027 | Res = ActOnOpenMPMasterDirective(AStmt, StartLoc, EndLoc); |
| 3028 | break; |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 3029 | case OMPD_critical: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 3030 | Res = ActOnOpenMPCriticalDirective(DirName, ClausesWithImplicit, AStmt, |
| 3031 | StartLoc, EndLoc); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 3032 | break; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3033 | case OMPD_parallel_for: |
| 3034 | Res = ActOnOpenMPParallelForDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3035 | EndLoc, VarsWithInheritedDSA); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3036 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3037 | break; |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 3038 | case OMPD_parallel_for_simd: |
| 3039 | Res = ActOnOpenMPParallelForSimdDirective( |
| 3040 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3041 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 3042 | break; |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 3043 | case OMPD_parallel_sections: |
| 3044 | Res = ActOnOpenMPParallelSectionsDirective(ClausesWithImplicit, AStmt, |
| 3045 | StartLoc, EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3046 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 3047 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3048 | case OMPD_task: |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 3049 | Res = |
| 3050 | ActOnOpenMPTaskDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3051 | AllowedNameModifiers.push_back(OMPD_task); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 3052 | break; |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 3053 | case OMPD_taskyield: |
| 3054 | assert(ClausesWithImplicit.empty() && |
| 3055 | "No clauses are allowed for 'omp taskyield' directive"); |
| 3056 | assert(AStmt == nullptr && |
| 3057 | "No associated statement allowed for 'omp taskyield' directive"); |
| 3058 | Res = ActOnOpenMPTaskyieldDirective(StartLoc, EndLoc); |
| 3059 | break; |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 3060 | case OMPD_barrier: |
| 3061 | assert(ClausesWithImplicit.empty() && |
| 3062 | "No clauses are allowed for 'omp barrier' directive"); |
| 3063 | assert(AStmt == nullptr && |
| 3064 | "No associated statement allowed for 'omp barrier' directive"); |
| 3065 | Res = ActOnOpenMPBarrierDirective(StartLoc, EndLoc); |
| 3066 | break; |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 3067 | case OMPD_taskwait: |
| 3068 | assert(ClausesWithImplicit.empty() && |
| 3069 | "No clauses are allowed for 'omp taskwait' directive"); |
| 3070 | assert(AStmt == nullptr && |
| 3071 | "No associated statement allowed for 'omp taskwait' directive"); |
| 3072 | Res = ActOnOpenMPTaskwaitDirective(StartLoc, EndLoc); |
| 3073 | break; |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 3074 | case OMPD_taskgroup: |
| 3075 | assert(ClausesWithImplicit.empty() && |
| 3076 | "No clauses are allowed for 'omp taskgroup' directive"); |
| 3077 | Res = ActOnOpenMPTaskgroupDirective(AStmt, StartLoc, EndLoc); |
| 3078 | break; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 3079 | case OMPD_flush: |
| 3080 | assert(AStmt == nullptr && |
| 3081 | "No associated statement allowed for 'omp flush' directive"); |
| 3082 | Res = ActOnOpenMPFlushDirective(ClausesWithImplicit, StartLoc, EndLoc); |
| 3083 | break; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 3084 | case OMPD_ordered: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 3085 | Res = ActOnOpenMPOrderedDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3086 | EndLoc); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 3087 | break; |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 3088 | case OMPD_atomic: |
| 3089 | Res = ActOnOpenMPAtomicDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3090 | EndLoc); |
| 3091 | break; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 3092 | case OMPD_teams: |
| 3093 | Res = |
| 3094 | ActOnOpenMPTeamsDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); |
| 3095 | break; |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 3096 | case OMPD_target: |
| 3097 | Res = ActOnOpenMPTargetDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3098 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3099 | AllowedNameModifiers.push_back(OMPD_target); |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 3100 | break; |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 3101 | case OMPD_target_parallel: |
| 3102 | Res = ActOnOpenMPTargetParallelDirective(ClausesWithImplicit, AStmt, |
| 3103 | StartLoc, EndLoc); |
| 3104 | AllowedNameModifiers.push_back(OMPD_target); |
| 3105 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 3106 | break; |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 3107 | case OMPD_target_parallel_for: |
| 3108 | Res = ActOnOpenMPTargetParallelForDirective( |
| 3109 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 3110 | AllowedNameModifiers.push_back(OMPD_target); |
| 3111 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 3112 | break; |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 3113 | case OMPD_cancellation_point: |
| 3114 | assert(ClausesWithImplicit.empty() && |
| 3115 | "No clauses are allowed for 'omp cancellation point' directive"); |
| 3116 | assert(AStmt == nullptr && "No associated statement allowed for 'omp " |
| 3117 | "cancellation point' directive"); |
| 3118 | Res = ActOnOpenMPCancellationPointDirective(StartLoc, EndLoc, CancelRegion); |
| 3119 | break; |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 3120 | case OMPD_cancel: |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 3121 | assert(AStmt == nullptr && |
| 3122 | "No associated statement allowed for 'omp cancel' directive"); |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 3123 | Res = ActOnOpenMPCancelDirective(ClausesWithImplicit, StartLoc, EndLoc, |
| 3124 | CancelRegion); |
| 3125 | AllowedNameModifiers.push_back(OMPD_cancel); |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 3126 | break; |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 3127 | case OMPD_target_data: |
| 3128 | Res = ActOnOpenMPTargetDataDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3129 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3130 | AllowedNameModifiers.push_back(OMPD_target_data); |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 3131 | break; |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 3132 | case OMPD_target_enter_data: |
| 3133 | Res = ActOnOpenMPTargetEnterDataDirective(ClausesWithImplicit, StartLoc, |
| 3134 | EndLoc); |
| 3135 | AllowedNameModifiers.push_back(OMPD_target_enter_data); |
| 3136 | break; |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 3137 | case OMPD_target_exit_data: |
| 3138 | Res = ActOnOpenMPTargetExitDataDirective(ClausesWithImplicit, StartLoc, |
| 3139 | EndLoc); |
| 3140 | AllowedNameModifiers.push_back(OMPD_target_exit_data); |
| 3141 | break; |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 3142 | case OMPD_taskloop: |
| 3143 | Res = ActOnOpenMPTaskLoopDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3144 | EndLoc, VarsWithInheritedDSA); |
| 3145 | AllowedNameModifiers.push_back(OMPD_taskloop); |
| 3146 | break; |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 3147 | case OMPD_taskloop_simd: |
| 3148 | Res = ActOnOpenMPTaskLoopSimdDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3149 | EndLoc, VarsWithInheritedDSA); |
| 3150 | AllowedNameModifiers.push_back(OMPD_taskloop); |
| 3151 | break; |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 3152 | case OMPD_distribute: |
| 3153 | Res = ActOnOpenMPDistributeDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3154 | EndLoc, VarsWithInheritedDSA); |
| 3155 | break; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 3156 | case OMPD_threadprivate: |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 3157 | case OMPD_declare_reduction: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3158 | llvm_unreachable("OpenMP Directive is not allowed"); |
| 3159 | case OMPD_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3160 | llvm_unreachable("Unknown OpenMP directive"); |
| 3161 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 3162 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3163 | for (auto P : VarsWithInheritedDSA) { |
| 3164 | Diag(P.second->getExprLoc(), diag::err_omp_no_dsa_for_variable) |
| 3165 | << P.first << P.second->getSourceRange(); |
| 3166 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3167 | ErrorFound = !VarsWithInheritedDSA.empty() || ErrorFound; |
| 3168 | |
| 3169 | if (!AllowedNameModifiers.empty()) |
| 3170 | ErrorFound = checkIfClauses(*this, Kind, Clauses, AllowedNameModifiers) || |
| 3171 | ErrorFound; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3172 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 3173 | if (ErrorFound) |
| 3174 | return StmtError(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3175 | return Res; |
| 3176 | } |
| 3177 | |
| 3178 | StmtResult Sema::ActOnOpenMPParallelDirective(ArrayRef<OMPClause *> Clauses, |
| 3179 | Stmt *AStmt, |
| 3180 | SourceLocation StartLoc, |
| 3181 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3182 | if (!AStmt) |
| 3183 | return StmtError(); |
| 3184 | |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 3185 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 3186 | // 1.2.2 OpenMP Language Terminology |
| 3187 | // Structured block - An executable statement with a single entry at the |
| 3188 | // top and a single exit at the bottom. |
| 3189 | // The point of exit cannot be a branch out of the structured block. |
| 3190 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 3191 | CS->getCapturedDecl()->setNothrow(); |
| 3192 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3193 | getCurFunction()->setHasBranchProtectedScope(); |
| 3194 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 3195 | return OMPParallelDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 3196 | DSAStack->isCancelRegion()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3197 | } |
| 3198 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3199 | namespace { |
| 3200 | /// \brief Helper class for checking canonical form of the OpenMP loops and |
| 3201 | /// extracting iteration space of each loop in the loop nest, that will be used |
| 3202 | /// for IR generation. |
| 3203 | class OpenMPIterationSpaceChecker { |
| 3204 | /// \brief Reference to Sema. |
| 3205 | Sema &SemaRef; |
| 3206 | /// \brief A location for diagnostics (when there is no some better location). |
| 3207 | SourceLocation DefaultLoc; |
| 3208 | /// \brief A location for diagnostics (when increment is not compatible). |
| 3209 | SourceLocation ConditionLoc; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3210 | /// \brief A source location for referring to loop init later. |
| 3211 | SourceRange InitSrcRange; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3212 | /// \brief A source location for referring to condition later. |
| 3213 | SourceRange ConditionSrcRange; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3214 | /// \brief A source location for referring to increment later. |
| 3215 | SourceRange IncrementSrcRange; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3216 | /// \brief Loop variable. |
| 3217 | VarDecl *Var; |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3218 | /// \brief Reference to loop variable. |
| 3219 | DeclRefExpr *VarRef; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3220 | /// \brief Lower bound (initializer for the var). |
| 3221 | Expr *LB; |
| 3222 | /// \brief Upper bound. |
| 3223 | Expr *UB; |
| 3224 | /// \brief Loop step (increment). |
| 3225 | Expr *Step; |
| 3226 | /// \brief This flag is true when condition is one of: |
| 3227 | /// Var < UB |
| 3228 | /// Var <= UB |
| 3229 | /// UB > Var |
| 3230 | /// UB >= Var |
| 3231 | bool TestIsLessOp; |
| 3232 | /// \brief This flag is true when condition is strict ( < or > ). |
| 3233 | bool TestIsStrictOp; |
| 3234 | /// \brief This flag is true when step is subtracted on each iteration. |
| 3235 | bool SubtractStep; |
| 3236 | |
| 3237 | public: |
| 3238 | OpenMPIterationSpaceChecker(Sema &SemaRef, SourceLocation DefaultLoc) |
| 3239 | : SemaRef(SemaRef), DefaultLoc(DefaultLoc), ConditionLoc(DefaultLoc), |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3240 | InitSrcRange(SourceRange()), ConditionSrcRange(SourceRange()), |
| 3241 | IncrementSrcRange(SourceRange()), Var(nullptr), VarRef(nullptr), |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3242 | LB(nullptr), UB(nullptr), Step(nullptr), TestIsLessOp(false), |
| 3243 | TestIsStrictOp(false), SubtractStep(false) {} |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3244 | /// \brief Check init-expr for canonical loop form and save loop counter |
| 3245 | /// variable - #Var and its initialization value - #LB. |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3246 | bool CheckInit(Stmt *S, bool EmitDiags = true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3247 | /// \brief Check test-expr for canonical form, save upper-bound (#UB), flags |
| 3248 | /// for less/greater and for strict/non-strict comparison. |
| 3249 | bool CheckCond(Expr *S); |
| 3250 | /// \brief Check incr-expr for canonical loop form and return true if it |
| 3251 | /// does not conform, otherwise save loop step (#Step). |
| 3252 | bool CheckInc(Expr *S); |
| 3253 | /// \brief Return the loop counter variable. |
| 3254 | VarDecl *GetLoopVar() const { return Var; } |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3255 | /// \brief Return the reference expression to loop counter variable. |
| 3256 | DeclRefExpr *GetLoopVarRefExpr() const { return VarRef; } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3257 | /// \brief Source range of the loop init. |
| 3258 | SourceRange GetInitSrcRange() const { return InitSrcRange; } |
| 3259 | /// \brief Source range of the loop condition. |
| 3260 | SourceRange GetConditionSrcRange() const { return ConditionSrcRange; } |
| 3261 | /// \brief Source range of the loop increment. |
| 3262 | SourceRange GetIncrementSrcRange() const { return IncrementSrcRange; } |
| 3263 | /// \brief True if the step should be subtracted. |
| 3264 | bool ShouldSubtractStep() const { return SubtractStep; } |
| 3265 | /// \brief Build the expression to calculate the number of iterations. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3266 | Expr * |
| 3267 | BuildNumIterations(Scope *S, const bool LimitedType, |
| 3268 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) const; |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3269 | /// \brief Build the precondition expression for the loops. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3270 | Expr *BuildPreCond(Scope *S, Expr *Cond, |
| 3271 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) const; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3272 | /// \brief Build reference expression to the counter be used for codegen. |
| 3273 | Expr *BuildCounterVar() const; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3274 | /// \brief Build reference expression to the private counter be used for |
| 3275 | /// codegen. |
| 3276 | Expr *BuildPrivateCounterVar() const; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3277 | /// \brief Build initization of the counter be used for codegen. |
| 3278 | Expr *BuildCounterInit() const; |
| 3279 | /// \brief Build step of the counter be used for codegen. |
| 3280 | Expr *BuildCounterStep() const; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3281 | /// \brief Return true if any expression is dependent. |
| 3282 | bool Dependent() const; |
| 3283 | |
| 3284 | private: |
| 3285 | /// \brief Check the right-hand side of an assignment in the increment |
| 3286 | /// expression. |
| 3287 | bool CheckIncRHS(Expr *RHS); |
| 3288 | /// \brief Helper to set loop counter variable and its initializer. |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3289 | bool SetVarAndLB(VarDecl *NewVar, DeclRefExpr *NewVarRefExpr, Expr *NewLB); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3290 | /// \brief Helper to set upper bound. |
Craig Topper | e335f25 | 2015-10-04 04:53:55 +0000 | [diff] [blame] | 3291 | bool SetUB(Expr *NewUB, bool LessOp, bool StrictOp, SourceRange SR, |
Craig Topper | 9cd5e4f | 2015-09-21 01:23:32 +0000 | [diff] [blame] | 3292 | SourceLocation SL); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3293 | /// \brief Helper to set loop increment. |
| 3294 | bool SetStep(Expr *NewStep, bool Subtract); |
| 3295 | }; |
| 3296 | |
| 3297 | bool OpenMPIterationSpaceChecker::Dependent() const { |
| 3298 | if (!Var) { |
| 3299 | assert(!LB && !UB && !Step); |
| 3300 | return false; |
| 3301 | } |
| 3302 | return Var->getType()->isDependentType() || (LB && LB->isValueDependent()) || |
| 3303 | (UB && UB->isValueDependent()) || (Step && Step->isValueDependent()); |
| 3304 | } |
| 3305 | |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3306 | template <typename T> |
| 3307 | static T *getExprAsWritten(T *E) { |
| 3308 | if (auto *ExprTemp = dyn_cast<ExprWithCleanups>(E)) |
| 3309 | E = ExprTemp->getSubExpr(); |
| 3310 | |
| 3311 | if (auto *MTE = dyn_cast<MaterializeTemporaryExpr>(E)) |
| 3312 | E = MTE->GetTemporaryExpr(); |
| 3313 | |
| 3314 | while (auto *Binder = dyn_cast<CXXBindTemporaryExpr>(E)) |
| 3315 | E = Binder->getSubExpr(); |
| 3316 | |
| 3317 | if (auto *ICE = dyn_cast<ImplicitCastExpr>(E)) |
| 3318 | E = ICE->getSubExprAsWritten(); |
| 3319 | return E->IgnoreParens(); |
| 3320 | } |
| 3321 | |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3322 | bool OpenMPIterationSpaceChecker::SetVarAndLB(VarDecl *NewVar, |
| 3323 | DeclRefExpr *NewVarRefExpr, |
| 3324 | Expr *NewLB) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3325 | // State consistency checking to ensure correct usage. |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3326 | assert(Var == nullptr && LB == nullptr && VarRef == nullptr && |
| 3327 | UB == nullptr && Step == nullptr && !TestIsLessOp && !TestIsStrictOp); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3328 | if (!NewVar || !NewLB) |
| 3329 | return true; |
| 3330 | Var = NewVar; |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3331 | VarRef = NewVarRefExpr; |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3332 | if (auto *CE = dyn_cast_or_null<CXXConstructExpr>(NewLB)) |
| 3333 | if (const CXXConstructorDecl *Ctor = CE->getConstructor()) |
Alexey Bataev | 0d08a7f | 2015-07-16 04:19:43 +0000 | [diff] [blame] | 3334 | if ((Ctor->isCopyOrMoveConstructor() || |
| 3335 | Ctor->isConvertingConstructor(/*AllowExplicit=*/false)) && |
| 3336 | CE->getNumArgs() > 0 && CE->getArg(0) != nullptr) |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3337 | NewLB = CE->getArg(0)->IgnoreParenImpCasts(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3338 | LB = NewLB; |
| 3339 | return false; |
| 3340 | } |
| 3341 | |
| 3342 | bool OpenMPIterationSpaceChecker::SetUB(Expr *NewUB, bool LessOp, bool StrictOp, |
Craig Topper | e335f25 | 2015-10-04 04:53:55 +0000 | [diff] [blame] | 3343 | SourceRange SR, SourceLocation SL) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3344 | // State consistency checking to ensure correct usage. |
| 3345 | assert(Var != nullptr && LB != nullptr && UB == nullptr && Step == nullptr && |
| 3346 | !TestIsLessOp && !TestIsStrictOp); |
| 3347 | if (!NewUB) |
| 3348 | return true; |
| 3349 | UB = NewUB; |
| 3350 | TestIsLessOp = LessOp; |
| 3351 | TestIsStrictOp = StrictOp; |
| 3352 | ConditionSrcRange = SR; |
| 3353 | ConditionLoc = SL; |
| 3354 | return false; |
| 3355 | } |
| 3356 | |
| 3357 | bool OpenMPIterationSpaceChecker::SetStep(Expr *NewStep, bool Subtract) { |
| 3358 | // State consistency checking to ensure correct usage. |
| 3359 | assert(Var != nullptr && LB != nullptr && Step == nullptr); |
| 3360 | if (!NewStep) |
| 3361 | return true; |
| 3362 | if (!NewStep->isValueDependent()) { |
| 3363 | // Check that the step is integer expression. |
| 3364 | SourceLocation StepLoc = NewStep->getLocStart(); |
| 3365 | ExprResult Val = |
| 3366 | SemaRef.PerformOpenMPImplicitIntegerConversion(StepLoc, NewStep); |
| 3367 | if (Val.isInvalid()) |
| 3368 | return true; |
| 3369 | NewStep = Val.get(); |
| 3370 | |
| 3371 | // OpenMP [2.6, Canonical Loop Form, Restrictions] |
| 3372 | // If test-expr is of form var relational-op b and relational-op is < or |
| 3373 | // <= then incr-expr must cause var to increase on each iteration of the |
| 3374 | // loop. If test-expr is of form var relational-op b and relational-op is |
| 3375 | // > or >= then incr-expr must cause var to decrease on each iteration of |
| 3376 | // the loop. |
| 3377 | // If test-expr is of form b relational-op var and relational-op is < or |
| 3378 | // <= then incr-expr must cause var to decrease on each iteration of the |
| 3379 | // loop. If test-expr is of form b relational-op var and relational-op is |
| 3380 | // > or >= then incr-expr must cause var to increase on each iteration of |
| 3381 | // the loop. |
| 3382 | llvm::APSInt Result; |
| 3383 | bool IsConstant = NewStep->isIntegerConstantExpr(Result, SemaRef.Context); |
| 3384 | bool IsUnsigned = !NewStep->getType()->hasSignedIntegerRepresentation(); |
| 3385 | bool IsConstNeg = |
| 3386 | IsConstant && Result.isSigned() && (Subtract != Result.isNegative()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3387 | bool IsConstPos = |
| 3388 | IsConstant && Result.isSigned() && (Subtract == Result.isNegative()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3389 | bool IsConstZero = IsConstant && !Result.getBoolValue(); |
| 3390 | if (UB && (IsConstZero || |
| 3391 | (TestIsLessOp ? (IsConstNeg || (IsUnsigned && Subtract)) |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3392 | : (IsConstPos || (IsUnsigned && !Subtract))))) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3393 | SemaRef.Diag(NewStep->getExprLoc(), |
| 3394 | diag::err_omp_loop_incr_not_compatible) |
| 3395 | << Var << TestIsLessOp << NewStep->getSourceRange(); |
| 3396 | SemaRef.Diag(ConditionLoc, |
| 3397 | diag::note_omp_loop_cond_requres_compatible_incr) |
| 3398 | << TestIsLessOp << ConditionSrcRange; |
| 3399 | return true; |
| 3400 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3401 | if (TestIsLessOp == Subtract) { |
| 3402 | NewStep = SemaRef.CreateBuiltinUnaryOp(NewStep->getExprLoc(), UO_Minus, |
| 3403 | NewStep).get(); |
| 3404 | Subtract = !Subtract; |
| 3405 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3406 | } |
| 3407 | |
| 3408 | Step = NewStep; |
| 3409 | SubtractStep = Subtract; |
| 3410 | return false; |
| 3411 | } |
| 3412 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3413 | bool OpenMPIterationSpaceChecker::CheckInit(Stmt *S, bool EmitDiags) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3414 | // Check init-expr for canonical loop form and save loop counter |
| 3415 | // variable - #Var and its initialization value - #LB. |
| 3416 | // OpenMP [2.6] Canonical loop form. init-expr may be one of the following: |
| 3417 | // var = lb |
| 3418 | // integer-type var = lb |
| 3419 | // random-access-iterator-type var = lb |
| 3420 | // pointer-type var = lb |
| 3421 | // |
| 3422 | if (!S) { |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3423 | if (EmitDiags) { |
| 3424 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_init); |
| 3425 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3426 | return true; |
| 3427 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3428 | InitSrcRange = S->getSourceRange(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3429 | if (Expr *E = dyn_cast<Expr>(S)) |
| 3430 | S = E->IgnoreParens(); |
| 3431 | if (auto BO = dyn_cast<BinaryOperator>(S)) { |
| 3432 | if (BO->getOpcode() == BO_Assign) |
| 3433 | if (auto DRE = dyn_cast<DeclRefExpr>(BO->getLHS()->IgnoreParens())) |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3434 | return SetVarAndLB(dyn_cast<VarDecl>(DRE->getDecl()), DRE, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3435 | BO->getRHS()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3436 | } else if (auto DS = dyn_cast<DeclStmt>(S)) { |
| 3437 | if (DS->isSingleDecl()) { |
| 3438 | if (auto Var = dyn_cast_or_null<VarDecl>(DS->getSingleDecl())) { |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3439 | if (Var->hasInit() && !Var->getType()->isReferenceType()) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3440 | // Accept non-canonical init form here but emit ext. warning. |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3441 | if (Var->getInitStyle() != VarDecl::CInit && EmitDiags) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3442 | SemaRef.Diag(S->getLocStart(), |
| 3443 | diag::ext_omp_loop_not_canonical_init) |
| 3444 | << S->getSourceRange(); |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3445 | return SetVarAndLB(Var, nullptr, Var->getInit()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3446 | } |
| 3447 | } |
| 3448 | } |
| 3449 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) |
| 3450 | if (CE->getOperator() == OO_Equal) |
| 3451 | if (auto DRE = dyn_cast<DeclRefExpr>(CE->getArg(0))) |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3452 | return SetVarAndLB(dyn_cast<VarDecl>(DRE->getDecl()), DRE, |
| 3453 | CE->getArg(1)); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3454 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3455 | if (EmitDiags) { |
| 3456 | SemaRef.Diag(S->getLocStart(), diag::err_omp_loop_not_canonical_init) |
| 3457 | << S->getSourceRange(); |
| 3458 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3459 | return true; |
| 3460 | } |
| 3461 | |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 3462 | /// \brief Ignore parenthesizes, implicit casts, copy constructor and return the |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3463 | /// variable (which may be the loop variable) if possible. |
| 3464 | static const VarDecl *GetInitVarDecl(const Expr *E) { |
| 3465 | if (!E) |
Craig Topper | 4b56692 | 2014-06-09 02:04:02 +0000 | [diff] [blame] | 3466 | return nullptr; |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3467 | E = getExprAsWritten(E); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3468 | if (auto *CE = dyn_cast_or_null<CXXConstructExpr>(E)) |
| 3469 | if (const CXXConstructorDecl *Ctor = CE->getConstructor()) |
Alexey Bataev | 0d08a7f | 2015-07-16 04:19:43 +0000 | [diff] [blame] | 3470 | if ((Ctor->isCopyOrMoveConstructor() || |
| 3471 | Ctor->isConvertingConstructor(/*AllowExplicit=*/false)) && |
| 3472 | CE->getNumArgs() > 0 && CE->getArg(0) != nullptr) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3473 | E = CE->getArg(0)->IgnoreParenImpCasts(); |
| 3474 | auto DRE = dyn_cast_or_null<DeclRefExpr>(E); |
| 3475 | if (!DRE) |
| 3476 | return nullptr; |
| 3477 | return dyn_cast<VarDecl>(DRE->getDecl()); |
| 3478 | } |
| 3479 | |
| 3480 | bool OpenMPIterationSpaceChecker::CheckCond(Expr *S) { |
| 3481 | // Check test-expr for canonical form, save upper-bound UB, flags for |
| 3482 | // less/greater and for strict/non-strict comparison. |
| 3483 | // OpenMP [2.6] Canonical loop form. Test-expr may be one of the following: |
| 3484 | // var relational-op b |
| 3485 | // b relational-op var |
| 3486 | // |
| 3487 | if (!S) { |
| 3488 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_cond) << Var; |
| 3489 | return true; |
| 3490 | } |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3491 | S = getExprAsWritten(S); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3492 | SourceLocation CondLoc = S->getLocStart(); |
| 3493 | if (auto BO = dyn_cast<BinaryOperator>(S)) { |
| 3494 | if (BO->isRelationalOp()) { |
| 3495 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 3496 | return SetUB(BO->getRHS(), |
| 3497 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_LE), |
| 3498 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_GT), |
| 3499 | BO->getSourceRange(), BO->getOperatorLoc()); |
| 3500 | if (GetInitVarDecl(BO->getRHS()) == Var) |
| 3501 | return SetUB(BO->getLHS(), |
| 3502 | (BO->getOpcode() == BO_GT || BO->getOpcode() == BO_GE), |
| 3503 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_GT), |
| 3504 | BO->getSourceRange(), BO->getOperatorLoc()); |
| 3505 | } |
| 3506 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
| 3507 | if (CE->getNumArgs() == 2) { |
| 3508 | auto Op = CE->getOperator(); |
| 3509 | switch (Op) { |
| 3510 | case OO_Greater: |
| 3511 | case OO_GreaterEqual: |
| 3512 | case OO_Less: |
| 3513 | case OO_LessEqual: |
| 3514 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 3515 | return SetUB(CE->getArg(1), Op == OO_Less || Op == OO_LessEqual, |
| 3516 | Op == OO_Less || Op == OO_Greater, CE->getSourceRange(), |
| 3517 | CE->getOperatorLoc()); |
| 3518 | if (GetInitVarDecl(CE->getArg(1)) == Var) |
| 3519 | return SetUB(CE->getArg(0), Op == OO_Greater || Op == OO_GreaterEqual, |
| 3520 | Op == OO_Less || Op == OO_Greater, CE->getSourceRange(), |
| 3521 | CE->getOperatorLoc()); |
| 3522 | break; |
| 3523 | default: |
| 3524 | break; |
| 3525 | } |
| 3526 | } |
| 3527 | } |
| 3528 | SemaRef.Diag(CondLoc, diag::err_omp_loop_not_canonical_cond) |
| 3529 | << S->getSourceRange() << Var; |
| 3530 | return true; |
| 3531 | } |
| 3532 | |
| 3533 | bool OpenMPIterationSpaceChecker::CheckIncRHS(Expr *RHS) { |
| 3534 | // RHS of canonical loop form increment can be: |
| 3535 | // var + incr |
| 3536 | // incr + var |
| 3537 | // var - incr |
| 3538 | // |
| 3539 | RHS = RHS->IgnoreParenImpCasts(); |
| 3540 | if (auto BO = dyn_cast<BinaryOperator>(RHS)) { |
| 3541 | if (BO->isAdditiveOp()) { |
| 3542 | bool IsAdd = BO->getOpcode() == BO_Add; |
| 3543 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 3544 | return SetStep(BO->getRHS(), !IsAdd); |
| 3545 | if (IsAdd && GetInitVarDecl(BO->getRHS()) == Var) |
| 3546 | return SetStep(BO->getLHS(), false); |
| 3547 | } |
| 3548 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(RHS)) { |
| 3549 | bool IsAdd = CE->getOperator() == OO_Plus; |
| 3550 | if ((IsAdd || CE->getOperator() == OO_Minus) && CE->getNumArgs() == 2) { |
| 3551 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 3552 | return SetStep(CE->getArg(1), !IsAdd); |
| 3553 | if (IsAdd && GetInitVarDecl(CE->getArg(1)) == Var) |
| 3554 | return SetStep(CE->getArg(0), false); |
| 3555 | } |
| 3556 | } |
| 3557 | SemaRef.Diag(RHS->getLocStart(), diag::err_omp_loop_not_canonical_incr) |
| 3558 | << RHS->getSourceRange() << Var; |
| 3559 | return true; |
| 3560 | } |
| 3561 | |
| 3562 | bool OpenMPIterationSpaceChecker::CheckInc(Expr *S) { |
| 3563 | // Check incr-expr for canonical loop form and return true if it |
| 3564 | // does not conform. |
| 3565 | // OpenMP [2.6] Canonical loop form. Test-expr may be one of the following: |
| 3566 | // ++var |
| 3567 | // var++ |
| 3568 | // --var |
| 3569 | // var-- |
| 3570 | // var += incr |
| 3571 | // var -= incr |
| 3572 | // var = var + incr |
| 3573 | // var = incr + var |
| 3574 | // var = var - incr |
| 3575 | // |
| 3576 | if (!S) { |
| 3577 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_incr) << Var; |
| 3578 | return true; |
| 3579 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3580 | IncrementSrcRange = S->getSourceRange(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3581 | S = S->IgnoreParens(); |
| 3582 | if (auto UO = dyn_cast<UnaryOperator>(S)) { |
| 3583 | if (UO->isIncrementDecrementOp() && GetInitVarDecl(UO->getSubExpr()) == Var) |
| 3584 | return SetStep( |
| 3585 | SemaRef.ActOnIntegerConstant(UO->getLocStart(), |
| 3586 | (UO->isDecrementOp() ? -1 : 1)).get(), |
| 3587 | false); |
| 3588 | } else if (auto BO = dyn_cast<BinaryOperator>(S)) { |
| 3589 | switch (BO->getOpcode()) { |
| 3590 | case BO_AddAssign: |
| 3591 | case BO_SubAssign: |
| 3592 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 3593 | return SetStep(BO->getRHS(), BO->getOpcode() == BO_SubAssign); |
| 3594 | break; |
| 3595 | case BO_Assign: |
| 3596 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 3597 | return CheckIncRHS(BO->getRHS()); |
| 3598 | break; |
| 3599 | default: |
| 3600 | break; |
| 3601 | } |
| 3602 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
| 3603 | switch (CE->getOperator()) { |
| 3604 | case OO_PlusPlus: |
| 3605 | case OO_MinusMinus: |
| 3606 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 3607 | return SetStep( |
| 3608 | SemaRef.ActOnIntegerConstant( |
| 3609 | CE->getLocStart(), |
| 3610 | ((CE->getOperator() == OO_MinusMinus) ? -1 : 1)).get(), |
| 3611 | false); |
| 3612 | break; |
| 3613 | case OO_PlusEqual: |
| 3614 | case OO_MinusEqual: |
| 3615 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 3616 | return SetStep(CE->getArg(1), CE->getOperator() == OO_MinusEqual); |
| 3617 | break; |
| 3618 | case OO_Equal: |
| 3619 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 3620 | return CheckIncRHS(CE->getArg(1)); |
| 3621 | break; |
| 3622 | default: |
| 3623 | break; |
| 3624 | } |
| 3625 | } |
| 3626 | SemaRef.Diag(S->getLocStart(), diag::err_omp_loop_not_canonical_incr) |
| 3627 | << S->getSourceRange() << Var; |
| 3628 | return true; |
| 3629 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3630 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3631 | static ExprResult |
| 3632 | tryBuildCapture(Sema &SemaRef, Expr *Capture, |
| 3633 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) { |
| 3634 | if (Capture->isEvaluatable(SemaRef.Context, Expr::SE_AllowSideEffects)) |
| 3635 | return SemaRef.PerformImplicitConversion( |
| 3636 | Capture->IgnoreImpCasts(), Capture->getType(), Sema::AA_Converting, |
| 3637 | /*AllowExplicit=*/true); |
| 3638 | auto I = Captures.find(Capture); |
| 3639 | if (I != Captures.end()) |
| 3640 | return buildCapture(SemaRef, Capture, I->second); |
| 3641 | DeclRefExpr *Ref = nullptr; |
| 3642 | ExprResult Res = buildCapture(SemaRef, Capture, Ref); |
| 3643 | Captures[Capture] = Ref; |
| 3644 | return Res; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3645 | } |
| 3646 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3647 | /// \brief Build the expression to calculate the number of iterations. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3648 | Expr *OpenMPIterationSpaceChecker::BuildNumIterations( |
| 3649 | Scope *S, const bool LimitedType, |
| 3650 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) const { |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3651 | ExprResult Diff; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3652 | auto VarType = Var->getType().getNonReferenceType(); |
| 3653 | if (VarType->isIntegerType() || VarType->isPointerType() || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3654 | SemaRef.getLangOpts().CPlusPlus) { |
| 3655 | // Upper - Lower |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3656 | auto *UBExpr = TestIsLessOp ? UB : LB; |
| 3657 | auto *LBExpr = TestIsLessOp ? LB : UB; |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3658 | Expr *Upper = tryBuildCapture(SemaRef, UBExpr, Captures).get(); |
| 3659 | Expr *Lower = tryBuildCapture(SemaRef, LBExpr, Captures).get(); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3660 | if (!Upper || !Lower) |
| 3661 | return nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3662 | |
| 3663 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Sub, Upper, Lower); |
| 3664 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3665 | if (!Diff.isUsable() && VarType->getAsCXXRecordDecl()) { |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3666 | // BuildBinOp already emitted error, this one is to point user to upper |
| 3667 | // and lower bound, and to tell what is passed to 'operator-'. |
| 3668 | SemaRef.Diag(Upper->getLocStart(), diag::err_omp_loop_diff_cxx) |
| 3669 | << Upper->getSourceRange() << Lower->getSourceRange(); |
| 3670 | return nullptr; |
| 3671 | } |
| 3672 | } |
| 3673 | |
| 3674 | if (!Diff.isUsable()) |
| 3675 | return nullptr; |
| 3676 | |
| 3677 | // Upper - Lower [- 1] |
| 3678 | if (TestIsStrictOp) |
| 3679 | Diff = SemaRef.BuildBinOp( |
| 3680 | S, DefaultLoc, BO_Sub, Diff.get(), |
| 3681 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 3682 | if (!Diff.isUsable()) |
| 3683 | return nullptr; |
| 3684 | |
| 3685 | // Upper - Lower [- 1] + Step |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3686 | auto NewStep = tryBuildCapture(SemaRef, Step, Captures); |
| 3687 | if (!NewStep.isUsable()) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3688 | return nullptr; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3689 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Add, Diff.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3690 | if (!Diff.isUsable()) |
| 3691 | return nullptr; |
| 3692 | |
| 3693 | // Parentheses (for dumping/debugging purposes only). |
| 3694 | Diff = SemaRef.ActOnParenExpr(DefaultLoc, DefaultLoc, Diff.get()); |
| 3695 | if (!Diff.isUsable()) |
| 3696 | return nullptr; |
| 3697 | |
| 3698 | // (Upper - Lower [- 1] + Step) / Step |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3699 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Div, Diff.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3700 | if (!Diff.isUsable()) |
| 3701 | return nullptr; |
| 3702 | |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3703 | // OpenMP runtime requires 32-bit or 64-bit loop variables. |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3704 | QualType Type = Diff.get()->getType(); |
| 3705 | auto &C = SemaRef.Context; |
| 3706 | bool UseVarType = VarType->hasIntegerRepresentation() && |
| 3707 | C.getTypeSize(Type) > C.getTypeSize(VarType); |
| 3708 | if (!Type->isIntegerType() || UseVarType) { |
| 3709 | unsigned NewSize = |
| 3710 | UseVarType ? C.getTypeSize(VarType) : C.getTypeSize(Type); |
| 3711 | bool IsSigned = UseVarType ? VarType->hasSignedIntegerRepresentation() |
| 3712 | : Type->hasSignedIntegerRepresentation(); |
| 3713 | Type = C.getIntTypeForBitwidth(NewSize, IsSigned); |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 3714 | if (!SemaRef.Context.hasSameType(Diff.get()->getType(), Type)) { |
| 3715 | Diff = SemaRef.PerformImplicitConversion( |
| 3716 | Diff.get(), Type, Sema::AA_Converting, /*AllowExplicit=*/true); |
| 3717 | if (!Diff.isUsable()) |
| 3718 | return nullptr; |
| 3719 | } |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3720 | } |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3721 | if (LimitedType) { |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3722 | unsigned NewSize = (C.getTypeSize(Type) > 32) ? 64 : 32; |
| 3723 | if (NewSize != C.getTypeSize(Type)) { |
| 3724 | if (NewSize < C.getTypeSize(Type)) { |
| 3725 | assert(NewSize == 64 && "incorrect loop var size"); |
| 3726 | SemaRef.Diag(DefaultLoc, diag::warn_omp_loop_64_bit_var) |
| 3727 | << InitSrcRange << ConditionSrcRange; |
| 3728 | } |
| 3729 | QualType NewType = C.getIntTypeForBitwidth( |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3730 | NewSize, Type->hasSignedIntegerRepresentation() || |
| 3731 | C.getTypeSize(Type) < NewSize); |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 3732 | if (!SemaRef.Context.hasSameType(Diff.get()->getType(), NewType)) { |
| 3733 | Diff = SemaRef.PerformImplicitConversion(Diff.get(), NewType, |
| 3734 | Sema::AA_Converting, true); |
| 3735 | if (!Diff.isUsable()) |
| 3736 | return nullptr; |
| 3737 | } |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3738 | } |
| 3739 | } |
| 3740 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3741 | return Diff.get(); |
| 3742 | } |
| 3743 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3744 | Expr *OpenMPIterationSpaceChecker::BuildPreCond( |
| 3745 | Scope *S, Expr *Cond, |
| 3746 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) const { |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3747 | // Try to build LB <op> UB, where <op> is <, >, <=, or >=. |
| 3748 | bool Suppress = SemaRef.getDiagnostics().getSuppressAllDiagnostics(); |
| 3749 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(/*Val=*/true); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3750 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3751 | auto NewLB = tryBuildCapture(SemaRef, LB, Captures); |
| 3752 | auto NewUB = tryBuildCapture(SemaRef, UB, Captures); |
| 3753 | if (!NewLB.isUsable() || !NewUB.isUsable()) |
| 3754 | return nullptr; |
| 3755 | |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3756 | auto CondExpr = SemaRef.BuildBinOp( |
| 3757 | S, DefaultLoc, TestIsLessOp ? (TestIsStrictOp ? BO_LT : BO_LE) |
| 3758 | : (TestIsStrictOp ? BO_GT : BO_GE), |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3759 | NewLB.get(), NewUB.get()); |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3760 | if (CondExpr.isUsable()) { |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3761 | if (!SemaRef.Context.hasSameUnqualifiedType(CondExpr.get()->getType(), |
| 3762 | SemaRef.Context.BoolTy)) |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 3763 | CondExpr = SemaRef.PerformImplicitConversion( |
| 3764 | CondExpr.get(), SemaRef.Context.BoolTy, /*Action=*/Sema::AA_Casting, |
| 3765 | /*AllowExplicit=*/true); |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3766 | } |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3767 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(Suppress); |
| 3768 | // Otherwise use original loop conditon and evaluate it in runtime. |
| 3769 | return CondExpr.isUsable() ? CondExpr.get() : Cond; |
| 3770 | } |
| 3771 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3772 | /// \brief Build reference expression to the counter be used for codegen. |
| 3773 | Expr *OpenMPIterationSpaceChecker::BuildCounterVar() const { |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3774 | return buildDeclRefExpr(SemaRef, Var, Var->getType().getNonReferenceType(), |
| 3775 | DefaultLoc); |
| 3776 | } |
| 3777 | |
| 3778 | Expr *OpenMPIterationSpaceChecker::BuildPrivateCounterVar() const { |
| 3779 | if (Var && !Var->isInvalidDecl()) { |
| 3780 | auto Type = Var->getType().getNonReferenceType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 3781 | auto *PrivateVar = |
| 3782 | buildVarDecl(SemaRef, DefaultLoc, Type, Var->getName(), |
| 3783 | Var->hasAttrs() ? &Var->getAttrs() : nullptr); |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3784 | if (PrivateVar->isInvalidDecl()) |
| 3785 | return nullptr; |
| 3786 | return buildDeclRefExpr(SemaRef, PrivateVar, Type, DefaultLoc); |
| 3787 | } |
| 3788 | return nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3789 | } |
| 3790 | |
| 3791 | /// \brief Build initization of the counter be used for codegen. |
| 3792 | Expr *OpenMPIterationSpaceChecker::BuildCounterInit() const { return LB; } |
| 3793 | |
| 3794 | /// \brief Build step of the counter be used for codegen. |
| 3795 | Expr *OpenMPIterationSpaceChecker::BuildCounterStep() const { return Step; } |
| 3796 | |
| 3797 | /// \brief Iteration space of a single for loop. |
| 3798 | struct LoopIterationSpace { |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3799 | /// \brief Condition of the loop. |
| 3800 | Expr *PreCond; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3801 | /// \brief This expression calculates the number of iterations in the loop. |
| 3802 | /// It is always possible to calculate it before starting the loop. |
| 3803 | Expr *NumIterations; |
| 3804 | /// \brief The loop counter variable. |
| 3805 | Expr *CounterVar; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3806 | /// \brief Private loop counter variable. |
| 3807 | Expr *PrivateCounterVar; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3808 | /// \brief This is initializer for the initial value of #CounterVar. |
| 3809 | Expr *CounterInit; |
| 3810 | /// \brief This is step for the #CounterVar used to generate its update: |
| 3811 | /// #CounterVar = #CounterInit + #CounterStep * CurrentIteration. |
| 3812 | Expr *CounterStep; |
| 3813 | /// \brief Should step be subtracted? |
| 3814 | bool Subtract; |
| 3815 | /// \brief Source range of the loop init. |
| 3816 | SourceRange InitSrcRange; |
| 3817 | /// \brief Source range of the loop condition. |
| 3818 | SourceRange CondSrcRange; |
| 3819 | /// \brief Source range of the loop increment. |
| 3820 | SourceRange IncSrcRange; |
| 3821 | }; |
| 3822 | |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 3823 | } // namespace |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3824 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3825 | void Sema::ActOnOpenMPLoopInitialization(SourceLocation ForLoc, Stmt *Init) { |
| 3826 | assert(getLangOpts().OpenMP && "OpenMP is not active."); |
| 3827 | assert(Init && "Expected loop in canonical form."); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 3828 | unsigned AssociatedLoops = DSAStack->getAssociatedLoops(); |
| 3829 | if (AssociatedLoops > 0 && |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3830 | isOpenMPLoopDirective(DSAStack->getCurrentDirective())) { |
| 3831 | OpenMPIterationSpaceChecker ISC(*this, ForLoc); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 3832 | if (!ISC.CheckInit(Init, /*EmitDiags=*/false)) |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3833 | DSAStack->addLoopControlVariable(ISC.GetLoopVar()); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 3834 | DSAStack->setAssociatedLoops(AssociatedLoops - 1); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3835 | } |
| 3836 | } |
| 3837 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3838 | /// \brief Called on a for stmt to check and extract its iteration space |
| 3839 | /// for further processing (such as collapsing). |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3840 | static bool CheckOpenMPIterationSpace( |
| 3841 | OpenMPDirectiveKind DKind, Stmt *S, Sema &SemaRef, DSAStackTy &DSA, |
| 3842 | unsigned CurrentNestedLoopCount, unsigned NestedLoopCount, |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3843 | Expr *CollapseLoopCountExpr, Expr *OrderedLoopCountExpr, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 3844 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3845 | LoopIterationSpace &ResultIterSpace, |
| 3846 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3847 | // OpenMP [2.6, Canonical Loop Form] |
| 3848 | // for (init-expr; test-expr; incr-expr) structured-block |
| 3849 | auto For = dyn_cast_or_null<ForStmt>(S); |
| 3850 | if (!For) { |
| 3851 | SemaRef.Diag(S->getLocStart(), diag::err_omp_not_for) |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3852 | << (CollapseLoopCountExpr != nullptr || OrderedLoopCountExpr != nullptr) |
| 3853 | << getOpenMPDirectiveName(DKind) << NestedLoopCount |
| 3854 | << (CurrentNestedLoopCount > 0) << CurrentNestedLoopCount; |
| 3855 | if (NestedLoopCount > 1) { |
| 3856 | if (CollapseLoopCountExpr && OrderedLoopCountExpr) |
| 3857 | SemaRef.Diag(DSA.getConstructLoc(), |
| 3858 | diag::note_omp_collapse_ordered_expr) |
| 3859 | << 2 << CollapseLoopCountExpr->getSourceRange() |
| 3860 | << OrderedLoopCountExpr->getSourceRange(); |
| 3861 | else if (CollapseLoopCountExpr) |
| 3862 | SemaRef.Diag(CollapseLoopCountExpr->getExprLoc(), |
| 3863 | diag::note_omp_collapse_ordered_expr) |
| 3864 | << 0 << CollapseLoopCountExpr->getSourceRange(); |
| 3865 | else |
| 3866 | SemaRef.Diag(OrderedLoopCountExpr->getExprLoc(), |
| 3867 | diag::note_omp_collapse_ordered_expr) |
| 3868 | << 1 << OrderedLoopCountExpr->getSourceRange(); |
| 3869 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3870 | return true; |
| 3871 | } |
| 3872 | assert(For->getBody()); |
| 3873 | |
| 3874 | OpenMPIterationSpaceChecker ISC(SemaRef, For->getForLoc()); |
| 3875 | |
| 3876 | // Check init. |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 3877 | auto Init = For->getInit(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3878 | if (ISC.CheckInit(Init)) { |
| 3879 | return true; |
| 3880 | } |
| 3881 | |
| 3882 | bool HasErrors = false; |
| 3883 | |
| 3884 | // Check loop variable's type. |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 3885 | auto Var = ISC.GetLoopVar(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3886 | |
| 3887 | // OpenMP [2.6, Canonical Loop Form] |
| 3888 | // Var is one of the following: |
| 3889 | // A variable of signed or unsigned integer type. |
| 3890 | // For C++, a variable of a random access iterator type. |
| 3891 | // For C, a variable of a pointer type. |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3892 | auto VarType = Var->getType().getNonReferenceType(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3893 | if (!VarType->isDependentType() && !VarType->isIntegerType() && |
| 3894 | !VarType->isPointerType() && |
| 3895 | !(SemaRef.getLangOpts().CPlusPlus && VarType->isOverloadableType())) { |
| 3896 | SemaRef.Diag(Init->getLocStart(), diag::err_omp_loop_variable_type) |
| 3897 | << SemaRef.getLangOpts().CPlusPlus; |
| 3898 | HasErrors = true; |
| 3899 | } |
| 3900 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3901 | // OpenMP, 2.14.1.1 Data-sharing Attribute Rules for Variables Referenced in a |
| 3902 | // Construct |
| 3903 | // The loop iteration variable(s) in the associated for-loop(s) of a for or |
| 3904 | // parallel for construct is (are) private. |
| 3905 | // The loop iteration variable in the associated for-loop of a simd construct |
| 3906 | // with just one associated for-loop is linear with a constant-linear-step |
| 3907 | // that is the increment of the associated for-loop. |
| 3908 | // Exclude loop var from the list of variables with implicitly defined data |
| 3909 | // sharing attributes. |
Benjamin Kramer | ad8e079 | 2014-10-10 15:32:48 +0000 | [diff] [blame] | 3910 | VarsWithImplicitDSA.erase(Var); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3911 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3912 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced in |
| 3913 | // a Construct, C/C++]. |
Alexey Bataev | cefffae | 2014-06-23 08:21:53 +0000 | [diff] [blame] | 3914 | // The loop iteration variable in the associated for-loop of a simd construct |
| 3915 | // with just one associated for-loop may be listed in a linear clause with a |
| 3916 | // constant-linear-step that is the increment of the associated for-loop. |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3917 | // The loop iteration variable(s) in the associated for-loop(s) of a for or |
| 3918 | // parallel for construct may be listed in a private or lastprivate clause. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 3919 | DSAStackTy::DSAVarData DVar = DSA.getTopDSA(Var, false); |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3920 | auto LoopVarRefExpr = ISC.GetLoopVarRefExpr(); |
| 3921 | // If LoopVarRefExpr is nullptr it means the corresponding loop variable is |
| 3922 | // declared in the loop and it is predetermined as a private. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3923 | auto PredeterminedCKind = |
| 3924 | isOpenMPSimdDirective(DKind) |
| 3925 | ? ((NestedLoopCount == 1) ? OMPC_linear : OMPC_lastprivate) |
| 3926 | : OMPC_private; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3927 | if (((isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown && |
Alexey Bataev | e648e80 | 2015-12-25 13:38:08 +0000 | [diff] [blame] | 3928 | DVar.CKind != PredeterminedCKind) || |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 3929 | ((isOpenMPWorksharingDirective(DKind) || DKind == OMPD_taskloop || |
Alexey Bataev | e648e80 | 2015-12-25 13:38:08 +0000 | [diff] [blame] | 3930 | isOpenMPDistributeDirective(DKind)) && |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 3931 | !isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown && |
Alexey Bataev | e648e80 | 2015-12-25 13:38:08 +0000 | [diff] [blame] | 3932 | DVar.CKind != OMPC_private && DVar.CKind != OMPC_lastprivate)) && |
| 3933 | (DVar.CKind != OMPC_private || DVar.RefExpr != nullptr)) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3934 | SemaRef.Diag(Init->getLocStart(), diag::err_omp_loop_var_dsa) |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3935 | << getOpenMPClauseName(DVar.CKind) << getOpenMPDirectiveName(DKind) |
| 3936 | << getOpenMPClauseName(PredeterminedCKind); |
Alexey Bataev | f2453a0 | 2015-05-06 07:25:08 +0000 | [diff] [blame] | 3937 | if (DVar.RefExpr == nullptr) |
| 3938 | DVar.CKind = PredeterminedCKind; |
| 3939 | ReportOriginalDSA(SemaRef, &DSA, Var, DVar, /*IsLoopIterVar=*/true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3940 | HasErrors = true; |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3941 | } else if (LoopVarRefExpr != nullptr) { |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3942 | // Make the loop iteration variable private (for worksharing constructs), |
| 3943 | // linear (for simd directives with the only one associated loop) or |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3944 | // lastprivate (for simd directives with several collapsed or ordered |
| 3945 | // loops). |
Alexey Bataev | 9aba41c | 2014-11-14 04:08:45 +0000 | [diff] [blame] | 3946 | if (DVar.CKind == OMPC_unknown) |
| 3947 | DVar = DSA.hasDSA(Var, isOpenMPPrivate, MatchesAlways(), |
| 3948 | /*FromParent=*/false); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3949 | DSA.addDSA(Var, LoopVarRefExpr, PredeterminedCKind); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3950 | } |
| 3951 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 3952 | assert(isOpenMPLoopDirective(DKind) && "DSA for non-loop vars"); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 3953 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3954 | // Check test-expr. |
| 3955 | HasErrors |= ISC.CheckCond(For->getCond()); |
| 3956 | |
| 3957 | // Check incr-expr. |
| 3958 | HasErrors |= ISC.CheckInc(For->getInc()); |
| 3959 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3960 | if (ISC.Dependent() || SemaRef.CurContext->isDependentContext() || HasErrors) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3961 | return HasErrors; |
| 3962 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3963 | // Build the loop's iteration space representation. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3964 | ResultIterSpace.PreCond = |
| 3965 | ISC.BuildPreCond(DSA.getCurScope(), For->getCond(), Captures); |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3966 | ResultIterSpace.NumIterations = ISC.BuildNumIterations( |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3967 | DSA.getCurScope(), |
| 3968 | (isOpenMPWorksharingDirective(DKind) || |
| 3969 | isOpenMPTaskLoopDirective(DKind) || isOpenMPDistributeDirective(DKind)), |
| 3970 | Captures); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3971 | ResultIterSpace.CounterVar = ISC.BuildCounterVar(); |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3972 | ResultIterSpace.PrivateCounterVar = ISC.BuildPrivateCounterVar(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3973 | ResultIterSpace.CounterInit = ISC.BuildCounterInit(); |
| 3974 | ResultIterSpace.CounterStep = ISC.BuildCounterStep(); |
| 3975 | ResultIterSpace.InitSrcRange = ISC.GetInitSrcRange(); |
| 3976 | ResultIterSpace.CondSrcRange = ISC.GetConditionSrcRange(); |
| 3977 | ResultIterSpace.IncSrcRange = ISC.GetIncrementSrcRange(); |
| 3978 | ResultIterSpace.Subtract = ISC.ShouldSubtractStep(); |
| 3979 | |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3980 | HasErrors |= (ResultIterSpace.PreCond == nullptr || |
| 3981 | ResultIterSpace.NumIterations == nullptr || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3982 | ResultIterSpace.CounterVar == nullptr || |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3983 | ResultIterSpace.PrivateCounterVar == nullptr || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3984 | ResultIterSpace.CounterInit == nullptr || |
| 3985 | ResultIterSpace.CounterStep == nullptr); |
| 3986 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3987 | return HasErrors; |
| 3988 | } |
| 3989 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3990 | /// \brief Build 'VarRef = Start. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3991 | static ExprResult |
| 3992 | BuildCounterInit(Sema &SemaRef, Scope *S, SourceLocation Loc, ExprResult VarRef, |
| 3993 | ExprResult Start, |
| 3994 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) { |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3995 | // Build 'VarRef = Start. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3996 | auto NewStart = tryBuildCapture(SemaRef, Start.get(), Captures); |
| 3997 | if (!NewStart.isUsable()) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3998 | return ExprError(); |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 3999 | if (!SemaRef.Context.hasSameType(NewStart.get()->getType(), |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 4000 | VarRef.get()->getType())) { |
| 4001 | NewStart = SemaRef.PerformImplicitConversion( |
| 4002 | NewStart.get(), VarRef.get()->getType(), Sema::AA_Converting, |
| 4003 | /*AllowExplicit=*/true); |
| 4004 | if (!NewStart.isUsable()) |
| 4005 | return ExprError(); |
| 4006 | } |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4007 | |
| 4008 | auto Init = |
| 4009 | SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), NewStart.get()); |
| 4010 | return Init; |
| 4011 | } |
| 4012 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4013 | /// \brief Build 'VarRef = Start + Iter * Step'. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4014 | static ExprResult |
| 4015 | BuildCounterUpdate(Sema &SemaRef, Scope *S, SourceLocation Loc, |
| 4016 | ExprResult VarRef, ExprResult Start, ExprResult Iter, |
| 4017 | ExprResult Step, bool Subtract, |
| 4018 | llvm::MapVector<Expr *, DeclRefExpr *> *Captures = nullptr) { |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4019 | // Add parentheses (for debugging purposes only). |
| 4020 | Iter = SemaRef.ActOnParenExpr(Loc, Loc, Iter.get()); |
| 4021 | if (!VarRef.isUsable() || !Start.isUsable() || !Iter.isUsable() || |
| 4022 | !Step.isUsable()) |
| 4023 | return ExprError(); |
| 4024 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4025 | ExprResult NewStep = Step; |
| 4026 | if (Captures) |
| 4027 | NewStep = tryBuildCapture(SemaRef, Step.get(), *Captures); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4028 | if (NewStep.isInvalid()) |
| 4029 | return ExprError(); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4030 | ExprResult Update = |
| 4031 | SemaRef.BuildBinOp(S, Loc, BO_Mul, Iter.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4032 | if (!Update.isUsable()) |
| 4033 | return ExprError(); |
| 4034 | |
Alexey Bataev | c0214e0 | 2016-02-16 12:13:49 +0000 | [diff] [blame] | 4035 | // Try to build 'VarRef = Start, VarRef (+|-)= Iter * Step' or |
| 4036 | // 'VarRef = Start (+|-) Iter * Step'. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4037 | ExprResult NewStart = Start; |
| 4038 | if (Captures) |
| 4039 | NewStart = tryBuildCapture(SemaRef, Start.get(), *Captures); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4040 | if (NewStart.isInvalid()) |
| 4041 | return ExprError(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4042 | |
Alexey Bataev | c0214e0 | 2016-02-16 12:13:49 +0000 | [diff] [blame] | 4043 | // First attempt: try to build 'VarRef = Start, VarRef += Iter * Step'. |
| 4044 | ExprResult SavedUpdate = Update; |
| 4045 | ExprResult UpdateVal; |
| 4046 | if (VarRef.get()->getType()->isOverloadableType() || |
| 4047 | NewStart.get()->getType()->isOverloadableType() || |
| 4048 | Update.get()->getType()->isOverloadableType()) { |
| 4049 | bool Suppress = SemaRef.getDiagnostics().getSuppressAllDiagnostics(); |
| 4050 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(/*Val=*/true); |
| 4051 | Update = |
| 4052 | SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), NewStart.get()); |
| 4053 | if (Update.isUsable()) { |
| 4054 | UpdateVal = |
| 4055 | SemaRef.BuildBinOp(S, Loc, Subtract ? BO_SubAssign : BO_AddAssign, |
| 4056 | VarRef.get(), SavedUpdate.get()); |
| 4057 | if (UpdateVal.isUsable()) { |
| 4058 | Update = SemaRef.CreateBuiltinBinOp(Loc, BO_Comma, Update.get(), |
| 4059 | UpdateVal.get()); |
| 4060 | } |
| 4061 | } |
| 4062 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(Suppress); |
| 4063 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4064 | |
Alexey Bataev | c0214e0 | 2016-02-16 12:13:49 +0000 | [diff] [blame] | 4065 | // Second attempt: try to build 'VarRef = Start (+|-) Iter * Step'. |
| 4066 | if (!Update.isUsable() || !UpdateVal.isUsable()) { |
| 4067 | Update = SemaRef.BuildBinOp(S, Loc, Subtract ? BO_Sub : BO_Add, |
| 4068 | NewStart.get(), SavedUpdate.get()); |
| 4069 | if (!Update.isUsable()) |
| 4070 | return ExprError(); |
| 4071 | |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 4072 | if (!SemaRef.Context.hasSameType(Update.get()->getType(), |
| 4073 | VarRef.get()->getType())) { |
| 4074 | Update = SemaRef.PerformImplicitConversion( |
| 4075 | Update.get(), VarRef.get()->getType(), Sema::AA_Converting, true); |
| 4076 | if (!Update.isUsable()) |
| 4077 | return ExprError(); |
| 4078 | } |
Alexey Bataev | c0214e0 | 2016-02-16 12:13:49 +0000 | [diff] [blame] | 4079 | |
| 4080 | Update = SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), Update.get()); |
| 4081 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4082 | return Update; |
| 4083 | } |
| 4084 | |
| 4085 | /// \brief Convert integer expression \a E to make it have at least \a Bits |
| 4086 | /// bits. |
| 4087 | static ExprResult WidenIterationCount(unsigned Bits, Expr *E, |
| 4088 | Sema &SemaRef) { |
| 4089 | if (E == nullptr) |
| 4090 | return ExprError(); |
| 4091 | auto &C = SemaRef.Context; |
| 4092 | QualType OldType = E->getType(); |
| 4093 | unsigned HasBits = C.getTypeSize(OldType); |
| 4094 | if (HasBits >= Bits) |
| 4095 | return ExprResult(E); |
| 4096 | // OK to convert to signed, because new type has more bits than old. |
| 4097 | QualType NewType = C.getIntTypeForBitwidth(Bits, /* Signed */ true); |
| 4098 | return SemaRef.PerformImplicitConversion(E, NewType, Sema::AA_Converting, |
| 4099 | true); |
| 4100 | } |
| 4101 | |
| 4102 | /// \brief Check if the given expression \a E is a constant integer that fits |
| 4103 | /// into \a Bits bits. |
| 4104 | static bool FitsInto(unsigned Bits, bool Signed, Expr *E, Sema &SemaRef) { |
| 4105 | if (E == nullptr) |
| 4106 | return false; |
| 4107 | llvm::APSInt Result; |
| 4108 | if (E->isIntegerConstantExpr(Result, SemaRef.Context)) |
| 4109 | return Signed ? Result.isSignedIntN(Bits) : Result.isIntN(Bits); |
| 4110 | return false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4111 | } |
| 4112 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4113 | /// Build preinits statement for the given declarations. |
| 4114 | static Stmt *buildPreInits(ASTContext &Context, |
| 4115 | SmallVectorImpl<Decl *> &PreInits) { |
| 4116 | if (!PreInits.empty()) { |
| 4117 | return new (Context) DeclStmt( |
| 4118 | DeclGroupRef::Create(Context, PreInits.begin(), PreInits.size()), |
| 4119 | SourceLocation(), SourceLocation()); |
| 4120 | } |
| 4121 | return nullptr; |
| 4122 | } |
| 4123 | |
| 4124 | /// Build preinits statement for the given declarations. |
| 4125 | static Stmt *buildPreInits(ASTContext &Context, |
| 4126 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) { |
| 4127 | if (!Captures.empty()) { |
| 4128 | SmallVector<Decl *, 16> PreInits; |
| 4129 | for (auto &Pair : Captures) |
| 4130 | PreInits.push_back(Pair.second->getDecl()); |
| 4131 | return buildPreInits(Context, PreInits); |
| 4132 | } |
| 4133 | return nullptr; |
| 4134 | } |
| 4135 | |
| 4136 | /// Build postupdate expression for the given list of postupdates expressions. |
| 4137 | static Expr *buildPostUpdate(Sema &S, ArrayRef<Expr *> PostUpdates) { |
| 4138 | Expr *PostUpdate = nullptr; |
| 4139 | if (!PostUpdates.empty()) { |
| 4140 | for (auto *E : PostUpdates) { |
| 4141 | Expr *ConvE = S.BuildCStyleCastExpr( |
| 4142 | E->getExprLoc(), |
| 4143 | S.Context.getTrivialTypeSourceInfo(S.Context.VoidTy), |
| 4144 | E->getExprLoc(), E) |
| 4145 | .get(); |
| 4146 | PostUpdate = PostUpdate |
| 4147 | ? S.CreateBuiltinBinOp(ConvE->getExprLoc(), BO_Comma, |
| 4148 | PostUpdate, ConvE) |
| 4149 | .get() |
| 4150 | : ConvE; |
| 4151 | } |
| 4152 | } |
| 4153 | return PostUpdate; |
| 4154 | } |
| 4155 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4156 | /// \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] | 4157 | /// \return Returns 0 if one of the collapsed stmts is not canonical for loop, |
| 4158 | /// number of collapsed loops otherwise. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4159 | static unsigned |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4160 | CheckOpenMPLoop(OpenMPDirectiveKind DKind, Expr *CollapseLoopCountExpr, |
| 4161 | Expr *OrderedLoopCountExpr, Stmt *AStmt, Sema &SemaRef, |
| 4162 | DSAStackTy &DSA, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 4163 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA, |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4164 | OMPLoopDirective::HelperExprs &Built) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 4165 | unsigned NestedLoopCount = 1; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4166 | if (CollapseLoopCountExpr) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 4167 | // Found 'collapse' clause - calculate collapse number. |
| 4168 | llvm::APSInt Result; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4169 | if (CollapseLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext())) |
Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 4170 | NestedLoopCount = Result.getLimitedValue(); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4171 | } |
| 4172 | if (OrderedLoopCountExpr) { |
| 4173 | // Found 'ordered' clause - calculate collapse number. |
| 4174 | llvm::APSInt Result; |
Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 4175 | if (OrderedLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext())) { |
| 4176 | if (Result.getLimitedValue() < NestedLoopCount) { |
| 4177 | SemaRef.Diag(OrderedLoopCountExpr->getExprLoc(), |
| 4178 | diag::err_omp_wrong_ordered_loop_count) |
| 4179 | << OrderedLoopCountExpr->getSourceRange(); |
| 4180 | SemaRef.Diag(CollapseLoopCountExpr->getExprLoc(), |
| 4181 | diag::note_collapse_loop_count) |
| 4182 | << CollapseLoopCountExpr->getSourceRange(); |
| 4183 | } |
| 4184 | NestedLoopCount = Result.getLimitedValue(); |
| 4185 | } |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 4186 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4187 | // This is helper routine for loop directives (e.g., 'for', 'simd', |
| 4188 | // 'for simd', etc.). |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4189 | llvm::MapVector<Expr *, DeclRefExpr *> Captures; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4190 | SmallVector<LoopIterationSpace, 4> IterSpaces; |
| 4191 | IterSpaces.resize(NestedLoopCount); |
| 4192 | Stmt *CurStmt = AStmt->IgnoreContainers(/* IgnoreCaptured */ true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4193 | for (unsigned Cnt = 0; Cnt < NestedLoopCount; ++Cnt) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 4194 | if (CheckOpenMPIterationSpace(DKind, CurStmt, SemaRef, DSA, Cnt, |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4195 | NestedLoopCount, CollapseLoopCountExpr, |
| 4196 | OrderedLoopCountExpr, VarsWithImplicitDSA, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4197 | IterSpaces[Cnt], Captures)) |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 4198 | return 0; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4199 | // 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] | 4200 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 4201 | // All loops associated with the construct must be perfectly nested; that |
| 4202 | // is, there must be no intervening code nor any OpenMP directive between |
| 4203 | // any two loops. |
| 4204 | CurStmt = cast<ForStmt>(CurStmt)->getBody()->IgnoreContainers(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4205 | } |
| 4206 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4207 | Built.clear(/* size */ NestedLoopCount); |
| 4208 | |
| 4209 | if (SemaRef.CurContext->isDependentContext()) |
| 4210 | return NestedLoopCount; |
| 4211 | |
| 4212 | // An example of what is generated for the following code: |
| 4213 | // |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4214 | // #pragma omp simd collapse(2) ordered(2) |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4215 | // for (i = 0; i < NI; ++i) |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4216 | // for (k = 0; k < NK; ++k) |
| 4217 | // for (j = J0; j < NJ; j+=2) { |
| 4218 | // <loop body> |
| 4219 | // } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4220 | // |
| 4221 | // We generate the code below. |
| 4222 | // Note: the loop body may be outlined in CodeGen. |
| 4223 | // Note: some counters may be C++ classes, operator- is used to find number of |
| 4224 | // iterations and operator+= to calculate counter value. |
| 4225 | // Note: decltype(NumIterations) must be integer type (in 'omp for', only i32 |
| 4226 | // or i64 is currently supported). |
| 4227 | // |
| 4228 | // #define NumIterations (NI * ((NJ - J0 - 1 + 2) / 2)) |
| 4229 | // for (int[32|64]_t IV = 0; IV < NumIterations; ++IV ) { |
| 4230 | // .local.i = IV / ((NJ - J0 - 1 + 2) / 2); |
| 4231 | // .local.j = J0 + (IV % ((NJ - J0 - 1 + 2) / 2)) * 2; |
| 4232 | // // similar updates for vars in clauses (e.g. 'linear') |
| 4233 | // <loop body (using local i and j)> |
| 4234 | // } |
| 4235 | // i = NI; // assign final values of counters |
| 4236 | // j = NJ; |
| 4237 | // |
| 4238 | |
| 4239 | // Last iteration number is (I1 * I2 * ... In) - 1, where I1, I2 ... In are |
| 4240 | // the iteration counts of the collapsed for loops. |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 4241 | // Precondition tests if there is at least one iteration (all conditions are |
| 4242 | // true). |
| 4243 | auto PreCond = ExprResult(IterSpaces[0].PreCond); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4244 | auto N0 = IterSpaces[0].NumIterations; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4245 | ExprResult LastIteration32 = WidenIterationCount( |
| 4246 | 32 /* Bits */, SemaRef.PerformImplicitConversion( |
| 4247 | N0->IgnoreImpCasts(), N0->getType(), |
| 4248 | Sema::AA_Converting, /*AllowExplicit=*/true) |
| 4249 | .get(), |
| 4250 | SemaRef); |
| 4251 | ExprResult LastIteration64 = WidenIterationCount( |
| 4252 | 64 /* Bits */, SemaRef.PerformImplicitConversion( |
| 4253 | N0->IgnoreImpCasts(), N0->getType(), |
| 4254 | Sema::AA_Converting, /*AllowExplicit=*/true) |
| 4255 | .get(), |
| 4256 | SemaRef); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4257 | |
| 4258 | if (!LastIteration32.isUsable() || !LastIteration64.isUsable()) |
| 4259 | return NestedLoopCount; |
| 4260 | |
| 4261 | auto &C = SemaRef.Context; |
| 4262 | bool AllCountsNeedLessThan32Bits = C.getTypeSize(N0->getType()) < 32; |
| 4263 | |
| 4264 | Scope *CurScope = DSA.getCurScope(); |
| 4265 | for (unsigned Cnt = 1; Cnt < NestedLoopCount; ++Cnt) { |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 4266 | if (PreCond.isUsable()) { |
| 4267 | PreCond = SemaRef.BuildBinOp(CurScope, SourceLocation(), BO_LAnd, |
| 4268 | PreCond.get(), IterSpaces[Cnt].PreCond); |
| 4269 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4270 | auto N = IterSpaces[Cnt].NumIterations; |
| 4271 | AllCountsNeedLessThan32Bits &= C.getTypeSize(N->getType()) < 32; |
| 4272 | if (LastIteration32.isUsable()) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4273 | LastIteration32 = SemaRef.BuildBinOp( |
| 4274 | CurScope, SourceLocation(), BO_Mul, LastIteration32.get(), |
| 4275 | SemaRef.PerformImplicitConversion(N->IgnoreImpCasts(), N->getType(), |
| 4276 | Sema::AA_Converting, |
| 4277 | /*AllowExplicit=*/true) |
| 4278 | .get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4279 | if (LastIteration64.isUsable()) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4280 | LastIteration64 = SemaRef.BuildBinOp( |
| 4281 | CurScope, SourceLocation(), BO_Mul, LastIteration64.get(), |
| 4282 | SemaRef.PerformImplicitConversion(N->IgnoreImpCasts(), N->getType(), |
| 4283 | Sema::AA_Converting, |
| 4284 | /*AllowExplicit=*/true) |
| 4285 | .get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4286 | } |
| 4287 | |
| 4288 | // Choose either the 32-bit or 64-bit version. |
| 4289 | ExprResult LastIteration = LastIteration64; |
| 4290 | if (LastIteration32.isUsable() && |
| 4291 | C.getTypeSize(LastIteration32.get()->getType()) == 32 && |
| 4292 | (AllCountsNeedLessThan32Bits || NestedLoopCount == 1 || |
| 4293 | FitsInto( |
| 4294 | 32 /* Bits */, |
| 4295 | LastIteration32.get()->getType()->hasSignedIntegerRepresentation(), |
| 4296 | LastIteration64.get(), SemaRef))) |
| 4297 | LastIteration = LastIteration32; |
| 4298 | |
| 4299 | if (!LastIteration.isUsable()) |
| 4300 | return 0; |
| 4301 | |
| 4302 | // Save the number of iterations. |
| 4303 | ExprResult NumIterations = LastIteration; |
| 4304 | { |
| 4305 | LastIteration = SemaRef.BuildBinOp( |
| 4306 | CurScope, SourceLocation(), BO_Sub, LastIteration.get(), |
| 4307 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 4308 | if (!LastIteration.isUsable()) |
| 4309 | return 0; |
| 4310 | } |
| 4311 | |
| 4312 | // Calculate the last iteration number beforehand instead of doing this on |
| 4313 | // each iteration. Do not do this if the number of iterations may be kfold-ed. |
| 4314 | llvm::APSInt Result; |
| 4315 | bool IsConstant = |
| 4316 | LastIteration.get()->isIntegerConstantExpr(Result, SemaRef.Context); |
| 4317 | ExprResult CalcLastIteration; |
| 4318 | if (!IsConstant) { |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4319 | ExprResult SaveRef = |
| 4320 | tryBuildCapture(SemaRef, LastIteration.get(), Captures); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4321 | LastIteration = SaveRef; |
| 4322 | |
| 4323 | // Prepare SaveRef + 1. |
| 4324 | NumIterations = SemaRef.BuildBinOp( |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4325 | CurScope, SourceLocation(), BO_Add, SaveRef.get(), |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4326 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 4327 | if (!NumIterations.isUsable()) |
| 4328 | return 0; |
| 4329 | } |
| 4330 | |
| 4331 | SourceLocation InitLoc = IterSpaces[0].InitSrcRange.getBegin(); |
| 4332 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4333 | QualType VType = LastIteration.get()->getType(); |
| 4334 | // Build variables passed into runtime, nesessary for worksharing directives. |
| 4335 | ExprResult LB, UB, IL, ST, EUB; |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 4336 | if (isOpenMPWorksharingDirective(DKind) || isOpenMPTaskLoopDirective(DKind) || |
| 4337 | isOpenMPDistributeDirective(DKind)) { |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4338 | // Lower bound variable, initialized with zero. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4339 | VarDecl *LBDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.lb"); |
| 4340 | LB = buildDeclRefExpr(SemaRef, LBDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4341 | SemaRef.AddInitializerToDecl( |
| 4342 | LBDecl, SemaRef.ActOnIntegerConstant(InitLoc, 0).get(), |
| 4343 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 4344 | |
| 4345 | // Upper bound variable, initialized with last iteration number. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4346 | VarDecl *UBDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.ub"); |
| 4347 | UB = buildDeclRefExpr(SemaRef, UBDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4348 | SemaRef.AddInitializerToDecl(UBDecl, LastIteration.get(), |
| 4349 | /*DirectInit*/ false, |
| 4350 | /*TypeMayContainAuto*/ false); |
| 4351 | |
| 4352 | // A 32-bit variable-flag where runtime returns 1 for the last iteration. |
| 4353 | // This will be used to implement clause 'lastprivate'. |
| 4354 | QualType Int32Ty = SemaRef.Context.getIntTypeForBitwidth(32, true); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4355 | VarDecl *ILDecl = buildVarDecl(SemaRef, InitLoc, Int32Ty, ".omp.is_last"); |
| 4356 | IL = buildDeclRefExpr(SemaRef, ILDecl, Int32Ty, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4357 | SemaRef.AddInitializerToDecl( |
| 4358 | ILDecl, SemaRef.ActOnIntegerConstant(InitLoc, 0).get(), |
| 4359 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 4360 | |
| 4361 | // Stride variable returned by runtime (we initialize it to 1 by default). |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4362 | VarDecl *STDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.stride"); |
| 4363 | ST = buildDeclRefExpr(SemaRef, STDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4364 | SemaRef.AddInitializerToDecl( |
| 4365 | STDecl, SemaRef.ActOnIntegerConstant(InitLoc, 1).get(), |
| 4366 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 4367 | |
| 4368 | // Build expression: UB = min(UB, LastIteration) |
| 4369 | // It is nesessary for CodeGen of directives with static scheduling. |
| 4370 | ExprResult IsUBGreater = SemaRef.BuildBinOp(CurScope, InitLoc, BO_GT, |
| 4371 | UB.get(), LastIteration.get()); |
| 4372 | ExprResult CondOp = SemaRef.ActOnConditionalOp( |
| 4373 | InitLoc, InitLoc, IsUBGreater.get(), LastIteration.get(), UB.get()); |
| 4374 | EUB = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, UB.get(), |
| 4375 | CondOp.get()); |
| 4376 | EUB = SemaRef.ActOnFinishFullExpr(EUB.get()); |
| 4377 | } |
| 4378 | |
| 4379 | // Build the iteration variable and its initialization before loop. |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4380 | ExprResult IV; |
| 4381 | ExprResult Init; |
| 4382 | { |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4383 | VarDecl *IVDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.iv"); |
| 4384 | IV = buildDeclRefExpr(SemaRef, IVDecl, VType, InitLoc); |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 4385 | Expr *RHS = (isOpenMPWorksharingDirective(DKind) || |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 4386 | isOpenMPTaskLoopDirective(DKind) || |
| 4387 | isOpenMPDistributeDirective(DKind)) |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4388 | ? LB.get() |
| 4389 | : SemaRef.ActOnIntegerConstant(SourceLocation(), 0).get(); |
| 4390 | Init = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, IV.get(), RHS); |
| 4391 | Init = SemaRef.ActOnFinishFullExpr(Init.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4392 | } |
| 4393 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4394 | // Loop condition (IV < NumIterations) or (IV <= UB) for worksharing loops. |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4395 | SourceLocation CondLoc; |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4396 | ExprResult Cond = |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 4397 | (isOpenMPWorksharingDirective(DKind) || |
| 4398 | isOpenMPTaskLoopDirective(DKind) || isOpenMPDistributeDirective(DKind)) |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4399 | ? SemaRef.BuildBinOp(CurScope, CondLoc, BO_LE, IV.get(), UB.get()) |
| 4400 | : SemaRef.BuildBinOp(CurScope, CondLoc, BO_LT, IV.get(), |
| 4401 | NumIterations.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4402 | |
| 4403 | // Loop increment (IV = IV + 1) |
| 4404 | SourceLocation IncLoc; |
| 4405 | ExprResult Inc = |
| 4406 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, IV.get(), |
| 4407 | SemaRef.ActOnIntegerConstant(IncLoc, 1).get()); |
| 4408 | if (!Inc.isUsable()) |
| 4409 | return 0; |
| 4410 | Inc = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, IV.get(), Inc.get()); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4411 | Inc = SemaRef.ActOnFinishFullExpr(Inc.get()); |
| 4412 | if (!Inc.isUsable()) |
| 4413 | return 0; |
| 4414 | |
| 4415 | // Increments for worksharing loops (LB = LB + ST; UB = UB + ST). |
| 4416 | // Used for directives with static scheduling. |
| 4417 | ExprResult NextLB, NextUB; |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 4418 | if (isOpenMPWorksharingDirective(DKind) || isOpenMPTaskLoopDirective(DKind) || |
| 4419 | isOpenMPDistributeDirective(DKind)) { |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4420 | // LB + ST |
| 4421 | NextLB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, LB.get(), ST.get()); |
| 4422 | if (!NextLB.isUsable()) |
| 4423 | return 0; |
| 4424 | // LB = LB + ST |
| 4425 | NextLB = |
| 4426 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, LB.get(), NextLB.get()); |
| 4427 | NextLB = SemaRef.ActOnFinishFullExpr(NextLB.get()); |
| 4428 | if (!NextLB.isUsable()) |
| 4429 | return 0; |
| 4430 | // UB + ST |
| 4431 | NextUB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, UB.get(), ST.get()); |
| 4432 | if (!NextUB.isUsable()) |
| 4433 | return 0; |
| 4434 | // UB = UB + ST |
| 4435 | NextUB = |
| 4436 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, UB.get(), NextUB.get()); |
| 4437 | NextUB = SemaRef.ActOnFinishFullExpr(NextUB.get()); |
| 4438 | if (!NextUB.isUsable()) |
| 4439 | return 0; |
| 4440 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4441 | |
| 4442 | // Build updates and final values of the loop counters. |
| 4443 | bool HasErrors = false; |
| 4444 | Built.Counters.resize(NestedLoopCount); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4445 | Built.Inits.resize(NestedLoopCount); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4446 | Built.Updates.resize(NestedLoopCount); |
| 4447 | Built.Finals.resize(NestedLoopCount); |
| 4448 | { |
| 4449 | ExprResult Div; |
| 4450 | // Go from inner nested loop to outer. |
| 4451 | for (int Cnt = NestedLoopCount - 1; Cnt >= 0; --Cnt) { |
| 4452 | LoopIterationSpace &IS = IterSpaces[Cnt]; |
| 4453 | SourceLocation UpdLoc = IS.IncSrcRange.getBegin(); |
| 4454 | // Build: Iter = (IV / Div) % IS.NumIters |
| 4455 | // where Div is product of previous iterations' IS.NumIters. |
| 4456 | ExprResult Iter; |
| 4457 | if (Div.isUsable()) { |
| 4458 | Iter = |
| 4459 | SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Div, IV.get(), Div.get()); |
| 4460 | } else { |
| 4461 | Iter = IV; |
| 4462 | assert((Cnt == (int)NestedLoopCount - 1) && |
| 4463 | "unusable div expected on first iteration only"); |
| 4464 | } |
| 4465 | |
| 4466 | if (Cnt != 0 && Iter.isUsable()) |
| 4467 | Iter = SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Rem, Iter.get(), |
| 4468 | IS.NumIterations); |
| 4469 | if (!Iter.isUsable()) { |
| 4470 | HasErrors = true; |
| 4471 | break; |
| 4472 | } |
| 4473 | |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4474 | // Build update: IS.CounterVar(Private) = IS.Start + Iter * IS.Step |
| 4475 | auto *CounterVar = buildDeclRefExpr( |
| 4476 | SemaRef, cast<VarDecl>(cast<DeclRefExpr>(IS.CounterVar)->getDecl()), |
| 4477 | IS.CounterVar->getType(), IS.CounterVar->getExprLoc(), |
| 4478 | /*RefersToCapture=*/true); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4479 | ExprResult Init = BuildCounterInit(SemaRef, CurScope, UpdLoc, CounterVar, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4480 | IS.CounterInit, Captures); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4481 | if (!Init.isUsable()) { |
| 4482 | HasErrors = true; |
| 4483 | break; |
| 4484 | } |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4485 | ExprResult Update = BuildCounterUpdate( |
| 4486 | SemaRef, CurScope, UpdLoc, CounterVar, IS.CounterInit, Iter, |
| 4487 | IS.CounterStep, IS.Subtract, &Captures); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4488 | if (!Update.isUsable()) { |
| 4489 | HasErrors = true; |
| 4490 | break; |
| 4491 | } |
| 4492 | |
| 4493 | // Build final: IS.CounterVar = IS.Start + IS.NumIters * IS.Step |
| 4494 | ExprResult Final = BuildCounterUpdate( |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4495 | SemaRef, CurScope, UpdLoc, CounterVar, IS.CounterInit, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4496 | IS.NumIterations, IS.CounterStep, IS.Subtract, &Captures); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4497 | if (!Final.isUsable()) { |
| 4498 | HasErrors = true; |
| 4499 | break; |
| 4500 | } |
| 4501 | |
| 4502 | // Build Div for the next iteration: Div <- Div * IS.NumIters |
| 4503 | if (Cnt != 0) { |
| 4504 | if (Div.isUnset()) |
| 4505 | Div = IS.NumIterations; |
| 4506 | else |
| 4507 | Div = SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Mul, Div.get(), |
| 4508 | IS.NumIterations); |
| 4509 | |
| 4510 | // Add parentheses (for debugging purposes only). |
| 4511 | if (Div.isUsable()) |
| 4512 | Div = SemaRef.ActOnParenExpr(UpdLoc, UpdLoc, Div.get()); |
| 4513 | if (!Div.isUsable()) { |
| 4514 | HasErrors = true; |
| 4515 | break; |
| 4516 | } |
| 4517 | } |
| 4518 | if (!Update.isUsable() || !Final.isUsable()) { |
| 4519 | HasErrors = true; |
| 4520 | break; |
| 4521 | } |
| 4522 | // Save results |
| 4523 | Built.Counters[Cnt] = IS.CounterVar; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 4524 | Built.PrivateCounters[Cnt] = IS.PrivateCounterVar; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4525 | Built.Inits[Cnt] = Init.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4526 | Built.Updates[Cnt] = Update.get(); |
| 4527 | Built.Finals[Cnt] = Final.get(); |
| 4528 | } |
| 4529 | } |
| 4530 | |
| 4531 | if (HasErrors) |
| 4532 | return 0; |
| 4533 | |
| 4534 | // Save results |
| 4535 | Built.IterationVarRef = IV.get(); |
| 4536 | Built.LastIteration = LastIteration.get(); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 4537 | Built.NumIterations = NumIterations.get(); |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 4538 | Built.CalcLastIteration = |
| 4539 | SemaRef.ActOnFinishFullExpr(CalcLastIteration.get()).get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4540 | Built.PreCond = PreCond.get(); |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4541 | Built.PreInits = buildPreInits(C, Captures); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4542 | Built.Cond = Cond.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4543 | Built.Init = Init.get(); |
| 4544 | Built.Inc = Inc.get(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4545 | Built.LB = LB.get(); |
| 4546 | Built.UB = UB.get(); |
| 4547 | Built.IL = IL.get(); |
| 4548 | Built.ST = ST.get(); |
| 4549 | Built.EUB = EUB.get(); |
| 4550 | Built.NLB = NextLB.get(); |
| 4551 | Built.NUB = NextUB.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4552 | |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 4553 | return NestedLoopCount; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4554 | } |
| 4555 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4556 | static Expr *getCollapseNumberExpr(ArrayRef<OMPClause *> Clauses) { |
Benjamin Kramer | fc600dc | 2015-08-30 15:12:28 +0000 | [diff] [blame] | 4557 | auto CollapseClauses = |
| 4558 | OMPExecutableDirective::getClausesOfKind<OMPCollapseClause>(Clauses); |
| 4559 | if (CollapseClauses.begin() != CollapseClauses.end()) |
| 4560 | return (*CollapseClauses.begin())->getNumForLoops(); |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 4561 | return nullptr; |
| 4562 | } |
| 4563 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4564 | static Expr *getOrderedNumberExpr(ArrayRef<OMPClause *> Clauses) { |
Benjamin Kramer | fc600dc | 2015-08-30 15:12:28 +0000 | [diff] [blame] | 4565 | auto OrderedClauses = |
| 4566 | OMPExecutableDirective::getClausesOfKind<OMPOrderedClause>(Clauses); |
| 4567 | if (OrderedClauses.begin() != OrderedClauses.end()) |
| 4568 | return (*OrderedClauses.begin())->getNumForLoops(); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4569 | return nullptr; |
| 4570 | } |
| 4571 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 4572 | static bool checkSimdlenSafelenValues(Sema &S, const Expr *Simdlen, |
| 4573 | const Expr *Safelen) { |
| 4574 | llvm::APSInt SimdlenRes, SafelenRes; |
| 4575 | if (Simdlen->isValueDependent() || Simdlen->isTypeDependent() || |
| 4576 | Simdlen->isInstantiationDependent() || |
| 4577 | Simdlen->containsUnexpandedParameterPack()) |
| 4578 | return false; |
| 4579 | if (Safelen->isValueDependent() || Safelen->isTypeDependent() || |
| 4580 | Safelen->isInstantiationDependent() || |
| 4581 | Safelen->containsUnexpandedParameterPack()) |
| 4582 | return false; |
| 4583 | Simdlen->EvaluateAsInt(SimdlenRes, S.Context); |
| 4584 | Safelen->EvaluateAsInt(SafelenRes, S.Context); |
| 4585 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 4586 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 4587 | // parameter must be less than or equal to the value of the safelen parameter. |
| 4588 | if (SimdlenRes > SafelenRes) { |
| 4589 | S.Diag(Simdlen->getExprLoc(), diag::err_omp_wrong_simdlen_safelen_values) |
| 4590 | << Simdlen->getSourceRange() << Safelen->getSourceRange(); |
| 4591 | return true; |
| 4592 | } |
| 4593 | return false; |
| 4594 | } |
| 4595 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4596 | StmtResult Sema::ActOnOpenMPSimdDirective( |
| 4597 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4598 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 4599 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4600 | if (!AStmt) |
| 4601 | return StmtError(); |
| 4602 | |
| 4603 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4604 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4605 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4606 | // define the nested loops number. |
| 4607 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 4608 | OMPD_simd, getCollapseNumberExpr(Clauses), getOrderedNumberExpr(Clauses), |
| 4609 | AStmt, *this, *DSAStack, VarsWithImplicitDSA, B); |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 4610 | if (NestedLoopCount == 0) |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 4611 | return StmtError(); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 4612 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4613 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 4614 | "omp simd loop exprs were not built"); |
| 4615 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 4616 | if (!CurContext->isDependentContext()) { |
| 4617 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4618 | for (auto C : Clauses) { |
| 4619 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 4620 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 4621 | B.NumIterations, *this, CurScope)) |
| 4622 | return StmtError(); |
| 4623 | } |
| 4624 | } |
| 4625 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 4626 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 4627 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 4628 | // parameter must be less than or equal to the value of the safelen parameter. |
| 4629 | OMPSafelenClause *Safelen = nullptr; |
| 4630 | OMPSimdlenClause *Simdlen = nullptr; |
| 4631 | for (auto *Clause : Clauses) { |
| 4632 | if (Clause->getClauseKind() == OMPC_safelen) |
| 4633 | Safelen = cast<OMPSafelenClause>(Clause); |
| 4634 | else if (Clause->getClauseKind() == OMPC_simdlen) |
| 4635 | Simdlen = cast<OMPSimdlenClause>(Clause); |
| 4636 | if (Safelen && Simdlen) |
| 4637 | break; |
| 4638 | } |
| 4639 | if (Simdlen && Safelen && |
| 4640 | checkSimdlenSafelenValues(*this, Simdlen->getSimdlen(), |
| 4641 | Safelen->getSafelen())) |
| 4642 | return StmtError(); |
| 4643 | |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 4644 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4645 | return OMPSimdDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| 4646 | Clauses, AStmt, B); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 4647 | } |
| 4648 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4649 | StmtResult Sema::ActOnOpenMPForDirective( |
| 4650 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4651 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 4652 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4653 | if (!AStmt) |
| 4654 | return StmtError(); |
| 4655 | |
| 4656 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4657 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4658 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4659 | // define the nested loops number. |
| 4660 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 4661 | OMPD_for, getCollapseNumberExpr(Clauses), getOrderedNumberExpr(Clauses), |
| 4662 | AStmt, *this, *DSAStack, VarsWithImplicitDSA, B); |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 4663 | if (NestedLoopCount == 0) |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4664 | return StmtError(); |
| 4665 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4666 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 4667 | "omp for loop exprs were not built"); |
| 4668 | |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 4669 | if (!CurContext->isDependentContext()) { |
| 4670 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4671 | for (auto C : Clauses) { |
| 4672 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 4673 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 4674 | B.NumIterations, *this, CurScope)) |
| 4675 | return StmtError(); |
| 4676 | } |
| 4677 | } |
| 4678 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4679 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4680 | return OMPForDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4681 | Clauses, AStmt, B, DSAStack->isCancelRegion()); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4682 | } |
| 4683 | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4684 | StmtResult Sema::ActOnOpenMPForSimdDirective( |
| 4685 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4686 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 4687 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4688 | if (!AStmt) |
| 4689 | return StmtError(); |
| 4690 | |
| 4691 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4692 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4693 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4694 | // define the nested loops number. |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4695 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4696 | CheckOpenMPLoop(OMPD_for_simd, getCollapseNumberExpr(Clauses), |
| 4697 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 4698 | VarsWithImplicitDSA, B); |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4699 | if (NestedLoopCount == 0) |
| 4700 | return StmtError(); |
| 4701 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4702 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 4703 | "omp for simd loop exprs were not built"); |
| 4704 | |
Alexey Bataev | 58e5bdb | 2015-06-18 04:45:29 +0000 | [diff] [blame] | 4705 | if (!CurContext->isDependentContext()) { |
| 4706 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4707 | for (auto C : Clauses) { |
| 4708 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 4709 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 4710 | B.NumIterations, *this, CurScope)) |
| 4711 | return StmtError(); |
| 4712 | } |
| 4713 | } |
| 4714 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 4715 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 4716 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 4717 | // parameter must be less than or equal to the value of the safelen parameter. |
| 4718 | OMPSafelenClause *Safelen = nullptr; |
| 4719 | OMPSimdlenClause *Simdlen = nullptr; |
| 4720 | for (auto *Clause : Clauses) { |
| 4721 | if (Clause->getClauseKind() == OMPC_safelen) |
| 4722 | Safelen = cast<OMPSafelenClause>(Clause); |
| 4723 | else if (Clause->getClauseKind() == OMPC_simdlen) |
| 4724 | Simdlen = cast<OMPSimdlenClause>(Clause); |
| 4725 | if (Safelen && Simdlen) |
| 4726 | break; |
| 4727 | } |
| 4728 | if (Simdlen && Safelen && |
| 4729 | checkSimdlenSafelenValues(*this, Simdlen->getSimdlen(), |
| 4730 | Safelen->getSafelen())) |
| 4731 | return StmtError(); |
| 4732 | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4733 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4734 | return OMPForSimdDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| 4735 | Clauses, AStmt, B); |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4736 | } |
| 4737 | |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4738 | StmtResult Sema::ActOnOpenMPSectionsDirective(ArrayRef<OMPClause *> Clauses, |
| 4739 | Stmt *AStmt, |
| 4740 | SourceLocation StartLoc, |
| 4741 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4742 | if (!AStmt) |
| 4743 | return StmtError(); |
| 4744 | |
| 4745 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4746 | auto BaseStmt = AStmt; |
| 4747 | while (CapturedStmt *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt)) |
| 4748 | BaseStmt = CS->getCapturedStmt(); |
| 4749 | if (auto C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) { |
| 4750 | auto S = C->children(); |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 4751 | if (S.begin() == S.end()) |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4752 | return StmtError(); |
| 4753 | // All associated statements must be '#pragma omp section' except for |
| 4754 | // the first one. |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 4755 | for (Stmt *SectionStmt : llvm::make_range(std::next(S.begin()), S.end())) { |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4756 | if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) { |
| 4757 | if (SectionStmt) |
| 4758 | Diag(SectionStmt->getLocStart(), |
| 4759 | diag::err_omp_sections_substmt_not_section); |
| 4760 | return StmtError(); |
| 4761 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4762 | cast<OMPSectionDirective>(SectionStmt) |
| 4763 | ->setHasCancel(DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4764 | } |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4765 | } else { |
| 4766 | Diag(AStmt->getLocStart(), diag::err_omp_sections_not_compound_stmt); |
| 4767 | return StmtError(); |
| 4768 | } |
| 4769 | |
| 4770 | getCurFunction()->setHasBranchProtectedScope(); |
| 4771 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4772 | return OMPSectionsDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 4773 | DSAStack->isCancelRegion()); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4774 | } |
| 4775 | |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4776 | StmtResult Sema::ActOnOpenMPSectionDirective(Stmt *AStmt, |
| 4777 | SourceLocation StartLoc, |
| 4778 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4779 | if (!AStmt) |
| 4780 | return StmtError(); |
| 4781 | |
| 4782 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4783 | |
| 4784 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4785 | DSAStack->setParentCancelRegion(DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4786 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4787 | return OMPSectionDirective::Create(Context, StartLoc, EndLoc, AStmt, |
| 4788 | DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4789 | } |
| 4790 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 4791 | StmtResult Sema::ActOnOpenMPSingleDirective(ArrayRef<OMPClause *> Clauses, |
| 4792 | Stmt *AStmt, |
| 4793 | SourceLocation StartLoc, |
| 4794 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4795 | if (!AStmt) |
| 4796 | return StmtError(); |
| 4797 | |
| 4798 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 74a05c9 | 2014-07-15 02:55:09 +0000 | [diff] [blame] | 4799 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 4800 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | 74a05c9 | 2014-07-15 02:55:09 +0000 | [diff] [blame] | 4801 | |
Alexey Bataev | 3255bf3 | 2015-01-19 05:20:46 +0000 | [diff] [blame] | 4802 | // OpenMP [2.7.3, single Construct, Restrictions] |
| 4803 | // The copyprivate clause must not be used with the nowait clause. |
| 4804 | OMPClause *Nowait = nullptr; |
| 4805 | OMPClause *Copyprivate = nullptr; |
| 4806 | for (auto *Clause : Clauses) { |
| 4807 | if (Clause->getClauseKind() == OMPC_nowait) |
| 4808 | Nowait = Clause; |
| 4809 | else if (Clause->getClauseKind() == OMPC_copyprivate) |
| 4810 | Copyprivate = Clause; |
| 4811 | if (Copyprivate && Nowait) { |
| 4812 | Diag(Copyprivate->getLocStart(), |
| 4813 | diag::err_omp_single_copyprivate_with_nowait); |
| 4814 | Diag(Nowait->getLocStart(), diag::note_omp_nowait_clause_here); |
| 4815 | return StmtError(); |
| 4816 | } |
| 4817 | } |
| 4818 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 4819 | return OMPSingleDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 4820 | } |
| 4821 | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 4822 | StmtResult Sema::ActOnOpenMPMasterDirective(Stmt *AStmt, |
| 4823 | SourceLocation StartLoc, |
| 4824 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4825 | if (!AStmt) |
| 4826 | return StmtError(); |
| 4827 | |
| 4828 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 4829 | |
| 4830 | getCurFunction()->setHasBranchProtectedScope(); |
| 4831 | |
| 4832 | return OMPMasterDirective::Create(Context, StartLoc, EndLoc, AStmt); |
| 4833 | } |
| 4834 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 4835 | StmtResult Sema::ActOnOpenMPCriticalDirective( |
| 4836 | const DeclarationNameInfo &DirName, ArrayRef<OMPClause *> Clauses, |
| 4837 | Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4838 | if (!AStmt) |
| 4839 | return StmtError(); |
| 4840 | |
| 4841 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 4842 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 4843 | bool ErrorFound = false; |
| 4844 | llvm::APSInt Hint; |
| 4845 | SourceLocation HintLoc; |
| 4846 | bool DependentHint = false; |
| 4847 | for (auto *C : Clauses) { |
| 4848 | if (C->getClauseKind() == OMPC_hint) { |
| 4849 | if (!DirName.getName()) { |
| 4850 | Diag(C->getLocStart(), diag::err_omp_hint_clause_no_name); |
| 4851 | ErrorFound = true; |
| 4852 | } |
| 4853 | Expr *E = cast<OMPHintClause>(C)->getHint(); |
| 4854 | if (E->isTypeDependent() || E->isValueDependent() || |
| 4855 | E->isInstantiationDependent()) |
| 4856 | DependentHint = true; |
| 4857 | else { |
| 4858 | Hint = E->EvaluateKnownConstInt(Context); |
| 4859 | HintLoc = C->getLocStart(); |
| 4860 | } |
| 4861 | } |
| 4862 | } |
| 4863 | if (ErrorFound) |
| 4864 | return StmtError(); |
| 4865 | auto Pair = DSAStack->getCriticalWithHint(DirName); |
| 4866 | if (Pair.first && DirName.getName() && !DependentHint) { |
| 4867 | if (llvm::APSInt::compareValues(Hint, Pair.second) != 0) { |
| 4868 | Diag(StartLoc, diag::err_omp_critical_with_hint); |
| 4869 | if (HintLoc.isValid()) { |
| 4870 | Diag(HintLoc, diag::note_omp_critical_hint_here) |
| 4871 | << 0 << Hint.toString(/*Radix=*/10, /*Signed=*/false); |
| 4872 | } else |
| 4873 | Diag(StartLoc, diag::note_omp_critical_no_hint) << 0; |
| 4874 | if (auto *C = Pair.first->getSingleClause<OMPHintClause>()) { |
| 4875 | Diag(C->getLocStart(), diag::note_omp_critical_hint_here) |
| 4876 | << 1 |
| 4877 | << C->getHint()->EvaluateKnownConstInt(Context).toString( |
| 4878 | /*Radix=*/10, /*Signed=*/false); |
| 4879 | } else |
| 4880 | Diag(Pair.first->getLocStart(), diag::note_omp_critical_no_hint) << 1; |
| 4881 | } |
| 4882 | } |
| 4883 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 4884 | getCurFunction()->setHasBranchProtectedScope(); |
| 4885 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 4886 | auto *Dir = OMPCriticalDirective::Create(Context, DirName, StartLoc, EndLoc, |
| 4887 | Clauses, AStmt); |
| 4888 | if (!Pair.first && DirName.getName() && !DependentHint) |
| 4889 | DSAStack->addCriticalWithHint(Dir, Hint); |
| 4890 | return Dir; |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 4891 | } |
| 4892 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4893 | StmtResult Sema::ActOnOpenMPParallelForDirective( |
| 4894 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4895 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 4896 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4897 | if (!AStmt) |
| 4898 | return StmtError(); |
| 4899 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4900 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 4901 | // 1.2.2 OpenMP Language Terminology |
| 4902 | // Structured block - An executable statement with a single entry at the |
| 4903 | // top and a single exit at the bottom. |
| 4904 | // The point of exit cannot be a branch out of the structured block. |
| 4905 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 4906 | CS->getCapturedDecl()->setNothrow(); |
| 4907 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4908 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4909 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4910 | // define the nested loops number. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4911 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4912 | CheckOpenMPLoop(OMPD_parallel_for, getCollapseNumberExpr(Clauses), |
| 4913 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 4914 | VarsWithImplicitDSA, B); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4915 | if (NestedLoopCount == 0) |
| 4916 | return StmtError(); |
| 4917 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4918 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 4919 | "omp parallel for loop exprs were not built"); |
| 4920 | |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 4921 | if (!CurContext->isDependentContext()) { |
| 4922 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4923 | for (auto C : Clauses) { |
| 4924 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 4925 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 4926 | B.NumIterations, *this, CurScope)) |
| 4927 | return StmtError(); |
| 4928 | } |
| 4929 | } |
| 4930 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4931 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4932 | return OMPParallelForDirective::Create(Context, StartLoc, EndLoc, |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4933 | NestedLoopCount, Clauses, AStmt, B, |
| 4934 | DSAStack->isCancelRegion()); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4935 | } |
| 4936 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4937 | StmtResult Sema::ActOnOpenMPParallelForSimdDirective( |
| 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 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +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. |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4955 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4956 | CheckOpenMPLoop(OMPD_parallel_for_simd, getCollapseNumberExpr(Clauses), |
| 4957 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 4958 | VarsWithImplicitDSA, B); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4959 | if (NestedLoopCount == 0) |
| 4960 | return StmtError(); |
| 4961 | |
Alexey Bataev | 3b5b5c4 | 2015-06-18 10:10:12 +0000 | [diff] [blame] | 4962 | if (!CurContext->isDependentContext()) { |
| 4963 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4964 | for (auto C : Clauses) { |
| 4965 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 4966 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 4967 | B.NumIterations, *this, CurScope)) |
| 4968 | return StmtError(); |
| 4969 | } |
| 4970 | } |
| 4971 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 4972 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 4973 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 4974 | // parameter must be less than or equal to the value of the safelen parameter. |
| 4975 | OMPSafelenClause *Safelen = nullptr; |
| 4976 | OMPSimdlenClause *Simdlen = nullptr; |
| 4977 | for (auto *Clause : Clauses) { |
| 4978 | if (Clause->getClauseKind() == OMPC_safelen) |
| 4979 | Safelen = cast<OMPSafelenClause>(Clause); |
| 4980 | else if (Clause->getClauseKind() == OMPC_simdlen) |
| 4981 | Simdlen = cast<OMPSimdlenClause>(Clause); |
| 4982 | if (Safelen && Simdlen) |
| 4983 | break; |
| 4984 | } |
| 4985 | if (Simdlen && Safelen && |
| 4986 | checkSimdlenSafelenValues(*this, Simdlen->getSimdlen(), |
| 4987 | Safelen->getSafelen())) |
| 4988 | return StmtError(); |
| 4989 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4990 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4991 | return OMPParallelForSimdDirective::Create( |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4992 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4993 | } |
| 4994 | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4995 | StmtResult |
| 4996 | Sema::ActOnOpenMPParallelSectionsDirective(ArrayRef<OMPClause *> Clauses, |
| 4997 | Stmt *AStmt, SourceLocation StartLoc, |
| 4998 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4999 | if (!AStmt) |
| 5000 | return StmtError(); |
| 5001 | |
| 5002 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 5003 | auto BaseStmt = AStmt; |
| 5004 | while (CapturedStmt *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt)) |
| 5005 | BaseStmt = CS->getCapturedStmt(); |
| 5006 | if (auto C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) { |
| 5007 | auto S = C->children(); |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 5008 | if (S.begin() == S.end()) |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 5009 | return StmtError(); |
| 5010 | // All associated statements must be '#pragma omp section' except for |
| 5011 | // the first one. |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 5012 | for (Stmt *SectionStmt : llvm::make_range(std::next(S.begin()), S.end())) { |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 5013 | if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) { |
| 5014 | if (SectionStmt) |
| 5015 | Diag(SectionStmt->getLocStart(), |
| 5016 | diag::err_omp_parallel_sections_substmt_not_section); |
| 5017 | return StmtError(); |
| 5018 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 5019 | cast<OMPSectionDirective>(SectionStmt) |
| 5020 | ->setHasCancel(DSAStack->isCancelRegion()); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 5021 | } |
| 5022 | } else { |
| 5023 | Diag(AStmt->getLocStart(), |
| 5024 | diag::err_omp_parallel_sections_not_compound_stmt); |
| 5025 | return StmtError(); |
| 5026 | } |
| 5027 | |
| 5028 | getCurFunction()->setHasBranchProtectedScope(); |
| 5029 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 5030 | return OMPParallelSectionsDirective::Create( |
| 5031 | Context, StartLoc, EndLoc, Clauses, AStmt, DSAStack->isCancelRegion()); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 5032 | } |
| 5033 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5034 | StmtResult Sema::ActOnOpenMPTaskDirective(ArrayRef<OMPClause *> Clauses, |
| 5035 | Stmt *AStmt, SourceLocation StartLoc, |
| 5036 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5037 | if (!AStmt) |
| 5038 | return StmtError(); |
| 5039 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5040 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 5041 | // 1.2.2 OpenMP Language Terminology |
| 5042 | // Structured block - An executable statement with a single entry at the |
| 5043 | // top and a single exit at the bottom. |
| 5044 | // The point of exit cannot be a branch out of the structured block. |
| 5045 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5046 | CS->getCapturedDecl()->setNothrow(); |
| 5047 | |
| 5048 | getCurFunction()->setHasBranchProtectedScope(); |
| 5049 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 5050 | return OMPTaskDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 5051 | DSAStack->isCancelRegion()); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5052 | } |
| 5053 | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 5054 | StmtResult Sema::ActOnOpenMPTaskyieldDirective(SourceLocation StartLoc, |
| 5055 | SourceLocation EndLoc) { |
| 5056 | return OMPTaskyieldDirective::Create(Context, StartLoc, EndLoc); |
| 5057 | } |
| 5058 | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 5059 | StmtResult Sema::ActOnOpenMPBarrierDirective(SourceLocation StartLoc, |
| 5060 | SourceLocation EndLoc) { |
| 5061 | return OMPBarrierDirective::Create(Context, StartLoc, EndLoc); |
| 5062 | } |
| 5063 | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 5064 | StmtResult Sema::ActOnOpenMPTaskwaitDirective(SourceLocation StartLoc, |
| 5065 | SourceLocation EndLoc) { |
| 5066 | return OMPTaskwaitDirective::Create(Context, StartLoc, EndLoc); |
| 5067 | } |
| 5068 | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 5069 | StmtResult Sema::ActOnOpenMPTaskgroupDirective(Stmt *AStmt, |
| 5070 | SourceLocation StartLoc, |
| 5071 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5072 | if (!AStmt) |
| 5073 | return StmtError(); |
| 5074 | |
| 5075 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 5076 | |
| 5077 | getCurFunction()->setHasBranchProtectedScope(); |
| 5078 | |
| 5079 | return OMPTaskgroupDirective::Create(Context, StartLoc, EndLoc, AStmt); |
| 5080 | } |
| 5081 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 5082 | StmtResult Sema::ActOnOpenMPFlushDirective(ArrayRef<OMPClause *> Clauses, |
| 5083 | SourceLocation StartLoc, |
| 5084 | SourceLocation EndLoc) { |
| 5085 | assert(Clauses.size() <= 1 && "Extra clauses in flush directive"); |
| 5086 | return OMPFlushDirective::Create(Context, StartLoc, EndLoc, Clauses); |
| 5087 | } |
| 5088 | |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5089 | StmtResult Sema::ActOnOpenMPOrderedDirective(ArrayRef<OMPClause *> Clauses, |
| 5090 | Stmt *AStmt, |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 5091 | SourceLocation StartLoc, |
| 5092 | SourceLocation EndLoc) { |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5093 | OMPClause *DependFound = nullptr; |
| 5094 | OMPClause *DependSourceClause = nullptr; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 5095 | OMPClause *DependSinkClause = nullptr; |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5096 | bool ErrorFound = false; |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5097 | OMPThreadsClause *TC = nullptr; |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5098 | OMPSIMDClause *SC = nullptr; |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5099 | for (auto *C : Clauses) { |
| 5100 | if (auto *DC = dyn_cast<OMPDependClause>(C)) { |
| 5101 | DependFound = C; |
| 5102 | if (DC->getDependencyKind() == OMPC_DEPEND_source) { |
| 5103 | if (DependSourceClause) { |
| 5104 | Diag(C->getLocStart(), diag::err_omp_more_one_clause) |
| 5105 | << getOpenMPDirectiveName(OMPD_ordered) |
| 5106 | << getOpenMPClauseName(OMPC_depend) << 2; |
| 5107 | ErrorFound = true; |
| 5108 | } else |
| 5109 | DependSourceClause = C; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 5110 | if (DependSinkClause) { |
| 5111 | Diag(C->getLocStart(), diag::err_omp_depend_sink_source_not_allowed) |
| 5112 | << 0; |
| 5113 | ErrorFound = true; |
| 5114 | } |
| 5115 | } else if (DC->getDependencyKind() == OMPC_DEPEND_sink) { |
| 5116 | if (DependSourceClause) { |
| 5117 | Diag(C->getLocStart(), diag::err_omp_depend_sink_source_not_allowed) |
| 5118 | << 1; |
| 5119 | ErrorFound = true; |
| 5120 | } |
| 5121 | DependSinkClause = C; |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5122 | } |
| 5123 | } else if (C->getClauseKind() == OMPC_threads) |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5124 | TC = cast<OMPThreadsClause>(C); |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5125 | else if (C->getClauseKind() == OMPC_simd) |
| 5126 | SC = cast<OMPSIMDClause>(C); |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5127 | } |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5128 | if (!ErrorFound && !SC && |
| 5129 | isOpenMPSimdDirective(DSAStack->getParentDirective())) { |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5130 | // OpenMP [2.8.1,simd Construct, Restrictions] |
| 5131 | // An ordered construct with the simd clause is the only OpenMP construct |
| 5132 | // that can appear in the simd region. |
| 5133 | Diag(StartLoc, diag::err_omp_prohibited_region_simd); |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5134 | ErrorFound = true; |
| 5135 | } else if (DependFound && (TC || SC)) { |
| 5136 | Diag(DependFound->getLocStart(), diag::err_omp_depend_clause_thread_simd) |
| 5137 | << getOpenMPClauseName(TC ? TC->getClauseKind() : SC->getClauseKind()); |
| 5138 | ErrorFound = true; |
| 5139 | } else if (DependFound && !DSAStack->getParentOrderedRegionParam()) { |
| 5140 | Diag(DependFound->getLocStart(), |
| 5141 | diag::err_omp_ordered_directive_without_param); |
| 5142 | ErrorFound = true; |
| 5143 | } else if (TC || Clauses.empty()) { |
| 5144 | if (auto *Param = DSAStack->getParentOrderedRegionParam()) { |
| 5145 | SourceLocation ErrLoc = TC ? TC->getLocStart() : StartLoc; |
| 5146 | Diag(ErrLoc, diag::err_omp_ordered_directive_with_param) |
| 5147 | << (TC != nullptr); |
| 5148 | Diag(Param->getLocStart(), diag::note_omp_ordered_param); |
| 5149 | ErrorFound = true; |
| 5150 | } |
| 5151 | } |
| 5152 | if ((!AStmt && !DependFound) || ErrorFound) |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5153 | return StmtError(); |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5154 | |
| 5155 | if (AStmt) { |
| 5156 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 5157 | |
| 5158 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5159 | } |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5160 | |
| 5161 | return OMPOrderedDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 5162 | } |
| 5163 | |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5164 | namespace { |
| 5165 | /// \brief Helper class for checking expression in 'omp atomic [update]' |
| 5166 | /// construct. |
| 5167 | class OpenMPAtomicUpdateChecker { |
| 5168 | /// \brief Error results for atomic update expressions. |
| 5169 | enum ExprAnalysisErrorCode { |
| 5170 | /// \brief A statement is not an expression statement. |
| 5171 | NotAnExpression, |
| 5172 | /// \brief Expression is not builtin binary or unary operation. |
| 5173 | NotABinaryOrUnaryExpression, |
| 5174 | /// \brief Unary operation is not post-/pre- increment/decrement operation. |
| 5175 | NotAnUnaryIncDecExpression, |
| 5176 | /// \brief An expression is not of scalar type. |
| 5177 | NotAScalarType, |
| 5178 | /// \brief A binary operation is not an assignment operation. |
| 5179 | NotAnAssignmentOp, |
| 5180 | /// \brief RHS part of the binary operation is not a binary expression. |
| 5181 | NotABinaryExpression, |
| 5182 | /// \brief RHS part is not additive/multiplicative/shift/biwise binary |
| 5183 | /// expression. |
| 5184 | NotABinaryOperator, |
| 5185 | /// \brief RHS binary operation does not have reference to the updated LHS |
| 5186 | /// part. |
| 5187 | NotAnUpdateExpression, |
| 5188 | /// \brief No errors is found. |
| 5189 | NoError |
| 5190 | }; |
| 5191 | /// \brief Reference to Sema. |
| 5192 | Sema &SemaRef; |
| 5193 | /// \brief A location for note diagnostics (when error is found). |
| 5194 | SourceLocation NoteLoc; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5195 | /// \brief 'x' lvalue part of the source atomic expression. |
| 5196 | Expr *X; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5197 | /// \brief 'expr' rvalue part of the source atomic expression. |
| 5198 | Expr *E; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5199 | /// \brief Helper expression of the form |
| 5200 | /// 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or |
| 5201 | /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'. |
| 5202 | Expr *UpdateExpr; |
| 5203 | /// \brief Is 'x' a LHS in a RHS part of full update expression. It is |
| 5204 | /// important for non-associative operations. |
| 5205 | bool IsXLHSInRHSPart; |
| 5206 | BinaryOperatorKind Op; |
| 5207 | SourceLocation OpLoc; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5208 | /// \brief true if the source expression is a postfix unary operation, false |
| 5209 | /// if it is a prefix unary operation. |
| 5210 | bool IsPostfixUpdate; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5211 | |
| 5212 | public: |
| 5213 | OpenMPAtomicUpdateChecker(Sema &SemaRef) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5214 | : SemaRef(SemaRef), X(nullptr), E(nullptr), UpdateExpr(nullptr), |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5215 | IsXLHSInRHSPart(false), Op(BO_PtrMemD), IsPostfixUpdate(false) {} |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5216 | /// \brief Check specified statement that it is suitable for 'atomic update' |
| 5217 | /// constructs and extract 'x', 'expr' and Operation from the original |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5218 | /// expression. If DiagId and NoteId == 0, then only check is performed |
| 5219 | /// without error notification. |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5220 | /// \param DiagId Diagnostic which should be emitted if error is found. |
| 5221 | /// \param NoteId Diagnostic note for the main error message. |
| 5222 | /// \return true if statement is not an update expression, false otherwise. |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5223 | bool checkStatement(Stmt *S, unsigned DiagId = 0, unsigned NoteId = 0); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5224 | /// \brief Return the 'x' lvalue part of the source atomic expression. |
| 5225 | Expr *getX() const { return X; } |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5226 | /// \brief Return the 'expr' rvalue part of the source atomic expression. |
| 5227 | Expr *getExpr() const { return E; } |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5228 | /// \brief Return the update expression used in calculation of the updated |
| 5229 | /// value. Always has form 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or |
| 5230 | /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'. |
| 5231 | Expr *getUpdateExpr() const { return UpdateExpr; } |
| 5232 | /// \brief Return true if 'x' is LHS in RHS part of full update expression, |
| 5233 | /// false otherwise. |
| 5234 | bool isXLHSInRHSPart() const { return IsXLHSInRHSPart; } |
| 5235 | |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5236 | /// \brief true if the source expression is a postfix unary operation, false |
| 5237 | /// if it is a prefix unary operation. |
| 5238 | bool isPostfixUpdate() const { return IsPostfixUpdate; } |
| 5239 | |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5240 | private: |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5241 | bool checkBinaryOperation(BinaryOperator *AtomicBinOp, unsigned DiagId = 0, |
| 5242 | unsigned NoteId = 0); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5243 | }; |
| 5244 | } // namespace |
| 5245 | |
| 5246 | bool OpenMPAtomicUpdateChecker::checkBinaryOperation( |
| 5247 | BinaryOperator *AtomicBinOp, unsigned DiagId, unsigned NoteId) { |
| 5248 | ExprAnalysisErrorCode ErrorFound = NoError; |
| 5249 | SourceLocation ErrorLoc, NoteLoc; |
| 5250 | SourceRange ErrorRange, NoteRange; |
| 5251 | // Allowed constructs are: |
| 5252 | // x = x binop expr; |
| 5253 | // x = expr binop x; |
| 5254 | if (AtomicBinOp->getOpcode() == BO_Assign) { |
| 5255 | X = AtomicBinOp->getLHS(); |
| 5256 | if (auto *AtomicInnerBinOp = dyn_cast<BinaryOperator>( |
| 5257 | AtomicBinOp->getRHS()->IgnoreParenImpCasts())) { |
| 5258 | if (AtomicInnerBinOp->isMultiplicativeOp() || |
| 5259 | AtomicInnerBinOp->isAdditiveOp() || AtomicInnerBinOp->isShiftOp() || |
| 5260 | AtomicInnerBinOp->isBitwiseOp()) { |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5261 | Op = AtomicInnerBinOp->getOpcode(); |
| 5262 | OpLoc = AtomicInnerBinOp->getOperatorLoc(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5263 | auto *LHS = AtomicInnerBinOp->getLHS(); |
| 5264 | auto *RHS = AtomicInnerBinOp->getRHS(); |
| 5265 | llvm::FoldingSetNodeID XId, LHSId, RHSId; |
| 5266 | X->IgnoreParenImpCasts()->Profile(XId, SemaRef.getASTContext(), |
| 5267 | /*Canonical=*/true); |
| 5268 | LHS->IgnoreParenImpCasts()->Profile(LHSId, SemaRef.getASTContext(), |
| 5269 | /*Canonical=*/true); |
| 5270 | RHS->IgnoreParenImpCasts()->Profile(RHSId, SemaRef.getASTContext(), |
| 5271 | /*Canonical=*/true); |
| 5272 | if (XId == LHSId) { |
| 5273 | E = RHS; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5274 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5275 | } else if (XId == RHSId) { |
| 5276 | E = LHS; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5277 | IsXLHSInRHSPart = false; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5278 | } else { |
| 5279 | ErrorLoc = AtomicInnerBinOp->getExprLoc(); |
| 5280 | ErrorRange = AtomicInnerBinOp->getSourceRange(); |
| 5281 | NoteLoc = X->getExprLoc(); |
| 5282 | NoteRange = X->getSourceRange(); |
| 5283 | ErrorFound = NotAnUpdateExpression; |
| 5284 | } |
| 5285 | } else { |
| 5286 | ErrorLoc = AtomicInnerBinOp->getExprLoc(); |
| 5287 | ErrorRange = AtomicInnerBinOp->getSourceRange(); |
| 5288 | NoteLoc = AtomicInnerBinOp->getOperatorLoc(); |
| 5289 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 5290 | ErrorFound = NotABinaryOperator; |
| 5291 | } |
| 5292 | } else { |
| 5293 | NoteLoc = ErrorLoc = AtomicBinOp->getRHS()->getExprLoc(); |
| 5294 | NoteRange = ErrorRange = AtomicBinOp->getRHS()->getSourceRange(); |
| 5295 | ErrorFound = NotABinaryExpression; |
| 5296 | } |
| 5297 | } else { |
| 5298 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5299 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5300 | NoteLoc = AtomicBinOp->getOperatorLoc(); |
| 5301 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 5302 | ErrorFound = NotAnAssignmentOp; |
| 5303 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5304 | if (ErrorFound != NoError && DiagId != 0 && NoteId != 0) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5305 | SemaRef.Diag(ErrorLoc, DiagId) << ErrorRange; |
| 5306 | SemaRef.Diag(NoteLoc, NoteId) << ErrorFound << NoteRange; |
| 5307 | return true; |
| 5308 | } else if (SemaRef.CurContext->isDependentContext()) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5309 | E = X = UpdateExpr = nullptr; |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5310 | return ErrorFound != NoError; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5311 | } |
| 5312 | |
| 5313 | bool OpenMPAtomicUpdateChecker::checkStatement(Stmt *S, unsigned DiagId, |
| 5314 | unsigned NoteId) { |
| 5315 | ExprAnalysisErrorCode ErrorFound = NoError; |
| 5316 | SourceLocation ErrorLoc, NoteLoc; |
| 5317 | SourceRange ErrorRange, NoteRange; |
| 5318 | // Allowed constructs are: |
| 5319 | // x++; |
| 5320 | // x--; |
| 5321 | // ++x; |
| 5322 | // --x; |
| 5323 | // x binop= expr; |
| 5324 | // x = x binop expr; |
| 5325 | // x = expr binop x; |
| 5326 | if (auto *AtomicBody = dyn_cast<Expr>(S)) { |
| 5327 | AtomicBody = AtomicBody->IgnoreParenImpCasts(); |
| 5328 | if (AtomicBody->getType()->isScalarType() || |
| 5329 | AtomicBody->isInstantiationDependent()) { |
| 5330 | if (auto *AtomicCompAssignOp = dyn_cast<CompoundAssignOperator>( |
| 5331 | AtomicBody->IgnoreParenImpCasts())) { |
| 5332 | // Check for Compound Assignment Operation |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5333 | Op = BinaryOperator::getOpForCompoundAssignment( |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5334 | AtomicCompAssignOp->getOpcode()); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5335 | OpLoc = AtomicCompAssignOp->getOperatorLoc(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5336 | E = AtomicCompAssignOp->getRHS(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5337 | X = AtomicCompAssignOp->getLHS(); |
| 5338 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5339 | } else if (auto *AtomicBinOp = dyn_cast<BinaryOperator>( |
| 5340 | AtomicBody->IgnoreParenImpCasts())) { |
| 5341 | // Check for Binary Operation |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5342 | if(checkBinaryOperation(AtomicBinOp, DiagId, NoteId)) |
| 5343 | return true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5344 | } else if (auto *AtomicUnaryOp = |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5345 | dyn_cast<UnaryOperator>(AtomicBody->IgnoreParenImpCasts())) { |
| 5346 | // Check for Unary Operation |
| 5347 | if (AtomicUnaryOp->isIncrementDecrementOp()) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5348 | IsPostfixUpdate = AtomicUnaryOp->isPostfix(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5349 | Op = AtomicUnaryOp->isIncrementOp() ? BO_Add : BO_Sub; |
| 5350 | OpLoc = AtomicUnaryOp->getOperatorLoc(); |
| 5351 | X = AtomicUnaryOp->getSubExpr(); |
| 5352 | E = SemaRef.ActOnIntegerConstant(OpLoc, /*uint64_t Val=*/1).get(); |
| 5353 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5354 | } else { |
| 5355 | ErrorFound = NotAnUnaryIncDecExpression; |
| 5356 | ErrorLoc = AtomicUnaryOp->getExprLoc(); |
| 5357 | ErrorRange = AtomicUnaryOp->getSourceRange(); |
| 5358 | NoteLoc = AtomicUnaryOp->getOperatorLoc(); |
| 5359 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 5360 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5361 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5362 | ErrorFound = NotABinaryOrUnaryExpression; |
| 5363 | NoteLoc = ErrorLoc = AtomicBody->getExprLoc(); |
| 5364 | NoteRange = ErrorRange = AtomicBody->getSourceRange(); |
| 5365 | } |
| 5366 | } else { |
| 5367 | ErrorFound = NotAScalarType; |
| 5368 | NoteLoc = ErrorLoc = AtomicBody->getLocStart(); |
| 5369 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
| 5370 | } |
| 5371 | } else { |
| 5372 | ErrorFound = NotAnExpression; |
| 5373 | NoteLoc = ErrorLoc = S->getLocStart(); |
| 5374 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
| 5375 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5376 | if (ErrorFound != NoError && DiagId != 0 && NoteId != 0) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5377 | SemaRef.Diag(ErrorLoc, DiagId) << ErrorRange; |
| 5378 | SemaRef.Diag(NoteLoc, NoteId) << ErrorFound << NoteRange; |
| 5379 | return true; |
| 5380 | } else if (SemaRef.CurContext->isDependentContext()) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5381 | E = X = UpdateExpr = nullptr; |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5382 | if (ErrorFound == NoError && E && X) { |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5383 | // Build an update expression of form 'OpaqueValueExpr(x) binop |
| 5384 | // OpaqueValueExpr(expr)' or 'OpaqueValueExpr(expr) binop |
| 5385 | // OpaqueValueExpr(x)' and then cast it to the type of the 'x' expression. |
| 5386 | auto *OVEX = new (SemaRef.getASTContext()) |
| 5387 | OpaqueValueExpr(X->getExprLoc(), X->getType(), VK_RValue); |
| 5388 | auto *OVEExpr = new (SemaRef.getASTContext()) |
| 5389 | OpaqueValueExpr(E->getExprLoc(), E->getType(), VK_RValue); |
| 5390 | auto Update = |
| 5391 | SemaRef.CreateBuiltinBinOp(OpLoc, Op, IsXLHSInRHSPart ? OVEX : OVEExpr, |
| 5392 | IsXLHSInRHSPart ? OVEExpr : OVEX); |
| 5393 | if (Update.isInvalid()) |
| 5394 | return true; |
| 5395 | Update = SemaRef.PerformImplicitConversion(Update.get(), X->getType(), |
| 5396 | Sema::AA_Casting); |
| 5397 | if (Update.isInvalid()) |
| 5398 | return true; |
| 5399 | UpdateExpr = Update.get(); |
| 5400 | } |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5401 | return ErrorFound != NoError; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5402 | } |
| 5403 | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 5404 | StmtResult Sema::ActOnOpenMPAtomicDirective(ArrayRef<OMPClause *> Clauses, |
| 5405 | Stmt *AStmt, |
| 5406 | SourceLocation StartLoc, |
| 5407 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5408 | if (!AStmt) |
| 5409 | return StmtError(); |
| 5410 | |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5411 | auto CS = cast<CapturedStmt>(AStmt); |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 5412 | // 1.2.2 OpenMP Language Terminology |
| 5413 | // Structured block - An executable statement with a single entry at the |
| 5414 | // top and a single exit at the bottom. |
| 5415 | // The point of exit cannot be a branch out of the structured block. |
| 5416 | // longjmp() and throw() must not violate the entry/exit criteria. |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5417 | OpenMPClauseKind AtomicKind = OMPC_unknown; |
| 5418 | SourceLocation AtomicKindLoc; |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5419 | for (auto *C : Clauses) { |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5420 | if (C->getClauseKind() == OMPC_read || C->getClauseKind() == OMPC_write || |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5421 | C->getClauseKind() == OMPC_update || |
| 5422 | C->getClauseKind() == OMPC_capture) { |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5423 | if (AtomicKind != OMPC_unknown) { |
| 5424 | Diag(C->getLocStart(), diag::err_omp_atomic_several_clauses) |
| 5425 | << SourceRange(C->getLocStart(), C->getLocEnd()); |
| 5426 | Diag(AtomicKindLoc, diag::note_omp_atomic_previous_clause) |
| 5427 | << getOpenMPClauseName(AtomicKind); |
| 5428 | } else { |
| 5429 | AtomicKind = C->getClauseKind(); |
| 5430 | AtomicKindLoc = C->getLocStart(); |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5431 | } |
| 5432 | } |
| 5433 | } |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5434 | |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5435 | auto Body = CS->getCapturedStmt(); |
Alexey Bataev | 10fec57 | 2015-03-11 04:48:56 +0000 | [diff] [blame] | 5436 | if (auto *EWC = dyn_cast<ExprWithCleanups>(Body)) |
| 5437 | Body = EWC->getSubExpr(); |
| 5438 | |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5439 | Expr *X = nullptr; |
| 5440 | Expr *V = nullptr; |
| 5441 | Expr *E = nullptr; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5442 | Expr *UE = nullptr; |
| 5443 | bool IsXLHSInRHSPart = false; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5444 | bool IsPostfixUpdate = false; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5445 | // OpenMP [2.12.6, atomic Construct] |
| 5446 | // In the next expressions: |
| 5447 | // * x and v (as applicable) are both l-value expressions with scalar type. |
| 5448 | // * During the execution of an atomic region, multiple syntactic |
| 5449 | // occurrences of x must designate the same storage location. |
| 5450 | // * Neither of v and expr (as applicable) may access the storage location |
| 5451 | // designated by x. |
| 5452 | // * Neither of x and expr (as applicable) may access the storage location |
| 5453 | // designated by v. |
| 5454 | // * expr is an expression with scalar type. |
| 5455 | // * binop is one of +, *, -, /, &, ^, |, <<, or >>. |
| 5456 | // * binop, binop=, ++, and -- are not overloaded operators. |
| 5457 | // * The expression x binop expr must be numerically equivalent to x binop |
| 5458 | // (expr). This requirement is satisfied if the operators in expr have |
| 5459 | // precedence greater than binop, or by using parentheses around expr or |
| 5460 | // subexpressions of expr. |
| 5461 | // * The expression expr binop x must be numerically equivalent to (expr) |
| 5462 | // binop x. This requirement is satisfied if the operators in expr have |
| 5463 | // precedence equal to or greater than binop, or by using parentheses around |
| 5464 | // expr or subexpressions of expr. |
| 5465 | // * For forms that allow multiple occurrences of x, the number of times |
| 5466 | // that x is evaluated is unspecified. |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5467 | if (AtomicKind == OMPC_read) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5468 | enum { |
| 5469 | NotAnExpression, |
| 5470 | NotAnAssignmentOp, |
| 5471 | NotAScalarType, |
| 5472 | NotAnLValue, |
| 5473 | NoError |
| 5474 | } ErrorFound = NoError; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5475 | SourceLocation ErrorLoc, NoteLoc; |
| 5476 | SourceRange ErrorRange, NoteRange; |
| 5477 | // If clause is read: |
| 5478 | // v = x; |
| 5479 | if (auto AtomicBody = dyn_cast<Expr>(Body)) { |
| 5480 | auto AtomicBinOp = |
| 5481 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 5482 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
| 5483 | X = AtomicBinOp->getRHS()->IgnoreParenImpCasts(); |
| 5484 | V = AtomicBinOp->getLHS()->IgnoreParenImpCasts(); |
| 5485 | if ((X->isInstantiationDependent() || X->getType()->isScalarType()) && |
| 5486 | (V->isInstantiationDependent() || V->getType()->isScalarType())) { |
| 5487 | if (!X->isLValue() || !V->isLValue()) { |
| 5488 | auto NotLValueExpr = X->isLValue() ? V : X; |
| 5489 | ErrorFound = NotAnLValue; |
| 5490 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5491 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5492 | NoteLoc = NotLValueExpr->getExprLoc(); |
| 5493 | NoteRange = NotLValueExpr->getSourceRange(); |
| 5494 | } |
| 5495 | } else if (!X->isInstantiationDependent() || |
| 5496 | !V->isInstantiationDependent()) { |
| 5497 | auto NotScalarExpr = |
| 5498 | (X->isInstantiationDependent() || X->getType()->isScalarType()) |
| 5499 | ? V |
| 5500 | : X; |
| 5501 | ErrorFound = NotAScalarType; |
| 5502 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5503 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5504 | NoteLoc = NotScalarExpr->getExprLoc(); |
| 5505 | NoteRange = NotScalarExpr->getSourceRange(); |
| 5506 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5507 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5508 | ErrorFound = NotAnAssignmentOp; |
| 5509 | ErrorLoc = AtomicBody->getExprLoc(); |
| 5510 | ErrorRange = AtomicBody->getSourceRange(); |
| 5511 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 5512 | : AtomicBody->getExprLoc(); |
| 5513 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 5514 | : AtomicBody->getSourceRange(); |
| 5515 | } |
| 5516 | } else { |
| 5517 | ErrorFound = NotAnExpression; |
| 5518 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 5519 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5520 | } |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5521 | if (ErrorFound != NoError) { |
| 5522 | Diag(ErrorLoc, diag::err_omp_atomic_read_not_expression_statement) |
| 5523 | << ErrorRange; |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5524 | Diag(NoteLoc, diag::note_omp_atomic_read_write) << ErrorFound |
| 5525 | << NoteRange; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5526 | return StmtError(); |
| 5527 | } else if (CurContext->isDependentContext()) |
| 5528 | V = X = nullptr; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5529 | } else if (AtomicKind == OMPC_write) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5530 | enum { |
| 5531 | NotAnExpression, |
| 5532 | NotAnAssignmentOp, |
| 5533 | NotAScalarType, |
| 5534 | NotAnLValue, |
| 5535 | NoError |
| 5536 | } ErrorFound = NoError; |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5537 | SourceLocation ErrorLoc, NoteLoc; |
| 5538 | SourceRange ErrorRange, NoteRange; |
| 5539 | // If clause is write: |
| 5540 | // x = expr; |
| 5541 | if (auto AtomicBody = dyn_cast<Expr>(Body)) { |
| 5542 | auto AtomicBinOp = |
| 5543 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 5544 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
Alexey Bataev | b832926 | 2015-02-27 06:33:30 +0000 | [diff] [blame] | 5545 | X = AtomicBinOp->getLHS(); |
| 5546 | E = AtomicBinOp->getRHS(); |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5547 | if ((X->isInstantiationDependent() || X->getType()->isScalarType()) && |
| 5548 | (E->isInstantiationDependent() || E->getType()->isScalarType())) { |
| 5549 | if (!X->isLValue()) { |
| 5550 | ErrorFound = NotAnLValue; |
| 5551 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5552 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5553 | NoteLoc = X->getExprLoc(); |
| 5554 | NoteRange = X->getSourceRange(); |
| 5555 | } |
| 5556 | } else if (!X->isInstantiationDependent() || |
| 5557 | !E->isInstantiationDependent()) { |
| 5558 | auto NotScalarExpr = |
| 5559 | (X->isInstantiationDependent() || X->getType()->isScalarType()) |
| 5560 | ? E |
| 5561 | : X; |
| 5562 | ErrorFound = NotAScalarType; |
| 5563 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5564 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5565 | NoteLoc = NotScalarExpr->getExprLoc(); |
| 5566 | NoteRange = NotScalarExpr->getSourceRange(); |
| 5567 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5568 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5569 | ErrorFound = NotAnAssignmentOp; |
| 5570 | ErrorLoc = AtomicBody->getExprLoc(); |
| 5571 | ErrorRange = AtomicBody->getSourceRange(); |
| 5572 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 5573 | : AtomicBody->getExprLoc(); |
| 5574 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 5575 | : AtomicBody->getSourceRange(); |
| 5576 | } |
| 5577 | } else { |
| 5578 | ErrorFound = NotAnExpression; |
| 5579 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 5580 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5581 | } |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5582 | if (ErrorFound != NoError) { |
| 5583 | Diag(ErrorLoc, diag::err_omp_atomic_write_not_expression_statement) |
| 5584 | << ErrorRange; |
| 5585 | Diag(NoteLoc, diag::note_omp_atomic_read_write) << ErrorFound |
| 5586 | << NoteRange; |
| 5587 | return StmtError(); |
| 5588 | } else if (CurContext->isDependentContext()) |
| 5589 | E = X = nullptr; |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5590 | } else if (AtomicKind == OMPC_update || AtomicKind == OMPC_unknown) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5591 | // If clause is update: |
| 5592 | // x++; |
| 5593 | // x--; |
| 5594 | // ++x; |
| 5595 | // --x; |
| 5596 | // x binop= expr; |
| 5597 | // x = x binop expr; |
| 5598 | // x = expr binop x; |
| 5599 | OpenMPAtomicUpdateChecker Checker(*this); |
| 5600 | if (Checker.checkStatement( |
| 5601 | Body, (AtomicKind == OMPC_update) |
| 5602 | ? diag::err_omp_atomic_update_not_expression_statement |
| 5603 | : diag::err_omp_atomic_not_expression_statement, |
| 5604 | diag::note_omp_atomic_update)) |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5605 | return StmtError(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5606 | if (!CurContext->isDependentContext()) { |
| 5607 | E = Checker.getExpr(); |
| 5608 | X = Checker.getX(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5609 | UE = Checker.getUpdateExpr(); |
| 5610 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5611 | } |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5612 | } else if (AtomicKind == OMPC_capture) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5613 | enum { |
| 5614 | NotAnAssignmentOp, |
| 5615 | NotACompoundStatement, |
| 5616 | NotTwoSubstatements, |
| 5617 | NotASpecificExpression, |
| 5618 | NoError |
| 5619 | } ErrorFound = NoError; |
| 5620 | SourceLocation ErrorLoc, NoteLoc; |
| 5621 | SourceRange ErrorRange, NoteRange; |
| 5622 | if (auto *AtomicBody = dyn_cast<Expr>(Body)) { |
| 5623 | // If clause is a capture: |
| 5624 | // v = x++; |
| 5625 | // v = x--; |
| 5626 | // v = ++x; |
| 5627 | // v = --x; |
| 5628 | // v = x binop= expr; |
| 5629 | // v = x = x binop expr; |
| 5630 | // v = x = expr binop x; |
| 5631 | auto *AtomicBinOp = |
| 5632 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 5633 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
| 5634 | V = AtomicBinOp->getLHS(); |
| 5635 | Body = AtomicBinOp->getRHS()->IgnoreParenImpCasts(); |
| 5636 | OpenMPAtomicUpdateChecker Checker(*this); |
| 5637 | if (Checker.checkStatement( |
| 5638 | Body, diag::err_omp_atomic_capture_not_expression_statement, |
| 5639 | diag::note_omp_atomic_update)) |
| 5640 | return StmtError(); |
| 5641 | E = Checker.getExpr(); |
| 5642 | X = Checker.getX(); |
| 5643 | UE = Checker.getUpdateExpr(); |
| 5644 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
| 5645 | IsPostfixUpdate = Checker.isPostfixUpdate(); |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5646 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5647 | ErrorLoc = AtomicBody->getExprLoc(); |
| 5648 | ErrorRange = AtomicBody->getSourceRange(); |
| 5649 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 5650 | : AtomicBody->getExprLoc(); |
| 5651 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 5652 | : AtomicBody->getSourceRange(); |
| 5653 | ErrorFound = NotAnAssignmentOp; |
| 5654 | } |
| 5655 | if (ErrorFound != NoError) { |
| 5656 | Diag(ErrorLoc, diag::err_omp_atomic_capture_not_expression_statement) |
| 5657 | << ErrorRange; |
| 5658 | Diag(NoteLoc, diag::note_omp_atomic_capture) << ErrorFound << NoteRange; |
| 5659 | return StmtError(); |
| 5660 | } else if (CurContext->isDependentContext()) { |
| 5661 | UE = V = E = X = nullptr; |
| 5662 | } |
| 5663 | } else { |
| 5664 | // If clause is a capture: |
| 5665 | // { v = x; x = expr; } |
| 5666 | // { v = x; x++; } |
| 5667 | // { v = x; x--; } |
| 5668 | // { v = x; ++x; } |
| 5669 | // { v = x; --x; } |
| 5670 | // { v = x; x binop= expr; } |
| 5671 | // { v = x; x = x binop expr; } |
| 5672 | // { v = x; x = expr binop x; } |
| 5673 | // { x++; v = x; } |
| 5674 | // { x--; v = x; } |
| 5675 | // { ++x; v = x; } |
| 5676 | // { --x; v = x; } |
| 5677 | // { x binop= expr; v = x; } |
| 5678 | // { x = x binop expr; v = x; } |
| 5679 | // { x = expr binop x; v = x; } |
| 5680 | if (auto *CS = dyn_cast<CompoundStmt>(Body)) { |
| 5681 | // Check that this is { expr1; expr2; } |
| 5682 | if (CS->size() == 2) { |
| 5683 | auto *First = CS->body_front(); |
| 5684 | auto *Second = CS->body_back(); |
| 5685 | if (auto *EWC = dyn_cast<ExprWithCleanups>(First)) |
| 5686 | First = EWC->getSubExpr()->IgnoreParenImpCasts(); |
| 5687 | if (auto *EWC = dyn_cast<ExprWithCleanups>(Second)) |
| 5688 | Second = EWC->getSubExpr()->IgnoreParenImpCasts(); |
| 5689 | // Need to find what subexpression is 'v' and what is 'x'. |
| 5690 | OpenMPAtomicUpdateChecker Checker(*this); |
| 5691 | bool IsUpdateExprFound = !Checker.checkStatement(Second); |
| 5692 | BinaryOperator *BinOp = nullptr; |
| 5693 | if (IsUpdateExprFound) { |
| 5694 | BinOp = dyn_cast<BinaryOperator>(First); |
| 5695 | IsUpdateExprFound = BinOp && BinOp->getOpcode() == BO_Assign; |
| 5696 | } |
| 5697 | if (IsUpdateExprFound && !CurContext->isDependentContext()) { |
| 5698 | // { v = x; x++; } |
| 5699 | // { v = x; x--; } |
| 5700 | // { v = x; ++x; } |
| 5701 | // { v = x; --x; } |
| 5702 | // { v = x; x binop= expr; } |
| 5703 | // { v = x; x = x binop expr; } |
| 5704 | // { v = x; x = expr binop x; } |
| 5705 | // Check that the first expression has form v = x. |
| 5706 | auto *PossibleX = BinOp->getRHS()->IgnoreParenImpCasts(); |
| 5707 | llvm::FoldingSetNodeID XId, PossibleXId; |
| 5708 | Checker.getX()->Profile(XId, Context, /*Canonical=*/true); |
| 5709 | PossibleX->Profile(PossibleXId, Context, /*Canonical=*/true); |
| 5710 | IsUpdateExprFound = XId == PossibleXId; |
| 5711 | if (IsUpdateExprFound) { |
| 5712 | V = BinOp->getLHS(); |
| 5713 | X = Checker.getX(); |
| 5714 | E = Checker.getExpr(); |
| 5715 | UE = Checker.getUpdateExpr(); |
| 5716 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5717 | IsPostfixUpdate = true; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5718 | } |
| 5719 | } |
| 5720 | if (!IsUpdateExprFound) { |
| 5721 | IsUpdateExprFound = !Checker.checkStatement(First); |
| 5722 | BinOp = nullptr; |
| 5723 | if (IsUpdateExprFound) { |
| 5724 | BinOp = dyn_cast<BinaryOperator>(Second); |
| 5725 | IsUpdateExprFound = BinOp && BinOp->getOpcode() == BO_Assign; |
| 5726 | } |
| 5727 | if (IsUpdateExprFound && !CurContext->isDependentContext()) { |
| 5728 | // { x++; v = x; } |
| 5729 | // { x--; v = x; } |
| 5730 | // { ++x; v = x; } |
| 5731 | // { --x; v = x; } |
| 5732 | // { x binop= expr; v = x; } |
| 5733 | // { x = x binop expr; v = x; } |
| 5734 | // { x = expr binop x; v = x; } |
| 5735 | // Check that the second expression has form v = x. |
| 5736 | auto *PossibleX = BinOp->getRHS()->IgnoreParenImpCasts(); |
| 5737 | llvm::FoldingSetNodeID XId, PossibleXId; |
| 5738 | Checker.getX()->Profile(XId, Context, /*Canonical=*/true); |
| 5739 | PossibleX->Profile(PossibleXId, Context, /*Canonical=*/true); |
| 5740 | IsUpdateExprFound = XId == PossibleXId; |
| 5741 | if (IsUpdateExprFound) { |
| 5742 | V = BinOp->getLHS(); |
| 5743 | X = Checker.getX(); |
| 5744 | E = Checker.getExpr(); |
| 5745 | UE = Checker.getUpdateExpr(); |
| 5746 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5747 | IsPostfixUpdate = false; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5748 | } |
| 5749 | } |
| 5750 | } |
| 5751 | if (!IsUpdateExprFound) { |
| 5752 | // { v = x; x = expr; } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5753 | auto *FirstExpr = dyn_cast<Expr>(First); |
| 5754 | auto *SecondExpr = dyn_cast<Expr>(Second); |
| 5755 | if (!FirstExpr || !SecondExpr || |
| 5756 | !(FirstExpr->isInstantiationDependent() || |
| 5757 | SecondExpr->isInstantiationDependent())) { |
| 5758 | auto *FirstBinOp = dyn_cast<BinaryOperator>(First); |
| 5759 | if (!FirstBinOp || FirstBinOp->getOpcode() != BO_Assign) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5760 | ErrorFound = NotAnAssignmentOp; |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5761 | NoteLoc = ErrorLoc = FirstBinOp ? FirstBinOp->getOperatorLoc() |
| 5762 | : First->getLocStart(); |
| 5763 | NoteRange = ErrorRange = FirstBinOp |
| 5764 | ? FirstBinOp->getSourceRange() |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5765 | : SourceRange(ErrorLoc, ErrorLoc); |
| 5766 | } else { |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5767 | auto *SecondBinOp = dyn_cast<BinaryOperator>(Second); |
| 5768 | if (!SecondBinOp || SecondBinOp->getOpcode() != BO_Assign) { |
| 5769 | ErrorFound = NotAnAssignmentOp; |
| 5770 | NoteLoc = ErrorLoc = SecondBinOp |
| 5771 | ? SecondBinOp->getOperatorLoc() |
| 5772 | : Second->getLocStart(); |
| 5773 | NoteRange = ErrorRange = |
| 5774 | SecondBinOp ? SecondBinOp->getSourceRange() |
| 5775 | : SourceRange(ErrorLoc, ErrorLoc); |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5776 | } else { |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5777 | auto *PossibleXRHSInFirst = |
| 5778 | FirstBinOp->getRHS()->IgnoreParenImpCasts(); |
| 5779 | auto *PossibleXLHSInSecond = |
| 5780 | SecondBinOp->getLHS()->IgnoreParenImpCasts(); |
| 5781 | llvm::FoldingSetNodeID X1Id, X2Id; |
| 5782 | PossibleXRHSInFirst->Profile(X1Id, Context, |
| 5783 | /*Canonical=*/true); |
| 5784 | PossibleXLHSInSecond->Profile(X2Id, Context, |
| 5785 | /*Canonical=*/true); |
| 5786 | IsUpdateExprFound = X1Id == X2Id; |
| 5787 | if (IsUpdateExprFound) { |
| 5788 | V = FirstBinOp->getLHS(); |
| 5789 | X = SecondBinOp->getLHS(); |
| 5790 | E = SecondBinOp->getRHS(); |
| 5791 | UE = nullptr; |
| 5792 | IsXLHSInRHSPart = false; |
| 5793 | IsPostfixUpdate = true; |
| 5794 | } else { |
| 5795 | ErrorFound = NotASpecificExpression; |
| 5796 | ErrorLoc = FirstBinOp->getExprLoc(); |
| 5797 | ErrorRange = FirstBinOp->getSourceRange(); |
| 5798 | NoteLoc = SecondBinOp->getLHS()->getExprLoc(); |
| 5799 | NoteRange = SecondBinOp->getRHS()->getSourceRange(); |
| 5800 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5801 | } |
| 5802 | } |
| 5803 | } |
| 5804 | } |
| 5805 | } else { |
| 5806 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 5807 | NoteRange = ErrorRange = |
| 5808 | SourceRange(Body->getLocStart(), Body->getLocStart()); |
| 5809 | ErrorFound = NotTwoSubstatements; |
| 5810 | } |
| 5811 | } else { |
| 5812 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 5813 | NoteRange = ErrorRange = |
| 5814 | SourceRange(Body->getLocStart(), Body->getLocStart()); |
| 5815 | ErrorFound = NotACompoundStatement; |
| 5816 | } |
| 5817 | if (ErrorFound != NoError) { |
| 5818 | Diag(ErrorLoc, diag::err_omp_atomic_capture_not_compound_statement) |
| 5819 | << ErrorRange; |
| 5820 | Diag(NoteLoc, diag::note_omp_atomic_capture) << ErrorFound << NoteRange; |
| 5821 | return StmtError(); |
| 5822 | } else if (CurContext->isDependentContext()) { |
| 5823 | UE = V = E = X = nullptr; |
| 5824 | } |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5825 | } |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5826 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 5827 | |
| 5828 | getCurFunction()->setHasBranchProtectedScope(); |
| 5829 | |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5830 | return OMPAtomicDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5831 | X, V, E, UE, IsXLHSInRHSPart, |
| 5832 | IsPostfixUpdate); |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 5833 | } |
| 5834 | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 5835 | StmtResult Sema::ActOnOpenMPTargetDirective(ArrayRef<OMPClause *> Clauses, |
| 5836 | Stmt *AStmt, |
| 5837 | SourceLocation StartLoc, |
| 5838 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5839 | if (!AStmt) |
| 5840 | return StmtError(); |
| 5841 | |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 5842 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 5843 | // 1.2.2 OpenMP Language Terminology |
| 5844 | // Structured block - An executable statement with a single entry at the |
| 5845 | // top and a single exit at the bottom. |
| 5846 | // The point of exit cannot be a branch out of the structured block. |
| 5847 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5848 | CS->getCapturedDecl()->setNothrow(); |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 5849 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 5850 | // OpenMP [2.16, Nesting of Regions] |
| 5851 | // If specified, a teams construct must be contained within a target |
| 5852 | // construct. That target construct must contain no statements or directives |
| 5853 | // outside of the teams construct. |
| 5854 | if (DSAStack->hasInnerTeamsRegion()) { |
| 5855 | auto S = AStmt->IgnoreContainers(/*IgnoreCaptured*/ true); |
| 5856 | bool OMPTeamsFound = true; |
| 5857 | if (auto *CS = dyn_cast<CompoundStmt>(S)) { |
| 5858 | auto I = CS->body_begin(); |
| 5859 | while (I != CS->body_end()) { |
| 5860 | auto OED = dyn_cast<OMPExecutableDirective>(*I); |
| 5861 | if (!OED || !isOpenMPTeamsDirective(OED->getDirectiveKind())) { |
| 5862 | OMPTeamsFound = false; |
| 5863 | break; |
| 5864 | } |
| 5865 | ++I; |
| 5866 | } |
| 5867 | assert(I != CS->body_end() && "Not found statement"); |
| 5868 | S = *I; |
| 5869 | } |
| 5870 | if (!OMPTeamsFound) { |
| 5871 | Diag(StartLoc, diag::err_omp_target_contains_not_only_teams); |
| 5872 | Diag(DSAStack->getInnerTeamsRegionLoc(), |
| 5873 | diag::note_omp_nested_teams_construct_here); |
| 5874 | Diag(S->getLocStart(), diag::note_omp_nested_statement_here) |
| 5875 | << isa<OMPExecutableDirective>(S); |
| 5876 | return StmtError(); |
| 5877 | } |
| 5878 | } |
| 5879 | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 5880 | getCurFunction()->setHasBranchProtectedScope(); |
| 5881 | |
| 5882 | return OMPTargetDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 5883 | } |
| 5884 | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 5885 | StmtResult |
| 5886 | Sema::ActOnOpenMPTargetParallelDirective(ArrayRef<OMPClause *> Clauses, |
| 5887 | Stmt *AStmt, SourceLocation StartLoc, |
| 5888 | SourceLocation EndLoc) { |
| 5889 | if (!AStmt) |
| 5890 | return StmtError(); |
| 5891 | |
| 5892 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 5893 | // 1.2.2 OpenMP Language Terminology |
| 5894 | // Structured block - An executable statement with a single entry at the |
| 5895 | // top and a single exit at the bottom. |
| 5896 | // The point of exit cannot be a branch out of the structured block. |
| 5897 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5898 | CS->getCapturedDecl()->setNothrow(); |
| 5899 | |
| 5900 | getCurFunction()->setHasBranchProtectedScope(); |
| 5901 | |
| 5902 | return OMPTargetParallelDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 5903 | AStmt); |
| 5904 | } |
| 5905 | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 5906 | StmtResult Sema::ActOnOpenMPTargetParallelForDirective( |
| 5907 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 5908 | SourceLocation EndLoc, |
| 5909 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 5910 | if (!AStmt) |
| 5911 | return StmtError(); |
| 5912 | |
| 5913 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 5914 | // 1.2.2 OpenMP Language Terminology |
| 5915 | // Structured block - An executable statement with a single entry at the |
| 5916 | // top and a single exit at the bottom. |
| 5917 | // The point of exit cannot be a branch out of the structured block. |
| 5918 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5919 | CS->getCapturedDecl()->setNothrow(); |
| 5920 | |
| 5921 | OMPLoopDirective::HelperExprs B; |
| 5922 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 5923 | // define the nested loops number. |
| 5924 | unsigned NestedLoopCount = |
| 5925 | CheckOpenMPLoop(OMPD_target_parallel_for, getCollapseNumberExpr(Clauses), |
| 5926 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 5927 | VarsWithImplicitDSA, B); |
| 5928 | if (NestedLoopCount == 0) |
| 5929 | return StmtError(); |
| 5930 | |
| 5931 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 5932 | "omp target parallel for loop exprs were not built"); |
| 5933 | |
| 5934 | if (!CurContext->isDependentContext()) { |
| 5935 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 5936 | for (auto C : Clauses) { |
| 5937 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 5938 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 5939 | B.NumIterations, *this, CurScope)) |
| 5940 | return StmtError(); |
| 5941 | } |
| 5942 | } |
| 5943 | |
| 5944 | getCurFunction()->setHasBranchProtectedScope(); |
| 5945 | return OMPTargetParallelForDirective::Create(Context, StartLoc, EndLoc, |
| 5946 | NestedLoopCount, Clauses, AStmt, |
| 5947 | B, DSAStack->isCancelRegion()); |
| 5948 | } |
| 5949 | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 5950 | /// \brief Check for existence of a map clause in the list of clauses. |
| 5951 | static bool HasMapClause(ArrayRef<OMPClause *> Clauses) { |
| 5952 | for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end(); |
| 5953 | I != E; ++I) { |
| 5954 | if (*I != nullptr && (*I)->getClauseKind() == OMPC_map) { |
| 5955 | return true; |
| 5956 | } |
| 5957 | } |
| 5958 | |
| 5959 | return false; |
| 5960 | } |
| 5961 | |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 5962 | StmtResult Sema::ActOnOpenMPTargetDataDirective(ArrayRef<OMPClause *> Clauses, |
| 5963 | Stmt *AStmt, |
| 5964 | SourceLocation StartLoc, |
| 5965 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5966 | if (!AStmt) |
| 5967 | return StmtError(); |
| 5968 | |
| 5969 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 5970 | |
Arpith Chacko Jacob | 46a04bb | 2016-01-21 19:57:55 +0000 | [diff] [blame] | 5971 | // OpenMP [2.10.1, Restrictions, p. 97] |
| 5972 | // At least one map clause must appear on the directive. |
| 5973 | if (!HasMapClause(Clauses)) { |
| 5974 | Diag(StartLoc, diag::err_omp_no_map_for_directive) << |
| 5975 | getOpenMPDirectiveName(OMPD_target_data); |
| 5976 | return StmtError(); |
| 5977 | } |
| 5978 | |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 5979 | getCurFunction()->setHasBranchProtectedScope(); |
| 5980 | |
| 5981 | return OMPTargetDataDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 5982 | AStmt); |
| 5983 | } |
| 5984 | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 5985 | StmtResult |
| 5986 | Sema::ActOnOpenMPTargetEnterDataDirective(ArrayRef<OMPClause *> Clauses, |
| 5987 | SourceLocation StartLoc, |
| 5988 | SourceLocation EndLoc) { |
| 5989 | // OpenMP [2.10.2, Restrictions, p. 99] |
| 5990 | // At least one map clause must appear on the directive. |
| 5991 | if (!HasMapClause(Clauses)) { |
| 5992 | Diag(StartLoc, diag::err_omp_no_map_for_directive) |
| 5993 | << getOpenMPDirectiveName(OMPD_target_enter_data); |
| 5994 | return StmtError(); |
| 5995 | } |
| 5996 | |
| 5997 | return OMPTargetEnterDataDirective::Create(Context, StartLoc, EndLoc, |
| 5998 | Clauses); |
| 5999 | } |
| 6000 | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 6001 | StmtResult |
| 6002 | Sema::ActOnOpenMPTargetExitDataDirective(ArrayRef<OMPClause *> Clauses, |
| 6003 | SourceLocation StartLoc, |
| 6004 | SourceLocation EndLoc) { |
| 6005 | // OpenMP [2.10.3, Restrictions, p. 102] |
| 6006 | // At least one map clause must appear on the directive. |
| 6007 | if (!HasMapClause(Clauses)) { |
| 6008 | Diag(StartLoc, diag::err_omp_no_map_for_directive) |
| 6009 | << getOpenMPDirectiveName(OMPD_target_exit_data); |
| 6010 | return StmtError(); |
| 6011 | } |
| 6012 | |
| 6013 | return OMPTargetExitDataDirective::Create(Context, StartLoc, EndLoc, Clauses); |
| 6014 | } |
| 6015 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 6016 | StmtResult Sema::ActOnOpenMPTeamsDirective(ArrayRef<OMPClause *> Clauses, |
| 6017 | Stmt *AStmt, SourceLocation StartLoc, |
| 6018 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6019 | if (!AStmt) |
| 6020 | return StmtError(); |
| 6021 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 6022 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6023 | // 1.2.2 OpenMP Language Terminology |
| 6024 | // Structured block - An executable statement with a single entry at the |
| 6025 | // top and a single exit at the bottom. |
| 6026 | // The point of exit cannot be a branch out of the structured block. |
| 6027 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6028 | CS->getCapturedDecl()->setNothrow(); |
| 6029 | |
| 6030 | getCurFunction()->setHasBranchProtectedScope(); |
| 6031 | |
| 6032 | return OMPTeamsDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 6033 | } |
| 6034 | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 6035 | StmtResult |
| 6036 | Sema::ActOnOpenMPCancellationPointDirective(SourceLocation StartLoc, |
| 6037 | SourceLocation EndLoc, |
| 6038 | OpenMPDirectiveKind CancelRegion) { |
| 6039 | if (CancelRegion != OMPD_parallel && CancelRegion != OMPD_for && |
| 6040 | CancelRegion != OMPD_sections && CancelRegion != OMPD_taskgroup) { |
| 6041 | Diag(StartLoc, diag::err_omp_wrong_cancel_region) |
| 6042 | << getOpenMPDirectiveName(CancelRegion); |
| 6043 | return StmtError(); |
| 6044 | } |
| 6045 | if (DSAStack->isParentNowaitRegion()) { |
| 6046 | Diag(StartLoc, diag::err_omp_parent_cancel_region_nowait) << 0; |
| 6047 | return StmtError(); |
| 6048 | } |
| 6049 | if (DSAStack->isParentOrderedRegion()) { |
| 6050 | Diag(StartLoc, diag::err_omp_parent_cancel_region_ordered) << 0; |
| 6051 | return StmtError(); |
| 6052 | } |
| 6053 | return OMPCancellationPointDirective::Create(Context, StartLoc, EndLoc, |
| 6054 | CancelRegion); |
| 6055 | } |
| 6056 | |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 6057 | StmtResult Sema::ActOnOpenMPCancelDirective(ArrayRef<OMPClause *> Clauses, |
| 6058 | SourceLocation StartLoc, |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 6059 | SourceLocation EndLoc, |
| 6060 | OpenMPDirectiveKind CancelRegion) { |
| 6061 | if (CancelRegion != OMPD_parallel && CancelRegion != OMPD_for && |
| 6062 | CancelRegion != OMPD_sections && CancelRegion != OMPD_taskgroup) { |
| 6063 | Diag(StartLoc, diag::err_omp_wrong_cancel_region) |
| 6064 | << getOpenMPDirectiveName(CancelRegion); |
| 6065 | return StmtError(); |
| 6066 | } |
| 6067 | if (DSAStack->isParentNowaitRegion()) { |
| 6068 | Diag(StartLoc, diag::err_omp_parent_cancel_region_nowait) << 1; |
| 6069 | return StmtError(); |
| 6070 | } |
| 6071 | if (DSAStack->isParentOrderedRegion()) { |
| 6072 | Diag(StartLoc, diag::err_omp_parent_cancel_region_ordered) << 1; |
| 6073 | return StmtError(); |
| 6074 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 6075 | DSAStack->setParentCancelRegion(/*Cancel=*/true); |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 6076 | return OMPCancelDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 6077 | CancelRegion); |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 6078 | } |
| 6079 | |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6080 | static bool checkGrainsizeNumTasksClauses(Sema &S, |
| 6081 | ArrayRef<OMPClause *> Clauses) { |
| 6082 | OMPClause *PrevClause = nullptr; |
| 6083 | bool ErrorFound = false; |
| 6084 | for (auto *C : Clauses) { |
| 6085 | if (C->getClauseKind() == OMPC_grainsize || |
| 6086 | C->getClauseKind() == OMPC_num_tasks) { |
| 6087 | if (!PrevClause) |
| 6088 | PrevClause = C; |
| 6089 | else if (PrevClause->getClauseKind() != C->getClauseKind()) { |
| 6090 | S.Diag(C->getLocStart(), |
| 6091 | diag::err_omp_grainsize_num_tasks_mutually_exclusive) |
| 6092 | << getOpenMPClauseName(C->getClauseKind()) |
| 6093 | << getOpenMPClauseName(PrevClause->getClauseKind()); |
| 6094 | S.Diag(PrevClause->getLocStart(), |
| 6095 | diag::note_omp_previous_grainsize_num_tasks) |
| 6096 | << getOpenMPClauseName(PrevClause->getClauseKind()); |
| 6097 | ErrorFound = true; |
| 6098 | } |
| 6099 | } |
| 6100 | } |
| 6101 | return ErrorFound; |
| 6102 | } |
| 6103 | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 6104 | StmtResult Sema::ActOnOpenMPTaskLoopDirective( |
| 6105 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6106 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 6107 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 6108 | if (!AStmt) |
| 6109 | return StmtError(); |
| 6110 | |
| 6111 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 6112 | OMPLoopDirective::HelperExprs B; |
| 6113 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 6114 | // define the nested loops number. |
| 6115 | unsigned NestedLoopCount = |
| 6116 | CheckOpenMPLoop(OMPD_taskloop, getCollapseNumberExpr(Clauses), |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 6117 | /*OrderedLoopCountExpr=*/nullptr, AStmt, *this, *DSAStack, |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 6118 | VarsWithImplicitDSA, B); |
| 6119 | if (NestedLoopCount == 0) |
| 6120 | return StmtError(); |
| 6121 | |
| 6122 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6123 | "omp for loop exprs were not built"); |
| 6124 | |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6125 | // OpenMP, [2.9.2 taskloop Construct, Restrictions] |
| 6126 | // The grainsize clause and num_tasks clause are mutually exclusive and may |
| 6127 | // not appear on the same taskloop directive. |
| 6128 | if (checkGrainsizeNumTasksClauses(*this, Clauses)) |
| 6129 | return StmtError(); |
| 6130 | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 6131 | getCurFunction()->setHasBranchProtectedScope(); |
| 6132 | return OMPTaskLoopDirective::Create(Context, StartLoc, EndLoc, |
| 6133 | NestedLoopCount, Clauses, AStmt, B); |
| 6134 | } |
| 6135 | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 6136 | StmtResult Sema::ActOnOpenMPTaskLoopSimdDirective( |
| 6137 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6138 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 6139 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 6140 | if (!AStmt) |
| 6141 | return StmtError(); |
| 6142 | |
| 6143 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 6144 | OMPLoopDirective::HelperExprs B; |
| 6145 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 6146 | // define the nested loops number. |
| 6147 | unsigned NestedLoopCount = |
| 6148 | CheckOpenMPLoop(OMPD_taskloop_simd, getCollapseNumberExpr(Clauses), |
| 6149 | /*OrderedLoopCountExpr=*/nullptr, AStmt, *this, *DSAStack, |
| 6150 | VarsWithImplicitDSA, B); |
| 6151 | if (NestedLoopCount == 0) |
| 6152 | return StmtError(); |
| 6153 | |
| 6154 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6155 | "omp for loop exprs were not built"); |
| 6156 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 6157 | if (!CurContext->isDependentContext()) { |
| 6158 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 6159 | for (auto C : Clauses) { |
| 6160 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 6161 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 6162 | B.NumIterations, *this, CurScope)) |
| 6163 | return StmtError(); |
| 6164 | } |
| 6165 | } |
| 6166 | |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6167 | // OpenMP, [2.9.2 taskloop Construct, Restrictions] |
| 6168 | // The grainsize clause and num_tasks clause are mutually exclusive and may |
| 6169 | // not appear on the same taskloop directive. |
| 6170 | if (checkGrainsizeNumTasksClauses(*this, Clauses)) |
| 6171 | return StmtError(); |
| 6172 | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 6173 | getCurFunction()->setHasBranchProtectedScope(); |
| 6174 | return OMPTaskLoopSimdDirective::Create(Context, StartLoc, EndLoc, |
| 6175 | NestedLoopCount, Clauses, AStmt, B); |
| 6176 | } |
| 6177 | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 6178 | StmtResult Sema::ActOnOpenMPDistributeDirective( |
| 6179 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6180 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 6181 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 6182 | if (!AStmt) |
| 6183 | return StmtError(); |
| 6184 | |
| 6185 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 6186 | OMPLoopDirective::HelperExprs B; |
| 6187 | // In presence of clause 'collapse' with number of loops, it will |
| 6188 | // define the nested loops number. |
| 6189 | unsigned NestedLoopCount = |
| 6190 | CheckOpenMPLoop(OMPD_distribute, getCollapseNumberExpr(Clauses), |
| 6191 | nullptr /*ordered not a clause on distribute*/, AStmt, |
| 6192 | *this, *DSAStack, VarsWithImplicitDSA, B); |
| 6193 | if (NestedLoopCount == 0) |
| 6194 | return StmtError(); |
| 6195 | |
| 6196 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6197 | "omp for loop exprs were not built"); |
| 6198 | |
| 6199 | getCurFunction()->setHasBranchProtectedScope(); |
| 6200 | return OMPDistributeDirective::Create(Context, StartLoc, EndLoc, |
| 6201 | NestedLoopCount, Clauses, AStmt, B); |
| 6202 | } |
| 6203 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6204 | OMPClause *Sema::ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, Expr *Expr, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6205 | SourceLocation StartLoc, |
| 6206 | SourceLocation LParenLoc, |
| 6207 | SourceLocation EndLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6208 | OMPClause *Res = nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6209 | switch (Kind) { |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 6210 | case OMPC_final: |
| 6211 | Res = ActOnOpenMPFinalClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6212 | break; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6213 | case OMPC_num_threads: |
| 6214 | Res = ActOnOpenMPNumThreadsClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6215 | break; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6216 | case OMPC_safelen: |
| 6217 | Res = ActOnOpenMPSafelenClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6218 | break; |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 6219 | case OMPC_simdlen: |
| 6220 | Res = ActOnOpenMPSimdlenClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6221 | break; |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6222 | case OMPC_collapse: |
| 6223 | Res = ActOnOpenMPCollapseClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6224 | break; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 6225 | case OMPC_ordered: |
| 6226 | Res = ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Expr); |
| 6227 | break; |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 6228 | case OMPC_device: |
| 6229 | Res = ActOnOpenMPDeviceClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6230 | break; |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 6231 | case OMPC_num_teams: |
| 6232 | Res = ActOnOpenMPNumTeamsClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6233 | break; |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6234 | case OMPC_thread_limit: |
| 6235 | Res = ActOnOpenMPThreadLimitClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6236 | break; |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6237 | case OMPC_priority: |
| 6238 | Res = ActOnOpenMPPriorityClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6239 | break; |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 6240 | case OMPC_grainsize: |
| 6241 | Res = ActOnOpenMPGrainsizeClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6242 | break; |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6243 | case OMPC_num_tasks: |
| 6244 | Res = ActOnOpenMPNumTasksClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6245 | break; |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 6246 | case OMPC_hint: |
| 6247 | Res = ActOnOpenMPHintClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6248 | break; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6249 | case OMPC_if: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6250 | case OMPC_default: |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6251 | case OMPC_proc_bind: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6252 | case OMPC_schedule: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6253 | case OMPC_private: |
| 6254 | case OMPC_firstprivate: |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6255 | case OMPC_lastprivate: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6256 | case OMPC_shared: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6257 | case OMPC_reduction: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6258 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 6259 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6260 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6261 | case OMPC_copyprivate: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6262 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 6263 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 6264 | case OMPC_mergeable: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6265 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 6266 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6267 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6268 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6269 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6270 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 6271 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6272 | case OMPC_depend: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6273 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6274 | case OMPC_simd: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 6275 | case OMPC_map: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 6276 | case OMPC_nogroup: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 6277 | case OMPC_dist_schedule: |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 6278 | case OMPC_defaultmap: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6279 | case OMPC_unknown: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6280 | llvm_unreachable("Clause is not allowed."); |
| 6281 | } |
| 6282 | return Res; |
| 6283 | } |
| 6284 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6285 | OMPClause *Sema::ActOnOpenMPIfClause(OpenMPDirectiveKind NameModifier, |
| 6286 | Expr *Condition, SourceLocation StartLoc, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6287 | SourceLocation LParenLoc, |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6288 | SourceLocation NameModifierLoc, |
| 6289 | SourceLocation ColonLoc, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6290 | SourceLocation EndLoc) { |
| 6291 | Expr *ValExpr = Condition; |
| 6292 | if (!Condition->isValueDependent() && !Condition->isTypeDependent() && |
| 6293 | !Condition->isInstantiationDependent() && |
| 6294 | !Condition->containsUnexpandedParameterPack()) { |
| 6295 | ExprResult Val = ActOnBooleanCondition(DSAStack->getCurScope(), |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6296 | Condition->getExprLoc(), Condition); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6297 | if (Val.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6298 | return nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6299 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6300 | ValExpr = Val.get(); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6301 | } |
| 6302 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6303 | return new (Context) OMPIfClause(NameModifier, ValExpr, StartLoc, LParenLoc, |
| 6304 | NameModifierLoc, ColonLoc, EndLoc); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6305 | } |
| 6306 | |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 6307 | OMPClause *Sema::ActOnOpenMPFinalClause(Expr *Condition, |
| 6308 | SourceLocation StartLoc, |
| 6309 | SourceLocation LParenLoc, |
| 6310 | SourceLocation EndLoc) { |
| 6311 | Expr *ValExpr = Condition; |
| 6312 | if (!Condition->isValueDependent() && !Condition->isTypeDependent() && |
| 6313 | !Condition->isInstantiationDependent() && |
| 6314 | !Condition->containsUnexpandedParameterPack()) { |
| 6315 | ExprResult Val = ActOnBooleanCondition(DSAStack->getCurScope(), |
| 6316 | Condition->getExprLoc(), Condition); |
| 6317 | if (Val.isInvalid()) |
| 6318 | return nullptr; |
| 6319 | |
| 6320 | ValExpr = Val.get(); |
| 6321 | } |
| 6322 | |
| 6323 | return new (Context) OMPFinalClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 6324 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 6325 | ExprResult Sema::PerformOpenMPImplicitIntegerConversion(SourceLocation Loc, |
| 6326 | Expr *Op) { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6327 | if (!Op) |
| 6328 | return ExprError(); |
| 6329 | |
| 6330 | class IntConvertDiagnoser : public ICEConvertDiagnoser { |
| 6331 | public: |
| 6332 | IntConvertDiagnoser() |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6333 | : ICEConvertDiagnoser(/*AllowScopedEnumerations*/ false, false, true) {} |
Craig Topper | e14c0f8 | 2014-03-12 04:55:44 +0000 | [diff] [blame] | 6334 | SemaDiagnosticBuilder diagnoseNotInt(Sema &S, SourceLocation Loc, |
| 6335 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6336 | return S.Diag(Loc, diag::err_omp_not_integral) << T; |
| 6337 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6338 | SemaDiagnosticBuilder diagnoseIncomplete(Sema &S, SourceLocation Loc, |
| 6339 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6340 | return S.Diag(Loc, diag::err_omp_incomplete_type) << T; |
| 6341 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6342 | SemaDiagnosticBuilder diagnoseExplicitConv(Sema &S, SourceLocation Loc, |
| 6343 | QualType T, |
| 6344 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6345 | return S.Diag(Loc, diag::err_omp_explicit_conversion) << T << ConvTy; |
| 6346 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6347 | SemaDiagnosticBuilder noteExplicitConv(Sema &S, CXXConversionDecl *Conv, |
| 6348 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6349 | return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6350 | << ConvTy->isEnumeralType() << ConvTy; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6351 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6352 | SemaDiagnosticBuilder diagnoseAmbiguous(Sema &S, SourceLocation Loc, |
| 6353 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6354 | return S.Diag(Loc, diag::err_omp_ambiguous_conversion) << T; |
| 6355 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6356 | SemaDiagnosticBuilder noteAmbiguous(Sema &S, CXXConversionDecl *Conv, |
| 6357 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6358 | return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6359 | << ConvTy->isEnumeralType() << ConvTy; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6360 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6361 | SemaDiagnosticBuilder diagnoseConversion(Sema &, SourceLocation, QualType, |
| 6362 | QualType) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6363 | llvm_unreachable("conversion functions are permitted"); |
| 6364 | } |
| 6365 | } ConvertDiagnoser; |
| 6366 | return PerformContextualImplicitConversion(Loc, Op, ConvertDiagnoser); |
| 6367 | } |
| 6368 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6369 | static bool IsNonNegativeIntegerValue(Expr *&ValExpr, Sema &SemaRef, |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6370 | OpenMPClauseKind CKind, |
| 6371 | bool StrictlyPositive) { |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6372 | if (!ValExpr->isTypeDependent() && !ValExpr->isValueDependent() && |
| 6373 | !ValExpr->isInstantiationDependent()) { |
| 6374 | SourceLocation Loc = ValExpr->getExprLoc(); |
| 6375 | ExprResult Value = |
| 6376 | SemaRef.PerformOpenMPImplicitIntegerConversion(Loc, ValExpr); |
| 6377 | if (Value.isInvalid()) |
| 6378 | return false; |
| 6379 | |
| 6380 | ValExpr = Value.get(); |
| 6381 | // The expression must evaluate to a non-negative integer value. |
| 6382 | llvm::APSInt Result; |
| 6383 | if (ValExpr->isIntegerConstantExpr(Result, SemaRef.Context) && |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6384 | Result.isSigned() && |
| 6385 | !((!StrictlyPositive && Result.isNonNegative()) || |
| 6386 | (StrictlyPositive && Result.isStrictlyPositive()))) { |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6387 | SemaRef.Diag(Loc, diag::err_omp_negative_expression_in_clause) |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6388 | << getOpenMPClauseName(CKind) << (StrictlyPositive ? 1 : 0) |
| 6389 | << ValExpr->getSourceRange(); |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6390 | return false; |
| 6391 | } |
| 6392 | } |
| 6393 | return true; |
| 6394 | } |
| 6395 | |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6396 | OMPClause *Sema::ActOnOpenMPNumThreadsClause(Expr *NumThreads, |
| 6397 | SourceLocation StartLoc, |
| 6398 | SourceLocation LParenLoc, |
| 6399 | SourceLocation EndLoc) { |
| 6400 | Expr *ValExpr = NumThreads; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6401 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6402 | // OpenMP [2.5, Restrictions] |
| 6403 | // The num_threads expression must evaluate to a positive integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6404 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_num_threads, |
| 6405 | /*StrictlyPositive=*/true)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6406 | return nullptr; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6407 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6408 | return new (Context) |
| 6409 | OMPNumThreadsClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6410 | } |
| 6411 | |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6412 | ExprResult Sema::VerifyPositiveIntegerConstantInClause(Expr *E, |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 6413 | OpenMPClauseKind CKind, |
| 6414 | bool StrictlyPositive) { |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6415 | if (!E) |
| 6416 | return ExprError(); |
| 6417 | if (E->isValueDependent() || E->isTypeDependent() || |
| 6418 | E->isInstantiationDependent() || E->containsUnexpandedParameterPack()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6419 | return E; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6420 | llvm::APSInt Result; |
| 6421 | ExprResult ICE = VerifyIntegerConstantExpression(E, &Result); |
| 6422 | if (ICE.isInvalid()) |
| 6423 | return ExprError(); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 6424 | if ((StrictlyPositive && !Result.isStrictlyPositive()) || |
| 6425 | (!StrictlyPositive && !Result.isNonNegative())) { |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6426 | Diag(E->getExprLoc(), diag::err_omp_negative_expression_in_clause) |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 6427 | << getOpenMPClauseName(CKind) << (StrictlyPositive ? 1 : 0) |
| 6428 | << E->getSourceRange(); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6429 | return ExprError(); |
| 6430 | } |
Alexander Musman | 09184fe | 2014-09-30 05:29:28 +0000 | [diff] [blame] | 6431 | if (CKind == OMPC_aligned && !Result.isPowerOf2()) { |
| 6432 | Diag(E->getExprLoc(), diag::warn_omp_alignment_not_power_of_two) |
| 6433 | << E->getSourceRange(); |
| 6434 | return ExprError(); |
| 6435 | } |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 6436 | if (CKind == OMPC_collapse && DSAStack->getAssociatedLoops() == 1) |
| 6437 | DSAStack->setAssociatedLoops(Result.getExtValue()); |
Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 6438 | else if (CKind == OMPC_ordered) |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 6439 | DSAStack->setAssociatedLoops(Result.getExtValue()); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6440 | return ICE; |
| 6441 | } |
| 6442 | |
| 6443 | OMPClause *Sema::ActOnOpenMPSafelenClause(Expr *Len, SourceLocation StartLoc, |
| 6444 | SourceLocation LParenLoc, |
| 6445 | SourceLocation EndLoc) { |
| 6446 | // OpenMP [2.8.1, simd construct, Description] |
| 6447 | // The parameter of the safelen clause must be a constant |
| 6448 | // positive integer expression. |
| 6449 | ExprResult Safelen = VerifyPositiveIntegerConstantInClause(Len, OMPC_safelen); |
| 6450 | if (Safelen.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6451 | return nullptr; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6452 | return new (Context) |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6453 | OMPSafelenClause(Safelen.get(), StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6454 | } |
| 6455 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 6456 | OMPClause *Sema::ActOnOpenMPSimdlenClause(Expr *Len, SourceLocation StartLoc, |
| 6457 | SourceLocation LParenLoc, |
| 6458 | SourceLocation EndLoc) { |
| 6459 | // OpenMP [2.8.1, simd construct, Description] |
| 6460 | // The parameter of the simdlen clause must be a constant |
| 6461 | // positive integer expression. |
| 6462 | ExprResult Simdlen = VerifyPositiveIntegerConstantInClause(Len, OMPC_simdlen); |
| 6463 | if (Simdlen.isInvalid()) |
| 6464 | return nullptr; |
| 6465 | return new (Context) |
| 6466 | OMPSimdlenClause(Simdlen.get(), StartLoc, LParenLoc, EndLoc); |
| 6467 | } |
| 6468 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6469 | OMPClause *Sema::ActOnOpenMPCollapseClause(Expr *NumForLoops, |
| 6470 | SourceLocation StartLoc, |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6471 | SourceLocation LParenLoc, |
| 6472 | SourceLocation EndLoc) { |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6473 | // OpenMP [2.7.1, loop construct, Description] |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6474 | // OpenMP [2.8.1, simd construct, Description] |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6475 | // OpenMP [2.9.6, distribute construct, Description] |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6476 | // The parameter of the collapse clause must be a constant |
| 6477 | // positive integer expression. |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6478 | ExprResult NumForLoopsResult = |
| 6479 | VerifyPositiveIntegerConstantInClause(NumForLoops, OMPC_collapse); |
| 6480 | if (NumForLoopsResult.isInvalid()) |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6481 | return nullptr; |
| 6482 | return new (Context) |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6483 | OMPCollapseClause(NumForLoopsResult.get(), StartLoc, LParenLoc, EndLoc); |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6484 | } |
| 6485 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 6486 | OMPClause *Sema::ActOnOpenMPOrderedClause(SourceLocation StartLoc, |
| 6487 | SourceLocation EndLoc, |
| 6488 | SourceLocation LParenLoc, |
| 6489 | Expr *NumForLoops) { |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 6490 | // OpenMP [2.7.1, loop construct, Description] |
| 6491 | // OpenMP [2.8.1, simd construct, Description] |
| 6492 | // OpenMP [2.9.6, distribute construct, Description] |
| 6493 | // The parameter of the ordered clause must be a constant |
| 6494 | // positive integer expression if any. |
| 6495 | if (NumForLoops && LParenLoc.isValid()) { |
| 6496 | ExprResult NumForLoopsResult = |
| 6497 | VerifyPositiveIntegerConstantInClause(NumForLoops, OMPC_ordered); |
| 6498 | if (NumForLoopsResult.isInvalid()) |
| 6499 | return nullptr; |
| 6500 | NumForLoops = NumForLoopsResult.get(); |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6501 | } else |
| 6502 | NumForLoops = nullptr; |
| 6503 | DSAStack->setOrderedRegion(/*IsOrdered=*/true, NumForLoops); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 6504 | return new (Context) |
| 6505 | OMPOrderedClause(NumForLoops, StartLoc, LParenLoc, EndLoc); |
| 6506 | } |
| 6507 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6508 | OMPClause *Sema::ActOnOpenMPSimpleClause( |
| 6509 | OpenMPClauseKind Kind, unsigned Argument, SourceLocation ArgumentLoc, |
| 6510 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6511 | OMPClause *Res = nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6512 | switch (Kind) { |
| 6513 | case OMPC_default: |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6514 | Res = |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6515 | ActOnOpenMPDefaultClause(static_cast<OpenMPDefaultClauseKind>(Argument), |
| 6516 | ArgumentLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6517 | break; |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6518 | case OMPC_proc_bind: |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6519 | Res = ActOnOpenMPProcBindClause( |
| 6520 | static_cast<OpenMPProcBindClauseKind>(Argument), ArgumentLoc, StartLoc, |
| 6521 | LParenLoc, EndLoc); |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6522 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6523 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 6524 | case OMPC_final: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6525 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6526 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 6527 | case OMPC_simdlen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6528 | case OMPC_collapse: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6529 | case OMPC_schedule: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6530 | case OMPC_private: |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6531 | case OMPC_firstprivate: |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6532 | case OMPC_lastprivate: |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6533 | case OMPC_shared: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6534 | case OMPC_reduction: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6535 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 6536 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6537 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6538 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6539 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6540 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 6541 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 6542 | case OMPC_mergeable: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6543 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 6544 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6545 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6546 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6547 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6548 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 6549 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6550 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 6551 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6552 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6553 | case OMPC_simd: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 6554 | case OMPC_map: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 6555 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6556 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6557 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 6558 | case OMPC_grainsize: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 6559 | case OMPC_nogroup: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6560 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 6561 | case OMPC_hint: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 6562 | case OMPC_dist_schedule: |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 6563 | case OMPC_defaultmap: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6564 | case OMPC_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6565 | llvm_unreachable("Clause is not allowed."); |
| 6566 | } |
| 6567 | return Res; |
| 6568 | } |
| 6569 | |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6570 | static std::string |
| 6571 | getListOfPossibleValues(OpenMPClauseKind K, unsigned First, unsigned Last, |
| 6572 | ArrayRef<unsigned> Exclude = llvm::None) { |
| 6573 | std::string Values; |
| 6574 | unsigned Bound = Last >= 2 ? Last - 2 : 0; |
| 6575 | unsigned Skipped = Exclude.size(); |
| 6576 | auto S = Exclude.begin(), E = Exclude.end(); |
| 6577 | for (unsigned i = First; i < Last; ++i) { |
| 6578 | if (std::find(S, E, i) != E) { |
| 6579 | --Skipped; |
| 6580 | continue; |
| 6581 | } |
| 6582 | Values += "'"; |
| 6583 | Values += getOpenMPSimpleClauseTypeName(K, i); |
| 6584 | Values += "'"; |
| 6585 | if (i == Bound - Skipped) |
| 6586 | Values += " or "; |
| 6587 | else if (i != Bound + 1 - Skipped) |
| 6588 | Values += ", "; |
| 6589 | } |
| 6590 | return Values; |
| 6591 | } |
| 6592 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6593 | OMPClause *Sema::ActOnOpenMPDefaultClause(OpenMPDefaultClauseKind Kind, |
| 6594 | SourceLocation KindKwLoc, |
| 6595 | SourceLocation StartLoc, |
| 6596 | SourceLocation LParenLoc, |
| 6597 | SourceLocation EndLoc) { |
| 6598 | if (Kind == OMPC_DEFAULT_unknown) { |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 6599 | static_assert(OMPC_DEFAULT_unknown > 0, |
| 6600 | "OMPC_DEFAULT_unknown not greater than 0"); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6601 | Diag(KindKwLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6602 | << getListOfPossibleValues(OMPC_default, /*First=*/0, |
| 6603 | /*Last=*/OMPC_DEFAULT_unknown) |
| 6604 | << getOpenMPClauseName(OMPC_default); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6605 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6606 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6607 | switch (Kind) { |
| 6608 | case OMPC_DEFAULT_none: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6609 | DSAStack->setDefaultDSANone(KindKwLoc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6610 | break; |
| 6611 | case OMPC_DEFAULT_shared: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6612 | DSAStack->setDefaultDSAShared(KindKwLoc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6613 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6614 | case OMPC_DEFAULT_unknown: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6615 | llvm_unreachable("Clause kind is not allowed."); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6616 | break; |
| 6617 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6618 | return new (Context) |
| 6619 | OMPDefaultClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6620 | } |
| 6621 | |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6622 | OMPClause *Sema::ActOnOpenMPProcBindClause(OpenMPProcBindClauseKind Kind, |
| 6623 | SourceLocation KindKwLoc, |
| 6624 | SourceLocation StartLoc, |
| 6625 | SourceLocation LParenLoc, |
| 6626 | SourceLocation EndLoc) { |
| 6627 | if (Kind == OMPC_PROC_BIND_unknown) { |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6628 | Diag(KindKwLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6629 | << getListOfPossibleValues(OMPC_proc_bind, /*First=*/0, |
| 6630 | /*Last=*/OMPC_PROC_BIND_unknown) |
| 6631 | << getOpenMPClauseName(OMPC_proc_bind); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6632 | return nullptr; |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6633 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6634 | return new (Context) |
| 6635 | OMPProcBindClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6636 | } |
| 6637 | |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6638 | OMPClause *Sema::ActOnOpenMPSingleExprWithArgClause( |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6639 | OpenMPClauseKind Kind, ArrayRef<unsigned> Argument, Expr *Expr, |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6640 | SourceLocation StartLoc, SourceLocation LParenLoc, |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6641 | ArrayRef<SourceLocation> ArgumentLoc, SourceLocation DelimLoc, |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6642 | SourceLocation EndLoc) { |
| 6643 | OMPClause *Res = nullptr; |
| 6644 | switch (Kind) { |
| 6645 | case OMPC_schedule: |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6646 | enum { Modifier1, Modifier2, ScheduleKind, NumberOfElements }; |
| 6647 | assert(Argument.size() == NumberOfElements && |
| 6648 | ArgumentLoc.size() == NumberOfElements); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6649 | Res = ActOnOpenMPScheduleClause( |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6650 | static_cast<OpenMPScheduleClauseModifier>(Argument[Modifier1]), |
| 6651 | static_cast<OpenMPScheduleClauseModifier>(Argument[Modifier2]), |
| 6652 | static_cast<OpenMPScheduleClauseKind>(Argument[ScheduleKind]), Expr, |
| 6653 | StartLoc, LParenLoc, ArgumentLoc[Modifier1], ArgumentLoc[Modifier2], |
| 6654 | ArgumentLoc[ScheduleKind], DelimLoc, EndLoc); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6655 | break; |
| 6656 | case OMPC_if: |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6657 | assert(Argument.size() == 1 && ArgumentLoc.size() == 1); |
| 6658 | Res = ActOnOpenMPIfClause(static_cast<OpenMPDirectiveKind>(Argument.back()), |
| 6659 | Expr, StartLoc, LParenLoc, ArgumentLoc.back(), |
| 6660 | DelimLoc, EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6661 | break; |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 6662 | case OMPC_dist_schedule: |
| 6663 | Res = ActOnOpenMPDistScheduleClause( |
| 6664 | static_cast<OpenMPDistScheduleClauseKind>(Argument.back()), Expr, |
| 6665 | StartLoc, LParenLoc, ArgumentLoc.back(), DelimLoc, EndLoc); |
| 6666 | break; |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 6667 | case OMPC_defaultmap: |
| 6668 | enum { Modifier, DefaultmapKind }; |
| 6669 | Res = ActOnOpenMPDefaultmapClause( |
| 6670 | static_cast<OpenMPDefaultmapClauseModifier>(Argument[Modifier]), |
| 6671 | static_cast<OpenMPDefaultmapClauseKind>(Argument[DefaultmapKind]), |
| 6672 | StartLoc, LParenLoc, ArgumentLoc[Modifier], |
| 6673 | ArgumentLoc[DefaultmapKind], EndLoc); |
| 6674 | break; |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 6675 | case OMPC_final: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6676 | case OMPC_num_threads: |
| 6677 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 6678 | case OMPC_simdlen: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6679 | case OMPC_collapse: |
| 6680 | case OMPC_default: |
| 6681 | case OMPC_proc_bind: |
| 6682 | case OMPC_private: |
| 6683 | case OMPC_firstprivate: |
| 6684 | case OMPC_lastprivate: |
| 6685 | case OMPC_shared: |
| 6686 | case OMPC_reduction: |
| 6687 | case OMPC_linear: |
| 6688 | case OMPC_aligned: |
| 6689 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6690 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6691 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6692 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 6693 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 6694 | case OMPC_mergeable: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6695 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 6696 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6697 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6698 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6699 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6700 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 6701 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6702 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 6703 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6704 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6705 | case OMPC_simd: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 6706 | case OMPC_map: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 6707 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6708 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6709 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 6710 | case OMPC_grainsize: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 6711 | case OMPC_nogroup: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6712 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 6713 | case OMPC_hint: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6714 | case OMPC_unknown: |
| 6715 | llvm_unreachable("Clause is not allowed."); |
| 6716 | } |
| 6717 | return Res; |
| 6718 | } |
| 6719 | |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6720 | static bool checkScheduleModifiers(Sema &S, OpenMPScheduleClauseModifier M1, |
| 6721 | OpenMPScheduleClauseModifier M2, |
| 6722 | SourceLocation M1Loc, SourceLocation M2Loc) { |
| 6723 | if (M1 == OMPC_SCHEDULE_MODIFIER_unknown && M1Loc.isValid()) { |
| 6724 | SmallVector<unsigned, 2> Excluded; |
| 6725 | if (M2 != OMPC_SCHEDULE_MODIFIER_unknown) |
| 6726 | Excluded.push_back(M2); |
| 6727 | if (M2 == OMPC_SCHEDULE_MODIFIER_nonmonotonic) |
| 6728 | Excluded.push_back(OMPC_SCHEDULE_MODIFIER_monotonic); |
| 6729 | if (M2 == OMPC_SCHEDULE_MODIFIER_monotonic) |
| 6730 | Excluded.push_back(OMPC_SCHEDULE_MODIFIER_nonmonotonic); |
| 6731 | S.Diag(M1Loc, diag::err_omp_unexpected_clause_value) |
| 6732 | << getListOfPossibleValues(OMPC_schedule, |
| 6733 | /*First=*/OMPC_SCHEDULE_MODIFIER_unknown + 1, |
| 6734 | /*Last=*/OMPC_SCHEDULE_MODIFIER_last, |
| 6735 | Excluded) |
| 6736 | << getOpenMPClauseName(OMPC_schedule); |
| 6737 | return true; |
| 6738 | } |
| 6739 | return false; |
| 6740 | } |
| 6741 | |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6742 | OMPClause *Sema::ActOnOpenMPScheduleClause( |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6743 | OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2, |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6744 | OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6745 | SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc, |
| 6746 | SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) { |
| 6747 | if (checkScheduleModifiers(*this, M1, M2, M1Loc, M2Loc) || |
| 6748 | checkScheduleModifiers(*this, M2, M1, M2Loc, M1Loc)) |
| 6749 | return nullptr; |
| 6750 | // OpenMP, 2.7.1, Loop Construct, Restrictions |
| 6751 | // Either the monotonic modifier or the nonmonotonic modifier can be specified |
| 6752 | // but not both. |
| 6753 | if ((M1 == M2 && M1 != OMPC_SCHEDULE_MODIFIER_unknown) || |
| 6754 | (M1 == OMPC_SCHEDULE_MODIFIER_monotonic && |
| 6755 | M2 == OMPC_SCHEDULE_MODIFIER_nonmonotonic) || |
| 6756 | (M1 == OMPC_SCHEDULE_MODIFIER_nonmonotonic && |
| 6757 | M2 == OMPC_SCHEDULE_MODIFIER_monotonic)) { |
| 6758 | Diag(M2Loc, diag::err_omp_unexpected_schedule_modifier) |
| 6759 | << getOpenMPSimpleClauseTypeName(OMPC_schedule, M2) |
| 6760 | << getOpenMPSimpleClauseTypeName(OMPC_schedule, M1); |
| 6761 | return nullptr; |
| 6762 | } |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6763 | if (Kind == OMPC_SCHEDULE_unknown) { |
| 6764 | std::string Values; |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6765 | if (M1Loc.isInvalid() && M2Loc.isInvalid()) { |
| 6766 | unsigned Exclude[] = {OMPC_SCHEDULE_unknown}; |
| 6767 | Values = getListOfPossibleValues(OMPC_schedule, /*First=*/0, |
| 6768 | /*Last=*/OMPC_SCHEDULE_MODIFIER_last, |
| 6769 | Exclude); |
| 6770 | } else { |
| 6771 | Values = getListOfPossibleValues(OMPC_schedule, /*First=*/0, |
| 6772 | /*Last=*/OMPC_SCHEDULE_unknown); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6773 | } |
| 6774 | Diag(KindLoc, diag::err_omp_unexpected_clause_value) |
| 6775 | << Values << getOpenMPClauseName(OMPC_schedule); |
| 6776 | return nullptr; |
| 6777 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6778 | // OpenMP, 2.7.1, Loop Construct, Restrictions |
| 6779 | // The nonmonotonic modifier can only be specified with schedule(dynamic) or |
| 6780 | // schedule(guided). |
| 6781 | if ((M1 == OMPC_SCHEDULE_MODIFIER_nonmonotonic || |
| 6782 | M2 == OMPC_SCHEDULE_MODIFIER_nonmonotonic) && |
| 6783 | Kind != OMPC_SCHEDULE_dynamic && Kind != OMPC_SCHEDULE_guided) { |
| 6784 | Diag(M1 == OMPC_SCHEDULE_MODIFIER_nonmonotonic ? M1Loc : M2Loc, |
| 6785 | diag::err_omp_schedule_nonmonotonic_static); |
| 6786 | return nullptr; |
| 6787 | } |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6788 | Expr *ValExpr = ChunkSize; |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 6789 | Stmt *HelperValStmt = nullptr; |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6790 | if (ChunkSize) { |
| 6791 | if (!ChunkSize->isValueDependent() && !ChunkSize->isTypeDependent() && |
| 6792 | !ChunkSize->isInstantiationDependent() && |
| 6793 | !ChunkSize->containsUnexpandedParameterPack()) { |
| 6794 | SourceLocation ChunkSizeLoc = ChunkSize->getLocStart(); |
| 6795 | ExprResult Val = |
| 6796 | PerformOpenMPImplicitIntegerConversion(ChunkSizeLoc, ChunkSize); |
| 6797 | if (Val.isInvalid()) |
| 6798 | return nullptr; |
| 6799 | |
| 6800 | ValExpr = Val.get(); |
| 6801 | |
| 6802 | // OpenMP [2.7.1, Restrictions] |
| 6803 | // chunk_size must be a loop invariant integer expression with a positive |
| 6804 | // value. |
| 6805 | llvm::APSInt Result; |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 6806 | if (ValExpr->isIntegerConstantExpr(Result, Context)) { |
| 6807 | if (Result.isSigned() && !Result.isStrictlyPositive()) { |
| 6808 | Diag(ChunkSizeLoc, diag::err_omp_negative_expression_in_clause) |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6809 | << "schedule" << 1 << ChunkSize->getSourceRange(); |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 6810 | return nullptr; |
| 6811 | } |
| 6812 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective())) { |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 6813 | llvm::MapVector<Expr *, DeclRefExpr *> Captures; |
| 6814 | ValExpr = tryBuildCapture(*this, ValExpr, Captures).get(); |
| 6815 | HelperValStmt = buildPreInits(Context, Captures); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6816 | } |
| 6817 | } |
| 6818 | } |
| 6819 | |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6820 | return new (Context) |
| 6821 | OMPScheduleClause(StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc, Kind, |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 6822 | ValExpr, HelperValStmt, M1, M1Loc, M2, M2Loc); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6823 | } |
| 6824 | |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6825 | OMPClause *Sema::ActOnOpenMPClause(OpenMPClauseKind Kind, |
| 6826 | SourceLocation StartLoc, |
| 6827 | SourceLocation EndLoc) { |
| 6828 | OMPClause *Res = nullptr; |
| 6829 | switch (Kind) { |
| 6830 | case OMPC_ordered: |
| 6831 | Res = ActOnOpenMPOrderedClause(StartLoc, EndLoc); |
| 6832 | break; |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6833 | case OMPC_nowait: |
| 6834 | Res = ActOnOpenMPNowaitClause(StartLoc, EndLoc); |
| 6835 | break; |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 6836 | case OMPC_untied: |
| 6837 | Res = ActOnOpenMPUntiedClause(StartLoc, EndLoc); |
| 6838 | break; |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 6839 | case OMPC_mergeable: |
| 6840 | Res = ActOnOpenMPMergeableClause(StartLoc, EndLoc); |
| 6841 | break; |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6842 | case OMPC_read: |
| 6843 | Res = ActOnOpenMPReadClause(StartLoc, EndLoc); |
| 6844 | break; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6845 | case OMPC_write: |
| 6846 | Res = ActOnOpenMPWriteClause(StartLoc, EndLoc); |
| 6847 | break; |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6848 | case OMPC_update: |
| 6849 | Res = ActOnOpenMPUpdateClause(StartLoc, EndLoc); |
| 6850 | break; |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6851 | case OMPC_capture: |
| 6852 | Res = ActOnOpenMPCaptureClause(StartLoc, EndLoc); |
| 6853 | break; |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 6854 | case OMPC_seq_cst: |
| 6855 | Res = ActOnOpenMPSeqCstClause(StartLoc, EndLoc); |
| 6856 | break; |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6857 | case OMPC_threads: |
| 6858 | Res = ActOnOpenMPThreadsClause(StartLoc, EndLoc); |
| 6859 | break; |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6860 | case OMPC_simd: |
| 6861 | Res = ActOnOpenMPSIMDClause(StartLoc, EndLoc); |
| 6862 | break; |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 6863 | case OMPC_nogroup: |
| 6864 | Res = ActOnOpenMPNogroupClause(StartLoc, EndLoc); |
| 6865 | break; |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6866 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 6867 | case OMPC_final: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6868 | case OMPC_num_threads: |
| 6869 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 6870 | case OMPC_simdlen: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6871 | case OMPC_collapse: |
| 6872 | case OMPC_schedule: |
| 6873 | case OMPC_private: |
| 6874 | case OMPC_firstprivate: |
| 6875 | case OMPC_lastprivate: |
| 6876 | case OMPC_shared: |
| 6877 | case OMPC_reduction: |
| 6878 | case OMPC_linear: |
| 6879 | case OMPC_aligned: |
| 6880 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6881 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6882 | case OMPC_default: |
| 6883 | case OMPC_proc_bind: |
| 6884 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 6885 | case OMPC_flush: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6886 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 6887 | case OMPC_device: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 6888 | case OMPC_map: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 6889 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6890 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6891 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 6892 | case OMPC_grainsize: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6893 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 6894 | case OMPC_hint: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 6895 | case OMPC_dist_schedule: |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 6896 | case OMPC_defaultmap: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6897 | case OMPC_unknown: |
| 6898 | llvm_unreachable("Clause is not allowed."); |
| 6899 | } |
| 6900 | return Res; |
| 6901 | } |
| 6902 | |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6903 | OMPClause *Sema::ActOnOpenMPNowaitClause(SourceLocation StartLoc, |
| 6904 | SourceLocation EndLoc) { |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 6905 | DSAStack->setNowaitRegion(); |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6906 | return new (Context) OMPNowaitClause(StartLoc, EndLoc); |
| 6907 | } |
| 6908 | |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 6909 | OMPClause *Sema::ActOnOpenMPUntiedClause(SourceLocation StartLoc, |
| 6910 | SourceLocation EndLoc) { |
| 6911 | return new (Context) OMPUntiedClause(StartLoc, EndLoc); |
| 6912 | } |
| 6913 | |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 6914 | OMPClause *Sema::ActOnOpenMPMergeableClause(SourceLocation StartLoc, |
| 6915 | SourceLocation EndLoc) { |
| 6916 | return new (Context) OMPMergeableClause(StartLoc, EndLoc); |
| 6917 | } |
| 6918 | |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6919 | OMPClause *Sema::ActOnOpenMPReadClause(SourceLocation StartLoc, |
| 6920 | SourceLocation EndLoc) { |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6921 | return new (Context) OMPReadClause(StartLoc, EndLoc); |
| 6922 | } |
| 6923 | |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6924 | OMPClause *Sema::ActOnOpenMPWriteClause(SourceLocation StartLoc, |
| 6925 | SourceLocation EndLoc) { |
| 6926 | return new (Context) OMPWriteClause(StartLoc, EndLoc); |
| 6927 | } |
| 6928 | |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6929 | OMPClause *Sema::ActOnOpenMPUpdateClause(SourceLocation StartLoc, |
| 6930 | SourceLocation EndLoc) { |
| 6931 | return new (Context) OMPUpdateClause(StartLoc, EndLoc); |
| 6932 | } |
| 6933 | |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6934 | OMPClause *Sema::ActOnOpenMPCaptureClause(SourceLocation StartLoc, |
| 6935 | SourceLocation EndLoc) { |
| 6936 | return new (Context) OMPCaptureClause(StartLoc, EndLoc); |
| 6937 | } |
| 6938 | |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 6939 | OMPClause *Sema::ActOnOpenMPSeqCstClause(SourceLocation StartLoc, |
| 6940 | SourceLocation EndLoc) { |
| 6941 | return new (Context) OMPSeqCstClause(StartLoc, EndLoc); |
| 6942 | } |
| 6943 | |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6944 | OMPClause *Sema::ActOnOpenMPThreadsClause(SourceLocation StartLoc, |
| 6945 | SourceLocation EndLoc) { |
| 6946 | return new (Context) OMPThreadsClause(StartLoc, EndLoc); |
| 6947 | } |
| 6948 | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6949 | OMPClause *Sema::ActOnOpenMPSIMDClause(SourceLocation StartLoc, |
| 6950 | SourceLocation EndLoc) { |
| 6951 | return new (Context) OMPSIMDClause(StartLoc, EndLoc); |
| 6952 | } |
| 6953 | |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 6954 | OMPClause *Sema::ActOnOpenMPNogroupClause(SourceLocation StartLoc, |
| 6955 | SourceLocation EndLoc) { |
| 6956 | return new (Context) OMPNogroupClause(StartLoc, EndLoc); |
| 6957 | } |
| 6958 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6959 | OMPClause *Sema::ActOnOpenMPVarListClause( |
| 6960 | OpenMPClauseKind Kind, ArrayRef<Expr *> VarList, Expr *TailExpr, |
| 6961 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, |
| 6962 | SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6963 | const DeclarationNameInfo &ReductionId, OpenMPDependClauseKind DepKind, |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 6964 | OpenMPLinearClauseKind LinKind, OpenMPMapClauseKind MapTypeModifier, |
| 6965 | OpenMPMapClauseKind MapType, bool IsMapTypeImplicit, |
| 6966 | SourceLocation DepLinMapLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6967 | OMPClause *Res = nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6968 | switch (Kind) { |
| 6969 | case OMPC_private: |
| 6970 | Res = ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 6971 | break; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6972 | case OMPC_firstprivate: |
| 6973 | Res = ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 6974 | break; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6975 | case OMPC_lastprivate: |
| 6976 | Res = ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 6977 | break; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6978 | case OMPC_shared: |
| 6979 | Res = ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 6980 | break; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6981 | case OMPC_reduction: |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 6982 | Res = ActOnOpenMPReductionClause(VarList, StartLoc, LParenLoc, ColonLoc, |
| 6983 | EndLoc, ReductionIdScopeSpec, ReductionId); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6984 | break; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6985 | case OMPC_linear: |
| 6986 | Res = ActOnOpenMPLinearClause(VarList, TailExpr, StartLoc, LParenLoc, |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 6987 | LinKind, DepLinMapLoc, ColonLoc, EndLoc); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6988 | break; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 6989 | case OMPC_aligned: |
| 6990 | Res = ActOnOpenMPAlignedClause(VarList, TailExpr, StartLoc, LParenLoc, |
| 6991 | ColonLoc, EndLoc); |
| 6992 | break; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6993 | case OMPC_copyin: |
| 6994 | Res = ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 6995 | break; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6996 | case OMPC_copyprivate: |
| 6997 | Res = ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 6998 | break; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 6999 | case OMPC_flush: |
| 7000 | Res = ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7001 | break; |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 7002 | case OMPC_depend: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 7003 | Res = ActOnOpenMPDependClause(DepKind, DepLinMapLoc, ColonLoc, VarList, |
| 7004 | StartLoc, LParenLoc, EndLoc); |
| 7005 | break; |
| 7006 | case OMPC_map: |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 7007 | Res = ActOnOpenMPMapClause(MapTypeModifier, MapType, IsMapTypeImplicit, |
| 7008 | DepLinMapLoc, ColonLoc, VarList, StartLoc, |
| 7009 | LParenLoc, EndLoc); |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 7010 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7011 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 7012 | case OMPC_final: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7013 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 7014 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 7015 | case OMPC_simdlen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 7016 | case OMPC_collapse: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7017 | case OMPC_default: |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 7018 | case OMPC_proc_bind: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7019 | case OMPC_schedule: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7020 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 7021 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 7022 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 7023 | case OMPC_mergeable: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7024 | case OMPC_threadprivate: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 7025 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 7026 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 7027 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 7028 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 7029 | case OMPC_seq_cst: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 7030 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 7031 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 7032 | case OMPC_simd: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 7033 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7034 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 7035 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 7036 | case OMPC_grainsize: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 7037 | case OMPC_nogroup: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 7038 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 7039 | case OMPC_hint: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 7040 | case OMPC_dist_schedule: |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 7041 | case OMPC_defaultmap: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7042 | case OMPC_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7043 | llvm_unreachable("Clause is not allowed."); |
| 7044 | } |
| 7045 | return Res; |
| 7046 | } |
| 7047 | |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 7048 | ExprResult Sema::getOpenMPCapturedExpr(VarDecl *Capture, ExprValueKind VK, |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 7049 | ExprObjectKind OK, SourceLocation Loc) { |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 7050 | ExprResult Res = BuildDeclRefExpr( |
| 7051 | Capture, Capture->getType().getNonReferenceType(), VK_LValue, Loc); |
| 7052 | if (!Res.isUsable()) |
| 7053 | return ExprError(); |
| 7054 | if (OK == OK_Ordinary && !getLangOpts().CPlusPlus) { |
| 7055 | Res = CreateBuiltinUnaryOp(Loc, UO_Deref, Res.get()); |
| 7056 | if (!Res.isUsable()) |
| 7057 | return ExprError(); |
| 7058 | } |
| 7059 | if (VK != VK_LValue && Res.get()->isGLValue()) { |
| 7060 | Res = DefaultLvalueConversion(Res.get()); |
| 7061 | if (!Res.isUsable()) |
| 7062 | return ExprError(); |
| 7063 | } |
| 7064 | return Res; |
| 7065 | } |
| 7066 | |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7067 | static std::pair<ValueDecl *, bool> |
| 7068 | getPrivateItem(Sema &S, Expr *&RefExpr, SourceLocation &ELoc, |
| 7069 | SourceRange &ERange, bool AllowArraySection = false) { |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7070 | if (RefExpr->isTypeDependent() || RefExpr->isValueDependent() || |
| 7071 | RefExpr->containsUnexpandedParameterPack()) |
| 7072 | return std::make_pair(nullptr, true); |
| 7073 | |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7074 | // OpenMP [3.1, C/C++] |
| 7075 | // A list item is a variable name. |
| 7076 | // OpenMP [2.9.3.3, Restrictions, p.1] |
| 7077 | // A variable that is part of another variable (as an array or |
| 7078 | // structure element) cannot appear in a private clause. |
| 7079 | RefExpr = RefExpr->IgnoreParens(); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7080 | enum { |
| 7081 | NoArrayExpr = -1, |
| 7082 | ArraySubscript = 0, |
| 7083 | OMPArraySection = 1 |
| 7084 | } IsArrayExpr = NoArrayExpr; |
| 7085 | if (AllowArraySection) { |
| 7086 | if (auto *ASE = dyn_cast_or_null<ArraySubscriptExpr>(RefExpr)) { |
| 7087 | auto *Base = ASE->getBase()->IgnoreParenImpCasts(); |
| 7088 | while (auto *TempASE = dyn_cast<ArraySubscriptExpr>(Base)) |
| 7089 | Base = TempASE->getBase()->IgnoreParenImpCasts(); |
| 7090 | RefExpr = Base; |
| 7091 | IsArrayExpr = ArraySubscript; |
| 7092 | } else if (auto *OASE = dyn_cast_or_null<OMPArraySectionExpr>(RefExpr)) { |
| 7093 | auto *Base = OASE->getBase()->IgnoreParenImpCasts(); |
| 7094 | while (auto *TempOASE = dyn_cast<OMPArraySectionExpr>(Base)) |
| 7095 | Base = TempOASE->getBase()->IgnoreParenImpCasts(); |
| 7096 | while (auto *TempASE = dyn_cast<ArraySubscriptExpr>(Base)) |
| 7097 | Base = TempASE->getBase()->IgnoreParenImpCasts(); |
| 7098 | RefExpr = Base; |
| 7099 | IsArrayExpr = OMPArraySection; |
| 7100 | } |
| 7101 | } |
| 7102 | ELoc = RefExpr->getExprLoc(); |
| 7103 | ERange = RefExpr->getSourceRange(); |
| 7104 | RefExpr = RefExpr->IgnoreParenImpCasts(); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7105 | auto *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr); |
| 7106 | auto *ME = dyn_cast_or_null<MemberExpr>(RefExpr); |
| 7107 | if ((!DE || !isa<VarDecl>(DE->getDecl())) && |
| 7108 | (S.getCurrentThisType().isNull() || !ME || |
| 7109 | !isa<CXXThisExpr>(ME->getBase()->IgnoreParenImpCasts()) || |
| 7110 | !isa<FieldDecl>(ME->getMemberDecl()))) { |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7111 | if (IsArrayExpr != NoArrayExpr) |
| 7112 | S.Diag(ELoc, diag::err_omp_expected_base_var_name) << IsArrayExpr |
| 7113 | << ERange; |
| 7114 | else { |
| 7115 | S.Diag(ELoc, |
| 7116 | AllowArraySection |
| 7117 | ? diag::err_omp_expected_var_name_member_expr_or_array_item |
| 7118 | : diag::err_omp_expected_var_name_member_expr) |
| 7119 | << (S.getCurrentThisType().isNull() ? 0 : 1) << ERange; |
| 7120 | } |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7121 | return std::make_pair(nullptr, false); |
| 7122 | } |
| 7123 | return std::make_pair(DE ? DE->getDecl() : ME->getMemberDecl(), false); |
| 7124 | } |
| 7125 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7126 | OMPClause *Sema::ActOnOpenMPPrivateClause(ArrayRef<Expr *> VarList, |
| 7127 | SourceLocation StartLoc, |
| 7128 | SourceLocation LParenLoc, |
| 7129 | SourceLocation EndLoc) { |
| 7130 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 7131 | SmallVector<Expr *, 8> PrivateCopies; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7132 | for (auto &RefExpr : VarList) { |
| 7133 | assert(RefExpr && "NULL expr in OpenMP private clause."); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7134 | SourceLocation ELoc; |
| 7135 | SourceRange ERange; |
| 7136 | Expr *SimpleRefExpr = RefExpr; |
| 7137 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7138 | if (Res.second) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7139 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7140 | Vars.push_back(RefExpr); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 7141 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7142 | } |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7143 | ValueDecl *D = Res.first; |
| 7144 | if (!D) |
| 7145 | continue; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7146 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7147 | QualType Type = D->getType(); |
| 7148 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7149 | |
| 7150 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 7151 | // A variable that appears in a private clause must not have an incomplete |
| 7152 | // type or a reference type. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7153 | if (RequireCompleteType(ELoc, Type, diag::err_omp_private_incomplete_type)) |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7154 | continue; |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7155 | Type = Type.getNonReferenceType(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7156 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7157 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 7158 | // in a Construct] |
| 7159 | // Variables with the predetermined data-sharing attributes may not be |
| 7160 | // listed in data-sharing attributes clauses, except for the cases |
| 7161 | // listed below. For these exceptions only, listing a predetermined |
| 7162 | // variable in a data-sharing attribute clause is allowed and overrides |
| 7163 | // the variable's predetermined data-sharing attributes. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7164 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7165 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_private) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7166 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 7167 | << getOpenMPClauseName(OMPC_private); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7168 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7169 | continue; |
| 7170 | } |
| 7171 | |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7172 | // Variably modified types are not supported for tasks. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 7173 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType() && |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7174 | DSAStack->getCurrentDirective() == OMPD_task) { |
| 7175 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
| 7176 | << getOpenMPClauseName(OMPC_private) << Type |
| 7177 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 7178 | bool IsDecl = |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7179 | !VD || |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7180 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7181 | Diag(D->getLocation(), |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7182 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7183 | << D; |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7184 | continue; |
| 7185 | } |
| 7186 | |
Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 7187 | // OpenMP 4.5 [2.15.5.1, Restrictions, p.3] |
| 7188 | // A list item cannot appear in both a map clause and a data-sharing |
| 7189 | // attribute clause on the same construct |
| 7190 | if (DSAStack->getCurrentDirective() == OMPD_target) { |
| 7191 | if(DSAStack->checkMapInfoForVar(VD, /* CurrentRegionOnly = */ true, |
| 7192 | [&](Expr *RE) -> bool {return true;})) { |
| 7193 | Diag(ELoc, diag::err_omp_variable_in_map_and_dsa) |
| 7194 | << getOpenMPClauseName(OMPC_private) |
| 7195 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 7196 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
| 7197 | continue; |
| 7198 | } |
| 7199 | } |
| 7200 | |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7201 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.1] |
| 7202 | // A variable of class type (or array thereof) that appears in a private |
| 7203 | // clause requires an accessible, unambiguous default constructor for the |
| 7204 | // class type. |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 7205 | // Generate helper private variable and initialize it with the default |
| 7206 | // value. The address of the original variable is replaced by the address of |
| 7207 | // the new private variable in CodeGen. This new variable is not added to |
| 7208 | // IdResolver, so the code in the OpenMP region uses original variable for |
| 7209 | // proper diagnostics. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7210 | Type = Type.getUnqualifiedType(); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7211 | auto VDPrivate = buildVarDecl(*this, ELoc, Type, D->getName(), |
| 7212 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7213 | ActOnUninitializedDecl(VDPrivate, /*TypeMayContainAuto=*/false); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 7214 | if (VDPrivate->isInvalidDecl()) |
| 7215 | continue; |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7216 | auto VDPrivateRefExpr = buildDeclRefExpr( |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7217 | *this, VDPrivate, RefExpr->getType().getUnqualifiedType(), ELoc); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 7218 | |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 7219 | DeclRefExpr *Ref = nullptr; |
| 7220 | if (!VD) |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 7221 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false); |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 7222 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_private, Ref); |
| 7223 | Vars.push_back(VD ? RefExpr->IgnoreParens() : Ref); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 7224 | PrivateCopies.push_back(VDPrivateRefExpr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7225 | } |
| 7226 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7227 | if (Vars.empty()) |
| 7228 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7229 | |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 7230 | return OMPPrivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
| 7231 | PrivateCopies); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7232 | } |
| 7233 | |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7234 | namespace { |
| 7235 | class DiagsUninitializedSeveretyRAII { |
| 7236 | private: |
| 7237 | DiagnosticsEngine &Diags; |
| 7238 | SourceLocation SavedLoc; |
| 7239 | bool IsIgnored; |
| 7240 | |
| 7241 | public: |
| 7242 | DiagsUninitializedSeveretyRAII(DiagnosticsEngine &Diags, SourceLocation Loc, |
| 7243 | bool IsIgnored) |
| 7244 | : Diags(Diags), SavedLoc(Loc), IsIgnored(IsIgnored) { |
| 7245 | if (!IsIgnored) { |
| 7246 | Diags.setSeverity(/*Diag*/ diag::warn_uninit_self_reference_in_init, |
| 7247 | /*Map*/ diag::Severity::Ignored, Loc); |
| 7248 | } |
| 7249 | } |
| 7250 | ~DiagsUninitializedSeveretyRAII() { |
| 7251 | if (!IsIgnored) |
| 7252 | Diags.popMappings(SavedLoc); |
| 7253 | } |
| 7254 | }; |
Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 7255 | } |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7256 | |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7257 | OMPClause *Sema::ActOnOpenMPFirstprivateClause(ArrayRef<Expr *> VarList, |
| 7258 | SourceLocation StartLoc, |
| 7259 | SourceLocation LParenLoc, |
| 7260 | SourceLocation EndLoc) { |
| 7261 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7262 | SmallVector<Expr *, 8> PrivateCopies; |
| 7263 | SmallVector<Expr *, 8> Inits; |
Alexey Bataev | 417089f | 2016-02-17 13:19:37 +0000 | [diff] [blame] | 7264 | SmallVector<Decl *, 4> ExprCaptures; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7265 | bool IsImplicitClause = |
| 7266 | StartLoc.isInvalid() && LParenLoc.isInvalid() && EndLoc.isInvalid(); |
| 7267 | auto ImplicitClauseLoc = DSAStack->getConstructLoc(); |
| 7268 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7269 | for (auto &RefExpr : VarList) { |
| 7270 | assert(RefExpr && "NULL expr in OpenMP firstprivate clause."); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7271 | SourceLocation ELoc; |
| 7272 | SourceRange ERange; |
| 7273 | Expr *SimpleRefExpr = RefExpr; |
| 7274 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7275 | if (Res.second) { |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7276 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7277 | Vars.push_back(RefExpr); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7278 | PrivateCopies.push_back(nullptr); |
| 7279 | Inits.push_back(nullptr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7280 | } |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7281 | ValueDecl *D = Res.first; |
| 7282 | if (!D) |
| 7283 | continue; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7284 | |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7285 | ELoc = IsImplicitClause ? ImplicitClauseLoc : ELoc; |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7286 | QualType Type = D->getType(); |
| 7287 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7288 | |
| 7289 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 7290 | // A variable that appears in a private clause must not have an incomplete |
| 7291 | // type or a reference type. |
| 7292 | if (RequireCompleteType(ELoc, Type, |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7293 | diag::err_omp_firstprivate_incomplete_type)) |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7294 | continue; |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7295 | Type = Type.getNonReferenceType(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7296 | |
| 7297 | // OpenMP [2.9.3.4, Restrictions, C/C++, p.1] |
| 7298 | // 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] | 7299 | // clause requires an accessible, unambiguous copy constructor for the |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7300 | // class type. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7301 | auto ElemType = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7302 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7303 | // If an implicit firstprivate variable found it was checked already. |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 7304 | DSAStackTy::DSAVarData TopDVar; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7305 | if (!IsImplicitClause) { |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7306 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 7307 | TopDVar = DVar; |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7308 | bool IsConstant = ElemType.isConstant(Context); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7309 | // OpenMP [2.4.13, Data-sharing Attribute Clauses] |
| 7310 | // A list item that specifies a given variable may not appear in more |
| 7311 | // than one clause on the same directive, except that a variable may be |
| 7312 | // specified in both firstprivate and lastprivate clauses. |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7313 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_firstprivate && |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7314 | DVar.CKind != OMPC_lastprivate && DVar.RefExpr) { |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7315 | Diag(ELoc, diag::err_omp_wrong_dsa) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7316 | << getOpenMPClauseName(DVar.CKind) |
| 7317 | << getOpenMPClauseName(OMPC_firstprivate); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7318 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7319 | continue; |
| 7320 | } |
| 7321 | |
| 7322 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 7323 | // in a Construct] |
| 7324 | // Variables with the predetermined data-sharing attributes may not be |
| 7325 | // listed in data-sharing attributes clauses, except for the cases |
| 7326 | // listed below. For these exceptions only, listing a predetermined |
| 7327 | // variable in a data-sharing attribute clause is allowed and overrides |
| 7328 | // the variable's predetermined data-sharing attributes. |
| 7329 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 7330 | // in a Construct, C/C++, p.2] |
| 7331 | // Variables with const-qualified type having no mutable member may be |
| 7332 | // listed in a firstprivate clause, even if they are static data members. |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7333 | if (!(IsConstant || (VD && VD->isStaticDataMember())) && !DVar.RefExpr && |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7334 | DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared) { |
| 7335 | Diag(ELoc, diag::err_omp_wrong_dsa) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7336 | << getOpenMPClauseName(DVar.CKind) |
| 7337 | << getOpenMPClauseName(OMPC_firstprivate); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7338 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7339 | continue; |
| 7340 | } |
| 7341 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7342 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7343 | // OpenMP [2.9.3.4, Restrictions, p.2] |
| 7344 | // A list item that is private within a parallel region must not appear |
| 7345 | // in a firstprivate clause on a worksharing construct if any of the |
| 7346 | // worksharing regions arising from the worksharing construct ever bind |
| 7347 | // to any of the parallel regions arising from the parallel construct. |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 7348 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 7349 | !isOpenMPParallelDirective(CurrDir)) { |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7350 | DVar = DSAStack->getImplicitDSA(D, true); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7351 | if (DVar.CKind != OMPC_shared && |
| 7352 | (isOpenMPParallelDirective(DVar.DKind) || |
| 7353 | DVar.DKind == OMPD_unknown)) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7354 | Diag(ELoc, diag::err_omp_required_access) |
| 7355 | << getOpenMPClauseName(OMPC_firstprivate) |
| 7356 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7357 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7358 | continue; |
| 7359 | } |
| 7360 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7361 | // OpenMP [2.9.3.4, Restrictions, p.3] |
| 7362 | // A list item that appears in a reduction clause of a parallel construct |
| 7363 | // must not appear in a firstprivate clause on a worksharing or task |
| 7364 | // construct if any of the worksharing or task regions arising from the |
| 7365 | // worksharing or task construct ever bind to any of the parallel regions |
| 7366 | // arising from the parallel construct. |
| 7367 | // OpenMP [2.9.3.4, Restrictions, p.4] |
| 7368 | // A list item that appears in a reduction clause in worksharing |
| 7369 | // construct must not appear in a firstprivate clause in a task construct |
| 7370 | // encountered during execution of any of the worksharing regions arising |
| 7371 | // from the worksharing construct. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7372 | if (CurrDir == OMPD_task) { |
| 7373 | DVar = |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7374 | DSAStack->hasInnermostDSA(D, MatchesAnyClause(OMPC_reduction), |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7375 | [](OpenMPDirectiveKind K) -> bool { |
| 7376 | return isOpenMPParallelDirective(K) || |
| 7377 | isOpenMPWorksharingDirective(K); |
| 7378 | }, |
| 7379 | false); |
| 7380 | if (DVar.CKind == OMPC_reduction && |
| 7381 | (isOpenMPParallelDirective(DVar.DKind) || |
| 7382 | isOpenMPWorksharingDirective(DVar.DKind))) { |
| 7383 | Diag(ELoc, diag::err_omp_parallel_reduction_in_task_firstprivate) |
| 7384 | << getOpenMPDirectiveName(DVar.DKind); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7385 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7386 | continue; |
| 7387 | } |
| 7388 | } |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7389 | |
| 7390 | // OpenMP 4.5 [2.15.3.4, Restrictions, p.3] |
| 7391 | // A list item that is private within a teams region must not appear in a |
| 7392 | // firstprivate clause on a distribute construct if any of the distribute |
| 7393 | // regions arising from the distribute construct ever bind to any of the |
| 7394 | // teams regions arising from the teams construct. |
| 7395 | // OpenMP 4.5 [2.15.3.4, Restrictions, p.3] |
| 7396 | // A list item that appears in a reduction clause of a teams construct |
| 7397 | // must not appear in a firstprivate clause on a distribute construct if |
| 7398 | // any of the distribute regions arising from the distribute construct |
| 7399 | // ever bind to any of the teams regions arising from the teams construct. |
| 7400 | // OpenMP 4.5 [2.10.8, Distribute Construct, p.3] |
| 7401 | // A list item may appear in a firstprivate or lastprivate clause but not |
| 7402 | // both. |
| 7403 | if (CurrDir == OMPD_distribute) { |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7404 | DVar = DSAStack->hasInnermostDSA(D, MatchesAnyClause(OMPC_private), |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7405 | [](OpenMPDirectiveKind K) -> bool { |
| 7406 | return isOpenMPTeamsDirective(K); |
| 7407 | }, |
| 7408 | false); |
| 7409 | if (DVar.CKind == OMPC_private && isOpenMPTeamsDirective(DVar.DKind)) { |
| 7410 | Diag(ELoc, diag::err_omp_firstprivate_distribute_private_teams); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7411 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7412 | continue; |
| 7413 | } |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7414 | DVar = DSAStack->hasInnermostDSA(D, MatchesAnyClause(OMPC_reduction), |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7415 | [](OpenMPDirectiveKind K) -> bool { |
| 7416 | return isOpenMPTeamsDirective(K); |
| 7417 | }, |
| 7418 | false); |
| 7419 | if (DVar.CKind == OMPC_reduction && |
| 7420 | isOpenMPTeamsDirective(DVar.DKind)) { |
| 7421 | Diag(ELoc, diag::err_omp_firstprivate_distribute_in_teams_reduction); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7422 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7423 | continue; |
| 7424 | } |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7425 | DVar = DSAStack->getTopDSA(D, false); |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7426 | if (DVar.CKind == OMPC_lastprivate) { |
| 7427 | Diag(ELoc, diag::err_omp_firstprivate_and_lastprivate_in_distribute); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7428 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7429 | continue; |
| 7430 | } |
| 7431 | } |
Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 7432 | // OpenMP 4.5 [2.15.5.1, Restrictions, p.3] |
| 7433 | // A list item cannot appear in both a map clause and a data-sharing |
| 7434 | // attribute clause on the same construct |
| 7435 | if (CurrDir == OMPD_target) { |
| 7436 | if(DSAStack->checkMapInfoForVar(VD, /* CurrentRegionOnly = */ true, |
| 7437 | [&](Expr *RE) -> bool {return true;})) { |
| 7438 | Diag(ELoc, diag::err_omp_variable_in_map_and_dsa) |
| 7439 | << getOpenMPClauseName(OMPC_firstprivate) |
| 7440 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 7441 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
| 7442 | continue; |
| 7443 | } |
| 7444 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7445 | } |
| 7446 | |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7447 | // Variably modified types are not supported for tasks. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 7448 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType() && |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7449 | DSAStack->getCurrentDirective() == OMPD_task) { |
| 7450 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
| 7451 | << getOpenMPClauseName(OMPC_firstprivate) << Type |
| 7452 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 7453 | bool IsDecl = |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7454 | !VD || |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7455 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7456 | Diag(D->getLocation(), |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7457 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7458 | << D; |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7459 | continue; |
| 7460 | } |
| 7461 | |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7462 | Type = Type.getUnqualifiedType(); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7463 | auto VDPrivate = buildVarDecl(*this, ELoc, Type, D->getName(), |
| 7464 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7465 | // Generate helper private variable and initialize it with the value of the |
| 7466 | // original variable. The address of the original variable is replaced by |
| 7467 | // the address of the new private variable in the CodeGen. This new variable |
| 7468 | // is not added to IdResolver, so the code in the OpenMP region uses |
| 7469 | // original variable for proper diagnostics and variable capturing. |
| 7470 | Expr *VDInitRefExpr = nullptr; |
| 7471 | // For arrays generate initializer for single element and replace it by the |
| 7472 | // original array element in CodeGen. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7473 | if (Type->isArrayType()) { |
| 7474 | auto VDInit = |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7475 | buildVarDecl(*this, RefExpr->getExprLoc(), ElemType, D->getName()); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7476 | VDInitRefExpr = buildDeclRefExpr(*this, VDInit, ElemType, ELoc); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7477 | auto Init = DefaultLvalueConversion(VDInitRefExpr).get(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7478 | ElemType = ElemType.getUnqualifiedType(); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7479 | auto *VDInitTemp = buildVarDecl(*this, RefExpr->getExprLoc(), ElemType, |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7480 | ".firstprivate.temp"); |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 7481 | InitializedEntity Entity = |
| 7482 | InitializedEntity::InitializeVariable(VDInitTemp); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7483 | InitializationKind Kind = InitializationKind::CreateCopy(ELoc, ELoc); |
| 7484 | |
| 7485 | InitializationSequence InitSeq(*this, Entity, Kind, Init); |
| 7486 | ExprResult Result = InitSeq.Perform(*this, Entity, Kind, Init); |
| 7487 | if (Result.isInvalid()) |
| 7488 | VDPrivate->setInvalidDecl(); |
| 7489 | else |
| 7490 | VDPrivate->setInit(Result.getAs<Expr>()); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7491 | // Remove temp variable declaration. |
| 7492 | Context.Deallocate(VDInitTemp); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7493 | } else { |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7494 | auto *VDInit = buildVarDecl(*this, RefExpr->getExprLoc(), Type, |
| 7495 | ".firstprivate.temp"); |
| 7496 | VDInitRefExpr = buildDeclRefExpr(*this, VDInit, RefExpr->getType(), |
| 7497 | RefExpr->getExprLoc()); |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 7498 | AddInitializerToDecl(VDPrivate, |
| 7499 | DefaultLvalueConversion(VDInitRefExpr).get(), |
| 7500 | /*DirectInit=*/false, /*TypeMayContainAuto=*/false); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7501 | } |
| 7502 | if (VDPrivate->isInvalidDecl()) { |
| 7503 | if (IsImplicitClause) { |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7504 | Diag(RefExpr->getExprLoc(), |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7505 | diag::note_omp_task_predetermined_firstprivate_here); |
| 7506 | } |
| 7507 | continue; |
| 7508 | } |
| 7509 | CurContext->addDecl(VDPrivate); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7510 | auto VDPrivateRefExpr = buildDeclRefExpr( |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7511 | *this, VDPrivate, RefExpr->getType().getUnqualifiedType(), |
| 7512 | RefExpr->getExprLoc()); |
| 7513 | DeclRefExpr *Ref = nullptr; |
Alexey Bataev | 417089f | 2016-02-17 13:19:37 +0000 | [diff] [blame] | 7514 | if (!VD) { |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 7515 | if (TopDVar.CKind == OMPC_lastprivate) |
| 7516 | Ref = TopDVar.PrivateCopy; |
| 7517 | else { |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 7518 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/true); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 7519 | if (!IsOpenMPCapturedDecl(D)) |
| 7520 | ExprCaptures.push_back(Ref->getDecl()); |
| 7521 | } |
Alexey Bataev | 417089f | 2016-02-17 13:19:37 +0000 | [diff] [blame] | 7522 | } |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7523 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_firstprivate, Ref); |
| 7524 | Vars.push_back(VD ? RefExpr->IgnoreParens() : Ref); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7525 | PrivateCopies.push_back(VDPrivateRefExpr); |
| 7526 | Inits.push_back(VDInitRefExpr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7527 | } |
| 7528 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7529 | if (Vars.empty()) |
| 7530 | return nullptr; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7531 | |
| 7532 | return OMPFirstprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 7533 | Vars, PrivateCopies, Inits, |
| 7534 | buildPreInits(Context, ExprCaptures)); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7535 | } |
| 7536 | |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7537 | OMPClause *Sema::ActOnOpenMPLastprivateClause(ArrayRef<Expr *> VarList, |
| 7538 | SourceLocation StartLoc, |
| 7539 | SourceLocation LParenLoc, |
| 7540 | SourceLocation EndLoc) { |
| 7541 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7542 | SmallVector<Expr *, 8> SrcExprs; |
| 7543 | SmallVector<Expr *, 8> DstExprs; |
| 7544 | SmallVector<Expr *, 8> AssignmentOps; |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 7545 | SmallVector<Decl *, 4> ExprCaptures; |
| 7546 | SmallVector<Expr *, 4> ExprPostUpdates; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7547 | for (auto &RefExpr : VarList) { |
| 7548 | assert(RefExpr && "NULL expr in OpenMP lastprivate clause."); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7549 | SourceLocation ELoc; |
| 7550 | SourceRange ERange; |
| 7551 | Expr *SimpleRefExpr = RefExpr; |
| 7552 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7553 | if (Res.second) { |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7554 | // It will be analyzed later. |
| 7555 | Vars.push_back(RefExpr); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7556 | SrcExprs.push_back(nullptr); |
| 7557 | DstExprs.push_back(nullptr); |
| 7558 | AssignmentOps.push_back(nullptr); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7559 | } |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7560 | ValueDecl *D = Res.first; |
| 7561 | if (!D) |
| 7562 | continue; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7563 | |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7564 | QualType Type = D->getType(); |
| 7565 | auto *VD = dyn_cast<VarDecl>(D); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7566 | |
| 7567 | // OpenMP [2.14.3.5, Restrictions, C/C++, p.2] |
| 7568 | // A variable that appears in a lastprivate clause must not have an |
| 7569 | // incomplete type or a reference type. |
| 7570 | if (RequireCompleteType(ELoc, Type, |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7571 | diag::err_omp_lastprivate_incomplete_type)) |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7572 | continue; |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7573 | Type = Type.getNonReferenceType(); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7574 | |
| 7575 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 7576 | // in a Construct] |
| 7577 | // Variables with the predetermined data-sharing attributes may not be |
| 7578 | // listed in data-sharing attributes clauses, except for the cases |
| 7579 | // listed below. |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7580 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7581 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_lastprivate && |
| 7582 | DVar.CKind != OMPC_firstprivate && |
| 7583 | (DVar.CKind != OMPC_private || DVar.RefExpr != nullptr)) { |
| 7584 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 7585 | << getOpenMPClauseName(DVar.CKind) |
| 7586 | << getOpenMPClauseName(OMPC_lastprivate); |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7587 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7588 | continue; |
| 7589 | } |
| 7590 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7591 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
| 7592 | // OpenMP [2.14.3.5, Restrictions, p.2] |
| 7593 | // A list item that is private within a parallel region, or that appears in |
| 7594 | // the reduction clause of a parallel construct, must not appear in a |
| 7595 | // lastprivate clause on a worksharing construct if any of the corresponding |
| 7596 | // worksharing regions ever binds to any of the corresponding parallel |
| 7597 | // regions. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7598 | DSAStackTy::DSAVarData TopDVar = DVar; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 7599 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 7600 | !isOpenMPParallelDirective(CurrDir)) { |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7601 | DVar = DSAStack->getImplicitDSA(D, true); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7602 | if (DVar.CKind != OMPC_shared) { |
| 7603 | Diag(ELoc, diag::err_omp_required_access) |
| 7604 | << getOpenMPClauseName(OMPC_lastprivate) |
| 7605 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7606 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7607 | continue; |
| 7608 | } |
| 7609 | } |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7610 | |
| 7611 | // OpenMP 4.5 [2.10.8, Distribute Construct, p.3] |
| 7612 | // A list item may appear in a firstprivate or lastprivate clause but not |
| 7613 | // both. |
| 7614 | if (CurrDir == OMPD_distribute) { |
| 7615 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
| 7616 | if (DVar.CKind == OMPC_firstprivate) { |
| 7617 | Diag(ELoc, diag::err_omp_firstprivate_and_lastprivate_in_distribute); |
| 7618 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
| 7619 | continue; |
| 7620 | } |
| 7621 | } |
| 7622 | |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7623 | // OpenMP [2.14.3.5, Restrictions, C++, p.1,2] |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7624 | // A variable of class type (or array thereof) that appears in a |
| 7625 | // lastprivate clause requires an accessible, unambiguous default |
| 7626 | // constructor for the class type, unless the list item is also specified |
| 7627 | // in a firstprivate clause. |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7628 | // A variable of class type (or array thereof) that appears in a |
| 7629 | // lastprivate clause requires an accessible, unambiguous copy assignment |
| 7630 | // operator for the class type. |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7631 | Type = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7632 | auto *SrcVD = buildVarDecl(*this, ERange.getBegin(), |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 7633 | Type.getUnqualifiedType(), ".lastprivate.src", |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7634 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 7635 | auto *PseudoSrcExpr = |
| 7636 | buildDeclRefExpr(*this, SrcVD, Type.getUnqualifiedType(), ELoc); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7637 | auto *DstVD = |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7638 | buildVarDecl(*this, ERange.getBegin(), Type, ".lastprivate.dst", |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7639 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 7640 | auto *PseudoDstExpr = buildDeclRefExpr(*this, DstVD, Type, ELoc); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7641 | // For arrays generate assignment operation for single element and replace |
| 7642 | // it by the original array element in CodeGen. |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7643 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, ELoc, BO_Assign, |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7644 | PseudoDstExpr, PseudoSrcExpr); |
| 7645 | if (AssignmentOp.isInvalid()) |
| 7646 | continue; |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7647 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), ELoc, |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7648 | /*DiscardedValue=*/true); |
| 7649 | if (AssignmentOp.isInvalid()) |
| 7650 | continue; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7651 | |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7652 | DeclRefExpr *Ref = nullptr; |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 7653 | if (!VD) { |
| 7654 | if (TopDVar.CKind == OMPC_firstprivate) |
| 7655 | Ref = TopDVar.PrivateCopy; |
| 7656 | else { |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 7657 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 7658 | if (!IsOpenMPCapturedDecl(D)) |
| 7659 | ExprCaptures.push_back(Ref->getDecl()); |
| 7660 | } |
| 7661 | if (TopDVar.CKind == OMPC_firstprivate || |
| 7662 | (!IsOpenMPCapturedDecl(D) && |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 7663 | Ref->getDecl()->hasAttr<OMPCaptureNoInitAttr>())) { |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 7664 | ExprResult RefRes = DefaultLvalueConversion(Ref); |
| 7665 | if (!RefRes.isUsable()) |
| 7666 | continue; |
| 7667 | ExprResult PostUpdateRes = |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7668 | BuildBinOp(DSAStack->getCurScope(), ELoc, BO_Assign, SimpleRefExpr, |
| 7669 | RefRes.get()); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 7670 | if (!PostUpdateRes.isUsable()) |
| 7671 | continue; |
Alexey Bataev | 78849fb | 2016-03-09 09:49:00 +0000 | [diff] [blame] | 7672 | ExprPostUpdates.push_back( |
| 7673 | IgnoredValueConversions(PostUpdateRes.get()).get()); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 7674 | } |
| 7675 | } |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7676 | if (TopDVar.CKind != OMPC_firstprivate) |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7677 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_lastprivate, Ref); |
| 7678 | Vars.push_back(VD ? RefExpr->IgnoreParens() : Ref); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7679 | SrcExprs.push_back(PseudoSrcExpr); |
| 7680 | DstExprs.push_back(PseudoDstExpr); |
| 7681 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7682 | } |
| 7683 | |
| 7684 | if (Vars.empty()) |
| 7685 | return nullptr; |
| 7686 | |
| 7687 | return OMPLastprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 7688 | Vars, SrcExprs, DstExprs, AssignmentOps, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 7689 | buildPreInits(Context, ExprCaptures), |
| 7690 | buildPostUpdate(*this, ExprPostUpdates)); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7691 | } |
| 7692 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7693 | OMPClause *Sema::ActOnOpenMPSharedClause(ArrayRef<Expr *> VarList, |
| 7694 | SourceLocation StartLoc, |
| 7695 | SourceLocation LParenLoc, |
| 7696 | SourceLocation EndLoc) { |
| 7697 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7698 | for (auto &RefExpr : VarList) { |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 7699 | assert(RefExpr && "NULL expr in OpenMP lastprivate clause."); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7700 | SourceLocation ELoc; |
| 7701 | SourceRange ERange; |
| 7702 | Expr *SimpleRefExpr = RefExpr; |
| 7703 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 7704 | if (Res.second) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7705 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7706 | Vars.push_back(RefExpr); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7707 | } |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 7708 | ValueDecl *D = Res.first; |
| 7709 | if (!D) |
| 7710 | continue; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7711 | |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 7712 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7713 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 7714 | // in a Construct] |
| 7715 | // Variables with the predetermined data-sharing attributes may not be |
| 7716 | // listed in data-sharing attributes clauses, except for the cases |
| 7717 | // listed below. For these exceptions only, listing a predetermined |
| 7718 | // variable in a data-sharing attribute clause is allowed and overrides |
| 7719 | // the variable's predetermined data-sharing attributes. |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 7720 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7721 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared && |
| 7722 | DVar.RefExpr) { |
| 7723 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 7724 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 7725 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7726 | continue; |
| 7727 | } |
| 7728 | |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 7729 | DeclRefExpr *Ref = nullptr; |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 7730 | if (!VD && IsOpenMPCapturedDecl(D)) |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 7731 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/true); |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 7732 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_shared, Ref); |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 7733 | Vars.push_back((VD || !Ref) ? RefExpr->IgnoreParens() : Ref); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7734 | } |
| 7735 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7736 | if (Vars.empty()) |
| 7737 | return nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7738 | |
| 7739 | return OMPSharedClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars); |
| 7740 | } |
| 7741 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7742 | namespace { |
| 7743 | class DSARefChecker : public StmtVisitor<DSARefChecker, bool> { |
| 7744 | DSAStackTy *Stack; |
| 7745 | |
| 7746 | public: |
| 7747 | bool VisitDeclRefExpr(DeclRefExpr *E) { |
| 7748 | if (VarDecl *VD = dyn_cast<VarDecl>(E->getDecl())) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7749 | DSAStackTy::DSAVarData DVar = Stack->getTopDSA(VD, false); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7750 | if (DVar.CKind == OMPC_shared && !DVar.RefExpr) |
| 7751 | return false; |
| 7752 | if (DVar.CKind != OMPC_unknown) |
| 7753 | return true; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7754 | DSAStackTy::DSAVarData DVarPrivate = |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7755 | Stack->hasDSA(VD, isOpenMPPrivate, MatchesAlways(), false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7756 | if (DVarPrivate.CKind != OMPC_unknown) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7757 | return true; |
| 7758 | return false; |
| 7759 | } |
| 7760 | return false; |
| 7761 | } |
| 7762 | bool VisitStmt(Stmt *S) { |
| 7763 | for (auto Child : S->children()) { |
| 7764 | if (Child && Visit(Child)) |
| 7765 | return true; |
| 7766 | } |
| 7767 | return false; |
| 7768 | } |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 7769 | explicit DSARefChecker(DSAStackTy *S) : Stack(S) {} |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7770 | }; |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 7771 | } // namespace |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7772 | |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7773 | namespace { |
| 7774 | // Transform MemberExpression for specified FieldDecl of current class to |
| 7775 | // DeclRefExpr to specified OMPCapturedExprDecl. |
| 7776 | class TransformExprToCaptures : public TreeTransform<TransformExprToCaptures> { |
| 7777 | typedef TreeTransform<TransformExprToCaptures> BaseTransform; |
| 7778 | ValueDecl *Field; |
| 7779 | DeclRefExpr *CapturedExpr; |
| 7780 | |
| 7781 | public: |
| 7782 | TransformExprToCaptures(Sema &SemaRef, ValueDecl *FieldDecl) |
| 7783 | : BaseTransform(SemaRef), Field(FieldDecl), CapturedExpr(nullptr) {} |
| 7784 | |
| 7785 | ExprResult TransformMemberExpr(MemberExpr *E) { |
| 7786 | if (isa<CXXThisExpr>(E->getBase()->IgnoreParenImpCasts()) && |
| 7787 | E->getMemberDecl() == Field) { |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 7788 | CapturedExpr = buildCapture(SemaRef, Field, E, /*WithInit=*/false); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7789 | return CapturedExpr; |
| 7790 | } |
| 7791 | return BaseTransform::TransformMemberExpr(E); |
| 7792 | } |
| 7793 | DeclRefExpr *getCapturedExpr() { return CapturedExpr; } |
| 7794 | }; |
| 7795 | } // namespace |
| 7796 | |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 7797 | template <typename T> |
| 7798 | static T filterLookupForUDR(SmallVectorImpl<UnresolvedSet<8>> &Lookups, |
| 7799 | const llvm::function_ref<T(ValueDecl *)> &Gen) { |
| 7800 | for (auto &Set : Lookups) { |
| 7801 | for (auto *D : Set) { |
| 7802 | if (auto Res = Gen(cast<ValueDecl>(D))) |
| 7803 | return Res; |
| 7804 | } |
| 7805 | } |
| 7806 | return T(); |
| 7807 | } |
| 7808 | |
| 7809 | static ExprResult |
| 7810 | buildDeclareReductionRef(Sema &SemaRef, SourceLocation Loc, SourceRange Range, |
| 7811 | Scope *S, CXXScopeSpec &ReductionIdScopeSpec, |
| 7812 | const DeclarationNameInfo &ReductionId, QualType Ty, |
| 7813 | CXXCastPath &BasePath, Expr *UnresolvedReduction) { |
| 7814 | if (ReductionIdScopeSpec.isInvalid()) |
| 7815 | return ExprError(); |
| 7816 | SmallVector<UnresolvedSet<8>, 4> Lookups; |
| 7817 | if (S) { |
| 7818 | LookupResult Lookup(SemaRef, ReductionId, Sema::LookupOMPReductionName); |
| 7819 | Lookup.suppressDiagnostics(); |
| 7820 | while (S && SemaRef.LookupParsedName(Lookup, S, &ReductionIdScopeSpec)) { |
| 7821 | auto *D = Lookup.getRepresentativeDecl(); |
| 7822 | do { |
| 7823 | S = S->getParent(); |
| 7824 | } while (S && !S->isDeclScope(D)); |
| 7825 | if (S) |
| 7826 | S = S->getParent(); |
| 7827 | Lookups.push_back(UnresolvedSet<8>()); |
| 7828 | Lookups.back().append(Lookup.begin(), Lookup.end()); |
| 7829 | Lookup.clear(); |
| 7830 | } |
| 7831 | } else if (auto *ULE = |
| 7832 | cast_or_null<UnresolvedLookupExpr>(UnresolvedReduction)) { |
| 7833 | Lookups.push_back(UnresolvedSet<8>()); |
| 7834 | Decl *PrevD = nullptr; |
| 7835 | for(auto *D : ULE->decls()) { |
| 7836 | if (D == PrevD) |
| 7837 | Lookups.push_back(UnresolvedSet<8>()); |
| 7838 | else if (auto *DRD = cast<OMPDeclareReductionDecl>(D)) |
| 7839 | Lookups.back().addDecl(DRD); |
| 7840 | PrevD = D; |
| 7841 | } |
| 7842 | } |
| 7843 | if (Ty->isDependentType() || Ty->isInstantiationDependentType() || |
| 7844 | Ty->containsUnexpandedParameterPack() || |
| 7845 | filterLookupForUDR<bool>(Lookups, [](ValueDecl *D) -> bool { |
| 7846 | return !D->isInvalidDecl() && |
| 7847 | (D->getType()->isDependentType() || |
| 7848 | D->getType()->isInstantiationDependentType() || |
| 7849 | D->getType()->containsUnexpandedParameterPack()); |
| 7850 | })) { |
| 7851 | UnresolvedSet<8> ResSet; |
| 7852 | for (auto &Set : Lookups) { |
| 7853 | ResSet.append(Set.begin(), Set.end()); |
| 7854 | // The last item marks the end of all declarations at the specified scope. |
| 7855 | ResSet.addDecl(Set[Set.size() - 1]); |
| 7856 | } |
| 7857 | return UnresolvedLookupExpr::Create( |
| 7858 | SemaRef.Context, /*NamingClass=*/nullptr, |
| 7859 | ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), ReductionId, |
| 7860 | /*ADL=*/true, /*Overloaded=*/true, ResSet.begin(), ResSet.end()); |
| 7861 | } |
| 7862 | if (auto *VD = filterLookupForUDR<ValueDecl *>( |
| 7863 | Lookups, [&SemaRef, Ty](ValueDecl *D) -> ValueDecl * { |
| 7864 | if (!D->isInvalidDecl() && |
| 7865 | SemaRef.Context.hasSameType(D->getType(), Ty)) |
| 7866 | return D; |
| 7867 | return nullptr; |
| 7868 | })) |
| 7869 | return SemaRef.BuildDeclRefExpr(VD, Ty, VK_LValue, Loc); |
| 7870 | if (auto *VD = filterLookupForUDR<ValueDecl *>( |
| 7871 | Lookups, [&SemaRef, Ty, Loc](ValueDecl *D) -> ValueDecl * { |
| 7872 | if (!D->isInvalidDecl() && |
| 7873 | SemaRef.IsDerivedFrom(Loc, Ty, D->getType()) && |
| 7874 | !Ty.isMoreQualifiedThan(D->getType())) |
| 7875 | return D; |
| 7876 | return nullptr; |
| 7877 | })) { |
| 7878 | CXXBasePaths Paths(/*FindAmbiguities=*/true, /*RecordPaths=*/true, |
| 7879 | /*DetectVirtual=*/false); |
| 7880 | if (SemaRef.IsDerivedFrom(Loc, Ty, VD->getType(), Paths)) { |
| 7881 | if (!Paths.isAmbiguous(SemaRef.Context.getCanonicalType( |
| 7882 | VD->getType().getUnqualifiedType()))) { |
| 7883 | if (SemaRef.CheckBaseClassAccess(Loc, VD->getType(), Ty, Paths.front(), |
| 7884 | /*DiagID=*/0) != |
| 7885 | Sema::AR_inaccessible) { |
| 7886 | SemaRef.BuildBasePathArray(Paths, BasePath); |
| 7887 | return SemaRef.BuildDeclRefExpr(VD, Ty, VK_LValue, Loc); |
| 7888 | } |
| 7889 | } |
| 7890 | } |
| 7891 | } |
| 7892 | if (ReductionIdScopeSpec.isSet()) { |
| 7893 | SemaRef.Diag(Loc, diag::err_omp_not_resolved_reduction_identifier) << Range; |
| 7894 | return ExprError(); |
| 7895 | } |
| 7896 | return ExprEmpty(); |
| 7897 | } |
| 7898 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7899 | OMPClause *Sema::ActOnOpenMPReductionClause( |
| 7900 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, SourceLocation LParenLoc, |
| 7901 | SourceLocation ColonLoc, SourceLocation EndLoc, |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 7902 | CXXScopeSpec &ReductionIdScopeSpec, const DeclarationNameInfo &ReductionId, |
| 7903 | ArrayRef<Expr *> UnresolvedReductions) { |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7904 | auto DN = ReductionId.getName(); |
| 7905 | auto OOK = DN.getCXXOverloadedOperator(); |
| 7906 | BinaryOperatorKind BOK = BO_Comma; |
| 7907 | |
| 7908 | // OpenMP [2.14.3.6, reduction clause] |
| 7909 | // C |
| 7910 | // reduction-identifier is either an identifier or one of the following |
| 7911 | // operators: +, -, *, &, |, ^, && and || |
| 7912 | // C++ |
| 7913 | // reduction-identifier is either an id-expression or one of the following |
| 7914 | // operators: +, -, *, &, |, ^, && and || |
| 7915 | // FIXME: Only 'min' and 'max' identifiers are supported for now. |
| 7916 | switch (OOK) { |
| 7917 | case OO_Plus: |
| 7918 | case OO_Minus: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7919 | BOK = BO_Add; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7920 | break; |
| 7921 | case OO_Star: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7922 | BOK = BO_Mul; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7923 | break; |
| 7924 | case OO_Amp: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7925 | BOK = BO_And; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7926 | break; |
| 7927 | case OO_Pipe: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7928 | BOK = BO_Or; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7929 | break; |
| 7930 | case OO_Caret: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7931 | BOK = BO_Xor; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7932 | break; |
| 7933 | case OO_AmpAmp: |
| 7934 | BOK = BO_LAnd; |
| 7935 | break; |
| 7936 | case OO_PipePipe: |
| 7937 | BOK = BO_LOr; |
| 7938 | break; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7939 | case OO_New: |
| 7940 | case OO_Delete: |
| 7941 | case OO_Array_New: |
| 7942 | case OO_Array_Delete: |
| 7943 | case OO_Slash: |
| 7944 | case OO_Percent: |
| 7945 | case OO_Tilde: |
| 7946 | case OO_Exclaim: |
| 7947 | case OO_Equal: |
| 7948 | case OO_Less: |
| 7949 | case OO_Greater: |
| 7950 | case OO_LessEqual: |
| 7951 | case OO_GreaterEqual: |
| 7952 | case OO_PlusEqual: |
| 7953 | case OO_MinusEqual: |
| 7954 | case OO_StarEqual: |
| 7955 | case OO_SlashEqual: |
| 7956 | case OO_PercentEqual: |
| 7957 | case OO_CaretEqual: |
| 7958 | case OO_AmpEqual: |
| 7959 | case OO_PipeEqual: |
| 7960 | case OO_LessLess: |
| 7961 | case OO_GreaterGreater: |
| 7962 | case OO_LessLessEqual: |
| 7963 | case OO_GreaterGreaterEqual: |
| 7964 | case OO_EqualEqual: |
| 7965 | case OO_ExclaimEqual: |
| 7966 | case OO_PlusPlus: |
| 7967 | case OO_MinusMinus: |
| 7968 | case OO_Comma: |
| 7969 | case OO_ArrowStar: |
| 7970 | case OO_Arrow: |
| 7971 | case OO_Call: |
| 7972 | case OO_Subscript: |
| 7973 | case OO_Conditional: |
Richard Smith | 9be594e | 2015-10-22 05:12:22 +0000 | [diff] [blame] | 7974 | case OO_Coawait: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7975 | case NUM_OVERLOADED_OPERATORS: |
| 7976 | llvm_unreachable("Unexpected reduction identifier"); |
| 7977 | case OO_None: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7978 | if (auto II = DN.getAsIdentifierInfo()) { |
| 7979 | if (II->isStr("max")) |
| 7980 | BOK = BO_GT; |
| 7981 | else if (II->isStr("min")) |
| 7982 | BOK = BO_LT; |
| 7983 | } |
| 7984 | break; |
| 7985 | } |
| 7986 | SourceRange ReductionIdRange; |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 7987 | if (ReductionIdScopeSpec.isValid()) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7988 | ReductionIdRange.setBegin(ReductionIdScopeSpec.getBeginLoc()); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7989 | ReductionIdRange.setEnd(ReductionId.getEndLoc()); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7990 | |
| 7991 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7992 | SmallVector<Expr *, 8> Privates; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7993 | SmallVector<Expr *, 8> LHSs; |
| 7994 | SmallVector<Expr *, 8> RHSs; |
| 7995 | SmallVector<Expr *, 8> ReductionOps; |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 7996 | SmallVector<Decl *, 4> ExprCaptures; |
| 7997 | SmallVector<Expr *, 4> ExprPostUpdates; |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 7998 | auto IR = UnresolvedReductions.begin(), ER = UnresolvedReductions.end(); |
| 7999 | bool FirstIter = true; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8000 | for (auto RefExpr : VarList) { |
| 8001 | assert(RefExpr && "nullptr expr in OpenMP reduction clause."); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8002 | // OpenMP [2.1, C/C++] |
| 8003 | // A list item is a variable or array section, subject to the restrictions |
| 8004 | // specified in Section 2.4 on page 42 and in each of the sections |
| 8005 | // describing clauses and directives for which a list appears. |
| 8006 | // OpenMP [2.14.3.3, Restrictions, p.1] |
| 8007 | // A variable that is part of another variable (as an array or |
| 8008 | // structure element) cannot appear in a private clause. |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8009 | if (!FirstIter && IR != ER) |
| 8010 | ++IR; |
| 8011 | FirstIter = false; |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8012 | SourceLocation ELoc; |
| 8013 | SourceRange ERange; |
| 8014 | Expr *SimpleRefExpr = RefExpr; |
| 8015 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange, |
| 8016 | /*AllowArraySection=*/true); |
| 8017 | if (Res.second) { |
| 8018 | // It will be analyzed later. |
| 8019 | Vars.push_back(RefExpr); |
| 8020 | Privates.push_back(nullptr); |
| 8021 | LHSs.push_back(nullptr); |
| 8022 | RHSs.push_back(nullptr); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8023 | // Try to find 'declare reduction' corresponding construct before using |
| 8024 | // builtin/overloaded operators. |
| 8025 | QualType Type = Context.DependentTy; |
| 8026 | CXXCastPath BasePath; |
| 8027 | ExprResult DeclareReductionRef = buildDeclareReductionRef( |
| 8028 | *this, ELoc, ERange, DSAStack->getCurScope(), ReductionIdScopeSpec, |
| 8029 | ReductionId, Type, BasePath, IR == ER ? nullptr : *IR); |
| 8030 | if (CurContext->isDependentContext() && |
| 8031 | (DeclareReductionRef.isUnset() || |
| 8032 | isa<UnresolvedLookupExpr>(DeclareReductionRef.get()))) |
| 8033 | ReductionOps.push_back(DeclareReductionRef.get()); |
| 8034 | else |
| 8035 | ReductionOps.push_back(nullptr); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8036 | } |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8037 | ValueDecl *D = Res.first; |
| 8038 | if (!D) |
| 8039 | continue; |
| 8040 | |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8041 | QualType Type; |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8042 | auto *ASE = dyn_cast<ArraySubscriptExpr>(RefExpr->IgnoreParens()); |
| 8043 | auto *OASE = dyn_cast<OMPArraySectionExpr>(RefExpr->IgnoreParens()); |
| 8044 | if (ASE) |
Alexey Bataev | 31300ed | 2016-02-04 11:27:03 +0000 | [diff] [blame] | 8045 | Type = ASE->getType().getNonReferenceType(); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8046 | else if (OASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8047 | auto BaseType = OMPArraySectionExpr::getBaseOriginalType(OASE->getBase()); |
| 8048 | if (auto *ATy = BaseType->getAsArrayTypeUnsafe()) |
| 8049 | Type = ATy->getElementType(); |
| 8050 | else |
| 8051 | Type = BaseType->getPointeeType(); |
Alexey Bataev | 31300ed | 2016-02-04 11:27:03 +0000 | [diff] [blame] | 8052 | Type = Type.getNonReferenceType(); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8053 | } else |
| 8054 | Type = Context.getBaseElementType(D->getType().getNonReferenceType()); |
| 8055 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8056 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8057 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 8058 | // A variable that appears in a private clause must not have an incomplete |
| 8059 | // type or a reference type. |
| 8060 | if (RequireCompleteType(ELoc, Type, |
| 8061 | diag::err_omp_reduction_incomplete_type)) |
| 8062 | continue; |
| 8063 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8064 | // A list item that appears in a reduction clause must not be |
| 8065 | // const-qualified. |
| 8066 | if (Type.getNonReferenceType().isConstant(Context)) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8067 | Diag(ELoc, diag::err_omp_const_reduction_list_item) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8068 | << getOpenMPClauseName(OMPC_reduction) << Type << ERange; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8069 | if (!ASE && !OASE) { |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8070 | bool IsDecl = !VD || |
| 8071 | VD->isThisDeclarationADefinition(Context) == |
| 8072 | VarDecl::DeclarationOnly; |
| 8073 | Diag(D->getLocation(), |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8074 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8075 | << D; |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8076 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8077 | continue; |
| 8078 | } |
| 8079 | // OpenMP [2.9.3.6, Restrictions, C/C++, p.4] |
| 8080 | // If a list-item is a reference type then it must bind to the same object |
| 8081 | // for all threads of the team. |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8082 | if (!ASE && !OASE && VD) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8083 | VarDecl *VDDef = VD->getDefinition(); |
Alexey Bataev | 31300ed | 2016-02-04 11:27:03 +0000 | [diff] [blame] | 8084 | if (VD->getType()->isReferenceType() && VDDef) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8085 | DSARefChecker Check(DSAStack); |
| 8086 | if (Check.Visit(VDDef->getInit())) { |
| 8087 | Diag(ELoc, diag::err_omp_reduction_ref_type_arg) << ERange; |
| 8088 | Diag(VDDef->getLocation(), diag::note_defined_here) << VDDef; |
| 8089 | continue; |
| 8090 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8091 | } |
| 8092 | } |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8093 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8094 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 8095 | // in a Construct] |
| 8096 | // Variables with the predetermined data-sharing attributes may not be |
| 8097 | // listed in data-sharing attributes clauses, except for the cases |
| 8098 | // listed below. For these exceptions only, listing a predetermined |
| 8099 | // variable in a data-sharing attribute clause is allowed and overrides |
| 8100 | // the variable's predetermined data-sharing attributes. |
| 8101 | // OpenMP [2.14.3.6, Restrictions, p.3] |
| 8102 | // Any number of reduction clauses can be specified on the directive, |
| 8103 | // but a list item can appear only once in the reduction clauses for that |
| 8104 | // directive. |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8105 | DSAStackTy::DSAVarData DVar; |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8106 | DVar = DSAStack->getTopDSA(D, false); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8107 | if (DVar.CKind == OMPC_reduction) { |
| 8108 | Diag(ELoc, diag::err_omp_once_referenced) |
| 8109 | << getOpenMPClauseName(OMPC_reduction); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8110 | if (DVar.RefExpr) |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8111 | Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_referenced); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8112 | } else if (DVar.CKind != OMPC_unknown) { |
| 8113 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 8114 | << getOpenMPClauseName(DVar.CKind) |
| 8115 | << getOpenMPClauseName(OMPC_reduction); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8116 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8117 | continue; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8118 | } |
| 8119 | |
| 8120 | // OpenMP [2.14.3.6, Restrictions, p.1] |
| 8121 | // A list item that appears in a reduction clause of a worksharing |
| 8122 | // construct must be shared in the parallel regions to which any of the |
| 8123 | // worksharing regions arising from the worksharing construct bind. |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8124 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
| 8125 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 8126 | !isOpenMPParallelDirective(CurrDir)) { |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8127 | DVar = DSAStack->getImplicitDSA(D, true); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8128 | if (DVar.CKind != OMPC_shared) { |
| 8129 | Diag(ELoc, diag::err_omp_required_access) |
| 8130 | << getOpenMPClauseName(OMPC_reduction) |
| 8131 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8132 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8133 | continue; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 8134 | } |
| 8135 | } |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8136 | |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8137 | // Try to find 'declare reduction' corresponding construct before using |
| 8138 | // builtin/overloaded operators. |
| 8139 | CXXCastPath BasePath; |
| 8140 | ExprResult DeclareReductionRef = buildDeclareReductionRef( |
| 8141 | *this, ELoc, ERange, DSAStack->getCurScope(), ReductionIdScopeSpec, |
| 8142 | ReductionId, Type, BasePath, IR == ER ? nullptr : *IR); |
| 8143 | if (DeclareReductionRef.isInvalid()) |
| 8144 | continue; |
| 8145 | if (CurContext->isDependentContext() && |
| 8146 | (DeclareReductionRef.isUnset() || |
| 8147 | isa<UnresolvedLookupExpr>(DeclareReductionRef.get()))) { |
| 8148 | Vars.push_back(RefExpr); |
| 8149 | Privates.push_back(nullptr); |
| 8150 | LHSs.push_back(nullptr); |
| 8151 | RHSs.push_back(nullptr); |
| 8152 | ReductionOps.push_back(DeclareReductionRef.get()); |
| 8153 | continue; |
| 8154 | } |
| 8155 | if (BOK == BO_Comma && DeclareReductionRef.isUnset()) { |
| 8156 | // Not allowed reduction identifier is found. |
| 8157 | Diag(ReductionId.getLocStart(), |
| 8158 | diag::err_omp_unknown_reduction_identifier) |
| 8159 | << Type << ReductionIdRange; |
| 8160 | continue; |
| 8161 | } |
| 8162 | |
| 8163 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
| 8164 | // The type of a list item that appears in a reduction clause must be valid |
| 8165 | // for the reduction-identifier. For a max or min reduction in C, the type |
| 8166 | // of the list item must be an allowed arithmetic data type: char, int, |
| 8167 | // float, double, or _Bool, possibly modified with long, short, signed, or |
| 8168 | // unsigned. For a max or min reduction in C++, the type of the list item |
| 8169 | // must be an allowed arithmetic data type: char, wchar_t, int, float, |
| 8170 | // double, or bool, possibly modified with long, short, signed, or unsigned. |
| 8171 | if (DeclareReductionRef.isUnset()) { |
| 8172 | if ((BOK == BO_GT || BOK == BO_LT) && |
| 8173 | !(Type->isScalarType() || |
| 8174 | (getLangOpts().CPlusPlus && Type->isArithmeticType()))) { |
| 8175 | Diag(ELoc, diag::err_omp_clause_not_arithmetic_type_arg) |
| 8176 | << getLangOpts().CPlusPlus; |
| 8177 | if (!ASE && !OASE) { |
| 8178 | bool IsDecl = !VD || |
| 8179 | VD->isThisDeclarationADefinition(Context) == |
| 8180 | VarDecl::DeclarationOnly; |
| 8181 | Diag(D->getLocation(), |
| 8182 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 8183 | << D; |
| 8184 | } |
| 8185 | continue; |
| 8186 | } |
| 8187 | if ((BOK == BO_OrAssign || BOK == BO_AndAssign || BOK == BO_XorAssign) && |
| 8188 | !getLangOpts().CPlusPlus && Type->isFloatingType()) { |
| 8189 | Diag(ELoc, diag::err_omp_clause_floating_type_arg); |
| 8190 | if (!ASE && !OASE) { |
| 8191 | bool IsDecl = !VD || |
| 8192 | VD->isThisDeclarationADefinition(Context) == |
| 8193 | VarDecl::DeclarationOnly; |
| 8194 | Diag(D->getLocation(), |
| 8195 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 8196 | << D; |
| 8197 | } |
| 8198 | continue; |
| 8199 | } |
| 8200 | } |
| 8201 | |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8202 | Type = Type.getNonLValueExprType(Context).getUnqualifiedType(); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8203 | auto *LHSVD = buildVarDecl(*this, ELoc, Type, ".reduction.lhs", |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8204 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 8205 | auto *RHSVD = buildVarDecl(*this, ELoc, Type, D->getName(), |
| 8206 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8207 | auto PrivateTy = Type; |
Alexey Bataev | 1189bd0 | 2016-01-26 12:20:39 +0000 | [diff] [blame] | 8208 | if (OASE || |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8209 | (!ASE && |
| 8210 | D->getType().getNonReferenceType()->isVariablyModifiedType())) { |
Alexey Bataev | 1189bd0 | 2016-01-26 12:20:39 +0000 | [diff] [blame] | 8211 | // For arays/array sections only: |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8212 | // Create pseudo array type for private copy. The size for this array will |
| 8213 | // be generated during codegen. |
| 8214 | // For array subscripts or single variables Private Ty is the same as Type |
| 8215 | // (type of the variable or single array element). |
| 8216 | PrivateTy = Context.getVariableArrayType( |
| 8217 | Type, new (Context) OpaqueValueExpr(SourceLocation(), |
| 8218 | Context.getSizeType(), VK_RValue), |
| 8219 | ArrayType::Normal, /*IndexTypeQuals=*/0, SourceRange()); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8220 | } else if (!ASE && !OASE && |
| 8221 | Context.getAsArrayType(D->getType().getNonReferenceType())) |
| 8222 | PrivateTy = D->getType().getNonReferenceType(); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8223 | // Private copy. |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8224 | auto *PrivateVD = buildVarDecl(*this, ELoc, PrivateTy, D->getName(), |
| 8225 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8226 | // Add initializer for private variable. |
| 8227 | Expr *Init = nullptr; |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8228 | auto *LHSDRE = buildDeclRefExpr(*this, LHSVD, Type, ELoc); |
| 8229 | auto *RHSDRE = buildDeclRefExpr(*this, RHSVD, Type, ELoc); |
| 8230 | if (DeclareReductionRef.isUsable()) { |
| 8231 | auto *DRDRef = DeclareReductionRef.getAs<DeclRefExpr>(); |
| 8232 | auto *DRD = cast<OMPDeclareReductionDecl>(DRDRef->getDecl()); |
| 8233 | if (DRD->getInitializer()) { |
| 8234 | Init = DRDRef; |
| 8235 | RHSVD->setInit(DRDRef); |
| 8236 | RHSVD->setInitStyle(VarDecl::CallInit); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8237 | } |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8238 | } else { |
| 8239 | switch (BOK) { |
| 8240 | case BO_Add: |
| 8241 | case BO_Xor: |
| 8242 | case BO_Or: |
| 8243 | case BO_LOr: |
| 8244 | // '+', '-', '^', '|', '||' reduction ops - initializer is '0'. |
| 8245 | if (Type->isScalarType() || Type->isAnyComplexType()) |
| 8246 | Init = ActOnIntegerConstant(ELoc, /*Val=*/0).get(); |
| 8247 | break; |
| 8248 | case BO_Mul: |
| 8249 | case BO_LAnd: |
| 8250 | if (Type->isScalarType() || Type->isAnyComplexType()) { |
| 8251 | // '*' and '&&' reduction ops - initializer is '1'. |
| 8252 | Init = ActOnIntegerConstant(ELoc, /*Val=*/1).get(); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8253 | } |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8254 | break; |
| 8255 | case BO_And: { |
| 8256 | // '&' reduction op - initializer is '~0'. |
| 8257 | QualType OrigType = Type; |
| 8258 | if (auto *ComplexTy = OrigType->getAs<ComplexType>()) |
| 8259 | Type = ComplexTy->getElementType(); |
| 8260 | if (Type->isRealFloatingType()) { |
| 8261 | llvm::APFloat InitValue = |
| 8262 | llvm::APFloat::getAllOnesValue(Context.getTypeSize(Type), |
| 8263 | /*isIEEE=*/true); |
| 8264 | Init = FloatingLiteral::Create(Context, InitValue, /*isexact=*/true, |
| 8265 | Type, ELoc); |
| 8266 | } else if (Type->isScalarType()) { |
| 8267 | auto Size = Context.getTypeSize(Type); |
| 8268 | QualType IntTy = Context.getIntTypeForBitwidth(Size, /*Signed=*/0); |
| 8269 | llvm::APInt InitValue = llvm::APInt::getAllOnesValue(Size); |
| 8270 | Init = IntegerLiteral::Create(Context, InitValue, IntTy, ELoc); |
| 8271 | } |
| 8272 | if (Init && OrigType->isAnyComplexType()) { |
| 8273 | // Init = 0xFFFF + 0xFFFFi; |
| 8274 | auto *Im = new (Context) ImaginaryLiteral(Init, OrigType); |
| 8275 | Init = CreateBuiltinBinOp(ELoc, BO_Add, Init, Im).get(); |
| 8276 | } |
| 8277 | Type = OrigType; |
| 8278 | break; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8279 | } |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8280 | case BO_LT: |
| 8281 | case BO_GT: { |
| 8282 | // 'min' reduction op - initializer is 'Largest representable number in |
| 8283 | // the reduction list item type'. |
| 8284 | // 'max' reduction op - initializer is 'Least representable number in |
| 8285 | // the reduction list item type'. |
| 8286 | if (Type->isIntegerType() || Type->isPointerType()) { |
| 8287 | bool IsSigned = Type->hasSignedIntegerRepresentation(); |
| 8288 | auto Size = Context.getTypeSize(Type); |
| 8289 | QualType IntTy = |
| 8290 | Context.getIntTypeForBitwidth(Size, /*Signed=*/IsSigned); |
| 8291 | llvm::APInt InitValue = |
| 8292 | (BOK != BO_LT) |
| 8293 | ? IsSigned ? llvm::APInt::getSignedMinValue(Size) |
| 8294 | : llvm::APInt::getMinValue(Size) |
| 8295 | : IsSigned ? llvm::APInt::getSignedMaxValue(Size) |
| 8296 | : llvm::APInt::getMaxValue(Size); |
| 8297 | Init = IntegerLiteral::Create(Context, InitValue, IntTy, ELoc); |
| 8298 | if (Type->isPointerType()) { |
| 8299 | // Cast to pointer type. |
| 8300 | auto CastExpr = BuildCStyleCastExpr( |
| 8301 | SourceLocation(), Context.getTrivialTypeSourceInfo(Type, ELoc), |
| 8302 | SourceLocation(), Init); |
| 8303 | if (CastExpr.isInvalid()) |
| 8304 | continue; |
| 8305 | Init = CastExpr.get(); |
| 8306 | } |
| 8307 | } else if (Type->isRealFloatingType()) { |
| 8308 | llvm::APFloat InitValue = llvm::APFloat::getLargest( |
| 8309 | Context.getFloatTypeSemantics(Type), BOK != BO_LT); |
| 8310 | Init = FloatingLiteral::Create(Context, InitValue, /*isexact=*/true, |
| 8311 | Type, ELoc); |
| 8312 | } |
| 8313 | break; |
| 8314 | } |
| 8315 | case BO_PtrMemD: |
| 8316 | case BO_PtrMemI: |
| 8317 | case BO_MulAssign: |
| 8318 | case BO_Div: |
| 8319 | case BO_Rem: |
| 8320 | case BO_Sub: |
| 8321 | case BO_Shl: |
| 8322 | case BO_Shr: |
| 8323 | case BO_LE: |
| 8324 | case BO_GE: |
| 8325 | case BO_EQ: |
| 8326 | case BO_NE: |
| 8327 | case BO_AndAssign: |
| 8328 | case BO_XorAssign: |
| 8329 | case BO_OrAssign: |
| 8330 | case BO_Assign: |
| 8331 | case BO_AddAssign: |
| 8332 | case BO_SubAssign: |
| 8333 | case BO_DivAssign: |
| 8334 | case BO_RemAssign: |
| 8335 | case BO_ShlAssign: |
| 8336 | case BO_ShrAssign: |
| 8337 | case BO_Comma: |
| 8338 | llvm_unreachable("Unexpected reduction operation"); |
| 8339 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8340 | } |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8341 | if (Init && DeclareReductionRef.isUnset()) { |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8342 | AddInitializerToDecl(RHSVD, Init, /*DirectInit=*/false, |
| 8343 | /*TypeMayContainAuto=*/false); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8344 | } else if (!Init) |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8345 | ActOnUninitializedDecl(RHSVD, /*TypeMayContainAuto=*/false); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8346 | if (RHSVD->isInvalidDecl()) |
| 8347 | continue; |
| 8348 | if (!RHSVD->hasInit() && DeclareReductionRef.isUnset()) { |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8349 | Diag(ELoc, diag::err_omp_reduction_id_not_compatible) << Type |
| 8350 | << ReductionIdRange; |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8351 | bool IsDecl = |
| 8352 | !VD || |
| 8353 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 8354 | Diag(D->getLocation(), |
| 8355 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 8356 | << D; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8357 | continue; |
| 8358 | } |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8359 | // Store initializer for single element in private copy. Will be used during |
| 8360 | // codegen. |
| 8361 | PrivateVD->setInit(RHSVD->getInit()); |
| 8362 | PrivateVD->setInitStyle(RHSVD->getInitStyle()); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8363 | auto *PrivateDRE = buildDeclRefExpr(*this, PrivateVD, PrivateTy, ELoc); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8364 | ExprResult ReductionOp; |
| 8365 | if (DeclareReductionRef.isUsable()) { |
| 8366 | QualType RedTy = DeclareReductionRef.get()->getType(); |
| 8367 | QualType PtrRedTy = Context.getPointerType(RedTy); |
| 8368 | ExprResult LHS = CreateBuiltinUnaryOp(ELoc, UO_AddrOf, LHSDRE); |
| 8369 | ExprResult RHS = CreateBuiltinUnaryOp(ELoc, UO_AddrOf, RHSDRE); |
| 8370 | if (!BasePath.empty()) { |
| 8371 | LHS = DefaultLvalueConversion(LHS.get()); |
| 8372 | RHS = DefaultLvalueConversion(RHS.get()); |
| 8373 | LHS = ImplicitCastExpr::Create(Context, PtrRedTy, |
| 8374 | CK_UncheckedDerivedToBase, LHS.get(), |
| 8375 | &BasePath, LHS.get()->getValueKind()); |
| 8376 | RHS = ImplicitCastExpr::Create(Context, PtrRedTy, |
| 8377 | CK_UncheckedDerivedToBase, RHS.get(), |
| 8378 | &BasePath, RHS.get()->getValueKind()); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8379 | } |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8380 | FunctionProtoType::ExtProtoInfo EPI; |
| 8381 | QualType Params[] = {PtrRedTy, PtrRedTy}; |
| 8382 | QualType FnTy = Context.getFunctionType(Context.VoidTy, Params, EPI); |
| 8383 | auto *OVE = new (Context) OpaqueValueExpr( |
| 8384 | ELoc, Context.getPointerType(FnTy), VK_RValue, OK_Ordinary, |
| 8385 | DefaultLvalueConversion(DeclareReductionRef.get()).get()); |
| 8386 | Expr *Args[] = {LHS.get(), RHS.get()}; |
| 8387 | ReductionOp = new (Context) |
| 8388 | CallExpr(Context, OVE, Args, Context.VoidTy, VK_RValue, ELoc); |
| 8389 | } else { |
| 8390 | ReductionOp = BuildBinOp(DSAStack->getCurScope(), |
| 8391 | ReductionId.getLocStart(), BOK, LHSDRE, RHSDRE); |
| 8392 | if (ReductionOp.isUsable()) { |
| 8393 | if (BOK != BO_LT && BOK != BO_GT) { |
| 8394 | ReductionOp = |
| 8395 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), |
| 8396 | BO_Assign, LHSDRE, ReductionOp.get()); |
| 8397 | } else { |
| 8398 | auto *ConditionalOp = new (Context) ConditionalOperator( |
| 8399 | ReductionOp.get(), SourceLocation(), LHSDRE, SourceLocation(), |
| 8400 | RHSDRE, Type, VK_LValue, OK_Ordinary); |
| 8401 | ReductionOp = |
| 8402 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), |
| 8403 | BO_Assign, LHSDRE, ConditionalOp); |
| 8404 | } |
| 8405 | ReductionOp = ActOnFinishFullExpr(ReductionOp.get()); |
| 8406 | } |
| 8407 | if (ReductionOp.isInvalid()) |
| 8408 | continue; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8409 | } |
| 8410 | |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8411 | DeclRefExpr *Ref = nullptr; |
| 8412 | Expr *VarsExpr = RefExpr->IgnoreParens(); |
| 8413 | if (!VD) { |
| 8414 | if (ASE || OASE) { |
| 8415 | TransformExprToCaptures RebuildToCapture(*this, D); |
| 8416 | VarsExpr = |
| 8417 | RebuildToCapture.TransformExpr(RefExpr->IgnoreParens()).get(); |
| 8418 | Ref = RebuildToCapture.getCapturedExpr(); |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 8419 | } else { |
| 8420 | VarsExpr = Ref = |
| 8421 | buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false); |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 8422 | } |
| 8423 | if (!IsOpenMPCapturedDecl(D)) { |
| 8424 | ExprCaptures.push_back(Ref->getDecl()); |
| 8425 | if (Ref->getDecl()->hasAttr<OMPCaptureNoInitAttr>()) { |
| 8426 | ExprResult RefRes = DefaultLvalueConversion(Ref); |
| 8427 | if (!RefRes.isUsable()) |
| 8428 | continue; |
| 8429 | ExprResult PostUpdateRes = |
| 8430 | BuildBinOp(DSAStack->getCurScope(), ELoc, BO_Assign, |
| 8431 | SimpleRefExpr, RefRes.get()); |
| 8432 | if (!PostUpdateRes.isUsable()) |
| 8433 | continue; |
| 8434 | ExprPostUpdates.push_back( |
| 8435 | IgnoredValueConversions(PostUpdateRes.get()).get()); |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 8436 | } |
| 8437 | } |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8438 | } |
| 8439 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_reduction, Ref); |
| 8440 | Vars.push_back(VarsExpr); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8441 | Privates.push_back(PrivateDRE); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8442 | LHSs.push_back(LHSDRE); |
| 8443 | RHSs.push_back(RHSDRE); |
| 8444 | ReductionOps.push_back(ReductionOp.get()); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8445 | } |
| 8446 | |
| 8447 | if (Vars.empty()) |
| 8448 | return nullptr; |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 8449 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8450 | return OMPReductionClause::Create( |
| 8451 | Context, StartLoc, LParenLoc, ColonLoc, EndLoc, Vars, |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8452 | ReductionIdScopeSpec.getWithLocInContext(Context), ReductionId, Privates, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 8453 | LHSs, RHSs, ReductionOps, buildPreInits(Context, ExprCaptures), |
| 8454 | buildPostUpdate(*this, ExprPostUpdates)); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8455 | } |
| 8456 | |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 8457 | OMPClause *Sema::ActOnOpenMPLinearClause( |
| 8458 | ArrayRef<Expr *> VarList, Expr *Step, SourceLocation StartLoc, |
| 8459 | SourceLocation LParenLoc, OpenMPLinearClauseKind LinKind, |
| 8460 | SourceLocation LinLoc, SourceLocation ColonLoc, SourceLocation EndLoc) { |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8461 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8462 | SmallVector<Expr *, 8> Privates; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8463 | SmallVector<Expr *, 8> Inits; |
Alexey Bataev | 78849fb | 2016-03-09 09:49:00 +0000 | [diff] [blame] | 8464 | SmallVector<Decl *, 4> ExprCaptures; |
| 8465 | SmallVector<Expr *, 4> ExprPostUpdates; |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 8466 | if ((!LangOpts.CPlusPlus && LinKind != OMPC_LINEAR_val) || |
| 8467 | LinKind == OMPC_LINEAR_unknown) { |
| 8468 | Diag(LinLoc, diag::err_omp_wrong_linear_modifier) << LangOpts.CPlusPlus; |
| 8469 | LinKind = OMPC_LINEAR_val; |
| 8470 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8471 | for (auto &RefExpr : VarList) { |
| 8472 | assert(RefExpr && "NULL expr in OpenMP linear clause."); |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8473 | SourceLocation ELoc; |
| 8474 | SourceRange ERange; |
| 8475 | Expr *SimpleRefExpr = RefExpr; |
| 8476 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange, |
| 8477 | /*AllowArraySection=*/false); |
| 8478 | if (Res.second) { |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8479 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8480 | Vars.push_back(RefExpr); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8481 | Privates.push_back(nullptr); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8482 | Inits.push_back(nullptr); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8483 | } |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8484 | ValueDecl *D = Res.first; |
| 8485 | if (!D) |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8486 | continue; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8487 | |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8488 | QualType Type = D->getType(); |
| 8489 | auto *VD = dyn_cast<VarDecl>(D); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8490 | |
| 8491 | // OpenMP [2.14.3.7, linear clause] |
| 8492 | // A list-item cannot appear in more than one linear clause. |
| 8493 | // A list-item that appears in a linear clause cannot appear in any |
| 8494 | // other data-sharing attribute clause. |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8495 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8496 | if (DVar.RefExpr) { |
| 8497 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 8498 | << getOpenMPClauseName(OMPC_linear); |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8499 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8500 | continue; |
| 8501 | } |
| 8502 | |
| 8503 | // A variable must not have an incomplete type or a reference type. |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8504 | if (RequireCompleteType(ELoc, Type, |
| 8505 | diag::err_omp_linear_incomplete_type)) |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8506 | continue; |
Alexey Bataev | 1185e19 | 2015-08-20 12:15:57 +0000 | [diff] [blame] | 8507 | if ((LinKind == OMPC_LINEAR_uval || LinKind == OMPC_LINEAR_ref) && |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8508 | !Type->isReferenceType()) { |
Alexey Bataev | 1185e19 | 2015-08-20 12:15:57 +0000 | [diff] [blame] | 8509 | Diag(ELoc, diag::err_omp_wrong_linear_modifier_non_reference) |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8510 | << Type << getOpenMPSimpleClauseTypeName(OMPC_linear, LinKind); |
Alexey Bataev | 1185e19 | 2015-08-20 12:15:57 +0000 | [diff] [blame] | 8511 | continue; |
| 8512 | } |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8513 | Type = Type.getNonReferenceType(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8514 | |
| 8515 | // A list item must not be const-qualified. |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8516 | if (Type.isConstant(Context)) { |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8517 | Diag(ELoc, diag::err_omp_const_variable) |
| 8518 | << getOpenMPClauseName(OMPC_linear); |
| 8519 | bool IsDecl = |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8520 | !VD || |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8521 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8522 | Diag(D->getLocation(), |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8523 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8524 | << D; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8525 | continue; |
| 8526 | } |
| 8527 | |
| 8528 | // A list item must be of integral or pointer type. |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8529 | Type = Type.getUnqualifiedType().getCanonicalType(); |
| 8530 | const auto *Ty = Type.getTypePtrOrNull(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8531 | if (!Ty || (!Ty->isDependentType() && !Ty->isIntegralType(Context) && |
| 8532 | !Ty->isPointerType())) { |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8533 | Diag(ELoc, diag::err_omp_linear_expected_int_or_ptr) << Type; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8534 | bool IsDecl = |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8535 | !VD || |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8536 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8537 | Diag(D->getLocation(), |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8538 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8539 | << D; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8540 | continue; |
| 8541 | } |
| 8542 | |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8543 | // Build private copy of original var. |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8544 | auto *Private = buildVarDecl(*this, ELoc, Type, D->getName(), |
| 8545 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 8546 | auto *PrivateRef = buildDeclRefExpr(*this, Private, Type, ELoc); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8547 | // Build var to save initial value. |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8548 | VarDecl *Init = buildVarDecl(*this, ELoc, Type, ".linear.start"); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 8549 | Expr *InitExpr; |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8550 | DeclRefExpr *Ref = nullptr; |
Alexey Bataev | 78849fb | 2016-03-09 09:49:00 +0000 | [diff] [blame] | 8551 | if (!VD) { |
| 8552 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false); |
| 8553 | if (!IsOpenMPCapturedDecl(D)) { |
| 8554 | ExprCaptures.push_back(Ref->getDecl()); |
| 8555 | if (Ref->getDecl()->hasAttr<OMPCaptureNoInitAttr>()) { |
| 8556 | ExprResult RefRes = DefaultLvalueConversion(Ref); |
| 8557 | if (!RefRes.isUsable()) |
| 8558 | continue; |
| 8559 | ExprResult PostUpdateRes = |
| 8560 | BuildBinOp(DSAStack->getCurScope(), ELoc, BO_Assign, |
| 8561 | SimpleRefExpr, RefRes.get()); |
| 8562 | if (!PostUpdateRes.isUsable()) |
| 8563 | continue; |
| 8564 | ExprPostUpdates.push_back( |
| 8565 | IgnoredValueConversions(PostUpdateRes.get()).get()); |
| 8566 | } |
| 8567 | } |
| 8568 | } |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 8569 | if (LinKind == OMPC_LINEAR_uval) |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8570 | InitExpr = VD ? VD->getInit() : SimpleRefExpr; |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 8571 | else |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8572 | InitExpr = VD ? SimpleRefExpr : Ref; |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 8573 | AddInitializerToDecl(Init, DefaultLvalueConversion(InitExpr).get(), |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8574 | /*DirectInit=*/false, /*TypeMayContainAuto=*/false); |
| 8575 | auto InitRef = buildDeclRefExpr(*this, Init, Type, ELoc); |
| 8576 | |
| 8577 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_linear, Ref); |
| 8578 | Vars.push_back(VD ? RefExpr->IgnoreParens() : Ref); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8579 | Privates.push_back(PrivateRef); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8580 | Inits.push_back(InitRef); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8581 | } |
| 8582 | |
| 8583 | if (Vars.empty()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 8584 | return nullptr; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8585 | |
| 8586 | Expr *StepExpr = Step; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8587 | Expr *CalcStepExpr = nullptr; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8588 | if (Step && !Step->isValueDependent() && !Step->isTypeDependent() && |
| 8589 | !Step->isInstantiationDependent() && |
| 8590 | !Step->containsUnexpandedParameterPack()) { |
| 8591 | SourceLocation StepLoc = Step->getLocStart(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 8592 | ExprResult Val = PerformOpenMPImplicitIntegerConversion(StepLoc, Step); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8593 | if (Val.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 8594 | return nullptr; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 8595 | StepExpr = Val.get(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8596 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8597 | // Build var to save the step value. |
| 8598 | VarDecl *SaveVar = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 8599 | buildVarDecl(*this, StepLoc, StepExpr->getType(), ".linear.step"); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8600 | ExprResult SaveRef = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 8601 | buildDeclRefExpr(*this, SaveVar, StepExpr->getType(), StepLoc); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8602 | ExprResult CalcStep = |
| 8603 | BuildBinOp(CurScope, StepLoc, BO_Assign, SaveRef.get(), StepExpr); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 8604 | CalcStep = ActOnFinishFullExpr(CalcStep.get()); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8605 | |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8606 | // Warn about zero linear step (it would be probably better specified as |
| 8607 | // making corresponding variables 'const'). |
| 8608 | llvm::APSInt Result; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8609 | bool IsConstant = StepExpr->isIntegerConstantExpr(Result, Context); |
| 8610 | if (IsConstant && !Result.isNegative() && !Result.isStrictlyPositive()) |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8611 | Diag(StepLoc, diag::warn_omp_linear_step_zero) << Vars[0] |
| 8612 | << (Vars.size() > 1); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8613 | if (!IsConstant && CalcStep.isUsable()) { |
| 8614 | // Calculate the step beforehand instead of doing this on each iteration. |
| 8615 | // (This is not used if the number of iterations may be kfold-ed). |
| 8616 | CalcStepExpr = CalcStep.get(); |
| 8617 | } |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8618 | } |
| 8619 | |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 8620 | return OMPLinearClause::Create(Context, StartLoc, LParenLoc, LinKind, LinLoc, |
| 8621 | ColonLoc, EndLoc, Vars, Privates, Inits, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 8622 | StepExpr, CalcStepExpr, |
| 8623 | buildPreInits(Context, ExprCaptures), |
| 8624 | buildPostUpdate(*this, ExprPostUpdates)); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8625 | } |
| 8626 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 8627 | static bool |
| 8628 | FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV, |
| 8629 | Expr *NumIterations, Sema &SemaRef, Scope *S) { |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8630 | // Walk the vars and build update/final expressions for the CodeGen. |
| 8631 | SmallVector<Expr *, 8> Updates; |
| 8632 | SmallVector<Expr *, 8> Finals; |
| 8633 | Expr *Step = Clause.getStep(); |
| 8634 | Expr *CalcStep = Clause.getCalcStep(); |
| 8635 | // OpenMP [2.14.3.7, linear clause] |
| 8636 | // If linear-step is not specified it is assumed to be 1. |
| 8637 | if (Step == nullptr) |
| 8638 | Step = SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get(); |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 8639 | else if (CalcStep) { |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8640 | Step = cast<BinaryOperator>(CalcStep)->getLHS(); |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 8641 | } |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8642 | bool HasErrors = false; |
| 8643 | auto CurInit = Clause.inits().begin(); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8644 | auto CurPrivate = Clause.privates().begin(); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 8645 | auto LinKind = Clause.getModifier(); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8646 | for (auto &RefExpr : Clause.varlists()) { |
| 8647 | Expr *InitExpr = *CurInit; |
| 8648 | |
| 8649 | // Build privatized reference to the current linear var. |
| 8650 | auto DE = cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 8651 | Expr *CapturedRef; |
| 8652 | if (LinKind == OMPC_LINEAR_uval) |
| 8653 | CapturedRef = cast<VarDecl>(DE->getDecl())->getInit(); |
| 8654 | else |
| 8655 | CapturedRef = |
| 8656 | buildDeclRefExpr(SemaRef, cast<VarDecl>(DE->getDecl()), |
| 8657 | DE->getType().getUnqualifiedType(), DE->getExprLoc(), |
| 8658 | /*RefersToCapture=*/true); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8659 | |
| 8660 | // Build update: Var = InitExpr + IV * Step |
| 8661 | ExprResult Update = |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8662 | BuildCounterUpdate(SemaRef, S, RefExpr->getExprLoc(), *CurPrivate, |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8663 | InitExpr, IV, Step, /* Subtract */ false); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 8664 | Update = SemaRef.ActOnFinishFullExpr(Update.get(), DE->getLocStart(), |
| 8665 | /*DiscardedValue=*/true); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8666 | |
| 8667 | // Build final: Var = InitExpr + NumIterations * Step |
| 8668 | ExprResult Final = |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8669 | BuildCounterUpdate(SemaRef, S, RefExpr->getExprLoc(), CapturedRef, |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 8670 | InitExpr, NumIterations, Step, /* Subtract */ false); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 8671 | Final = SemaRef.ActOnFinishFullExpr(Final.get(), DE->getLocStart(), |
| 8672 | /*DiscardedValue=*/true); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8673 | if (!Update.isUsable() || !Final.isUsable()) { |
| 8674 | Updates.push_back(nullptr); |
| 8675 | Finals.push_back(nullptr); |
| 8676 | HasErrors = true; |
| 8677 | } else { |
| 8678 | Updates.push_back(Update.get()); |
| 8679 | Finals.push_back(Final.get()); |
| 8680 | } |
Richard Trieu | cc3949d | 2016-02-18 22:34:54 +0000 | [diff] [blame] | 8681 | ++CurInit; |
| 8682 | ++CurPrivate; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8683 | } |
| 8684 | Clause.setUpdates(Updates); |
| 8685 | Clause.setFinals(Finals); |
| 8686 | return HasErrors; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8687 | } |
| 8688 | |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 8689 | OMPClause *Sema::ActOnOpenMPAlignedClause( |
| 8690 | ArrayRef<Expr *> VarList, Expr *Alignment, SourceLocation StartLoc, |
| 8691 | SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc) { |
| 8692 | |
| 8693 | SmallVector<Expr *, 8> Vars; |
| 8694 | for (auto &RefExpr : VarList) { |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 8695 | assert(RefExpr && "NULL expr in OpenMP linear clause."); |
| 8696 | SourceLocation ELoc; |
| 8697 | SourceRange ERange; |
| 8698 | Expr *SimpleRefExpr = RefExpr; |
| 8699 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange, |
| 8700 | /*AllowArraySection=*/false); |
| 8701 | if (Res.second) { |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 8702 | // It will be analyzed later. |
| 8703 | Vars.push_back(RefExpr); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 8704 | } |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 8705 | ValueDecl *D = Res.first; |
| 8706 | if (!D) |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 8707 | continue; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 8708 | |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 8709 | QualType QType = D->getType(); |
| 8710 | auto *VD = dyn_cast<VarDecl>(D); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 8711 | |
| 8712 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 8713 | // The type of list items appearing in the aligned clause must be |
| 8714 | // array, pointer, reference to array, or reference to pointer. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8715 | QType = QType.getNonReferenceType().getUnqualifiedType().getCanonicalType(); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 8716 | const Type *Ty = QType.getTypePtrOrNull(); |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 8717 | if (!Ty || (!Ty->isArrayType() && !Ty->isPointerType())) { |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 8718 | Diag(ELoc, diag::err_omp_aligned_expected_array_or_ptr) |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 8719 | << QType << getLangOpts().CPlusPlus << ERange; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 8720 | bool IsDecl = |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 8721 | !VD || |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 8722 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 8723 | Diag(D->getLocation(), |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 8724 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 8725 | << D; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 8726 | continue; |
| 8727 | } |
| 8728 | |
| 8729 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 8730 | // A list-item cannot appear in more than one aligned clause. |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 8731 | if (Expr *PrevRef = DSAStack->addUniqueAligned(D, SimpleRefExpr)) { |
| 8732 | Diag(ELoc, diag::err_omp_aligned_twice) << ERange; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 8733 | Diag(PrevRef->getExprLoc(), diag::note_omp_explicit_dsa) |
| 8734 | << getOpenMPClauseName(OMPC_aligned); |
| 8735 | continue; |
| 8736 | } |
| 8737 | |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 8738 | DeclRefExpr *Ref = nullptr; |
| 8739 | if (!VD && IsOpenMPCapturedDecl(D)) |
| 8740 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/true); |
| 8741 | Vars.push_back(DefaultFunctionArrayConversion( |
| 8742 | (VD || !Ref) ? RefExpr->IgnoreParens() : Ref) |
| 8743 | .get()); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 8744 | } |
| 8745 | |
| 8746 | // OpenMP [2.8.1, simd construct, Description] |
| 8747 | // The parameter of the aligned clause, alignment, must be a constant |
| 8748 | // positive integer expression. |
| 8749 | // If no optional parameter is specified, implementation-defined default |
| 8750 | // alignments for SIMD instructions on the target platforms are assumed. |
| 8751 | if (Alignment != nullptr) { |
| 8752 | ExprResult AlignResult = |
| 8753 | VerifyPositiveIntegerConstantInClause(Alignment, OMPC_aligned); |
| 8754 | if (AlignResult.isInvalid()) |
| 8755 | return nullptr; |
| 8756 | Alignment = AlignResult.get(); |
| 8757 | } |
| 8758 | if (Vars.empty()) |
| 8759 | return nullptr; |
| 8760 | |
| 8761 | return OMPAlignedClause::Create(Context, StartLoc, LParenLoc, ColonLoc, |
| 8762 | EndLoc, Vars, Alignment); |
| 8763 | } |
| 8764 | |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8765 | OMPClause *Sema::ActOnOpenMPCopyinClause(ArrayRef<Expr *> VarList, |
| 8766 | SourceLocation StartLoc, |
| 8767 | SourceLocation LParenLoc, |
| 8768 | SourceLocation EndLoc) { |
| 8769 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 8770 | SmallVector<Expr *, 8> SrcExprs; |
| 8771 | SmallVector<Expr *, 8> DstExprs; |
| 8772 | SmallVector<Expr *, 8> AssignmentOps; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8773 | for (auto &RefExpr : VarList) { |
| 8774 | assert(RefExpr && "NULL expr in OpenMP copyin clause."); |
| 8775 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8776 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8777 | Vars.push_back(RefExpr); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 8778 | SrcExprs.push_back(nullptr); |
| 8779 | DstExprs.push_back(nullptr); |
| 8780 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8781 | continue; |
| 8782 | } |
| 8783 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8784 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8785 | // OpenMP [2.1, C/C++] |
| 8786 | // A list item is a variable name. |
| 8787 | // OpenMP [2.14.4.1, Restrictions, p.1] |
| 8788 | // A list item that appears in a copyin clause must be threadprivate. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8789 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8790 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8791 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr) |
| 8792 | << 0 << RefExpr->getSourceRange(); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8793 | continue; |
| 8794 | } |
| 8795 | |
| 8796 | Decl *D = DE->getDecl(); |
| 8797 | VarDecl *VD = cast<VarDecl>(D); |
| 8798 | |
| 8799 | QualType Type = VD->getType(); |
| 8800 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 8801 | // It will be analyzed later. |
| 8802 | Vars.push_back(DE); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 8803 | SrcExprs.push_back(nullptr); |
| 8804 | DstExprs.push_back(nullptr); |
| 8805 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8806 | continue; |
| 8807 | } |
| 8808 | |
| 8809 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.1] |
| 8810 | // A list item that appears in a copyin clause must be threadprivate. |
| 8811 | if (!DSAStack->isThreadPrivate(VD)) { |
| 8812 | Diag(ELoc, diag::err_omp_required_access) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8813 | << getOpenMPClauseName(OMPC_copyin) |
| 8814 | << getOpenMPDirectiveName(OMPD_threadprivate); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8815 | continue; |
| 8816 | } |
| 8817 | |
| 8818 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.2] |
| 8819 | // A variable of class type (or array thereof) that appears in a |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 8820 | // copyin clause requires an accessible, unambiguous copy assignment |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8821 | // operator for the class type. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8822 | auto ElemType = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 8823 | auto *SrcVD = |
| 8824 | buildVarDecl(*this, DE->getLocStart(), ElemType.getUnqualifiedType(), |
| 8825 | ".copyin.src", VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 8826 | auto *PseudoSrcExpr = buildDeclRefExpr( |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8827 | *this, SrcVD, ElemType.getUnqualifiedType(), DE->getExprLoc()); |
| 8828 | auto *DstVD = |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 8829 | buildVarDecl(*this, DE->getLocStart(), ElemType, ".copyin.dst", |
| 8830 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 8831 | auto *PseudoDstExpr = |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8832 | buildDeclRefExpr(*this, DstVD, ElemType, DE->getExprLoc()); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 8833 | // For arrays generate assignment operation for single element and replace |
| 8834 | // it by the original array element in CodeGen. |
| 8835 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, DE->getExprLoc(), BO_Assign, |
| 8836 | PseudoDstExpr, PseudoSrcExpr); |
| 8837 | if (AssignmentOp.isInvalid()) |
| 8838 | continue; |
| 8839 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), DE->getExprLoc(), |
| 8840 | /*DiscardedValue=*/true); |
| 8841 | if (AssignmentOp.isInvalid()) |
| 8842 | continue; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8843 | |
| 8844 | DSAStack->addDSA(VD, DE, OMPC_copyin); |
| 8845 | Vars.push_back(DE); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 8846 | SrcExprs.push_back(PseudoSrcExpr); |
| 8847 | DstExprs.push_back(PseudoDstExpr); |
| 8848 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8849 | } |
| 8850 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8851 | if (Vars.empty()) |
| 8852 | return nullptr; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8853 | |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 8854 | return OMPCopyinClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
| 8855 | SrcExprs, DstExprs, AssignmentOps); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8856 | } |
| 8857 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8858 | OMPClause *Sema::ActOnOpenMPCopyprivateClause(ArrayRef<Expr *> VarList, |
| 8859 | SourceLocation StartLoc, |
| 8860 | SourceLocation LParenLoc, |
| 8861 | SourceLocation EndLoc) { |
| 8862 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 8863 | SmallVector<Expr *, 8> SrcExprs; |
| 8864 | SmallVector<Expr *, 8> DstExprs; |
| 8865 | SmallVector<Expr *, 8> AssignmentOps; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8866 | for (auto &RefExpr : VarList) { |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 8867 | assert(RefExpr && "NULL expr in OpenMP linear clause."); |
| 8868 | SourceLocation ELoc; |
| 8869 | SourceRange ERange; |
| 8870 | Expr *SimpleRefExpr = RefExpr; |
| 8871 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange, |
| 8872 | /*AllowArraySection=*/false); |
| 8873 | if (Res.second) { |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8874 | // It will be analyzed later. |
| 8875 | Vars.push_back(RefExpr); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 8876 | SrcExprs.push_back(nullptr); |
| 8877 | DstExprs.push_back(nullptr); |
| 8878 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8879 | } |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 8880 | ValueDecl *D = Res.first; |
| 8881 | if (!D) |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8882 | continue; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8883 | |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 8884 | QualType Type = D->getType(); |
| 8885 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8886 | |
| 8887 | // OpenMP [2.14.4.2, Restrictions, p.2] |
| 8888 | // A list item that appears in a copyprivate clause may not appear in a |
| 8889 | // private or firstprivate clause on the single construct. |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 8890 | if (!VD || !DSAStack->isThreadPrivate(VD)) { |
| 8891 | auto DVar = DSAStack->getTopDSA(D, false); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 8892 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_copyprivate && |
| 8893 | DVar.RefExpr) { |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8894 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 8895 | << getOpenMPClauseName(DVar.CKind) |
| 8896 | << getOpenMPClauseName(OMPC_copyprivate); |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 8897 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8898 | continue; |
| 8899 | } |
| 8900 | |
| 8901 | // OpenMP [2.11.4.2, Restrictions, p.1] |
| 8902 | // All list items that appear in a copyprivate clause must be either |
| 8903 | // threadprivate or private in the enclosing context. |
| 8904 | if (DVar.CKind == OMPC_unknown) { |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 8905 | DVar = DSAStack->getImplicitDSA(D, false); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8906 | if (DVar.CKind == OMPC_shared) { |
| 8907 | Diag(ELoc, diag::err_omp_required_access) |
| 8908 | << getOpenMPClauseName(OMPC_copyprivate) |
| 8909 | << "threadprivate or private in the enclosing context"; |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 8910 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8911 | continue; |
| 8912 | } |
| 8913 | } |
| 8914 | } |
| 8915 | |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 8916 | // Variably modified types are not supported. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 8917 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType()) { |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 8918 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8919 | << getOpenMPClauseName(OMPC_copyprivate) << Type |
| 8920 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 8921 | bool IsDecl = |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 8922 | !VD || |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 8923 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 8924 | Diag(D->getLocation(), |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 8925 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 8926 | << D; |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 8927 | continue; |
| 8928 | } |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8929 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8930 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.2] |
| 8931 | // A variable of class type (or array thereof) that appears in a |
| 8932 | // copyin clause requires an accessible, unambiguous copy assignment |
| 8933 | // operator for the class type. |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8934 | Type = Context.getBaseElementType(Type.getNonReferenceType()) |
| 8935 | .getUnqualifiedType(); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 8936 | auto *SrcVD = |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 8937 | buildVarDecl(*this, RefExpr->getLocStart(), Type, ".copyprivate.src", |
| 8938 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 8939 | auto *PseudoSrcExpr = buildDeclRefExpr(*this, SrcVD, Type, ELoc); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 8940 | auto *DstVD = |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 8941 | buildVarDecl(*this, RefExpr->getLocStart(), Type, ".copyprivate.dst", |
| 8942 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 8943 | auto *PseudoDstExpr = |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 8944 | buildDeclRefExpr(*this, DstVD, Type, ELoc); |
| 8945 | auto AssignmentOp = BuildBinOp(DSAStack->getCurScope(), ELoc, BO_Assign, |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 8946 | PseudoDstExpr, PseudoSrcExpr); |
| 8947 | if (AssignmentOp.isInvalid()) |
| 8948 | continue; |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 8949 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), ELoc, |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 8950 | /*DiscardedValue=*/true); |
| 8951 | if (AssignmentOp.isInvalid()) |
| 8952 | continue; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8953 | |
| 8954 | // No need to mark vars as copyprivate, they are already threadprivate or |
| 8955 | // implicitly private. |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 8956 | assert(VD || IsOpenMPCapturedDecl(D)); |
| 8957 | Vars.push_back( |
| 8958 | VD ? RefExpr->IgnoreParens() |
| 8959 | : buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false)); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 8960 | SrcExprs.push_back(PseudoSrcExpr); |
| 8961 | DstExprs.push_back(PseudoDstExpr); |
| 8962 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8963 | } |
| 8964 | |
| 8965 | if (Vars.empty()) |
| 8966 | return nullptr; |
| 8967 | |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 8968 | return OMPCopyprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| 8969 | Vars, SrcExprs, DstExprs, AssignmentOps); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8970 | } |
| 8971 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 8972 | OMPClause *Sema::ActOnOpenMPFlushClause(ArrayRef<Expr *> VarList, |
| 8973 | SourceLocation StartLoc, |
| 8974 | SourceLocation LParenLoc, |
| 8975 | SourceLocation EndLoc) { |
| 8976 | if (VarList.empty()) |
| 8977 | return nullptr; |
| 8978 | |
| 8979 | return OMPFlushClause::Create(Context, StartLoc, LParenLoc, EndLoc, VarList); |
| 8980 | } |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 8981 | |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8982 | OMPClause * |
| 8983 | Sema::ActOnOpenMPDependClause(OpenMPDependClauseKind DepKind, |
| 8984 | SourceLocation DepLoc, SourceLocation ColonLoc, |
| 8985 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
| 8986 | SourceLocation LParenLoc, SourceLocation EndLoc) { |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 8987 | if (DSAStack->getCurrentDirective() == OMPD_ordered && |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 8988 | DepKind != OMPC_DEPEND_source && DepKind != OMPC_DEPEND_sink) { |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 8989 | Diag(DepLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 8990 | << "'source' or 'sink'" << getOpenMPClauseName(OMPC_depend); |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 8991 | return nullptr; |
| 8992 | } |
| 8993 | if (DSAStack->getCurrentDirective() != OMPD_ordered && |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 8994 | (DepKind == OMPC_DEPEND_unknown || DepKind == OMPC_DEPEND_source || |
| 8995 | DepKind == OMPC_DEPEND_sink)) { |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 8996 | unsigned Except[] = {OMPC_DEPEND_source, OMPC_DEPEND_sink}; |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8997 | Diag(DepLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 8998 | << getListOfPossibleValues(OMPC_depend, /*First=*/0, |
| 8999 | /*Last=*/OMPC_DEPEND_unknown, Except) |
| 9000 | << getOpenMPClauseName(OMPC_depend); |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 9001 | return nullptr; |
| 9002 | } |
| 9003 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 9004 | llvm::APSInt DepCounter(/*BitWidth=*/32); |
| 9005 | llvm::APSInt TotalDepCount(/*BitWidth=*/32); |
| 9006 | if (DepKind == OMPC_DEPEND_sink) { |
| 9007 | if (auto *OrderedCountExpr = DSAStack->getParentOrderedRegionParam()) { |
| 9008 | TotalDepCount = OrderedCountExpr->EvaluateKnownConstInt(Context); |
| 9009 | TotalDepCount.setIsUnsigned(/*Val=*/true); |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 9010 | } |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 9011 | } |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 9012 | if ((DepKind != OMPC_DEPEND_sink && DepKind != OMPC_DEPEND_source) || |
| 9013 | DSAStack->getParentOrderedRegionParam()) { |
| 9014 | for (auto &RefExpr : VarList) { |
| 9015 | assert(RefExpr && "NULL expr in OpenMP shared clause."); |
| 9016 | if (isa<DependentScopeDeclRefExpr>(RefExpr) || |
| 9017 | (DepKind == OMPC_DEPEND_sink && CurContext->isDependentContext())) { |
| 9018 | // It will be analyzed later. |
| 9019 | Vars.push_back(RefExpr); |
| 9020 | continue; |
| 9021 | } |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 9022 | |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 9023 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 9024 | auto *SimpleExpr = RefExpr->IgnoreParenCasts(); |
| 9025 | if (DepKind == OMPC_DEPEND_sink) { |
| 9026 | if (DepCounter >= TotalDepCount) { |
| 9027 | Diag(ELoc, diag::err_omp_depend_sink_unexpected_expr); |
| 9028 | continue; |
| 9029 | } |
| 9030 | ++DepCounter; |
| 9031 | // OpenMP [2.13.9, Summary] |
| 9032 | // depend(dependence-type : vec), where dependence-type is: |
| 9033 | // 'sink' and where vec is the iteration vector, which has the form: |
| 9034 | // x1 [+- d1], x2 [+- d2 ], . . . , xn [+- dn] |
| 9035 | // where n is the value specified by the ordered clause in the loop |
| 9036 | // directive, xi denotes the loop iteration variable of the i-th nested |
| 9037 | // loop associated with the loop directive, and di is a constant |
| 9038 | // non-negative integer. |
| 9039 | SimpleExpr = SimpleExpr->IgnoreImplicit(); |
| 9040 | auto *DE = dyn_cast<DeclRefExpr>(SimpleExpr); |
| 9041 | if (!DE) { |
| 9042 | OverloadedOperatorKind OOK = OO_None; |
| 9043 | SourceLocation OOLoc; |
| 9044 | Expr *LHS, *RHS; |
| 9045 | if (auto *BO = dyn_cast<BinaryOperator>(SimpleExpr)) { |
| 9046 | OOK = BinaryOperator::getOverloadedOperator(BO->getOpcode()); |
| 9047 | OOLoc = BO->getOperatorLoc(); |
| 9048 | LHS = BO->getLHS()->IgnoreParenImpCasts(); |
| 9049 | RHS = BO->getRHS()->IgnoreParenImpCasts(); |
| 9050 | } else if (auto *OCE = dyn_cast<CXXOperatorCallExpr>(SimpleExpr)) { |
| 9051 | OOK = OCE->getOperator(); |
| 9052 | OOLoc = OCE->getOperatorLoc(); |
| 9053 | LHS = OCE->getArg(/*Arg=*/0)->IgnoreParenImpCasts(); |
| 9054 | RHS = OCE->getArg(/*Arg=*/1)->IgnoreParenImpCasts(); |
| 9055 | } else if (auto *MCE = dyn_cast<CXXMemberCallExpr>(SimpleExpr)) { |
| 9056 | OOK = MCE->getMethodDecl() |
| 9057 | ->getNameInfo() |
| 9058 | .getName() |
| 9059 | .getCXXOverloadedOperator(); |
| 9060 | OOLoc = MCE->getCallee()->getExprLoc(); |
| 9061 | LHS = MCE->getImplicitObjectArgument()->IgnoreParenImpCasts(); |
| 9062 | RHS = MCE->getArg(/*Arg=*/0)->IgnoreParenImpCasts(); |
| 9063 | } else { |
| 9064 | Diag(ELoc, diag::err_omp_depend_sink_wrong_expr); |
| 9065 | continue; |
| 9066 | } |
| 9067 | DE = dyn_cast<DeclRefExpr>(LHS); |
| 9068 | if (!DE) { |
| 9069 | Diag(LHS->getExprLoc(), |
| 9070 | diag::err_omp_depend_sink_expected_loop_iteration) |
| 9071 | << DSAStack->getParentLoopControlVariable( |
| 9072 | DepCounter.getZExtValue()); |
| 9073 | continue; |
| 9074 | } |
| 9075 | if (OOK != OO_Plus && OOK != OO_Minus) { |
| 9076 | Diag(OOLoc, diag::err_omp_depend_sink_expected_plus_minus); |
| 9077 | continue; |
| 9078 | } |
| 9079 | ExprResult Res = VerifyPositiveIntegerConstantInClause( |
| 9080 | RHS, OMPC_depend, /*StrictlyPositive=*/false); |
| 9081 | if (Res.isInvalid()) |
| 9082 | continue; |
| 9083 | } |
| 9084 | auto *VD = dyn_cast<VarDecl>(DE->getDecl()); |
| 9085 | if (!CurContext->isDependentContext() && |
| 9086 | DSAStack->getParentOrderedRegionParam() && |
| 9087 | (!VD || DepCounter != DSAStack->isParentLoopControlVariable(VD))) { |
| 9088 | Diag(DE->getExprLoc(), |
| 9089 | diag::err_omp_depend_sink_expected_loop_iteration) |
| 9090 | << DSAStack->getParentLoopControlVariable( |
| 9091 | DepCounter.getZExtValue()); |
| 9092 | continue; |
| 9093 | } |
| 9094 | } else { |
| 9095 | // OpenMP [2.11.1.1, Restrictions, p.3] |
| 9096 | // A variable that is part of another variable (such as a field of a |
| 9097 | // structure) but is not an array element or an array section cannot |
| 9098 | // appear in a depend clause. |
| 9099 | auto *DE = dyn_cast<DeclRefExpr>(SimpleExpr); |
| 9100 | auto *ASE = dyn_cast<ArraySubscriptExpr>(SimpleExpr); |
| 9101 | auto *OASE = dyn_cast<OMPArraySectionExpr>(SimpleExpr); |
| 9102 | if (!RefExpr->IgnoreParenImpCasts()->isLValue() || |
| 9103 | (!ASE && !DE && !OASE) || (DE && !isa<VarDecl>(DE->getDecl())) || |
Alexey Bataev | 31300ed | 2016-02-04 11:27:03 +0000 | [diff] [blame] | 9104 | (ASE && |
| 9105 | !ASE->getBase() |
| 9106 | ->getType() |
| 9107 | .getNonReferenceType() |
| 9108 | ->isPointerType() && |
| 9109 | !ASE->getBase()->getType().getNonReferenceType()->isArrayType())) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 9110 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr_or_array_item) |
| 9111 | << 0 << RefExpr->getSourceRange(); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 9112 | continue; |
| 9113 | } |
| 9114 | } |
| 9115 | |
| 9116 | Vars.push_back(RefExpr->IgnoreParenImpCasts()); |
| 9117 | } |
| 9118 | |
| 9119 | if (!CurContext->isDependentContext() && DepKind == OMPC_DEPEND_sink && |
| 9120 | TotalDepCount > VarList.size() && |
| 9121 | DSAStack->getParentOrderedRegionParam()) { |
| 9122 | Diag(EndLoc, diag::err_omp_depend_sink_expected_loop_iteration) |
| 9123 | << DSAStack->getParentLoopControlVariable(VarList.size() + 1); |
| 9124 | } |
| 9125 | if (DepKind != OMPC_DEPEND_source && DepKind != OMPC_DEPEND_sink && |
| 9126 | Vars.empty()) |
| 9127 | return nullptr; |
| 9128 | } |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 9129 | |
| 9130 | return OMPDependClause::Create(Context, StartLoc, LParenLoc, EndLoc, DepKind, |
| 9131 | DepLoc, ColonLoc, Vars); |
| 9132 | } |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 9133 | |
| 9134 | OMPClause *Sema::ActOnOpenMPDeviceClause(Expr *Device, SourceLocation StartLoc, |
| 9135 | SourceLocation LParenLoc, |
| 9136 | SourceLocation EndLoc) { |
| 9137 | Expr *ValExpr = Device; |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 9138 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 9139 | // OpenMP [2.9.1, Restrictions] |
| 9140 | // The device expression must evaluate to a non-negative integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 9141 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_device, |
| 9142 | /*StrictlyPositive=*/false)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 9143 | return nullptr; |
| 9144 | |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 9145 | return new (Context) OMPDeviceClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 9146 | } |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9147 | |
| 9148 | static bool IsCXXRecordForMappable(Sema &SemaRef, SourceLocation Loc, |
| 9149 | DSAStackTy *Stack, CXXRecordDecl *RD) { |
| 9150 | if (!RD || RD->isInvalidDecl()) |
| 9151 | return true; |
| 9152 | |
Alexey Bataev | c9bd03d | 2015-12-17 06:55:08 +0000 | [diff] [blame] | 9153 | if (auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(RD)) |
| 9154 | if (auto *CTD = CTSD->getSpecializedTemplate()) |
| 9155 | RD = CTD->getTemplatedDecl(); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9156 | auto QTy = SemaRef.Context.getRecordType(RD); |
| 9157 | if (RD->isDynamicClass()) { |
| 9158 | SemaRef.Diag(Loc, diag::err_omp_not_mappable_type) << QTy; |
| 9159 | SemaRef.Diag(RD->getLocation(), diag::note_omp_polymorphic_in_target); |
| 9160 | return false; |
| 9161 | } |
| 9162 | auto *DC = RD; |
| 9163 | bool IsCorrect = true; |
| 9164 | for (auto *I : DC->decls()) { |
| 9165 | if (I) { |
| 9166 | if (auto *MD = dyn_cast<CXXMethodDecl>(I)) { |
| 9167 | if (MD->isStatic()) { |
| 9168 | SemaRef.Diag(Loc, diag::err_omp_not_mappable_type) << QTy; |
| 9169 | SemaRef.Diag(MD->getLocation(), |
| 9170 | diag::note_omp_static_member_in_target); |
| 9171 | IsCorrect = false; |
| 9172 | } |
| 9173 | } else if (auto *VD = dyn_cast<VarDecl>(I)) { |
| 9174 | if (VD->isStaticDataMember()) { |
| 9175 | SemaRef.Diag(Loc, diag::err_omp_not_mappable_type) << QTy; |
| 9176 | SemaRef.Diag(VD->getLocation(), |
| 9177 | diag::note_omp_static_member_in_target); |
| 9178 | IsCorrect = false; |
| 9179 | } |
| 9180 | } |
| 9181 | } |
| 9182 | } |
| 9183 | |
| 9184 | for (auto &I : RD->bases()) { |
| 9185 | if (!IsCXXRecordForMappable(SemaRef, I.getLocStart(), Stack, |
| 9186 | I.getType()->getAsCXXRecordDecl())) |
| 9187 | IsCorrect = false; |
| 9188 | } |
| 9189 | return IsCorrect; |
| 9190 | } |
| 9191 | |
| 9192 | static bool CheckTypeMappable(SourceLocation SL, SourceRange SR, Sema &SemaRef, |
| 9193 | DSAStackTy *Stack, QualType QTy) { |
| 9194 | NamedDecl *ND; |
| 9195 | if (QTy->isIncompleteType(&ND)) { |
| 9196 | SemaRef.Diag(SL, diag::err_incomplete_type) << QTy << SR; |
| 9197 | return false; |
| 9198 | } else if (CXXRecordDecl *RD = dyn_cast_or_null<CXXRecordDecl>(ND)) { |
| 9199 | if (!RD->isInvalidDecl() && |
| 9200 | !IsCXXRecordForMappable(SemaRef, SL, Stack, RD)) |
| 9201 | return false; |
| 9202 | } |
| 9203 | return true; |
| 9204 | } |
| 9205 | |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 9206 | /// \brief Return true if it can be proven that the provided array expression |
| 9207 | /// (array section or array subscript) does NOT specify the whole size of the |
| 9208 | /// array whose base type is \a BaseQTy. |
| 9209 | static bool CheckArrayExpressionDoesNotReferToWholeSize(Sema &SemaRef, |
| 9210 | const Expr *E, |
| 9211 | QualType BaseQTy) { |
| 9212 | auto *OASE = dyn_cast<OMPArraySectionExpr>(E); |
| 9213 | |
| 9214 | // If this is an array subscript, it refers to the whole size if the size of |
| 9215 | // the dimension is constant and equals 1. Also, an array section assumes the |
| 9216 | // format of an array subscript if no colon is used. |
| 9217 | if (isa<ArraySubscriptExpr>(E) || (OASE && OASE->getColonLoc().isInvalid())) { |
| 9218 | if (auto *ATy = dyn_cast<ConstantArrayType>(BaseQTy.getTypePtr())) |
| 9219 | return ATy->getSize().getSExtValue() != 1; |
| 9220 | // Size can't be evaluated statically. |
| 9221 | return false; |
| 9222 | } |
| 9223 | |
| 9224 | assert(OASE && "Expecting array section if not an array subscript."); |
| 9225 | auto *LowerBound = OASE->getLowerBound(); |
| 9226 | auto *Length = OASE->getLength(); |
| 9227 | |
| 9228 | // If there is a lower bound that does not evaluates to zero, we are not |
| 9229 | // convering the whole dimension. |
| 9230 | if (LowerBound) { |
| 9231 | llvm::APSInt ConstLowerBound; |
| 9232 | if (!LowerBound->EvaluateAsInt(ConstLowerBound, SemaRef.getASTContext())) |
| 9233 | return false; // Can't get the integer value as a constant. |
| 9234 | if (ConstLowerBound.getSExtValue()) |
| 9235 | return true; |
| 9236 | } |
| 9237 | |
| 9238 | // If we don't have a length we covering the whole dimension. |
| 9239 | if (!Length) |
| 9240 | return false; |
| 9241 | |
| 9242 | // If the base is a pointer, we don't have a way to get the size of the |
| 9243 | // pointee. |
| 9244 | if (BaseQTy->isPointerType()) |
| 9245 | return false; |
| 9246 | |
| 9247 | // We can only check if the length is the same as the size of the dimension |
| 9248 | // if we have a constant array. |
| 9249 | auto *CATy = dyn_cast<ConstantArrayType>(BaseQTy.getTypePtr()); |
| 9250 | if (!CATy) |
| 9251 | return false; |
| 9252 | |
| 9253 | llvm::APSInt ConstLength; |
| 9254 | if (!Length->EvaluateAsInt(ConstLength, SemaRef.getASTContext())) |
| 9255 | return false; // Can't get the integer value as a constant. |
| 9256 | |
| 9257 | return CATy->getSize().getSExtValue() != ConstLength.getSExtValue(); |
| 9258 | } |
| 9259 | |
| 9260 | // Return true if it can be proven that the provided array expression (array |
| 9261 | // section or array subscript) does NOT specify a single element of the array |
| 9262 | // whose base type is \a BaseQTy. |
| 9263 | static bool CheckArrayExpressionDoesNotReferToUnitySize(Sema &SemaRef, |
| 9264 | const Expr *E, |
| 9265 | QualType BaseQTy) { |
| 9266 | auto *OASE = dyn_cast<OMPArraySectionExpr>(E); |
| 9267 | |
| 9268 | // An array subscript always refer to a single element. Also, an array section |
| 9269 | // assumes the format of an array subscript if no colon is used. |
| 9270 | if (isa<ArraySubscriptExpr>(E) || (OASE && OASE->getColonLoc().isInvalid())) |
| 9271 | return false; |
| 9272 | |
| 9273 | assert(OASE && "Expecting array section if not an array subscript."); |
| 9274 | auto *Length = OASE->getLength(); |
| 9275 | |
| 9276 | // If we don't have a length we have to check if the array has unitary size |
| 9277 | // for this dimension. Also, we should always expect a length if the base type |
| 9278 | // is pointer. |
| 9279 | if (!Length) { |
| 9280 | if (auto *ATy = dyn_cast<ConstantArrayType>(BaseQTy.getTypePtr())) |
| 9281 | return ATy->getSize().getSExtValue() != 1; |
| 9282 | // We cannot assume anything. |
| 9283 | return false; |
| 9284 | } |
| 9285 | |
| 9286 | // Check if the length evaluates to 1. |
| 9287 | llvm::APSInt ConstLength; |
| 9288 | if (!Length->EvaluateAsInt(ConstLength, SemaRef.getASTContext())) |
| 9289 | return false; // Can't get the integer value as a constant. |
| 9290 | |
| 9291 | return ConstLength.getSExtValue() != 1; |
| 9292 | } |
| 9293 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9294 | // Return the expression of the base of the map clause or null if it cannot |
| 9295 | // be determined and do all the necessary checks to see if the expression is |
| 9296 | // valid as a standalone map clause expression. |
| 9297 | static Expr *CheckMapClauseExpressionBase(Sema &SemaRef, Expr *E) { |
| 9298 | SourceLocation ELoc = E->getExprLoc(); |
| 9299 | SourceRange ERange = E->getSourceRange(); |
| 9300 | |
| 9301 | // The base of elements of list in a map clause have to be either: |
| 9302 | // - a reference to variable or field. |
| 9303 | // - a member expression. |
| 9304 | // - an array expression. |
| 9305 | // |
| 9306 | // E.g. if we have the expression 'r.S.Arr[:12]', we want to retrieve the |
| 9307 | // reference to 'r'. |
| 9308 | // |
| 9309 | // If we have: |
| 9310 | // |
| 9311 | // struct SS { |
| 9312 | // Bla S; |
| 9313 | // foo() { |
| 9314 | // #pragma omp target map (S.Arr[:12]); |
| 9315 | // } |
| 9316 | // } |
| 9317 | // |
| 9318 | // We want to retrieve the member expression 'this->S'; |
| 9319 | |
| 9320 | Expr *RelevantExpr = nullptr; |
| 9321 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9322 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.2] |
| 9323 | // If a list item is an array section, it must specify contiguous storage. |
| 9324 | // |
| 9325 | // For this restriction it is sufficient that we make sure only references |
| 9326 | // to variables or fields and array expressions, and that no array sections |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 9327 | // exist except in the rightmost expression (unless they cover the whole |
| 9328 | // dimension of the array). E.g. these would be invalid: |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9329 | // |
| 9330 | // r.ArrS[3:5].Arr[6:7] |
| 9331 | // |
| 9332 | // r.ArrS[3:5].x |
| 9333 | // |
| 9334 | // but these would be valid: |
| 9335 | // r.ArrS[3].Arr[6:7] |
| 9336 | // |
| 9337 | // r.ArrS[3].x |
| 9338 | |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 9339 | bool AllowUnitySizeArraySection = true; |
| 9340 | bool AllowWholeSizeArraySection = true; |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9341 | |
Dmitry Polukhin | 644a925 | 2016-03-11 07:58:34 +0000 | [diff] [blame] | 9342 | while (!RelevantExpr) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9343 | E = E->IgnoreParenImpCasts(); |
| 9344 | |
| 9345 | if (auto *CurE = dyn_cast<DeclRefExpr>(E)) { |
| 9346 | if (!isa<VarDecl>(CurE->getDecl())) |
| 9347 | break; |
| 9348 | |
| 9349 | RelevantExpr = CurE; |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 9350 | |
| 9351 | // If we got a reference to a declaration, we should not expect any array |
| 9352 | // section before that. |
| 9353 | AllowUnitySizeArraySection = false; |
| 9354 | AllowWholeSizeArraySection = false; |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9355 | continue; |
| 9356 | } |
| 9357 | |
| 9358 | if (auto *CurE = dyn_cast<MemberExpr>(E)) { |
| 9359 | auto *BaseE = CurE->getBase()->IgnoreParenImpCasts(); |
| 9360 | |
| 9361 | if (isa<CXXThisExpr>(BaseE)) |
| 9362 | // We found a base expression: this->Val. |
| 9363 | RelevantExpr = CurE; |
| 9364 | else |
| 9365 | E = BaseE; |
| 9366 | |
| 9367 | if (!isa<FieldDecl>(CurE->getMemberDecl())) { |
| 9368 | SemaRef.Diag(ELoc, diag::err_omp_expected_access_to_data_field) |
| 9369 | << CurE->getSourceRange(); |
| 9370 | break; |
| 9371 | } |
| 9372 | |
| 9373 | auto *FD = cast<FieldDecl>(CurE->getMemberDecl()); |
| 9374 | |
| 9375 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C/C++, p.3] |
| 9376 | // A bit-field cannot appear in a map clause. |
| 9377 | // |
| 9378 | if (FD->isBitField()) { |
| 9379 | SemaRef.Diag(ELoc, diag::err_omp_bit_fields_forbidden_in_map_clause) |
| 9380 | << CurE->getSourceRange(); |
| 9381 | break; |
| 9382 | } |
| 9383 | |
| 9384 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] |
| 9385 | // If the type of a list item is a reference to a type T then the type |
| 9386 | // will be considered to be T for all purposes of this clause. |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 9387 | QualType CurType = BaseE->getType().getNonReferenceType(); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9388 | |
| 9389 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C/C++, p.2] |
| 9390 | // A list item cannot be a variable that is a member of a structure with |
| 9391 | // a union type. |
| 9392 | // |
| 9393 | if (auto *RT = CurType->getAs<RecordType>()) |
| 9394 | if (RT->isUnionType()) { |
| 9395 | SemaRef.Diag(ELoc, diag::err_omp_union_type_not_allowed) |
| 9396 | << CurE->getSourceRange(); |
| 9397 | break; |
| 9398 | } |
| 9399 | |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 9400 | // If we got a member expression, we should not expect any array section |
| 9401 | // before that: |
| 9402 | // |
| 9403 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.7] |
| 9404 | // If a list item is an element of a structure, only the rightmost symbol |
| 9405 | // of the variable reference can be an array section. |
| 9406 | // |
| 9407 | AllowUnitySizeArraySection = false; |
| 9408 | AllowWholeSizeArraySection = false; |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9409 | continue; |
| 9410 | } |
| 9411 | |
| 9412 | if (auto *CurE = dyn_cast<ArraySubscriptExpr>(E)) { |
| 9413 | E = CurE->getBase()->IgnoreParenImpCasts(); |
| 9414 | |
| 9415 | if (!E->getType()->isAnyPointerType() && !E->getType()->isArrayType()) { |
| 9416 | SemaRef.Diag(ELoc, diag::err_omp_expected_base_var_name) |
| 9417 | << 0 << CurE->getSourceRange(); |
| 9418 | break; |
| 9419 | } |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 9420 | |
| 9421 | // If we got an array subscript that express the whole dimension we |
| 9422 | // can have any array expressions before. If it only expressing part of |
| 9423 | // the dimension, we can only have unitary-size array expressions. |
| 9424 | if (CheckArrayExpressionDoesNotReferToWholeSize(SemaRef, CurE, |
| 9425 | E->getType())) |
| 9426 | AllowWholeSizeArraySection = false; |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9427 | continue; |
| 9428 | } |
| 9429 | |
| 9430 | if (auto *CurE = dyn_cast<OMPArraySectionExpr>(E)) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9431 | E = CurE->getBase()->IgnoreParenImpCasts(); |
| 9432 | |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 9433 | auto CurType = |
| 9434 | OMPArraySectionExpr::getBaseOriginalType(E).getCanonicalType(); |
| 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 |
| 9438 | // will be considered to be T for all purposes of this clause. |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9439 | if (CurType->isReferenceType()) |
| 9440 | CurType = CurType->getPointeeType(); |
| 9441 | |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 9442 | bool IsPointer = CurType->isAnyPointerType(); |
| 9443 | |
| 9444 | if (!IsPointer && !CurType->isArrayType()) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9445 | SemaRef.Diag(ELoc, diag::err_omp_expected_base_var_name) |
| 9446 | << 0 << CurE->getSourceRange(); |
| 9447 | break; |
| 9448 | } |
| 9449 | |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 9450 | bool NotWhole = |
| 9451 | CheckArrayExpressionDoesNotReferToWholeSize(SemaRef, CurE, CurType); |
| 9452 | bool NotUnity = |
| 9453 | CheckArrayExpressionDoesNotReferToUnitySize(SemaRef, CurE, CurType); |
| 9454 | |
| 9455 | if (AllowWholeSizeArraySection && AllowUnitySizeArraySection) { |
| 9456 | // Any array section is currently allowed. |
| 9457 | // |
| 9458 | // If this array section refers to the whole dimension we can still |
| 9459 | // accept other array sections before this one, except if the base is a |
| 9460 | // pointer. Otherwise, only unitary sections are accepted. |
| 9461 | if (NotWhole || IsPointer) |
| 9462 | AllowWholeSizeArraySection = false; |
| 9463 | } else if ((AllowUnitySizeArraySection && NotUnity) || |
| 9464 | (AllowWholeSizeArraySection && NotWhole)) { |
| 9465 | // A unity or whole array section is not allowed and that is not |
| 9466 | // compatible with the properties of the current array section. |
| 9467 | SemaRef.Diag( |
| 9468 | ELoc, diag::err_array_section_does_not_specify_contiguous_storage) |
| 9469 | << CurE->getSourceRange(); |
| 9470 | break; |
| 9471 | } |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9472 | continue; |
| 9473 | } |
| 9474 | |
| 9475 | // If nothing else worked, this is not a valid map clause expression. |
| 9476 | SemaRef.Diag(ELoc, |
| 9477 | diag::err_omp_expected_named_var_member_or_array_expression) |
| 9478 | << ERange; |
| 9479 | break; |
| 9480 | } |
| 9481 | |
| 9482 | return RelevantExpr; |
| 9483 | } |
| 9484 | |
| 9485 | // Return true if expression E associated with value VD has conflicts with other |
| 9486 | // map information. |
| 9487 | static bool CheckMapConflicts(Sema &SemaRef, DSAStackTy *DSAS, ValueDecl *VD, |
| 9488 | Expr *E, bool CurrentRegionOnly) { |
| 9489 | assert(VD && E); |
| 9490 | |
| 9491 | // Types used to organize the components of a valid map clause. |
| 9492 | typedef std::pair<Expr *, ValueDecl *> MapExpressionComponent; |
| 9493 | typedef SmallVector<MapExpressionComponent, 4> MapExpressionComponents; |
| 9494 | |
| 9495 | // Helper to extract the components in the map clause expression E and store |
| 9496 | // them into MEC. This assumes that E is a valid map clause expression, i.e. |
| 9497 | // it has already passed the single clause checks. |
| 9498 | auto ExtractMapExpressionComponents = [](Expr *TE, |
| 9499 | MapExpressionComponents &MEC) { |
| 9500 | while (true) { |
| 9501 | TE = TE->IgnoreParenImpCasts(); |
| 9502 | |
| 9503 | if (auto *CurE = dyn_cast<DeclRefExpr>(TE)) { |
| 9504 | MEC.push_back( |
| 9505 | MapExpressionComponent(CurE, cast<VarDecl>(CurE->getDecl()))); |
| 9506 | break; |
| 9507 | } |
| 9508 | |
| 9509 | if (auto *CurE = dyn_cast<MemberExpr>(TE)) { |
| 9510 | auto *BaseE = CurE->getBase()->IgnoreParenImpCasts(); |
| 9511 | |
| 9512 | MEC.push_back(MapExpressionComponent( |
| 9513 | CurE, cast<FieldDecl>(CurE->getMemberDecl()))); |
| 9514 | if (isa<CXXThisExpr>(BaseE)) |
| 9515 | break; |
| 9516 | |
| 9517 | TE = BaseE; |
| 9518 | continue; |
| 9519 | } |
| 9520 | |
| 9521 | if (auto *CurE = dyn_cast<ArraySubscriptExpr>(TE)) { |
| 9522 | MEC.push_back(MapExpressionComponent(CurE, nullptr)); |
| 9523 | TE = CurE->getBase()->IgnoreParenImpCasts(); |
| 9524 | continue; |
| 9525 | } |
| 9526 | |
| 9527 | if (auto *CurE = dyn_cast<OMPArraySectionExpr>(TE)) { |
| 9528 | MEC.push_back(MapExpressionComponent(CurE, nullptr)); |
| 9529 | TE = CurE->getBase()->IgnoreParenImpCasts(); |
| 9530 | continue; |
| 9531 | } |
| 9532 | |
| 9533 | llvm_unreachable( |
| 9534 | "Expecting only valid map clause expressions at this point!"); |
| 9535 | } |
| 9536 | }; |
| 9537 | |
| 9538 | SourceLocation ELoc = E->getExprLoc(); |
| 9539 | SourceRange ERange = E->getSourceRange(); |
| 9540 | |
| 9541 | // In order to easily check the conflicts we need to match each component of |
| 9542 | // the expression under test with the components of the expressions that are |
| 9543 | // already in the stack. |
| 9544 | |
| 9545 | MapExpressionComponents CurComponents; |
| 9546 | ExtractMapExpressionComponents(E, CurComponents); |
| 9547 | |
| 9548 | assert(!CurComponents.empty() && "Map clause expression with no components!"); |
| 9549 | assert(CurComponents.back().second == VD && |
| 9550 | "Map clause expression with unexpected base!"); |
| 9551 | |
| 9552 | // Variables to help detecting enclosing problems in data environment nests. |
| 9553 | bool IsEnclosedByDataEnvironmentExpr = false; |
| 9554 | Expr *EnclosingExpr = nullptr; |
| 9555 | |
| 9556 | bool FoundError = |
| 9557 | DSAS->checkMapInfoForVar(VD, CurrentRegionOnly, [&](Expr *RE) -> bool { |
| 9558 | MapExpressionComponents StackComponents; |
| 9559 | ExtractMapExpressionComponents(RE, StackComponents); |
| 9560 | assert(!StackComponents.empty() && |
| 9561 | "Map clause expression with no components!"); |
| 9562 | assert(StackComponents.back().second == VD && |
| 9563 | "Map clause expression with unexpected base!"); |
| 9564 | |
| 9565 | // Expressions must start from the same base. Here we detect at which |
| 9566 | // point both expressions diverge from each other and see if we can |
| 9567 | // detect if the memory referred to both expressions is contiguous and |
| 9568 | // do not overlap. |
| 9569 | auto CI = CurComponents.rbegin(); |
| 9570 | auto CE = CurComponents.rend(); |
| 9571 | auto SI = StackComponents.rbegin(); |
| 9572 | auto SE = StackComponents.rend(); |
| 9573 | for (; CI != CE && SI != SE; ++CI, ++SI) { |
| 9574 | |
| 9575 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.3] |
| 9576 | // At most one list item can be an array item derived from a given |
| 9577 | // variable in map clauses of the same construct. |
| 9578 | if (CurrentRegionOnly && (isa<ArraySubscriptExpr>(CI->first) || |
| 9579 | isa<OMPArraySectionExpr>(CI->first)) && |
| 9580 | (isa<ArraySubscriptExpr>(SI->first) || |
| 9581 | isa<OMPArraySectionExpr>(SI->first))) { |
| 9582 | SemaRef.Diag(CI->first->getExprLoc(), |
| 9583 | diag::err_omp_multiple_array_items_in_map_clause) |
| 9584 | << CI->first->getSourceRange(); |
| 9585 | ; |
| 9586 | SemaRef.Diag(SI->first->getExprLoc(), diag::note_used_here) |
| 9587 | << SI->first->getSourceRange(); |
| 9588 | return true; |
| 9589 | } |
| 9590 | |
| 9591 | // Do both expressions have the same kind? |
| 9592 | if (CI->first->getStmtClass() != SI->first->getStmtClass()) |
| 9593 | break; |
| 9594 | |
| 9595 | // Are we dealing with different variables/fields? |
| 9596 | if (CI->second != SI->second) |
| 9597 | break; |
| 9598 | } |
| 9599 | |
| 9600 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.4] |
| 9601 | // List items of map clauses in the same construct must not share |
| 9602 | // original storage. |
| 9603 | // |
| 9604 | // If the expressions are exactly the same or one is a subset of the |
| 9605 | // other, it means they are sharing storage. |
| 9606 | if (CI == CE && SI == SE) { |
| 9607 | if (CurrentRegionOnly) { |
| 9608 | SemaRef.Diag(ELoc, diag::err_omp_map_shared_storage) << ERange; |
| 9609 | SemaRef.Diag(RE->getExprLoc(), diag::note_used_here) |
| 9610 | << RE->getSourceRange(); |
| 9611 | return true; |
| 9612 | } else { |
| 9613 | // If we find the same expression in the enclosing data environment, |
| 9614 | // that is legal. |
| 9615 | IsEnclosedByDataEnvironmentExpr = true; |
| 9616 | return false; |
| 9617 | } |
| 9618 | } |
| 9619 | |
| 9620 | QualType DerivedType = std::prev(CI)->first->getType(); |
| 9621 | SourceLocation DerivedLoc = std::prev(CI)->first->getExprLoc(); |
| 9622 | |
| 9623 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] |
| 9624 | // If the type of a list item is a reference to a type T then the type |
| 9625 | // will be considered to be T for all purposes of this clause. |
| 9626 | if (DerivedType->isReferenceType()) |
| 9627 | DerivedType = DerivedType->getPointeeType(); |
| 9628 | |
| 9629 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C/C++, p.1] |
| 9630 | // A variable for which the type is pointer and an array section |
| 9631 | // derived from that variable must not appear as list items of map |
| 9632 | // clauses of the same construct. |
| 9633 | // |
| 9634 | // Also, cover one of the cases in: |
| 9635 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.5] |
| 9636 | // If any part of the original storage of a list item has corresponding |
| 9637 | // storage in the device data environment, all of the original storage |
| 9638 | // must have corresponding storage in the device data environment. |
| 9639 | // |
| 9640 | if (DerivedType->isAnyPointerType()) { |
| 9641 | if (CI == CE || SI == SE) { |
| 9642 | SemaRef.Diag( |
| 9643 | DerivedLoc, |
| 9644 | diag::err_omp_pointer_mapped_along_with_derived_section) |
| 9645 | << DerivedLoc; |
| 9646 | } else { |
| 9647 | assert(CI != CE && SI != SE); |
| 9648 | SemaRef.Diag(DerivedLoc, diag::err_omp_same_pointer_derreferenced) |
| 9649 | << DerivedLoc; |
| 9650 | } |
| 9651 | SemaRef.Diag(RE->getExprLoc(), diag::note_used_here) |
| 9652 | << RE->getSourceRange(); |
| 9653 | return true; |
| 9654 | } |
| 9655 | |
| 9656 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.4] |
| 9657 | // List items of map clauses in the same construct must not share |
| 9658 | // original storage. |
| 9659 | // |
| 9660 | // An expression is a subset of the other. |
| 9661 | if (CurrentRegionOnly && (CI == CE || SI == SE)) { |
| 9662 | SemaRef.Diag(ELoc, diag::err_omp_map_shared_storage) << ERange; |
| 9663 | SemaRef.Diag(RE->getExprLoc(), diag::note_used_here) |
| 9664 | << RE->getSourceRange(); |
| 9665 | return true; |
| 9666 | } |
| 9667 | |
| 9668 | // The current expression uses the same base as other expression in the |
| 9669 | // data environment but does not contain it completelly. |
| 9670 | if (!CurrentRegionOnly && SI != SE) |
| 9671 | EnclosingExpr = RE; |
| 9672 | |
| 9673 | // The current expression is a subset of the expression in the data |
| 9674 | // environment. |
| 9675 | IsEnclosedByDataEnvironmentExpr |= |
| 9676 | (!CurrentRegionOnly && CI != CE && SI == SE); |
| 9677 | |
| 9678 | return false; |
| 9679 | }); |
| 9680 | |
| 9681 | if (CurrentRegionOnly) |
| 9682 | return FoundError; |
| 9683 | |
| 9684 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.5] |
| 9685 | // If any part of the original storage of a list item has corresponding |
| 9686 | // storage in the device data environment, all of the original storage must |
| 9687 | // have corresponding storage in the device data environment. |
| 9688 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.6] |
| 9689 | // If a list item is an element of a structure, and a different element of |
| 9690 | // the structure has a corresponding list item in the device data environment |
| 9691 | // prior to a task encountering the construct associated with the map clause, |
| 9692 | // then the list item must also have a correspnding list item in the device |
| 9693 | // data environment prior to the task encountering the construct. |
| 9694 | // |
| 9695 | if (EnclosingExpr && !IsEnclosedByDataEnvironmentExpr) { |
| 9696 | SemaRef.Diag(ELoc, |
| 9697 | diag::err_omp_original_storage_is_shared_and_does_not_contain) |
| 9698 | << ERange; |
| 9699 | SemaRef.Diag(EnclosingExpr->getExprLoc(), diag::note_used_here) |
| 9700 | << EnclosingExpr->getSourceRange(); |
| 9701 | return true; |
| 9702 | } |
| 9703 | |
| 9704 | return FoundError; |
| 9705 | } |
| 9706 | |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 9707 | OMPClause * |
| 9708 | Sema::ActOnOpenMPMapClause(OpenMPMapClauseKind MapTypeModifier, |
| 9709 | OpenMPMapClauseKind MapType, bool IsMapTypeImplicit, |
| 9710 | SourceLocation MapLoc, SourceLocation ColonLoc, |
| 9711 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
| 9712 | SourceLocation LParenLoc, SourceLocation EndLoc) { |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9713 | SmallVector<Expr *, 4> Vars; |
| 9714 | |
| 9715 | for (auto &RE : VarList) { |
| 9716 | assert(RE && "Null expr in omp map"); |
| 9717 | if (isa<DependentScopeDeclRefExpr>(RE)) { |
| 9718 | // It will be analyzed later. |
| 9719 | Vars.push_back(RE); |
| 9720 | continue; |
| 9721 | } |
| 9722 | SourceLocation ELoc = RE->getExprLoc(); |
| 9723 | |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9724 | auto *VE = RE->IgnoreParenLValueCasts(); |
| 9725 | |
| 9726 | if (VE->isValueDependent() || VE->isTypeDependent() || |
| 9727 | VE->isInstantiationDependent() || |
| 9728 | VE->containsUnexpandedParameterPack()) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9729 | // We can only analyze this information once the missing information is |
| 9730 | // resolved. |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9731 | Vars.push_back(RE); |
| 9732 | continue; |
| 9733 | } |
| 9734 | |
| 9735 | auto *SimpleExpr = RE->IgnoreParenCasts(); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9736 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9737 | if (!RE->IgnoreParenImpCasts()->isLValue()) { |
| 9738 | Diag(ELoc, diag::err_omp_expected_named_var_member_or_array_expression) |
| 9739 | << RE->getSourceRange(); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9740 | continue; |
| 9741 | } |
| 9742 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9743 | // Obtain the array or member expression bases if required. |
| 9744 | auto *BE = CheckMapClauseExpressionBase(*this, SimpleExpr); |
| 9745 | if (!BE) |
| 9746 | continue; |
| 9747 | |
| 9748 | // If the base is a reference to a variable, we rely on that variable for |
| 9749 | // the following checks. If it is a 'this' expression we rely on the field. |
| 9750 | ValueDecl *D = nullptr; |
| 9751 | if (auto *DRE = dyn_cast<DeclRefExpr>(BE)) { |
| 9752 | D = DRE->getDecl(); |
| 9753 | } else { |
| 9754 | auto *ME = cast<MemberExpr>(BE); |
| 9755 | assert(isa<CXXThisExpr>(ME->getBase()) && "Unexpected expression!"); |
| 9756 | D = ME->getMemberDecl(); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9757 | } |
| 9758 | assert(D && "Null decl on map clause."); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9759 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9760 | auto *VD = dyn_cast<VarDecl>(D); |
| 9761 | auto *FD = dyn_cast<FieldDecl>(D); |
| 9762 | |
| 9763 | assert((VD || FD) && "Only variables or fields are expected here!"); |
NAKAMURA Takumi | 6dcb814 | 2016-01-23 01:38:20 +0000 | [diff] [blame] | 9764 | (void)FD; |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9765 | |
| 9766 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.10] |
| 9767 | // threadprivate variables cannot appear in a map clause. |
| 9768 | if (VD && DSAStack->isThreadPrivate(VD)) { |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9769 | auto DVar = DSAStack->getTopDSA(VD, false); |
| 9770 | Diag(ELoc, diag::err_omp_threadprivate_in_map); |
| 9771 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 9772 | continue; |
| 9773 | } |
| 9774 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9775 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.9] |
| 9776 | // A list item cannot appear in both a map clause and a data-sharing |
| 9777 | // attribute clause on the same construct. |
| 9778 | // |
| 9779 | // TODO: Implement this check - it cannot currently be tested because of |
| 9780 | // missing implementation of the other data sharing clauses in target |
| 9781 | // directives. |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9782 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9783 | // Check conflicts with other map clause expressions. We check the conflicts |
| 9784 | // with the current construct separately from the enclosing data |
| 9785 | // environment, because the restrictions are different. |
| 9786 | if (CheckMapConflicts(*this, DSAStack, D, SimpleExpr, |
| 9787 | /*CurrentRegionOnly=*/true)) |
| 9788 | break; |
| 9789 | if (CheckMapConflicts(*this, DSAStack, D, SimpleExpr, |
| 9790 | /*CurrentRegionOnly=*/false)) |
| 9791 | break; |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9792 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9793 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] |
| 9794 | // If the type of a list item is a reference to a type T then the type will |
| 9795 | // be considered to be T for all purposes of this clause. |
| 9796 | QualType Type = D->getType(); |
| 9797 | if (Type->isReferenceType()) |
| 9798 | Type = Type->getPointeeType(); |
| 9799 | |
| 9800 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.9] |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9801 | // A list item must have a mappable type. |
| 9802 | if (!CheckTypeMappable(VE->getExprLoc(), VE->getSourceRange(), *this, |
| 9803 | DSAStack, Type)) |
| 9804 | continue; |
| 9805 | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 9806 | // target enter data |
| 9807 | // OpenMP [2.10.2, Restrictions, p. 99] |
| 9808 | // A map-type must be specified in all map clauses and must be either |
| 9809 | // to or alloc. |
| 9810 | OpenMPDirectiveKind DKind = DSAStack->getCurrentDirective(); |
| 9811 | if (DKind == OMPD_target_enter_data && |
| 9812 | !(MapType == OMPC_MAP_to || MapType == OMPC_MAP_alloc)) { |
| 9813 | Diag(StartLoc, diag::err_omp_invalid_map_type_for_directive) |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 9814 | << (IsMapTypeImplicit ? 1 : 0) |
| 9815 | << getOpenMPSimpleClauseTypeName(OMPC_map, MapType) |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 9816 | << getOpenMPDirectiveName(DKind); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9817 | continue; |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 9818 | } |
| 9819 | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 9820 | // target exit_data |
| 9821 | // OpenMP [2.10.3, Restrictions, p. 102] |
| 9822 | // A map-type must be specified in all map clauses and must be either |
| 9823 | // from, release, or delete. |
| 9824 | DKind = DSAStack->getCurrentDirective(); |
| 9825 | if (DKind == OMPD_target_exit_data && |
| 9826 | !(MapType == OMPC_MAP_from || MapType == OMPC_MAP_release || |
| 9827 | MapType == OMPC_MAP_delete)) { |
| 9828 | Diag(StartLoc, diag::err_omp_invalid_map_type_for_directive) |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 9829 | << (IsMapTypeImplicit ? 1 : 0) |
| 9830 | << getOpenMPSimpleClauseTypeName(OMPC_map, MapType) |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 9831 | << getOpenMPDirectiveName(DKind); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9832 | continue; |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 9833 | } |
| 9834 | |
Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 9835 | // OpenMP 4.5 [2.15.5.1, Restrictions, p.3] |
| 9836 | // A list item cannot appear in both a map clause and a data-sharing |
| 9837 | // attribute clause on the same construct |
| 9838 | if (DKind == OMPD_target && VD) { |
| 9839 | auto DVar = DSAStack->getTopDSA(VD, false); |
| 9840 | if (isOpenMPPrivate(DVar.CKind)) { |
| 9841 | Diag(ELoc, diag::err_omp_variable_in_map_and_dsa) |
| 9842 | << getOpenMPClauseName(DVar.CKind) |
| 9843 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 9844 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
| 9845 | continue; |
| 9846 | } |
| 9847 | } |
| 9848 | |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9849 | Vars.push_back(RE); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9850 | DSAStack->addExprToVarMapInfo(D, RE); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9851 | } |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9852 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9853 | // We need to produce a map clause even if we don't have variables so that |
| 9854 | // other diagnostics related with non-existing map clauses are accurate. |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9855 | return OMPMapClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 9856 | MapTypeModifier, MapType, IsMapTypeImplicit, |
| 9857 | MapLoc); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9858 | } |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 9859 | |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 9860 | QualType Sema::ActOnOpenMPDeclareReductionType(SourceLocation TyLoc, |
| 9861 | TypeResult ParsedType) { |
| 9862 | assert(ParsedType.isUsable()); |
| 9863 | |
| 9864 | QualType ReductionType = GetTypeFromParser(ParsedType.get()); |
| 9865 | if (ReductionType.isNull()) |
| 9866 | return QualType(); |
| 9867 | |
| 9868 | // [OpenMP 4.0], 2.15 declare reduction Directive, Restrictions, C\C++ |
| 9869 | // A type name in a declare reduction directive cannot be a function type, an |
| 9870 | // array type, a reference type, or a type qualified with const, volatile or |
| 9871 | // restrict. |
| 9872 | if (ReductionType.hasQualifiers()) { |
| 9873 | Diag(TyLoc, diag::err_omp_reduction_wrong_type) << 0; |
| 9874 | return QualType(); |
| 9875 | } |
| 9876 | |
| 9877 | if (ReductionType->isFunctionType()) { |
| 9878 | Diag(TyLoc, diag::err_omp_reduction_wrong_type) << 1; |
| 9879 | return QualType(); |
| 9880 | } |
| 9881 | if (ReductionType->isReferenceType()) { |
| 9882 | Diag(TyLoc, diag::err_omp_reduction_wrong_type) << 2; |
| 9883 | return QualType(); |
| 9884 | } |
| 9885 | if (ReductionType->isArrayType()) { |
| 9886 | Diag(TyLoc, diag::err_omp_reduction_wrong_type) << 3; |
| 9887 | return QualType(); |
| 9888 | } |
| 9889 | return ReductionType; |
| 9890 | } |
| 9891 | |
| 9892 | Sema::DeclGroupPtrTy Sema::ActOnOpenMPDeclareReductionDirectiveStart( |
| 9893 | Scope *S, DeclContext *DC, DeclarationName Name, |
| 9894 | ArrayRef<std::pair<QualType, SourceLocation>> ReductionTypes, |
| 9895 | AccessSpecifier AS, Decl *PrevDeclInScope) { |
| 9896 | SmallVector<Decl *, 8> Decls; |
| 9897 | Decls.reserve(ReductionTypes.size()); |
| 9898 | |
| 9899 | LookupResult Lookup(*this, Name, SourceLocation(), LookupOMPReductionName, |
| 9900 | ForRedeclaration); |
| 9901 | // [OpenMP 4.0], 2.15 declare reduction Directive, Restrictions |
| 9902 | // A reduction-identifier may not be re-declared in the current scope for the |
| 9903 | // same type or for a type that is compatible according to the base language |
| 9904 | // rules. |
| 9905 | llvm::DenseMap<QualType, SourceLocation> PreviousRedeclTypes; |
| 9906 | OMPDeclareReductionDecl *PrevDRD = nullptr; |
| 9907 | bool InCompoundScope = true; |
| 9908 | if (S != nullptr) { |
| 9909 | // Find previous declaration with the same name not referenced in other |
| 9910 | // declarations. |
| 9911 | FunctionScopeInfo *ParentFn = getEnclosingFunction(); |
| 9912 | InCompoundScope = |
| 9913 | (ParentFn != nullptr) && !ParentFn->CompoundScopes.empty(); |
| 9914 | LookupName(Lookup, S); |
| 9915 | FilterLookupForScope(Lookup, DC, S, /*ConsiderLinkage=*/false, |
| 9916 | /*AllowInlineNamespace=*/false); |
| 9917 | llvm::DenseMap<OMPDeclareReductionDecl *, bool> UsedAsPrevious; |
| 9918 | auto Filter = Lookup.makeFilter(); |
| 9919 | while (Filter.hasNext()) { |
| 9920 | auto *PrevDecl = cast<OMPDeclareReductionDecl>(Filter.next()); |
| 9921 | if (InCompoundScope) { |
| 9922 | auto I = UsedAsPrevious.find(PrevDecl); |
| 9923 | if (I == UsedAsPrevious.end()) |
| 9924 | UsedAsPrevious[PrevDecl] = false; |
| 9925 | if (auto *D = PrevDecl->getPrevDeclInScope()) |
| 9926 | UsedAsPrevious[D] = true; |
| 9927 | } |
| 9928 | PreviousRedeclTypes[PrevDecl->getType().getCanonicalType()] = |
| 9929 | PrevDecl->getLocation(); |
| 9930 | } |
| 9931 | Filter.done(); |
| 9932 | if (InCompoundScope) { |
| 9933 | for (auto &PrevData : UsedAsPrevious) { |
| 9934 | if (!PrevData.second) { |
| 9935 | PrevDRD = PrevData.first; |
| 9936 | break; |
| 9937 | } |
| 9938 | } |
| 9939 | } |
| 9940 | } else if (PrevDeclInScope != nullptr) { |
| 9941 | auto *PrevDRDInScope = PrevDRD = |
| 9942 | cast<OMPDeclareReductionDecl>(PrevDeclInScope); |
| 9943 | do { |
| 9944 | PreviousRedeclTypes[PrevDRDInScope->getType().getCanonicalType()] = |
| 9945 | PrevDRDInScope->getLocation(); |
| 9946 | PrevDRDInScope = PrevDRDInScope->getPrevDeclInScope(); |
| 9947 | } while (PrevDRDInScope != nullptr); |
| 9948 | } |
| 9949 | for (auto &TyData : ReductionTypes) { |
| 9950 | auto I = PreviousRedeclTypes.find(TyData.first.getCanonicalType()); |
| 9951 | bool Invalid = false; |
| 9952 | if (I != PreviousRedeclTypes.end()) { |
| 9953 | Diag(TyData.second, diag::err_omp_declare_reduction_redefinition) |
| 9954 | << TyData.first; |
| 9955 | Diag(I->second, diag::note_previous_definition); |
| 9956 | Invalid = true; |
| 9957 | } |
| 9958 | PreviousRedeclTypes[TyData.first.getCanonicalType()] = TyData.second; |
| 9959 | auto *DRD = OMPDeclareReductionDecl::Create(Context, DC, TyData.second, |
| 9960 | Name, TyData.first, PrevDRD); |
| 9961 | DC->addDecl(DRD); |
| 9962 | DRD->setAccess(AS); |
| 9963 | Decls.push_back(DRD); |
| 9964 | if (Invalid) |
| 9965 | DRD->setInvalidDecl(); |
| 9966 | else |
| 9967 | PrevDRD = DRD; |
| 9968 | } |
| 9969 | |
| 9970 | return DeclGroupPtrTy::make( |
| 9971 | DeclGroupRef::Create(Context, Decls.begin(), Decls.size())); |
| 9972 | } |
| 9973 | |
| 9974 | void Sema::ActOnOpenMPDeclareReductionCombinerStart(Scope *S, Decl *D) { |
| 9975 | auto *DRD = cast<OMPDeclareReductionDecl>(D); |
| 9976 | |
| 9977 | // Enter new function scope. |
| 9978 | PushFunctionScope(); |
| 9979 | getCurFunction()->setHasBranchProtectedScope(); |
| 9980 | getCurFunction()->setHasOMPDeclareReductionCombiner(); |
| 9981 | |
| 9982 | if (S != nullptr) |
| 9983 | PushDeclContext(S, DRD); |
| 9984 | else |
| 9985 | CurContext = DRD; |
| 9986 | |
| 9987 | PushExpressionEvaluationContext(PotentiallyEvaluated); |
| 9988 | |
| 9989 | QualType ReductionType = DRD->getType(); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9990 | // Create 'T* omp_parm;T omp_in;'. All references to 'omp_in' will |
| 9991 | // be replaced by '*omp_parm' during codegen. This required because 'omp_in' |
| 9992 | // uses semantics of argument handles by value, but it should be passed by |
| 9993 | // reference. C lang does not support references, so pass all parameters as |
| 9994 | // pointers. |
| 9995 | // Create 'T omp_in;' variable. |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 9996 | auto *OmpInParm = |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9997 | buildVarDecl(*this, D->getLocation(), ReductionType, "omp_in"); |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 9998 | // Create 'T* omp_parm;T omp_out;'. All references to 'omp_out' will |
| 9999 | // be replaced by '*omp_parm' during codegen. This required because 'omp_out' |
| 10000 | // uses semantics of argument handles by value, but it should be passed by |
| 10001 | // reference. C lang does not support references, so pass all parameters as |
| 10002 | // pointers. |
| 10003 | // Create 'T omp_out;' variable. |
| 10004 | auto *OmpOutParm = |
| 10005 | buildVarDecl(*this, D->getLocation(), ReductionType, "omp_out"); |
| 10006 | if (S != nullptr) { |
| 10007 | PushOnScopeChains(OmpInParm, S); |
| 10008 | PushOnScopeChains(OmpOutParm, S); |
| 10009 | } else { |
| 10010 | DRD->addDecl(OmpInParm); |
| 10011 | DRD->addDecl(OmpOutParm); |
| 10012 | } |
| 10013 | } |
| 10014 | |
| 10015 | void Sema::ActOnOpenMPDeclareReductionCombinerEnd(Decl *D, Expr *Combiner) { |
| 10016 | auto *DRD = cast<OMPDeclareReductionDecl>(D); |
| 10017 | DiscardCleanupsInEvaluationContext(); |
| 10018 | PopExpressionEvaluationContext(); |
| 10019 | |
| 10020 | PopDeclContext(); |
| 10021 | PopFunctionScopeInfo(); |
| 10022 | |
| 10023 | if (Combiner != nullptr) |
| 10024 | DRD->setCombiner(Combiner); |
| 10025 | else |
| 10026 | DRD->setInvalidDecl(); |
| 10027 | } |
| 10028 | |
| 10029 | void Sema::ActOnOpenMPDeclareReductionInitializerStart(Scope *S, Decl *D) { |
| 10030 | auto *DRD = cast<OMPDeclareReductionDecl>(D); |
| 10031 | |
| 10032 | // Enter new function scope. |
| 10033 | PushFunctionScope(); |
| 10034 | getCurFunction()->setHasBranchProtectedScope(); |
| 10035 | |
| 10036 | if (S != nullptr) |
| 10037 | PushDeclContext(S, DRD); |
| 10038 | else |
| 10039 | CurContext = DRD; |
| 10040 | |
| 10041 | PushExpressionEvaluationContext(PotentiallyEvaluated); |
| 10042 | |
| 10043 | QualType ReductionType = DRD->getType(); |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 10044 | // Create 'T* omp_parm;T omp_priv;'. All references to 'omp_priv' will |
| 10045 | // be replaced by '*omp_parm' during codegen. This required because 'omp_priv' |
| 10046 | // uses semantics of argument handles by value, but it should be passed by |
| 10047 | // reference. C lang does not support references, so pass all parameters as |
| 10048 | // pointers. |
| 10049 | // Create 'T omp_priv;' variable. |
| 10050 | auto *OmpPrivParm = |
| 10051 | buildVarDecl(*this, D->getLocation(), ReductionType, "omp_priv"); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 10052 | // Create 'T* omp_parm;T omp_orig;'. All references to 'omp_orig' will |
| 10053 | // be replaced by '*omp_parm' during codegen. This required because 'omp_orig' |
| 10054 | // uses semantics of argument handles by value, but it should be passed by |
| 10055 | // reference. C lang does not support references, so pass all parameters as |
| 10056 | // pointers. |
| 10057 | // Create 'T omp_orig;' variable. |
| 10058 | auto *OmpOrigParm = |
| 10059 | buildVarDecl(*this, D->getLocation(), ReductionType, "omp_orig"); |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 10060 | if (S != nullptr) { |
| 10061 | PushOnScopeChains(OmpPrivParm, S); |
| 10062 | PushOnScopeChains(OmpOrigParm, S); |
| 10063 | } else { |
| 10064 | DRD->addDecl(OmpPrivParm); |
| 10065 | DRD->addDecl(OmpOrigParm); |
| 10066 | } |
| 10067 | } |
| 10068 | |
| 10069 | void Sema::ActOnOpenMPDeclareReductionInitializerEnd(Decl *D, |
| 10070 | Expr *Initializer) { |
| 10071 | auto *DRD = cast<OMPDeclareReductionDecl>(D); |
| 10072 | DiscardCleanupsInEvaluationContext(); |
| 10073 | PopExpressionEvaluationContext(); |
| 10074 | |
| 10075 | PopDeclContext(); |
| 10076 | PopFunctionScopeInfo(); |
| 10077 | |
| 10078 | if (Initializer != nullptr) |
| 10079 | DRD->setInitializer(Initializer); |
| 10080 | else |
| 10081 | DRD->setInvalidDecl(); |
| 10082 | } |
| 10083 | |
| 10084 | Sema::DeclGroupPtrTy Sema::ActOnOpenMPDeclareReductionDirectiveEnd( |
| 10085 | Scope *S, DeclGroupPtrTy DeclReductions, bool IsValid) { |
| 10086 | for (auto *D : DeclReductions.get()) { |
| 10087 | if (IsValid) { |
| 10088 | auto *DRD = cast<OMPDeclareReductionDecl>(D); |
| 10089 | if (S != nullptr) |
| 10090 | PushOnScopeChains(DRD, S, /*AddToContext=*/false); |
| 10091 | } else |
| 10092 | D->setInvalidDecl(); |
| 10093 | } |
| 10094 | return DeclReductions; |
| 10095 | } |
| 10096 | |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 10097 | OMPClause *Sema::ActOnOpenMPNumTeamsClause(Expr *NumTeams, |
| 10098 | SourceLocation StartLoc, |
| 10099 | SourceLocation LParenLoc, |
| 10100 | SourceLocation EndLoc) { |
| 10101 | Expr *ValExpr = NumTeams; |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 10102 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 10103 | // OpenMP [teams Constrcut, Restrictions] |
| 10104 | // The num_teams expression must evaluate to a positive integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 10105 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_num_teams, |
| 10106 | /*StrictlyPositive=*/true)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 10107 | return nullptr; |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 10108 | |
| 10109 | return new (Context) OMPNumTeamsClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 10110 | } |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 10111 | |
| 10112 | OMPClause *Sema::ActOnOpenMPThreadLimitClause(Expr *ThreadLimit, |
| 10113 | SourceLocation StartLoc, |
| 10114 | SourceLocation LParenLoc, |
| 10115 | SourceLocation EndLoc) { |
| 10116 | Expr *ValExpr = ThreadLimit; |
| 10117 | |
| 10118 | // OpenMP [teams Constrcut, Restrictions] |
| 10119 | // The thread_limit expression must evaluate to a positive integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 10120 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_thread_limit, |
| 10121 | /*StrictlyPositive=*/true)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 10122 | return nullptr; |
| 10123 | |
| 10124 | return new (Context) OMPThreadLimitClause(ValExpr, StartLoc, LParenLoc, |
| 10125 | EndLoc); |
| 10126 | } |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 10127 | |
| 10128 | OMPClause *Sema::ActOnOpenMPPriorityClause(Expr *Priority, |
| 10129 | SourceLocation StartLoc, |
| 10130 | SourceLocation LParenLoc, |
| 10131 | SourceLocation EndLoc) { |
| 10132 | Expr *ValExpr = Priority; |
| 10133 | |
| 10134 | // OpenMP [2.9.1, task Constrcut] |
| 10135 | // The priority-value is a non-negative numerical scalar expression. |
| 10136 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_priority, |
| 10137 | /*StrictlyPositive=*/false)) |
| 10138 | return nullptr; |
| 10139 | |
| 10140 | return new (Context) OMPPriorityClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 10141 | } |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 10142 | |
| 10143 | OMPClause *Sema::ActOnOpenMPGrainsizeClause(Expr *Grainsize, |
| 10144 | SourceLocation StartLoc, |
| 10145 | SourceLocation LParenLoc, |
| 10146 | SourceLocation EndLoc) { |
| 10147 | Expr *ValExpr = Grainsize; |
| 10148 | |
| 10149 | // OpenMP [2.9.2, taskloop Constrcut] |
| 10150 | // The parameter of the grainsize clause must be a positive integer |
| 10151 | // expression. |
| 10152 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_grainsize, |
| 10153 | /*StrictlyPositive=*/true)) |
| 10154 | return nullptr; |
| 10155 | |
| 10156 | return new (Context) OMPGrainsizeClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 10157 | } |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 10158 | |
| 10159 | OMPClause *Sema::ActOnOpenMPNumTasksClause(Expr *NumTasks, |
| 10160 | SourceLocation StartLoc, |
| 10161 | SourceLocation LParenLoc, |
| 10162 | SourceLocation EndLoc) { |
| 10163 | Expr *ValExpr = NumTasks; |
| 10164 | |
| 10165 | // OpenMP [2.9.2, taskloop Constrcut] |
| 10166 | // The parameter of the num_tasks clause must be a positive integer |
| 10167 | // expression. |
| 10168 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_num_tasks, |
| 10169 | /*StrictlyPositive=*/true)) |
| 10170 | return nullptr; |
| 10171 | |
| 10172 | return new (Context) OMPNumTasksClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 10173 | } |
| 10174 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 10175 | OMPClause *Sema::ActOnOpenMPHintClause(Expr *Hint, SourceLocation StartLoc, |
| 10176 | SourceLocation LParenLoc, |
| 10177 | SourceLocation EndLoc) { |
| 10178 | // OpenMP [2.13.2, critical construct, Description] |
| 10179 | // ... where hint-expression is an integer constant expression that evaluates |
| 10180 | // to a valid lock hint. |
| 10181 | ExprResult HintExpr = VerifyPositiveIntegerConstantInClause(Hint, OMPC_hint); |
| 10182 | if (HintExpr.isInvalid()) |
| 10183 | return nullptr; |
| 10184 | return new (Context) |
| 10185 | OMPHintClause(HintExpr.get(), StartLoc, LParenLoc, EndLoc); |
| 10186 | } |
| 10187 | |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 10188 | OMPClause *Sema::ActOnOpenMPDistScheduleClause( |
| 10189 | OpenMPDistScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, |
| 10190 | SourceLocation LParenLoc, SourceLocation KindLoc, SourceLocation CommaLoc, |
| 10191 | SourceLocation EndLoc) { |
| 10192 | if (Kind == OMPC_DIST_SCHEDULE_unknown) { |
| 10193 | std::string Values; |
| 10194 | Values += "'"; |
| 10195 | Values += getOpenMPSimpleClauseTypeName(OMPC_dist_schedule, 0); |
| 10196 | Values += "'"; |
| 10197 | Diag(KindLoc, diag::err_omp_unexpected_clause_value) |
| 10198 | << Values << getOpenMPClauseName(OMPC_dist_schedule); |
| 10199 | return nullptr; |
| 10200 | } |
| 10201 | Expr *ValExpr = ChunkSize; |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 10202 | Stmt *HelperValStmt = nullptr; |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 10203 | if (ChunkSize) { |
| 10204 | if (!ChunkSize->isValueDependent() && !ChunkSize->isTypeDependent() && |
| 10205 | !ChunkSize->isInstantiationDependent() && |
| 10206 | !ChunkSize->containsUnexpandedParameterPack()) { |
| 10207 | SourceLocation ChunkSizeLoc = ChunkSize->getLocStart(); |
| 10208 | ExprResult Val = |
| 10209 | PerformOpenMPImplicitIntegerConversion(ChunkSizeLoc, ChunkSize); |
| 10210 | if (Val.isInvalid()) |
| 10211 | return nullptr; |
| 10212 | |
| 10213 | ValExpr = Val.get(); |
| 10214 | |
| 10215 | // OpenMP [2.7.1, Restrictions] |
| 10216 | // chunk_size must be a loop invariant integer expression with a positive |
| 10217 | // value. |
| 10218 | llvm::APSInt Result; |
| 10219 | if (ValExpr->isIntegerConstantExpr(Result, Context)) { |
| 10220 | if (Result.isSigned() && !Result.isStrictlyPositive()) { |
| 10221 | Diag(ChunkSizeLoc, diag::err_omp_negative_expression_in_clause) |
| 10222 | << "dist_schedule" << ChunkSize->getSourceRange(); |
| 10223 | return nullptr; |
| 10224 | } |
| 10225 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective())) { |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 10226 | llvm::MapVector<Expr *, DeclRefExpr *> Captures; |
| 10227 | ValExpr = tryBuildCapture(*this, ValExpr, Captures).get(); |
| 10228 | HelperValStmt = buildPreInits(Context, Captures); |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 10229 | } |
| 10230 | } |
| 10231 | } |
| 10232 | |
| 10233 | return new (Context) |
| 10234 | OMPDistScheduleClause(StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc, |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 10235 | Kind, ValExpr, HelperValStmt); |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 10236 | } |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 10237 | |
| 10238 | OMPClause *Sema::ActOnOpenMPDefaultmapClause( |
| 10239 | OpenMPDefaultmapClauseModifier M, OpenMPDefaultmapClauseKind Kind, |
| 10240 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation MLoc, |
| 10241 | SourceLocation KindLoc, SourceLocation EndLoc) { |
| 10242 | // OpenMP 4.5 only supports 'defaultmap(tofrom: scalar)' |
| 10243 | if (M != OMPC_DEFAULTMAP_MODIFIER_tofrom || |
| 10244 | Kind != OMPC_DEFAULTMAP_scalar) { |
| 10245 | std::string Value; |
| 10246 | SourceLocation Loc; |
| 10247 | Value += "'"; |
| 10248 | if (M != OMPC_DEFAULTMAP_MODIFIER_tofrom) { |
| 10249 | Value += getOpenMPSimpleClauseTypeName(OMPC_defaultmap, |
| 10250 | OMPC_DEFAULTMAP_MODIFIER_tofrom); |
| 10251 | Loc = MLoc; |
| 10252 | } else { |
| 10253 | Value += getOpenMPSimpleClauseTypeName(OMPC_defaultmap, |
| 10254 | OMPC_DEFAULTMAP_scalar); |
| 10255 | Loc = KindLoc; |
| 10256 | } |
| 10257 | Value += "'"; |
| 10258 | Diag(Loc, diag::err_omp_unexpected_clause_value) |
| 10259 | << Value << getOpenMPClauseName(OMPC_defaultmap); |
| 10260 | return nullptr; |
| 10261 | } |
| 10262 | |
| 10263 | return new (Context) |
| 10264 | OMPDefaultmapClause(StartLoc, LParenLoc, MLoc, KindLoc, EndLoc, Kind, M); |
| 10265 | } |