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 | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 93 | typedef std::pair<unsigned, VarDecl *> LCDeclInfo; |
| 94 | typedef llvm::DenseMap<ValueDecl *, LCDeclInfo> LoopControlVariablesMapTy; |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 95 | typedef llvm::DenseMap<ValueDecl *, MapInfo> MappedDeclsTy; |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 96 | typedef llvm::StringMap<std::pair<OMPCriticalDirective *, llvm::APSInt>> |
| 97 | CriticalsWithHintsTy; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 98 | |
| 99 | struct SharingMapTy { |
| 100 | DeclSAMapTy SharingMap; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 101 | AlignedMapTy AlignedMap; |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 102 | MappedDeclsTy MappedDecls; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 103 | LoopControlVariablesMapTy LCVMap; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 104 | DefaultDataSharingAttributes DefaultAttr; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 105 | SourceLocation DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 106 | OpenMPDirectiveKind Directive; |
| 107 | DeclarationNameInfo DirectiveName; |
| 108 | Scope *CurScope; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 109 | SourceLocation ConstructLoc; |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 110 | /// \brief first argument (Expr *) contains optional argument of the |
| 111 | /// 'ordered' clause, the second one is true if the regions has 'ordered' |
| 112 | /// clause, false otherwise. |
| 113 | llvm::PointerIntPair<Expr *, 1, bool> OrderedRegion; |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 114 | bool NowaitRegion; |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 115 | bool CancelRegion; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 116 | unsigned AssociatedLoops; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 117 | SourceLocation InnerTeamsRegionLoc; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 118 | SharingMapTy(OpenMPDirectiveKind DKind, DeclarationNameInfo Name, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 119 | Scope *CurScope, SourceLocation Loc) |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 120 | : SharingMap(), AlignedMap(), LCVMap(), DefaultAttr(DSA_unspecified), |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 121 | Directive(DKind), DirectiveName(std::move(Name)), CurScope(CurScope), |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 122 | ConstructLoc(Loc), OrderedRegion(), NowaitRegion(false), |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 123 | CancelRegion(false), AssociatedLoops(1), InnerTeamsRegionLoc() {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 124 | SharingMapTy() |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 125 | : SharingMap(), AlignedMap(), LCVMap(), DefaultAttr(DSA_unspecified), |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 126 | Directive(OMPD_unknown), DirectiveName(), CurScope(nullptr), |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 127 | ConstructLoc(), OrderedRegion(), NowaitRegion(false), |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 128 | CancelRegion(false), AssociatedLoops(1), InnerTeamsRegionLoc() {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 129 | }; |
| 130 | |
Axel Naumann | 323862e | 2016-02-03 10:45:22 +0000 | [diff] [blame] | 131 | typedef SmallVector<SharingMapTy, 4> StackTy; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 132 | |
| 133 | /// \brief Stack of used declaration and their data-sharing attributes. |
| 134 | StackTy Stack; |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 135 | /// \brief true, if check for DSA must be from parent directive, false, if |
| 136 | /// from current directive. |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 137 | OpenMPClauseKind ClauseKindMode; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 138 | Sema &SemaRef; |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 139 | bool ForceCapturing; |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 140 | CriticalsWithHintsTy Criticals; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 141 | |
| 142 | typedef SmallVector<SharingMapTy, 8>::reverse_iterator reverse_iterator; |
| 143 | |
Dmitry Polukhin | dc78bc82 | 2016-04-01 09:52:30 +0000 | [diff] [blame] | 144 | DSAVarData getDSA(StackTy::reverse_iterator& Iter, ValueDecl *D); |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 145 | |
| 146 | /// \brief Checks if the variable is a local for OpenMP region. |
| 147 | bool isOpenMPLocal(VarDecl *D, StackTy::reverse_iterator Iter); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 148 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 149 | public: |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 150 | explicit DSAStackTy(Sema &S) |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 151 | : Stack(1), ClauseKindMode(OMPC_unknown), SemaRef(S), |
| 152 | ForceCapturing(false) {} |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 153 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 154 | bool isClauseParsingMode() const { return ClauseKindMode != OMPC_unknown; } |
| 155 | void setClauseParsingMode(OpenMPClauseKind K) { ClauseKindMode = K; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 156 | |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 157 | bool isForceVarCapturing() const { return ForceCapturing; } |
| 158 | void setForceVarCapturing(bool V) { ForceCapturing = V; } |
| 159 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 160 | void push(OpenMPDirectiveKind DKind, const DeclarationNameInfo &DirName, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 161 | Scope *CurScope, SourceLocation Loc) { |
| 162 | Stack.push_back(SharingMapTy(DKind, DirName, CurScope, Loc)); |
| 163 | Stack.back().DefaultAttrLoc = Loc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | void pop() { |
| 167 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty!"); |
| 168 | Stack.pop_back(); |
| 169 | } |
| 170 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 171 | void addCriticalWithHint(OMPCriticalDirective *D, llvm::APSInt Hint) { |
| 172 | Criticals[D->getDirectiveName().getAsString()] = std::make_pair(D, Hint); |
| 173 | } |
| 174 | const std::pair<OMPCriticalDirective *, llvm::APSInt> |
| 175 | getCriticalWithHint(const DeclarationNameInfo &Name) const { |
| 176 | auto I = Criticals.find(Name.getAsString()); |
| 177 | if (I != Criticals.end()) |
| 178 | return I->second; |
| 179 | return std::make_pair(nullptr, llvm::APSInt()); |
| 180 | } |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 181 | /// \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] | 182 | /// add it and return NULL; otherwise return previous occurrence's expression |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 183 | /// for diagnostics. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 184 | Expr *addUniqueAligned(ValueDecl *D, Expr *NewDE); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 185 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 186 | /// \brief Register specified variable as loop control variable. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 187 | void addLoopControlVariable(ValueDecl *D, VarDecl *Capture); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 188 | /// \brief Check if the specified variable is a loop control variable for |
| 189 | /// current region. |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 190 | /// \return The index of the loop control variable in the list of associated |
| 191 | /// for-loops (from outer to inner). |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 192 | LCDeclInfo isLoopControlVariable(ValueDecl *D); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 193 | /// \brief Check if the specified variable is a loop control variable for |
| 194 | /// parent region. |
| 195 | /// \return The index of the loop control variable in the list of associated |
| 196 | /// for-loops (from outer to inner). |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 197 | LCDeclInfo isParentLoopControlVariable(ValueDecl *D); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 198 | /// \brief Get the loop control variable for the I-th loop (or nullptr) in |
| 199 | /// parent directive. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 200 | ValueDecl *getParentLoopControlVariable(unsigned I); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 201 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 202 | /// \brief Adds explicit data sharing attribute to the specified declaration. |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 203 | void addDSA(ValueDecl *D, Expr *E, OpenMPClauseKind A, |
| 204 | DeclRefExpr *PrivateCopy = nullptr); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 205 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 206 | /// \brief Returns data sharing attributes from top of the stack for the |
| 207 | /// specified declaration. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 208 | DSAVarData getTopDSA(ValueDecl *D, bool FromParent); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 209 | /// \brief Returns data-sharing attributes for the specified declaration. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 210 | DSAVarData getImplicitDSA(ValueDecl *D, bool FromParent); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 211 | /// \brief Checks if the specified variables has data-sharing attributes which |
| 212 | /// match specified \a CPred predicate in any directive which matches \a DPred |
| 213 | /// predicate. |
| 214 | template <class ClausesPredicate, class DirectivesPredicate> |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 215 | DSAVarData hasDSA(ValueDecl *D, ClausesPredicate CPred, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 216 | DirectivesPredicate DPred, bool FromParent); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 217 | /// \brief Checks if the specified variables has data-sharing attributes which |
| 218 | /// match specified \a CPred predicate in any innermost directive which |
| 219 | /// matches \a DPred predicate. |
| 220 | template <class ClausesPredicate, class DirectivesPredicate> |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 221 | DSAVarData hasInnermostDSA(ValueDecl *D, ClausesPredicate CPred, |
| 222 | DirectivesPredicate DPred, bool FromParent); |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 223 | /// \brief Checks if the specified variables has explicit data-sharing |
| 224 | /// attributes which match specified \a CPred predicate at the specified |
| 225 | /// OpenMP region. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 226 | bool hasExplicitDSA(ValueDecl *D, |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 227 | const llvm::function_ref<bool(OpenMPClauseKind)> &CPred, |
| 228 | unsigned Level); |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 229 | |
| 230 | /// \brief Returns true if the directive at level \Level matches in the |
| 231 | /// specified \a DPred predicate. |
| 232 | bool hasExplicitDirective( |
| 233 | const llvm::function_ref<bool(OpenMPDirectiveKind)> &DPred, |
| 234 | unsigned Level); |
| 235 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 236 | /// \brief Finds a directive which matches specified \a DPred predicate. |
| 237 | template <class NamedDirectivesPredicate> |
| 238 | bool hasDirective(NamedDirectivesPredicate DPred, bool FromParent); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 239 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 240 | /// \brief Returns currently analyzed directive. |
| 241 | OpenMPDirectiveKind getCurrentDirective() const { |
| 242 | return Stack.back().Directive; |
| 243 | } |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 244 | /// \brief Returns parent directive. |
| 245 | OpenMPDirectiveKind getParentDirective() const { |
| 246 | if (Stack.size() > 2) |
| 247 | return Stack[Stack.size() - 2].Directive; |
| 248 | return OMPD_unknown; |
| 249 | } |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 250 | /// \brief Return the directive associated with the provided scope. |
| 251 | OpenMPDirectiveKind getDirectiveForScope(const Scope *S) const; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 252 | |
| 253 | /// \brief Set default data sharing attribute to none. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 254 | void setDefaultDSANone(SourceLocation Loc) { |
| 255 | Stack.back().DefaultAttr = DSA_none; |
| 256 | Stack.back().DefaultAttrLoc = Loc; |
| 257 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 258 | /// \brief Set default data sharing attribute to shared. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 259 | void setDefaultDSAShared(SourceLocation Loc) { |
| 260 | Stack.back().DefaultAttr = DSA_shared; |
| 261 | Stack.back().DefaultAttrLoc = Loc; |
| 262 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 263 | |
| 264 | DefaultDataSharingAttributes getDefaultDSA() const { |
| 265 | return Stack.back().DefaultAttr; |
| 266 | } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 267 | SourceLocation getDefaultDSALocation() const { |
| 268 | return Stack.back().DefaultAttrLoc; |
| 269 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 270 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 271 | /// \brief Checks if the specified variable is a threadprivate. |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 272 | bool isThreadPrivate(VarDecl *D) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 273 | DSAVarData DVar = getTopDSA(D, false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 274 | return isOpenMPThreadPrivate(DVar.CKind); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 275 | } |
| 276 | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 277 | /// \brief Marks current region as ordered (it has an 'ordered' clause). |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 278 | void setOrderedRegion(bool IsOrdered, Expr *Param) { |
| 279 | Stack.back().OrderedRegion.setInt(IsOrdered); |
| 280 | Stack.back().OrderedRegion.setPointer(Param); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 281 | } |
| 282 | /// \brief Returns true, if parent region is ordered (has associated |
| 283 | /// 'ordered' clause), false - otherwise. |
| 284 | bool isParentOrderedRegion() const { |
| 285 | if (Stack.size() > 2) |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 286 | return Stack[Stack.size() - 2].OrderedRegion.getInt(); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 287 | return false; |
| 288 | } |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 289 | /// \brief Returns optional parameter for the ordered region. |
| 290 | Expr *getParentOrderedRegionParam() const { |
| 291 | if (Stack.size() > 2) |
| 292 | return Stack[Stack.size() - 2].OrderedRegion.getPointer(); |
| 293 | return nullptr; |
| 294 | } |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 295 | /// \brief Marks current region as nowait (it has a 'nowait' clause). |
| 296 | void setNowaitRegion(bool IsNowait = true) { |
| 297 | Stack.back().NowaitRegion = IsNowait; |
| 298 | } |
| 299 | /// \brief Returns true, if parent region is nowait (has associated |
| 300 | /// 'nowait' clause), false - otherwise. |
| 301 | bool isParentNowaitRegion() const { |
| 302 | if (Stack.size() > 2) |
| 303 | return Stack[Stack.size() - 2].NowaitRegion; |
| 304 | return false; |
| 305 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 306 | /// \brief Marks parent region as cancel region. |
| 307 | void setParentCancelRegion(bool Cancel = true) { |
| 308 | if (Stack.size() > 2) |
| 309 | Stack[Stack.size() - 2].CancelRegion = |
| 310 | Stack[Stack.size() - 2].CancelRegion || Cancel; |
| 311 | } |
| 312 | /// \brief Return true if current region has inner cancel construct. |
| 313 | bool isCancelRegion() const { |
| 314 | return Stack.back().CancelRegion; |
| 315 | } |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 316 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 317 | /// \brief Set collapse value for the region. |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 318 | void setAssociatedLoops(unsigned Val) { Stack.back().AssociatedLoops = Val; } |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 319 | /// \brief Return collapse value for region. |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 320 | unsigned getAssociatedLoops() const { return Stack.back().AssociatedLoops; } |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 321 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 322 | /// \brief Marks current target region as one with closely nested teams |
| 323 | /// region. |
| 324 | void setParentTeamsRegionLoc(SourceLocation TeamsRegionLoc) { |
| 325 | if (Stack.size() > 2) |
| 326 | Stack[Stack.size() - 2].InnerTeamsRegionLoc = TeamsRegionLoc; |
| 327 | } |
| 328 | /// \brief Returns true, if current region has closely nested teams region. |
| 329 | bool hasInnerTeamsRegion() const { |
| 330 | return getInnerTeamsRegionLoc().isValid(); |
| 331 | } |
| 332 | /// \brief Returns location of the nested teams region (if any). |
| 333 | SourceLocation getInnerTeamsRegionLoc() const { |
| 334 | if (Stack.size() > 1) |
| 335 | return Stack.back().InnerTeamsRegionLoc; |
| 336 | return SourceLocation(); |
| 337 | } |
| 338 | |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 339 | Scope *getCurScope() const { return Stack.back().CurScope; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 340 | Scope *getCurScope() { return Stack.back().CurScope; } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 341 | SourceLocation getConstructLoc() { return Stack.back().ConstructLoc; } |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 342 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 343 | // Do the check specified in MapInfoCheck and return true if any issue is |
| 344 | // found. |
| 345 | template <class MapInfoCheck> |
| 346 | bool checkMapInfoForVar(ValueDecl *VD, bool CurrentRegionOnly, |
| 347 | MapInfoCheck Check) { |
| 348 | auto SI = Stack.rbegin(); |
| 349 | auto SE = Stack.rend(); |
| 350 | |
| 351 | if (SI == SE) |
| 352 | return false; |
| 353 | |
| 354 | if (CurrentRegionOnly) { |
| 355 | SE = std::next(SI); |
| 356 | } else { |
| 357 | ++SI; |
| 358 | } |
| 359 | |
| 360 | for (; SI != SE; ++SI) { |
| 361 | auto MI = SI->MappedDecls.find(VD); |
| 362 | if (MI != SI->MappedDecls.end()) { |
| 363 | for (Expr *E : MI->second) { |
| 364 | if (Check(E)) |
| 365 | return true; |
| 366 | } |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 367 | } |
| 368 | } |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 369 | return false; |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 370 | } |
| 371 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 372 | void addExprToVarMapInfo(ValueDecl *VD, Expr *E) { |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 373 | if (Stack.size() > 1) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 374 | Stack.back().MappedDecls[VD].push_back(E); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 375 | } |
| 376 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 377 | }; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 378 | bool isParallelOrTaskRegion(OpenMPDirectiveKind DKind) { |
| 379 | return isOpenMPParallelDirective(DKind) || DKind == OMPD_task || |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 380 | isOpenMPTeamsDirective(DKind) || DKind == OMPD_unknown || |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 381 | isOpenMPTaskLoopDirective(DKind); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 382 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 383 | } // namespace |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 384 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 385 | static ValueDecl *getCanonicalDecl(ValueDecl *D) { |
| 386 | auto *VD = dyn_cast<VarDecl>(D); |
| 387 | auto *FD = dyn_cast<FieldDecl>(D); |
| 388 | if (VD != nullptr) { |
| 389 | VD = VD->getCanonicalDecl(); |
| 390 | D = VD; |
| 391 | } else { |
| 392 | assert(FD); |
| 393 | FD = FD->getCanonicalDecl(); |
| 394 | D = FD; |
| 395 | } |
| 396 | return D; |
| 397 | } |
| 398 | |
Dmitry Polukhin | dc78bc82 | 2016-04-01 09:52:30 +0000 | [diff] [blame] | 399 | DSAStackTy::DSAVarData DSAStackTy::getDSA(StackTy::reverse_iterator& Iter, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 400 | ValueDecl *D) { |
| 401 | D = getCanonicalDecl(D); |
| 402 | auto *VD = dyn_cast<VarDecl>(D); |
| 403 | auto *FD = dyn_cast<FieldDecl>(D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 404 | DSAVarData DVar; |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 405 | if (Iter == std::prev(Stack.rend())) { |
Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 406 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 407 | // in a region but not in construct] |
| 408 | // File-scope or namespace-scope variables referenced in called routines |
| 409 | // in the region are shared unless they appear in a threadprivate |
| 410 | // directive. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 411 | if (VD && !VD->isFunctionOrMethodVarDecl() && !isa<ParmVarDecl>(D)) |
Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 412 | DVar.CKind = OMPC_shared; |
| 413 | |
| 414 | // OpenMP [2.9.1.2, Data-sharing Attribute Rules for Variables Referenced |
| 415 | // in a region but not in construct] |
| 416 | // Variables with static storage duration that are declared in called |
| 417 | // routines in the region are shared. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 418 | if (VD && VD->hasGlobalStorage()) |
| 419 | DVar.CKind = OMPC_shared; |
| 420 | |
| 421 | // Non-static data members are shared by default. |
| 422 | if (FD) |
Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 423 | DVar.CKind = OMPC_shared; |
| 424 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 425 | return DVar; |
| 426 | } |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 427 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 428 | DVar.DKind = Iter->Directive; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 429 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 430 | // in a Construct, C/C++, predetermined, p.1] |
| 431 | // Variables with automatic storage duration that are declared in a scope |
| 432 | // inside the construct are private. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 433 | if (VD && isOpenMPLocal(VD, Iter) && VD->isLocalVarDecl() && |
| 434 | (VD->getStorageClass() == SC_Auto || VD->getStorageClass() == SC_None)) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 435 | DVar.CKind = OMPC_private; |
| 436 | return DVar; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 437 | } |
| 438 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 439 | // Explicitly specified attributes and local variables with predetermined |
| 440 | // attributes. |
| 441 | if (Iter->SharingMap.count(D)) { |
| 442 | DVar.RefExpr = Iter->SharingMap[D].RefExpr; |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 443 | DVar.PrivateCopy = Iter->SharingMap[D].PrivateCopy; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 444 | DVar.CKind = Iter->SharingMap[D].Attributes; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 445 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 446 | return DVar; |
| 447 | } |
| 448 | |
| 449 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 450 | // in a Construct, C/C++, implicitly determined, p.1] |
| 451 | // In a parallel or task construct, the data-sharing attributes of these |
| 452 | // variables are determined by the default clause, if present. |
| 453 | switch (Iter->DefaultAttr) { |
| 454 | case DSA_shared: |
| 455 | DVar.CKind = OMPC_shared; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 456 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 457 | return DVar; |
| 458 | case DSA_none: |
| 459 | return DVar; |
| 460 | case DSA_unspecified: |
| 461 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 462 | // in a Construct, implicitly determined, p.2] |
| 463 | // In a parallel construct, if no default clause is present, these |
| 464 | // variables are shared. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 465 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 466 | if (isOpenMPParallelDirective(DVar.DKind) || |
| 467 | isOpenMPTeamsDirective(DVar.DKind)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 468 | DVar.CKind = OMPC_shared; |
| 469 | return DVar; |
| 470 | } |
| 471 | |
| 472 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 473 | // in a Construct, implicitly determined, p.4] |
| 474 | // In a task construct, if no default clause is present, a variable that in |
| 475 | // the enclosing context is determined to be shared by all implicit tasks |
| 476 | // bound to the current team is shared. |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 477 | if (DVar.DKind == OMPD_task) { |
| 478 | DSAVarData DVarTemp; |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 479 | for (StackTy::reverse_iterator I = std::next(Iter), EE = Stack.rend(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 480 | I != EE; ++I) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 481 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables |
| 482 | // Referenced |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 483 | // in a Construct, implicitly determined, p.6] |
| 484 | // In a task construct, if no default clause is present, a variable |
| 485 | // whose data-sharing attribute is not determined by the rules above is |
| 486 | // firstprivate. |
| 487 | DVarTemp = getDSA(I, D); |
| 488 | if (DVarTemp.CKind != OMPC_shared) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 489 | DVar.RefExpr = nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 490 | DVar.DKind = OMPD_task; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 491 | DVar.CKind = OMPC_firstprivate; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 492 | return DVar; |
| 493 | } |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 494 | if (isParallelOrTaskRegion(I->Directive)) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 495 | break; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 496 | } |
| 497 | DVar.DKind = OMPD_task; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 498 | DVar.CKind = |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 499 | (DVarTemp.CKind == OMPC_unknown) ? OMPC_firstprivate : OMPC_shared; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 500 | return DVar; |
| 501 | } |
| 502 | } |
| 503 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 504 | // in a Construct, implicitly determined, p.3] |
| 505 | // For constructs other than task, if no default clause is present, these |
| 506 | // variables inherit their data-sharing attributes from the enclosing |
| 507 | // context. |
Dmitry Polukhin | dc78bc82 | 2016-04-01 09:52:30 +0000 | [diff] [blame] | 508 | return getDSA(++Iter, D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 509 | } |
| 510 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 511 | Expr *DSAStackTy::addUniqueAligned(ValueDecl *D, Expr *NewDE) { |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 512 | assert(Stack.size() > 1 && "Data sharing attributes stack is empty"); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 513 | D = getCanonicalDecl(D); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 514 | auto It = Stack.back().AlignedMap.find(D); |
| 515 | if (It == Stack.back().AlignedMap.end()) { |
| 516 | assert(NewDE && "Unexpected nullptr expr to be added into aligned map"); |
| 517 | Stack.back().AlignedMap[D] = NewDE; |
| 518 | return nullptr; |
| 519 | } else { |
| 520 | assert(It->second && "Unexpected nullptr expr in the aligned map"); |
| 521 | return It->second; |
| 522 | } |
| 523 | return nullptr; |
| 524 | } |
| 525 | |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 526 | void DSAStackTy::addLoopControlVariable(ValueDecl *D, VarDecl *Capture) { |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 527 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 528 | D = getCanonicalDecl(D); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 529 | Stack.back().LCVMap.insert( |
| 530 | std::make_pair(D, LCDeclInfo(Stack.back().LCVMap.size() + 1, Capture))); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 531 | } |
| 532 | |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 533 | DSAStackTy::LCDeclInfo DSAStackTy::isLoopControlVariable(ValueDecl *D) { |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 534 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 535 | D = getCanonicalDecl(D); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 536 | return Stack.back().LCVMap.count(D) > 0 ? Stack.back().LCVMap[D] |
| 537 | : LCDeclInfo(0, nullptr); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 538 | } |
| 539 | |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 540 | DSAStackTy::LCDeclInfo DSAStackTy::isParentLoopControlVariable(ValueDecl *D) { |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 541 | assert(Stack.size() > 2 && "Data-sharing attributes stack is empty"); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 542 | D = getCanonicalDecl(D); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 543 | return Stack[Stack.size() - 2].LCVMap.count(D) > 0 |
| 544 | ? Stack[Stack.size() - 2].LCVMap[D] |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 545 | : LCDeclInfo(0, nullptr); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 546 | } |
| 547 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 548 | ValueDecl *DSAStackTy::getParentLoopControlVariable(unsigned I) { |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 549 | assert(Stack.size() > 2 && "Data-sharing attributes stack is empty"); |
| 550 | if (Stack[Stack.size() - 2].LCVMap.size() < I) |
| 551 | return nullptr; |
| 552 | for (auto &Pair : Stack[Stack.size() - 2].LCVMap) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 553 | if (Pair.second.first == I) |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 554 | return Pair.first; |
| 555 | } |
| 556 | return nullptr; |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 557 | } |
| 558 | |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 559 | void DSAStackTy::addDSA(ValueDecl *D, Expr *E, OpenMPClauseKind A, |
| 560 | DeclRefExpr *PrivateCopy) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 561 | D = getCanonicalDecl(D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 562 | if (A == OMPC_threadprivate) { |
| 563 | Stack[0].SharingMap[D].Attributes = A; |
| 564 | Stack[0].SharingMap[D].RefExpr = E; |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 565 | Stack[0].SharingMap[D].PrivateCopy = nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 566 | } else { |
| 567 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); |
| 568 | Stack.back().SharingMap[D].Attributes = A; |
| 569 | Stack.back().SharingMap[D].RefExpr = E; |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 570 | Stack.back().SharingMap[D].PrivateCopy = PrivateCopy; |
| 571 | if (PrivateCopy) |
| 572 | addDSA(PrivateCopy->getDecl(), PrivateCopy, A); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 573 | } |
| 574 | } |
| 575 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 576 | bool DSAStackTy::isOpenMPLocal(VarDecl *D, StackTy::reverse_iterator Iter) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 577 | D = D->getCanonicalDecl(); |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 578 | if (Stack.size() > 2) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 579 | reverse_iterator I = Iter, E = std::prev(Stack.rend()); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 580 | Scope *TopScope = nullptr; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 581 | while (I != E && !isParallelOrTaskRegion(I->Directive)) { |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 582 | ++I; |
| 583 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 584 | if (I == E) |
| 585 | return false; |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 586 | TopScope = I->CurScope ? I->CurScope->getParent() : nullptr; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 587 | Scope *CurScope = getCurScope(); |
| 588 | while (CurScope != TopScope && !CurScope->isDeclScope(D)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 589 | CurScope = CurScope->getParent(); |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 590 | } |
| 591 | return CurScope != TopScope; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 592 | } |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 593 | return false; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 594 | } |
| 595 | |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 596 | /// \brief Build a variable declaration for OpenMP loop iteration variable. |
| 597 | static VarDecl *buildVarDecl(Sema &SemaRef, SourceLocation Loc, QualType Type, |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 598 | StringRef Name, const AttrVec *Attrs = nullptr) { |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 599 | DeclContext *DC = SemaRef.CurContext; |
| 600 | IdentifierInfo *II = &SemaRef.PP.getIdentifierTable().get(Name); |
| 601 | TypeSourceInfo *TInfo = SemaRef.Context.getTrivialTypeSourceInfo(Type, Loc); |
| 602 | VarDecl *Decl = |
| 603 | VarDecl::Create(SemaRef.Context, DC, Loc, Loc, II, Type, TInfo, SC_None); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 604 | if (Attrs) { |
| 605 | for (specific_attr_iterator<AlignedAttr> I(Attrs->begin()), E(Attrs->end()); |
| 606 | I != E; ++I) |
| 607 | Decl->addAttr(*I); |
| 608 | } |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 609 | Decl->setImplicit(); |
| 610 | return Decl; |
| 611 | } |
| 612 | |
| 613 | static DeclRefExpr *buildDeclRefExpr(Sema &S, VarDecl *D, QualType Ty, |
| 614 | SourceLocation Loc, |
| 615 | bool RefersToCapture = false) { |
| 616 | D->setReferenced(); |
| 617 | D->markUsed(S.Context); |
| 618 | return DeclRefExpr::Create(S.getASTContext(), NestedNameSpecifierLoc(), |
| 619 | SourceLocation(), D, RefersToCapture, Loc, Ty, |
| 620 | VK_LValue); |
| 621 | } |
| 622 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 623 | DSAStackTy::DSAVarData DSAStackTy::getTopDSA(ValueDecl *D, bool FromParent) { |
| 624 | D = getCanonicalDecl(D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 625 | DSAVarData DVar; |
| 626 | |
| 627 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 628 | // in a Construct, C/C++, predetermined, p.1] |
| 629 | // Variables appearing in threadprivate directives are threadprivate. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 630 | auto *VD = dyn_cast<VarDecl>(D); |
| 631 | if ((VD && VD->getTLSKind() != VarDecl::TLS_None && |
| 632 | !(VD->hasAttr<OMPThreadPrivateDeclAttr>() && |
Samuel Antao | f8b5012 | 2015-07-13 22:54:53 +0000 | [diff] [blame] | 633 | SemaRef.getLangOpts().OpenMPUseTLS && |
| 634 | SemaRef.getASTContext().getTargetInfo().isTLSSupported())) || |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 635 | (VD && VD->getStorageClass() == SC_Register && |
| 636 | VD->hasAttr<AsmLabelAttr>() && !VD->isLocalVarDecl())) { |
| 637 | addDSA(D, buildDeclRefExpr(SemaRef, VD, D->getType().getNonReferenceType(), |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 638 | D->getLocation()), |
Alexey Bataev | f2453a0 | 2015-05-06 07:25:08 +0000 | [diff] [blame] | 639 | OMPC_threadprivate); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 640 | } |
| 641 | if (Stack[0].SharingMap.count(D)) { |
| 642 | DVar.RefExpr = Stack[0].SharingMap[D].RefExpr; |
| 643 | DVar.CKind = OMPC_threadprivate; |
| 644 | return DVar; |
| 645 | } |
| 646 | |
| 647 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
Alexey Bataev | dffa93a | 2015-12-10 08:20:58 +0000 | [diff] [blame] | 648 | // in a Construct, C/C++, predetermined, p.4] |
| 649 | // Static data members are shared. |
| 650 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 651 | // in a Construct, C/C++, predetermined, p.7] |
| 652 | // Variables with static storage duration that are declared in a scope |
| 653 | // inside the construct are shared. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 654 | if (VD && VD->isStaticDataMember()) { |
Alexey Bataev | dffa93a | 2015-12-10 08:20:58 +0000 | [diff] [blame] | 655 | DSAVarData DVarTemp = |
| 656 | hasDSA(D, isOpenMPPrivate, MatchesAlways(), FromParent); |
| 657 | if (DVarTemp.CKind != OMPC_unknown && DVarTemp.RefExpr) |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 658 | return DVar; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 659 | |
Alexey Bataev | dffa93a | 2015-12-10 08:20:58 +0000 | [diff] [blame] | 660 | DVar.CKind = OMPC_shared; |
| 661 | return DVar; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 662 | } |
| 663 | |
| 664 | QualType Type = D->getType().getNonReferenceType().getCanonicalType(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 665 | bool IsConstant = Type.isConstant(SemaRef.getASTContext()); |
| 666 | Type = SemaRef.getASTContext().getBaseElementType(Type); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 667 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 668 | // in a Construct, C/C++, predetermined, p.6] |
| 669 | // Variables with const qualified type having no mutable member are |
| 670 | // shared. |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 671 | CXXRecordDecl *RD = |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 672 | SemaRef.getLangOpts().CPlusPlus ? Type->getAsCXXRecordDecl() : nullptr; |
Alexey Bataev | c9bd03d | 2015-12-17 06:55:08 +0000 | [diff] [blame] | 673 | if (auto *CTSD = dyn_cast_or_null<ClassTemplateSpecializationDecl>(RD)) |
| 674 | if (auto *CTD = CTSD->getSpecializedTemplate()) |
| 675 | RD = CTD->getTemplatedDecl(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 676 | if (IsConstant && |
Alexey Bataev | 4bcad7f | 2016-02-10 10:50:12 +0000 | [diff] [blame] | 677 | !(SemaRef.getLangOpts().CPlusPlus && RD && RD->hasDefinition() && |
| 678 | RD->hasMutableFields())) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 679 | // Variables with const-qualified type having no mutable member may be |
| 680 | // listed in a firstprivate clause, even if they are static data members. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 681 | DSAVarData DVarTemp = hasDSA(D, MatchesAnyClause(OMPC_firstprivate), |
| 682 | MatchesAlways(), FromParent); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 683 | if (DVarTemp.CKind == OMPC_firstprivate && DVarTemp.RefExpr) |
| 684 | return DVar; |
| 685 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 686 | DVar.CKind = OMPC_shared; |
| 687 | return DVar; |
| 688 | } |
| 689 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 690 | // Explicitly specified attributes and local variables with predetermined |
| 691 | // attributes. |
Alexey Bataev | dffa93a | 2015-12-10 08:20:58 +0000 | [diff] [blame] | 692 | auto StartI = std::next(Stack.rbegin()); |
| 693 | auto EndI = std::prev(Stack.rend()); |
| 694 | if (FromParent && StartI != EndI) { |
| 695 | StartI = std::next(StartI); |
| 696 | } |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 697 | auto I = std::prev(StartI); |
| 698 | if (I->SharingMap.count(D)) { |
| 699 | DVar.RefExpr = I->SharingMap[D].RefExpr; |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 700 | DVar.PrivateCopy = I->SharingMap[D].PrivateCopy; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 701 | DVar.CKind = I->SharingMap[D].Attributes; |
| 702 | DVar.ImplicitDSALoc = I->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 703 | } |
| 704 | |
| 705 | return DVar; |
| 706 | } |
| 707 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 708 | DSAStackTy::DSAVarData DSAStackTy::getImplicitDSA(ValueDecl *D, |
| 709 | bool FromParent) { |
| 710 | D = getCanonicalDecl(D); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 711 | auto StartI = Stack.rbegin(); |
| 712 | auto EndI = std::prev(Stack.rend()); |
| 713 | if (FromParent && StartI != EndI) { |
| 714 | StartI = std::next(StartI); |
| 715 | } |
| 716 | return getDSA(StartI, D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 717 | } |
| 718 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 719 | template <class ClausesPredicate, class DirectivesPredicate> |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 720 | DSAStackTy::DSAVarData DSAStackTy::hasDSA(ValueDecl *D, ClausesPredicate CPred, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 721 | DirectivesPredicate DPred, |
| 722 | bool FromParent) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 723 | D = getCanonicalDecl(D); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 724 | auto StartI = std::next(Stack.rbegin()); |
Dmitry Polukhin | dc78bc82 | 2016-04-01 09:52:30 +0000 | [diff] [blame] | 725 | auto EndI = Stack.rend(); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 726 | if (FromParent && StartI != EndI) { |
| 727 | StartI = std::next(StartI); |
| 728 | } |
| 729 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
| 730 | if (!DPred(I->Directive) && !isParallelOrTaskRegion(I->Directive)) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 731 | continue; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 732 | DSAVarData DVar = getDSA(I, D); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 733 | if (CPred(DVar.CKind)) |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 734 | return DVar; |
| 735 | } |
| 736 | return DSAVarData(); |
| 737 | } |
| 738 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 739 | template <class ClausesPredicate, class DirectivesPredicate> |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 740 | DSAStackTy::DSAVarData |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 741 | DSAStackTy::hasInnermostDSA(ValueDecl *D, ClausesPredicate CPred, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 742 | DirectivesPredicate DPred, bool FromParent) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 743 | D = getCanonicalDecl(D); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 744 | auto StartI = std::next(Stack.rbegin()); |
Dmitry Polukhin | dc78bc82 | 2016-04-01 09:52:30 +0000 | [diff] [blame] | 745 | auto EndI = Stack.rend(); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 746 | if (FromParent && StartI != EndI) { |
| 747 | StartI = std::next(StartI); |
| 748 | } |
| 749 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 750 | if (!DPred(I->Directive)) |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 751 | break; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 752 | DSAVarData DVar = getDSA(I, D); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 753 | if (CPred(DVar.CKind)) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 754 | return DVar; |
| 755 | return DSAVarData(); |
| 756 | } |
| 757 | return DSAVarData(); |
| 758 | } |
| 759 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 760 | bool DSAStackTy::hasExplicitDSA( |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 761 | ValueDecl *D, const llvm::function_ref<bool(OpenMPClauseKind)> &CPred, |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 762 | unsigned Level) { |
| 763 | if (CPred(ClauseKindMode)) |
| 764 | return true; |
| 765 | if (isClauseParsingMode()) |
| 766 | ++Level; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 767 | D = getCanonicalDecl(D); |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 768 | auto StartI = Stack.rbegin(); |
| 769 | auto EndI = std::prev(Stack.rend()); |
NAKAMURA Takumi | 0332eda | 2015-06-23 10:01:20 +0000 | [diff] [blame] | 770 | if (std::distance(StartI, EndI) <= (int)Level) |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 771 | return false; |
| 772 | std::advance(StartI, Level); |
| 773 | return (StartI->SharingMap.count(D) > 0) && StartI->SharingMap[D].RefExpr && |
| 774 | CPred(StartI->SharingMap[D].Attributes); |
| 775 | } |
| 776 | |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 777 | bool DSAStackTy::hasExplicitDirective( |
| 778 | const llvm::function_ref<bool(OpenMPDirectiveKind)> &DPred, |
| 779 | unsigned Level) { |
| 780 | if (isClauseParsingMode()) |
| 781 | ++Level; |
| 782 | auto StartI = Stack.rbegin(); |
| 783 | auto EndI = std::prev(Stack.rend()); |
| 784 | if (std::distance(StartI, EndI) <= (int)Level) |
| 785 | return false; |
| 786 | std::advance(StartI, Level); |
| 787 | return DPred(StartI->Directive); |
| 788 | } |
| 789 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 790 | template <class NamedDirectivesPredicate> |
| 791 | bool DSAStackTy::hasDirective(NamedDirectivesPredicate DPred, bool FromParent) { |
| 792 | auto StartI = std::next(Stack.rbegin()); |
| 793 | auto EndI = std::prev(Stack.rend()); |
| 794 | if (FromParent && StartI != EndI) { |
| 795 | StartI = std::next(StartI); |
| 796 | } |
| 797 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
| 798 | if (DPred(I->Directive, I->DirectiveName, I->ConstructLoc)) |
| 799 | return true; |
| 800 | } |
| 801 | return false; |
| 802 | } |
| 803 | |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 804 | OpenMPDirectiveKind DSAStackTy::getDirectiveForScope(const Scope *S) const { |
| 805 | for (auto I = Stack.rbegin(), EE = Stack.rend(); I != EE; ++I) |
| 806 | if (I->CurScope == S) |
| 807 | return I->Directive; |
| 808 | return OMPD_unknown; |
| 809 | } |
| 810 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 811 | void Sema::InitDataSharingAttributesStack() { |
| 812 | VarDataSharingAttributesStack = new DSAStackTy(*this); |
| 813 | } |
| 814 | |
| 815 | #define DSAStack static_cast<DSAStackTy *>(VarDataSharingAttributesStack) |
| 816 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 817 | bool Sema::IsOpenMPCapturedByRef(ValueDecl *D, |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 818 | const CapturedRegionScopeInfo *RSI) { |
| 819 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| 820 | |
| 821 | auto &Ctx = getASTContext(); |
| 822 | bool IsByRef = true; |
| 823 | |
| 824 | // Find the directive that is associated with the provided scope. |
| 825 | auto DKind = DSAStack->getDirectiveForScope(RSI->TheScope); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 826 | auto Ty = D->getType(); |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 827 | |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 828 | if (isOpenMPTargetExecutionDirective(DKind)) { |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 829 | // This table summarizes how a given variable should be passed to the device |
| 830 | // given its type and the clauses where it appears. This table is based on |
| 831 | // the description in OpenMP 4.5 [2.10.4, target Construct] and |
| 832 | // OpenMP 4.5 [2.15.5, Data-mapping Attribute Rules and Clauses]. |
| 833 | // |
| 834 | // ========================================================================= |
| 835 | // | type | defaultmap | pvt | first | is_device_ptr | map | res. | |
| 836 | // | |(tofrom:scalar)| | pvt | | | | |
| 837 | // ========================================================================= |
| 838 | // | scl | | | | - | | bycopy| |
| 839 | // | scl | | - | x | - | - | bycopy| |
| 840 | // | scl | | x | - | - | - | null | |
| 841 | // | scl | x | | | - | | byref | |
| 842 | // | scl | x | - | x | - | - | bycopy| |
| 843 | // | scl | x | x | - | - | - | null | |
| 844 | // | scl | | - | - | - | x | byref | |
| 845 | // | scl | x | - | - | - | x | byref | |
| 846 | // |
| 847 | // | agg | n.a. | | | - | | byref | |
| 848 | // | agg | n.a. | - | x | - | - | byref | |
| 849 | // | agg | n.a. | x | - | - | - | null | |
| 850 | // | agg | n.a. | - | - | - | x | byref | |
| 851 | // | agg | n.a. | - | - | - | x[] | byref | |
| 852 | // |
| 853 | // | ptr | n.a. | | | - | | bycopy| |
| 854 | // | ptr | n.a. | - | x | - | - | bycopy| |
| 855 | // | ptr | n.a. | x | - | - | - | null | |
| 856 | // | ptr | n.a. | - | - | - | x | byref | |
| 857 | // | ptr | n.a. | - | - | - | x[] | bycopy| |
| 858 | // | ptr | n.a. | - | - | x | | bycopy| |
| 859 | // | ptr | n.a. | - | - | x | x | bycopy| |
| 860 | // | ptr | n.a. | - | - | x | x[] | bycopy| |
| 861 | // ========================================================================= |
| 862 | // Legend: |
| 863 | // scl - scalar |
| 864 | // ptr - pointer |
| 865 | // agg - aggregate |
| 866 | // x - applies |
| 867 | // - - invalid in this combination |
| 868 | // [] - mapped with an array section |
| 869 | // byref - should be mapped by reference |
| 870 | // byval - should be mapped by value |
| 871 | // null - initialize a local variable to null on the device |
| 872 | // |
| 873 | // Observations: |
| 874 | // - All scalar declarations that show up in a map clause have to be passed |
| 875 | // by reference, because they may have been mapped in the enclosing data |
| 876 | // environment. |
| 877 | // - If the scalar value does not fit the size of uintptr, it has to be |
| 878 | // passed by reference, regardless the result in the table above. |
| 879 | // - For pointers mapped by value that have either an implicit map or an |
| 880 | // array section, the runtime library may pass the NULL value to the |
| 881 | // device instead of the value passed to it by the compiler. |
| 882 | |
| 883 | // FIXME: Right now, only implicit maps are implemented. Properly mapping |
| 884 | // values requires having the map, private, and firstprivate clauses SEMA |
| 885 | // and parsing in place, which we don't yet. |
| 886 | |
| 887 | if (Ty->isReferenceType()) |
| 888 | Ty = Ty->castAs<ReferenceType>()->getPointeeType(); |
| 889 | IsByRef = !Ty->isScalarType(); |
| 890 | } |
| 891 | |
| 892 | // When passing data by value, we need to make sure it fits the uintptr size |
| 893 | // and alignment, because the runtime library only deals with uintptr types. |
| 894 | // If it does not fit the uintptr size, we need to pass the data by reference |
| 895 | // instead. |
| 896 | if (!IsByRef && |
| 897 | (Ctx.getTypeSizeInChars(Ty) > |
| 898 | Ctx.getTypeSizeInChars(Ctx.getUIntPtrType()) || |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 899 | Ctx.getDeclAlign(D) > Ctx.getTypeAlignInChars(Ctx.getUIntPtrType()))) |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 900 | IsByRef = true; |
| 901 | |
| 902 | return IsByRef; |
| 903 | } |
| 904 | |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 905 | VarDecl *Sema::IsOpenMPCapturedDecl(ValueDecl *D) { |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 906 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 907 | D = getCanonicalDecl(D); |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 908 | |
| 909 | // If we are attempting to capture a global variable in a directive with |
| 910 | // 'target' we return true so that this global is also mapped to the device. |
| 911 | // |
| 912 | // FIXME: If the declaration is enclosed in a 'declare target' directive, |
| 913 | // then it should not be captured. Therefore, an extra check has to be |
| 914 | // inserted here once support for 'declare target' is added. |
| 915 | // |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 916 | auto *VD = dyn_cast<VarDecl>(D); |
| 917 | if (VD && !VD->hasLocalStorage()) { |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 918 | if (DSAStack->getCurrentDirective() == OMPD_target && |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 919 | !DSAStack->isClauseParsingMode()) |
| 920 | return VD; |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 921 | if (DSAStack->getCurScope() && |
| 922 | DSAStack->hasDirective( |
| 923 | [](OpenMPDirectiveKind K, const DeclarationNameInfo &DNI, |
| 924 | SourceLocation Loc) -> bool { |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 925 | return isOpenMPTargetExecutionDirective(K); |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 926 | }, |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 927 | false)) |
| 928 | return VD; |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 929 | } |
| 930 | |
Alexey Bataev | 48977c3 | 2015-08-04 08:10:48 +0000 | [diff] [blame] | 931 | if (DSAStack->getCurrentDirective() != OMPD_unknown && |
| 932 | (!DSAStack->isClauseParsingMode() || |
| 933 | DSAStack->getParentDirective() != OMPD_unknown)) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 934 | auto &&Info = DSAStack->isLoopControlVariable(D); |
| 935 | if (Info.first || |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 936 | (VD && VD->hasLocalStorage() && |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 937 | isParallelOrTaskRegion(DSAStack->getCurrentDirective())) || |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 938 | (VD && DSAStack->isForceVarCapturing())) |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 939 | return VD ? VD : Info.second; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 940 | auto DVarPrivate = DSAStack->getTopDSA(D, DSAStack->isClauseParsingMode()); |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 941 | if (DVarPrivate.CKind != OMPC_unknown && isOpenMPPrivate(DVarPrivate.CKind)) |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 942 | return VD ? VD : cast<VarDecl>(DVarPrivate.PrivateCopy->getDecl()); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 943 | DVarPrivate = DSAStack->hasDSA(D, isOpenMPPrivate, MatchesAlways(), |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 944 | DSAStack->isClauseParsingMode()); |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 945 | if (DVarPrivate.CKind != OMPC_unknown) |
| 946 | return VD ? VD : cast<VarDecl>(DVarPrivate.PrivateCopy->getDecl()); |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 947 | } |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 948 | return nullptr; |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 949 | } |
| 950 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 951 | bool Sema::isOpenMPPrivateDecl(ValueDecl *D, unsigned Level) { |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 952 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| 953 | return DSAStack->hasExplicitDSA( |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 954 | D, [](OpenMPClauseKind K) -> bool { return K == OMPC_private; }, Level); |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 955 | } |
| 956 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 957 | bool Sema::isOpenMPTargetCapturedDecl(ValueDecl *D, unsigned Level) { |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 958 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| 959 | // Return true if the current level is no longer enclosed in a target region. |
| 960 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 961 | auto *VD = dyn_cast<VarDecl>(D); |
| 962 | return VD && !VD->hasLocalStorage() && |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 963 | DSAStack->hasExplicitDirective(isOpenMPTargetExecutionDirective, |
| 964 | Level); |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 965 | } |
| 966 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 967 | void Sema::DestroyDataSharingAttributesStack() { delete DSAStack; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 968 | |
| 969 | void Sema::StartOpenMPDSABlock(OpenMPDirectiveKind DKind, |
| 970 | const DeclarationNameInfo &DirName, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 971 | Scope *CurScope, SourceLocation Loc) { |
| 972 | DSAStack->push(DKind, DirName, CurScope, Loc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 973 | PushExpressionEvaluationContext(PotentiallyEvaluated); |
| 974 | } |
| 975 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 976 | void Sema::StartOpenMPClause(OpenMPClauseKind K) { |
| 977 | DSAStack->setClauseParsingMode(K); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 978 | } |
| 979 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 980 | void Sema::EndOpenMPClause() { |
| 981 | DSAStack->setClauseParsingMode(/*K=*/OMPC_unknown); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 982 | } |
| 983 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 984 | void Sema::EndOpenMPDSABlock(Stmt *CurDirective) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 985 | // OpenMP [2.14.3.5, Restrictions, C/C++, p.1] |
| 986 | // A variable of class type (or array thereof) that appears in a lastprivate |
| 987 | // clause requires an accessible, unambiguous default constructor for the |
| 988 | // class type, unless the list item is also specified in a firstprivate |
| 989 | // clause. |
| 990 | if (auto D = dyn_cast_or_null<OMPExecutableDirective>(CurDirective)) { |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 991 | for (auto *C : D->clauses()) { |
| 992 | if (auto *Clause = dyn_cast<OMPLastprivateClause>(C)) { |
| 993 | SmallVector<Expr *, 8> PrivateCopies; |
| 994 | for (auto *DE : Clause->varlists()) { |
| 995 | if (DE->isValueDependent() || DE->isTypeDependent()) { |
| 996 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 997 | continue; |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 998 | } |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 999 | auto *DRE = cast<DeclRefExpr>(DE->IgnoreParens()); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 1000 | VarDecl *VD = cast<VarDecl>(DRE->getDecl()); |
| 1001 | QualType Type = VD->getType().getNonReferenceType(); |
| 1002 | auto DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1003 | if (DVar.CKind == OMPC_lastprivate) { |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1004 | // Generate helper private variable and initialize it with the |
| 1005 | // default value. The address of the original variable is replaced |
| 1006 | // by the address of the new private variable in CodeGen. This new |
| 1007 | // variable is not added to IdResolver, so the code in the OpenMP |
| 1008 | // region uses original variable for proper diagnostics. |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 1009 | auto *VDPrivate = buildVarDecl( |
| 1010 | *this, DE->getExprLoc(), Type.getUnqualifiedType(), |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 1011 | VD->getName(), VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1012 | ActOnUninitializedDecl(VDPrivate, /*TypeMayContainAuto=*/false); |
| 1013 | if (VDPrivate->isInvalidDecl()) |
| 1014 | continue; |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 1015 | PrivateCopies.push_back(buildDeclRefExpr( |
| 1016 | *this, VDPrivate, DE->getType(), DE->getExprLoc())); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1017 | } else { |
| 1018 | // The variable is also a firstprivate, so initialization sequence |
| 1019 | // for private copy is generated already. |
| 1020 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1021 | } |
| 1022 | } |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1023 | // Set initializers to private copies if no errors were found. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1024 | if (PrivateCopies.size() == Clause->varlist_size()) |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1025 | Clause->setPrivateCopies(PrivateCopies); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1026 | } |
| 1027 | } |
| 1028 | } |
| 1029 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1030 | DSAStack->pop(); |
| 1031 | DiscardCleanupsInEvaluationContext(); |
| 1032 | PopExpressionEvaluationContext(); |
| 1033 | } |
| 1034 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 1035 | static bool |
| 1036 | FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV, |
| 1037 | Expr *NumIterations, Sema &SemaRef, Scope *S); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 1038 | |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1039 | namespace { |
| 1040 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1041 | class VarDeclFilterCCC : public CorrectionCandidateCallback { |
| 1042 | private: |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1043 | Sema &SemaRef; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1044 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1045 | public: |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1046 | explicit VarDeclFilterCCC(Sema &S) : SemaRef(S) {} |
Craig Topper | e14c0f8 | 2014-03-12 04:55:44 +0000 | [diff] [blame] | 1047 | bool ValidateCandidate(const TypoCorrection &Candidate) override { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1048 | NamedDecl *ND = Candidate.getCorrectionDecl(); |
| 1049 | if (VarDecl *VD = dyn_cast_or_null<VarDecl>(ND)) { |
| 1050 | return VD->hasGlobalStorage() && |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1051 | SemaRef.isDeclInScope(ND, SemaRef.getCurLexicalContext(), |
| 1052 | SemaRef.getCurScope()); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1053 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1054 | return false; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1055 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1056 | }; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1057 | } // namespace |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1058 | |
| 1059 | ExprResult Sema::ActOnOpenMPIdExpression(Scope *CurScope, |
| 1060 | CXXScopeSpec &ScopeSpec, |
| 1061 | const DeclarationNameInfo &Id) { |
| 1062 | LookupResult Lookup(*this, Id, LookupOrdinaryName); |
| 1063 | LookupParsedName(Lookup, CurScope, &ScopeSpec, true); |
| 1064 | |
| 1065 | if (Lookup.isAmbiguous()) |
| 1066 | return ExprError(); |
| 1067 | |
| 1068 | VarDecl *VD; |
| 1069 | if (!Lookup.isSingleResult()) { |
Kaelyn Takata | 89c881b | 2014-10-27 18:07:29 +0000 | [diff] [blame] | 1070 | if (TypoCorrection Corrected = CorrectTypo( |
| 1071 | Id, LookupOrdinaryName, CurScope, nullptr, |
| 1072 | llvm::make_unique<VarDeclFilterCCC>(*this), CTK_ErrorRecovery)) { |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 1073 | diagnoseTypo(Corrected, |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 1074 | PDiag(Lookup.empty() |
| 1075 | ? diag::err_undeclared_var_use_suggest |
| 1076 | : diag::err_omp_expected_var_arg_suggest) |
| 1077 | << Id.getName()); |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 1078 | VD = Corrected.getCorrectionDeclAs<VarDecl>(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1079 | } else { |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 1080 | Diag(Id.getLoc(), Lookup.empty() ? diag::err_undeclared_var_use |
| 1081 | : diag::err_omp_expected_var_arg) |
| 1082 | << Id.getName(); |
| 1083 | return ExprError(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1084 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1085 | } else { |
| 1086 | if (!(VD = Lookup.getAsSingle<VarDecl>())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1087 | Diag(Id.getLoc(), diag::err_omp_expected_var_arg) << Id.getName(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1088 | Diag(Lookup.getFoundDecl()->getLocation(), diag::note_declared_at); |
| 1089 | return ExprError(); |
| 1090 | } |
| 1091 | } |
| 1092 | Lookup.suppressDiagnostics(); |
| 1093 | |
| 1094 | // OpenMP [2.9.2, Syntax, C/C++] |
| 1095 | // Variables must be file-scope, namespace-scope, or static block-scope. |
| 1096 | if (!VD->hasGlobalStorage()) { |
| 1097 | Diag(Id.getLoc(), diag::err_omp_global_var_arg) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1098 | << getOpenMPDirectiveName(OMPD_threadprivate) << !VD->isStaticLocal(); |
| 1099 | bool IsDecl = |
| 1100 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1101 | Diag(VD->getLocation(), |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1102 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1103 | << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1104 | return ExprError(); |
| 1105 | } |
| 1106 | |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1107 | VarDecl *CanonicalVD = VD->getCanonicalDecl(); |
| 1108 | NamedDecl *ND = cast<NamedDecl>(CanonicalVD); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1109 | // OpenMP [2.9.2, Restrictions, C/C++, p.2] |
| 1110 | // A threadprivate directive for file-scope variables must appear outside |
| 1111 | // any definition or declaration. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1112 | if (CanonicalVD->getDeclContext()->isTranslationUnit() && |
| 1113 | !getCurLexicalContext()->isTranslationUnit()) { |
| 1114 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1115 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1116 | bool IsDecl = |
| 1117 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1118 | Diag(VD->getLocation(), |
| 1119 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1120 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1121 | return ExprError(); |
| 1122 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1123 | // OpenMP [2.9.2, Restrictions, C/C++, p.3] |
| 1124 | // A threadprivate directive for static class member variables must appear |
| 1125 | // in the class definition, in the same scope in which the member |
| 1126 | // variables are declared. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1127 | if (CanonicalVD->isStaticDataMember() && |
| 1128 | !CanonicalVD->getDeclContext()->Equals(getCurLexicalContext())) { |
| 1129 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1130 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1131 | bool IsDecl = |
| 1132 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1133 | Diag(VD->getLocation(), |
| 1134 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1135 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1136 | return ExprError(); |
| 1137 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1138 | // OpenMP [2.9.2, Restrictions, C/C++, p.4] |
| 1139 | // A threadprivate directive for namespace-scope variables must appear |
| 1140 | // outside any definition or declaration other than the namespace |
| 1141 | // definition itself. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1142 | if (CanonicalVD->getDeclContext()->isNamespace() && |
| 1143 | (!getCurLexicalContext()->isFileContext() || |
| 1144 | !getCurLexicalContext()->Encloses(CanonicalVD->getDeclContext()))) { |
| 1145 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1146 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1147 | bool IsDecl = |
| 1148 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1149 | Diag(VD->getLocation(), |
| 1150 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1151 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1152 | return ExprError(); |
| 1153 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1154 | // OpenMP [2.9.2, Restrictions, C/C++, p.6] |
| 1155 | // A threadprivate directive for static block-scope variables must appear |
| 1156 | // in the scope of the variable and not in a nested scope. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1157 | if (CanonicalVD->isStaticLocal() && CurScope && |
| 1158 | !isDeclInScope(ND, getCurLexicalContext(), CurScope)) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1159 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1160 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1161 | bool IsDecl = |
| 1162 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1163 | Diag(VD->getLocation(), |
| 1164 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1165 | << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1166 | return ExprError(); |
| 1167 | } |
| 1168 | |
| 1169 | // OpenMP [2.9.2, Restrictions, C/C++, p.2-6] |
| 1170 | // A threadprivate directive must lexically precede all references to any |
| 1171 | // of the variables in its list. |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 1172 | if (VD->isUsed() && !DSAStack->isThreadPrivate(VD)) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1173 | Diag(Id.getLoc(), diag::err_omp_var_used) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1174 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1175 | return ExprError(); |
| 1176 | } |
| 1177 | |
| 1178 | QualType ExprType = VD->getType().getNonReferenceType(); |
Alexey Bataev | 376b4a4 | 2016-02-09 09:41:09 +0000 | [diff] [blame] | 1179 | return DeclRefExpr::Create(Context, NestedNameSpecifierLoc(), |
| 1180 | SourceLocation(), VD, |
| 1181 | /*RefersToEnclosingVariableOrCapture=*/false, |
| 1182 | Id.getLoc(), ExprType, VK_LValue); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1183 | } |
| 1184 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1185 | Sema::DeclGroupPtrTy |
| 1186 | Sema::ActOnOpenMPThreadprivateDirective(SourceLocation Loc, |
| 1187 | ArrayRef<Expr *> VarList) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1188 | if (OMPThreadPrivateDecl *D = CheckOMPThreadPrivateDecl(Loc, VarList)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1189 | CurContext->addDecl(D); |
| 1190 | return DeclGroupPtrTy::make(DeclGroupRef(D)); |
| 1191 | } |
David Blaikie | 0403cb1 | 2016-01-15 23:43:25 +0000 | [diff] [blame] | 1192 | return nullptr; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1193 | } |
| 1194 | |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1195 | namespace { |
| 1196 | class LocalVarRefChecker : public ConstStmtVisitor<LocalVarRefChecker, bool> { |
| 1197 | Sema &SemaRef; |
| 1198 | |
| 1199 | public: |
| 1200 | bool VisitDeclRefExpr(const DeclRefExpr *E) { |
| 1201 | if (auto VD = dyn_cast<VarDecl>(E->getDecl())) { |
| 1202 | if (VD->hasLocalStorage()) { |
| 1203 | SemaRef.Diag(E->getLocStart(), |
| 1204 | diag::err_omp_local_var_in_threadprivate_init) |
| 1205 | << E->getSourceRange(); |
| 1206 | SemaRef.Diag(VD->getLocation(), diag::note_defined_here) |
| 1207 | << VD << VD->getSourceRange(); |
| 1208 | return true; |
| 1209 | } |
| 1210 | } |
| 1211 | return false; |
| 1212 | } |
| 1213 | bool VisitStmt(const Stmt *S) { |
| 1214 | for (auto Child : S->children()) { |
| 1215 | if (Child && Visit(Child)) |
| 1216 | return true; |
| 1217 | } |
| 1218 | return false; |
| 1219 | } |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 1220 | explicit LocalVarRefChecker(Sema &SemaRef) : SemaRef(SemaRef) {} |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1221 | }; |
| 1222 | } // namespace |
| 1223 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1224 | OMPThreadPrivateDecl * |
| 1225 | Sema::CheckOMPThreadPrivateDecl(SourceLocation Loc, ArrayRef<Expr *> VarList) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1226 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1227 | for (auto &RefExpr : VarList) { |
| 1228 | DeclRefExpr *DE = cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1229 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); |
| 1230 | SourceLocation ILoc = DE->getExprLoc(); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1231 | |
Alexey Bataev | 376b4a4 | 2016-02-09 09:41:09 +0000 | [diff] [blame] | 1232 | // Mark variable as used. |
| 1233 | VD->setReferenced(); |
| 1234 | VD->markUsed(Context); |
| 1235 | |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 1236 | QualType QType = VD->getType(); |
| 1237 | if (QType->isDependentType() || QType->isInstantiationDependentType()) { |
| 1238 | // It will be analyzed later. |
| 1239 | Vars.push_back(DE); |
| 1240 | continue; |
| 1241 | } |
| 1242 | |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1243 | // OpenMP [2.9.2, Restrictions, C/C++, p.10] |
| 1244 | // A threadprivate variable must not have an incomplete type. |
| 1245 | if (RequireCompleteType(ILoc, VD->getType(), |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1246 | diag::err_omp_threadprivate_incomplete_type)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1247 | continue; |
| 1248 | } |
| 1249 | |
| 1250 | // OpenMP [2.9.2, Restrictions, C/C++, p.10] |
| 1251 | // A threadprivate variable must not have a reference type. |
| 1252 | if (VD->getType()->isReferenceType()) { |
| 1253 | Diag(ILoc, diag::err_omp_ref_type_arg) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1254 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD->getType(); |
| 1255 | bool IsDecl = |
| 1256 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1257 | Diag(VD->getLocation(), |
| 1258 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1259 | << VD; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1260 | continue; |
| 1261 | } |
| 1262 | |
Samuel Antao | f8b5012 | 2015-07-13 22:54:53 +0000 | [diff] [blame] | 1263 | // Check if this is a TLS variable. If TLS is not being supported, produce |
| 1264 | // the corresponding diagnostic. |
| 1265 | if ((VD->getTLSKind() != VarDecl::TLS_None && |
| 1266 | !(VD->hasAttr<OMPThreadPrivateDeclAttr>() && |
| 1267 | getLangOpts().OpenMPUseTLS && |
| 1268 | getASTContext().getTargetInfo().isTLSSupported())) || |
Alexey Bataev | 1a8b3f1 | 2015-05-06 06:34:55 +0000 | [diff] [blame] | 1269 | (VD->getStorageClass() == SC_Register && VD->hasAttr<AsmLabelAttr>() && |
| 1270 | !VD->isLocalVarDecl())) { |
Alexey Bataev | 26a3924 | 2015-01-13 03:35:30 +0000 | [diff] [blame] | 1271 | Diag(ILoc, diag::err_omp_var_thread_local) |
| 1272 | << VD << ((VD->getTLSKind() != VarDecl::TLS_None) ? 0 : 1); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1273 | bool IsDecl = |
| 1274 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1275 | Diag(VD->getLocation(), |
| 1276 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1277 | << VD; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1278 | continue; |
| 1279 | } |
| 1280 | |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1281 | // Check if initial value of threadprivate variable reference variable with |
| 1282 | // local storage (it is not supported by runtime). |
| 1283 | if (auto Init = VD->getAnyInitializer()) { |
| 1284 | LocalVarRefChecker Checker(*this); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1285 | if (Checker.Visit(Init)) |
| 1286 | continue; |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1287 | } |
| 1288 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1289 | Vars.push_back(RefExpr); |
Alexey Bataev | d178ad4 | 2014-03-07 08:03:37 +0000 | [diff] [blame] | 1290 | DSAStack->addDSA(VD, DE, OMPC_threadprivate); |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 1291 | VD->addAttr(OMPThreadPrivateDeclAttr::CreateImplicit( |
| 1292 | Context, SourceRange(Loc, Loc))); |
| 1293 | if (auto *ML = Context.getASTMutationListener()) |
| 1294 | ML->DeclarationMarkedOpenMPThreadPrivate(VD); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1295 | } |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 1296 | OMPThreadPrivateDecl *D = nullptr; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 1297 | if (!Vars.empty()) { |
| 1298 | D = OMPThreadPrivateDecl::Create(Context, getCurLexicalContext(), Loc, |
| 1299 | Vars); |
| 1300 | D->setAccess(AS_public); |
| 1301 | } |
| 1302 | return D; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1303 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1304 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1305 | static void ReportOriginalDSA(Sema &SemaRef, DSAStackTy *Stack, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1306 | const ValueDecl *D, DSAStackTy::DSAVarData DVar, |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1307 | bool IsLoopIterVar = false) { |
| 1308 | if (DVar.RefExpr) { |
| 1309 | SemaRef.Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_explicit_dsa) |
| 1310 | << getOpenMPClauseName(DVar.CKind); |
| 1311 | return; |
| 1312 | } |
| 1313 | enum { |
| 1314 | PDSA_StaticMemberShared, |
| 1315 | PDSA_StaticLocalVarShared, |
| 1316 | PDSA_LoopIterVarPrivate, |
| 1317 | PDSA_LoopIterVarLinear, |
| 1318 | PDSA_LoopIterVarLastprivate, |
| 1319 | PDSA_ConstVarShared, |
| 1320 | PDSA_GlobalVarShared, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1321 | PDSA_TaskVarFirstprivate, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1322 | PDSA_LocalVarPrivate, |
| 1323 | PDSA_Implicit |
| 1324 | } Reason = PDSA_Implicit; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1325 | bool ReportHint = false; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1326 | auto ReportLoc = D->getLocation(); |
| 1327 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1328 | if (IsLoopIterVar) { |
| 1329 | if (DVar.CKind == OMPC_private) |
| 1330 | Reason = PDSA_LoopIterVarPrivate; |
| 1331 | else if (DVar.CKind == OMPC_lastprivate) |
| 1332 | Reason = PDSA_LoopIterVarLastprivate; |
| 1333 | else |
| 1334 | Reason = PDSA_LoopIterVarLinear; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1335 | } else if (DVar.DKind == OMPD_task && DVar.CKind == OMPC_firstprivate) { |
| 1336 | Reason = PDSA_TaskVarFirstprivate; |
| 1337 | ReportLoc = DVar.ImplicitDSALoc; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1338 | } else if (VD && VD->isStaticLocal()) |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1339 | Reason = PDSA_StaticLocalVarShared; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1340 | else if (VD && VD->isStaticDataMember()) |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1341 | Reason = PDSA_StaticMemberShared; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1342 | else if (VD && VD->isFileVarDecl()) |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1343 | Reason = PDSA_GlobalVarShared; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1344 | else if (D->getType().isConstant(SemaRef.getASTContext())) |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1345 | Reason = PDSA_ConstVarShared; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1346 | else if (VD && VD->isLocalVarDecl() && DVar.CKind == OMPC_private) { |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1347 | ReportHint = true; |
| 1348 | Reason = PDSA_LocalVarPrivate; |
| 1349 | } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1350 | if (Reason != PDSA_Implicit) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1351 | SemaRef.Diag(ReportLoc, diag::note_omp_predetermined_dsa) |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1352 | << Reason << ReportHint |
| 1353 | << getOpenMPDirectiveName(Stack->getCurrentDirective()); |
| 1354 | } else if (DVar.ImplicitDSALoc.isValid()) { |
| 1355 | SemaRef.Diag(DVar.ImplicitDSALoc, diag::note_omp_implicit_dsa) |
| 1356 | << getOpenMPClauseName(DVar.CKind); |
| 1357 | } |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1358 | } |
| 1359 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1360 | namespace { |
| 1361 | class DSAAttrChecker : public StmtVisitor<DSAAttrChecker, void> { |
| 1362 | DSAStackTy *Stack; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1363 | Sema &SemaRef; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1364 | bool ErrorFound; |
| 1365 | CapturedStmt *CS; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1366 | llvm::SmallVector<Expr *, 8> ImplicitFirstprivate; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1367 | llvm::DenseMap<ValueDecl *, Expr *> VarsWithInheritedDSA; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1368 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1369 | public: |
| 1370 | void VisitDeclRefExpr(DeclRefExpr *E) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1371 | if (auto *VD = dyn_cast<VarDecl>(E->getDecl())) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1372 | // Skip internally declared variables. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1373 | if (VD->isLocalVarDecl() && !CS->capturesVariable(VD)) |
| 1374 | 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 DVar = Stack->getTopDSA(VD, false); |
| 1377 | // Check if the variable has explicit DSA set and stop analysis if it so. |
| 1378 | if (DVar.RefExpr) return; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1379 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1380 | auto ELoc = E->getExprLoc(); |
| 1381 | auto DKind = Stack->getCurrentDirective(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1382 | // The default(none) clause requires that each variable that is referenced |
| 1383 | // in the construct, and does not have a predetermined data-sharing |
| 1384 | // attribute, must have its data-sharing attribute explicitly determined |
| 1385 | // by being listed in a data-sharing attribute clause. |
| 1386 | if (DVar.CKind == OMPC_unknown && Stack->getDefaultDSA() == DSA_none && |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1387 | isParallelOrTaskRegion(DKind) && |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1388 | VarsWithInheritedDSA.count(VD) == 0) { |
| 1389 | VarsWithInheritedDSA[VD] = E; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1390 | return; |
| 1391 | } |
| 1392 | |
| 1393 | // OpenMP [2.9.3.6, Restrictions, p.2] |
| 1394 | // A list item that appears in a reduction clause of the innermost |
| 1395 | // enclosing worksharing or parallel construct may not be accessed in an |
| 1396 | // explicit task. |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1397 | DVar = Stack->hasInnermostDSA(VD, MatchesAnyClause(OMPC_reduction), |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1398 | [](OpenMPDirectiveKind K) -> bool { |
| 1399 | return isOpenMPParallelDirective(K) || |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1400 | isOpenMPWorksharingDirective(K) || |
| 1401 | isOpenMPTeamsDirective(K); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1402 | }, |
| 1403 | false); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1404 | if (DKind == OMPD_task && DVar.CKind == OMPC_reduction) { |
| 1405 | ErrorFound = true; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1406 | SemaRef.Diag(ELoc, diag::err_omp_reduction_in_task); |
| 1407 | ReportOriginalDSA(SemaRef, Stack, VD, DVar); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1408 | return; |
| 1409 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1410 | |
| 1411 | // Define implicit data-sharing attributes for task. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1412 | DVar = Stack->getImplicitDSA(VD, false); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1413 | if (DKind == OMPD_task && DVar.CKind != OMPC_shared) |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1414 | ImplicitFirstprivate.push_back(E); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1415 | } |
| 1416 | } |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1417 | void VisitMemberExpr(MemberExpr *E) { |
| 1418 | if (isa<CXXThisExpr>(E->getBase()->IgnoreParens())) { |
| 1419 | if (auto *FD = dyn_cast<FieldDecl>(E->getMemberDecl())) { |
| 1420 | auto DVar = Stack->getTopDSA(FD, false); |
| 1421 | // Check if the variable has explicit DSA set and stop analysis if it |
| 1422 | // so. |
| 1423 | if (DVar.RefExpr) |
| 1424 | return; |
| 1425 | |
| 1426 | auto ELoc = E->getExprLoc(); |
| 1427 | auto DKind = Stack->getCurrentDirective(); |
| 1428 | // OpenMP [2.9.3.6, Restrictions, p.2] |
| 1429 | // A list item that appears in a reduction clause of the innermost |
| 1430 | // enclosing worksharing or parallel construct may not be accessed in |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 1431 | // an explicit task. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1432 | DVar = |
| 1433 | Stack->hasInnermostDSA(FD, MatchesAnyClause(OMPC_reduction), |
| 1434 | [](OpenMPDirectiveKind K) -> bool { |
| 1435 | return isOpenMPParallelDirective(K) || |
| 1436 | isOpenMPWorksharingDirective(K) || |
| 1437 | isOpenMPTeamsDirective(K); |
| 1438 | }, |
| 1439 | false); |
| 1440 | if (DKind == OMPD_task && DVar.CKind == OMPC_reduction) { |
| 1441 | ErrorFound = true; |
| 1442 | SemaRef.Diag(ELoc, diag::err_omp_reduction_in_task); |
| 1443 | ReportOriginalDSA(SemaRef, Stack, FD, DVar); |
| 1444 | return; |
| 1445 | } |
| 1446 | |
| 1447 | // Define implicit data-sharing attributes for task. |
| 1448 | DVar = Stack->getImplicitDSA(FD, false); |
| 1449 | if (DKind == OMPD_task && DVar.CKind != OMPC_shared) |
| 1450 | ImplicitFirstprivate.push_back(E); |
| 1451 | } |
| 1452 | } |
| 1453 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1454 | void VisitOMPExecutableDirective(OMPExecutableDirective *S) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1455 | for (auto *C : S->clauses()) { |
| 1456 | // Skip analysis of arguments of implicitly defined firstprivate clause |
| 1457 | // for task directives. |
| 1458 | if (C && (!isa<OMPFirstprivateClause>(C) || C->getLocStart().isValid())) |
| 1459 | for (auto *CC : C->children()) { |
| 1460 | if (CC) |
| 1461 | Visit(CC); |
| 1462 | } |
| 1463 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1464 | } |
| 1465 | void VisitStmt(Stmt *S) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1466 | for (auto *C : S->children()) { |
| 1467 | if (C && !isa<OMPExecutableDirective>(C)) |
| 1468 | Visit(C); |
| 1469 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1470 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1471 | |
| 1472 | bool isErrorFound() { return ErrorFound; } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1473 | ArrayRef<Expr *> getImplicitFirstprivate() { return ImplicitFirstprivate; } |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1474 | llvm::DenseMap<ValueDecl *, Expr *> &getVarsWithInheritedDSA() { |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1475 | return VarsWithInheritedDSA; |
| 1476 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1477 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1478 | DSAAttrChecker(DSAStackTy *S, Sema &SemaRef, CapturedStmt *CS) |
| 1479 | : Stack(S), SemaRef(SemaRef), ErrorFound(false), CS(CS) {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1480 | }; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1481 | } // namespace |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1482 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1483 | void Sema::ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, Scope *CurScope) { |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1484 | switch (DKind) { |
| 1485 | case OMPD_parallel: { |
| 1486 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1487 | QualType KmpInt32PtrTy = |
| 1488 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1489 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1490 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1491 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1492 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1493 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1494 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1495 | Params); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1496 | break; |
| 1497 | } |
| 1498 | case OMPD_simd: { |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1499 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1500 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1501 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1502 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1503 | Params); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1504 | break; |
| 1505 | } |
| 1506 | case OMPD_for: { |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1507 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1508 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1509 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1510 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1511 | Params); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1512 | break; |
| 1513 | } |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1514 | case OMPD_for_simd: { |
| 1515 | Sema::CapturedParamNameType Params[] = { |
| 1516 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1517 | }; |
| 1518 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1519 | Params); |
| 1520 | break; |
| 1521 | } |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 1522 | case OMPD_sections: { |
| 1523 | Sema::CapturedParamNameType Params[] = { |
| 1524 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1525 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1526 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1527 | Params); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 1528 | break; |
| 1529 | } |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1530 | case OMPD_section: { |
| 1531 | Sema::CapturedParamNameType Params[] = { |
| 1532 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1533 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1534 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1535 | Params); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1536 | break; |
| 1537 | } |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 1538 | case OMPD_single: { |
| 1539 | Sema::CapturedParamNameType Params[] = { |
| 1540 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1541 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1542 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1543 | Params); |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 1544 | break; |
| 1545 | } |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1546 | case OMPD_master: { |
| 1547 | Sema::CapturedParamNameType Params[] = { |
| 1548 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1549 | }; |
| 1550 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1551 | Params); |
| 1552 | break; |
| 1553 | } |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1554 | case OMPD_critical: { |
| 1555 | Sema::CapturedParamNameType Params[] = { |
| 1556 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1557 | }; |
| 1558 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1559 | Params); |
| 1560 | break; |
| 1561 | } |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1562 | case OMPD_parallel_for: { |
| 1563 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1564 | QualType KmpInt32PtrTy = |
| 1565 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1566 | Sema::CapturedParamNameType Params[] = { |
| 1567 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1568 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1569 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1570 | }; |
| 1571 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1572 | Params); |
| 1573 | break; |
| 1574 | } |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1575 | case OMPD_parallel_for_simd: { |
| 1576 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1577 | QualType KmpInt32PtrTy = |
| 1578 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1579 | Sema::CapturedParamNameType Params[] = { |
| 1580 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1581 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1582 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1583 | }; |
| 1584 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1585 | Params); |
| 1586 | break; |
| 1587 | } |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1588 | case OMPD_parallel_sections: { |
Alexey Bataev | 68adb7d | 2015-04-14 03:29:22 +0000 | [diff] [blame] | 1589 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1590 | QualType KmpInt32PtrTy = |
| 1591 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1592 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | 68adb7d | 2015-04-14 03:29:22 +0000 | [diff] [blame] | 1593 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1594 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1595 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1596 | }; |
| 1597 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1598 | Params); |
| 1599 | break; |
| 1600 | } |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1601 | case OMPD_task: { |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1602 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 3ae88e2 | 2015-05-22 08:56:35 +0000 | [diff] [blame] | 1603 | QualType Args[] = {Context.VoidPtrTy.withConst().withRestrict()}; |
| 1604 | FunctionProtoType::ExtProtoInfo EPI; |
| 1605 | EPI.Variadic = true; |
| 1606 | QualType CopyFnType = Context.getFunctionType(Context.VoidTy, Args, EPI); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1607 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1608 | std::make_pair(".global_tid.", KmpInt32Ty), |
| 1609 | std::make_pair(".part_id.", KmpInt32Ty), |
Alexey Bataev | 3ae88e2 | 2015-05-22 08:56:35 +0000 | [diff] [blame] | 1610 | std::make_pair(".privates.", |
| 1611 | Context.VoidPtrTy.withConst().withRestrict()), |
| 1612 | std::make_pair( |
| 1613 | ".copy_fn.", |
| 1614 | Context.getPointerType(CopyFnType).withConst().withRestrict()), |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1615 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1616 | }; |
| 1617 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1618 | Params); |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1619 | // Mark this captured region as inlined, because we don't use outlined |
| 1620 | // function directly. |
| 1621 | getCurCapturedRegion()->TheCapturedDecl->addAttr( |
| 1622 | AlwaysInlineAttr::CreateImplicit( |
| 1623 | Context, AlwaysInlineAttr::Keyword_forceinline, SourceRange())); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1624 | break; |
| 1625 | } |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1626 | case OMPD_ordered: { |
| 1627 | Sema::CapturedParamNameType Params[] = { |
| 1628 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1629 | }; |
| 1630 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1631 | Params); |
| 1632 | break; |
| 1633 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1634 | case OMPD_atomic: { |
| 1635 | Sema::CapturedParamNameType Params[] = { |
| 1636 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1637 | }; |
| 1638 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1639 | Params); |
| 1640 | break; |
| 1641 | } |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 1642 | case OMPD_target_data: |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 1643 | case OMPD_target: |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 1644 | case OMPD_target_parallel: |
| 1645 | case OMPD_target_parallel_for: { |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1646 | Sema::CapturedParamNameType Params[] = { |
| 1647 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1648 | }; |
| 1649 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1650 | Params); |
| 1651 | break; |
| 1652 | } |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1653 | case OMPD_teams: { |
| 1654 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1655 | QualType KmpInt32PtrTy = |
| 1656 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1657 | Sema::CapturedParamNameType Params[] = { |
| 1658 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1659 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1660 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1661 | }; |
| 1662 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1663 | Params); |
| 1664 | break; |
| 1665 | } |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1666 | case OMPD_taskgroup: { |
| 1667 | Sema::CapturedParamNameType Params[] = { |
| 1668 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1669 | }; |
| 1670 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1671 | Params); |
| 1672 | break; |
| 1673 | } |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1674 | case OMPD_taskloop: { |
| 1675 | Sema::CapturedParamNameType Params[] = { |
| 1676 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1677 | }; |
| 1678 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1679 | Params); |
| 1680 | break; |
| 1681 | } |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1682 | case OMPD_taskloop_simd: { |
| 1683 | Sema::CapturedParamNameType Params[] = { |
| 1684 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1685 | }; |
| 1686 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1687 | Params); |
| 1688 | break; |
| 1689 | } |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1690 | case OMPD_distribute: { |
| 1691 | Sema::CapturedParamNameType Params[] = { |
| 1692 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1693 | }; |
| 1694 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1695 | Params); |
| 1696 | break; |
| 1697 | } |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1698 | case OMPD_threadprivate: |
Alexey Bataev | ee9af45 | 2014-11-21 11:33:46 +0000 | [diff] [blame] | 1699 | case OMPD_taskyield: |
| 1700 | case OMPD_barrier: |
| 1701 | case OMPD_taskwait: |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1702 | case OMPD_cancellation_point: |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1703 | case OMPD_cancel: |
Alexey Bataev | ee9af45 | 2014-11-21 11:33:46 +0000 | [diff] [blame] | 1704 | case OMPD_flush: |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1705 | case OMPD_target_enter_data: |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1706 | case OMPD_target_exit_data: |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 1707 | case OMPD_declare_reduction: |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 1708 | case OMPD_declare_simd: |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1709 | llvm_unreachable("OpenMP Directive is not allowed"); |
| 1710 | case OMPD_unknown: |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1711 | llvm_unreachable("Unknown OpenMP directive"); |
| 1712 | } |
| 1713 | } |
| 1714 | |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1715 | static OMPCapturedExprDecl *buildCaptureDecl(Sema &S, IdentifierInfo *Id, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 1716 | Expr *CaptureExpr, bool WithInit, |
| 1717 | bool AsExpression) { |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 1718 | assert(CaptureExpr); |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 1719 | ASTContext &C = S.getASTContext(); |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 1720 | Expr *Init = AsExpression ? CaptureExpr : CaptureExpr->IgnoreImpCasts(); |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 1721 | QualType Ty = Init->getType(); |
| 1722 | if (CaptureExpr->getObjectKind() == OK_Ordinary && CaptureExpr->isGLValue()) { |
| 1723 | if (S.getLangOpts().CPlusPlus) |
| 1724 | Ty = C.getLValueReferenceType(Ty); |
| 1725 | else { |
| 1726 | Ty = C.getPointerType(Ty); |
| 1727 | ExprResult Res = |
| 1728 | S.CreateBuiltinUnaryOp(CaptureExpr->getExprLoc(), UO_AddrOf, Init); |
| 1729 | if (!Res.isUsable()) |
| 1730 | return nullptr; |
| 1731 | Init = Res.get(); |
| 1732 | } |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 1733 | WithInit = true; |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 1734 | } |
| 1735 | auto *CED = OMPCapturedExprDecl::Create(C, S.CurContext, Id, Ty); |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 1736 | if (!WithInit) |
| 1737 | CED->addAttr(OMPCaptureNoInitAttr::CreateImplicit(C, SourceRange())); |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 1738 | S.CurContext->addHiddenDecl(CED); |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 1739 | S.AddInitializerToDecl(CED, Init, /*DirectInit=*/false, |
| 1740 | /*TypeMayContainAuto=*/true); |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1741 | return CED; |
| 1742 | } |
| 1743 | |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 1744 | static DeclRefExpr *buildCapture(Sema &S, ValueDecl *D, Expr *CaptureExpr, |
| 1745 | bool WithInit) { |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 1746 | OMPCapturedExprDecl *CD; |
| 1747 | if (auto *VD = S.IsOpenMPCapturedDecl(D)) |
| 1748 | CD = cast<OMPCapturedExprDecl>(VD); |
| 1749 | else |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 1750 | CD = buildCaptureDecl(S, D->getIdentifier(), CaptureExpr, WithInit, |
| 1751 | /*AsExpression=*/false); |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1752 | return buildDeclRefExpr(S, CD, CD->getType().getNonReferenceType(), |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 1753 | CaptureExpr->getExprLoc()); |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1754 | } |
| 1755 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 1756 | static ExprResult buildCapture(Sema &S, Expr *CaptureExpr, DeclRefExpr *&Ref) { |
| 1757 | if (!Ref) { |
| 1758 | auto *CD = |
| 1759 | buildCaptureDecl(S, &S.getASTContext().Idents.get(".capture_expr."), |
| 1760 | CaptureExpr, /*WithInit=*/true, /*AsExpression=*/true); |
| 1761 | Ref = buildDeclRefExpr(S, CD, CD->getType().getNonReferenceType(), |
| 1762 | CaptureExpr->getExprLoc()); |
| 1763 | } |
| 1764 | ExprResult Res = Ref; |
| 1765 | if (!S.getLangOpts().CPlusPlus && |
| 1766 | CaptureExpr->getObjectKind() == OK_Ordinary && CaptureExpr->isGLValue() && |
| 1767 | Ref->getType()->isPointerType()) |
| 1768 | Res = S.CreateBuiltinUnaryOp(CaptureExpr->getExprLoc(), UO_Deref, Ref); |
| 1769 | if (!Res.isUsable()) |
| 1770 | return ExprError(); |
| 1771 | return CaptureExpr->isGLValue() ? Res : S.DefaultLvalueConversion(Res.get()); |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 1772 | } |
| 1773 | |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1774 | StmtResult Sema::ActOnOpenMPRegionEnd(StmtResult S, |
| 1775 | ArrayRef<OMPClause *> Clauses) { |
| 1776 | if (!S.isUsable()) { |
| 1777 | ActOnCapturedRegionError(); |
| 1778 | return StmtError(); |
| 1779 | } |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1780 | |
| 1781 | OMPOrderedClause *OC = nullptr; |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1782 | OMPScheduleClause *SC = nullptr; |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1783 | SmallVector<OMPLinearClause *, 4> LCs; |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1784 | // This is required for proper codegen. |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1785 | for (auto *Clause : Clauses) { |
Alexey Bataev | 16dc7b6 | 2015-05-20 03:46:04 +0000 | [diff] [blame] | 1786 | if (isOpenMPPrivate(Clause->getClauseKind()) || |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 1787 | Clause->getClauseKind() == OMPC_copyprivate || |
| 1788 | (getLangOpts().OpenMPUseTLS && |
| 1789 | getASTContext().getTargetInfo().isTLSSupported() && |
| 1790 | Clause->getClauseKind() == OMPC_copyin)) { |
| 1791 | DSAStack->setForceVarCapturing(Clause->getClauseKind() == OMPC_copyin); |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1792 | // Mark all variables in private list clauses as used in inner region. |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1793 | for (auto *VarRef : Clause->children()) { |
| 1794 | if (auto *E = cast_or_null<Expr>(VarRef)) { |
Alexey Bataev | 8bf6b3e | 2015-04-02 13:07:08 +0000 | [diff] [blame] | 1795 | MarkDeclarationsReferencedInExpr(E); |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1796 | } |
| 1797 | } |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 1798 | DSAStack->setForceVarCapturing(/*V=*/false); |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1799 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective())) { |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1800 | // Mark all variables in private list clauses as used in inner region. |
| 1801 | // Required for proper codegen of combined directives. |
| 1802 | // TODO: add processing for other clauses. |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1803 | if (auto *C = OMPClauseWithPreInit::get(Clause)) { |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 1804 | if (auto *DS = cast_or_null<DeclStmt>(C->getPreInitStmt())) { |
| 1805 | for (auto *D : DS->decls()) |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1806 | MarkVariableReferenced(D->getLocation(), cast<VarDecl>(D)); |
| 1807 | } |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 1808 | } |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 1809 | if (auto *C = OMPClauseWithPostUpdate::get(Clause)) { |
| 1810 | if (auto *E = C->getPostUpdateExpr()) |
| 1811 | MarkDeclarationsReferencedInExpr(E); |
| 1812 | } |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1813 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1814 | if (Clause->getClauseKind() == OMPC_schedule) |
| 1815 | SC = cast<OMPScheduleClause>(Clause); |
| 1816 | else if (Clause->getClauseKind() == OMPC_ordered) |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1817 | OC = cast<OMPOrderedClause>(Clause); |
| 1818 | else if (Clause->getClauseKind() == OMPC_linear) |
| 1819 | LCs.push_back(cast<OMPLinearClause>(Clause)); |
| 1820 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1821 | bool ErrorFound = false; |
| 1822 | // OpenMP, 2.7.1 Loop Construct, Restrictions |
| 1823 | // The nonmonotonic modifier cannot be specified if an ordered clause is |
| 1824 | // specified. |
| 1825 | if (SC && |
| 1826 | (SC->getFirstScheduleModifier() == OMPC_SCHEDULE_MODIFIER_nonmonotonic || |
| 1827 | SC->getSecondScheduleModifier() == |
| 1828 | OMPC_SCHEDULE_MODIFIER_nonmonotonic) && |
| 1829 | OC) { |
| 1830 | Diag(SC->getFirstScheduleModifier() == OMPC_SCHEDULE_MODIFIER_nonmonotonic |
| 1831 | ? SC->getFirstScheduleModifierLoc() |
| 1832 | : SC->getSecondScheduleModifierLoc(), |
| 1833 | diag::err_omp_schedule_nonmonotonic_ordered) |
| 1834 | << SourceRange(OC->getLocStart(), OC->getLocEnd()); |
| 1835 | ErrorFound = true; |
| 1836 | } |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1837 | if (!LCs.empty() && OC && OC->getNumForLoops()) { |
| 1838 | for (auto *C : LCs) { |
| 1839 | Diag(C->getLocStart(), diag::err_omp_linear_ordered) |
| 1840 | << SourceRange(OC->getLocStart(), OC->getLocEnd()); |
| 1841 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1842 | ErrorFound = true; |
| 1843 | } |
Alexey Bataev | 113438c | 2015-12-30 12:06:23 +0000 | [diff] [blame] | 1844 | if (isOpenMPWorksharingDirective(DSAStack->getCurrentDirective()) && |
| 1845 | isOpenMPSimdDirective(DSAStack->getCurrentDirective()) && OC && |
| 1846 | OC->getNumForLoops()) { |
| 1847 | Diag(OC->getLocStart(), diag::err_omp_ordered_simd) |
| 1848 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 1849 | ErrorFound = true; |
| 1850 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1851 | if (ErrorFound) { |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1852 | ActOnCapturedRegionError(); |
| 1853 | return StmtError(); |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1854 | } |
| 1855 | return ActOnCapturedRegionEnd(S.get()); |
| 1856 | } |
| 1857 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1858 | static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, |
| 1859 | OpenMPDirectiveKind CurrentRegion, |
| 1860 | const DeclarationNameInfo &CurrentName, |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1861 | OpenMPDirectiveKind CancelRegion, |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1862 | SourceLocation StartLoc) { |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1863 | // Allowed nesting of constructs |
| 1864 | // +------------------+-----------------+------------------------------------+ |
| 1865 | // | Parent directive | Child directive | Closely (!), No-Closely(+), Both(*)| |
| 1866 | // +------------------+-----------------+------------------------------------+ |
| 1867 | // | parallel | parallel | * | |
| 1868 | // | parallel | for | * | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1869 | // | parallel | for simd | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1870 | // | parallel | master | * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1871 | // | parallel | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1872 | // | parallel | simd | * | |
| 1873 | // | parallel | sections | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1874 | // | parallel | section | + | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1875 | // | parallel | single | * | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1876 | // | parallel | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1877 | // | parallel |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1878 | // | parallel |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1879 | // | parallel | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1880 | // | parallel | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1881 | // | parallel | barrier | * | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1882 | // | parallel | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1883 | // | parallel | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1884 | // | parallel | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1885 | // | parallel | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1886 | // | parallel | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1887 | // | parallel | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 1888 | // | parallel | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 1889 | // | parallel | target parallel | * | |
| 1890 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1891 | // | parallel | target enter | * | |
| 1892 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1893 | // | parallel | target exit | * | |
| 1894 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1895 | // | parallel | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1896 | // | parallel | cancellation | | |
| 1897 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1898 | // | parallel | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1899 | // | parallel | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1900 | // | parallel | taskloop simd | * | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1901 | // | parallel | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1902 | // +------------------+-----------------+------------------------------------+ |
| 1903 | // | for | parallel | * | |
| 1904 | // | for | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1905 | // | for | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1906 | // | for | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1907 | // | for | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1908 | // | for | simd | * | |
| 1909 | // | for | sections | + | |
| 1910 | // | for | section | + | |
| 1911 | // | for | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1912 | // | for | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1913 | // | for |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1914 | // | for |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1915 | // | for | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1916 | // | for | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1917 | // | for | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1918 | // | for | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1919 | // | for | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1920 | // | for | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1921 | // | for | ordered | * (if construct is ordered) | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1922 | // | for | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1923 | // | for | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 1924 | // | for | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 1925 | // | for | target parallel | * | |
| 1926 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1927 | // | for | target enter | * | |
| 1928 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1929 | // | for | target exit | * | |
| 1930 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1931 | // | for | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1932 | // | for | cancellation | | |
| 1933 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1934 | // | for | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1935 | // | for | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1936 | // | for | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1937 | // | for | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1938 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1939 | // | master | parallel | * | |
| 1940 | // | master | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1941 | // | master | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1942 | // | master | master | * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1943 | // | master | critical | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1944 | // | master | simd | * | |
| 1945 | // | master | sections | + | |
| 1946 | // | master | section | + | |
| 1947 | // | master | single | + | |
| 1948 | // | master | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1949 | // | master |parallel for simd| * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1950 | // | master |parallel sections| * | |
| 1951 | // | master | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1952 | // | master | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1953 | // | master | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1954 | // | master | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1955 | // | master | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1956 | // | master | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1957 | // | master | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1958 | // | master | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1959 | // | master | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 1960 | // | master | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 1961 | // | master | target parallel | * | |
| 1962 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1963 | // | master | target enter | * | |
| 1964 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1965 | // | master | target exit | * | |
| 1966 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1967 | // | master | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1968 | // | master | cancellation | | |
| 1969 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1970 | // | master | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1971 | // | master | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1972 | // | master | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1973 | // | master | distribute | | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1974 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1975 | // | critical | parallel | * | |
| 1976 | // | critical | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1977 | // | critical | for simd | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1978 | // | critical | master | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1979 | // | critical | critical | * (should have different names) | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1980 | // | critical | simd | * | |
| 1981 | // | critical | sections | + | |
| 1982 | // | critical | section | + | |
| 1983 | // | critical | single | + | |
| 1984 | // | critical | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1985 | // | critical |parallel for simd| * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1986 | // | critical |parallel sections| * | |
| 1987 | // | critical | task | * | |
| 1988 | // | critical | taskyield | * | |
| 1989 | // | critical | barrier | + | |
| 1990 | // | critical | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1991 | // | critical | taskgroup | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1992 | // | critical | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1993 | // | critical | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1994 | // | critical | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 1995 | // | critical | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 1996 | // | critical | target parallel | * | |
| 1997 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1998 | // | critical | target enter | * | |
| 1999 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2000 | // | critical | target exit | * | |
| 2001 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2002 | // | critical | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2003 | // | critical | cancellation | | |
| 2004 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2005 | // | critical | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2006 | // | critical | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2007 | // | critical | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2008 | // | critical | distribute | | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2009 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2010 | // | simd | parallel | | |
| 2011 | // | simd | for | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2012 | // | simd | for simd | | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2013 | // | simd | master | | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2014 | // | simd | critical | | |
Alexey Bataev | 1f09221 | 2016-02-02 04:59:52 +0000 | [diff] [blame] | 2015 | // | simd | simd | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2016 | // | simd | sections | | |
| 2017 | // | simd | section | | |
| 2018 | // | simd | single | | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2019 | // | simd | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2020 | // | simd |parallel for simd| | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2021 | // | simd |parallel sections| | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2022 | // | simd | task | | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2023 | // | simd | taskyield | | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2024 | // | simd | barrier | | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2025 | // | simd | taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2026 | // | simd | taskgroup | | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2027 | // | simd | flush | | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2028 | // | simd | ordered | + (with simd clause) | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2029 | // | simd | atomic | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2030 | // | simd | target | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2031 | // | simd | target parallel | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2032 | // | simd | target parallel | | |
| 2033 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2034 | // | simd | target enter | | |
| 2035 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2036 | // | simd | target exit | | |
| 2037 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2038 | // | simd | teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2039 | // | simd | cancellation | | |
| 2040 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2041 | // | simd | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2042 | // | simd | taskloop | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2043 | // | simd | taskloop simd | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2044 | // | simd | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2045 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2046 | // | for simd | parallel | | |
| 2047 | // | for simd | for | | |
| 2048 | // | for simd | for simd | | |
| 2049 | // | for simd | master | | |
| 2050 | // | for simd | critical | | |
Alexey Bataev | 1f09221 | 2016-02-02 04:59:52 +0000 | [diff] [blame] | 2051 | // | for simd | simd | * | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2052 | // | for simd | sections | | |
| 2053 | // | for simd | section | | |
| 2054 | // | for simd | single | | |
| 2055 | // | for simd | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2056 | // | for simd |parallel for simd| | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2057 | // | for simd |parallel sections| | |
| 2058 | // | for simd | task | | |
| 2059 | // | for simd | taskyield | | |
| 2060 | // | for simd | barrier | | |
| 2061 | // | for simd | taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2062 | // | for simd | taskgroup | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2063 | // | for simd | flush | | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2064 | // | for simd | ordered | + (with simd clause) | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2065 | // | for simd | atomic | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2066 | // | for simd | target | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2067 | // | for simd | target parallel | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2068 | // | for simd | target parallel | | |
| 2069 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2070 | // | for simd | target enter | | |
| 2071 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2072 | // | for simd | target exit | | |
| 2073 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2074 | // | for simd | teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2075 | // | for simd | cancellation | | |
| 2076 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2077 | // | for simd | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2078 | // | for simd | taskloop | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2079 | // | for simd | taskloop simd | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2080 | // | for simd | distribute | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2081 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2082 | // | parallel for simd| parallel | | |
| 2083 | // | parallel for simd| for | | |
| 2084 | // | parallel for simd| for simd | | |
| 2085 | // | parallel for simd| master | | |
| 2086 | // | parallel for simd| critical | | |
Alexey Bataev | 1f09221 | 2016-02-02 04:59:52 +0000 | [diff] [blame] | 2087 | // | parallel for simd| simd | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2088 | // | parallel for simd| sections | | |
| 2089 | // | parallel for simd| section | | |
| 2090 | // | parallel for simd| single | | |
| 2091 | // | parallel for simd| parallel for | | |
| 2092 | // | parallel for simd|parallel for simd| | |
| 2093 | // | parallel for simd|parallel sections| | |
| 2094 | // | parallel for simd| task | | |
| 2095 | // | parallel for simd| taskyield | | |
| 2096 | // | parallel for simd| barrier | | |
| 2097 | // | parallel for simd| taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2098 | // | parallel for simd| taskgroup | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2099 | // | parallel for simd| flush | | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2100 | // | parallel for simd| ordered | + (with simd clause) | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2101 | // | parallel for simd| atomic | | |
| 2102 | // | parallel for simd| target | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2103 | // | parallel for simd| target parallel | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2104 | // | parallel for simd| target parallel | | |
| 2105 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2106 | // | parallel for simd| target enter | | |
| 2107 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2108 | // | parallel for simd| target exit | | |
| 2109 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2110 | // | parallel for simd| teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2111 | // | parallel for simd| cancellation | | |
| 2112 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2113 | // | parallel for simd| cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2114 | // | parallel for simd| taskloop | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2115 | // | parallel for simd| taskloop simd | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2116 | // | parallel for simd| distribute | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2117 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2118 | // | sections | parallel | * | |
| 2119 | // | sections | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2120 | // | sections | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2121 | // | sections | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2122 | // | sections | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2123 | // | sections | simd | * | |
| 2124 | // | sections | sections | + | |
| 2125 | // | sections | section | * | |
| 2126 | // | sections | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2127 | // | sections | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2128 | // | sections |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2129 | // | sections |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2130 | // | sections | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2131 | // | sections | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2132 | // | sections | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2133 | // | sections | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2134 | // | sections | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2135 | // | sections | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2136 | // | sections | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2137 | // | sections | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2138 | // | sections | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2139 | // | sections | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2140 | // | sections | target parallel | * | |
| 2141 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2142 | // | sections | target enter | * | |
| 2143 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2144 | // | sections | target exit | * | |
| 2145 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2146 | // | sections | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2147 | // | sections | cancellation | | |
| 2148 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2149 | // | sections | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2150 | // | sections | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2151 | // | sections | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2152 | // | sections | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2153 | // +------------------+-----------------+------------------------------------+ |
| 2154 | // | section | parallel | * | |
| 2155 | // | section | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2156 | // | section | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2157 | // | section | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2158 | // | section | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2159 | // | section | simd | * | |
| 2160 | // | section | sections | + | |
| 2161 | // | section | section | + | |
| 2162 | // | section | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2163 | // | section | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2164 | // | section |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2165 | // | section |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2166 | // | section | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2167 | // | section | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2168 | // | section | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2169 | // | section | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2170 | // | section | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2171 | // | section | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2172 | // | section | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2173 | // | section | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2174 | // | section | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2175 | // | section | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2176 | // | section | target parallel | * | |
| 2177 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2178 | // | section | target enter | * | |
| 2179 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2180 | // | section | target exit | * | |
| 2181 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2182 | // | section | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2183 | // | section | cancellation | | |
| 2184 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2185 | // | section | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2186 | // | section | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2187 | // | section | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2188 | // | section | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2189 | // +------------------+-----------------+------------------------------------+ |
| 2190 | // | single | parallel | * | |
| 2191 | // | single | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2192 | // | single | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2193 | // | single | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2194 | // | single | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2195 | // | single | simd | * | |
| 2196 | // | single | sections | + | |
| 2197 | // | single | section | + | |
| 2198 | // | single | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2199 | // | single | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2200 | // | single |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2201 | // | single |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2202 | // | single | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2203 | // | single | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2204 | // | single | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2205 | // | single | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2206 | // | single | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2207 | // | single | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2208 | // | single | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2209 | // | single | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2210 | // | single | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2211 | // | single | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2212 | // | single | target parallel | * | |
| 2213 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2214 | // | single | target enter | * | |
| 2215 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2216 | // | single | target exit | * | |
| 2217 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2218 | // | single | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2219 | // | single | cancellation | | |
| 2220 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2221 | // | single | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2222 | // | single | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2223 | // | single | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2224 | // | single | distribute | | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2225 | // +------------------+-----------------+------------------------------------+ |
| 2226 | // | parallel for | parallel | * | |
| 2227 | // | parallel for | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2228 | // | parallel for | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2229 | // | parallel for | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2230 | // | parallel for | critical | * | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2231 | // | parallel for | simd | * | |
| 2232 | // | parallel for | sections | + | |
| 2233 | // | parallel for | section | + | |
| 2234 | // | parallel for | single | + | |
| 2235 | // | parallel for | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2236 | // | parallel for |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2237 | // | parallel for |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2238 | // | parallel for | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2239 | // | parallel for | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2240 | // | parallel for | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2241 | // | parallel for | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2242 | // | parallel for | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2243 | // | parallel for | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2244 | // | parallel for | ordered | * (if construct is ordered) | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2245 | // | parallel for | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2246 | // | parallel for | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2247 | // | parallel for | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2248 | // | parallel for | target parallel | * | |
| 2249 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2250 | // | parallel for | target enter | * | |
| 2251 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2252 | // | parallel for | target exit | * | |
| 2253 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2254 | // | parallel for | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2255 | // | parallel for | cancellation | | |
| 2256 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2257 | // | parallel for | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2258 | // | parallel for | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2259 | // | parallel for | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2260 | // | parallel for | distribute | | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2261 | // +------------------+-----------------+------------------------------------+ |
| 2262 | // | parallel sections| parallel | * | |
| 2263 | // | parallel sections| for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2264 | // | parallel sections| for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2265 | // | parallel sections| master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2266 | // | parallel sections| critical | + | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2267 | // | parallel sections| simd | * | |
| 2268 | // | parallel sections| sections | + | |
| 2269 | // | parallel sections| section | * | |
| 2270 | // | parallel sections| single | + | |
| 2271 | // | parallel sections| parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2272 | // | parallel sections|parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2273 | // | parallel sections|parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2274 | // | parallel sections| task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2275 | // | parallel sections| taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2276 | // | parallel sections| barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2277 | // | parallel sections| taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2278 | // | parallel sections| taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2279 | // | parallel sections| flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2280 | // | parallel sections| ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2281 | // | parallel sections| atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2282 | // | parallel sections| target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2283 | // | parallel sections| target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2284 | // | parallel sections| target parallel | * | |
| 2285 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2286 | // | parallel sections| target enter | * | |
| 2287 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2288 | // | parallel sections| target exit | * | |
| 2289 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2290 | // | parallel sections| teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2291 | // | parallel sections| cancellation | | |
| 2292 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2293 | // | parallel sections| cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2294 | // | parallel sections| taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2295 | // | parallel sections| taskloop simd | * | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2296 | // | parallel sections| distribute | | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2297 | // +------------------+-----------------+------------------------------------+ |
| 2298 | // | task | parallel | * | |
| 2299 | // | task | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2300 | // | task | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2301 | // | task | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2302 | // | task | critical | * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2303 | // | task | simd | * | |
| 2304 | // | task | sections | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2305 | // | task | section | + | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2306 | // | task | single | + | |
| 2307 | // | task | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2308 | // | task |parallel for simd| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2309 | // | task |parallel sections| * | |
| 2310 | // | task | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2311 | // | task | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2312 | // | task | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2313 | // | task | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2314 | // | task | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2315 | // | task | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2316 | // | task | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2317 | // | task | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2318 | // | task | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2319 | // | task | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2320 | // | task | target parallel | * | |
| 2321 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2322 | // | task | target enter | * | |
| 2323 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2324 | // | task | target exit | * | |
| 2325 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2326 | // | task | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2327 | // | task | cancellation | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2328 | // | | point | ! | |
| 2329 | // | task | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2330 | // | task | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2331 | // | task | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2332 | // | task | distribute | | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2333 | // +------------------+-----------------+------------------------------------+ |
| 2334 | // | ordered | parallel | * | |
| 2335 | // | ordered | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2336 | // | ordered | for simd | + | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2337 | // | ordered | master | * | |
| 2338 | // | ordered | critical | * | |
| 2339 | // | ordered | simd | * | |
| 2340 | // | ordered | sections | + | |
| 2341 | // | ordered | section | + | |
| 2342 | // | ordered | single | + | |
| 2343 | // | ordered | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2344 | // | ordered |parallel for simd| * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2345 | // | ordered |parallel sections| * | |
| 2346 | // | ordered | task | * | |
| 2347 | // | ordered | taskyield | * | |
| 2348 | // | ordered | barrier | + | |
| 2349 | // | ordered | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2350 | // | ordered | taskgroup | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2351 | // | ordered | flush | * | |
| 2352 | // | ordered | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2353 | // | ordered | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2354 | // | ordered | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2355 | // | ordered | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2356 | // | ordered | target parallel | * | |
| 2357 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2358 | // | ordered | target enter | * | |
| 2359 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2360 | // | ordered | target exit | * | |
| 2361 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2362 | // | ordered | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2363 | // | ordered | cancellation | | |
| 2364 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2365 | // | ordered | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2366 | // | ordered | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2367 | // | ordered | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2368 | // | ordered | distribute | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2369 | // +------------------+-----------------+------------------------------------+ |
| 2370 | // | atomic | parallel | | |
| 2371 | // | atomic | for | | |
| 2372 | // | atomic | for simd | | |
| 2373 | // | atomic | master | | |
| 2374 | // | atomic | critical | | |
| 2375 | // | atomic | simd | | |
| 2376 | // | atomic | sections | | |
| 2377 | // | atomic | section | | |
| 2378 | // | atomic | single | | |
| 2379 | // | atomic | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2380 | // | atomic |parallel for simd| | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2381 | // | atomic |parallel sections| | |
| 2382 | // | atomic | task | | |
| 2383 | // | atomic | taskyield | | |
| 2384 | // | atomic | barrier | | |
| 2385 | // | atomic | taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2386 | // | atomic | taskgroup | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2387 | // | atomic | flush | | |
| 2388 | // | atomic | ordered | | |
| 2389 | // | atomic | atomic | | |
| 2390 | // | atomic | target | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2391 | // | atomic | target parallel | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2392 | // | atomic | target parallel | | |
| 2393 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2394 | // | atomic | target enter | | |
| 2395 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2396 | // | atomic | target exit | | |
| 2397 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2398 | // | atomic | teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2399 | // | atomic | cancellation | | |
| 2400 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2401 | // | atomic | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2402 | // | atomic | taskloop | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2403 | // | atomic | taskloop simd | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2404 | // | atomic | distribute | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2405 | // +------------------+-----------------+------------------------------------+ |
| 2406 | // | target | parallel | * | |
| 2407 | // | target | for | * | |
| 2408 | // | target | for simd | * | |
| 2409 | // | target | master | * | |
| 2410 | // | target | critical | * | |
| 2411 | // | target | simd | * | |
| 2412 | // | target | sections | * | |
| 2413 | // | target | section | * | |
| 2414 | // | target | single | * | |
| 2415 | // | target | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2416 | // | target |parallel for simd| * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2417 | // | target |parallel sections| * | |
| 2418 | // | target | task | * | |
| 2419 | // | target | taskyield | * | |
| 2420 | // | target | barrier | * | |
| 2421 | // | target | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2422 | // | target | taskgroup | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2423 | // | target | flush | * | |
| 2424 | // | target | ordered | * | |
| 2425 | // | target | atomic | * | |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2426 | // | target | target | | |
| 2427 | // | target | target parallel | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2428 | // | target | target parallel | | |
| 2429 | // | | for | | |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2430 | // | target | target enter | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2431 | // | | data | | |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2432 | // | target | target exit | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2433 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2434 | // | target | teams | * | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2435 | // | target | cancellation | | |
| 2436 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2437 | // | target | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2438 | // | target | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2439 | // | target | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2440 | // | target | distribute | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2441 | // +------------------+-----------------+------------------------------------+ |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2442 | // | target parallel | parallel | * | |
| 2443 | // | target parallel | for | * | |
| 2444 | // | target parallel | for simd | * | |
| 2445 | // | target parallel | master | * | |
| 2446 | // | target parallel | critical | * | |
| 2447 | // | target parallel | simd | * | |
| 2448 | // | target parallel | sections | * | |
| 2449 | // | target parallel | section | * | |
| 2450 | // | target parallel | single | * | |
| 2451 | // | target parallel | parallel for | * | |
| 2452 | // | target parallel |parallel for simd| * | |
| 2453 | // | target parallel |parallel sections| * | |
| 2454 | // | target parallel | task | * | |
| 2455 | // | target parallel | taskyield | * | |
| 2456 | // | target parallel | barrier | * | |
| 2457 | // | target parallel | taskwait | * | |
| 2458 | // | target parallel | taskgroup | * | |
| 2459 | // | target parallel | flush | * | |
| 2460 | // | target parallel | ordered | * | |
| 2461 | // | target parallel | atomic | * | |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2462 | // | target parallel | target | | |
| 2463 | // | target parallel | target parallel | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2464 | // | target parallel | target parallel | | |
| 2465 | // | | for | | |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2466 | // | target parallel | target enter | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2467 | // | | data | | |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2468 | // | target parallel | target exit | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2469 | // | | data | | |
| 2470 | // | target parallel | teams | | |
| 2471 | // | target parallel | cancellation | | |
| 2472 | // | | point | ! | |
| 2473 | // | target parallel | cancel | ! | |
| 2474 | // | target parallel | taskloop | * | |
| 2475 | // | target parallel | taskloop simd | * | |
| 2476 | // | target parallel | distribute | | |
| 2477 | // +------------------+-----------------+------------------------------------+ |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2478 | // | target parallel | parallel | * | |
| 2479 | // | for | | | |
| 2480 | // | target parallel | for | * | |
| 2481 | // | for | | | |
| 2482 | // | target parallel | for simd | * | |
| 2483 | // | for | | | |
| 2484 | // | target parallel | master | * | |
| 2485 | // | for | | | |
| 2486 | // | target parallel | critical | * | |
| 2487 | // | for | | | |
| 2488 | // | target parallel | simd | * | |
| 2489 | // | for | | | |
| 2490 | // | target parallel | sections | * | |
| 2491 | // | for | | | |
| 2492 | // | target parallel | section | * | |
| 2493 | // | for | | | |
| 2494 | // | target parallel | single | * | |
| 2495 | // | for | | | |
| 2496 | // | target parallel | parallel for | * | |
| 2497 | // | for | | | |
| 2498 | // | target parallel |parallel for simd| * | |
| 2499 | // | for | | | |
| 2500 | // | target parallel |parallel sections| * | |
| 2501 | // | for | | | |
| 2502 | // | target parallel | task | * | |
| 2503 | // | for | | | |
| 2504 | // | target parallel | taskyield | * | |
| 2505 | // | for | | | |
| 2506 | // | target parallel | barrier | * | |
| 2507 | // | for | | | |
| 2508 | // | target parallel | taskwait | * | |
| 2509 | // | for | | | |
| 2510 | // | target parallel | taskgroup | * | |
| 2511 | // | for | | | |
| 2512 | // | target parallel | flush | * | |
| 2513 | // | for | | | |
| 2514 | // | target parallel | ordered | * | |
| 2515 | // | for | | | |
| 2516 | // | target parallel | atomic | * | |
| 2517 | // | for | | | |
| 2518 | // | target parallel | target | | |
| 2519 | // | for | | | |
| 2520 | // | target parallel | target parallel | | |
| 2521 | // | for | | | |
| 2522 | // | target parallel | target parallel | | |
| 2523 | // | for | for | | |
| 2524 | // | target parallel | target enter | | |
| 2525 | // | for | data | | |
| 2526 | // | target parallel | target exit | | |
| 2527 | // | for | data | | |
| 2528 | // | target parallel | teams | | |
| 2529 | // | for | | | |
| 2530 | // | target parallel | cancellation | | |
| 2531 | // | for | point | ! | |
| 2532 | // | target parallel | cancel | ! | |
| 2533 | // | for | | | |
| 2534 | // | target parallel | taskloop | * | |
| 2535 | // | for | | | |
| 2536 | // | target parallel | taskloop simd | * | |
| 2537 | // | for | | | |
| 2538 | // | target parallel | distribute | | |
| 2539 | // | for | | | |
| 2540 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2541 | // | teams | parallel | * | |
| 2542 | // | teams | for | + | |
| 2543 | // | teams | for simd | + | |
| 2544 | // | teams | master | + | |
| 2545 | // | teams | critical | + | |
| 2546 | // | teams | simd | + | |
| 2547 | // | teams | sections | + | |
| 2548 | // | teams | section | + | |
| 2549 | // | teams | single | + | |
| 2550 | // | teams | parallel for | * | |
| 2551 | // | teams |parallel for simd| * | |
| 2552 | // | teams |parallel sections| * | |
| 2553 | // | teams | task | + | |
| 2554 | // | teams | taskyield | + | |
| 2555 | // | teams | barrier | + | |
| 2556 | // | teams | taskwait | + | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2557 | // | teams | taskgroup | + | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2558 | // | teams | flush | + | |
| 2559 | // | teams | ordered | + | |
| 2560 | // | teams | atomic | + | |
| 2561 | // | teams | target | + | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2562 | // | teams | target parallel | + | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2563 | // | teams | target parallel | + | |
| 2564 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2565 | // | teams | target enter | + | |
| 2566 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2567 | // | teams | target exit | + | |
| 2568 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2569 | // | teams | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2570 | // | teams | cancellation | | |
| 2571 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2572 | // | teams | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2573 | // | teams | taskloop | + | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2574 | // | teams | taskloop simd | + | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2575 | // | teams | distribute | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2576 | // +------------------+-----------------+------------------------------------+ |
| 2577 | // | taskloop | parallel | * | |
| 2578 | // | taskloop | for | + | |
| 2579 | // | taskloop | for simd | + | |
| 2580 | // | taskloop | master | + | |
| 2581 | // | taskloop | critical | * | |
| 2582 | // | taskloop | simd | * | |
| 2583 | // | taskloop | sections | + | |
| 2584 | // | taskloop | section | + | |
| 2585 | // | taskloop | single | + | |
| 2586 | // | taskloop | parallel for | * | |
| 2587 | // | taskloop |parallel for simd| * | |
| 2588 | // | taskloop |parallel sections| * | |
| 2589 | // | taskloop | task | * | |
| 2590 | // | taskloop | taskyield | * | |
| 2591 | // | taskloop | barrier | + | |
| 2592 | // | taskloop | taskwait | * | |
| 2593 | // | taskloop | taskgroup | * | |
| 2594 | // | taskloop | flush | * | |
| 2595 | // | taskloop | ordered | + | |
| 2596 | // | taskloop | atomic | * | |
| 2597 | // | taskloop | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2598 | // | taskloop | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2599 | // | taskloop | target parallel | * | |
| 2600 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2601 | // | taskloop | target enter | * | |
| 2602 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2603 | // | taskloop | target exit | * | |
| 2604 | // | | data | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2605 | // | taskloop | teams | + | |
| 2606 | // | taskloop | cancellation | | |
| 2607 | // | | point | | |
| 2608 | // | taskloop | cancel | | |
| 2609 | // | taskloop | taskloop | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2610 | // | taskloop | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2611 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2612 | // | taskloop simd | parallel | | |
| 2613 | // | taskloop simd | for | | |
| 2614 | // | taskloop simd | for simd | | |
| 2615 | // | taskloop simd | master | | |
| 2616 | // | taskloop simd | critical | | |
Alexey Bataev | 1f09221 | 2016-02-02 04:59:52 +0000 | [diff] [blame] | 2617 | // | taskloop simd | simd | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2618 | // | taskloop simd | sections | | |
| 2619 | // | taskloop simd | section | | |
| 2620 | // | taskloop simd | single | | |
| 2621 | // | taskloop simd | parallel for | | |
| 2622 | // | taskloop simd |parallel for simd| | |
| 2623 | // | taskloop simd |parallel sections| | |
| 2624 | // | taskloop simd | task | | |
| 2625 | // | taskloop simd | taskyield | | |
| 2626 | // | taskloop simd | barrier | | |
| 2627 | // | taskloop simd | taskwait | | |
| 2628 | // | taskloop simd | taskgroup | | |
| 2629 | // | taskloop simd | flush | | |
| 2630 | // | taskloop simd | ordered | + (with simd clause) | |
| 2631 | // | taskloop simd | atomic | | |
| 2632 | // | taskloop simd | target | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2633 | // | taskloop simd | target parallel | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2634 | // | taskloop simd | target parallel | | |
| 2635 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2636 | // | taskloop simd | target enter | | |
| 2637 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2638 | // | taskloop simd | target exit | | |
| 2639 | // | | data | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2640 | // | taskloop simd | teams | | |
| 2641 | // | taskloop simd | cancellation | | |
| 2642 | // | | point | | |
| 2643 | // | taskloop simd | cancel | | |
| 2644 | // | taskloop simd | taskloop | | |
| 2645 | // | taskloop simd | taskloop simd | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2646 | // | taskloop simd | distribute | | |
| 2647 | // +------------------+-----------------+------------------------------------+ |
| 2648 | // | distribute | parallel | * | |
| 2649 | // | distribute | for | * | |
| 2650 | // | distribute | for simd | * | |
| 2651 | // | distribute | master | * | |
| 2652 | // | distribute | critical | * | |
| 2653 | // | distribute | simd | * | |
| 2654 | // | distribute | sections | * | |
| 2655 | // | distribute | section | * | |
| 2656 | // | distribute | single | * | |
| 2657 | // | distribute | parallel for | * | |
| 2658 | // | distribute |parallel for simd| * | |
| 2659 | // | distribute |parallel sections| * | |
| 2660 | // | distribute | task | * | |
| 2661 | // | distribute | taskyield | * | |
| 2662 | // | distribute | barrier | * | |
| 2663 | // | distribute | taskwait | * | |
| 2664 | // | distribute | taskgroup | * | |
| 2665 | // | distribute | flush | * | |
| 2666 | // | distribute | ordered | + | |
| 2667 | // | distribute | atomic | * | |
| 2668 | // | distribute | target | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2669 | // | distribute | target parallel | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2670 | // | distribute | target parallel | | |
| 2671 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2672 | // | distribute | target enter | | |
| 2673 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2674 | // | distribute | target exit | | |
| 2675 | // | | data | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2676 | // | distribute | teams | | |
| 2677 | // | distribute | cancellation | + | |
| 2678 | // | | point | | |
| 2679 | // | distribute | cancel | + | |
| 2680 | // | distribute | taskloop | * | |
| 2681 | // | distribute | taskloop simd | * | |
| 2682 | // | distribute | distribute | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2683 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2684 | if (Stack->getCurScope()) { |
| 2685 | auto ParentRegion = Stack->getParentDirective(); |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2686 | auto OffendingRegion = ParentRegion; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2687 | bool NestingProhibited = false; |
| 2688 | bool CloseNesting = true; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2689 | enum { |
| 2690 | NoRecommend, |
| 2691 | ShouldBeInParallelRegion, |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2692 | ShouldBeInOrderedRegion, |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2693 | ShouldBeInTargetRegion, |
| 2694 | ShouldBeInTeamsRegion |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2695 | } Recommend = NoRecommend; |
Alexey Bataev | 1f09221 | 2016-02-02 04:59:52 +0000 | [diff] [blame] | 2696 | if (isOpenMPSimdDirective(ParentRegion) && CurrentRegion != OMPD_ordered && |
| 2697 | CurrentRegion != OMPD_simd) { |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2698 | // OpenMP [2.16, Nesting of Regions] |
| 2699 | // OpenMP constructs may not be nested inside a simd region. |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2700 | // OpenMP [2.8.1,simd Construct, Restrictions] |
| 2701 | // An ordered construct with the simd clause is the only OpenMP construct |
| 2702 | // that can appear in the simd region. |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2703 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region_simd); |
| 2704 | return true; |
| 2705 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2706 | if (ParentRegion == OMPD_atomic) { |
| 2707 | // OpenMP [2.16, Nesting of Regions] |
| 2708 | // OpenMP constructs may not be nested inside an atomic region. |
| 2709 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region_atomic); |
| 2710 | return true; |
| 2711 | } |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2712 | if (CurrentRegion == OMPD_section) { |
| 2713 | // OpenMP [2.7.2, sections Construct, Restrictions] |
| 2714 | // Orphaned section directives are prohibited. That is, the section |
| 2715 | // directives must appear within the sections construct and must not be |
| 2716 | // encountered elsewhere in the sections region. |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2717 | if (ParentRegion != OMPD_sections && |
| 2718 | ParentRegion != OMPD_parallel_sections) { |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2719 | SemaRef.Diag(StartLoc, diag::err_omp_orphaned_section_directive) |
| 2720 | << (ParentRegion != OMPD_unknown) |
| 2721 | << getOpenMPDirectiveName(ParentRegion); |
| 2722 | return true; |
| 2723 | } |
| 2724 | return false; |
| 2725 | } |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2726 | // Allow some constructs to be orphaned (they could be used in functions, |
| 2727 | // called from OpenMP regions with the required preconditions). |
| 2728 | if (ParentRegion == OMPD_unknown) |
| 2729 | return false; |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2730 | if (CurrentRegion == OMPD_cancellation_point || |
| 2731 | CurrentRegion == OMPD_cancel) { |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2732 | // OpenMP [2.16, Nesting of Regions] |
| 2733 | // A cancellation point construct for which construct-type-clause is |
| 2734 | // taskgroup must be nested inside a task construct. A cancellation |
| 2735 | // point construct for which construct-type-clause is not taskgroup must |
| 2736 | // be closely nested inside an OpenMP construct that matches the type |
| 2737 | // specified in construct-type-clause. |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2738 | // A cancel construct for which construct-type-clause is taskgroup must be |
| 2739 | // nested inside a task construct. A cancel construct for which |
| 2740 | // construct-type-clause is not taskgroup must be closely nested inside an |
| 2741 | // OpenMP construct that matches the type specified in |
| 2742 | // construct-type-clause. |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2743 | NestingProhibited = |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2744 | !((CancelRegion == OMPD_parallel && |
| 2745 | (ParentRegion == OMPD_parallel || |
| 2746 | ParentRegion == OMPD_target_parallel)) || |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 2747 | (CancelRegion == OMPD_for && |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2748 | (ParentRegion == OMPD_for || ParentRegion == OMPD_parallel_for || |
| 2749 | ParentRegion == OMPD_target_parallel_for)) || |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2750 | (CancelRegion == OMPD_taskgroup && ParentRegion == OMPD_task) || |
| 2751 | (CancelRegion == OMPD_sections && |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 2752 | (ParentRegion == OMPD_section || ParentRegion == OMPD_sections || |
| 2753 | ParentRegion == OMPD_parallel_sections))); |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2754 | } else if (CurrentRegion == OMPD_master) { |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2755 | // OpenMP [2.16, Nesting of Regions] |
| 2756 | // A master region may not be closely nested inside a worksharing, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2757 | // atomic, or explicit task region. |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2758 | NestingProhibited = isOpenMPWorksharingDirective(ParentRegion) || |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2759 | ParentRegion == OMPD_task || |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2760 | isOpenMPTaskLoopDirective(ParentRegion); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2761 | } else if (CurrentRegion == OMPD_critical && CurrentName.getName()) { |
| 2762 | // OpenMP [2.16, Nesting of Regions] |
| 2763 | // A critical region may not be nested (closely or otherwise) inside a |
| 2764 | // critical region with the same name. Note that this restriction is not |
| 2765 | // sufficient to prevent deadlock. |
| 2766 | SourceLocation PreviousCriticalLoc; |
| 2767 | bool DeadLock = |
| 2768 | Stack->hasDirective([CurrentName, &PreviousCriticalLoc]( |
| 2769 | OpenMPDirectiveKind K, |
| 2770 | const DeclarationNameInfo &DNI, |
| 2771 | SourceLocation Loc) |
| 2772 | ->bool { |
| 2773 | if (K == OMPD_critical && |
| 2774 | DNI.getName() == CurrentName.getName()) { |
| 2775 | PreviousCriticalLoc = Loc; |
| 2776 | return true; |
| 2777 | } else |
| 2778 | return false; |
| 2779 | }, |
| 2780 | false /* skip top directive */); |
| 2781 | if (DeadLock) { |
| 2782 | SemaRef.Diag(StartLoc, |
| 2783 | diag::err_omp_prohibited_region_critical_same_name) |
| 2784 | << CurrentName.getName(); |
| 2785 | if (PreviousCriticalLoc.isValid()) |
| 2786 | SemaRef.Diag(PreviousCriticalLoc, |
| 2787 | diag::note_omp_previous_critical_region); |
| 2788 | return true; |
| 2789 | } |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2790 | } else if (CurrentRegion == OMPD_barrier) { |
| 2791 | // OpenMP [2.16, Nesting of Regions] |
| 2792 | // A barrier region may not be closely nested inside a worksharing, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2793 | // explicit task, critical, ordered, atomic, or master region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2794 | NestingProhibited = |
| 2795 | isOpenMPWorksharingDirective(ParentRegion) || |
| 2796 | ParentRegion == OMPD_task || ParentRegion == OMPD_master || |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2797 | ParentRegion == OMPD_critical || ParentRegion == OMPD_ordered || |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2798 | isOpenMPTaskLoopDirective(ParentRegion); |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2799 | } else if (isOpenMPWorksharingDirective(CurrentRegion) && |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2800 | !isOpenMPParallelDirective(CurrentRegion)) { |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2801 | // OpenMP [2.16, Nesting of Regions] |
| 2802 | // A worksharing region may not be closely nested inside a worksharing, |
| 2803 | // explicit task, critical, ordered, atomic, or master region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2804 | NestingProhibited = |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2805 | isOpenMPWorksharingDirective(ParentRegion) || |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2806 | ParentRegion == OMPD_task || ParentRegion == OMPD_master || |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2807 | ParentRegion == OMPD_critical || ParentRegion == OMPD_ordered || |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2808 | isOpenMPTaskLoopDirective(ParentRegion); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2809 | Recommend = ShouldBeInParallelRegion; |
| 2810 | } else if (CurrentRegion == OMPD_ordered) { |
| 2811 | // OpenMP [2.16, Nesting of Regions] |
| 2812 | // An ordered region may not be closely nested inside a critical, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2813 | // atomic, or explicit task region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2814 | // An ordered region must be closely nested inside a loop region (or |
| 2815 | // parallel loop region) with an ordered clause. |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2816 | // OpenMP [2.8.1,simd Construct, Restrictions] |
| 2817 | // An ordered construct with the simd clause is the only OpenMP construct |
| 2818 | // that can appear in the simd region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2819 | NestingProhibited = ParentRegion == OMPD_critical || |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2820 | ParentRegion == OMPD_task || |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2821 | isOpenMPTaskLoopDirective(ParentRegion) || |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2822 | !(isOpenMPSimdDirective(ParentRegion) || |
| 2823 | Stack->isParentOrderedRegion()); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2824 | Recommend = ShouldBeInOrderedRegion; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2825 | } else if (isOpenMPTeamsDirective(CurrentRegion)) { |
| 2826 | // OpenMP [2.16, Nesting of Regions] |
| 2827 | // If specified, a teams construct must be contained within a target |
| 2828 | // construct. |
| 2829 | NestingProhibited = ParentRegion != OMPD_target; |
| 2830 | Recommend = ShouldBeInTargetRegion; |
| 2831 | Stack->setParentTeamsRegionLoc(Stack->getConstructLoc()); |
| 2832 | } |
| 2833 | if (!NestingProhibited && isOpenMPTeamsDirective(ParentRegion)) { |
| 2834 | // OpenMP [2.16, Nesting of Regions] |
| 2835 | // distribute, parallel, parallel sections, parallel workshare, and the |
| 2836 | // parallel loop and parallel loop SIMD constructs are the only OpenMP |
| 2837 | // constructs that can be closely nested in the teams region. |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2838 | NestingProhibited = !isOpenMPParallelDirective(CurrentRegion) && |
| 2839 | !isOpenMPDistributeDirective(CurrentRegion); |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2840 | Recommend = ShouldBeInParallelRegion; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2841 | } |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2842 | if (!NestingProhibited && isOpenMPDistributeDirective(CurrentRegion)) { |
| 2843 | // OpenMP 4.5 [2.17 Nesting of Regions] |
| 2844 | // The region associated with the distribute construct must be strictly |
| 2845 | // nested inside a teams region |
| 2846 | NestingProhibited = !isOpenMPTeamsDirective(ParentRegion); |
| 2847 | Recommend = ShouldBeInTeamsRegion; |
| 2848 | } |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2849 | if (!NestingProhibited && |
| 2850 | (isOpenMPTargetExecutionDirective(CurrentRegion) || |
| 2851 | isOpenMPTargetDataManagementDirective(CurrentRegion))) { |
| 2852 | // OpenMP 4.5 [2.17 Nesting of Regions] |
| 2853 | // If a target, target update, target data, target enter data, or |
| 2854 | // target exit data construct is encountered during execution of a |
| 2855 | // target region, the behavior is unspecified. |
| 2856 | NestingProhibited = Stack->hasDirective( |
| 2857 | [&OffendingRegion](OpenMPDirectiveKind K, |
| 2858 | const DeclarationNameInfo &DNI, |
| 2859 | SourceLocation Loc) -> bool { |
| 2860 | if (isOpenMPTargetExecutionDirective(K)) { |
| 2861 | OffendingRegion = K; |
| 2862 | return true; |
| 2863 | } else |
| 2864 | return false; |
| 2865 | }, |
| 2866 | false /* don't skip top directive */); |
| 2867 | CloseNesting = false; |
| 2868 | } |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2869 | if (NestingProhibited) { |
| 2870 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region) |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2871 | << CloseNesting << getOpenMPDirectiveName(OffendingRegion) |
| 2872 | << Recommend << getOpenMPDirectiveName(CurrentRegion); |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2873 | return true; |
| 2874 | } |
| 2875 | } |
| 2876 | return false; |
| 2877 | } |
| 2878 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2879 | static bool checkIfClauses(Sema &S, OpenMPDirectiveKind Kind, |
| 2880 | ArrayRef<OMPClause *> Clauses, |
| 2881 | ArrayRef<OpenMPDirectiveKind> AllowedNameModifiers) { |
| 2882 | bool ErrorFound = false; |
| 2883 | unsigned NamedModifiersNumber = 0; |
| 2884 | SmallVector<const OMPIfClause *, OMPC_unknown + 1> FoundNameModifiers( |
| 2885 | OMPD_unknown + 1); |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2886 | SmallVector<SourceLocation, 4> NameModifierLoc; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2887 | for (const auto *C : Clauses) { |
| 2888 | if (const auto *IC = dyn_cast_or_null<OMPIfClause>(C)) { |
| 2889 | // At most one if clause without a directive-name-modifier can appear on |
| 2890 | // the directive. |
| 2891 | OpenMPDirectiveKind CurNM = IC->getNameModifier(); |
| 2892 | if (FoundNameModifiers[CurNM]) { |
| 2893 | S.Diag(C->getLocStart(), diag::err_omp_more_one_clause) |
| 2894 | << getOpenMPDirectiveName(Kind) << getOpenMPClauseName(OMPC_if) |
| 2895 | << (CurNM != OMPD_unknown) << getOpenMPDirectiveName(CurNM); |
| 2896 | ErrorFound = true; |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2897 | } else if (CurNM != OMPD_unknown) { |
| 2898 | NameModifierLoc.push_back(IC->getNameModifierLoc()); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2899 | ++NamedModifiersNumber; |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2900 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2901 | FoundNameModifiers[CurNM] = IC; |
| 2902 | if (CurNM == OMPD_unknown) |
| 2903 | continue; |
| 2904 | // Check if the specified name modifier is allowed for the current |
| 2905 | // directive. |
| 2906 | // At most one if clause with the particular directive-name-modifier can |
| 2907 | // appear on the directive. |
| 2908 | bool MatchFound = false; |
| 2909 | for (auto NM : AllowedNameModifiers) { |
| 2910 | if (CurNM == NM) { |
| 2911 | MatchFound = true; |
| 2912 | break; |
| 2913 | } |
| 2914 | } |
| 2915 | if (!MatchFound) { |
| 2916 | S.Diag(IC->getNameModifierLoc(), |
| 2917 | diag::err_omp_wrong_if_directive_name_modifier) |
| 2918 | << getOpenMPDirectiveName(CurNM) << getOpenMPDirectiveName(Kind); |
| 2919 | ErrorFound = true; |
| 2920 | } |
| 2921 | } |
| 2922 | } |
| 2923 | // If any if clause on the directive includes a directive-name-modifier then |
| 2924 | // all if clauses on the directive must include a directive-name-modifier. |
| 2925 | if (FoundNameModifiers[OMPD_unknown] && NamedModifiersNumber > 0) { |
| 2926 | if (NamedModifiersNumber == AllowedNameModifiers.size()) { |
| 2927 | S.Diag(FoundNameModifiers[OMPD_unknown]->getLocStart(), |
| 2928 | diag::err_omp_no_more_if_clause); |
| 2929 | } else { |
| 2930 | std::string Values; |
| 2931 | std::string Sep(", "); |
| 2932 | unsigned AllowedCnt = 0; |
| 2933 | unsigned TotalAllowedNum = |
| 2934 | AllowedNameModifiers.size() - NamedModifiersNumber; |
| 2935 | for (unsigned Cnt = 0, End = AllowedNameModifiers.size(); Cnt < End; |
| 2936 | ++Cnt) { |
| 2937 | OpenMPDirectiveKind NM = AllowedNameModifiers[Cnt]; |
| 2938 | if (!FoundNameModifiers[NM]) { |
| 2939 | Values += "'"; |
| 2940 | Values += getOpenMPDirectiveName(NM); |
| 2941 | Values += "'"; |
| 2942 | if (AllowedCnt + 2 == TotalAllowedNum) |
| 2943 | Values += " or "; |
| 2944 | else if (AllowedCnt + 1 != TotalAllowedNum) |
| 2945 | Values += Sep; |
| 2946 | ++AllowedCnt; |
| 2947 | } |
| 2948 | } |
| 2949 | S.Diag(FoundNameModifiers[OMPD_unknown]->getCondition()->getLocStart(), |
| 2950 | diag::err_omp_unnamed_if_clause) |
| 2951 | << (TotalAllowedNum > 1) << Values; |
| 2952 | } |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2953 | for (auto Loc : NameModifierLoc) { |
| 2954 | S.Diag(Loc, diag::note_omp_previous_named_if_clause); |
| 2955 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2956 | ErrorFound = true; |
| 2957 | } |
| 2958 | return ErrorFound; |
| 2959 | } |
| 2960 | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2961 | StmtResult Sema::ActOnOpenMPExecutableDirective( |
| 2962 | OpenMPDirectiveKind Kind, const DeclarationNameInfo &DirName, |
| 2963 | OpenMPDirectiveKind CancelRegion, ArrayRef<OMPClause *> Clauses, |
| 2964 | Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2965 | StmtResult Res = StmtError(); |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2966 | if (CheckNestingOfRegions(*this, DSAStack, Kind, DirName, CancelRegion, |
| 2967 | StartLoc)) |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2968 | return StmtError(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2969 | |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2970 | llvm::SmallVector<OMPClause *, 8> ClausesWithImplicit; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 2971 | llvm::DenseMap<ValueDecl *, Expr *> VarsWithInheritedDSA; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2972 | bool ErrorFound = false; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2973 | ClausesWithImplicit.append(Clauses.begin(), Clauses.end()); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2974 | if (AStmt) { |
| 2975 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 2976 | |
| 2977 | // Check default data sharing attributes for referenced variables. |
| 2978 | DSAAttrChecker DSAChecker(DSAStack, *this, cast<CapturedStmt>(AStmt)); |
| 2979 | DSAChecker.Visit(cast<CapturedStmt>(AStmt)->getCapturedStmt()); |
| 2980 | if (DSAChecker.isErrorFound()) |
| 2981 | return StmtError(); |
| 2982 | // Generate list of implicitly defined firstprivate variables. |
| 2983 | VarsWithInheritedDSA = DSAChecker.getVarsWithInheritedDSA(); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2984 | |
| 2985 | if (!DSAChecker.getImplicitFirstprivate().empty()) { |
| 2986 | if (OMPClause *Implicit = ActOnOpenMPFirstprivateClause( |
| 2987 | DSAChecker.getImplicitFirstprivate(), SourceLocation(), |
| 2988 | SourceLocation(), SourceLocation())) { |
| 2989 | ClausesWithImplicit.push_back(Implicit); |
| 2990 | ErrorFound = cast<OMPFirstprivateClause>(Implicit)->varlist_size() != |
| 2991 | DSAChecker.getImplicitFirstprivate().size(); |
| 2992 | } else |
| 2993 | ErrorFound = true; |
| 2994 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2995 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2996 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2997 | llvm::SmallVector<OpenMPDirectiveKind, 4> AllowedNameModifiers; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2998 | switch (Kind) { |
| 2999 | case OMPD_parallel: |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 3000 | Res = ActOnOpenMPParallelDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3001 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3002 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3003 | break; |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 3004 | case OMPD_simd: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3005 | Res = ActOnOpenMPSimdDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc, |
| 3006 | VarsWithInheritedDSA); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 3007 | break; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3008 | case OMPD_for: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3009 | Res = ActOnOpenMPForDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc, |
| 3010 | VarsWithInheritedDSA); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3011 | break; |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 3012 | case OMPD_for_simd: |
| 3013 | Res = ActOnOpenMPForSimdDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3014 | EndLoc, VarsWithInheritedDSA); |
| 3015 | break; |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 3016 | case OMPD_sections: |
| 3017 | Res = ActOnOpenMPSectionsDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3018 | EndLoc); |
| 3019 | break; |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 3020 | case OMPD_section: |
| 3021 | assert(ClausesWithImplicit.empty() && |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 3022 | "No clauses are allowed for 'omp section' directive"); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 3023 | Res = ActOnOpenMPSectionDirective(AStmt, StartLoc, EndLoc); |
| 3024 | break; |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 3025 | case OMPD_single: |
| 3026 | Res = ActOnOpenMPSingleDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3027 | EndLoc); |
| 3028 | break; |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 3029 | case OMPD_master: |
| 3030 | assert(ClausesWithImplicit.empty() && |
| 3031 | "No clauses are allowed for 'omp master' directive"); |
| 3032 | Res = ActOnOpenMPMasterDirective(AStmt, StartLoc, EndLoc); |
| 3033 | break; |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 3034 | case OMPD_critical: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 3035 | Res = ActOnOpenMPCriticalDirective(DirName, ClausesWithImplicit, AStmt, |
| 3036 | StartLoc, EndLoc); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 3037 | break; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3038 | case OMPD_parallel_for: |
| 3039 | Res = ActOnOpenMPParallelForDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3040 | EndLoc, VarsWithInheritedDSA); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3041 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3042 | break; |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 3043 | case OMPD_parallel_for_simd: |
| 3044 | Res = ActOnOpenMPParallelForSimdDirective( |
| 3045 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3046 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 3047 | break; |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 3048 | case OMPD_parallel_sections: |
| 3049 | Res = ActOnOpenMPParallelSectionsDirective(ClausesWithImplicit, AStmt, |
| 3050 | StartLoc, EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3051 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 3052 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3053 | case OMPD_task: |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 3054 | Res = |
| 3055 | ActOnOpenMPTaskDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3056 | AllowedNameModifiers.push_back(OMPD_task); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 3057 | break; |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 3058 | case OMPD_taskyield: |
| 3059 | assert(ClausesWithImplicit.empty() && |
| 3060 | "No clauses are allowed for 'omp taskyield' directive"); |
| 3061 | assert(AStmt == nullptr && |
| 3062 | "No associated statement allowed for 'omp taskyield' directive"); |
| 3063 | Res = ActOnOpenMPTaskyieldDirective(StartLoc, EndLoc); |
| 3064 | break; |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 3065 | case OMPD_barrier: |
| 3066 | assert(ClausesWithImplicit.empty() && |
| 3067 | "No clauses are allowed for 'omp barrier' directive"); |
| 3068 | assert(AStmt == nullptr && |
| 3069 | "No associated statement allowed for 'omp barrier' directive"); |
| 3070 | Res = ActOnOpenMPBarrierDirective(StartLoc, EndLoc); |
| 3071 | break; |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 3072 | case OMPD_taskwait: |
| 3073 | assert(ClausesWithImplicit.empty() && |
| 3074 | "No clauses are allowed for 'omp taskwait' directive"); |
| 3075 | assert(AStmt == nullptr && |
| 3076 | "No associated statement allowed for 'omp taskwait' directive"); |
| 3077 | Res = ActOnOpenMPTaskwaitDirective(StartLoc, EndLoc); |
| 3078 | break; |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 3079 | case OMPD_taskgroup: |
| 3080 | assert(ClausesWithImplicit.empty() && |
| 3081 | "No clauses are allowed for 'omp taskgroup' directive"); |
| 3082 | Res = ActOnOpenMPTaskgroupDirective(AStmt, StartLoc, EndLoc); |
| 3083 | break; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 3084 | case OMPD_flush: |
| 3085 | assert(AStmt == nullptr && |
| 3086 | "No associated statement allowed for 'omp flush' directive"); |
| 3087 | Res = ActOnOpenMPFlushDirective(ClausesWithImplicit, StartLoc, EndLoc); |
| 3088 | break; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 3089 | case OMPD_ordered: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 3090 | Res = ActOnOpenMPOrderedDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3091 | EndLoc); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 3092 | break; |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 3093 | case OMPD_atomic: |
| 3094 | Res = ActOnOpenMPAtomicDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3095 | EndLoc); |
| 3096 | break; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 3097 | case OMPD_teams: |
| 3098 | Res = |
| 3099 | ActOnOpenMPTeamsDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); |
| 3100 | break; |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 3101 | case OMPD_target: |
| 3102 | Res = ActOnOpenMPTargetDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3103 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3104 | AllowedNameModifiers.push_back(OMPD_target); |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 3105 | break; |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 3106 | case OMPD_target_parallel: |
| 3107 | Res = ActOnOpenMPTargetParallelDirective(ClausesWithImplicit, AStmt, |
| 3108 | StartLoc, EndLoc); |
| 3109 | AllowedNameModifiers.push_back(OMPD_target); |
| 3110 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 3111 | break; |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 3112 | case OMPD_target_parallel_for: |
| 3113 | Res = ActOnOpenMPTargetParallelForDirective( |
| 3114 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 3115 | AllowedNameModifiers.push_back(OMPD_target); |
| 3116 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 3117 | break; |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 3118 | case OMPD_cancellation_point: |
| 3119 | assert(ClausesWithImplicit.empty() && |
| 3120 | "No clauses are allowed for 'omp cancellation point' directive"); |
| 3121 | assert(AStmt == nullptr && "No associated statement allowed for 'omp " |
| 3122 | "cancellation point' directive"); |
| 3123 | Res = ActOnOpenMPCancellationPointDirective(StartLoc, EndLoc, CancelRegion); |
| 3124 | break; |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 3125 | case OMPD_cancel: |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 3126 | assert(AStmt == nullptr && |
| 3127 | "No associated statement allowed for 'omp cancel' directive"); |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 3128 | Res = ActOnOpenMPCancelDirective(ClausesWithImplicit, StartLoc, EndLoc, |
| 3129 | CancelRegion); |
| 3130 | AllowedNameModifiers.push_back(OMPD_cancel); |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 3131 | break; |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 3132 | case OMPD_target_data: |
| 3133 | Res = ActOnOpenMPTargetDataDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3134 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3135 | AllowedNameModifiers.push_back(OMPD_target_data); |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 3136 | break; |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 3137 | case OMPD_target_enter_data: |
| 3138 | Res = ActOnOpenMPTargetEnterDataDirective(ClausesWithImplicit, StartLoc, |
| 3139 | EndLoc); |
| 3140 | AllowedNameModifiers.push_back(OMPD_target_enter_data); |
| 3141 | break; |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 3142 | case OMPD_target_exit_data: |
| 3143 | Res = ActOnOpenMPTargetExitDataDirective(ClausesWithImplicit, StartLoc, |
| 3144 | EndLoc); |
| 3145 | AllowedNameModifiers.push_back(OMPD_target_exit_data); |
| 3146 | break; |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 3147 | case OMPD_taskloop: |
| 3148 | Res = ActOnOpenMPTaskLoopDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3149 | EndLoc, VarsWithInheritedDSA); |
| 3150 | AllowedNameModifiers.push_back(OMPD_taskloop); |
| 3151 | break; |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 3152 | case OMPD_taskloop_simd: |
| 3153 | Res = ActOnOpenMPTaskLoopSimdDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3154 | EndLoc, VarsWithInheritedDSA); |
| 3155 | AllowedNameModifiers.push_back(OMPD_taskloop); |
| 3156 | break; |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 3157 | case OMPD_distribute: |
| 3158 | Res = ActOnOpenMPDistributeDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3159 | EndLoc, VarsWithInheritedDSA); |
| 3160 | break; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 3161 | case OMPD_threadprivate: |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 3162 | case OMPD_declare_reduction: |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 3163 | case OMPD_declare_simd: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3164 | llvm_unreachable("OpenMP Directive is not allowed"); |
| 3165 | case OMPD_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3166 | llvm_unreachable("Unknown OpenMP directive"); |
| 3167 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 3168 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3169 | for (auto P : VarsWithInheritedDSA) { |
| 3170 | Diag(P.second->getExprLoc(), diag::err_omp_no_dsa_for_variable) |
| 3171 | << P.first << P.second->getSourceRange(); |
| 3172 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3173 | ErrorFound = !VarsWithInheritedDSA.empty() || ErrorFound; |
| 3174 | |
| 3175 | if (!AllowedNameModifiers.empty()) |
| 3176 | ErrorFound = checkIfClauses(*this, Kind, Clauses, AllowedNameModifiers) || |
| 3177 | ErrorFound; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3178 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 3179 | if (ErrorFound) |
| 3180 | return StmtError(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3181 | return Res; |
| 3182 | } |
| 3183 | |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 3184 | Sema::DeclGroupPtrTy |
| 3185 | Sema::ActOnOpenMPDeclareSimdDirective(DeclGroupPtrTy DG, |
| 3186 | SourceLocation StartLoc) { |
| 3187 | if (!DG || DG.get().isNull()) |
| 3188 | return DeclGroupPtrTy(); |
| 3189 | |
| 3190 | if (!DG.get().isSingleDecl()) { |
| 3191 | Diag(StartLoc, diag::err_omp_single_decl_in_declare_simd); |
| 3192 | return DG; |
| 3193 | } |
| 3194 | auto *ADecl = DG.get().getSingleDecl(); |
| 3195 | if (auto *FTD = dyn_cast<FunctionTemplateDecl>(ADecl)) |
| 3196 | ADecl = FTD->getTemplatedDecl(); |
| 3197 | |
| 3198 | if (!isa<FunctionDecl>(ADecl)) { |
| 3199 | Diag(ADecl->getLocation(), diag::err_omp_function_expected) |
| 3200 | << ADecl->getDeclContext()->isFileContext(); |
| 3201 | return DeclGroupPtrTy(); |
| 3202 | } |
| 3203 | |
| 3204 | auto *NewAttr = OMPDeclareSimdDeclAttr::CreateImplicit( |
| 3205 | Context, SourceRange(StartLoc, StartLoc)); |
| 3206 | ADecl->addAttr(NewAttr); |
| 3207 | return ConvertDeclToDeclGroup(ADecl); |
| 3208 | } |
| 3209 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3210 | StmtResult Sema::ActOnOpenMPParallelDirective(ArrayRef<OMPClause *> Clauses, |
| 3211 | Stmt *AStmt, |
| 3212 | SourceLocation StartLoc, |
| 3213 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3214 | if (!AStmt) |
| 3215 | return StmtError(); |
| 3216 | |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 3217 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 3218 | // 1.2.2 OpenMP Language Terminology |
| 3219 | // Structured block - An executable statement with a single entry at the |
| 3220 | // top and a single exit at the bottom. |
| 3221 | // The point of exit cannot be a branch out of the structured block. |
| 3222 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 3223 | CS->getCapturedDecl()->setNothrow(); |
| 3224 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3225 | getCurFunction()->setHasBranchProtectedScope(); |
| 3226 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 3227 | return OMPParallelDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 3228 | DSAStack->isCancelRegion()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3229 | } |
| 3230 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3231 | namespace { |
| 3232 | /// \brief Helper class for checking canonical form of the OpenMP loops and |
| 3233 | /// extracting iteration space of each loop in the loop nest, that will be used |
| 3234 | /// for IR generation. |
| 3235 | class OpenMPIterationSpaceChecker { |
| 3236 | /// \brief Reference to Sema. |
| 3237 | Sema &SemaRef; |
| 3238 | /// \brief A location for diagnostics (when there is no some better location). |
| 3239 | SourceLocation DefaultLoc; |
| 3240 | /// \brief A location for diagnostics (when increment is not compatible). |
| 3241 | SourceLocation ConditionLoc; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3242 | /// \brief A source location for referring to loop init later. |
| 3243 | SourceRange InitSrcRange; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3244 | /// \brief A source location for referring to condition later. |
| 3245 | SourceRange ConditionSrcRange; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3246 | /// \brief A source location for referring to increment later. |
| 3247 | SourceRange IncrementSrcRange; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3248 | /// \brief Loop variable. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3249 | ValueDecl *LCDecl = nullptr; |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3250 | /// \brief Reference to loop variable. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3251 | Expr *LCRef = nullptr; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3252 | /// \brief Lower bound (initializer for the var). |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3253 | Expr *LB = nullptr; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3254 | /// \brief Upper bound. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3255 | Expr *UB = nullptr; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3256 | /// \brief Loop step (increment). |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3257 | Expr *Step = nullptr; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3258 | /// \brief This flag is true when condition is one of: |
| 3259 | /// Var < UB |
| 3260 | /// Var <= UB |
| 3261 | /// UB > Var |
| 3262 | /// UB >= Var |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3263 | bool TestIsLessOp = false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3264 | /// \brief This flag is true when condition is strict ( < or > ). |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3265 | bool TestIsStrictOp = false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3266 | /// \brief This flag is true when step is subtracted on each iteration. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3267 | bool SubtractStep = false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3268 | |
| 3269 | public: |
| 3270 | OpenMPIterationSpaceChecker(Sema &SemaRef, SourceLocation DefaultLoc) |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3271 | : SemaRef(SemaRef), DefaultLoc(DefaultLoc), ConditionLoc(DefaultLoc) {} |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3272 | /// \brief Check init-expr for canonical loop form and save loop counter |
| 3273 | /// variable - #Var and its initialization value - #LB. |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3274 | bool CheckInit(Stmt *S, bool EmitDiags = true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3275 | /// \brief Check test-expr for canonical form, save upper-bound (#UB), flags |
| 3276 | /// for less/greater and for strict/non-strict comparison. |
| 3277 | bool CheckCond(Expr *S); |
| 3278 | /// \brief Check incr-expr for canonical loop form and return true if it |
| 3279 | /// does not conform, otherwise save loop step (#Step). |
| 3280 | bool CheckInc(Expr *S); |
| 3281 | /// \brief Return the loop counter variable. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3282 | ValueDecl *GetLoopDecl() const { return LCDecl; } |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3283 | /// \brief Return the reference expression to loop counter variable. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3284 | Expr *GetLoopDeclRefExpr() const { return LCRef; } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3285 | /// \brief Source range of the loop init. |
| 3286 | SourceRange GetInitSrcRange() const { return InitSrcRange; } |
| 3287 | /// \brief Source range of the loop condition. |
| 3288 | SourceRange GetConditionSrcRange() const { return ConditionSrcRange; } |
| 3289 | /// \brief Source range of the loop increment. |
| 3290 | SourceRange GetIncrementSrcRange() const { return IncrementSrcRange; } |
| 3291 | /// \brief True if the step should be subtracted. |
| 3292 | bool ShouldSubtractStep() const { return SubtractStep; } |
| 3293 | /// \brief Build the expression to calculate the number of iterations. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3294 | Expr * |
| 3295 | BuildNumIterations(Scope *S, const bool LimitedType, |
| 3296 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) const; |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3297 | /// \brief Build the precondition expression for the loops. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3298 | Expr *BuildPreCond(Scope *S, Expr *Cond, |
| 3299 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) const; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3300 | /// \brief Build reference expression to the counter be used for codegen. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3301 | DeclRefExpr * |
| 3302 | BuildCounterVar(llvm::MapVector<Expr *, DeclRefExpr *> &Captures) const; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3303 | /// \brief Build reference expression to the private counter be used for |
| 3304 | /// codegen. |
| 3305 | Expr *BuildPrivateCounterVar() const; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3306 | /// \brief Build initization of the counter be used for codegen. |
| 3307 | Expr *BuildCounterInit() const; |
| 3308 | /// \brief Build step of the counter be used for codegen. |
| 3309 | Expr *BuildCounterStep() const; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3310 | /// \brief Return true if any expression is dependent. |
| 3311 | bool Dependent() const; |
| 3312 | |
| 3313 | private: |
| 3314 | /// \brief Check the right-hand side of an assignment in the increment |
| 3315 | /// expression. |
| 3316 | bool CheckIncRHS(Expr *RHS); |
| 3317 | /// \brief Helper to set loop counter variable and its initializer. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3318 | bool SetLCDeclAndLB(ValueDecl *NewLCDecl, Expr *NewDeclRefExpr, Expr *NewLB); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3319 | /// \brief Helper to set upper bound. |
Craig Topper | e335f25 | 2015-10-04 04:53:55 +0000 | [diff] [blame] | 3320 | bool SetUB(Expr *NewUB, bool LessOp, bool StrictOp, SourceRange SR, |
Craig Topper | 9cd5e4f | 2015-09-21 01:23:32 +0000 | [diff] [blame] | 3321 | SourceLocation SL); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3322 | /// \brief Helper to set loop increment. |
| 3323 | bool SetStep(Expr *NewStep, bool Subtract); |
| 3324 | }; |
| 3325 | |
| 3326 | bool OpenMPIterationSpaceChecker::Dependent() const { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3327 | if (!LCDecl) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3328 | assert(!LB && !UB && !Step); |
| 3329 | return false; |
| 3330 | } |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3331 | return LCDecl->getType()->isDependentType() || |
| 3332 | (LB && LB->isValueDependent()) || (UB && UB->isValueDependent()) || |
| 3333 | (Step && Step->isValueDependent()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3334 | } |
| 3335 | |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3336 | static Expr *getExprAsWritten(Expr *E) { |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3337 | if (auto *ExprTemp = dyn_cast<ExprWithCleanups>(E)) |
| 3338 | E = ExprTemp->getSubExpr(); |
| 3339 | |
| 3340 | if (auto *MTE = dyn_cast<MaterializeTemporaryExpr>(E)) |
| 3341 | E = MTE->GetTemporaryExpr(); |
| 3342 | |
| 3343 | while (auto *Binder = dyn_cast<CXXBindTemporaryExpr>(E)) |
| 3344 | E = Binder->getSubExpr(); |
| 3345 | |
| 3346 | if (auto *ICE = dyn_cast<ImplicitCastExpr>(E)) |
| 3347 | E = ICE->getSubExprAsWritten(); |
| 3348 | return E->IgnoreParens(); |
| 3349 | } |
| 3350 | |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3351 | bool OpenMPIterationSpaceChecker::SetLCDeclAndLB(ValueDecl *NewLCDecl, |
| 3352 | Expr *NewLCRefExpr, |
| 3353 | Expr *NewLB) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3354 | // State consistency checking to ensure correct usage. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3355 | assert(LCDecl == nullptr && LB == nullptr && LCRef == nullptr && |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3356 | UB == nullptr && Step == nullptr && !TestIsLessOp && !TestIsStrictOp); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3357 | if (!NewLCDecl || !NewLB) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3358 | return true; |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3359 | LCDecl = getCanonicalDecl(NewLCDecl); |
| 3360 | LCRef = NewLCRefExpr; |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3361 | if (auto *CE = dyn_cast_or_null<CXXConstructExpr>(NewLB)) |
| 3362 | if (const CXXConstructorDecl *Ctor = CE->getConstructor()) |
Alexey Bataev | 0d08a7f | 2015-07-16 04:19:43 +0000 | [diff] [blame] | 3363 | if ((Ctor->isCopyOrMoveConstructor() || |
| 3364 | Ctor->isConvertingConstructor(/*AllowExplicit=*/false)) && |
| 3365 | CE->getNumArgs() > 0 && CE->getArg(0) != nullptr) |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3366 | NewLB = CE->getArg(0)->IgnoreParenImpCasts(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3367 | LB = NewLB; |
| 3368 | return false; |
| 3369 | } |
| 3370 | |
| 3371 | bool OpenMPIterationSpaceChecker::SetUB(Expr *NewUB, bool LessOp, bool StrictOp, |
Craig Topper | e335f25 | 2015-10-04 04:53:55 +0000 | [diff] [blame] | 3372 | SourceRange SR, SourceLocation SL) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3373 | // State consistency checking to ensure correct usage. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3374 | assert(LCDecl != nullptr && LB != nullptr && UB == nullptr && |
| 3375 | Step == nullptr && !TestIsLessOp && !TestIsStrictOp); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3376 | if (!NewUB) |
| 3377 | return true; |
| 3378 | UB = NewUB; |
| 3379 | TestIsLessOp = LessOp; |
| 3380 | TestIsStrictOp = StrictOp; |
| 3381 | ConditionSrcRange = SR; |
| 3382 | ConditionLoc = SL; |
| 3383 | return false; |
| 3384 | } |
| 3385 | |
| 3386 | bool OpenMPIterationSpaceChecker::SetStep(Expr *NewStep, bool Subtract) { |
| 3387 | // State consistency checking to ensure correct usage. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3388 | assert(LCDecl != nullptr && LB != nullptr && Step == nullptr); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3389 | if (!NewStep) |
| 3390 | return true; |
| 3391 | if (!NewStep->isValueDependent()) { |
| 3392 | // Check that the step is integer expression. |
| 3393 | SourceLocation StepLoc = NewStep->getLocStart(); |
| 3394 | ExprResult Val = |
| 3395 | SemaRef.PerformOpenMPImplicitIntegerConversion(StepLoc, NewStep); |
| 3396 | if (Val.isInvalid()) |
| 3397 | return true; |
| 3398 | NewStep = Val.get(); |
| 3399 | |
| 3400 | // OpenMP [2.6, Canonical Loop Form, Restrictions] |
| 3401 | // If test-expr is of form var relational-op b and relational-op is < or |
| 3402 | // <= then incr-expr must cause var to increase on each iteration of the |
| 3403 | // loop. If test-expr is of form var relational-op b and relational-op is |
| 3404 | // > or >= then incr-expr must cause var to decrease on each iteration of |
| 3405 | // the loop. |
| 3406 | // If test-expr is of form b relational-op var and relational-op is < or |
| 3407 | // <= then incr-expr must cause var to decrease on each iteration of the |
| 3408 | // loop. If test-expr is of form b relational-op var and relational-op is |
| 3409 | // > or >= then incr-expr must cause var to increase on each iteration of |
| 3410 | // the loop. |
| 3411 | llvm::APSInt Result; |
| 3412 | bool IsConstant = NewStep->isIntegerConstantExpr(Result, SemaRef.Context); |
| 3413 | bool IsUnsigned = !NewStep->getType()->hasSignedIntegerRepresentation(); |
| 3414 | bool IsConstNeg = |
| 3415 | IsConstant && Result.isSigned() && (Subtract != Result.isNegative()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3416 | bool IsConstPos = |
| 3417 | IsConstant && Result.isSigned() && (Subtract == Result.isNegative()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3418 | bool IsConstZero = IsConstant && !Result.getBoolValue(); |
| 3419 | if (UB && (IsConstZero || |
| 3420 | (TestIsLessOp ? (IsConstNeg || (IsUnsigned && Subtract)) |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3421 | : (IsConstPos || (IsUnsigned && !Subtract))))) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3422 | SemaRef.Diag(NewStep->getExprLoc(), |
| 3423 | diag::err_omp_loop_incr_not_compatible) |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3424 | << LCDecl << TestIsLessOp << NewStep->getSourceRange(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3425 | SemaRef.Diag(ConditionLoc, |
| 3426 | diag::note_omp_loop_cond_requres_compatible_incr) |
| 3427 | << TestIsLessOp << ConditionSrcRange; |
| 3428 | return true; |
| 3429 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3430 | if (TestIsLessOp == Subtract) { |
| 3431 | NewStep = SemaRef.CreateBuiltinUnaryOp(NewStep->getExprLoc(), UO_Minus, |
| 3432 | NewStep).get(); |
| 3433 | Subtract = !Subtract; |
| 3434 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3435 | } |
| 3436 | |
| 3437 | Step = NewStep; |
| 3438 | SubtractStep = Subtract; |
| 3439 | return false; |
| 3440 | } |
| 3441 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3442 | bool OpenMPIterationSpaceChecker::CheckInit(Stmt *S, bool EmitDiags) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3443 | // Check init-expr for canonical loop form and save loop counter |
| 3444 | // variable - #Var and its initialization value - #LB. |
| 3445 | // OpenMP [2.6] Canonical loop form. init-expr may be one of the following: |
| 3446 | // var = lb |
| 3447 | // integer-type var = lb |
| 3448 | // random-access-iterator-type var = lb |
| 3449 | // pointer-type var = lb |
| 3450 | // |
| 3451 | if (!S) { |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3452 | if (EmitDiags) { |
| 3453 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_init); |
| 3454 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3455 | return true; |
| 3456 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3457 | InitSrcRange = S->getSourceRange(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3458 | if (Expr *E = dyn_cast<Expr>(S)) |
| 3459 | S = E->IgnoreParens(); |
| 3460 | if (auto BO = dyn_cast<BinaryOperator>(S)) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3461 | if (BO->getOpcode() == BO_Assign) { |
| 3462 | auto *LHS = BO->getLHS()->IgnoreParens(); |
| 3463 | if (auto *DRE = dyn_cast<DeclRefExpr>(LHS)) { |
| 3464 | if (auto *CED = dyn_cast<OMPCapturedExprDecl>(DRE->getDecl())) |
| 3465 | if (auto *ME = dyn_cast<MemberExpr>(getExprAsWritten(CED->getInit()))) |
| 3466 | return SetLCDeclAndLB(ME->getMemberDecl(), ME, BO->getRHS()); |
| 3467 | return SetLCDeclAndLB(DRE->getDecl(), DRE, BO->getRHS()); |
| 3468 | } |
| 3469 | if (auto *ME = dyn_cast<MemberExpr>(LHS)) { |
| 3470 | if (ME->isArrow() && |
| 3471 | isa<CXXThisExpr>(ME->getBase()->IgnoreParenImpCasts())) |
| 3472 | return SetLCDeclAndLB(ME->getMemberDecl(), ME, BO->getRHS()); |
| 3473 | } |
| 3474 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3475 | } else if (auto DS = dyn_cast<DeclStmt>(S)) { |
| 3476 | if (DS->isSingleDecl()) { |
| 3477 | if (auto Var = dyn_cast_or_null<VarDecl>(DS->getSingleDecl())) { |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3478 | if (Var->hasInit() && !Var->getType()->isReferenceType()) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3479 | // Accept non-canonical init form here but emit ext. warning. |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3480 | if (Var->getInitStyle() != VarDecl::CInit && EmitDiags) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3481 | SemaRef.Diag(S->getLocStart(), |
| 3482 | diag::ext_omp_loop_not_canonical_init) |
| 3483 | << S->getSourceRange(); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3484 | return SetLCDeclAndLB(Var, nullptr, Var->getInit()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3485 | } |
| 3486 | } |
| 3487 | } |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3488 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
| 3489 | if (CE->getOperator() == OO_Equal) { |
| 3490 | auto *LHS = CE->getArg(0); |
| 3491 | if (auto DRE = dyn_cast<DeclRefExpr>(LHS)) { |
| 3492 | if (auto *CED = dyn_cast<OMPCapturedExprDecl>(DRE->getDecl())) |
| 3493 | if (auto *ME = dyn_cast<MemberExpr>(getExprAsWritten(CED->getInit()))) |
| 3494 | return SetLCDeclAndLB(ME->getMemberDecl(), ME, BO->getRHS()); |
| 3495 | return SetLCDeclAndLB(DRE->getDecl(), DRE, CE->getArg(1)); |
| 3496 | } |
| 3497 | if (auto *ME = dyn_cast<MemberExpr>(LHS)) { |
| 3498 | if (ME->isArrow() && |
| 3499 | isa<CXXThisExpr>(ME->getBase()->IgnoreParenImpCasts())) |
| 3500 | return SetLCDeclAndLB(ME->getMemberDecl(), ME, BO->getRHS()); |
| 3501 | } |
| 3502 | } |
| 3503 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3504 | |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3505 | if (Dependent() || SemaRef.CurContext->isDependentContext()) |
| 3506 | return false; |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3507 | if (EmitDiags) { |
| 3508 | SemaRef.Diag(S->getLocStart(), diag::err_omp_loop_not_canonical_init) |
| 3509 | << S->getSourceRange(); |
| 3510 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3511 | return true; |
| 3512 | } |
| 3513 | |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 3514 | /// \brief Ignore parenthesizes, implicit casts, copy constructor and return the |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3515 | /// variable (which may be the loop variable) if possible. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3516 | static const ValueDecl *GetInitLCDecl(Expr *E) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3517 | if (!E) |
Craig Topper | 4b56692 | 2014-06-09 02:04:02 +0000 | [diff] [blame] | 3518 | return nullptr; |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3519 | E = getExprAsWritten(E); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3520 | if (auto *CE = dyn_cast_or_null<CXXConstructExpr>(E)) |
| 3521 | if (const CXXConstructorDecl *Ctor = CE->getConstructor()) |
Alexey Bataev | 0d08a7f | 2015-07-16 04:19:43 +0000 | [diff] [blame] | 3522 | if ((Ctor->isCopyOrMoveConstructor() || |
| 3523 | Ctor->isConvertingConstructor(/*AllowExplicit=*/false)) && |
| 3524 | CE->getNumArgs() > 0 && CE->getArg(0) != nullptr) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3525 | E = CE->getArg(0)->IgnoreParenImpCasts(); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3526 | if (auto *DRE = dyn_cast_or_null<DeclRefExpr>(E)) { |
| 3527 | if (auto *VD = dyn_cast<VarDecl>(DRE->getDecl())) { |
| 3528 | if (auto *CED = dyn_cast<OMPCapturedExprDecl>(VD)) |
| 3529 | if (auto *ME = dyn_cast<MemberExpr>(getExprAsWritten(CED->getInit()))) |
| 3530 | return getCanonicalDecl(ME->getMemberDecl()); |
| 3531 | return getCanonicalDecl(VD); |
| 3532 | } |
| 3533 | } |
| 3534 | if (auto *ME = dyn_cast_or_null<MemberExpr>(E)) |
| 3535 | if (ME->isArrow() && isa<CXXThisExpr>(ME->getBase()->IgnoreParenImpCasts())) |
| 3536 | return getCanonicalDecl(ME->getMemberDecl()); |
| 3537 | return nullptr; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3538 | } |
| 3539 | |
| 3540 | bool OpenMPIterationSpaceChecker::CheckCond(Expr *S) { |
| 3541 | // Check test-expr for canonical form, save upper-bound UB, flags for |
| 3542 | // less/greater and for strict/non-strict comparison. |
| 3543 | // OpenMP [2.6] Canonical loop form. Test-expr may be one of the following: |
| 3544 | // var relational-op b |
| 3545 | // b relational-op var |
| 3546 | // |
| 3547 | if (!S) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3548 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_cond) << LCDecl; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3549 | return true; |
| 3550 | } |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3551 | S = getExprAsWritten(S); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3552 | SourceLocation CondLoc = S->getLocStart(); |
| 3553 | if (auto BO = dyn_cast<BinaryOperator>(S)) { |
| 3554 | if (BO->isRelationalOp()) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3555 | if (GetInitLCDecl(BO->getLHS()) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3556 | return SetUB(BO->getRHS(), |
| 3557 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_LE), |
| 3558 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_GT), |
| 3559 | BO->getSourceRange(), BO->getOperatorLoc()); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3560 | if (GetInitLCDecl(BO->getRHS()) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3561 | return SetUB(BO->getLHS(), |
| 3562 | (BO->getOpcode() == BO_GT || BO->getOpcode() == BO_GE), |
| 3563 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_GT), |
| 3564 | BO->getSourceRange(), BO->getOperatorLoc()); |
| 3565 | } |
| 3566 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
| 3567 | if (CE->getNumArgs() == 2) { |
| 3568 | auto Op = CE->getOperator(); |
| 3569 | switch (Op) { |
| 3570 | case OO_Greater: |
| 3571 | case OO_GreaterEqual: |
| 3572 | case OO_Less: |
| 3573 | case OO_LessEqual: |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3574 | if (GetInitLCDecl(CE->getArg(0)) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3575 | return SetUB(CE->getArg(1), Op == OO_Less || Op == OO_LessEqual, |
| 3576 | Op == OO_Less || Op == OO_Greater, CE->getSourceRange(), |
| 3577 | CE->getOperatorLoc()); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3578 | if (GetInitLCDecl(CE->getArg(1)) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3579 | return SetUB(CE->getArg(0), Op == OO_Greater || Op == OO_GreaterEqual, |
| 3580 | Op == OO_Less || Op == OO_Greater, CE->getSourceRange(), |
| 3581 | CE->getOperatorLoc()); |
| 3582 | break; |
| 3583 | default: |
| 3584 | break; |
| 3585 | } |
| 3586 | } |
| 3587 | } |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3588 | if (Dependent() || SemaRef.CurContext->isDependentContext()) |
| 3589 | return false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3590 | SemaRef.Diag(CondLoc, diag::err_omp_loop_not_canonical_cond) |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3591 | << S->getSourceRange() << LCDecl; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3592 | return true; |
| 3593 | } |
| 3594 | |
| 3595 | bool OpenMPIterationSpaceChecker::CheckIncRHS(Expr *RHS) { |
| 3596 | // RHS of canonical loop form increment can be: |
| 3597 | // var + incr |
| 3598 | // incr + var |
| 3599 | // var - incr |
| 3600 | // |
| 3601 | RHS = RHS->IgnoreParenImpCasts(); |
| 3602 | if (auto BO = dyn_cast<BinaryOperator>(RHS)) { |
| 3603 | if (BO->isAdditiveOp()) { |
| 3604 | bool IsAdd = BO->getOpcode() == BO_Add; |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3605 | if (GetInitLCDecl(BO->getLHS()) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3606 | return SetStep(BO->getRHS(), !IsAdd); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3607 | if (IsAdd && GetInitLCDecl(BO->getRHS()) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3608 | return SetStep(BO->getLHS(), false); |
| 3609 | } |
| 3610 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(RHS)) { |
| 3611 | bool IsAdd = CE->getOperator() == OO_Plus; |
| 3612 | if ((IsAdd || CE->getOperator() == OO_Minus) && CE->getNumArgs() == 2) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3613 | if (GetInitLCDecl(CE->getArg(0)) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3614 | return SetStep(CE->getArg(1), !IsAdd); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3615 | if (IsAdd && GetInitLCDecl(CE->getArg(1)) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3616 | return SetStep(CE->getArg(0), false); |
| 3617 | } |
| 3618 | } |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3619 | if (Dependent() || SemaRef.CurContext->isDependentContext()) |
| 3620 | return false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3621 | SemaRef.Diag(RHS->getLocStart(), diag::err_omp_loop_not_canonical_incr) |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3622 | << RHS->getSourceRange() << LCDecl; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3623 | return true; |
| 3624 | } |
| 3625 | |
| 3626 | bool OpenMPIterationSpaceChecker::CheckInc(Expr *S) { |
| 3627 | // Check incr-expr for canonical loop form and return true if it |
| 3628 | // does not conform. |
| 3629 | // OpenMP [2.6] Canonical loop form. Test-expr may be one of the following: |
| 3630 | // ++var |
| 3631 | // var++ |
| 3632 | // --var |
| 3633 | // var-- |
| 3634 | // var += incr |
| 3635 | // var -= incr |
| 3636 | // var = var + incr |
| 3637 | // var = incr + var |
| 3638 | // var = var - incr |
| 3639 | // |
| 3640 | if (!S) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3641 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_incr) << LCDecl; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3642 | return true; |
| 3643 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3644 | IncrementSrcRange = S->getSourceRange(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3645 | S = S->IgnoreParens(); |
| 3646 | if (auto UO = dyn_cast<UnaryOperator>(S)) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3647 | if (UO->isIncrementDecrementOp() && |
| 3648 | GetInitLCDecl(UO->getSubExpr()) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3649 | return SetStep( |
| 3650 | SemaRef.ActOnIntegerConstant(UO->getLocStart(), |
| 3651 | (UO->isDecrementOp() ? -1 : 1)).get(), |
| 3652 | false); |
| 3653 | } else if (auto BO = dyn_cast<BinaryOperator>(S)) { |
| 3654 | switch (BO->getOpcode()) { |
| 3655 | case BO_AddAssign: |
| 3656 | case BO_SubAssign: |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3657 | if (GetInitLCDecl(BO->getLHS()) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3658 | return SetStep(BO->getRHS(), BO->getOpcode() == BO_SubAssign); |
| 3659 | break; |
| 3660 | case BO_Assign: |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3661 | if (GetInitLCDecl(BO->getLHS()) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3662 | return CheckIncRHS(BO->getRHS()); |
| 3663 | break; |
| 3664 | default: |
| 3665 | break; |
| 3666 | } |
| 3667 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
| 3668 | switch (CE->getOperator()) { |
| 3669 | case OO_PlusPlus: |
| 3670 | case OO_MinusMinus: |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3671 | if (GetInitLCDecl(CE->getArg(0)) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3672 | return SetStep( |
| 3673 | SemaRef.ActOnIntegerConstant( |
| 3674 | CE->getLocStart(), |
| 3675 | ((CE->getOperator() == OO_MinusMinus) ? -1 : 1)).get(), |
| 3676 | false); |
| 3677 | break; |
| 3678 | case OO_PlusEqual: |
| 3679 | case OO_MinusEqual: |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3680 | if (GetInitLCDecl(CE->getArg(0)) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3681 | return SetStep(CE->getArg(1), CE->getOperator() == OO_MinusEqual); |
| 3682 | break; |
| 3683 | case OO_Equal: |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3684 | if (GetInitLCDecl(CE->getArg(0)) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3685 | return CheckIncRHS(CE->getArg(1)); |
| 3686 | break; |
| 3687 | default: |
| 3688 | break; |
| 3689 | } |
| 3690 | } |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3691 | if (Dependent() || SemaRef.CurContext->isDependentContext()) |
| 3692 | return false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3693 | SemaRef.Diag(S->getLocStart(), diag::err_omp_loop_not_canonical_incr) |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3694 | << S->getSourceRange() << LCDecl; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3695 | return true; |
| 3696 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3697 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3698 | static ExprResult |
| 3699 | tryBuildCapture(Sema &SemaRef, Expr *Capture, |
| 3700 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) { |
| 3701 | if (Capture->isEvaluatable(SemaRef.Context, Expr::SE_AllowSideEffects)) |
| 3702 | return SemaRef.PerformImplicitConversion( |
| 3703 | Capture->IgnoreImpCasts(), Capture->getType(), Sema::AA_Converting, |
| 3704 | /*AllowExplicit=*/true); |
| 3705 | auto I = Captures.find(Capture); |
| 3706 | if (I != Captures.end()) |
| 3707 | return buildCapture(SemaRef, Capture, I->second); |
| 3708 | DeclRefExpr *Ref = nullptr; |
| 3709 | ExprResult Res = buildCapture(SemaRef, Capture, Ref); |
| 3710 | Captures[Capture] = Ref; |
| 3711 | return Res; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3712 | } |
| 3713 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3714 | /// \brief Build the expression to calculate the number of iterations. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3715 | Expr *OpenMPIterationSpaceChecker::BuildNumIterations( |
| 3716 | Scope *S, const bool LimitedType, |
| 3717 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) const { |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3718 | ExprResult Diff; |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3719 | auto VarType = LCDecl->getType().getNonReferenceType(); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3720 | if (VarType->isIntegerType() || VarType->isPointerType() || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3721 | SemaRef.getLangOpts().CPlusPlus) { |
| 3722 | // Upper - Lower |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3723 | auto *UBExpr = TestIsLessOp ? UB : LB; |
| 3724 | auto *LBExpr = TestIsLessOp ? LB : UB; |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3725 | Expr *Upper = tryBuildCapture(SemaRef, UBExpr, Captures).get(); |
| 3726 | Expr *Lower = tryBuildCapture(SemaRef, LBExpr, Captures).get(); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3727 | if (!Upper || !Lower) |
| 3728 | return nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3729 | |
| 3730 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Sub, Upper, Lower); |
| 3731 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3732 | if (!Diff.isUsable() && VarType->getAsCXXRecordDecl()) { |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3733 | // BuildBinOp already emitted error, this one is to point user to upper |
| 3734 | // and lower bound, and to tell what is passed to 'operator-'. |
| 3735 | SemaRef.Diag(Upper->getLocStart(), diag::err_omp_loop_diff_cxx) |
| 3736 | << Upper->getSourceRange() << Lower->getSourceRange(); |
| 3737 | return nullptr; |
| 3738 | } |
| 3739 | } |
| 3740 | |
| 3741 | if (!Diff.isUsable()) |
| 3742 | return nullptr; |
| 3743 | |
| 3744 | // Upper - Lower [- 1] |
| 3745 | if (TestIsStrictOp) |
| 3746 | Diff = SemaRef.BuildBinOp( |
| 3747 | S, DefaultLoc, BO_Sub, Diff.get(), |
| 3748 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 3749 | if (!Diff.isUsable()) |
| 3750 | return nullptr; |
| 3751 | |
| 3752 | // Upper - Lower [- 1] + Step |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3753 | auto NewStep = tryBuildCapture(SemaRef, Step, Captures); |
| 3754 | if (!NewStep.isUsable()) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3755 | return nullptr; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3756 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Add, Diff.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3757 | if (!Diff.isUsable()) |
| 3758 | return nullptr; |
| 3759 | |
| 3760 | // Parentheses (for dumping/debugging purposes only). |
| 3761 | Diff = SemaRef.ActOnParenExpr(DefaultLoc, DefaultLoc, Diff.get()); |
| 3762 | if (!Diff.isUsable()) |
| 3763 | return nullptr; |
| 3764 | |
| 3765 | // (Upper - Lower [- 1] + Step) / Step |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3766 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Div, Diff.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3767 | if (!Diff.isUsable()) |
| 3768 | return nullptr; |
| 3769 | |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3770 | // OpenMP runtime requires 32-bit or 64-bit loop variables. |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3771 | QualType Type = Diff.get()->getType(); |
| 3772 | auto &C = SemaRef.Context; |
| 3773 | bool UseVarType = VarType->hasIntegerRepresentation() && |
| 3774 | C.getTypeSize(Type) > C.getTypeSize(VarType); |
| 3775 | if (!Type->isIntegerType() || UseVarType) { |
| 3776 | unsigned NewSize = |
| 3777 | UseVarType ? C.getTypeSize(VarType) : C.getTypeSize(Type); |
| 3778 | bool IsSigned = UseVarType ? VarType->hasSignedIntegerRepresentation() |
| 3779 | : Type->hasSignedIntegerRepresentation(); |
| 3780 | Type = C.getIntTypeForBitwidth(NewSize, IsSigned); |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 3781 | if (!SemaRef.Context.hasSameType(Diff.get()->getType(), Type)) { |
| 3782 | Diff = SemaRef.PerformImplicitConversion( |
| 3783 | Diff.get(), Type, Sema::AA_Converting, /*AllowExplicit=*/true); |
| 3784 | if (!Diff.isUsable()) |
| 3785 | return nullptr; |
| 3786 | } |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3787 | } |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3788 | if (LimitedType) { |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3789 | unsigned NewSize = (C.getTypeSize(Type) > 32) ? 64 : 32; |
| 3790 | if (NewSize != C.getTypeSize(Type)) { |
| 3791 | if (NewSize < C.getTypeSize(Type)) { |
| 3792 | assert(NewSize == 64 && "incorrect loop var size"); |
| 3793 | SemaRef.Diag(DefaultLoc, diag::warn_omp_loop_64_bit_var) |
| 3794 | << InitSrcRange << ConditionSrcRange; |
| 3795 | } |
| 3796 | QualType NewType = C.getIntTypeForBitwidth( |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3797 | NewSize, Type->hasSignedIntegerRepresentation() || |
| 3798 | C.getTypeSize(Type) < NewSize); |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 3799 | if (!SemaRef.Context.hasSameType(Diff.get()->getType(), NewType)) { |
| 3800 | Diff = SemaRef.PerformImplicitConversion(Diff.get(), NewType, |
| 3801 | Sema::AA_Converting, true); |
| 3802 | if (!Diff.isUsable()) |
| 3803 | return nullptr; |
| 3804 | } |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3805 | } |
| 3806 | } |
| 3807 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3808 | return Diff.get(); |
| 3809 | } |
| 3810 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3811 | Expr *OpenMPIterationSpaceChecker::BuildPreCond( |
| 3812 | Scope *S, Expr *Cond, |
| 3813 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) const { |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3814 | // Try to build LB <op> UB, where <op> is <, >, <=, or >=. |
| 3815 | bool Suppress = SemaRef.getDiagnostics().getSuppressAllDiagnostics(); |
| 3816 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(/*Val=*/true); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3817 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3818 | auto NewLB = tryBuildCapture(SemaRef, LB, Captures); |
| 3819 | auto NewUB = tryBuildCapture(SemaRef, UB, Captures); |
| 3820 | if (!NewLB.isUsable() || !NewUB.isUsable()) |
| 3821 | return nullptr; |
| 3822 | |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3823 | auto CondExpr = SemaRef.BuildBinOp( |
| 3824 | S, DefaultLoc, TestIsLessOp ? (TestIsStrictOp ? BO_LT : BO_LE) |
| 3825 | : (TestIsStrictOp ? BO_GT : BO_GE), |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3826 | NewLB.get(), NewUB.get()); |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3827 | if (CondExpr.isUsable()) { |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3828 | if (!SemaRef.Context.hasSameUnqualifiedType(CondExpr.get()->getType(), |
| 3829 | SemaRef.Context.BoolTy)) |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 3830 | CondExpr = SemaRef.PerformImplicitConversion( |
| 3831 | CondExpr.get(), SemaRef.Context.BoolTy, /*Action=*/Sema::AA_Casting, |
| 3832 | /*AllowExplicit=*/true); |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3833 | } |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3834 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(Suppress); |
| 3835 | // Otherwise use original loop conditon and evaluate it in runtime. |
| 3836 | return CondExpr.isUsable() ? CondExpr.get() : Cond; |
| 3837 | } |
| 3838 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3839 | /// \brief Build reference expression to the counter be used for codegen. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3840 | DeclRefExpr *OpenMPIterationSpaceChecker::BuildCounterVar( |
| 3841 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) const { |
| 3842 | auto *VD = dyn_cast<VarDecl>(LCDecl); |
| 3843 | if (!VD) { |
| 3844 | VD = SemaRef.IsOpenMPCapturedDecl(LCDecl); |
| 3845 | auto *Ref = buildDeclRefExpr( |
| 3846 | SemaRef, VD, VD->getType().getNonReferenceType(), DefaultLoc); |
| 3847 | Captures.insert(std::make_pair(LCRef, Ref)); |
| 3848 | return Ref; |
| 3849 | } |
| 3850 | return buildDeclRefExpr(SemaRef, VD, VD->getType().getNonReferenceType(), |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3851 | DefaultLoc); |
| 3852 | } |
| 3853 | |
| 3854 | Expr *OpenMPIterationSpaceChecker::BuildPrivateCounterVar() const { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3855 | if (LCDecl && !LCDecl->isInvalidDecl()) { |
| 3856 | auto Type = LCDecl->getType().getNonReferenceType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 3857 | auto *PrivateVar = |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3858 | buildVarDecl(SemaRef, DefaultLoc, Type, LCDecl->getName(), |
| 3859 | LCDecl->hasAttrs() ? &LCDecl->getAttrs() : nullptr); |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3860 | if (PrivateVar->isInvalidDecl()) |
| 3861 | return nullptr; |
| 3862 | return buildDeclRefExpr(SemaRef, PrivateVar, Type, DefaultLoc); |
| 3863 | } |
| 3864 | return nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3865 | } |
| 3866 | |
| 3867 | /// \brief Build initization of the counter be used for codegen. |
| 3868 | Expr *OpenMPIterationSpaceChecker::BuildCounterInit() const { return LB; } |
| 3869 | |
| 3870 | /// \brief Build step of the counter be used for codegen. |
| 3871 | Expr *OpenMPIterationSpaceChecker::BuildCounterStep() const { return Step; } |
| 3872 | |
| 3873 | /// \brief Iteration space of a single for loop. |
| 3874 | struct LoopIterationSpace { |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3875 | /// \brief Condition of the loop. |
| 3876 | Expr *PreCond; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3877 | /// \brief This expression calculates the number of iterations in the loop. |
| 3878 | /// It is always possible to calculate it before starting the loop. |
| 3879 | Expr *NumIterations; |
| 3880 | /// \brief The loop counter variable. |
| 3881 | Expr *CounterVar; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3882 | /// \brief Private loop counter variable. |
| 3883 | Expr *PrivateCounterVar; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3884 | /// \brief This is initializer for the initial value of #CounterVar. |
| 3885 | Expr *CounterInit; |
| 3886 | /// \brief This is step for the #CounterVar used to generate its update: |
| 3887 | /// #CounterVar = #CounterInit + #CounterStep * CurrentIteration. |
| 3888 | Expr *CounterStep; |
| 3889 | /// \brief Should step be subtracted? |
| 3890 | bool Subtract; |
| 3891 | /// \brief Source range of the loop init. |
| 3892 | SourceRange InitSrcRange; |
| 3893 | /// \brief Source range of the loop condition. |
| 3894 | SourceRange CondSrcRange; |
| 3895 | /// \brief Source range of the loop increment. |
| 3896 | SourceRange IncSrcRange; |
| 3897 | }; |
| 3898 | |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 3899 | } // namespace |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3900 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3901 | void Sema::ActOnOpenMPLoopInitialization(SourceLocation ForLoc, Stmt *Init) { |
| 3902 | assert(getLangOpts().OpenMP && "OpenMP is not active."); |
| 3903 | assert(Init && "Expected loop in canonical form."); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 3904 | unsigned AssociatedLoops = DSAStack->getAssociatedLoops(); |
| 3905 | if (AssociatedLoops > 0 && |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3906 | isOpenMPLoopDirective(DSAStack->getCurrentDirective())) { |
| 3907 | OpenMPIterationSpaceChecker ISC(*this, ForLoc); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3908 | if (!ISC.CheckInit(Init, /*EmitDiags=*/false)) { |
| 3909 | if (auto *D = ISC.GetLoopDecl()) { |
| 3910 | auto *VD = dyn_cast<VarDecl>(D); |
| 3911 | if (!VD) { |
| 3912 | if (auto *Private = IsOpenMPCapturedDecl(D)) |
| 3913 | VD = Private; |
| 3914 | else { |
| 3915 | auto *Ref = buildCapture(*this, D, ISC.GetLoopDeclRefExpr(), |
| 3916 | /*WithInit=*/false); |
| 3917 | VD = cast<VarDecl>(Ref->getDecl()); |
| 3918 | } |
| 3919 | } |
| 3920 | DSAStack->addLoopControlVariable(D, VD); |
| 3921 | } |
| 3922 | } |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 3923 | DSAStack->setAssociatedLoops(AssociatedLoops - 1); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3924 | } |
| 3925 | } |
| 3926 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3927 | /// \brief Called on a for stmt to check and extract its iteration space |
| 3928 | /// for further processing (such as collapsing). |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3929 | static bool CheckOpenMPIterationSpace( |
| 3930 | OpenMPDirectiveKind DKind, Stmt *S, Sema &SemaRef, DSAStackTy &DSA, |
| 3931 | unsigned CurrentNestedLoopCount, unsigned NestedLoopCount, |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3932 | Expr *CollapseLoopCountExpr, Expr *OrderedLoopCountExpr, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 3933 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3934 | LoopIterationSpace &ResultIterSpace, |
| 3935 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3936 | // OpenMP [2.6, Canonical Loop Form] |
| 3937 | // for (init-expr; test-expr; incr-expr) structured-block |
| 3938 | auto For = dyn_cast_or_null<ForStmt>(S); |
| 3939 | if (!For) { |
| 3940 | SemaRef.Diag(S->getLocStart(), diag::err_omp_not_for) |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3941 | << (CollapseLoopCountExpr != nullptr || OrderedLoopCountExpr != nullptr) |
| 3942 | << getOpenMPDirectiveName(DKind) << NestedLoopCount |
| 3943 | << (CurrentNestedLoopCount > 0) << CurrentNestedLoopCount; |
| 3944 | if (NestedLoopCount > 1) { |
| 3945 | if (CollapseLoopCountExpr && OrderedLoopCountExpr) |
| 3946 | SemaRef.Diag(DSA.getConstructLoc(), |
| 3947 | diag::note_omp_collapse_ordered_expr) |
| 3948 | << 2 << CollapseLoopCountExpr->getSourceRange() |
| 3949 | << OrderedLoopCountExpr->getSourceRange(); |
| 3950 | else if (CollapseLoopCountExpr) |
| 3951 | SemaRef.Diag(CollapseLoopCountExpr->getExprLoc(), |
| 3952 | diag::note_omp_collapse_ordered_expr) |
| 3953 | << 0 << CollapseLoopCountExpr->getSourceRange(); |
| 3954 | else |
| 3955 | SemaRef.Diag(OrderedLoopCountExpr->getExprLoc(), |
| 3956 | diag::note_omp_collapse_ordered_expr) |
| 3957 | << 1 << OrderedLoopCountExpr->getSourceRange(); |
| 3958 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3959 | return true; |
| 3960 | } |
| 3961 | assert(For->getBody()); |
| 3962 | |
| 3963 | OpenMPIterationSpaceChecker ISC(SemaRef, For->getForLoc()); |
| 3964 | |
| 3965 | // Check init. |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 3966 | auto Init = For->getInit(); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3967 | if (ISC.CheckInit(Init)) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3968 | return true; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3969 | |
| 3970 | bool HasErrors = false; |
| 3971 | |
| 3972 | // Check loop variable's type. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3973 | if (auto *LCDecl = ISC.GetLoopDecl()) { |
| 3974 | auto *LoopDeclRefExpr = ISC.GetLoopDeclRefExpr(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3975 | |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3976 | // OpenMP [2.6, Canonical Loop Form] |
| 3977 | // Var is one of the following: |
| 3978 | // A variable of signed or unsigned integer type. |
| 3979 | // For C++, a variable of a random access iterator type. |
| 3980 | // For C, a variable of a pointer type. |
| 3981 | auto VarType = LCDecl->getType().getNonReferenceType(); |
| 3982 | if (!VarType->isDependentType() && !VarType->isIntegerType() && |
| 3983 | !VarType->isPointerType() && |
| 3984 | !(SemaRef.getLangOpts().CPlusPlus && VarType->isOverloadableType())) { |
| 3985 | SemaRef.Diag(Init->getLocStart(), diag::err_omp_loop_variable_type) |
| 3986 | << SemaRef.getLangOpts().CPlusPlus; |
| 3987 | HasErrors = true; |
| 3988 | } |
| 3989 | |
| 3990 | // OpenMP, 2.14.1.1 Data-sharing Attribute Rules for Variables Referenced in |
| 3991 | // a Construct |
| 3992 | // The loop iteration variable(s) in the associated for-loop(s) of a for or |
| 3993 | // parallel for construct is (are) private. |
| 3994 | // The loop iteration variable in the associated for-loop of a simd |
| 3995 | // construct with just one associated for-loop is linear with a |
| 3996 | // constant-linear-step that is the increment of the associated for-loop. |
| 3997 | // Exclude loop var from the list of variables with implicitly defined data |
| 3998 | // sharing attributes. |
| 3999 | VarsWithImplicitDSA.erase(LCDecl); |
| 4000 | |
| 4001 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 4002 | // in a Construct, C/C++]. |
| 4003 | // The loop iteration variable in the associated for-loop of a simd |
| 4004 | // construct with just one associated for-loop may be listed in a linear |
| 4005 | // clause with a constant-linear-step that is the increment of the |
| 4006 | // associated for-loop. |
| 4007 | // The loop iteration variable(s) in the associated for-loop(s) of a for or |
| 4008 | // parallel for construct may be listed in a private or lastprivate clause. |
| 4009 | DSAStackTy::DSAVarData DVar = DSA.getTopDSA(LCDecl, false); |
| 4010 | // If LoopVarRefExpr is nullptr it means the corresponding loop variable is |
| 4011 | // declared in the loop and it is predetermined as a private. |
| 4012 | auto PredeterminedCKind = |
| 4013 | isOpenMPSimdDirective(DKind) |
| 4014 | ? ((NestedLoopCount == 1) ? OMPC_linear : OMPC_lastprivate) |
| 4015 | : OMPC_private; |
| 4016 | if (((isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown && |
| 4017 | DVar.CKind != PredeterminedCKind) || |
| 4018 | ((isOpenMPWorksharingDirective(DKind) || DKind == OMPD_taskloop || |
| 4019 | isOpenMPDistributeDirective(DKind)) && |
| 4020 | !isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown && |
| 4021 | DVar.CKind != OMPC_private && DVar.CKind != OMPC_lastprivate)) && |
| 4022 | (DVar.CKind != OMPC_private || DVar.RefExpr != nullptr)) { |
| 4023 | SemaRef.Diag(Init->getLocStart(), diag::err_omp_loop_var_dsa) |
| 4024 | << getOpenMPClauseName(DVar.CKind) << getOpenMPDirectiveName(DKind) |
| 4025 | << getOpenMPClauseName(PredeterminedCKind); |
| 4026 | if (DVar.RefExpr == nullptr) |
| 4027 | DVar.CKind = PredeterminedCKind; |
| 4028 | ReportOriginalDSA(SemaRef, &DSA, LCDecl, DVar, /*IsLoopIterVar=*/true); |
| 4029 | HasErrors = true; |
| 4030 | } else if (LoopDeclRefExpr != nullptr) { |
| 4031 | // Make the loop iteration variable private (for worksharing constructs), |
| 4032 | // linear (for simd directives with the only one associated loop) or |
| 4033 | // lastprivate (for simd directives with several collapsed or ordered |
| 4034 | // loops). |
| 4035 | if (DVar.CKind == OMPC_unknown) |
| 4036 | DVar = DSA.hasDSA(LCDecl, isOpenMPPrivate, MatchesAlways(), |
| 4037 | /*FromParent=*/false); |
| 4038 | DSA.addDSA(LCDecl, LoopDeclRefExpr, PredeterminedCKind); |
| 4039 | } |
| 4040 | |
| 4041 | assert(isOpenMPLoopDirective(DKind) && "DSA for non-loop vars"); |
| 4042 | |
| 4043 | // Check test-expr. |
| 4044 | HasErrors |= ISC.CheckCond(For->getCond()); |
| 4045 | |
| 4046 | // Check incr-expr. |
| 4047 | HasErrors |= ISC.CheckInc(For->getInc()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4048 | } |
| 4049 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4050 | if (ISC.Dependent() || SemaRef.CurContext->isDependentContext() || HasErrors) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4051 | return HasErrors; |
| 4052 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4053 | // Build the loop's iteration space representation. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4054 | ResultIterSpace.PreCond = |
| 4055 | ISC.BuildPreCond(DSA.getCurScope(), For->getCond(), Captures); |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 4056 | ResultIterSpace.NumIterations = ISC.BuildNumIterations( |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4057 | DSA.getCurScope(), |
| 4058 | (isOpenMPWorksharingDirective(DKind) || |
| 4059 | isOpenMPTaskLoopDirective(DKind) || isOpenMPDistributeDirective(DKind)), |
| 4060 | Captures); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4061 | ResultIterSpace.CounterVar = ISC.BuildCounterVar(Captures); |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 4062 | ResultIterSpace.PrivateCounterVar = ISC.BuildPrivateCounterVar(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4063 | ResultIterSpace.CounterInit = ISC.BuildCounterInit(); |
| 4064 | ResultIterSpace.CounterStep = ISC.BuildCounterStep(); |
| 4065 | ResultIterSpace.InitSrcRange = ISC.GetInitSrcRange(); |
| 4066 | ResultIterSpace.CondSrcRange = ISC.GetConditionSrcRange(); |
| 4067 | ResultIterSpace.IncSrcRange = ISC.GetIncrementSrcRange(); |
| 4068 | ResultIterSpace.Subtract = ISC.ShouldSubtractStep(); |
| 4069 | |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 4070 | HasErrors |= (ResultIterSpace.PreCond == nullptr || |
| 4071 | ResultIterSpace.NumIterations == nullptr || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4072 | ResultIterSpace.CounterVar == nullptr || |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 4073 | ResultIterSpace.PrivateCounterVar == nullptr || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4074 | ResultIterSpace.CounterInit == nullptr || |
| 4075 | ResultIterSpace.CounterStep == nullptr); |
| 4076 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4077 | return HasErrors; |
| 4078 | } |
| 4079 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4080 | /// \brief Build 'VarRef = Start. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4081 | static ExprResult |
| 4082 | BuildCounterInit(Sema &SemaRef, Scope *S, SourceLocation Loc, ExprResult VarRef, |
| 4083 | ExprResult Start, |
| 4084 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) { |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4085 | // Build 'VarRef = Start. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4086 | auto NewStart = tryBuildCapture(SemaRef, Start.get(), Captures); |
| 4087 | if (!NewStart.isUsable()) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4088 | return ExprError(); |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 4089 | if (!SemaRef.Context.hasSameType(NewStart.get()->getType(), |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 4090 | VarRef.get()->getType())) { |
| 4091 | NewStart = SemaRef.PerformImplicitConversion( |
| 4092 | NewStart.get(), VarRef.get()->getType(), Sema::AA_Converting, |
| 4093 | /*AllowExplicit=*/true); |
| 4094 | if (!NewStart.isUsable()) |
| 4095 | return ExprError(); |
| 4096 | } |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4097 | |
| 4098 | auto Init = |
| 4099 | SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), NewStart.get()); |
| 4100 | return Init; |
| 4101 | } |
| 4102 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4103 | /// \brief Build 'VarRef = Start + Iter * Step'. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4104 | static ExprResult |
| 4105 | BuildCounterUpdate(Sema &SemaRef, Scope *S, SourceLocation Loc, |
| 4106 | ExprResult VarRef, ExprResult Start, ExprResult Iter, |
| 4107 | ExprResult Step, bool Subtract, |
| 4108 | llvm::MapVector<Expr *, DeclRefExpr *> *Captures = nullptr) { |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4109 | // Add parentheses (for debugging purposes only). |
| 4110 | Iter = SemaRef.ActOnParenExpr(Loc, Loc, Iter.get()); |
| 4111 | if (!VarRef.isUsable() || !Start.isUsable() || !Iter.isUsable() || |
| 4112 | !Step.isUsable()) |
| 4113 | return ExprError(); |
| 4114 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4115 | ExprResult NewStep = Step; |
| 4116 | if (Captures) |
| 4117 | NewStep = tryBuildCapture(SemaRef, Step.get(), *Captures); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4118 | if (NewStep.isInvalid()) |
| 4119 | return ExprError(); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4120 | ExprResult Update = |
| 4121 | SemaRef.BuildBinOp(S, Loc, BO_Mul, Iter.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4122 | if (!Update.isUsable()) |
| 4123 | return ExprError(); |
| 4124 | |
Alexey Bataev | c0214e0 | 2016-02-16 12:13:49 +0000 | [diff] [blame] | 4125 | // Try to build 'VarRef = Start, VarRef (+|-)= Iter * Step' or |
| 4126 | // 'VarRef = Start (+|-) Iter * Step'. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4127 | ExprResult NewStart = Start; |
| 4128 | if (Captures) |
| 4129 | NewStart = tryBuildCapture(SemaRef, Start.get(), *Captures); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4130 | if (NewStart.isInvalid()) |
| 4131 | return ExprError(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4132 | |
Alexey Bataev | c0214e0 | 2016-02-16 12:13:49 +0000 | [diff] [blame] | 4133 | // First attempt: try to build 'VarRef = Start, VarRef += Iter * Step'. |
| 4134 | ExprResult SavedUpdate = Update; |
| 4135 | ExprResult UpdateVal; |
| 4136 | if (VarRef.get()->getType()->isOverloadableType() || |
| 4137 | NewStart.get()->getType()->isOverloadableType() || |
| 4138 | Update.get()->getType()->isOverloadableType()) { |
| 4139 | bool Suppress = SemaRef.getDiagnostics().getSuppressAllDiagnostics(); |
| 4140 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(/*Val=*/true); |
| 4141 | Update = |
| 4142 | SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), NewStart.get()); |
| 4143 | if (Update.isUsable()) { |
| 4144 | UpdateVal = |
| 4145 | SemaRef.BuildBinOp(S, Loc, Subtract ? BO_SubAssign : BO_AddAssign, |
| 4146 | VarRef.get(), SavedUpdate.get()); |
| 4147 | if (UpdateVal.isUsable()) { |
| 4148 | Update = SemaRef.CreateBuiltinBinOp(Loc, BO_Comma, Update.get(), |
| 4149 | UpdateVal.get()); |
| 4150 | } |
| 4151 | } |
| 4152 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(Suppress); |
| 4153 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4154 | |
Alexey Bataev | c0214e0 | 2016-02-16 12:13:49 +0000 | [diff] [blame] | 4155 | // Second attempt: try to build 'VarRef = Start (+|-) Iter * Step'. |
| 4156 | if (!Update.isUsable() || !UpdateVal.isUsable()) { |
| 4157 | Update = SemaRef.BuildBinOp(S, Loc, Subtract ? BO_Sub : BO_Add, |
| 4158 | NewStart.get(), SavedUpdate.get()); |
| 4159 | if (!Update.isUsable()) |
| 4160 | return ExprError(); |
| 4161 | |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 4162 | if (!SemaRef.Context.hasSameType(Update.get()->getType(), |
| 4163 | VarRef.get()->getType())) { |
| 4164 | Update = SemaRef.PerformImplicitConversion( |
| 4165 | Update.get(), VarRef.get()->getType(), Sema::AA_Converting, true); |
| 4166 | if (!Update.isUsable()) |
| 4167 | return ExprError(); |
| 4168 | } |
Alexey Bataev | c0214e0 | 2016-02-16 12:13:49 +0000 | [diff] [blame] | 4169 | |
| 4170 | Update = SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), Update.get()); |
| 4171 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4172 | return Update; |
| 4173 | } |
| 4174 | |
| 4175 | /// \brief Convert integer expression \a E to make it have at least \a Bits |
| 4176 | /// bits. |
| 4177 | static ExprResult WidenIterationCount(unsigned Bits, Expr *E, |
| 4178 | Sema &SemaRef) { |
| 4179 | if (E == nullptr) |
| 4180 | return ExprError(); |
| 4181 | auto &C = SemaRef.Context; |
| 4182 | QualType OldType = E->getType(); |
| 4183 | unsigned HasBits = C.getTypeSize(OldType); |
| 4184 | if (HasBits >= Bits) |
| 4185 | return ExprResult(E); |
| 4186 | // OK to convert to signed, because new type has more bits than old. |
| 4187 | QualType NewType = C.getIntTypeForBitwidth(Bits, /* Signed */ true); |
| 4188 | return SemaRef.PerformImplicitConversion(E, NewType, Sema::AA_Converting, |
| 4189 | true); |
| 4190 | } |
| 4191 | |
| 4192 | /// \brief Check if the given expression \a E is a constant integer that fits |
| 4193 | /// into \a Bits bits. |
| 4194 | static bool FitsInto(unsigned Bits, bool Signed, Expr *E, Sema &SemaRef) { |
| 4195 | if (E == nullptr) |
| 4196 | return false; |
| 4197 | llvm::APSInt Result; |
| 4198 | if (E->isIntegerConstantExpr(Result, SemaRef.Context)) |
| 4199 | return Signed ? Result.isSignedIntN(Bits) : Result.isIntN(Bits); |
| 4200 | return false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4201 | } |
| 4202 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4203 | /// Build preinits statement for the given declarations. |
| 4204 | static Stmt *buildPreInits(ASTContext &Context, |
| 4205 | SmallVectorImpl<Decl *> &PreInits) { |
| 4206 | if (!PreInits.empty()) { |
| 4207 | return new (Context) DeclStmt( |
| 4208 | DeclGroupRef::Create(Context, PreInits.begin(), PreInits.size()), |
| 4209 | SourceLocation(), SourceLocation()); |
| 4210 | } |
| 4211 | return nullptr; |
| 4212 | } |
| 4213 | |
| 4214 | /// Build preinits statement for the given declarations. |
| 4215 | static Stmt *buildPreInits(ASTContext &Context, |
| 4216 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) { |
| 4217 | if (!Captures.empty()) { |
| 4218 | SmallVector<Decl *, 16> PreInits; |
| 4219 | for (auto &Pair : Captures) |
| 4220 | PreInits.push_back(Pair.second->getDecl()); |
| 4221 | return buildPreInits(Context, PreInits); |
| 4222 | } |
| 4223 | return nullptr; |
| 4224 | } |
| 4225 | |
| 4226 | /// Build postupdate expression for the given list of postupdates expressions. |
| 4227 | static Expr *buildPostUpdate(Sema &S, ArrayRef<Expr *> PostUpdates) { |
| 4228 | Expr *PostUpdate = nullptr; |
| 4229 | if (!PostUpdates.empty()) { |
| 4230 | for (auto *E : PostUpdates) { |
| 4231 | Expr *ConvE = S.BuildCStyleCastExpr( |
| 4232 | E->getExprLoc(), |
| 4233 | S.Context.getTrivialTypeSourceInfo(S.Context.VoidTy), |
| 4234 | E->getExprLoc(), E) |
| 4235 | .get(); |
| 4236 | PostUpdate = PostUpdate |
| 4237 | ? S.CreateBuiltinBinOp(ConvE->getExprLoc(), BO_Comma, |
| 4238 | PostUpdate, ConvE) |
| 4239 | .get() |
| 4240 | : ConvE; |
| 4241 | } |
| 4242 | } |
| 4243 | return PostUpdate; |
| 4244 | } |
| 4245 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4246 | /// \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] | 4247 | /// \return Returns 0 if one of the collapsed stmts is not canonical for loop, |
| 4248 | /// number of collapsed loops otherwise. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4249 | static unsigned |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4250 | CheckOpenMPLoop(OpenMPDirectiveKind DKind, Expr *CollapseLoopCountExpr, |
| 4251 | Expr *OrderedLoopCountExpr, Stmt *AStmt, Sema &SemaRef, |
| 4252 | DSAStackTy &DSA, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 4253 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA, |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4254 | OMPLoopDirective::HelperExprs &Built) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 4255 | unsigned NestedLoopCount = 1; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4256 | if (CollapseLoopCountExpr) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 4257 | // Found 'collapse' clause - calculate collapse number. |
| 4258 | llvm::APSInt Result; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4259 | if (CollapseLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext())) |
Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 4260 | NestedLoopCount = Result.getLimitedValue(); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4261 | } |
| 4262 | if (OrderedLoopCountExpr) { |
| 4263 | // Found 'ordered' clause - calculate collapse number. |
| 4264 | llvm::APSInt Result; |
Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 4265 | if (OrderedLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext())) { |
| 4266 | if (Result.getLimitedValue() < NestedLoopCount) { |
| 4267 | SemaRef.Diag(OrderedLoopCountExpr->getExprLoc(), |
| 4268 | diag::err_omp_wrong_ordered_loop_count) |
| 4269 | << OrderedLoopCountExpr->getSourceRange(); |
| 4270 | SemaRef.Diag(CollapseLoopCountExpr->getExprLoc(), |
| 4271 | diag::note_collapse_loop_count) |
| 4272 | << CollapseLoopCountExpr->getSourceRange(); |
| 4273 | } |
| 4274 | NestedLoopCount = Result.getLimitedValue(); |
| 4275 | } |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 4276 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4277 | // This is helper routine for loop directives (e.g., 'for', 'simd', |
| 4278 | // 'for simd', etc.). |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4279 | llvm::MapVector<Expr *, DeclRefExpr *> Captures; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4280 | SmallVector<LoopIterationSpace, 4> IterSpaces; |
| 4281 | IterSpaces.resize(NestedLoopCount); |
| 4282 | Stmt *CurStmt = AStmt->IgnoreContainers(/* IgnoreCaptured */ true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4283 | for (unsigned Cnt = 0; Cnt < NestedLoopCount; ++Cnt) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 4284 | if (CheckOpenMPIterationSpace(DKind, CurStmt, SemaRef, DSA, Cnt, |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4285 | NestedLoopCount, CollapseLoopCountExpr, |
| 4286 | OrderedLoopCountExpr, VarsWithImplicitDSA, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4287 | IterSpaces[Cnt], Captures)) |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 4288 | return 0; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4289 | // 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] | 4290 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 4291 | // All loops associated with the construct must be perfectly nested; that |
| 4292 | // is, there must be no intervening code nor any OpenMP directive between |
| 4293 | // any two loops. |
| 4294 | CurStmt = cast<ForStmt>(CurStmt)->getBody()->IgnoreContainers(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4295 | } |
| 4296 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4297 | Built.clear(/* size */ NestedLoopCount); |
| 4298 | |
| 4299 | if (SemaRef.CurContext->isDependentContext()) |
| 4300 | return NestedLoopCount; |
| 4301 | |
| 4302 | // An example of what is generated for the following code: |
| 4303 | // |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4304 | // #pragma omp simd collapse(2) ordered(2) |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4305 | // for (i = 0; i < NI; ++i) |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4306 | // for (k = 0; k < NK; ++k) |
| 4307 | // for (j = J0; j < NJ; j+=2) { |
| 4308 | // <loop body> |
| 4309 | // } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4310 | // |
| 4311 | // We generate the code below. |
| 4312 | // Note: the loop body may be outlined in CodeGen. |
| 4313 | // Note: some counters may be C++ classes, operator- is used to find number of |
| 4314 | // iterations and operator+= to calculate counter value. |
| 4315 | // Note: decltype(NumIterations) must be integer type (in 'omp for', only i32 |
| 4316 | // or i64 is currently supported). |
| 4317 | // |
| 4318 | // #define NumIterations (NI * ((NJ - J0 - 1 + 2) / 2)) |
| 4319 | // for (int[32|64]_t IV = 0; IV < NumIterations; ++IV ) { |
| 4320 | // .local.i = IV / ((NJ - J0 - 1 + 2) / 2); |
| 4321 | // .local.j = J0 + (IV % ((NJ - J0 - 1 + 2) / 2)) * 2; |
| 4322 | // // similar updates for vars in clauses (e.g. 'linear') |
| 4323 | // <loop body (using local i and j)> |
| 4324 | // } |
| 4325 | // i = NI; // assign final values of counters |
| 4326 | // j = NJ; |
| 4327 | // |
| 4328 | |
| 4329 | // Last iteration number is (I1 * I2 * ... In) - 1, where I1, I2 ... In are |
| 4330 | // the iteration counts of the collapsed for loops. |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 4331 | // Precondition tests if there is at least one iteration (all conditions are |
| 4332 | // true). |
| 4333 | auto PreCond = ExprResult(IterSpaces[0].PreCond); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4334 | auto N0 = IterSpaces[0].NumIterations; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4335 | ExprResult LastIteration32 = WidenIterationCount( |
| 4336 | 32 /* Bits */, SemaRef.PerformImplicitConversion( |
| 4337 | N0->IgnoreImpCasts(), N0->getType(), |
| 4338 | Sema::AA_Converting, /*AllowExplicit=*/true) |
| 4339 | .get(), |
| 4340 | SemaRef); |
| 4341 | ExprResult LastIteration64 = WidenIterationCount( |
| 4342 | 64 /* Bits */, SemaRef.PerformImplicitConversion( |
| 4343 | N0->IgnoreImpCasts(), N0->getType(), |
| 4344 | Sema::AA_Converting, /*AllowExplicit=*/true) |
| 4345 | .get(), |
| 4346 | SemaRef); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4347 | |
| 4348 | if (!LastIteration32.isUsable() || !LastIteration64.isUsable()) |
| 4349 | return NestedLoopCount; |
| 4350 | |
| 4351 | auto &C = SemaRef.Context; |
| 4352 | bool AllCountsNeedLessThan32Bits = C.getTypeSize(N0->getType()) < 32; |
| 4353 | |
| 4354 | Scope *CurScope = DSA.getCurScope(); |
| 4355 | for (unsigned Cnt = 1; Cnt < NestedLoopCount; ++Cnt) { |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 4356 | if (PreCond.isUsable()) { |
| 4357 | PreCond = SemaRef.BuildBinOp(CurScope, SourceLocation(), BO_LAnd, |
| 4358 | PreCond.get(), IterSpaces[Cnt].PreCond); |
| 4359 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4360 | auto N = IterSpaces[Cnt].NumIterations; |
| 4361 | AllCountsNeedLessThan32Bits &= C.getTypeSize(N->getType()) < 32; |
| 4362 | if (LastIteration32.isUsable()) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4363 | LastIteration32 = SemaRef.BuildBinOp( |
| 4364 | CurScope, SourceLocation(), BO_Mul, LastIteration32.get(), |
| 4365 | SemaRef.PerformImplicitConversion(N->IgnoreImpCasts(), N->getType(), |
| 4366 | Sema::AA_Converting, |
| 4367 | /*AllowExplicit=*/true) |
| 4368 | .get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4369 | if (LastIteration64.isUsable()) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4370 | LastIteration64 = SemaRef.BuildBinOp( |
| 4371 | CurScope, SourceLocation(), BO_Mul, LastIteration64.get(), |
| 4372 | SemaRef.PerformImplicitConversion(N->IgnoreImpCasts(), N->getType(), |
| 4373 | Sema::AA_Converting, |
| 4374 | /*AllowExplicit=*/true) |
| 4375 | .get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4376 | } |
| 4377 | |
| 4378 | // Choose either the 32-bit or 64-bit version. |
| 4379 | ExprResult LastIteration = LastIteration64; |
| 4380 | if (LastIteration32.isUsable() && |
| 4381 | C.getTypeSize(LastIteration32.get()->getType()) == 32 && |
| 4382 | (AllCountsNeedLessThan32Bits || NestedLoopCount == 1 || |
| 4383 | FitsInto( |
| 4384 | 32 /* Bits */, |
| 4385 | LastIteration32.get()->getType()->hasSignedIntegerRepresentation(), |
| 4386 | LastIteration64.get(), SemaRef))) |
| 4387 | LastIteration = LastIteration32; |
| 4388 | |
| 4389 | if (!LastIteration.isUsable()) |
| 4390 | return 0; |
| 4391 | |
| 4392 | // Save the number of iterations. |
| 4393 | ExprResult NumIterations = LastIteration; |
| 4394 | { |
| 4395 | LastIteration = SemaRef.BuildBinOp( |
| 4396 | CurScope, SourceLocation(), BO_Sub, LastIteration.get(), |
| 4397 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 4398 | if (!LastIteration.isUsable()) |
| 4399 | return 0; |
| 4400 | } |
| 4401 | |
| 4402 | // Calculate the last iteration number beforehand instead of doing this on |
| 4403 | // each iteration. Do not do this if the number of iterations may be kfold-ed. |
| 4404 | llvm::APSInt Result; |
| 4405 | bool IsConstant = |
| 4406 | LastIteration.get()->isIntegerConstantExpr(Result, SemaRef.Context); |
| 4407 | ExprResult CalcLastIteration; |
| 4408 | if (!IsConstant) { |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4409 | ExprResult SaveRef = |
| 4410 | tryBuildCapture(SemaRef, LastIteration.get(), Captures); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4411 | LastIteration = SaveRef; |
| 4412 | |
| 4413 | // Prepare SaveRef + 1. |
| 4414 | NumIterations = SemaRef.BuildBinOp( |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4415 | CurScope, SourceLocation(), BO_Add, SaveRef.get(), |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4416 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 4417 | if (!NumIterations.isUsable()) |
| 4418 | return 0; |
| 4419 | } |
| 4420 | |
| 4421 | SourceLocation InitLoc = IterSpaces[0].InitSrcRange.getBegin(); |
| 4422 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4423 | QualType VType = LastIteration.get()->getType(); |
| 4424 | // Build variables passed into runtime, nesessary for worksharing directives. |
| 4425 | ExprResult LB, UB, IL, ST, EUB; |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 4426 | if (isOpenMPWorksharingDirective(DKind) || isOpenMPTaskLoopDirective(DKind) || |
| 4427 | isOpenMPDistributeDirective(DKind)) { |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4428 | // Lower bound variable, initialized with zero. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4429 | VarDecl *LBDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.lb"); |
| 4430 | LB = buildDeclRefExpr(SemaRef, LBDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4431 | SemaRef.AddInitializerToDecl( |
| 4432 | LBDecl, SemaRef.ActOnIntegerConstant(InitLoc, 0).get(), |
| 4433 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 4434 | |
| 4435 | // Upper bound variable, initialized with last iteration number. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4436 | VarDecl *UBDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.ub"); |
| 4437 | UB = buildDeclRefExpr(SemaRef, UBDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4438 | SemaRef.AddInitializerToDecl(UBDecl, LastIteration.get(), |
| 4439 | /*DirectInit*/ false, |
| 4440 | /*TypeMayContainAuto*/ false); |
| 4441 | |
| 4442 | // A 32-bit variable-flag where runtime returns 1 for the last iteration. |
| 4443 | // This will be used to implement clause 'lastprivate'. |
| 4444 | QualType Int32Ty = SemaRef.Context.getIntTypeForBitwidth(32, true); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4445 | VarDecl *ILDecl = buildVarDecl(SemaRef, InitLoc, Int32Ty, ".omp.is_last"); |
| 4446 | IL = buildDeclRefExpr(SemaRef, ILDecl, Int32Ty, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4447 | SemaRef.AddInitializerToDecl( |
| 4448 | ILDecl, SemaRef.ActOnIntegerConstant(InitLoc, 0).get(), |
| 4449 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 4450 | |
| 4451 | // Stride variable returned by runtime (we initialize it to 1 by default). |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4452 | VarDecl *STDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.stride"); |
| 4453 | ST = buildDeclRefExpr(SemaRef, STDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4454 | SemaRef.AddInitializerToDecl( |
| 4455 | STDecl, SemaRef.ActOnIntegerConstant(InitLoc, 1).get(), |
| 4456 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 4457 | |
| 4458 | // Build expression: UB = min(UB, LastIteration) |
| 4459 | // It is nesessary for CodeGen of directives with static scheduling. |
| 4460 | ExprResult IsUBGreater = SemaRef.BuildBinOp(CurScope, InitLoc, BO_GT, |
| 4461 | UB.get(), LastIteration.get()); |
| 4462 | ExprResult CondOp = SemaRef.ActOnConditionalOp( |
| 4463 | InitLoc, InitLoc, IsUBGreater.get(), LastIteration.get(), UB.get()); |
| 4464 | EUB = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, UB.get(), |
| 4465 | CondOp.get()); |
| 4466 | EUB = SemaRef.ActOnFinishFullExpr(EUB.get()); |
| 4467 | } |
| 4468 | |
| 4469 | // Build the iteration variable and its initialization before loop. |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4470 | ExprResult IV; |
| 4471 | ExprResult Init; |
| 4472 | { |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4473 | VarDecl *IVDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.iv"); |
| 4474 | IV = buildDeclRefExpr(SemaRef, IVDecl, VType, InitLoc); |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 4475 | Expr *RHS = (isOpenMPWorksharingDirective(DKind) || |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 4476 | isOpenMPTaskLoopDirective(DKind) || |
| 4477 | isOpenMPDistributeDirective(DKind)) |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4478 | ? LB.get() |
| 4479 | : SemaRef.ActOnIntegerConstant(SourceLocation(), 0).get(); |
| 4480 | Init = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, IV.get(), RHS); |
| 4481 | Init = SemaRef.ActOnFinishFullExpr(Init.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4482 | } |
| 4483 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4484 | // Loop condition (IV < NumIterations) or (IV <= UB) for worksharing loops. |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4485 | SourceLocation CondLoc; |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4486 | ExprResult Cond = |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 4487 | (isOpenMPWorksharingDirective(DKind) || |
| 4488 | isOpenMPTaskLoopDirective(DKind) || isOpenMPDistributeDirective(DKind)) |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4489 | ? SemaRef.BuildBinOp(CurScope, CondLoc, BO_LE, IV.get(), UB.get()) |
| 4490 | : SemaRef.BuildBinOp(CurScope, CondLoc, BO_LT, IV.get(), |
| 4491 | NumIterations.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4492 | |
| 4493 | // Loop increment (IV = IV + 1) |
| 4494 | SourceLocation IncLoc; |
| 4495 | ExprResult Inc = |
| 4496 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, IV.get(), |
| 4497 | SemaRef.ActOnIntegerConstant(IncLoc, 1).get()); |
| 4498 | if (!Inc.isUsable()) |
| 4499 | return 0; |
| 4500 | Inc = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, IV.get(), Inc.get()); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4501 | Inc = SemaRef.ActOnFinishFullExpr(Inc.get()); |
| 4502 | if (!Inc.isUsable()) |
| 4503 | return 0; |
| 4504 | |
| 4505 | // Increments for worksharing loops (LB = LB + ST; UB = UB + ST). |
| 4506 | // Used for directives with static scheduling. |
| 4507 | ExprResult NextLB, NextUB; |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 4508 | if (isOpenMPWorksharingDirective(DKind) || isOpenMPTaskLoopDirective(DKind) || |
| 4509 | isOpenMPDistributeDirective(DKind)) { |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4510 | // LB + ST |
| 4511 | NextLB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, LB.get(), ST.get()); |
| 4512 | if (!NextLB.isUsable()) |
| 4513 | return 0; |
| 4514 | // LB = LB + ST |
| 4515 | NextLB = |
| 4516 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, LB.get(), NextLB.get()); |
| 4517 | NextLB = SemaRef.ActOnFinishFullExpr(NextLB.get()); |
| 4518 | if (!NextLB.isUsable()) |
| 4519 | return 0; |
| 4520 | // UB + ST |
| 4521 | NextUB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, UB.get(), ST.get()); |
| 4522 | if (!NextUB.isUsable()) |
| 4523 | return 0; |
| 4524 | // UB = UB + ST |
| 4525 | NextUB = |
| 4526 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, UB.get(), NextUB.get()); |
| 4527 | NextUB = SemaRef.ActOnFinishFullExpr(NextUB.get()); |
| 4528 | if (!NextUB.isUsable()) |
| 4529 | return 0; |
| 4530 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4531 | |
| 4532 | // Build updates and final values of the loop counters. |
| 4533 | bool HasErrors = false; |
| 4534 | Built.Counters.resize(NestedLoopCount); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4535 | Built.Inits.resize(NestedLoopCount); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4536 | Built.Updates.resize(NestedLoopCount); |
| 4537 | Built.Finals.resize(NestedLoopCount); |
| 4538 | { |
| 4539 | ExprResult Div; |
| 4540 | // Go from inner nested loop to outer. |
| 4541 | for (int Cnt = NestedLoopCount - 1; Cnt >= 0; --Cnt) { |
| 4542 | LoopIterationSpace &IS = IterSpaces[Cnt]; |
| 4543 | SourceLocation UpdLoc = IS.IncSrcRange.getBegin(); |
| 4544 | // Build: Iter = (IV / Div) % IS.NumIters |
| 4545 | // where Div is product of previous iterations' IS.NumIters. |
| 4546 | ExprResult Iter; |
| 4547 | if (Div.isUsable()) { |
| 4548 | Iter = |
| 4549 | SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Div, IV.get(), Div.get()); |
| 4550 | } else { |
| 4551 | Iter = IV; |
| 4552 | assert((Cnt == (int)NestedLoopCount - 1) && |
| 4553 | "unusable div expected on first iteration only"); |
| 4554 | } |
| 4555 | |
| 4556 | if (Cnt != 0 && Iter.isUsable()) |
| 4557 | Iter = SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Rem, Iter.get(), |
| 4558 | IS.NumIterations); |
| 4559 | if (!Iter.isUsable()) { |
| 4560 | HasErrors = true; |
| 4561 | break; |
| 4562 | } |
| 4563 | |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4564 | // Build update: IS.CounterVar(Private) = IS.Start + Iter * IS.Step |
| 4565 | auto *CounterVar = buildDeclRefExpr( |
| 4566 | SemaRef, cast<VarDecl>(cast<DeclRefExpr>(IS.CounterVar)->getDecl()), |
| 4567 | IS.CounterVar->getType(), IS.CounterVar->getExprLoc(), |
| 4568 | /*RefersToCapture=*/true); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4569 | ExprResult Init = BuildCounterInit(SemaRef, CurScope, UpdLoc, CounterVar, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4570 | IS.CounterInit, Captures); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4571 | if (!Init.isUsable()) { |
| 4572 | HasErrors = true; |
| 4573 | break; |
| 4574 | } |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4575 | ExprResult Update = BuildCounterUpdate( |
| 4576 | SemaRef, CurScope, UpdLoc, CounterVar, IS.CounterInit, Iter, |
| 4577 | IS.CounterStep, IS.Subtract, &Captures); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4578 | if (!Update.isUsable()) { |
| 4579 | HasErrors = true; |
| 4580 | break; |
| 4581 | } |
| 4582 | |
| 4583 | // Build final: IS.CounterVar = IS.Start + IS.NumIters * IS.Step |
| 4584 | ExprResult Final = BuildCounterUpdate( |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4585 | SemaRef, CurScope, UpdLoc, CounterVar, IS.CounterInit, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4586 | IS.NumIterations, IS.CounterStep, IS.Subtract, &Captures); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4587 | if (!Final.isUsable()) { |
| 4588 | HasErrors = true; |
| 4589 | break; |
| 4590 | } |
| 4591 | |
| 4592 | // Build Div for the next iteration: Div <- Div * IS.NumIters |
| 4593 | if (Cnt != 0) { |
| 4594 | if (Div.isUnset()) |
| 4595 | Div = IS.NumIterations; |
| 4596 | else |
| 4597 | Div = SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Mul, Div.get(), |
| 4598 | IS.NumIterations); |
| 4599 | |
| 4600 | // Add parentheses (for debugging purposes only). |
| 4601 | if (Div.isUsable()) |
| 4602 | Div = SemaRef.ActOnParenExpr(UpdLoc, UpdLoc, Div.get()); |
| 4603 | if (!Div.isUsable()) { |
| 4604 | HasErrors = true; |
| 4605 | break; |
| 4606 | } |
| 4607 | } |
| 4608 | if (!Update.isUsable() || !Final.isUsable()) { |
| 4609 | HasErrors = true; |
| 4610 | break; |
| 4611 | } |
| 4612 | // Save results |
| 4613 | Built.Counters[Cnt] = IS.CounterVar; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 4614 | Built.PrivateCounters[Cnt] = IS.PrivateCounterVar; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4615 | Built.Inits[Cnt] = Init.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4616 | Built.Updates[Cnt] = Update.get(); |
| 4617 | Built.Finals[Cnt] = Final.get(); |
| 4618 | } |
| 4619 | } |
| 4620 | |
| 4621 | if (HasErrors) |
| 4622 | return 0; |
| 4623 | |
| 4624 | // Save results |
| 4625 | Built.IterationVarRef = IV.get(); |
| 4626 | Built.LastIteration = LastIteration.get(); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 4627 | Built.NumIterations = NumIterations.get(); |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 4628 | Built.CalcLastIteration = |
| 4629 | SemaRef.ActOnFinishFullExpr(CalcLastIteration.get()).get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4630 | Built.PreCond = PreCond.get(); |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4631 | Built.PreInits = buildPreInits(C, Captures); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4632 | Built.Cond = Cond.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4633 | Built.Init = Init.get(); |
| 4634 | Built.Inc = Inc.get(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4635 | Built.LB = LB.get(); |
| 4636 | Built.UB = UB.get(); |
| 4637 | Built.IL = IL.get(); |
| 4638 | Built.ST = ST.get(); |
| 4639 | Built.EUB = EUB.get(); |
| 4640 | Built.NLB = NextLB.get(); |
| 4641 | Built.NUB = NextUB.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4642 | |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 4643 | return NestedLoopCount; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4644 | } |
| 4645 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4646 | static Expr *getCollapseNumberExpr(ArrayRef<OMPClause *> Clauses) { |
Benjamin Kramer | fc600dc | 2015-08-30 15:12:28 +0000 | [diff] [blame] | 4647 | auto CollapseClauses = |
| 4648 | OMPExecutableDirective::getClausesOfKind<OMPCollapseClause>(Clauses); |
| 4649 | if (CollapseClauses.begin() != CollapseClauses.end()) |
| 4650 | return (*CollapseClauses.begin())->getNumForLoops(); |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 4651 | return nullptr; |
| 4652 | } |
| 4653 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4654 | static Expr *getOrderedNumberExpr(ArrayRef<OMPClause *> Clauses) { |
Benjamin Kramer | fc600dc | 2015-08-30 15:12:28 +0000 | [diff] [blame] | 4655 | auto OrderedClauses = |
| 4656 | OMPExecutableDirective::getClausesOfKind<OMPOrderedClause>(Clauses); |
| 4657 | if (OrderedClauses.begin() != OrderedClauses.end()) |
| 4658 | return (*OrderedClauses.begin())->getNumForLoops(); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4659 | return nullptr; |
| 4660 | } |
| 4661 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 4662 | static bool checkSimdlenSafelenValues(Sema &S, const Expr *Simdlen, |
| 4663 | const Expr *Safelen) { |
| 4664 | llvm::APSInt SimdlenRes, SafelenRes; |
| 4665 | if (Simdlen->isValueDependent() || Simdlen->isTypeDependent() || |
| 4666 | Simdlen->isInstantiationDependent() || |
| 4667 | Simdlen->containsUnexpandedParameterPack()) |
| 4668 | return false; |
| 4669 | if (Safelen->isValueDependent() || Safelen->isTypeDependent() || |
| 4670 | Safelen->isInstantiationDependent() || |
| 4671 | Safelen->containsUnexpandedParameterPack()) |
| 4672 | return false; |
| 4673 | Simdlen->EvaluateAsInt(SimdlenRes, S.Context); |
| 4674 | Safelen->EvaluateAsInt(SafelenRes, S.Context); |
| 4675 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 4676 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 4677 | // parameter must be less than or equal to the value of the safelen parameter. |
| 4678 | if (SimdlenRes > SafelenRes) { |
| 4679 | S.Diag(Simdlen->getExprLoc(), diag::err_omp_wrong_simdlen_safelen_values) |
| 4680 | << Simdlen->getSourceRange() << Safelen->getSourceRange(); |
| 4681 | return true; |
| 4682 | } |
| 4683 | return false; |
| 4684 | } |
| 4685 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4686 | StmtResult Sema::ActOnOpenMPSimdDirective( |
| 4687 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4688 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 4689 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4690 | if (!AStmt) |
| 4691 | return StmtError(); |
| 4692 | |
| 4693 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4694 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4695 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4696 | // define the nested loops number. |
| 4697 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 4698 | OMPD_simd, getCollapseNumberExpr(Clauses), getOrderedNumberExpr(Clauses), |
| 4699 | AStmt, *this, *DSAStack, VarsWithImplicitDSA, B); |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 4700 | if (NestedLoopCount == 0) |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 4701 | return StmtError(); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 4702 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4703 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 4704 | "omp simd loop exprs were not built"); |
| 4705 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 4706 | if (!CurContext->isDependentContext()) { |
| 4707 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4708 | for (auto C : Clauses) { |
| 4709 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 4710 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 4711 | B.NumIterations, *this, CurScope)) |
| 4712 | return StmtError(); |
| 4713 | } |
| 4714 | } |
| 4715 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 4716 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 4717 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 4718 | // parameter must be less than or equal to the value of the safelen parameter. |
| 4719 | OMPSafelenClause *Safelen = nullptr; |
| 4720 | OMPSimdlenClause *Simdlen = nullptr; |
| 4721 | for (auto *Clause : Clauses) { |
| 4722 | if (Clause->getClauseKind() == OMPC_safelen) |
| 4723 | Safelen = cast<OMPSafelenClause>(Clause); |
| 4724 | else if (Clause->getClauseKind() == OMPC_simdlen) |
| 4725 | Simdlen = cast<OMPSimdlenClause>(Clause); |
| 4726 | if (Safelen && Simdlen) |
| 4727 | break; |
| 4728 | } |
| 4729 | if (Simdlen && Safelen && |
| 4730 | checkSimdlenSafelenValues(*this, Simdlen->getSimdlen(), |
| 4731 | Safelen->getSafelen())) |
| 4732 | return StmtError(); |
| 4733 | |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 4734 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4735 | return OMPSimdDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| 4736 | Clauses, AStmt, B); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 4737 | } |
| 4738 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4739 | StmtResult Sema::ActOnOpenMPForDirective( |
| 4740 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4741 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 4742 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4743 | if (!AStmt) |
| 4744 | return StmtError(); |
| 4745 | |
| 4746 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4747 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4748 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4749 | // define the nested loops number. |
| 4750 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 4751 | OMPD_for, getCollapseNumberExpr(Clauses), getOrderedNumberExpr(Clauses), |
| 4752 | AStmt, *this, *DSAStack, VarsWithImplicitDSA, B); |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 4753 | if (NestedLoopCount == 0) |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4754 | return StmtError(); |
| 4755 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4756 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 4757 | "omp for loop exprs were not built"); |
| 4758 | |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 4759 | if (!CurContext->isDependentContext()) { |
| 4760 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4761 | for (auto C : Clauses) { |
| 4762 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 4763 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 4764 | B.NumIterations, *this, CurScope)) |
| 4765 | return StmtError(); |
| 4766 | } |
| 4767 | } |
| 4768 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4769 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4770 | return OMPForDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4771 | Clauses, AStmt, B, DSAStack->isCancelRegion()); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4772 | } |
| 4773 | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4774 | StmtResult Sema::ActOnOpenMPForSimdDirective( |
| 4775 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4776 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 4777 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4778 | if (!AStmt) |
| 4779 | return StmtError(); |
| 4780 | |
| 4781 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4782 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4783 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4784 | // define the nested loops number. |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4785 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4786 | CheckOpenMPLoop(OMPD_for_simd, getCollapseNumberExpr(Clauses), |
| 4787 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 4788 | VarsWithImplicitDSA, B); |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4789 | if (NestedLoopCount == 0) |
| 4790 | return StmtError(); |
| 4791 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4792 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 4793 | "omp for simd loop exprs were not built"); |
| 4794 | |
Alexey Bataev | 58e5bdb | 2015-06-18 04:45:29 +0000 | [diff] [blame] | 4795 | if (!CurContext->isDependentContext()) { |
| 4796 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4797 | for (auto C : Clauses) { |
| 4798 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 4799 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 4800 | B.NumIterations, *this, CurScope)) |
| 4801 | return StmtError(); |
| 4802 | } |
| 4803 | } |
| 4804 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 4805 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 4806 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 4807 | // parameter must be less than or equal to the value of the safelen parameter. |
| 4808 | OMPSafelenClause *Safelen = nullptr; |
| 4809 | OMPSimdlenClause *Simdlen = nullptr; |
| 4810 | for (auto *Clause : Clauses) { |
| 4811 | if (Clause->getClauseKind() == OMPC_safelen) |
| 4812 | Safelen = cast<OMPSafelenClause>(Clause); |
| 4813 | else if (Clause->getClauseKind() == OMPC_simdlen) |
| 4814 | Simdlen = cast<OMPSimdlenClause>(Clause); |
| 4815 | if (Safelen && Simdlen) |
| 4816 | break; |
| 4817 | } |
| 4818 | if (Simdlen && Safelen && |
| 4819 | checkSimdlenSafelenValues(*this, Simdlen->getSimdlen(), |
| 4820 | Safelen->getSafelen())) |
| 4821 | return StmtError(); |
| 4822 | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4823 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4824 | return OMPForSimdDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| 4825 | Clauses, AStmt, B); |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4826 | } |
| 4827 | |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4828 | StmtResult Sema::ActOnOpenMPSectionsDirective(ArrayRef<OMPClause *> Clauses, |
| 4829 | Stmt *AStmt, |
| 4830 | SourceLocation StartLoc, |
| 4831 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4832 | if (!AStmt) |
| 4833 | return StmtError(); |
| 4834 | |
| 4835 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4836 | auto BaseStmt = AStmt; |
| 4837 | while (CapturedStmt *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt)) |
| 4838 | BaseStmt = CS->getCapturedStmt(); |
| 4839 | if (auto C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) { |
| 4840 | auto S = C->children(); |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 4841 | if (S.begin() == S.end()) |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4842 | return StmtError(); |
| 4843 | // All associated statements must be '#pragma omp section' except for |
| 4844 | // the first one. |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 4845 | for (Stmt *SectionStmt : llvm::make_range(std::next(S.begin()), S.end())) { |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4846 | if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) { |
| 4847 | if (SectionStmt) |
| 4848 | Diag(SectionStmt->getLocStart(), |
| 4849 | diag::err_omp_sections_substmt_not_section); |
| 4850 | return StmtError(); |
| 4851 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4852 | cast<OMPSectionDirective>(SectionStmt) |
| 4853 | ->setHasCancel(DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4854 | } |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4855 | } else { |
| 4856 | Diag(AStmt->getLocStart(), diag::err_omp_sections_not_compound_stmt); |
| 4857 | return StmtError(); |
| 4858 | } |
| 4859 | |
| 4860 | getCurFunction()->setHasBranchProtectedScope(); |
| 4861 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4862 | return OMPSectionsDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 4863 | DSAStack->isCancelRegion()); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4864 | } |
| 4865 | |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4866 | StmtResult Sema::ActOnOpenMPSectionDirective(Stmt *AStmt, |
| 4867 | SourceLocation StartLoc, |
| 4868 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4869 | if (!AStmt) |
| 4870 | return StmtError(); |
| 4871 | |
| 4872 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4873 | |
| 4874 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4875 | DSAStack->setParentCancelRegion(DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4876 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4877 | return OMPSectionDirective::Create(Context, StartLoc, EndLoc, AStmt, |
| 4878 | DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4879 | } |
| 4880 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 4881 | StmtResult Sema::ActOnOpenMPSingleDirective(ArrayRef<OMPClause *> Clauses, |
| 4882 | Stmt *AStmt, |
| 4883 | SourceLocation StartLoc, |
| 4884 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4885 | if (!AStmt) |
| 4886 | return StmtError(); |
| 4887 | |
| 4888 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 74a05c9 | 2014-07-15 02:55:09 +0000 | [diff] [blame] | 4889 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 4890 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | 74a05c9 | 2014-07-15 02:55:09 +0000 | [diff] [blame] | 4891 | |
Alexey Bataev | 3255bf3 | 2015-01-19 05:20:46 +0000 | [diff] [blame] | 4892 | // OpenMP [2.7.3, single Construct, Restrictions] |
| 4893 | // The copyprivate clause must not be used with the nowait clause. |
| 4894 | OMPClause *Nowait = nullptr; |
| 4895 | OMPClause *Copyprivate = nullptr; |
| 4896 | for (auto *Clause : Clauses) { |
| 4897 | if (Clause->getClauseKind() == OMPC_nowait) |
| 4898 | Nowait = Clause; |
| 4899 | else if (Clause->getClauseKind() == OMPC_copyprivate) |
| 4900 | Copyprivate = Clause; |
| 4901 | if (Copyprivate && Nowait) { |
| 4902 | Diag(Copyprivate->getLocStart(), |
| 4903 | diag::err_omp_single_copyprivate_with_nowait); |
| 4904 | Diag(Nowait->getLocStart(), diag::note_omp_nowait_clause_here); |
| 4905 | return StmtError(); |
| 4906 | } |
| 4907 | } |
| 4908 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 4909 | return OMPSingleDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 4910 | } |
| 4911 | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 4912 | StmtResult Sema::ActOnOpenMPMasterDirective(Stmt *AStmt, |
| 4913 | SourceLocation StartLoc, |
| 4914 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4915 | if (!AStmt) |
| 4916 | return StmtError(); |
| 4917 | |
| 4918 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 4919 | |
| 4920 | getCurFunction()->setHasBranchProtectedScope(); |
| 4921 | |
| 4922 | return OMPMasterDirective::Create(Context, StartLoc, EndLoc, AStmt); |
| 4923 | } |
| 4924 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 4925 | StmtResult Sema::ActOnOpenMPCriticalDirective( |
| 4926 | const DeclarationNameInfo &DirName, ArrayRef<OMPClause *> Clauses, |
| 4927 | Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4928 | if (!AStmt) |
| 4929 | return StmtError(); |
| 4930 | |
| 4931 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 4932 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 4933 | bool ErrorFound = false; |
| 4934 | llvm::APSInt Hint; |
| 4935 | SourceLocation HintLoc; |
| 4936 | bool DependentHint = false; |
| 4937 | for (auto *C : Clauses) { |
| 4938 | if (C->getClauseKind() == OMPC_hint) { |
| 4939 | if (!DirName.getName()) { |
| 4940 | Diag(C->getLocStart(), diag::err_omp_hint_clause_no_name); |
| 4941 | ErrorFound = true; |
| 4942 | } |
| 4943 | Expr *E = cast<OMPHintClause>(C)->getHint(); |
| 4944 | if (E->isTypeDependent() || E->isValueDependent() || |
| 4945 | E->isInstantiationDependent()) |
| 4946 | DependentHint = true; |
| 4947 | else { |
| 4948 | Hint = E->EvaluateKnownConstInt(Context); |
| 4949 | HintLoc = C->getLocStart(); |
| 4950 | } |
| 4951 | } |
| 4952 | } |
| 4953 | if (ErrorFound) |
| 4954 | return StmtError(); |
| 4955 | auto Pair = DSAStack->getCriticalWithHint(DirName); |
| 4956 | if (Pair.first && DirName.getName() && !DependentHint) { |
| 4957 | if (llvm::APSInt::compareValues(Hint, Pair.second) != 0) { |
| 4958 | Diag(StartLoc, diag::err_omp_critical_with_hint); |
| 4959 | if (HintLoc.isValid()) { |
| 4960 | Diag(HintLoc, diag::note_omp_critical_hint_here) |
| 4961 | << 0 << Hint.toString(/*Radix=*/10, /*Signed=*/false); |
| 4962 | } else |
| 4963 | Diag(StartLoc, diag::note_omp_critical_no_hint) << 0; |
| 4964 | if (auto *C = Pair.first->getSingleClause<OMPHintClause>()) { |
| 4965 | Diag(C->getLocStart(), diag::note_omp_critical_hint_here) |
| 4966 | << 1 |
| 4967 | << C->getHint()->EvaluateKnownConstInt(Context).toString( |
| 4968 | /*Radix=*/10, /*Signed=*/false); |
| 4969 | } else |
| 4970 | Diag(Pair.first->getLocStart(), diag::note_omp_critical_no_hint) << 1; |
| 4971 | } |
| 4972 | } |
| 4973 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 4974 | getCurFunction()->setHasBranchProtectedScope(); |
| 4975 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 4976 | auto *Dir = OMPCriticalDirective::Create(Context, DirName, StartLoc, EndLoc, |
| 4977 | Clauses, AStmt); |
| 4978 | if (!Pair.first && DirName.getName() && !DependentHint) |
| 4979 | DSAStack->addCriticalWithHint(Dir, Hint); |
| 4980 | return Dir; |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 4981 | } |
| 4982 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4983 | StmtResult Sema::ActOnOpenMPParallelForDirective( |
| 4984 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4985 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 4986 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4987 | if (!AStmt) |
| 4988 | return StmtError(); |
| 4989 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4990 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 4991 | // 1.2.2 OpenMP Language Terminology |
| 4992 | // Structured block - An executable statement with a single entry at the |
| 4993 | // top and a single exit at the bottom. |
| 4994 | // The point of exit cannot be a branch out of the structured block. |
| 4995 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 4996 | CS->getCapturedDecl()->setNothrow(); |
| 4997 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4998 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4999 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 5000 | // define the nested loops number. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 5001 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5002 | CheckOpenMPLoop(OMPD_parallel_for, getCollapseNumberExpr(Clauses), |
| 5003 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 5004 | VarsWithImplicitDSA, B); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 5005 | if (NestedLoopCount == 0) |
| 5006 | return StmtError(); |
| 5007 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5008 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 5009 | "omp parallel for loop exprs were not built"); |
| 5010 | |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 5011 | if (!CurContext->isDependentContext()) { |
| 5012 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 5013 | for (auto C : Clauses) { |
| 5014 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 5015 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 5016 | B.NumIterations, *this, CurScope)) |
| 5017 | return StmtError(); |
| 5018 | } |
| 5019 | } |
| 5020 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 5021 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5022 | return OMPParallelForDirective::Create(Context, StartLoc, EndLoc, |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 5023 | NestedLoopCount, Clauses, AStmt, B, |
| 5024 | DSAStack->isCancelRegion()); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 5025 | } |
| 5026 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 5027 | StmtResult Sema::ActOnOpenMPParallelForSimdDirective( |
| 5028 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 5029 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 5030 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5031 | if (!AStmt) |
| 5032 | return StmtError(); |
| 5033 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 5034 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 5035 | // 1.2.2 OpenMP Language Terminology |
| 5036 | // Structured block - An executable statement with a single entry at the |
| 5037 | // top and a single exit at the bottom. |
| 5038 | // The point of exit cannot be a branch out of the structured block. |
| 5039 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5040 | CS->getCapturedDecl()->setNothrow(); |
| 5041 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5042 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5043 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 5044 | // define the nested loops number. |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 5045 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5046 | CheckOpenMPLoop(OMPD_parallel_for_simd, getCollapseNumberExpr(Clauses), |
| 5047 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 5048 | VarsWithImplicitDSA, B); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 5049 | if (NestedLoopCount == 0) |
| 5050 | return StmtError(); |
| 5051 | |
Alexey Bataev | 3b5b5c4 | 2015-06-18 10:10:12 +0000 | [diff] [blame] | 5052 | if (!CurContext->isDependentContext()) { |
| 5053 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 5054 | for (auto C : Clauses) { |
| 5055 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 5056 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 5057 | B.NumIterations, *this, CurScope)) |
| 5058 | return StmtError(); |
| 5059 | } |
| 5060 | } |
| 5061 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 5062 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 5063 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 5064 | // parameter must be less than or equal to the value of the safelen parameter. |
| 5065 | OMPSafelenClause *Safelen = nullptr; |
| 5066 | OMPSimdlenClause *Simdlen = nullptr; |
| 5067 | for (auto *Clause : Clauses) { |
| 5068 | if (Clause->getClauseKind() == OMPC_safelen) |
| 5069 | Safelen = cast<OMPSafelenClause>(Clause); |
| 5070 | else if (Clause->getClauseKind() == OMPC_simdlen) |
| 5071 | Simdlen = cast<OMPSimdlenClause>(Clause); |
| 5072 | if (Safelen && Simdlen) |
| 5073 | break; |
| 5074 | } |
| 5075 | if (Simdlen && Safelen && |
| 5076 | checkSimdlenSafelenValues(*this, Simdlen->getSimdlen(), |
| 5077 | Safelen->getSafelen())) |
| 5078 | return StmtError(); |
| 5079 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 5080 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5081 | return OMPParallelForSimdDirective::Create( |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5082 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 5083 | } |
| 5084 | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 5085 | StmtResult |
| 5086 | Sema::ActOnOpenMPParallelSectionsDirective(ArrayRef<OMPClause *> Clauses, |
| 5087 | Stmt *AStmt, SourceLocation StartLoc, |
| 5088 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5089 | if (!AStmt) |
| 5090 | return StmtError(); |
| 5091 | |
| 5092 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 5093 | auto BaseStmt = AStmt; |
| 5094 | while (CapturedStmt *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt)) |
| 5095 | BaseStmt = CS->getCapturedStmt(); |
| 5096 | if (auto C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) { |
| 5097 | auto S = C->children(); |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 5098 | if (S.begin() == S.end()) |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 5099 | return StmtError(); |
| 5100 | // All associated statements must be '#pragma omp section' except for |
| 5101 | // the first one. |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 5102 | for (Stmt *SectionStmt : llvm::make_range(std::next(S.begin()), S.end())) { |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 5103 | if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) { |
| 5104 | if (SectionStmt) |
| 5105 | Diag(SectionStmt->getLocStart(), |
| 5106 | diag::err_omp_parallel_sections_substmt_not_section); |
| 5107 | return StmtError(); |
| 5108 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 5109 | cast<OMPSectionDirective>(SectionStmt) |
| 5110 | ->setHasCancel(DSAStack->isCancelRegion()); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 5111 | } |
| 5112 | } else { |
| 5113 | Diag(AStmt->getLocStart(), |
| 5114 | diag::err_omp_parallel_sections_not_compound_stmt); |
| 5115 | return StmtError(); |
| 5116 | } |
| 5117 | |
| 5118 | getCurFunction()->setHasBranchProtectedScope(); |
| 5119 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 5120 | return OMPParallelSectionsDirective::Create( |
| 5121 | Context, StartLoc, EndLoc, Clauses, AStmt, DSAStack->isCancelRegion()); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 5122 | } |
| 5123 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5124 | StmtResult Sema::ActOnOpenMPTaskDirective(ArrayRef<OMPClause *> Clauses, |
| 5125 | Stmt *AStmt, SourceLocation StartLoc, |
| 5126 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5127 | if (!AStmt) |
| 5128 | return StmtError(); |
| 5129 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5130 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 5131 | // 1.2.2 OpenMP Language Terminology |
| 5132 | // Structured block - An executable statement with a single entry at the |
| 5133 | // top and a single exit at the bottom. |
| 5134 | // The point of exit cannot be a branch out of the structured block. |
| 5135 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5136 | CS->getCapturedDecl()->setNothrow(); |
| 5137 | |
| 5138 | getCurFunction()->setHasBranchProtectedScope(); |
| 5139 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 5140 | return OMPTaskDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 5141 | DSAStack->isCancelRegion()); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5142 | } |
| 5143 | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 5144 | StmtResult Sema::ActOnOpenMPTaskyieldDirective(SourceLocation StartLoc, |
| 5145 | SourceLocation EndLoc) { |
| 5146 | return OMPTaskyieldDirective::Create(Context, StartLoc, EndLoc); |
| 5147 | } |
| 5148 | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 5149 | StmtResult Sema::ActOnOpenMPBarrierDirective(SourceLocation StartLoc, |
| 5150 | SourceLocation EndLoc) { |
| 5151 | return OMPBarrierDirective::Create(Context, StartLoc, EndLoc); |
| 5152 | } |
| 5153 | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 5154 | StmtResult Sema::ActOnOpenMPTaskwaitDirective(SourceLocation StartLoc, |
| 5155 | SourceLocation EndLoc) { |
| 5156 | return OMPTaskwaitDirective::Create(Context, StartLoc, EndLoc); |
| 5157 | } |
| 5158 | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 5159 | StmtResult Sema::ActOnOpenMPTaskgroupDirective(Stmt *AStmt, |
| 5160 | SourceLocation StartLoc, |
| 5161 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5162 | if (!AStmt) |
| 5163 | return StmtError(); |
| 5164 | |
| 5165 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 5166 | |
| 5167 | getCurFunction()->setHasBranchProtectedScope(); |
| 5168 | |
| 5169 | return OMPTaskgroupDirective::Create(Context, StartLoc, EndLoc, AStmt); |
| 5170 | } |
| 5171 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 5172 | StmtResult Sema::ActOnOpenMPFlushDirective(ArrayRef<OMPClause *> Clauses, |
| 5173 | SourceLocation StartLoc, |
| 5174 | SourceLocation EndLoc) { |
| 5175 | assert(Clauses.size() <= 1 && "Extra clauses in flush directive"); |
| 5176 | return OMPFlushDirective::Create(Context, StartLoc, EndLoc, Clauses); |
| 5177 | } |
| 5178 | |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5179 | StmtResult Sema::ActOnOpenMPOrderedDirective(ArrayRef<OMPClause *> Clauses, |
| 5180 | Stmt *AStmt, |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 5181 | SourceLocation StartLoc, |
| 5182 | SourceLocation EndLoc) { |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5183 | OMPClause *DependFound = nullptr; |
| 5184 | OMPClause *DependSourceClause = nullptr; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 5185 | OMPClause *DependSinkClause = nullptr; |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5186 | bool ErrorFound = false; |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5187 | OMPThreadsClause *TC = nullptr; |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5188 | OMPSIMDClause *SC = nullptr; |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5189 | for (auto *C : Clauses) { |
| 5190 | if (auto *DC = dyn_cast<OMPDependClause>(C)) { |
| 5191 | DependFound = C; |
| 5192 | if (DC->getDependencyKind() == OMPC_DEPEND_source) { |
| 5193 | if (DependSourceClause) { |
| 5194 | Diag(C->getLocStart(), diag::err_omp_more_one_clause) |
| 5195 | << getOpenMPDirectiveName(OMPD_ordered) |
| 5196 | << getOpenMPClauseName(OMPC_depend) << 2; |
| 5197 | ErrorFound = true; |
| 5198 | } else |
| 5199 | DependSourceClause = C; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 5200 | if (DependSinkClause) { |
| 5201 | Diag(C->getLocStart(), diag::err_omp_depend_sink_source_not_allowed) |
| 5202 | << 0; |
| 5203 | ErrorFound = true; |
| 5204 | } |
| 5205 | } else if (DC->getDependencyKind() == OMPC_DEPEND_sink) { |
| 5206 | if (DependSourceClause) { |
| 5207 | Diag(C->getLocStart(), diag::err_omp_depend_sink_source_not_allowed) |
| 5208 | << 1; |
| 5209 | ErrorFound = true; |
| 5210 | } |
| 5211 | DependSinkClause = C; |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5212 | } |
| 5213 | } else if (C->getClauseKind() == OMPC_threads) |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5214 | TC = cast<OMPThreadsClause>(C); |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5215 | else if (C->getClauseKind() == OMPC_simd) |
| 5216 | SC = cast<OMPSIMDClause>(C); |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5217 | } |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5218 | if (!ErrorFound && !SC && |
| 5219 | isOpenMPSimdDirective(DSAStack->getParentDirective())) { |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5220 | // OpenMP [2.8.1,simd Construct, Restrictions] |
| 5221 | // An ordered construct with the simd clause is the only OpenMP construct |
| 5222 | // that can appear in the simd region. |
| 5223 | Diag(StartLoc, diag::err_omp_prohibited_region_simd); |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5224 | ErrorFound = true; |
| 5225 | } else if (DependFound && (TC || SC)) { |
| 5226 | Diag(DependFound->getLocStart(), diag::err_omp_depend_clause_thread_simd) |
| 5227 | << getOpenMPClauseName(TC ? TC->getClauseKind() : SC->getClauseKind()); |
| 5228 | ErrorFound = true; |
| 5229 | } else if (DependFound && !DSAStack->getParentOrderedRegionParam()) { |
| 5230 | Diag(DependFound->getLocStart(), |
| 5231 | diag::err_omp_ordered_directive_without_param); |
| 5232 | ErrorFound = true; |
| 5233 | } else if (TC || Clauses.empty()) { |
| 5234 | if (auto *Param = DSAStack->getParentOrderedRegionParam()) { |
| 5235 | SourceLocation ErrLoc = TC ? TC->getLocStart() : StartLoc; |
| 5236 | Diag(ErrLoc, diag::err_omp_ordered_directive_with_param) |
| 5237 | << (TC != nullptr); |
| 5238 | Diag(Param->getLocStart(), diag::note_omp_ordered_param); |
| 5239 | ErrorFound = true; |
| 5240 | } |
| 5241 | } |
| 5242 | if ((!AStmt && !DependFound) || ErrorFound) |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5243 | return StmtError(); |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5244 | |
| 5245 | if (AStmt) { |
| 5246 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 5247 | |
| 5248 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5249 | } |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5250 | |
| 5251 | return OMPOrderedDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 5252 | } |
| 5253 | |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5254 | namespace { |
| 5255 | /// \brief Helper class for checking expression in 'omp atomic [update]' |
| 5256 | /// construct. |
| 5257 | class OpenMPAtomicUpdateChecker { |
| 5258 | /// \brief Error results for atomic update expressions. |
| 5259 | enum ExprAnalysisErrorCode { |
| 5260 | /// \brief A statement is not an expression statement. |
| 5261 | NotAnExpression, |
| 5262 | /// \brief Expression is not builtin binary or unary operation. |
| 5263 | NotABinaryOrUnaryExpression, |
| 5264 | /// \brief Unary operation is not post-/pre- increment/decrement operation. |
| 5265 | NotAnUnaryIncDecExpression, |
| 5266 | /// \brief An expression is not of scalar type. |
| 5267 | NotAScalarType, |
| 5268 | /// \brief A binary operation is not an assignment operation. |
| 5269 | NotAnAssignmentOp, |
| 5270 | /// \brief RHS part of the binary operation is not a binary expression. |
| 5271 | NotABinaryExpression, |
| 5272 | /// \brief RHS part is not additive/multiplicative/shift/biwise binary |
| 5273 | /// expression. |
| 5274 | NotABinaryOperator, |
| 5275 | /// \brief RHS binary operation does not have reference to the updated LHS |
| 5276 | /// part. |
| 5277 | NotAnUpdateExpression, |
| 5278 | /// \brief No errors is found. |
| 5279 | NoError |
| 5280 | }; |
| 5281 | /// \brief Reference to Sema. |
| 5282 | Sema &SemaRef; |
| 5283 | /// \brief A location for note diagnostics (when error is found). |
| 5284 | SourceLocation NoteLoc; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5285 | /// \brief 'x' lvalue part of the source atomic expression. |
| 5286 | Expr *X; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5287 | /// \brief 'expr' rvalue part of the source atomic expression. |
| 5288 | Expr *E; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5289 | /// \brief Helper expression of the form |
| 5290 | /// 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or |
| 5291 | /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'. |
| 5292 | Expr *UpdateExpr; |
| 5293 | /// \brief Is 'x' a LHS in a RHS part of full update expression. It is |
| 5294 | /// important for non-associative operations. |
| 5295 | bool IsXLHSInRHSPart; |
| 5296 | BinaryOperatorKind Op; |
| 5297 | SourceLocation OpLoc; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5298 | /// \brief true if the source expression is a postfix unary operation, false |
| 5299 | /// if it is a prefix unary operation. |
| 5300 | bool IsPostfixUpdate; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5301 | |
| 5302 | public: |
| 5303 | OpenMPAtomicUpdateChecker(Sema &SemaRef) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5304 | : SemaRef(SemaRef), X(nullptr), E(nullptr), UpdateExpr(nullptr), |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5305 | IsXLHSInRHSPart(false), Op(BO_PtrMemD), IsPostfixUpdate(false) {} |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5306 | /// \brief Check specified statement that it is suitable for 'atomic update' |
| 5307 | /// constructs and extract 'x', 'expr' and Operation from the original |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5308 | /// expression. If DiagId and NoteId == 0, then only check is performed |
| 5309 | /// without error notification. |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5310 | /// \param DiagId Diagnostic which should be emitted if error is found. |
| 5311 | /// \param NoteId Diagnostic note for the main error message. |
| 5312 | /// \return true if statement is not an update expression, false otherwise. |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5313 | bool checkStatement(Stmt *S, unsigned DiagId = 0, unsigned NoteId = 0); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5314 | /// \brief Return the 'x' lvalue part of the source atomic expression. |
| 5315 | Expr *getX() const { return X; } |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5316 | /// \brief Return the 'expr' rvalue part of the source atomic expression. |
| 5317 | Expr *getExpr() const { return E; } |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5318 | /// \brief Return the update expression used in calculation of the updated |
| 5319 | /// value. Always has form 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or |
| 5320 | /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'. |
| 5321 | Expr *getUpdateExpr() const { return UpdateExpr; } |
| 5322 | /// \brief Return true if 'x' is LHS in RHS part of full update expression, |
| 5323 | /// false otherwise. |
| 5324 | bool isXLHSInRHSPart() const { return IsXLHSInRHSPart; } |
| 5325 | |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5326 | /// \brief true if the source expression is a postfix unary operation, false |
| 5327 | /// if it is a prefix unary operation. |
| 5328 | bool isPostfixUpdate() const { return IsPostfixUpdate; } |
| 5329 | |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5330 | private: |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5331 | bool checkBinaryOperation(BinaryOperator *AtomicBinOp, unsigned DiagId = 0, |
| 5332 | unsigned NoteId = 0); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5333 | }; |
| 5334 | } // namespace |
| 5335 | |
| 5336 | bool OpenMPAtomicUpdateChecker::checkBinaryOperation( |
| 5337 | BinaryOperator *AtomicBinOp, unsigned DiagId, unsigned NoteId) { |
| 5338 | ExprAnalysisErrorCode ErrorFound = NoError; |
| 5339 | SourceLocation ErrorLoc, NoteLoc; |
| 5340 | SourceRange ErrorRange, NoteRange; |
| 5341 | // Allowed constructs are: |
| 5342 | // x = x binop expr; |
| 5343 | // x = expr binop x; |
| 5344 | if (AtomicBinOp->getOpcode() == BO_Assign) { |
| 5345 | X = AtomicBinOp->getLHS(); |
| 5346 | if (auto *AtomicInnerBinOp = dyn_cast<BinaryOperator>( |
| 5347 | AtomicBinOp->getRHS()->IgnoreParenImpCasts())) { |
| 5348 | if (AtomicInnerBinOp->isMultiplicativeOp() || |
| 5349 | AtomicInnerBinOp->isAdditiveOp() || AtomicInnerBinOp->isShiftOp() || |
| 5350 | AtomicInnerBinOp->isBitwiseOp()) { |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5351 | Op = AtomicInnerBinOp->getOpcode(); |
| 5352 | OpLoc = AtomicInnerBinOp->getOperatorLoc(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5353 | auto *LHS = AtomicInnerBinOp->getLHS(); |
| 5354 | auto *RHS = AtomicInnerBinOp->getRHS(); |
| 5355 | llvm::FoldingSetNodeID XId, LHSId, RHSId; |
| 5356 | X->IgnoreParenImpCasts()->Profile(XId, SemaRef.getASTContext(), |
| 5357 | /*Canonical=*/true); |
| 5358 | LHS->IgnoreParenImpCasts()->Profile(LHSId, SemaRef.getASTContext(), |
| 5359 | /*Canonical=*/true); |
| 5360 | RHS->IgnoreParenImpCasts()->Profile(RHSId, SemaRef.getASTContext(), |
| 5361 | /*Canonical=*/true); |
| 5362 | if (XId == LHSId) { |
| 5363 | E = RHS; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5364 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5365 | } else if (XId == RHSId) { |
| 5366 | E = LHS; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5367 | IsXLHSInRHSPart = false; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5368 | } else { |
| 5369 | ErrorLoc = AtomicInnerBinOp->getExprLoc(); |
| 5370 | ErrorRange = AtomicInnerBinOp->getSourceRange(); |
| 5371 | NoteLoc = X->getExprLoc(); |
| 5372 | NoteRange = X->getSourceRange(); |
| 5373 | ErrorFound = NotAnUpdateExpression; |
| 5374 | } |
| 5375 | } else { |
| 5376 | ErrorLoc = AtomicInnerBinOp->getExprLoc(); |
| 5377 | ErrorRange = AtomicInnerBinOp->getSourceRange(); |
| 5378 | NoteLoc = AtomicInnerBinOp->getOperatorLoc(); |
| 5379 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 5380 | ErrorFound = NotABinaryOperator; |
| 5381 | } |
| 5382 | } else { |
| 5383 | NoteLoc = ErrorLoc = AtomicBinOp->getRHS()->getExprLoc(); |
| 5384 | NoteRange = ErrorRange = AtomicBinOp->getRHS()->getSourceRange(); |
| 5385 | ErrorFound = NotABinaryExpression; |
| 5386 | } |
| 5387 | } else { |
| 5388 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5389 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5390 | NoteLoc = AtomicBinOp->getOperatorLoc(); |
| 5391 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 5392 | ErrorFound = NotAnAssignmentOp; |
| 5393 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5394 | if (ErrorFound != NoError && DiagId != 0 && NoteId != 0) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5395 | SemaRef.Diag(ErrorLoc, DiagId) << ErrorRange; |
| 5396 | SemaRef.Diag(NoteLoc, NoteId) << ErrorFound << NoteRange; |
| 5397 | return true; |
| 5398 | } else if (SemaRef.CurContext->isDependentContext()) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5399 | E = X = UpdateExpr = nullptr; |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5400 | return ErrorFound != NoError; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5401 | } |
| 5402 | |
| 5403 | bool OpenMPAtomicUpdateChecker::checkStatement(Stmt *S, unsigned DiagId, |
| 5404 | unsigned NoteId) { |
| 5405 | ExprAnalysisErrorCode ErrorFound = NoError; |
| 5406 | SourceLocation ErrorLoc, NoteLoc; |
| 5407 | SourceRange ErrorRange, NoteRange; |
| 5408 | // Allowed constructs are: |
| 5409 | // x++; |
| 5410 | // x--; |
| 5411 | // ++x; |
| 5412 | // --x; |
| 5413 | // x binop= expr; |
| 5414 | // x = x binop expr; |
| 5415 | // x = expr binop x; |
| 5416 | if (auto *AtomicBody = dyn_cast<Expr>(S)) { |
| 5417 | AtomicBody = AtomicBody->IgnoreParenImpCasts(); |
| 5418 | if (AtomicBody->getType()->isScalarType() || |
| 5419 | AtomicBody->isInstantiationDependent()) { |
| 5420 | if (auto *AtomicCompAssignOp = dyn_cast<CompoundAssignOperator>( |
| 5421 | AtomicBody->IgnoreParenImpCasts())) { |
| 5422 | // Check for Compound Assignment Operation |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5423 | Op = BinaryOperator::getOpForCompoundAssignment( |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5424 | AtomicCompAssignOp->getOpcode()); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5425 | OpLoc = AtomicCompAssignOp->getOperatorLoc(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5426 | E = AtomicCompAssignOp->getRHS(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5427 | X = AtomicCompAssignOp->getLHS(); |
| 5428 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5429 | } else if (auto *AtomicBinOp = dyn_cast<BinaryOperator>( |
| 5430 | AtomicBody->IgnoreParenImpCasts())) { |
| 5431 | // Check for Binary Operation |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5432 | if(checkBinaryOperation(AtomicBinOp, DiagId, NoteId)) |
| 5433 | return true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5434 | } else if (auto *AtomicUnaryOp = |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5435 | dyn_cast<UnaryOperator>(AtomicBody->IgnoreParenImpCasts())) { |
| 5436 | // Check for Unary Operation |
| 5437 | if (AtomicUnaryOp->isIncrementDecrementOp()) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5438 | IsPostfixUpdate = AtomicUnaryOp->isPostfix(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5439 | Op = AtomicUnaryOp->isIncrementOp() ? BO_Add : BO_Sub; |
| 5440 | OpLoc = AtomicUnaryOp->getOperatorLoc(); |
| 5441 | X = AtomicUnaryOp->getSubExpr(); |
| 5442 | E = SemaRef.ActOnIntegerConstant(OpLoc, /*uint64_t Val=*/1).get(); |
| 5443 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5444 | } else { |
| 5445 | ErrorFound = NotAnUnaryIncDecExpression; |
| 5446 | ErrorLoc = AtomicUnaryOp->getExprLoc(); |
| 5447 | ErrorRange = AtomicUnaryOp->getSourceRange(); |
| 5448 | NoteLoc = AtomicUnaryOp->getOperatorLoc(); |
| 5449 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 5450 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5451 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5452 | ErrorFound = NotABinaryOrUnaryExpression; |
| 5453 | NoteLoc = ErrorLoc = AtomicBody->getExprLoc(); |
| 5454 | NoteRange = ErrorRange = AtomicBody->getSourceRange(); |
| 5455 | } |
| 5456 | } else { |
| 5457 | ErrorFound = NotAScalarType; |
| 5458 | NoteLoc = ErrorLoc = AtomicBody->getLocStart(); |
| 5459 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
| 5460 | } |
| 5461 | } else { |
| 5462 | ErrorFound = NotAnExpression; |
| 5463 | NoteLoc = ErrorLoc = S->getLocStart(); |
| 5464 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
| 5465 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5466 | if (ErrorFound != NoError && DiagId != 0 && NoteId != 0) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5467 | SemaRef.Diag(ErrorLoc, DiagId) << ErrorRange; |
| 5468 | SemaRef.Diag(NoteLoc, NoteId) << ErrorFound << NoteRange; |
| 5469 | return true; |
| 5470 | } else if (SemaRef.CurContext->isDependentContext()) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5471 | E = X = UpdateExpr = nullptr; |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5472 | if (ErrorFound == NoError && E && X) { |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5473 | // Build an update expression of form 'OpaqueValueExpr(x) binop |
| 5474 | // OpaqueValueExpr(expr)' or 'OpaqueValueExpr(expr) binop |
| 5475 | // OpaqueValueExpr(x)' and then cast it to the type of the 'x' expression. |
| 5476 | auto *OVEX = new (SemaRef.getASTContext()) |
| 5477 | OpaqueValueExpr(X->getExprLoc(), X->getType(), VK_RValue); |
| 5478 | auto *OVEExpr = new (SemaRef.getASTContext()) |
| 5479 | OpaqueValueExpr(E->getExprLoc(), E->getType(), VK_RValue); |
| 5480 | auto Update = |
| 5481 | SemaRef.CreateBuiltinBinOp(OpLoc, Op, IsXLHSInRHSPart ? OVEX : OVEExpr, |
| 5482 | IsXLHSInRHSPart ? OVEExpr : OVEX); |
| 5483 | if (Update.isInvalid()) |
| 5484 | return true; |
| 5485 | Update = SemaRef.PerformImplicitConversion(Update.get(), X->getType(), |
| 5486 | Sema::AA_Casting); |
| 5487 | if (Update.isInvalid()) |
| 5488 | return true; |
| 5489 | UpdateExpr = Update.get(); |
| 5490 | } |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5491 | return ErrorFound != NoError; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5492 | } |
| 5493 | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 5494 | StmtResult Sema::ActOnOpenMPAtomicDirective(ArrayRef<OMPClause *> Clauses, |
| 5495 | Stmt *AStmt, |
| 5496 | SourceLocation StartLoc, |
| 5497 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5498 | if (!AStmt) |
| 5499 | return StmtError(); |
| 5500 | |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5501 | auto CS = cast<CapturedStmt>(AStmt); |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 5502 | // 1.2.2 OpenMP Language Terminology |
| 5503 | // Structured block - An executable statement with a single entry at the |
| 5504 | // top and a single exit at the bottom. |
| 5505 | // The point of exit cannot be a branch out of the structured block. |
| 5506 | // longjmp() and throw() must not violate the entry/exit criteria. |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5507 | OpenMPClauseKind AtomicKind = OMPC_unknown; |
| 5508 | SourceLocation AtomicKindLoc; |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5509 | for (auto *C : Clauses) { |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5510 | if (C->getClauseKind() == OMPC_read || C->getClauseKind() == OMPC_write || |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5511 | C->getClauseKind() == OMPC_update || |
| 5512 | C->getClauseKind() == OMPC_capture) { |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5513 | if (AtomicKind != OMPC_unknown) { |
| 5514 | Diag(C->getLocStart(), diag::err_omp_atomic_several_clauses) |
| 5515 | << SourceRange(C->getLocStart(), C->getLocEnd()); |
| 5516 | Diag(AtomicKindLoc, diag::note_omp_atomic_previous_clause) |
| 5517 | << getOpenMPClauseName(AtomicKind); |
| 5518 | } else { |
| 5519 | AtomicKind = C->getClauseKind(); |
| 5520 | AtomicKindLoc = C->getLocStart(); |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5521 | } |
| 5522 | } |
| 5523 | } |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5524 | |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5525 | auto Body = CS->getCapturedStmt(); |
Alexey Bataev | 10fec57 | 2015-03-11 04:48:56 +0000 | [diff] [blame] | 5526 | if (auto *EWC = dyn_cast<ExprWithCleanups>(Body)) |
| 5527 | Body = EWC->getSubExpr(); |
| 5528 | |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5529 | Expr *X = nullptr; |
| 5530 | Expr *V = nullptr; |
| 5531 | Expr *E = nullptr; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5532 | Expr *UE = nullptr; |
| 5533 | bool IsXLHSInRHSPart = false; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5534 | bool IsPostfixUpdate = false; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5535 | // OpenMP [2.12.6, atomic Construct] |
| 5536 | // In the next expressions: |
| 5537 | // * x and v (as applicable) are both l-value expressions with scalar type. |
| 5538 | // * During the execution of an atomic region, multiple syntactic |
| 5539 | // occurrences of x must designate the same storage location. |
| 5540 | // * Neither of v and expr (as applicable) may access the storage location |
| 5541 | // designated by x. |
| 5542 | // * Neither of x and expr (as applicable) may access the storage location |
| 5543 | // designated by v. |
| 5544 | // * expr is an expression with scalar type. |
| 5545 | // * binop is one of +, *, -, /, &, ^, |, <<, or >>. |
| 5546 | // * binop, binop=, ++, and -- are not overloaded operators. |
| 5547 | // * The expression x binop expr must be numerically equivalent to x binop |
| 5548 | // (expr). This requirement is satisfied if the operators in expr have |
| 5549 | // precedence greater than binop, or by using parentheses around expr or |
| 5550 | // subexpressions of expr. |
| 5551 | // * The expression expr binop x must be numerically equivalent to (expr) |
| 5552 | // binop x. This requirement is satisfied if the operators in expr have |
| 5553 | // precedence equal to or greater than binop, or by using parentheses around |
| 5554 | // expr or subexpressions of expr. |
| 5555 | // * For forms that allow multiple occurrences of x, the number of times |
| 5556 | // that x is evaluated is unspecified. |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5557 | if (AtomicKind == OMPC_read) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5558 | enum { |
| 5559 | NotAnExpression, |
| 5560 | NotAnAssignmentOp, |
| 5561 | NotAScalarType, |
| 5562 | NotAnLValue, |
| 5563 | NoError |
| 5564 | } ErrorFound = NoError; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5565 | SourceLocation ErrorLoc, NoteLoc; |
| 5566 | SourceRange ErrorRange, NoteRange; |
| 5567 | // If clause is read: |
| 5568 | // v = x; |
| 5569 | if (auto AtomicBody = dyn_cast<Expr>(Body)) { |
| 5570 | auto AtomicBinOp = |
| 5571 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 5572 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
| 5573 | X = AtomicBinOp->getRHS()->IgnoreParenImpCasts(); |
| 5574 | V = AtomicBinOp->getLHS()->IgnoreParenImpCasts(); |
| 5575 | if ((X->isInstantiationDependent() || X->getType()->isScalarType()) && |
| 5576 | (V->isInstantiationDependent() || V->getType()->isScalarType())) { |
| 5577 | if (!X->isLValue() || !V->isLValue()) { |
| 5578 | auto NotLValueExpr = X->isLValue() ? V : X; |
| 5579 | ErrorFound = NotAnLValue; |
| 5580 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5581 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5582 | NoteLoc = NotLValueExpr->getExprLoc(); |
| 5583 | NoteRange = NotLValueExpr->getSourceRange(); |
| 5584 | } |
| 5585 | } else if (!X->isInstantiationDependent() || |
| 5586 | !V->isInstantiationDependent()) { |
| 5587 | auto NotScalarExpr = |
| 5588 | (X->isInstantiationDependent() || X->getType()->isScalarType()) |
| 5589 | ? V |
| 5590 | : X; |
| 5591 | ErrorFound = NotAScalarType; |
| 5592 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5593 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5594 | NoteLoc = NotScalarExpr->getExprLoc(); |
| 5595 | NoteRange = NotScalarExpr->getSourceRange(); |
| 5596 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5597 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5598 | ErrorFound = NotAnAssignmentOp; |
| 5599 | ErrorLoc = AtomicBody->getExprLoc(); |
| 5600 | ErrorRange = AtomicBody->getSourceRange(); |
| 5601 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 5602 | : AtomicBody->getExprLoc(); |
| 5603 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 5604 | : AtomicBody->getSourceRange(); |
| 5605 | } |
| 5606 | } else { |
| 5607 | ErrorFound = NotAnExpression; |
| 5608 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 5609 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5610 | } |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5611 | if (ErrorFound != NoError) { |
| 5612 | Diag(ErrorLoc, diag::err_omp_atomic_read_not_expression_statement) |
| 5613 | << ErrorRange; |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5614 | Diag(NoteLoc, diag::note_omp_atomic_read_write) << ErrorFound |
| 5615 | << NoteRange; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5616 | return StmtError(); |
| 5617 | } else if (CurContext->isDependentContext()) |
| 5618 | V = X = nullptr; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5619 | } else if (AtomicKind == OMPC_write) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5620 | enum { |
| 5621 | NotAnExpression, |
| 5622 | NotAnAssignmentOp, |
| 5623 | NotAScalarType, |
| 5624 | NotAnLValue, |
| 5625 | NoError |
| 5626 | } ErrorFound = NoError; |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5627 | SourceLocation ErrorLoc, NoteLoc; |
| 5628 | SourceRange ErrorRange, NoteRange; |
| 5629 | // If clause is write: |
| 5630 | // x = expr; |
| 5631 | if (auto AtomicBody = dyn_cast<Expr>(Body)) { |
| 5632 | auto AtomicBinOp = |
| 5633 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 5634 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
Alexey Bataev | b832926 | 2015-02-27 06:33:30 +0000 | [diff] [blame] | 5635 | X = AtomicBinOp->getLHS(); |
| 5636 | E = AtomicBinOp->getRHS(); |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5637 | if ((X->isInstantiationDependent() || X->getType()->isScalarType()) && |
| 5638 | (E->isInstantiationDependent() || E->getType()->isScalarType())) { |
| 5639 | if (!X->isLValue()) { |
| 5640 | ErrorFound = NotAnLValue; |
| 5641 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5642 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5643 | NoteLoc = X->getExprLoc(); |
| 5644 | NoteRange = X->getSourceRange(); |
| 5645 | } |
| 5646 | } else if (!X->isInstantiationDependent() || |
| 5647 | !E->isInstantiationDependent()) { |
| 5648 | auto NotScalarExpr = |
| 5649 | (X->isInstantiationDependent() || X->getType()->isScalarType()) |
| 5650 | ? E |
| 5651 | : X; |
| 5652 | ErrorFound = NotAScalarType; |
| 5653 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5654 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5655 | NoteLoc = NotScalarExpr->getExprLoc(); |
| 5656 | NoteRange = NotScalarExpr->getSourceRange(); |
| 5657 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5658 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5659 | ErrorFound = NotAnAssignmentOp; |
| 5660 | ErrorLoc = AtomicBody->getExprLoc(); |
| 5661 | ErrorRange = AtomicBody->getSourceRange(); |
| 5662 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 5663 | : AtomicBody->getExprLoc(); |
| 5664 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 5665 | : AtomicBody->getSourceRange(); |
| 5666 | } |
| 5667 | } else { |
| 5668 | ErrorFound = NotAnExpression; |
| 5669 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 5670 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5671 | } |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5672 | if (ErrorFound != NoError) { |
| 5673 | Diag(ErrorLoc, diag::err_omp_atomic_write_not_expression_statement) |
| 5674 | << ErrorRange; |
| 5675 | Diag(NoteLoc, diag::note_omp_atomic_read_write) << ErrorFound |
| 5676 | << NoteRange; |
| 5677 | return StmtError(); |
| 5678 | } else if (CurContext->isDependentContext()) |
| 5679 | E = X = nullptr; |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5680 | } else if (AtomicKind == OMPC_update || AtomicKind == OMPC_unknown) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5681 | // If clause is update: |
| 5682 | // x++; |
| 5683 | // x--; |
| 5684 | // ++x; |
| 5685 | // --x; |
| 5686 | // x binop= expr; |
| 5687 | // x = x binop expr; |
| 5688 | // x = expr binop x; |
| 5689 | OpenMPAtomicUpdateChecker Checker(*this); |
| 5690 | if (Checker.checkStatement( |
| 5691 | Body, (AtomicKind == OMPC_update) |
| 5692 | ? diag::err_omp_atomic_update_not_expression_statement |
| 5693 | : diag::err_omp_atomic_not_expression_statement, |
| 5694 | diag::note_omp_atomic_update)) |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5695 | return StmtError(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5696 | if (!CurContext->isDependentContext()) { |
| 5697 | E = Checker.getExpr(); |
| 5698 | X = Checker.getX(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5699 | UE = Checker.getUpdateExpr(); |
| 5700 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5701 | } |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5702 | } else if (AtomicKind == OMPC_capture) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5703 | enum { |
| 5704 | NotAnAssignmentOp, |
| 5705 | NotACompoundStatement, |
| 5706 | NotTwoSubstatements, |
| 5707 | NotASpecificExpression, |
| 5708 | NoError |
| 5709 | } ErrorFound = NoError; |
| 5710 | SourceLocation ErrorLoc, NoteLoc; |
| 5711 | SourceRange ErrorRange, NoteRange; |
| 5712 | if (auto *AtomicBody = dyn_cast<Expr>(Body)) { |
| 5713 | // If clause is a capture: |
| 5714 | // v = x++; |
| 5715 | // v = x--; |
| 5716 | // v = ++x; |
| 5717 | // v = --x; |
| 5718 | // v = x binop= expr; |
| 5719 | // v = x = x binop expr; |
| 5720 | // v = x = expr binop x; |
| 5721 | auto *AtomicBinOp = |
| 5722 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 5723 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
| 5724 | V = AtomicBinOp->getLHS(); |
| 5725 | Body = AtomicBinOp->getRHS()->IgnoreParenImpCasts(); |
| 5726 | OpenMPAtomicUpdateChecker Checker(*this); |
| 5727 | if (Checker.checkStatement( |
| 5728 | Body, diag::err_omp_atomic_capture_not_expression_statement, |
| 5729 | diag::note_omp_atomic_update)) |
| 5730 | return StmtError(); |
| 5731 | E = Checker.getExpr(); |
| 5732 | X = Checker.getX(); |
| 5733 | UE = Checker.getUpdateExpr(); |
| 5734 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
| 5735 | IsPostfixUpdate = Checker.isPostfixUpdate(); |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5736 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5737 | ErrorLoc = AtomicBody->getExprLoc(); |
| 5738 | ErrorRange = AtomicBody->getSourceRange(); |
| 5739 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 5740 | : AtomicBody->getExprLoc(); |
| 5741 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 5742 | : AtomicBody->getSourceRange(); |
| 5743 | ErrorFound = NotAnAssignmentOp; |
| 5744 | } |
| 5745 | if (ErrorFound != NoError) { |
| 5746 | Diag(ErrorLoc, diag::err_omp_atomic_capture_not_expression_statement) |
| 5747 | << ErrorRange; |
| 5748 | Diag(NoteLoc, diag::note_omp_atomic_capture) << ErrorFound << NoteRange; |
| 5749 | return StmtError(); |
| 5750 | } else if (CurContext->isDependentContext()) { |
| 5751 | UE = V = E = X = nullptr; |
| 5752 | } |
| 5753 | } else { |
| 5754 | // If clause is a capture: |
| 5755 | // { v = x; x = expr; } |
| 5756 | // { v = x; x++; } |
| 5757 | // { v = x; x--; } |
| 5758 | // { v = x; ++x; } |
| 5759 | // { v = x; --x; } |
| 5760 | // { v = x; x binop= expr; } |
| 5761 | // { v = x; x = x binop expr; } |
| 5762 | // { v = x; x = expr binop x; } |
| 5763 | // { x++; v = x; } |
| 5764 | // { x--; v = x; } |
| 5765 | // { ++x; v = x; } |
| 5766 | // { --x; v = x; } |
| 5767 | // { x binop= expr; v = x; } |
| 5768 | // { x = x binop expr; v = x; } |
| 5769 | // { x = expr binop x; v = x; } |
| 5770 | if (auto *CS = dyn_cast<CompoundStmt>(Body)) { |
| 5771 | // Check that this is { expr1; expr2; } |
| 5772 | if (CS->size() == 2) { |
| 5773 | auto *First = CS->body_front(); |
| 5774 | auto *Second = CS->body_back(); |
| 5775 | if (auto *EWC = dyn_cast<ExprWithCleanups>(First)) |
| 5776 | First = EWC->getSubExpr()->IgnoreParenImpCasts(); |
| 5777 | if (auto *EWC = dyn_cast<ExprWithCleanups>(Second)) |
| 5778 | Second = EWC->getSubExpr()->IgnoreParenImpCasts(); |
| 5779 | // Need to find what subexpression is 'v' and what is 'x'. |
| 5780 | OpenMPAtomicUpdateChecker Checker(*this); |
| 5781 | bool IsUpdateExprFound = !Checker.checkStatement(Second); |
| 5782 | BinaryOperator *BinOp = nullptr; |
| 5783 | if (IsUpdateExprFound) { |
| 5784 | BinOp = dyn_cast<BinaryOperator>(First); |
| 5785 | IsUpdateExprFound = BinOp && BinOp->getOpcode() == BO_Assign; |
| 5786 | } |
| 5787 | if (IsUpdateExprFound && !CurContext->isDependentContext()) { |
| 5788 | // { v = x; x++; } |
| 5789 | // { v = x; x--; } |
| 5790 | // { v = x; ++x; } |
| 5791 | // { v = x; --x; } |
| 5792 | // { v = x; x binop= expr; } |
| 5793 | // { v = x; x = x binop expr; } |
| 5794 | // { v = x; x = expr binop x; } |
| 5795 | // Check that the first expression has form v = x. |
| 5796 | auto *PossibleX = BinOp->getRHS()->IgnoreParenImpCasts(); |
| 5797 | llvm::FoldingSetNodeID XId, PossibleXId; |
| 5798 | Checker.getX()->Profile(XId, Context, /*Canonical=*/true); |
| 5799 | PossibleX->Profile(PossibleXId, Context, /*Canonical=*/true); |
| 5800 | IsUpdateExprFound = XId == PossibleXId; |
| 5801 | if (IsUpdateExprFound) { |
| 5802 | V = BinOp->getLHS(); |
| 5803 | X = Checker.getX(); |
| 5804 | E = Checker.getExpr(); |
| 5805 | UE = Checker.getUpdateExpr(); |
| 5806 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5807 | IsPostfixUpdate = true; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5808 | } |
| 5809 | } |
| 5810 | if (!IsUpdateExprFound) { |
| 5811 | IsUpdateExprFound = !Checker.checkStatement(First); |
| 5812 | BinOp = nullptr; |
| 5813 | if (IsUpdateExprFound) { |
| 5814 | BinOp = dyn_cast<BinaryOperator>(Second); |
| 5815 | IsUpdateExprFound = BinOp && BinOp->getOpcode() == BO_Assign; |
| 5816 | } |
| 5817 | if (IsUpdateExprFound && !CurContext->isDependentContext()) { |
| 5818 | // { x++; v = x; } |
| 5819 | // { x--; v = x; } |
| 5820 | // { ++x; v = x; } |
| 5821 | // { --x; v = x; } |
| 5822 | // { x binop= expr; v = x; } |
| 5823 | // { x = x binop expr; v = x; } |
| 5824 | // { x = expr binop x; v = x; } |
| 5825 | // Check that the second expression has form v = x. |
| 5826 | auto *PossibleX = BinOp->getRHS()->IgnoreParenImpCasts(); |
| 5827 | llvm::FoldingSetNodeID XId, PossibleXId; |
| 5828 | Checker.getX()->Profile(XId, Context, /*Canonical=*/true); |
| 5829 | PossibleX->Profile(PossibleXId, Context, /*Canonical=*/true); |
| 5830 | IsUpdateExprFound = XId == PossibleXId; |
| 5831 | if (IsUpdateExprFound) { |
| 5832 | V = BinOp->getLHS(); |
| 5833 | X = Checker.getX(); |
| 5834 | E = Checker.getExpr(); |
| 5835 | UE = Checker.getUpdateExpr(); |
| 5836 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5837 | IsPostfixUpdate = false; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5838 | } |
| 5839 | } |
| 5840 | } |
| 5841 | if (!IsUpdateExprFound) { |
| 5842 | // { v = x; x = expr; } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5843 | auto *FirstExpr = dyn_cast<Expr>(First); |
| 5844 | auto *SecondExpr = dyn_cast<Expr>(Second); |
| 5845 | if (!FirstExpr || !SecondExpr || |
| 5846 | !(FirstExpr->isInstantiationDependent() || |
| 5847 | SecondExpr->isInstantiationDependent())) { |
| 5848 | auto *FirstBinOp = dyn_cast<BinaryOperator>(First); |
| 5849 | if (!FirstBinOp || FirstBinOp->getOpcode() != BO_Assign) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5850 | ErrorFound = NotAnAssignmentOp; |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5851 | NoteLoc = ErrorLoc = FirstBinOp ? FirstBinOp->getOperatorLoc() |
| 5852 | : First->getLocStart(); |
| 5853 | NoteRange = ErrorRange = FirstBinOp |
| 5854 | ? FirstBinOp->getSourceRange() |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5855 | : SourceRange(ErrorLoc, ErrorLoc); |
| 5856 | } else { |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5857 | auto *SecondBinOp = dyn_cast<BinaryOperator>(Second); |
| 5858 | if (!SecondBinOp || SecondBinOp->getOpcode() != BO_Assign) { |
| 5859 | ErrorFound = NotAnAssignmentOp; |
| 5860 | NoteLoc = ErrorLoc = SecondBinOp |
| 5861 | ? SecondBinOp->getOperatorLoc() |
| 5862 | : Second->getLocStart(); |
| 5863 | NoteRange = ErrorRange = |
| 5864 | SecondBinOp ? SecondBinOp->getSourceRange() |
| 5865 | : SourceRange(ErrorLoc, ErrorLoc); |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5866 | } else { |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5867 | auto *PossibleXRHSInFirst = |
| 5868 | FirstBinOp->getRHS()->IgnoreParenImpCasts(); |
| 5869 | auto *PossibleXLHSInSecond = |
| 5870 | SecondBinOp->getLHS()->IgnoreParenImpCasts(); |
| 5871 | llvm::FoldingSetNodeID X1Id, X2Id; |
| 5872 | PossibleXRHSInFirst->Profile(X1Id, Context, |
| 5873 | /*Canonical=*/true); |
| 5874 | PossibleXLHSInSecond->Profile(X2Id, Context, |
| 5875 | /*Canonical=*/true); |
| 5876 | IsUpdateExprFound = X1Id == X2Id; |
| 5877 | if (IsUpdateExprFound) { |
| 5878 | V = FirstBinOp->getLHS(); |
| 5879 | X = SecondBinOp->getLHS(); |
| 5880 | E = SecondBinOp->getRHS(); |
| 5881 | UE = nullptr; |
| 5882 | IsXLHSInRHSPart = false; |
| 5883 | IsPostfixUpdate = true; |
| 5884 | } else { |
| 5885 | ErrorFound = NotASpecificExpression; |
| 5886 | ErrorLoc = FirstBinOp->getExprLoc(); |
| 5887 | ErrorRange = FirstBinOp->getSourceRange(); |
| 5888 | NoteLoc = SecondBinOp->getLHS()->getExprLoc(); |
| 5889 | NoteRange = SecondBinOp->getRHS()->getSourceRange(); |
| 5890 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5891 | } |
| 5892 | } |
| 5893 | } |
| 5894 | } |
| 5895 | } else { |
| 5896 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 5897 | NoteRange = ErrorRange = |
| 5898 | SourceRange(Body->getLocStart(), Body->getLocStart()); |
| 5899 | ErrorFound = NotTwoSubstatements; |
| 5900 | } |
| 5901 | } else { |
| 5902 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 5903 | NoteRange = ErrorRange = |
| 5904 | SourceRange(Body->getLocStart(), Body->getLocStart()); |
| 5905 | ErrorFound = NotACompoundStatement; |
| 5906 | } |
| 5907 | if (ErrorFound != NoError) { |
| 5908 | Diag(ErrorLoc, diag::err_omp_atomic_capture_not_compound_statement) |
| 5909 | << ErrorRange; |
| 5910 | Diag(NoteLoc, diag::note_omp_atomic_capture) << ErrorFound << NoteRange; |
| 5911 | return StmtError(); |
| 5912 | } else if (CurContext->isDependentContext()) { |
| 5913 | UE = V = E = X = nullptr; |
| 5914 | } |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5915 | } |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5916 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 5917 | |
| 5918 | getCurFunction()->setHasBranchProtectedScope(); |
| 5919 | |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5920 | return OMPAtomicDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5921 | X, V, E, UE, IsXLHSInRHSPart, |
| 5922 | IsPostfixUpdate); |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 5923 | } |
| 5924 | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 5925 | StmtResult Sema::ActOnOpenMPTargetDirective(ArrayRef<OMPClause *> Clauses, |
| 5926 | Stmt *AStmt, |
| 5927 | SourceLocation StartLoc, |
| 5928 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5929 | if (!AStmt) |
| 5930 | return StmtError(); |
| 5931 | |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 5932 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 5933 | // 1.2.2 OpenMP Language Terminology |
| 5934 | // Structured block - An executable statement with a single entry at the |
| 5935 | // top and a single exit at the bottom. |
| 5936 | // The point of exit cannot be a branch out of the structured block. |
| 5937 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5938 | CS->getCapturedDecl()->setNothrow(); |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 5939 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 5940 | // OpenMP [2.16, Nesting of Regions] |
| 5941 | // If specified, a teams construct must be contained within a target |
| 5942 | // construct. That target construct must contain no statements or directives |
| 5943 | // outside of the teams construct. |
| 5944 | if (DSAStack->hasInnerTeamsRegion()) { |
| 5945 | auto S = AStmt->IgnoreContainers(/*IgnoreCaptured*/ true); |
| 5946 | bool OMPTeamsFound = true; |
| 5947 | if (auto *CS = dyn_cast<CompoundStmt>(S)) { |
| 5948 | auto I = CS->body_begin(); |
| 5949 | while (I != CS->body_end()) { |
| 5950 | auto OED = dyn_cast<OMPExecutableDirective>(*I); |
| 5951 | if (!OED || !isOpenMPTeamsDirective(OED->getDirectiveKind())) { |
| 5952 | OMPTeamsFound = false; |
| 5953 | break; |
| 5954 | } |
| 5955 | ++I; |
| 5956 | } |
| 5957 | assert(I != CS->body_end() && "Not found statement"); |
| 5958 | S = *I; |
| 5959 | } |
| 5960 | if (!OMPTeamsFound) { |
| 5961 | Diag(StartLoc, diag::err_omp_target_contains_not_only_teams); |
| 5962 | Diag(DSAStack->getInnerTeamsRegionLoc(), |
| 5963 | diag::note_omp_nested_teams_construct_here); |
| 5964 | Diag(S->getLocStart(), diag::note_omp_nested_statement_here) |
| 5965 | << isa<OMPExecutableDirective>(S); |
| 5966 | return StmtError(); |
| 5967 | } |
| 5968 | } |
| 5969 | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 5970 | getCurFunction()->setHasBranchProtectedScope(); |
| 5971 | |
| 5972 | return OMPTargetDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 5973 | } |
| 5974 | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 5975 | StmtResult |
| 5976 | Sema::ActOnOpenMPTargetParallelDirective(ArrayRef<OMPClause *> Clauses, |
| 5977 | Stmt *AStmt, SourceLocation StartLoc, |
| 5978 | SourceLocation EndLoc) { |
| 5979 | if (!AStmt) |
| 5980 | return StmtError(); |
| 5981 | |
| 5982 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 5983 | // 1.2.2 OpenMP Language Terminology |
| 5984 | // Structured block - An executable statement with a single entry at the |
| 5985 | // top and a single exit at the bottom. |
| 5986 | // The point of exit cannot be a branch out of the structured block. |
| 5987 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5988 | CS->getCapturedDecl()->setNothrow(); |
| 5989 | |
| 5990 | getCurFunction()->setHasBranchProtectedScope(); |
| 5991 | |
| 5992 | return OMPTargetParallelDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 5993 | AStmt); |
| 5994 | } |
| 5995 | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 5996 | StmtResult Sema::ActOnOpenMPTargetParallelForDirective( |
| 5997 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 5998 | SourceLocation EndLoc, |
| 5999 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 6000 | if (!AStmt) |
| 6001 | return StmtError(); |
| 6002 | |
| 6003 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6004 | // 1.2.2 OpenMP Language Terminology |
| 6005 | // Structured block - An executable statement with a single entry at the |
| 6006 | // top and a single exit at the bottom. |
| 6007 | // The point of exit cannot be a branch out of the structured block. |
| 6008 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6009 | CS->getCapturedDecl()->setNothrow(); |
| 6010 | |
| 6011 | OMPLoopDirective::HelperExprs B; |
| 6012 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 6013 | // define the nested loops number. |
| 6014 | unsigned NestedLoopCount = |
| 6015 | CheckOpenMPLoop(OMPD_target_parallel_for, getCollapseNumberExpr(Clauses), |
| 6016 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 6017 | VarsWithImplicitDSA, B); |
| 6018 | if (NestedLoopCount == 0) |
| 6019 | return StmtError(); |
| 6020 | |
| 6021 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6022 | "omp target parallel for loop exprs were not built"); |
| 6023 | |
| 6024 | if (!CurContext->isDependentContext()) { |
| 6025 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 6026 | for (auto C : Clauses) { |
| 6027 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 6028 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 6029 | B.NumIterations, *this, CurScope)) |
| 6030 | return StmtError(); |
| 6031 | } |
| 6032 | } |
| 6033 | |
| 6034 | getCurFunction()->setHasBranchProtectedScope(); |
| 6035 | return OMPTargetParallelForDirective::Create(Context, StartLoc, EndLoc, |
| 6036 | NestedLoopCount, Clauses, AStmt, |
| 6037 | B, DSAStack->isCancelRegion()); |
| 6038 | } |
| 6039 | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 6040 | /// \brief Check for existence of a map clause in the list of clauses. |
| 6041 | static bool HasMapClause(ArrayRef<OMPClause *> Clauses) { |
| 6042 | for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end(); |
| 6043 | I != E; ++I) { |
| 6044 | if (*I != nullptr && (*I)->getClauseKind() == OMPC_map) { |
| 6045 | return true; |
| 6046 | } |
| 6047 | } |
| 6048 | |
| 6049 | return false; |
| 6050 | } |
| 6051 | |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 6052 | StmtResult Sema::ActOnOpenMPTargetDataDirective(ArrayRef<OMPClause *> Clauses, |
| 6053 | Stmt *AStmt, |
| 6054 | SourceLocation StartLoc, |
| 6055 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6056 | if (!AStmt) |
| 6057 | return StmtError(); |
| 6058 | |
| 6059 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 6060 | |
Arpith Chacko Jacob | 46a04bb | 2016-01-21 19:57:55 +0000 | [diff] [blame] | 6061 | // OpenMP [2.10.1, Restrictions, p. 97] |
| 6062 | // At least one map clause must appear on the directive. |
| 6063 | if (!HasMapClause(Clauses)) { |
| 6064 | Diag(StartLoc, diag::err_omp_no_map_for_directive) << |
| 6065 | getOpenMPDirectiveName(OMPD_target_data); |
| 6066 | return StmtError(); |
| 6067 | } |
| 6068 | |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 6069 | getCurFunction()->setHasBranchProtectedScope(); |
| 6070 | |
| 6071 | return OMPTargetDataDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 6072 | AStmt); |
| 6073 | } |
| 6074 | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 6075 | StmtResult |
| 6076 | Sema::ActOnOpenMPTargetEnterDataDirective(ArrayRef<OMPClause *> Clauses, |
| 6077 | SourceLocation StartLoc, |
| 6078 | SourceLocation EndLoc) { |
| 6079 | // OpenMP [2.10.2, Restrictions, p. 99] |
| 6080 | // At least one map clause must appear on the directive. |
| 6081 | if (!HasMapClause(Clauses)) { |
| 6082 | Diag(StartLoc, diag::err_omp_no_map_for_directive) |
| 6083 | << getOpenMPDirectiveName(OMPD_target_enter_data); |
| 6084 | return StmtError(); |
| 6085 | } |
| 6086 | |
| 6087 | return OMPTargetEnterDataDirective::Create(Context, StartLoc, EndLoc, |
| 6088 | Clauses); |
| 6089 | } |
| 6090 | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 6091 | StmtResult |
| 6092 | Sema::ActOnOpenMPTargetExitDataDirective(ArrayRef<OMPClause *> Clauses, |
| 6093 | SourceLocation StartLoc, |
| 6094 | SourceLocation EndLoc) { |
| 6095 | // OpenMP [2.10.3, Restrictions, p. 102] |
| 6096 | // At least one map clause must appear on the directive. |
| 6097 | if (!HasMapClause(Clauses)) { |
| 6098 | Diag(StartLoc, diag::err_omp_no_map_for_directive) |
| 6099 | << getOpenMPDirectiveName(OMPD_target_exit_data); |
| 6100 | return StmtError(); |
| 6101 | } |
| 6102 | |
| 6103 | return OMPTargetExitDataDirective::Create(Context, StartLoc, EndLoc, Clauses); |
| 6104 | } |
| 6105 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 6106 | StmtResult Sema::ActOnOpenMPTeamsDirective(ArrayRef<OMPClause *> Clauses, |
| 6107 | Stmt *AStmt, SourceLocation StartLoc, |
| 6108 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6109 | if (!AStmt) |
| 6110 | return StmtError(); |
| 6111 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 6112 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6113 | // 1.2.2 OpenMP Language Terminology |
| 6114 | // Structured block - An executable statement with a single entry at the |
| 6115 | // top and a single exit at the bottom. |
| 6116 | // The point of exit cannot be a branch out of the structured block. |
| 6117 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6118 | CS->getCapturedDecl()->setNothrow(); |
| 6119 | |
| 6120 | getCurFunction()->setHasBranchProtectedScope(); |
| 6121 | |
| 6122 | return OMPTeamsDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 6123 | } |
| 6124 | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 6125 | StmtResult |
| 6126 | Sema::ActOnOpenMPCancellationPointDirective(SourceLocation StartLoc, |
| 6127 | SourceLocation EndLoc, |
| 6128 | OpenMPDirectiveKind CancelRegion) { |
| 6129 | if (CancelRegion != OMPD_parallel && CancelRegion != OMPD_for && |
| 6130 | CancelRegion != OMPD_sections && CancelRegion != OMPD_taskgroup) { |
| 6131 | Diag(StartLoc, diag::err_omp_wrong_cancel_region) |
| 6132 | << getOpenMPDirectiveName(CancelRegion); |
| 6133 | return StmtError(); |
| 6134 | } |
| 6135 | if (DSAStack->isParentNowaitRegion()) { |
| 6136 | Diag(StartLoc, diag::err_omp_parent_cancel_region_nowait) << 0; |
| 6137 | return StmtError(); |
| 6138 | } |
| 6139 | if (DSAStack->isParentOrderedRegion()) { |
| 6140 | Diag(StartLoc, diag::err_omp_parent_cancel_region_ordered) << 0; |
| 6141 | return StmtError(); |
| 6142 | } |
| 6143 | return OMPCancellationPointDirective::Create(Context, StartLoc, EndLoc, |
| 6144 | CancelRegion); |
| 6145 | } |
| 6146 | |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 6147 | StmtResult Sema::ActOnOpenMPCancelDirective(ArrayRef<OMPClause *> Clauses, |
| 6148 | SourceLocation StartLoc, |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 6149 | SourceLocation EndLoc, |
| 6150 | OpenMPDirectiveKind CancelRegion) { |
| 6151 | if (CancelRegion != OMPD_parallel && CancelRegion != OMPD_for && |
| 6152 | CancelRegion != OMPD_sections && CancelRegion != OMPD_taskgroup) { |
| 6153 | Diag(StartLoc, diag::err_omp_wrong_cancel_region) |
| 6154 | << getOpenMPDirectiveName(CancelRegion); |
| 6155 | return StmtError(); |
| 6156 | } |
| 6157 | if (DSAStack->isParentNowaitRegion()) { |
| 6158 | Diag(StartLoc, diag::err_omp_parent_cancel_region_nowait) << 1; |
| 6159 | return StmtError(); |
| 6160 | } |
| 6161 | if (DSAStack->isParentOrderedRegion()) { |
| 6162 | Diag(StartLoc, diag::err_omp_parent_cancel_region_ordered) << 1; |
| 6163 | return StmtError(); |
| 6164 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 6165 | DSAStack->setParentCancelRegion(/*Cancel=*/true); |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 6166 | return OMPCancelDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 6167 | CancelRegion); |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 6168 | } |
| 6169 | |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6170 | static bool checkGrainsizeNumTasksClauses(Sema &S, |
| 6171 | ArrayRef<OMPClause *> Clauses) { |
| 6172 | OMPClause *PrevClause = nullptr; |
| 6173 | bool ErrorFound = false; |
| 6174 | for (auto *C : Clauses) { |
| 6175 | if (C->getClauseKind() == OMPC_grainsize || |
| 6176 | C->getClauseKind() == OMPC_num_tasks) { |
| 6177 | if (!PrevClause) |
| 6178 | PrevClause = C; |
| 6179 | else if (PrevClause->getClauseKind() != C->getClauseKind()) { |
| 6180 | S.Diag(C->getLocStart(), |
| 6181 | diag::err_omp_grainsize_num_tasks_mutually_exclusive) |
| 6182 | << getOpenMPClauseName(C->getClauseKind()) |
| 6183 | << getOpenMPClauseName(PrevClause->getClauseKind()); |
| 6184 | S.Diag(PrevClause->getLocStart(), |
| 6185 | diag::note_omp_previous_grainsize_num_tasks) |
| 6186 | << getOpenMPClauseName(PrevClause->getClauseKind()); |
| 6187 | ErrorFound = true; |
| 6188 | } |
| 6189 | } |
| 6190 | } |
| 6191 | return ErrorFound; |
| 6192 | } |
| 6193 | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 6194 | StmtResult Sema::ActOnOpenMPTaskLoopDirective( |
| 6195 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6196 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 6197 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 6198 | if (!AStmt) |
| 6199 | return StmtError(); |
| 6200 | |
| 6201 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 6202 | OMPLoopDirective::HelperExprs B; |
| 6203 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 6204 | // define the nested loops number. |
| 6205 | unsigned NestedLoopCount = |
| 6206 | CheckOpenMPLoop(OMPD_taskloop, getCollapseNumberExpr(Clauses), |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 6207 | /*OrderedLoopCountExpr=*/nullptr, AStmt, *this, *DSAStack, |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 6208 | VarsWithImplicitDSA, B); |
| 6209 | if (NestedLoopCount == 0) |
| 6210 | return StmtError(); |
| 6211 | |
| 6212 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6213 | "omp for loop exprs were not built"); |
| 6214 | |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6215 | // OpenMP, [2.9.2 taskloop Construct, Restrictions] |
| 6216 | // The grainsize clause and num_tasks clause are mutually exclusive and may |
| 6217 | // not appear on the same taskloop directive. |
| 6218 | if (checkGrainsizeNumTasksClauses(*this, Clauses)) |
| 6219 | return StmtError(); |
| 6220 | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 6221 | getCurFunction()->setHasBranchProtectedScope(); |
| 6222 | return OMPTaskLoopDirective::Create(Context, StartLoc, EndLoc, |
| 6223 | NestedLoopCount, Clauses, AStmt, B); |
| 6224 | } |
| 6225 | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 6226 | StmtResult Sema::ActOnOpenMPTaskLoopSimdDirective( |
| 6227 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6228 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 6229 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 6230 | if (!AStmt) |
| 6231 | return StmtError(); |
| 6232 | |
| 6233 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 6234 | OMPLoopDirective::HelperExprs B; |
| 6235 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 6236 | // define the nested loops number. |
| 6237 | unsigned NestedLoopCount = |
| 6238 | CheckOpenMPLoop(OMPD_taskloop_simd, getCollapseNumberExpr(Clauses), |
| 6239 | /*OrderedLoopCountExpr=*/nullptr, AStmt, *this, *DSAStack, |
| 6240 | VarsWithImplicitDSA, B); |
| 6241 | if (NestedLoopCount == 0) |
| 6242 | return StmtError(); |
| 6243 | |
| 6244 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6245 | "omp for loop exprs were not built"); |
| 6246 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 6247 | if (!CurContext->isDependentContext()) { |
| 6248 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 6249 | for (auto C : Clauses) { |
| 6250 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 6251 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 6252 | B.NumIterations, *this, CurScope)) |
| 6253 | return StmtError(); |
| 6254 | } |
| 6255 | } |
| 6256 | |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6257 | // OpenMP, [2.9.2 taskloop Construct, Restrictions] |
| 6258 | // The grainsize clause and num_tasks clause are mutually exclusive and may |
| 6259 | // not appear on the same taskloop directive. |
| 6260 | if (checkGrainsizeNumTasksClauses(*this, Clauses)) |
| 6261 | return StmtError(); |
| 6262 | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 6263 | getCurFunction()->setHasBranchProtectedScope(); |
| 6264 | return OMPTaskLoopSimdDirective::Create(Context, StartLoc, EndLoc, |
| 6265 | NestedLoopCount, Clauses, AStmt, B); |
| 6266 | } |
| 6267 | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 6268 | StmtResult Sema::ActOnOpenMPDistributeDirective( |
| 6269 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6270 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 6271 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 6272 | if (!AStmt) |
| 6273 | return StmtError(); |
| 6274 | |
| 6275 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 6276 | OMPLoopDirective::HelperExprs B; |
| 6277 | // In presence of clause 'collapse' with number of loops, it will |
| 6278 | // define the nested loops number. |
| 6279 | unsigned NestedLoopCount = |
| 6280 | CheckOpenMPLoop(OMPD_distribute, getCollapseNumberExpr(Clauses), |
| 6281 | nullptr /*ordered not a clause on distribute*/, AStmt, |
| 6282 | *this, *DSAStack, VarsWithImplicitDSA, B); |
| 6283 | if (NestedLoopCount == 0) |
| 6284 | return StmtError(); |
| 6285 | |
| 6286 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6287 | "omp for loop exprs were not built"); |
| 6288 | |
| 6289 | getCurFunction()->setHasBranchProtectedScope(); |
| 6290 | return OMPDistributeDirective::Create(Context, StartLoc, EndLoc, |
| 6291 | NestedLoopCount, Clauses, AStmt, B); |
| 6292 | } |
| 6293 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6294 | OMPClause *Sema::ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, Expr *Expr, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6295 | SourceLocation StartLoc, |
| 6296 | SourceLocation LParenLoc, |
| 6297 | SourceLocation EndLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6298 | OMPClause *Res = nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6299 | switch (Kind) { |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 6300 | case OMPC_final: |
| 6301 | Res = ActOnOpenMPFinalClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6302 | break; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6303 | case OMPC_num_threads: |
| 6304 | Res = ActOnOpenMPNumThreadsClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6305 | break; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6306 | case OMPC_safelen: |
| 6307 | Res = ActOnOpenMPSafelenClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6308 | break; |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 6309 | case OMPC_simdlen: |
| 6310 | Res = ActOnOpenMPSimdlenClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6311 | break; |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6312 | case OMPC_collapse: |
| 6313 | Res = ActOnOpenMPCollapseClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6314 | break; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 6315 | case OMPC_ordered: |
| 6316 | Res = ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Expr); |
| 6317 | break; |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 6318 | case OMPC_device: |
| 6319 | Res = ActOnOpenMPDeviceClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6320 | break; |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 6321 | case OMPC_num_teams: |
| 6322 | Res = ActOnOpenMPNumTeamsClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6323 | break; |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6324 | case OMPC_thread_limit: |
| 6325 | Res = ActOnOpenMPThreadLimitClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6326 | break; |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6327 | case OMPC_priority: |
| 6328 | Res = ActOnOpenMPPriorityClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6329 | break; |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 6330 | case OMPC_grainsize: |
| 6331 | Res = ActOnOpenMPGrainsizeClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6332 | break; |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6333 | case OMPC_num_tasks: |
| 6334 | Res = ActOnOpenMPNumTasksClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6335 | break; |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 6336 | case OMPC_hint: |
| 6337 | Res = ActOnOpenMPHintClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6338 | break; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6339 | case OMPC_if: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6340 | case OMPC_default: |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6341 | case OMPC_proc_bind: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6342 | case OMPC_schedule: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6343 | case OMPC_private: |
| 6344 | case OMPC_firstprivate: |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6345 | case OMPC_lastprivate: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6346 | case OMPC_shared: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6347 | case OMPC_reduction: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6348 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 6349 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6350 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6351 | case OMPC_copyprivate: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6352 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 6353 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 6354 | case OMPC_mergeable: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6355 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 6356 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6357 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6358 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6359 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6360 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 6361 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6362 | case OMPC_depend: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6363 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6364 | case OMPC_simd: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 6365 | case OMPC_map: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 6366 | case OMPC_nogroup: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 6367 | case OMPC_dist_schedule: |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 6368 | case OMPC_defaultmap: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6369 | case OMPC_unknown: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6370 | llvm_unreachable("Clause is not allowed."); |
| 6371 | } |
| 6372 | return Res; |
| 6373 | } |
| 6374 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6375 | OMPClause *Sema::ActOnOpenMPIfClause(OpenMPDirectiveKind NameModifier, |
| 6376 | Expr *Condition, SourceLocation StartLoc, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6377 | SourceLocation LParenLoc, |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6378 | SourceLocation NameModifierLoc, |
| 6379 | SourceLocation ColonLoc, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6380 | SourceLocation EndLoc) { |
| 6381 | Expr *ValExpr = Condition; |
| 6382 | if (!Condition->isValueDependent() && !Condition->isTypeDependent() && |
| 6383 | !Condition->isInstantiationDependent() && |
| 6384 | !Condition->containsUnexpandedParameterPack()) { |
| 6385 | ExprResult Val = ActOnBooleanCondition(DSAStack->getCurScope(), |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6386 | Condition->getExprLoc(), Condition); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6387 | if (Val.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6388 | return nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6389 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6390 | ValExpr = Val.get(); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6391 | } |
| 6392 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6393 | return new (Context) OMPIfClause(NameModifier, ValExpr, StartLoc, LParenLoc, |
| 6394 | NameModifierLoc, ColonLoc, EndLoc); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6395 | } |
| 6396 | |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 6397 | OMPClause *Sema::ActOnOpenMPFinalClause(Expr *Condition, |
| 6398 | SourceLocation StartLoc, |
| 6399 | SourceLocation LParenLoc, |
| 6400 | SourceLocation EndLoc) { |
| 6401 | Expr *ValExpr = Condition; |
| 6402 | if (!Condition->isValueDependent() && !Condition->isTypeDependent() && |
| 6403 | !Condition->isInstantiationDependent() && |
| 6404 | !Condition->containsUnexpandedParameterPack()) { |
| 6405 | ExprResult Val = ActOnBooleanCondition(DSAStack->getCurScope(), |
| 6406 | Condition->getExprLoc(), Condition); |
| 6407 | if (Val.isInvalid()) |
| 6408 | return nullptr; |
| 6409 | |
| 6410 | ValExpr = Val.get(); |
| 6411 | } |
| 6412 | |
| 6413 | return new (Context) OMPFinalClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 6414 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 6415 | ExprResult Sema::PerformOpenMPImplicitIntegerConversion(SourceLocation Loc, |
| 6416 | Expr *Op) { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6417 | if (!Op) |
| 6418 | return ExprError(); |
| 6419 | |
| 6420 | class IntConvertDiagnoser : public ICEConvertDiagnoser { |
| 6421 | public: |
| 6422 | IntConvertDiagnoser() |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6423 | : ICEConvertDiagnoser(/*AllowScopedEnumerations*/ false, false, true) {} |
Craig Topper | e14c0f8 | 2014-03-12 04:55:44 +0000 | [diff] [blame] | 6424 | SemaDiagnosticBuilder diagnoseNotInt(Sema &S, SourceLocation Loc, |
| 6425 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6426 | return S.Diag(Loc, diag::err_omp_not_integral) << T; |
| 6427 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6428 | SemaDiagnosticBuilder diagnoseIncomplete(Sema &S, SourceLocation Loc, |
| 6429 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6430 | return S.Diag(Loc, diag::err_omp_incomplete_type) << T; |
| 6431 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6432 | SemaDiagnosticBuilder diagnoseExplicitConv(Sema &S, SourceLocation Loc, |
| 6433 | QualType T, |
| 6434 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6435 | return S.Diag(Loc, diag::err_omp_explicit_conversion) << T << ConvTy; |
| 6436 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6437 | SemaDiagnosticBuilder noteExplicitConv(Sema &S, CXXConversionDecl *Conv, |
| 6438 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6439 | return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6440 | << ConvTy->isEnumeralType() << ConvTy; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6441 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6442 | SemaDiagnosticBuilder diagnoseAmbiguous(Sema &S, SourceLocation Loc, |
| 6443 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6444 | return S.Diag(Loc, diag::err_omp_ambiguous_conversion) << T; |
| 6445 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6446 | SemaDiagnosticBuilder noteAmbiguous(Sema &S, CXXConversionDecl *Conv, |
| 6447 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6448 | return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6449 | << ConvTy->isEnumeralType() << ConvTy; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6450 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6451 | SemaDiagnosticBuilder diagnoseConversion(Sema &, SourceLocation, QualType, |
| 6452 | QualType) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6453 | llvm_unreachable("conversion functions are permitted"); |
| 6454 | } |
| 6455 | } ConvertDiagnoser; |
| 6456 | return PerformContextualImplicitConversion(Loc, Op, ConvertDiagnoser); |
| 6457 | } |
| 6458 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6459 | static bool IsNonNegativeIntegerValue(Expr *&ValExpr, Sema &SemaRef, |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6460 | OpenMPClauseKind CKind, |
| 6461 | bool StrictlyPositive) { |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6462 | if (!ValExpr->isTypeDependent() && !ValExpr->isValueDependent() && |
| 6463 | !ValExpr->isInstantiationDependent()) { |
| 6464 | SourceLocation Loc = ValExpr->getExprLoc(); |
| 6465 | ExprResult Value = |
| 6466 | SemaRef.PerformOpenMPImplicitIntegerConversion(Loc, ValExpr); |
| 6467 | if (Value.isInvalid()) |
| 6468 | return false; |
| 6469 | |
| 6470 | ValExpr = Value.get(); |
| 6471 | // The expression must evaluate to a non-negative integer value. |
| 6472 | llvm::APSInt Result; |
| 6473 | if (ValExpr->isIntegerConstantExpr(Result, SemaRef.Context) && |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6474 | Result.isSigned() && |
| 6475 | !((!StrictlyPositive && Result.isNonNegative()) || |
| 6476 | (StrictlyPositive && Result.isStrictlyPositive()))) { |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6477 | SemaRef.Diag(Loc, diag::err_omp_negative_expression_in_clause) |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6478 | << getOpenMPClauseName(CKind) << (StrictlyPositive ? 1 : 0) |
| 6479 | << ValExpr->getSourceRange(); |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6480 | return false; |
| 6481 | } |
| 6482 | } |
| 6483 | return true; |
| 6484 | } |
| 6485 | |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6486 | OMPClause *Sema::ActOnOpenMPNumThreadsClause(Expr *NumThreads, |
| 6487 | SourceLocation StartLoc, |
| 6488 | SourceLocation LParenLoc, |
| 6489 | SourceLocation EndLoc) { |
| 6490 | Expr *ValExpr = NumThreads; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6491 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6492 | // OpenMP [2.5, Restrictions] |
| 6493 | // The num_threads expression must evaluate to a positive integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6494 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_num_threads, |
| 6495 | /*StrictlyPositive=*/true)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6496 | return nullptr; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6497 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6498 | return new (Context) |
| 6499 | OMPNumThreadsClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6500 | } |
| 6501 | |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6502 | ExprResult Sema::VerifyPositiveIntegerConstantInClause(Expr *E, |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 6503 | OpenMPClauseKind CKind, |
| 6504 | bool StrictlyPositive) { |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6505 | if (!E) |
| 6506 | return ExprError(); |
| 6507 | if (E->isValueDependent() || E->isTypeDependent() || |
| 6508 | E->isInstantiationDependent() || E->containsUnexpandedParameterPack()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6509 | return E; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6510 | llvm::APSInt Result; |
| 6511 | ExprResult ICE = VerifyIntegerConstantExpression(E, &Result); |
| 6512 | if (ICE.isInvalid()) |
| 6513 | return ExprError(); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 6514 | if ((StrictlyPositive && !Result.isStrictlyPositive()) || |
| 6515 | (!StrictlyPositive && !Result.isNonNegative())) { |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6516 | Diag(E->getExprLoc(), diag::err_omp_negative_expression_in_clause) |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 6517 | << getOpenMPClauseName(CKind) << (StrictlyPositive ? 1 : 0) |
| 6518 | << E->getSourceRange(); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6519 | return ExprError(); |
| 6520 | } |
Alexander Musman | 09184fe | 2014-09-30 05:29:28 +0000 | [diff] [blame] | 6521 | if (CKind == OMPC_aligned && !Result.isPowerOf2()) { |
| 6522 | Diag(E->getExprLoc(), diag::warn_omp_alignment_not_power_of_two) |
| 6523 | << E->getSourceRange(); |
| 6524 | return ExprError(); |
| 6525 | } |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 6526 | if (CKind == OMPC_collapse && DSAStack->getAssociatedLoops() == 1) |
| 6527 | DSAStack->setAssociatedLoops(Result.getExtValue()); |
Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 6528 | else if (CKind == OMPC_ordered) |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 6529 | DSAStack->setAssociatedLoops(Result.getExtValue()); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6530 | return ICE; |
| 6531 | } |
| 6532 | |
| 6533 | OMPClause *Sema::ActOnOpenMPSafelenClause(Expr *Len, SourceLocation StartLoc, |
| 6534 | SourceLocation LParenLoc, |
| 6535 | SourceLocation EndLoc) { |
| 6536 | // OpenMP [2.8.1, simd construct, Description] |
| 6537 | // The parameter of the safelen clause must be a constant |
| 6538 | // positive integer expression. |
| 6539 | ExprResult Safelen = VerifyPositiveIntegerConstantInClause(Len, OMPC_safelen); |
| 6540 | if (Safelen.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6541 | return nullptr; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6542 | return new (Context) |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6543 | OMPSafelenClause(Safelen.get(), StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6544 | } |
| 6545 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 6546 | OMPClause *Sema::ActOnOpenMPSimdlenClause(Expr *Len, SourceLocation StartLoc, |
| 6547 | SourceLocation LParenLoc, |
| 6548 | SourceLocation EndLoc) { |
| 6549 | // OpenMP [2.8.1, simd construct, Description] |
| 6550 | // The parameter of the simdlen clause must be a constant |
| 6551 | // positive integer expression. |
| 6552 | ExprResult Simdlen = VerifyPositiveIntegerConstantInClause(Len, OMPC_simdlen); |
| 6553 | if (Simdlen.isInvalid()) |
| 6554 | return nullptr; |
| 6555 | return new (Context) |
| 6556 | OMPSimdlenClause(Simdlen.get(), StartLoc, LParenLoc, EndLoc); |
| 6557 | } |
| 6558 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6559 | OMPClause *Sema::ActOnOpenMPCollapseClause(Expr *NumForLoops, |
| 6560 | SourceLocation StartLoc, |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6561 | SourceLocation LParenLoc, |
| 6562 | SourceLocation EndLoc) { |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6563 | // OpenMP [2.7.1, loop construct, Description] |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6564 | // OpenMP [2.8.1, simd construct, Description] |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6565 | // OpenMP [2.9.6, distribute construct, Description] |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6566 | // The parameter of the collapse clause must be a constant |
| 6567 | // positive integer expression. |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6568 | ExprResult NumForLoopsResult = |
| 6569 | VerifyPositiveIntegerConstantInClause(NumForLoops, OMPC_collapse); |
| 6570 | if (NumForLoopsResult.isInvalid()) |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6571 | return nullptr; |
| 6572 | return new (Context) |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6573 | OMPCollapseClause(NumForLoopsResult.get(), StartLoc, LParenLoc, EndLoc); |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6574 | } |
| 6575 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 6576 | OMPClause *Sema::ActOnOpenMPOrderedClause(SourceLocation StartLoc, |
| 6577 | SourceLocation EndLoc, |
| 6578 | SourceLocation LParenLoc, |
| 6579 | Expr *NumForLoops) { |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 6580 | // OpenMP [2.7.1, loop construct, Description] |
| 6581 | // OpenMP [2.8.1, simd construct, Description] |
| 6582 | // OpenMP [2.9.6, distribute construct, Description] |
| 6583 | // The parameter of the ordered clause must be a constant |
| 6584 | // positive integer expression if any. |
| 6585 | if (NumForLoops && LParenLoc.isValid()) { |
| 6586 | ExprResult NumForLoopsResult = |
| 6587 | VerifyPositiveIntegerConstantInClause(NumForLoops, OMPC_ordered); |
| 6588 | if (NumForLoopsResult.isInvalid()) |
| 6589 | return nullptr; |
| 6590 | NumForLoops = NumForLoopsResult.get(); |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6591 | } else |
| 6592 | NumForLoops = nullptr; |
| 6593 | DSAStack->setOrderedRegion(/*IsOrdered=*/true, NumForLoops); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 6594 | return new (Context) |
| 6595 | OMPOrderedClause(NumForLoops, StartLoc, LParenLoc, EndLoc); |
| 6596 | } |
| 6597 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6598 | OMPClause *Sema::ActOnOpenMPSimpleClause( |
| 6599 | OpenMPClauseKind Kind, unsigned Argument, SourceLocation ArgumentLoc, |
| 6600 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6601 | OMPClause *Res = nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6602 | switch (Kind) { |
| 6603 | case OMPC_default: |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6604 | Res = |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6605 | ActOnOpenMPDefaultClause(static_cast<OpenMPDefaultClauseKind>(Argument), |
| 6606 | ArgumentLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6607 | break; |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6608 | case OMPC_proc_bind: |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6609 | Res = ActOnOpenMPProcBindClause( |
| 6610 | static_cast<OpenMPProcBindClauseKind>(Argument), ArgumentLoc, StartLoc, |
| 6611 | LParenLoc, EndLoc); |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6612 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6613 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 6614 | case OMPC_final: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6615 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6616 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 6617 | case OMPC_simdlen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6618 | case OMPC_collapse: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6619 | case OMPC_schedule: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6620 | case OMPC_private: |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6621 | case OMPC_firstprivate: |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6622 | case OMPC_lastprivate: |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6623 | case OMPC_shared: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6624 | case OMPC_reduction: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6625 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 6626 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6627 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6628 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6629 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6630 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 6631 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 6632 | case OMPC_mergeable: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6633 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 6634 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6635 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6636 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6637 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6638 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 6639 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6640 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 6641 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6642 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6643 | case OMPC_simd: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 6644 | case OMPC_map: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 6645 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6646 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6647 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 6648 | case OMPC_grainsize: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 6649 | case OMPC_nogroup: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6650 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 6651 | case OMPC_hint: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 6652 | case OMPC_dist_schedule: |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 6653 | case OMPC_defaultmap: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6654 | case OMPC_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6655 | llvm_unreachable("Clause is not allowed."); |
| 6656 | } |
| 6657 | return Res; |
| 6658 | } |
| 6659 | |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6660 | static std::string |
| 6661 | getListOfPossibleValues(OpenMPClauseKind K, unsigned First, unsigned Last, |
| 6662 | ArrayRef<unsigned> Exclude = llvm::None) { |
| 6663 | std::string Values; |
| 6664 | unsigned Bound = Last >= 2 ? Last - 2 : 0; |
| 6665 | unsigned Skipped = Exclude.size(); |
| 6666 | auto S = Exclude.begin(), E = Exclude.end(); |
| 6667 | for (unsigned i = First; i < Last; ++i) { |
| 6668 | if (std::find(S, E, i) != E) { |
| 6669 | --Skipped; |
| 6670 | continue; |
| 6671 | } |
| 6672 | Values += "'"; |
| 6673 | Values += getOpenMPSimpleClauseTypeName(K, i); |
| 6674 | Values += "'"; |
| 6675 | if (i == Bound - Skipped) |
| 6676 | Values += " or "; |
| 6677 | else if (i != Bound + 1 - Skipped) |
| 6678 | Values += ", "; |
| 6679 | } |
| 6680 | return Values; |
| 6681 | } |
| 6682 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6683 | OMPClause *Sema::ActOnOpenMPDefaultClause(OpenMPDefaultClauseKind Kind, |
| 6684 | SourceLocation KindKwLoc, |
| 6685 | SourceLocation StartLoc, |
| 6686 | SourceLocation LParenLoc, |
| 6687 | SourceLocation EndLoc) { |
| 6688 | if (Kind == OMPC_DEFAULT_unknown) { |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 6689 | static_assert(OMPC_DEFAULT_unknown > 0, |
| 6690 | "OMPC_DEFAULT_unknown not greater than 0"); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6691 | Diag(KindKwLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6692 | << getListOfPossibleValues(OMPC_default, /*First=*/0, |
| 6693 | /*Last=*/OMPC_DEFAULT_unknown) |
| 6694 | << getOpenMPClauseName(OMPC_default); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6695 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6696 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6697 | switch (Kind) { |
| 6698 | case OMPC_DEFAULT_none: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6699 | DSAStack->setDefaultDSANone(KindKwLoc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6700 | break; |
| 6701 | case OMPC_DEFAULT_shared: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6702 | DSAStack->setDefaultDSAShared(KindKwLoc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6703 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6704 | case OMPC_DEFAULT_unknown: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6705 | llvm_unreachable("Clause kind is not allowed."); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6706 | break; |
| 6707 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6708 | return new (Context) |
| 6709 | OMPDefaultClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6710 | } |
| 6711 | |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6712 | OMPClause *Sema::ActOnOpenMPProcBindClause(OpenMPProcBindClauseKind Kind, |
| 6713 | SourceLocation KindKwLoc, |
| 6714 | SourceLocation StartLoc, |
| 6715 | SourceLocation LParenLoc, |
| 6716 | SourceLocation EndLoc) { |
| 6717 | if (Kind == OMPC_PROC_BIND_unknown) { |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6718 | Diag(KindKwLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6719 | << getListOfPossibleValues(OMPC_proc_bind, /*First=*/0, |
| 6720 | /*Last=*/OMPC_PROC_BIND_unknown) |
| 6721 | << getOpenMPClauseName(OMPC_proc_bind); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6722 | return nullptr; |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6723 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6724 | return new (Context) |
| 6725 | OMPProcBindClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6726 | } |
| 6727 | |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6728 | OMPClause *Sema::ActOnOpenMPSingleExprWithArgClause( |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6729 | OpenMPClauseKind Kind, ArrayRef<unsigned> Argument, Expr *Expr, |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6730 | SourceLocation StartLoc, SourceLocation LParenLoc, |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6731 | ArrayRef<SourceLocation> ArgumentLoc, SourceLocation DelimLoc, |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6732 | SourceLocation EndLoc) { |
| 6733 | OMPClause *Res = nullptr; |
| 6734 | switch (Kind) { |
| 6735 | case OMPC_schedule: |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6736 | enum { Modifier1, Modifier2, ScheduleKind, NumberOfElements }; |
| 6737 | assert(Argument.size() == NumberOfElements && |
| 6738 | ArgumentLoc.size() == NumberOfElements); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6739 | Res = ActOnOpenMPScheduleClause( |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6740 | static_cast<OpenMPScheduleClauseModifier>(Argument[Modifier1]), |
| 6741 | static_cast<OpenMPScheduleClauseModifier>(Argument[Modifier2]), |
| 6742 | static_cast<OpenMPScheduleClauseKind>(Argument[ScheduleKind]), Expr, |
| 6743 | StartLoc, LParenLoc, ArgumentLoc[Modifier1], ArgumentLoc[Modifier2], |
| 6744 | ArgumentLoc[ScheduleKind], DelimLoc, EndLoc); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6745 | break; |
| 6746 | case OMPC_if: |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6747 | assert(Argument.size() == 1 && ArgumentLoc.size() == 1); |
| 6748 | Res = ActOnOpenMPIfClause(static_cast<OpenMPDirectiveKind>(Argument.back()), |
| 6749 | Expr, StartLoc, LParenLoc, ArgumentLoc.back(), |
| 6750 | DelimLoc, EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6751 | break; |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 6752 | case OMPC_dist_schedule: |
| 6753 | Res = ActOnOpenMPDistScheduleClause( |
| 6754 | static_cast<OpenMPDistScheduleClauseKind>(Argument.back()), Expr, |
| 6755 | StartLoc, LParenLoc, ArgumentLoc.back(), DelimLoc, EndLoc); |
| 6756 | break; |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 6757 | case OMPC_defaultmap: |
| 6758 | enum { Modifier, DefaultmapKind }; |
| 6759 | Res = ActOnOpenMPDefaultmapClause( |
| 6760 | static_cast<OpenMPDefaultmapClauseModifier>(Argument[Modifier]), |
| 6761 | static_cast<OpenMPDefaultmapClauseKind>(Argument[DefaultmapKind]), |
| 6762 | StartLoc, LParenLoc, ArgumentLoc[Modifier], |
| 6763 | ArgumentLoc[DefaultmapKind], EndLoc); |
| 6764 | break; |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 6765 | case OMPC_final: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6766 | case OMPC_num_threads: |
| 6767 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 6768 | case OMPC_simdlen: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6769 | case OMPC_collapse: |
| 6770 | case OMPC_default: |
| 6771 | case OMPC_proc_bind: |
| 6772 | case OMPC_private: |
| 6773 | case OMPC_firstprivate: |
| 6774 | case OMPC_lastprivate: |
| 6775 | case OMPC_shared: |
| 6776 | case OMPC_reduction: |
| 6777 | case OMPC_linear: |
| 6778 | case OMPC_aligned: |
| 6779 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6780 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6781 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6782 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 6783 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 6784 | case OMPC_mergeable: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6785 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 6786 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6787 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6788 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6789 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6790 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 6791 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6792 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 6793 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6794 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6795 | case OMPC_simd: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 6796 | case OMPC_map: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 6797 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6798 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6799 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 6800 | case OMPC_grainsize: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 6801 | case OMPC_nogroup: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6802 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 6803 | case OMPC_hint: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6804 | case OMPC_unknown: |
| 6805 | llvm_unreachable("Clause is not allowed."); |
| 6806 | } |
| 6807 | return Res; |
| 6808 | } |
| 6809 | |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6810 | static bool checkScheduleModifiers(Sema &S, OpenMPScheduleClauseModifier M1, |
| 6811 | OpenMPScheduleClauseModifier M2, |
| 6812 | SourceLocation M1Loc, SourceLocation M2Loc) { |
| 6813 | if (M1 == OMPC_SCHEDULE_MODIFIER_unknown && M1Loc.isValid()) { |
| 6814 | SmallVector<unsigned, 2> Excluded; |
| 6815 | if (M2 != OMPC_SCHEDULE_MODIFIER_unknown) |
| 6816 | Excluded.push_back(M2); |
| 6817 | if (M2 == OMPC_SCHEDULE_MODIFIER_nonmonotonic) |
| 6818 | Excluded.push_back(OMPC_SCHEDULE_MODIFIER_monotonic); |
| 6819 | if (M2 == OMPC_SCHEDULE_MODIFIER_monotonic) |
| 6820 | Excluded.push_back(OMPC_SCHEDULE_MODIFIER_nonmonotonic); |
| 6821 | S.Diag(M1Loc, diag::err_omp_unexpected_clause_value) |
| 6822 | << getListOfPossibleValues(OMPC_schedule, |
| 6823 | /*First=*/OMPC_SCHEDULE_MODIFIER_unknown + 1, |
| 6824 | /*Last=*/OMPC_SCHEDULE_MODIFIER_last, |
| 6825 | Excluded) |
| 6826 | << getOpenMPClauseName(OMPC_schedule); |
| 6827 | return true; |
| 6828 | } |
| 6829 | return false; |
| 6830 | } |
| 6831 | |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6832 | OMPClause *Sema::ActOnOpenMPScheduleClause( |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6833 | OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2, |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6834 | OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6835 | SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc, |
| 6836 | SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) { |
| 6837 | if (checkScheduleModifiers(*this, M1, M2, M1Loc, M2Loc) || |
| 6838 | checkScheduleModifiers(*this, M2, M1, M2Loc, M1Loc)) |
| 6839 | return nullptr; |
| 6840 | // OpenMP, 2.7.1, Loop Construct, Restrictions |
| 6841 | // Either the monotonic modifier or the nonmonotonic modifier can be specified |
| 6842 | // but not both. |
| 6843 | if ((M1 == M2 && M1 != OMPC_SCHEDULE_MODIFIER_unknown) || |
| 6844 | (M1 == OMPC_SCHEDULE_MODIFIER_monotonic && |
| 6845 | M2 == OMPC_SCHEDULE_MODIFIER_nonmonotonic) || |
| 6846 | (M1 == OMPC_SCHEDULE_MODIFIER_nonmonotonic && |
| 6847 | M2 == OMPC_SCHEDULE_MODIFIER_monotonic)) { |
| 6848 | Diag(M2Loc, diag::err_omp_unexpected_schedule_modifier) |
| 6849 | << getOpenMPSimpleClauseTypeName(OMPC_schedule, M2) |
| 6850 | << getOpenMPSimpleClauseTypeName(OMPC_schedule, M1); |
| 6851 | return nullptr; |
| 6852 | } |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6853 | if (Kind == OMPC_SCHEDULE_unknown) { |
| 6854 | std::string Values; |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6855 | if (M1Loc.isInvalid() && M2Loc.isInvalid()) { |
| 6856 | unsigned Exclude[] = {OMPC_SCHEDULE_unknown}; |
| 6857 | Values = getListOfPossibleValues(OMPC_schedule, /*First=*/0, |
| 6858 | /*Last=*/OMPC_SCHEDULE_MODIFIER_last, |
| 6859 | Exclude); |
| 6860 | } else { |
| 6861 | Values = getListOfPossibleValues(OMPC_schedule, /*First=*/0, |
| 6862 | /*Last=*/OMPC_SCHEDULE_unknown); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6863 | } |
| 6864 | Diag(KindLoc, diag::err_omp_unexpected_clause_value) |
| 6865 | << Values << getOpenMPClauseName(OMPC_schedule); |
| 6866 | return nullptr; |
| 6867 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6868 | // OpenMP, 2.7.1, Loop Construct, Restrictions |
| 6869 | // The nonmonotonic modifier can only be specified with schedule(dynamic) or |
| 6870 | // schedule(guided). |
| 6871 | if ((M1 == OMPC_SCHEDULE_MODIFIER_nonmonotonic || |
| 6872 | M2 == OMPC_SCHEDULE_MODIFIER_nonmonotonic) && |
| 6873 | Kind != OMPC_SCHEDULE_dynamic && Kind != OMPC_SCHEDULE_guided) { |
| 6874 | Diag(M1 == OMPC_SCHEDULE_MODIFIER_nonmonotonic ? M1Loc : M2Loc, |
| 6875 | diag::err_omp_schedule_nonmonotonic_static); |
| 6876 | return nullptr; |
| 6877 | } |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6878 | Expr *ValExpr = ChunkSize; |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 6879 | Stmt *HelperValStmt = nullptr; |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6880 | if (ChunkSize) { |
| 6881 | if (!ChunkSize->isValueDependent() && !ChunkSize->isTypeDependent() && |
| 6882 | !ChunkSize->isInstantiationDependent() && |
| 6883 | !ChunkSize->containsUnexpandedParameterPack()) { |
| 6884 | SourceLocation ChunkSizeLoc = ChunkSize->getLocStart(); |
| 6885 | ExprResult Val = |
| 6886 | PerformOpenMPImplicitIntegerConversion(ChunkSizeLoc, ChunkSize); |
| 6887 | if (Val.isInvalid()) |
| 6888 | return nullptr; |
| 6889 | |
| 6890 | ValExpr = Val.get(); |
| 6891 | |
| 6892 | // OpenMP [2.7.1, Restrictions] |
| 6893 | // chunk_size must be a loop invariant integer expression with a positive |
| 6894 | // value. |
| 6895 | llvm::APSInt Result; |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 6896 | if (ValExpr->isIntegerConstantExpr(Result, Context)) { |
| 6897 | if (Result.isSigned() && !Result.isStrictlyPositive()) { |
| 6898 | Diag(ChunkSizeLoc, diag::err_omp_negative_expression_in_clause) |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6899 | << "schedule" << 1 << ChunkSize->getSourceRange(); |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 6900 | return nullptr; |
| 6901 | } |
| 6902 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective())) { |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 6903 | llvm::MapVector<Expr *, DeclRefExpr *> Captures; |
| 6904 | ValExpr = tryBuildCapture(*this, ValExpr, Captures).get(); |
| 6905 | HelperValStmt = buildPreInits(Context, Captures); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6906 | } |
| 6907 | } |
| 6908 | } |
| 6909 | |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6910 | return new (Context) |
| 6911 | OMPScheduleClause(StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc, Kind, |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 6912 | ValExpr, HelperValStmt, M1, M1Loc, M2, M2Loc); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6913 | } |
| 6914 | |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6915 | OMPClause *Sema::ActOnOpenMPClause(OpenMPClauseKind Kind, |
| 6916 | SourceLocation StartLoc, |
| 6917 | SourceLocation EndLoc) { |
| 6918 | OMPClause *Res = nullptr; |
| 6919 | switch (Kind) { |
| 6920 | case OMPC_ordered: |
| 6921 | Res = ActOnOpenMPOrderedClause(StartLoc, EndLoc); |
| 6922 | break; |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6923 | case OMPC_nowait: |
| 6924 | Res = ActOnOpenMPNowaitClause(StartLoc, EndLoc); |
| 6925 | break; |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 6926 | case OMPC_untied: |
| 6927 | Res = ActOnOpenMPUntiedClause(StartLoc, EndLoc); |
| 6928 | break; |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 6929 | case OMPC_mergeable: |
| 6930 | Res = ActOnOpenMPMergeableClause(StartLoc, EndLoc); |
| 6931 | break; |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6932 | case OMPC_read: |
| 6933 | Res = ActOnOpenMPReadClause(StartLoc, EndLoc); |
| 6934 | break; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6935 | case OMPC_write: |
| 6936 | Res = ActOnOpenMPWriteClause(StartLoc, EndLoc); |
| 6937 | break; |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6938 | case OMPC_update: |
| 6939 | Res = ActOnOpenMPUpdateClause(StartLoc, EndLoc); |
| 6940 | break; |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6941 | case OMPC_capture: |
| 6942 | Res = ActOnOpenMPCaptureClause(StartLoc, EndLoc); |
| 6943 | break; |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 6944 | case OMPC_seq_cst: |
| 6945 | Res = ActOnOpenMPSeqCstClause(StartLoc, EndLoc); |
| 6946 | break; |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6947 | case OMPC_threads: |
| 6948 | Res = ActOnOpenMPThreadsClause(StartLoc, EndLoc); |
| 6949 | break; |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6950 | case OMPC_simd: |
| 6951 | Res = ActOnOpenMPSIMDClause(StartLoc, EndLoc); |
| 6952 | break; |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 6953 | case OMPC_nogroup: |
| 6954 | Res = ActOnOpenMPNogroupClause(StartLoc, EndLoc); |
| 6955 | break; |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6956 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 6957 | case OMPC_final: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6958 | case OMPC_num_threads: |
| 6959 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 6960 | case OMPC_simdlen: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6961 | case OMPC_collapse: |
| 6962 | case OMPC_schedule: |
| 6963 | case OMPC_private: |
| 6964 | case OMPC_firstprivate: |
| 6965 | case OMPC_lastprivate: |
| 6966 | case OMPC_shared: |
| 6967 | case OMPC_reduction: |
| 6968 | case OMPC_linear: |
| 6969 | case OMPC_aligned: |
| 6970 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6971 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6972 | case OMPC_default: |
| 6973 | case OMPC_proc_bind: |
| 6974 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 6975 | case OMPC_flush: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6976 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 6977 | case OMPC_device: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 6978 | case OMPC_map: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 6979 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6980 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6981 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 6982 | case OMPC_grainsize: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6983 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 6984 | case OMPC_hint: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 6985 | case OMPC_dist_schedule: |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 6986 | case OMPC_defaultmap: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6987 | case OMPC_unknown: |
| 6988 | llvm_unreachable("Clause is not allowed."); |
| 6989 | } |
| 6990 | return Res; |
| 6991 | } |
| 6992 | |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6993 | OMPClause *Sema::ActOnOpenMPNowaitClause(SourceLocation StartLoc, |
| 6994 | SourceLocation EndLoc) { |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 6995 | DSAStack->setNowaitRegion(); |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6996 | return new (Context) OMPNowaitClause(StartLoc, EndLoc); |
| 6997 | } |
| 6998 | |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 6999 | OMPClause *Sema::ActOnOpenMPUntiedClause(SourceLocation StartLoc, |
| 7000 | SourceLocation EndLoc) { |
| 7001 | return new (Context) OMPUntiedClause(StartLoc, EndLoc); |
| 7002 | } |
| 7003 | |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 7004 | OMPClause *Sema::ActOnOpenMPMergeableClause(SourceLocation StartLoc, |
| 7005 | SourceLocation EndLoc) { |
| 7006 | return new (Context) OMPMergeableClause(StartLoc, EndLoc); |
| 7007 | } |
| 7008 | |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 7009 | OMPClause *Sema::ActOnOpenMPReadClause(SourceLocation StartLoc, |
| 7010 | SourceLocation EndLoc) { |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 7011 | return new (Context) OMPReadClause(StartLoc, EndLoc); |
| 7012 | } |
| 7013 | |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 7014 | OMPClause *Sema::ActOnOpenMPWriteClause(SourceLocation StartLoc, |
| 7015 | SourceLocation EndLoc) { |
| 7016 | return new (Context) OMPWriteClause(StartLoc, EndLoc); |
| 7017 | } |
| 7018 | |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 7019 | OMPClause *Sema::ActOnOpenMPUpdateClause(SourceLocation StartLoc, |
| 7020 | SourceLocation EndLoc) { |
| 7021 | return new (Context) OMPUpdateClause(StartLoc, EndLoc); |
| 7022 | } |
| 7023 | |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 7024 | OMPClause *Sema::ActOnOpenMPCaptureClause(SourceLocation StartLoc, |
| 7025 | SourceLocation EndLoc) { |
| 7026 | return new (Context) OMPCaptureClause(StartLoc, EndLoc); |
| 7027 | } |
| 7028 | |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 7029 | OMPClause *Sema::ActOnOpenMPSeqCstClause(SourceLocation StartLoc, |
| 7030 | SourceLocation EndLoc) { |
| 7031 | return new (Context) OMPSeqCstClause(StartLoc, EndLoc); |
| 7032 | } |
| 7033 | |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 7034 | OMPClause *Sema::ActOnOpenMPThreadsClause(SourceLocation StartLoc, |
| 7035 | SourceLocation EndLoc) { |
| 7036 | return new (Context) OMPThreadsClause(StartLoc, EndLoc); |
| 7037 | } |
| 7038 | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 7039 | OMPClause *Sema::ActOnOpenMPSIMDClause(SourceLocation StartLoc, |
| 7040 | SourceLocation EndLoc) { |
| 7041 | return new (Context) OMPSIMDClause(StartLoc, EndLoc); |
| 7042 | } |
| 7043 | |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 7044 | OMPClause *Sema::ActOnOpenMPNogroupClause(SourceLocation StartLoc, |
| 7045 | SourceLocation EndLoc) { |
| 7046 | return new (Context) OMPNogroupClause(StartLoc, EndLoc); |
| 7047 | } |
| 7048 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7049 | OMPClause *Sema::ActOnOpenMPVarListClause( |
| 7050 | OpenMPClauseKind Kind, ArrayRef<Expr *> VarList, Expr *TailExpr, |
| 7051 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, |
| 7052 | SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 7053 | const DeclarationNameInfo &ReductionId, OpenMPDependClauseKind DepKind, |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 7054 | OpenMPLinearClauseKind LinKind, OpenMPMapClauseKind MapTypeModifier, |
| 7055 | OpenMPMapClauseKind MapType, bool IsMapTypeImplicit, |
| 7056 | SourceLocation DepLinMapLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 7057 | OMPClause *Res = nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7058 | switch (Kind) { |
| 7059 | case OMPC_private: |
| 7060 | Res = ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7061 | break; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7062 | case OMPC_firstprivate: |
| 7063 | Res = ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7064 | break; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7065 | case OMPC_lastprivate: |
| 7066 | Res = ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7067 | break; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7068 | case OMPC_shared: |
| 7069 | Res = ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7070 | break; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7071 | case OMPC_reduction: |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 7072 | Res = ActOnOpenMPReductionClause(VarList, StartLoc, LParenLoc, ColonLoc, |
| 7073 | EndLoc, ReductionIdScopeSpec, ReductionId); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7074 | break; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7075 | case OMPC_linear: |
| 7076 | Res = ActOnOpenMPLinearClause(VarList, TailExpr, StartLoc, LParenLoc, |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 7077 | LinKind, DepLinMapLoc, ColonLoc, EndLoc); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7078 | break; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 7079 | case OMPC_aligned: |
| 7080 | Res = ActOnOpenMPAlignedClause(VarList, TailExpr, StartLoc, LParenLoc, |
| 7081 | ColonLoc, EndLoc); |
| 7082 | break; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7083 | case OMPC_copyin: |
| 7084 | Res = ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7085 | break; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7086 | case OMPC_copyprivate: |
| 7087 | Res = ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7088 | break; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 7089 | case OMPC_flush: |
| 7090 | Res = ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7091 | break; |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 7092 | case OMPC_depend: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 7093 | Res = ActOnOpenMPDependClause(DepKind, DepLinMapLoc, ColonLoc, VarList, |
| 7094 | StartLoc, LParenLoc, EndLoc); |
| 7095 | break; |
| 7096 | case OMPC_map: |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 7097 | Res = ActOnOpenMPMapClause(MapTypeModifier, MapType, IsMapTypeImplicit, |
| 7098 | DepLinMapLoc, ColonLoc, VarList, StartLoc, |
| 7099 | LParenLoc, EndLoc); |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 7100 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7101 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 7102 | case OMPC_final: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7103 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 7104 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 7105 | case OMPC_simdlen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 7106 | case OMPC_collapse: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7107 | case OMPC_default: |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 7108 | case OMPC_proc_bind: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7109 | case OMPC_schedule: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7110 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 7111 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 7112 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 7113 | case OMPC_mergeable: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7114 | case OMPC_threadprivate: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 7115 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 7116 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 7117 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 7118 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 7119 | case OMPC_seq_cst: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 7120 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 7121 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 7122 | case OMPC_simd: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 7123 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7124 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 7125 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 7126 | case OMPC_grainsize: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 7127 | case OMPC_nogroup: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 7128 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 7129 | case OMPC_hint: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 7130 | case OMPC_dist_schedule: |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 7131 | case OMPC_defaultmap: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7132 | case OMPC_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7133 | llvm_unreachable("Clause is not allowed."); |
| 7134 | } |
| 7135 | return Res; |
| 7136 | } |
| 7137 | |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 7138 | ExprResult Sema::getOpenMPCapturedExpr(VarDecl *Capture, ExprValueKind VK, |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 7139 | ExprObjectKind OK, SourceLocation Loc) { |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 7140 | ExprResult Res = BuildDeclRefExpr( |
| 7141 | Capture, Capture->getType().getNonReferenceType(), VK_LValue, Loc); |
| 7142 | if (!Res.isUsable()) |
| 7143 | return ExprError(); |
| 7144 | if (OK == OK_Ordinary && !getLangOpts().CPlusPlus) { |
| 7145 | Res = CreateBuiltinUnaryOp(Loc, UO_Deref, Res.get()); |
| 7146 | if (!Res.isUsable()) |
| 7147 | return ExprError(); |
| 7148 | } |
| 7149 | if (VK != VK_LValue && Res.get()->isGLValue()) { |
| 7150 | Res = DefaultLvalueConversion(Res.get()); |
| 7151 | if (!Res.isUsable()) |
| 7152 | return ExprError(); |
| 7153 | } |
| 7154 | return Res; |
| 7155 | } |
| 7156 | |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7157 | static std::pair<ValueDecl *, bool> |
| 7158 | getPrivateItem(Sema &S, Expr *&RefExpr, SourceLocation &ELoc, |
| 7159 | SourceRange &ERange, bool AllowArraySection = false) { |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7160 | if (RefExpr->isTypeDependent() || RefExpr->isValueDependent() || |
| 7161 | RefExpr->containsUnexpandedParameterPack()) |
| 7162 | return std::make_pair(nullptr, true); |
| 7163 | |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7164 | // OpenMP [3.1, C/C++] |
| 7165 | // A list item is a variable name. |
| 7166 | // OpenMP [2.9.3.3, Restrictions, p.1] |
| 7167 | // A variable that is part of another variable (as an array or |
| 7168 | // structure element) cannot appear in a private clause. |
| 7169 | RefExpr = RefExpr->IgnoreParens(); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7170 | enum { |
| 7171 | NoArrayExpr = -1, |
| 7172 | ArraySubscript = 0, |
| 7173 | OMPArraySection = 1 |
| 7174 | } IsArrayExpr = NoArrayExpr; |
| 7175 | if (AllowArraySection) { |
| 7176 | if (auto *ASE = dyn_cast_or_null<ArraySubscriptExpr>(RefExpr)) { |
| 7177 | auto *Base = ASE->getBase()->IgnoreParenImpCasts(); |
| 7178 | while (auto *TempASE = dyn_cast<ArraySubscriptExpr>(Base)) |
| 7179 | Base = TempASE->getBase()->IgnoreParenImpCasts(); |
| 7180 | RefExpr = Base; |
| 7181 | IsArrayExpr = ArraySubscript; |
| 7182 | } else if (auto *OASE = dyn_cast_or_null<OMPArraySectionExpr>(RefExpr)) { |
| 7183 | auto *Base = OASE->getBase()->IgnoreParenImpCasts(); |
| 7184 | while (auto *TempOASE = dyn_cast<OMPArraySectionExpr>(Base)) |
| 7185 | Base = TempOASE->getBase()->IgnoreParenImpCasts(); |
| 7186 | while (auto *TempASE = dyn_cast<ArraySubscriptExpr>(Base)) |
| 7187 | Base = TempASE->getBase()->IgnoreParenImpCasts(); |
| 7188 | RefExpr = Base; |
| 7189 | IsArrayExpr = OMPArraySection; |
| 7190 | } |
| 7191 | } |
| 7192 | ELoc = RefExpr->getExprLoc(); |
| 7193 | ERange = RefExpr->getSourceRange(); |
| 7194 | RefExpr = RefExpr->IgnoreParenImpCasts(); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7195 | auto *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr); |
| 7196 | auto *ME = dyn_cast_or_null<MemberExpr>(RefExpr); |
| 7197 | if ((!DE || !isa<VarDecl>(DE->getDecl())) && |
| 7198 | (S.getCurrentThisType().isNull() || !ME || |
| 7199 | !isa<CXXThisExpr>(ME->getBase()->IgnoreParenImpCasts()) || |
| 7200 | !isa<FieldDecl>(ME->getMemberDecl()))) { |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7201 | if (IsArrayExpr != NoArrayExpr) |
| 7202 | S.Diag(ELoc, diag::err_omp_expected_base_var_name) << IsArrayExpr |
| 7203 | << ERange; |
| 7204 | else { |
| 7205 | S.Diag(ELoc, |
| 7206 | AllowArraySection |
| 7207 | ? diag::err_omp_expected_var_name_member_expr_or_array_item |
| 7208 | : diag::err_omp_expected_var_name_member_expr) |
| 7209 | << (S.getCurrentThisType().isNull() ? 0 : 1) << ERange; |
| 7210 | } |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7211 | return std::make_pair(nullptr, false); |
| 7212 | } |
| 7213 | return std::make_pair(DE ? DE->getDecl() : ME->getMemberDecl(), false); |
| 7214 | } |
| 7215 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7216 | OMPClause *Sema::ActOnOpenMPPrivateClause(ArrayRef<Expr *> VarList, |
| 7217 | SourceLocation StartLoc, |
| 7218 | SourceLocation LParenLoc, |
| 7219 | SourceLocation EndLoc) { |
| 7220 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 7221 | SmallVector<Expr *, 8> PrivateCopies; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7222 | for (auto &RefExpr : VarList) { |
| 7223 | assert(RefExpr && "NULL expr in OpenMP private clause."); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7224 | SourceLocation ELoc; |
| 7225 | SourceRange ERange; |
| 7226 | Expr *SimpleRefExpr = RefExpr; |
| 7227 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7228 | if (Res.second) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7229 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7230 | Vars.push_back(RefExpr); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 7231 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7232 | } |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7233 | ValueDecl *D = Res.first; |
| 7234 | if (!D) |
| 7235 | continue; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7236 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7237 | QualType Type = D->getType(); |
| 7238 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7239 | |
| 7240 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 7241 | // A variable that appears in a private clause must not have an incomplete |
| 7242 | // type or a reference type. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7243 | if (RequireCompleteType(ELoc, Type, diag::err_omp_private_incomplete_type)) |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7244 | continue; |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7245 | Type = Type.getNonReferenceType(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7246 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7247 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 7248 | // in a Construct] |
| 7249 | // Variables with the predetermined data-sharing attributes may not be |
| 7250 | // listed in data-sharing attributes clauses, except for the cases |
| 7251 | // listed below. For these exceptions only, listing a predetermined |
| 7252 | // variable in a data-sharing attribute clause is allowed and overrides |
| 7253 | // the variable's predetermined data-sharing attributes. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7254 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7255 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_private) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7256 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 7257 | << getOpenMPClauseName(OMPC_private); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7258 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7259 | continue; |
| 7260 | } |
| 7261 | |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7262 | // Variably modified types are not supported for tasks. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 7263 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType() && |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7264 | DSAStack->getCurrentDirective() == OMPD_task) { |
| 7265 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
| 7266 | << getOpenMPClauseName(OMPC_private) << Type |
| 7267 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 7268 | bool IsDecl = |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7269 | !VD || |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7270 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7271 | Diag(D->getLocation(), |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7272 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7273 | << D; |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7274 | continue; |
| 7275 | } |
| 7276 | |
Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 7277 | // OpenMP 4.5 [2.15.5.1, Restrictions, p.3] |
| 7278 | // A list item cannot appear in both a map clause and a data-sharing |
| 7279 | // attribute clause on the same construct |
| 7280 | if (DSAStack->getCurrentDirective() == OMPD_target) { |
| 7281 | if(DSAStack->checkMapInfoForVar(VD, /* CurrentRegionOnly = */ true, |
| 7282 | [&](Expr *RE) -> bool {return true;})) { |
| 7283 | Diag(ELoc, diag::err_omp_variable_in_map_and_dsa) |
| 7284 | << getOpenMPClauseName(OMPC_private) |
| 7285 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 7286 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
| 7287 | continue; |
| 7288 | } |
| 7289 | } |
| 7290 | |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7291 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.1] |
| 7292 | // A variable of class type (or array thereof) that appears in a private |
| 7293 | // clause requires an accessible, unambiguous default constructor for the |
| 7294 | // class type. |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 7295 | // Generate helper private variable and initialize it with the default |
| 7296 | // value. The address of the original variable is replaced by the address of |
| 7297 | // the new private variable in CodeGen. This new variable is not added to |
| 7298 | // IdResolver, so the code in the OpenMP region uses original variable for |
| 7299 | // proper diagnostics. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7300 | Type = Type.getUnqualifiedType(); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7301 | auto VDPrivate = buildVarDecl(*this, ELoc, Type, D->getName(), |
| 7302 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7303 | ActOnUninitializedDecl(VDPrivate, /*TypeMayContainAuto=*/false); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 7304 | if (VDPrivate->isInvalidDecl()) |
| 7305 | continue; |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7306 | auto VDPrivateRefExpr = buildDeclRefExpr( |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7307 | *this, VDPrivate, RefExpr->getType().getUnqualifiedType(), ELoc); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 7308 | |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 7309 | DeclRefExpr *Ref = nullptr; |
| 7310 | if (!VD) |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 7311 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false); |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 7312 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_private, Ref); |
| 7313 | Vars.push_back(VD ? RefExpr->IgnoreParens() : Ref); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 7314 | PrivateCopies.push_back(VDPrivateRefExpr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7315 | } |
| 7316 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7317 | if (Vars.empty()) |
| 7318 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7319 | |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 7320 | return OMPPrivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
| 7321 | PrivateCopies); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7322 | } |
| 7323 | |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7324 | namespace { |
| 7325 | class DiagsUninitializedSeveretyRAII { |
| 7326 | private: |
| 7327 | DiagnosticsEngine &Diags; |
| 7328 | SourceLocation SavedLoc; |
| 7329 | bool IsIgnored; |
| 7330 | |
| 7331 | public: |
| 7332 | DiagsUninitializedSeveretyRAII(DiagnosticsEngine &Diags, SourceLocation Loc, |
| 7333 | bool IsIgnored) |
| 7334 | : Diags(Diags), SavedLoc(Loc), IsIgnored(IsIgnored) { |
| 7335 | if (!IsIgnored) { |
| 7336 | Diags.setSeverity(/*Diag*/ diag::warn_uninit_self_reference_in_init, |
| 7337 | /*Map*/ diag::Severity::Ignored, Loc); |
| 7338 | } |
| 7339 | } |
| 7340 | ~DiagsUninitializedSeveretyRAII() { |
| 7341 | if (!IsIgnored) |
| 7342 | Diags.popMappings(SavedLoc); |
| 7343 | } |
| 7344 | }; |
Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 7345 | } |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7346 | |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7347 | OMPClause *Sema::ActOnOpenMPFirstprivateClause(ArrayRef<Expr *> VarList, |
| 7348 | SourceLocation StartLoc, |
| 7349 | SourceLocation LParenLoc, |
| 7350 | SourceLocation EndLoc) { |
| 7351 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7352 | SmallVector<Expr *, 8> PrivateCopies; |
| 7353 | SmallVector<Expr *, 8> Inits; |
Alexey Bataev | 417089f | 2016-02-17 13:19:37 +0000 | [diff] [blame] | 7354 | SmallVector<Decl *, 4> ExprCaptures; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7355 | bool IsImplicitClause = |
| 7356 | StartLoc.isInvalid() && LParenLoc.isInvalid() && EndLoc.isInvalid(); |
| 7357 | auto ImplicitClauseLoc = DSAStack->getConstructLoc(); |
| 7358 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7359 | for (auto &RefExpr : VarList) { |
| 7360 | assert(RefExpr && "NULL expr in OpenMP firstprivate clause."); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7361 | SourceLocation ELoc; |
| 7362 | SourceRange ERange; |
| 7363 | Expr *SimpleRefExpr = RefExpr; |
| 7364 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7365 | if (Res.second) { |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7366 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7367 | Vars.push_back(RefExpr); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7368 | PrivateCopies.push_back(nullptr); |
| 7369 | Inits.push_back(nullptr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7370 | } |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7371 | ValueDecl *D = Res.first; |
| 7372 | if (!D) |
| 7373 | continue; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7374 | |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7375 | ELoc = IsImplicitClause ? ImplicitClauseLoc : ELoc; |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7376 | QualType Type = D->getType(); |
| 7377 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7378 | |
| 7379 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 7380 | // A variable that appears in a private clause must not have an incomplete |
| 7381 | // type or a reference type. |
| 7382 | if (RequireCompleteType(ELoc, Type, |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7383 | diag::err_omp_firstprivate_incomplete_type)) |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7384 | continue; |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7385 | Type = Type.getNonReferenceType(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7386 | |
| 7387 | // OpenMP [2.9.3.4, Restrictions, C/C++, p.1] |
| 7388 | // 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] | 7389 | // clause requires an accessible, unambiguous copy constructor for the |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7390 | // class type. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7391 | auto ElemType = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7392 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7393 | // If an implicit firstprivate variable found it was checked already. |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 7394 | DSAStackTy::DSAVarData TopDVar; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7395 | if (!IsImplicitClause) { |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7396 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 7397 | TopDVar = DVar; |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7398 | bool IsConstant = ElemType.isConstant(Context); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7399 | // OpenMP [2.4.13, Data-sharing Attribute Clauses] |
| 7400 | // A list item that specifies a given variable may not appear in more |
| 7401 | // than one clause on the same directive, except that a variable may be |
| 7402 | // specified in both firstprivate and lastprivate clauses. |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7403 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_firstprivate && |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7404 | DVar.CKind != OMPC_lastprivate && DVar.RefExpr) { |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7405 | Diag(ELoc, diag::err_omp_wrong_dsa) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7406 | << getOpenMPClauseName(DVar.CKind) |
| 7407 | << getOpenMPClauseName(OMPC_firstprivate); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7408 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7409 | continue; |
| 7410 | } |
| 7411 | |
| 7412 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 7413 | // in a Construct] |
| 7414 | // Variables with the predetermined data-sharing attributes may not be |
| 7415 | // listed in data-sharing attributes clauses, except for the cases |
| 7416 | // listed below. For these exceptions only, listing a predetermined |
| 7417 | // variable in a data-sharing attribute clause is allowed and overrides |
| 7418 | // the variable's predetermined data-sharing attributes. |
| 7419 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 7420 | // in a Construct, C/C++, p.2] |
| 7421 | // Variables with const-qualified type having no mutable member may be |
| 7422 | // listed in a firstprivate clause, even if they are static data members. |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7423 | if (!(IsConstant || (VD && VD->isStaticDataMember())) && !DVar.RefExpr && |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7424 | DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared) { |
| 7425 | Diag(ELoc, diag::err_omp_wrong_dsa) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7426 | << getOpenMPClauseName(DVar.CKind) |
| 7427 | << getOpenMPClauseName(OMPC_firstprivate); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7428 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7429 | continue; |
| 7430 | } |
| 7431 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7432 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7433 | // OpenMP [2.9.3.4, Restrictions, p.2] |
| 7434 | // A list item that is private within a parallel region must not appear |
| 7435 | // in a firstprivate clause on a worksharing construct if any of the |
| 7436 | // worksharing regions arising from the worksharing construct ever bind |
| 7437 | // to any of the parallel regions arising from the parallel construct. |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 7438 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 7439 | !isOpenMPParallelDirective(CurrDir)) { |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7440 | DVar = DSAStack->getImplicitDSA(D, true); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7441 | if (DVar.CKind != OMPC_shared && |
| 7442 | (isOpenMPParallelDirective(DVar.DKind) || |
| 7443 | DVar.DKind == OMPD_unknown)) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7444 | Diag(ELoc, diag::err_omp_required_access) |
| 7445 | << getOpenMPClauseName(OMPC_firstprivate) |
| 7446 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7447 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7448 | continue; |
| 7449 | } |
| 7450 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7451 | // OpenMP [2.9.3.4, Restrictions, p.3] |
| 7452 | // A list item that appears in a reduction clause of a parallel construct |
| 7453 | // must not appear in a firstprivate clause on a worksharing or task |
| 7454 | // construct if any of the worksharing or task regions arising from the |
| 7455 | // worksharing or task construct ever bind to any of the parallel regions |
| 7456 | // arising from the parallel construct. |
| 7457 | // OpenMP [2.9.3.4, Restrictions, p.4] |
| 7458 | // A list item that appears in a reduction clause in worksharing |
| 7459 | // construct must not appear in a firstprivate clause in a task construct |
| 7460 | // encountered during execution of any of the worksharing regions arising |
| 7461 | // from the worksharing construct. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7462 | if (CurrDir == OMPD_task) { |
| 7463 | DVar = |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7464 | DSAStack->hasInnermostDSA(D, MatchesAnyClause(OMPC_reduction), |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7465 | [](OpenMPDirectiveKind K) -> bool { |
| 7466 | return isOpenMPParallelDirective(K) || |
| 7467 | isOpenMPWorksharingDirective(K); |
| 7468 | }, |
| 7469 | false); |
| 7470 | if (DVar.CKind == OMPC_reduction && |
| 7471 | (isOpenMPParallelDirective(DVar.DKind) || |
| 7472 | isOpenMPWorksharingDirective(DVar.DKind))) { |
| 7473 | Diag(ELoc, diag::err_omp_parallel_reduction_in_task_firstprivate) |
| 7474 | << getOpenMPDirectiveName(DVar.DKind); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7475 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7476 | continue; |
| 7477 | } |
| 7478 | } |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7479 | |
| 7480 | // OpenMP 4.5 [2.15.3.4, Restrictions, p.3] |
| 7481 | // A list item that is private within a teams region must not appear in a |
| 7482 | // firstprivate clause on a distribute construct if any of the distribute |
| 7483 | // regions arising from the distribute construct ever bind to any of the |
| 7484 | // teams regions arising from the teams construct. |
| 7485 | // OpenMP 4.5 [2.15.3.4, Restrictions, p.3] |
| 7486 | // A list item that appears in a reduction clause of a teams construct |
| 7487 | // must not appear in a firstprivate clause on a distribute construct if |
| 7488 | // any of the distribute regions arising from the distribute construct |
| 7489 | // ever bind to any of the teams regions arising from the teams construct. |
| 7490 | // OpenMP 4.5 [2.10.8, Distribute Construct, p.3] |
| 7491 | // A list item may appear in a firstprivate or lastprivate clause but not |
| 7492 | // both. |
| 7493 | if (CurrDir == OMPD_distribute) { |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7494 | DVar = DSAStack->hasInnermostDSA(D, MatchesAnyClause(OMPC_private), |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7495 | [](OpenMPDirectiveKind K) -> bool { |
| 7496 | return isOpenMPTeamsDirective(K); |
| 7497 | }, |
| 7498 | false); |
| 7499 | if (DVar.CKind == OMPC_private && isOpenMPTeamsDirective(DVar.DKind)) { |
| 7500 | Diag(ELoc, diag::err_omp_firstprivate_distribute_private_teams); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7501 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7502 | continue; |
| 7503 | } |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7504 | DVar = DSAStack->hasInnermostDSA(D, MatchesAnyClause(OMPC_reduction), |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7505 | [](OpenMPDirectiveKind K) -> bool { |
| 7506 | return isOpenMPTeamsDirective(K); |
| 7507 | }, |
| 7508 | false); |
| 7509 | if (DVar.CKind == OMPC_reduction && |
| 7510 | isOpenMPTeamsDirective(DVar.DKind)) { |
| 7511 | Diag(ELoc, diag::err_omp_firstprivate_distribute_in_teams_reduction); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7512 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7513 | continue; |
| 7514 | } |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7515 | DVar = DSAStack->getTopDSA(D, false); |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7516 | if (DVar.CKind == OMPC_lastprivate) { |
| 7517 | Diag(ELoc, diag::err_omp_firstprivate_and_lastprivate_in_distribute); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7518 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7519 | continue; |
| 7520 | } |
| 7521 | } |
Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 7522 | // OpenMP 4.5 [2.15.5.1, Restrictions, p.3] |
| 7523 | // A list item cannot appear in both a map clause and a data-sharing |
| 7524 | // attribute clause on the same construct |
| 7525 | if (CurrDir == OMPD_target) { |
| 7526 | if(DSAStack->checkMapInfoForVar(VD, /* CurrentRegionOnly = */ true, |
| 7527 | [&](Expr *RE) -> bool {return true;})) { |
| 7528 | Diag(ELoc, diag::err_omp_variable_in_map_and_dsa) |
| 7529 | << getOpenMPClauseName(OMPC_firstprivate) |
| 7530 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 7531 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
| 7532 | continue; |
| 7533 | } |
| 7534 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7535 | } |
| 7536 | |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7537 | // Variably modified types are not supported for tasks. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 7538 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType() && |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7539 | DSAStack->getCurrentDirective() == OMPD_task) { |
| 7540 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
| 7541 | << getOpenMPClauseName(OMPC_firstprivate) << Type |
| 7542 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 7543 | bool IsDecl = |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7544 | !VD || |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7545 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7546 | Diag(D->getLocation(), |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7547 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7548 | << D; |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7549 | continue; |
| 7550 | } |
| 7551 | |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7552 | Type = Type.getUnqualifiedType(); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7553 | auto VDPrivate = buildVarDecl(*this, ELoc, Type, D->getName(), |
| 7554 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7555 | // Generate helper private variable and initialize it with the value of the |
| 7556 | // original variable. The address of the original variable is replaced by |
| 7557 | // the address of the new private variable in the CodeGen. This new variable |
| 7558 | // is not added to IdResolver, so the code in the OpenMP region uses |
| 7559 | // original variable for proper diagnostics and variable capturing. |
| 7560 | Expr *VDInitRefExpr = nullptr; |
| 7561 | // For arrays generate initializer for single element and replace it by the |
| 7562 | // original array element in CodeGen. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7563 | if (Type->isArrayType()) { |
| 7564 | auto VDInit = |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7565 | buildVarDecl(*this, RefExpr->getExprLoc(), ElemType, D->getName()); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7566 | VDInitRefExpr = buildDeclRefExpr(*this, VDInit, ElemType, ELoc); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7567 | auto Init = DefaultLvalueConversion(VDInitRefExpr).get(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7568 | ElemType = ElemType.getUnqualifiedType(); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7569 | auto *VDInitTemp = buildVarDecl(*this, RefExpr->getExprLoc(), ElemType, |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7570 | ".firstprivate.temp"); |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 7571 | InitializedEntity Entity = |
| 7572 | InitializedEntity::InitializeVariable(VDInitTemp); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7573 | InitializationKind Kind = InitializationKind::CreateCopy(ELoc, ELoc); |
| 7574 | |
| 7575 | InitializationSequence InitSeq(*this, Entity, Kind, Init); |
| 7576 | ExprResult Result = InitSeq.Perform(*this, Entity, Kind, Init); |
| 7577 | if (Result.isInvalid()) |
| 7578 | VDPrivate->setInvalidDecl(); |
| 7579 | else |
| 7580 | VDPrivate->setInit(Result.getAs<Expr>()); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7581 | // Remove temp variable declaration. |
| 7582 | Context.Deallocate(VDInitTemp); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7583 | } else { |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7584 | auto *VDInit = buildVarDecl(*this, RefExpr->getExprLoc(), Type, |
| 7585 | ".firstprivate.temp"); |
| 7586 | VDInitRefExpr = buildDeclRefExpr(*this, VDInit, RefExpr->getType(), |
| 7587 | RefExpr->getExprLoc()); |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 7588 | AddInitializerToDecl(VDPrivate, |
| 7589 | DefaultLvalueConversion(VDInitRefExpr).get(), |
| 7590 | /*DirectInit=*/false, /*TypeMayContainAuto=*/false); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7591 | } |
| 7592 | if (VDPrivate->isInvalidDecl()) { |
| 7593 | if (IsImplicitClause) { |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7594 | Diag(RefExpr->getExprLoc(), |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7595 | diag::note_omp_task_predetermined_firstprivate_here); |
| 7596 | } |
| 7597 | continue; |
| 7598 | } |
| 7599 | CurContext->addDecl(VDPrivate); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7600 | auto VDPrivateRefExpr = buildDeclRefExpr( |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7601 | *this, VDPrivate, RefExpr->getType().getUnqualifiedType(), |
| 7602 | RefExpr->getExprLoc()); |
| 7603 | DeclRefExpr *Ref = nullptr; |
Alexey Bataev | 417089f | 2016-02-17 13:19:37 +0000 | [diff] [blame] | 7604 | if (!VD) { |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 7605 | if (TopDVar.CKind == OMPC_lastprivate) |
| 7606 | Ref = TopDVar.PrivateCopy; |
| 7607 | else { |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 7608 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/true); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 7609 | if (!IsOpenMPCapturedDecl(D)) |
| 7610 | ExprCaptures.push_back(Ref->getDecl()); |
| 7611 | } |
Alexey Bataev | 417089f | 2016-02-17 13:19:37 +0000 | [diff] [blame] | 7612 | } |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7613 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_firstprivate, Ref); |
| 7614 | Vars.push_back(VD ? RefExpr->IgnoreParens() : Ref); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7615 | PrivateCopies.push_back(VDPrivateRefExpr); |
| 7616 | Inits.push_back(VDInitRefExpr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7617 | } |
| 7618 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7619 | if (Vars.empty()) |
| 7620 | return nullptr; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7621 | |
| 7622 | return OMPFirstprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 7623 | Vars, PrivateCopies, Inits, |
| 7624 | buildPreInits(Context, ExprCaptures)); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7625 | } |
| 7626 | |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7627 | OMPClause *Sema::ActOnOpenMPLastprivateClause(ArrayRef<Expr *> VarList, |
| 7628 | SourceLocation StartLoc, |
| 7629 | SourceLocation LParenLoc, |
| 7630 | SourceLocation EndLoc) { |
| 7631 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7632 | SmallVector<Expr *, 8> SrcExprs; |
| 7633 | SmallVector<Expr *, 8> DstExprs; |
| 7634 | SmallVector<Expr *, 8> AssignmentOps; |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 7635 | SmallVector<Decl *, 4> ExprCaptures; |
| 7636 | SmallVector<Expr *, 4> ExprPostUpdates; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7637 | for (auto &RefExpr : VarList) { |
| 7638 | assert(RefExpr && "NULL expr in OpenMP lastprivate clause."); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7639 | SourceLocation ELoc; |
| 7640 | SourceRange ERange; |
| 7641 | Expr *SimpleRefExpr = RefExpr; |
| 7642 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7643 | if (Res.second) { |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7644 | // It will be analyzed later. |
| 7645 | Vars.push_back(RefExpr); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7646 | SrcExprs.push_back(nullptr); |
| 7647 | DstExprs.push_back(nullptr); |
| 7648 | AssignmentOps.push_back(nullptr); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7649 | } |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7650 | ValueDecl *D = Res.first; |
| 7651 | if (!D) |
| 7652 | continue; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7653 | |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7654 | QualType Type = D->getType(); |
| 7655 | auto *VD = dyn_cast<VarDecl>(D); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7656 | |
| 7657 | // OpenMP [2.14.3.5, Restrictions, C/C++, p.2] |
| 7658 | // A variable that appears in a lastprivate clause must not have an |
| 7659 | // incomplete type or a reference type. |
| 7660 | if (RequireCompleteType(ELoc, Type, |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7661 | diag::err_omp_lastprivate_incomplete_type)) |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7662 | continue; |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7663 | Type = Type.getNonReferenceType(); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7664 | |
| 7665 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 7666 | // in a Construct] |
| 7667 | // Variables with the predetermined data-sharing attributes may not be |
| 7668 | // listed in data-sharing attributes clauses, except for the cases |
| 7669 | // listed below. |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7670 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7671 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_lastprivate && |
| 7672 | DVar.CKind != OMPC_firstprivate && |
| 7673 | (DVar.CKind != OMPC_private || DVar.RefExpr != nullptr)) { |
| 7674 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 7675 | << getOpenMPClauseName(DVar.CKind) |
| 7676 | << getOpenMPClauseName(OMPC_lastprivate); |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7677 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7678 | continue; |
| 7679 | } |
| 7680 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7681 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
| 7682 | // OpenMP [2.14.3.5, Restrictions, p.2] |
| 7683 | // A list item that is private within a parallel region, or that appears in |
| 7684 | // the reduction clause of a parallel construct, must not appear in a |
| 7685 | // lastprivate clause on a worksharing construct if any of the corresponding |
| 7686 | // worksharing regions ever binds to any of the corresponding parallel |
| 7687 | // regions. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7688 | DSAStackTy::DSAVarData TopDVar = DVar; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 7689 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 7690 | !isOpenMPParallelDirective(CurrDir)) { |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7691 | DVar = DSAStack->getImplicitDSA(D, true); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7692 | if (DVar.CKind != OMPC_shared) { |
| 7693 | Diag(ELoc, diag::err_omp_required_access) |
| 7694 | << getOpenMPClauseName(OMPC_lastprivate) |
| 7695 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7696 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7697 | continue; |
| 7698 | } |
| 7699 | } |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7700 | |
| 7701 | // OpenMP 4.5 [2.10.8, Distribute Construct, p.3] |
| 7702 | // A list item may appear in a firstprivate or lastprivate clause but not |
| 7703 | // both. |
| 7704 | if (CurrDir == OMPD_distribute) { |
| 7705 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
| 7706 | if (DVar.CKind == OMPC_firstprivate) { |
| 7707 | Diag(ELoc, diag::err_omp_firstprivate_and_lastprivate_in_distribute); |
| 7708 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
| 7709 | continue; |
| 7710 | } |
| 7711 | } |
| 7712 | |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7713 | // OpenMP [2.14.3.5, Restrictions, C++, p.1,2] |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7714 | // A variable of class type (or array thereof) that appears in a |
| 7715 | // lastprivate clause requires an accessible, unambiguous default |
| 7716 | // constructor for the class type, unless the list item is also specified |
| 7717 | // in a firstprivate clause. |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7718 | // A variable of class type (or array thereof) that appears in a |
| 7719 | // lastprivate clause requires an accessible, unambiguous copy assignment |
| 7720 | // operator for the class type. |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7721 | Type = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7722 | auto *SrcVD = buildVarDecl(*this, ERange.getBegin(), |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 7723 | Type.getUnqualifiedType(), ".lastprivate.src", |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7724 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 7725 | auto *PseudoSrcExpr = |
| 7726 | buildDeclRefExpr(*this, SrcVD, Type.getUnqualifiedType(), ELoc); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7727 | auto *DstVD = |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7728 | buildVarDecl(*this, ERange.getBegin(), Type, ".lastprivate.dst", |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7729 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 7730 | auto *PseudoDstExpr = buildDeclRefExpr(*this, DstVD, Type, ELoc); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7731 | // For arrays generate assignment operation for single element and replace |
| 7732 | // it by the original array element in CodeGen. |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7733 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, ELoc, BO_Assign, |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7734 | PseudoDstExpr, PseudoSrcExpr); |
| 7735 | if (AssignmentOp.isInvalid()) |
| 7736 | continue; |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7737 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), ELoc, |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7738 | /*DiscardedValue=*/true); |
| 7739 | if (AssignmentOp.isInvalid()) |
| 7740 | continue; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7741 | |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7742 | DeclRefExpr *Ref = nullptr; |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 7743 | if (!VD) { |
| 7744 | if (TopDVar.CKind == OMPC_firstprivate) |
| 7745 | Ref = TopDVar.PrivateCopy; |
| 7746 | else { |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 7747 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 7748 | if (!IsOpenMPCapturedDecl(D)) |
| 7749 | ExprCaptures.push_back(Ref->getDecl()); |
| 7750 | } |
| 7751 | if (TopDVar.CKind == OMPC_firstprivate || |
| 7752 | (!IsOpenMPCapturedDecl(D) && |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 7753 | Ref->getDecl()->hasAttr<OMPCaptureNoInitAttr>())) { |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 7754 | ExprResult RefRes = DefaultLvalueConversion(Ref); |
| 7755 | if (!RefRes.isUsable()) |
| 7756 | continue; |
| 7757 | ExprResult PostUpdateRes = |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7758 | BuildBinOp(DSAStack->getCurScope(), ELoc, BO_Assign, SimpleRefExpr, |
| 7759 | RefRes.get()); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 7760 | if (!PostUpdateRes.isUsable()) |
| 7761 | continue; |
Alexey Bataev | 78849fb | 2016-03-09 09:49:00 +0000 | [diff] [blame] | 7762 | ExprPostUpdates.push_back( |
| 7763 | IgnoredValueConversions(PostUpdateRes.get()).get()); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 7764 | } |
| 7765 | } |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7766 | if (TopDVar.CKind != OMPC_firstprivate) |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7767 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_lastprivate, Ref); |
| 7768 | Vars.push_back(VD ? RefExpr->IgnoreParens() : Ref); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7769 | SrcExprs.push_back(PseudoSrcExpr); |
| 7770 | DstExprs.push_back(PseudoDstExpr); |
| 7771 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7772 | } |
| 7773 | |
| 7774 | if (Vars.empty()) |
| 7775 | return nullptr; |
| 7776 | |
| 7777 | return OMPLastprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 7778 | Vars, SrcExprs, DstExprs, AssignmentOps, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 7779 | buildPreInits(Context, ExprCaptures), |
| 7780 | buildPostUpdate(*this, ExprPostUpdates)); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7781 | } |
| 7782 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7783 | OMPClause *Sema::ActOnOpenMPSharedClause(ArrayRef<Expr *> VarList, |
| 7784 | SourceLocation StartLoc, |
| 7785 | SourceLocation LParenLoc, |
| 7786 | SourceLocation EndLoc) { |
| 7787 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7788 | for (auto &RefExpr : VarList) { |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 7789 | assert(RefExpr && "NULL expr in OpenMP lastprivate clause."); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7790 | SourceLocation ELoc; |
| 7791 | SourceRange ERange; |
| 7792 | Expr *SimpleRefExpr = RefExpr; |
| 7793 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 7794 | if (Res.second) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7795 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7796 | Vars.push_back(RefExpr); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7797 | } |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 7798 | ValueDecl *D = Res.first; |
| 7799 | if (!D) |
| 7800 | continue; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7801 | |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 7802 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7803 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 7804 | // in a Construct] |
| 7805 | // Variables with the predetermined data-sharing attributes may not be |
| 7806 | // listed in data-sharing attributes clauses, except for the cases |
| 7807 | // listed below. For these exceptions only, listing a predetermined |
| 7808 | // variable in a data-sharing attribute clause is allowed and overrides |
| 7809 | // the variable's predetermined data-sharing attributes. |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 7810 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7811 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared && |
| 7812 | DVar.RefExpr) { |
| 7813 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 7814 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 7815 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7816 | continue; |
| 7817 | } |
| 7818 | |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 7819 | DeclRefExpr *Ref = nullptr; |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 7820 | if (!VD && IsOpenMPCapturedDecl(D)) |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 7821 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/true); |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 7822 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_shared, Ref); |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 7823 | Vars.push_back((VD || !Ref) ? RefExpr->IgnoreParens() : Ref); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7824 | } |
| 7825 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7826 | if (Vars.empty()) |
| 7827 | return nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7828 | |
| 7829 | return OMPSharedClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars); |
| 7830 | } |
| 7831 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7832 | namespace { |
| 7833 | class DSARefChecker : public StmtVisitor<DSARefChecker, bool> { |
| 7834 | DSAStackTy *Stack; |
| 7835 | |
| 7836 | public: |
| 7837 | bool VisitDeclRefExpr(DeclRefExpr *E) { |
| 7838 | if (VarDecl *VD = dyn_cast<VarDecl>(E->getDecl())) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7839 | DSAStackTy::DSAVarData DVar = Stack->getTopDSA(VD, false); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7840 | if (DVar.CKind == OMPC_shared && !DVar.RefExpr) |
| 7841 | return false; |
| 7842 | if (DVar.CKind != OMPC_unknown) |
| 7843 | return true; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7844 | DSAStackTy::DSAVarData DVarPrivate = |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7845 | Stack->hasDSA(VD, isOpenMPPrivate, MatchesAlways(), false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7846 | if (DVarPrivate.CKind != OMPC_unknown) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7847 | return true; |
| 7848 | return false; |
| 7849 | } |
| 7850 | return false; |
| 7851 | } |
| 7852 | bool VisitStmt(Stmt *S) { |
| 7853 | for (auto Child : S->children()) { |
| 7854 | if (Child && Visit(Child)) |
| 7855 | return true; |
| 7856 | } |
| 7857 | return false; |
| 7858 | } |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 7859 | explicit DSARefChecker(DSAStackTy *S) : Stack(S) {} |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7860 | }; |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 7861 | } // namespace |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7862 | |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7863 | namespace { |
| 7864 | // Transform MemberExpression for specified FieldDecl of current class to |
| 7865 | // DeclRefExpr to specified OMPCapturedExprDecl. |
| 7866 | class TransformExprToCaptures : public TreeTransform<TransformExprToCaptures> { |
| 7867 | typedef TreeTransform<TransformExprToCaptures> BaseTransform; |
| 7868 | ValueDecl *Field; |
| 7869 | DeclRefExpr *CapturedExpr; |
| 7870 | |
| 7871 | public: |
| 7872 | TransformExprToCaptures(Sema &SemaRef, ValueDecl *FieldDecl) |
| 7873 | : BaseTransform(SemaRef), Field(FieldDecl), CapturedExpr(nullptr) {} |
| 7874 | |
| 7875 | ExprResult TransformMemberExpr(MemberExpr *E) { |
| 7876 | if (isa<CXXThisExpr>(E->getBase()->IgnoreParenImpCasts()) && |
| 7877 | E->getMemberDecl() == Field) { |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 7878 | CapturedExpr = buildCapture(SemaRef, Field, E, /*WithInit=*/false); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7879 | return CapturedExpr; |
| 7880 | } |
| 7881 | return BaseTransform::TransformMemberExpr(E); |
| 7882 | } |
| 7883 | DeclRefExpr *getCapturedExpr() { return CapturedExpr; } |
| 7884 | }; |
| 7885 | } // namespace |
| 7886 | |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 7887 | template <typename T> |
| 7888 | static T filterLookupForUDR(SmallVectorImpl<UnresolvedSet<8>> &Lookups, |
| 7889 | const llvm::function_ref<T(ValueDecl *)> &Gen) { |
| 7890 | for (auto &Set : Lookups) { |
| 7891 | for (auto *D : Set) { |
| 7892 | if (auto Res = Gen(cast<ValueDecl>(D))) |
| 7893 | return Res; |
| 7894 | } |
| 7895 | } |
| 7896 | return T(); |
| 7897 | } |
| 7898 | |
| 7899 | static ExprResult |
| 7900 | buildDeclareReductionRef(Sema &SemaRef, SourceLocation Loc, SourceRange Range, |
| 7901 | Scope *S, CXXScopeSpec &ReductionIdScopeSpec, |
| 7902 | const DeclarationNameInfo &ReductionId, QualType Ty, |
| 7903 | CXXCastPath &BasePath, Expr *UnresolvedReduction) { |
| 7904 | if (ReductionIdScopeSpec.isInvalid()) |
| 7905 | return ExprError(); |
| 7906 | SmallVector<UnresolvedSet<8>, 4> Lookups; |
| 7907 | if (S) { |
| 7908 | LookupResult Lookup(SemaRef, ReductionId, Sema::LookupOMPReductionName); |
| 7909 | Lookup.suppressDiagnostics(); |
| 7910 | while (S && SemaRef.LookupParsedName(Lookup, S, &ReductionIdScopeSpec)) { |
| 7911 | auto *D = Lookup.getRepresentativeDecl(); |
| 7912 | do { |
| 7913 | S = S->getParent(); |
| 7914 | } while (S && !S->isDeclScope(D)); |
| 7915 | if (S) |
| 7916 | S = S->getParent(); |
| 7917 | Lookups.push_back(UnresolvedSet<8>()); |
| 7918 | Lookups.back().append(Lookup.begin(), Lookup.end()); |
| 7919 | Lookup.clear(); |
| 7920 | } |
| 7921 | } else if (auto *ULE = |
| 7922 | cast_or_null<UnresolvedLookupExpr>(UnresolvedReduction)) { |
| 7923 | Lookups.push_back(UnresolvedSet<8>()); |
| 7924 | Decl *PrevD = nullptr; |
| 7925 | for(auto *D : ULE->decls()) { |
| 7926 | if (D == PrevD) |
| 7927 | Lookups.push_back(UnresolvedSet<8>()); |
| 7928 | else if (auto *DRD = cast<OMPDeclareReductionDecl>(D)) |
| 7929 | Lookups.back().addDecl(DRD); |
| 7930 | PrevD = D; |
| 7931 | } |
| 7932 | } |
| 7933 | if (Ty->isDependentType() || Ty->isInstantiationDependentType() || |
| 7934 | Ty->containsUnexpandedParameterPack() || |
| 7935 | filterLookupForUDR<bool>(Lookups, [](ValueDecl *D) -> bool { |
| 7936 | return !D->isInvalidDecl() && |
| 7937 | (D->getType()->isDependentType() || |
| 7938 | D->getType()->isInstantiationDependentType() || |
| 7939 | D->getType()->containsUnexpandedParameterPack()); |
| 7940 | })) { |
| 7941 | UnresolvedSet<8> ResSet; |
| 7942 | for (auto &Set : Lookups) { |
| 7943 | ResSet.append(Set.begin(), Set.end()); |
| 7944 | // The last item marks the end of all declarations at the specified scope. |
| 7945 | ResSet.addDecl(Set[Set.size() - 1]); |
| 7946 | } |
| 7947 | return UnresolvedLookupExpr::Create( |
| 7948 | SemaRef.Context, /*NamingClass=*/nullptr, |
| 7949 | ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), ReductionId, |
| 7950 | /*ADL=*/true, /*Overloaded=*/true, ResSet.begin(), ResSet.end()); |
| 7951 | } |
| 7952 | if (auto *VD = filterLookupForUDR<ValueDecl *>( |
| 7953 | Lookups, [&SemaRef, Ty](ValueDecl *D) -> ValueDecl * { |
| 7954 | if (!D->isInvalidDecl() && |
| 7955 | SemaRef.Context.hasSameType(D->getType(), Ty)) |
| 7956 | return D; |
| 7957 | return nullptr; |
| 7958 | })) |
| 7959 | return SemaRef.BuildDeclRefExpr(VD, Ty, VK_LValue, Loc); |
| 7960 | if (auto *VD = filterLookupForUDR<ValueDecl *>( |
| 7961 | Lookups, [&SemaRef, Ty, Loc](ValueDecl *D) -> ValueDecl * { |
| 7962 | if (!D->isInvalidDecl() && |
| 7963 | SemaRef.IsDerivedFrom(Loc, Ty, D->getType()) && |
| 7964 | !Ty.isMoreQualifiedThan(D->getType())) |
| 7965 | return D; |
| 7966 | return nullptr; |
| 7967 | })) { |
| 7968 | CXXBasePaths Paths(/*FindAmbiguities=*/true, /*RecordPaths=*/true, |
| 7969 | /*DetectVirtual=*/false); |
| 7970 | if (SemaRef.IsDerivedFrom(Loc, Ty, VD->getType(), Paths)) { |
| 7971 | if (!Paths.isAmbiguous(SemaRef.Context.getCanonicalType( |
| 7972 | VD->getType().getUnqualifiedType()))) { |
| 7973 | if (SemaRef.CheckBaseClassAccess(Loc, VD->getType(), Ty, Paths.front(), |
| 7974 | /*DiagID=*/0) != |
| 7975 | Sema::AR_inaccessible) { |
| 7976 | SemaRef.BuildBasePathArray(Paths, BasePath); |
| 7977 | return SemaRef.BuildDeclRefExpr(VD, Ty, VK_LValue, Loc); |
| 7978 | } |
| 7979 | } |
| 7980 | } |
| 7981 | } |
| 7982 | if (ReductionIdScopeSpec.isSet()) { |
| 7983 | SemaRef.Diag(Loc, diag::err_omp_not_resolved_reduction_identifier) << Range; |
| 7984 | return ExprError(); |
| 7985 | } |
| 7986 | return ExprEmpty(); |
| 7987 | } |
| 7988 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7989 | OMPClause *Sema::ActOnOpenMPReductionClause( |
| 7990 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, SourceLocation LParenLoc, |
| 7991 | SourceLocation ColonLoc, SourceLocation EndLoc, |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 7992 | CXXScopeSpec &ReductionIdScopeSpec, const DeclarationNameInfo &ReductionId, |
| 7993 | ArrayRef<Expr *> UnresolvedReductions) { |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7994 | auto DN = ReductionId.getName(); |
| 7995 | auto OOK = DN.getCXXOverloadedOperator(); |
| 7996 | BinaryOperatorKind BOK = BO_Comma; |
| 7997 | |
| 7998 | // OpenMP [2.14.3.6, reduction clause] |
| 7999 | // C |
| 8000 | // reduction-identifier is either an identifier or one of the following |
| 8001 | // operators: +, -, *, &, |, ^, && and || |
| 8002 | // C++ |
| 8003 | // reduction-identifier is either an id-expression or one of the following |
| 8004 | // operators: +, -, *, &, |, ^, && and || |
| 8005 | // FIXME: Only 'min' and 'max' identifiers are supported for now. |
| 8006 | switch (OOK) { |
| 8007 | case OO_Plus: |
| 8008 | case OO_Minus: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8009 | BOK = BO_Add; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8010 | break; |
| 8011 | case OO_Star: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8012 | BOK = BO_Mul; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8013 | break; |
| 8014 | case OO_Amp: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8015 | BOK = BO_And; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8016 | break; |
| 8017 | case OO_Pipe: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8018 | BOK = BO_Or; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8019 | break; |
| 8020 | case OO_Caret: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8021 | BOK = BO_Xor; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8022 | break; |
| 8023 | case OO_AmpAmp: |
| 8024 | BOK = BO_LAnd; |
| 8025 | break; |
| 8026 | case OO_PipePipe: |
| 8027 | BOK = BO_LOr; |
| 8028 | break; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8029 | case OO_New: |
| 8030 | case OO_Delete: |
| 8031 | case OO_Array_New: |
| 8032 | case OO_Array_Delete: |
| 8033 | case OO_Slash: |
| 8034 | case OO_Percent: |
| 8035 | case OO_Tilde: |
| 8036 | case OO_Exclaim: |
| 8037 | case OO_Equal: |
| 8038 | case OO_Less: |
| 8039 | case OO_Greater: |
| 8040 | case OO_LessEqual: |
| 8041 | case OO_GreaterEqual: |
| 8042 | case OO_PlusEqual: |
| 8043 | case OO_MinusEqual: |
| 8044 | case OO_StarEqual: |
| 8045 | case OO_SlashEqual: |
| 8046 | case OO_PercentEqual: |
| 8047 | case OO_CaretEqual: |
| 8048 | case OO_AmpEqual: |
| 8049 | case OO_PipeEqual: |
| 8050 | case OO_LessLess: |
| 8051 | case OO_GreaterGreater: |
| 8052 | case OO_LessLessEqual: |
| 8053 | case OO_GreaterGreaterEqual: |
| 8054 | case OO_EqualEqual: |
| 8055 | case OO_ExclaimEqual: |
| 8056 | case OO_PlusPlus: |
| 8057 | case OO_MinusMinus: |
| 8058 | case OO_Comma: |
| 8059 | case OO_ArrowStar: |
| 8060 | case OO_Arrow: |
| 8061 | case OO_Call: |
| 8062 | case OO_Subscript: |
| 8063 | case OO_Conditional: |
Richard Smith | 9be594e | 2015-10-22 05:12:22 +0000 | [diff] [blame] | 8064 | case OO_Coawait: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8065 | case NUM_OVERLOADED_OPERATORS: |
| 8066 | llvm_unreachable("Unexpected reduction identifier"); |
| 8067 | case OO_None: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8068 | if (auto II = DN.getAsIdentifierInfo()) { |
| 8069 | if (II->isStr("max")) |
| 8070 | BOK = BO_GT; |
| 8071 | else if (II->isStr("min")) |
| 8072 | BOK = BO_LT; |
| 8073 | } |
| 8074 | break; |
| 8075 | } |
| 8076 | SourceRange ReductionIdRange; |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8077 | if (ReductionIdScopeSpec.isValid()) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8078 | ReductionIdRange.setBegin(ReductionIdScopeSpec.getBeginLoc()); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8079 | ReductionIdRange.setEnd(ReductionId.getEndLoc()); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8080 | |
| 8081 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8082 | SmallVector<Expr *, 8> Privates; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8083 | SmallVector<Expr *, 8> LHSs; |
| 8084 | SmallVector<Expr *, 8> RHSs; |
| 8085 | SmallVector<Expr *, 8> ReductionOps; |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 8086 | SmallVector<Decl *, 4> ExprCaptures; |
| 8087 | SmallVector<Expr *, 4> ExprPostUpdates; |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8088 | auto IR = UnresolvedReductions.begin(), ER = UnresolvedReductions.end(); |
| 8089 | bool FirstIter = true; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8090 | for (auto RefExpr : VarList) { |
| 8091 | assert(RefExpr && "nullptr expr in OpenMP reduction clause."); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8092 | // OpenMP [2.1, C/C++] |
| 8093 | // A list item is a variable or array section, subject to the restrictions |
| 8094 | // specified in Section 2.4 on page 42 and in each of the sections |
| 8095 | // describing clauses and directives for which a list appears. |
| 8096 | // OpenMP [2.14.3.3, Restrictions, p.1] |
| 8097 | // A variable that is part of another variable (as an array or |
| 8098 | // structure element) cannot appear in a private clause. |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8099 | if (!FirstIter && IR != ER) |
| 8100 | ++IR; |
| 8101 | FirstIter = false; |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8102 | SourceLocation ELoc; |
| 8103 | SourceRange ERange; |
| 8104 | Expr *SimpleRefExpr = RefExpr; |
| 8105 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange, |
| 8106 | /*AllowArraySection=*/true); |
| 8107 | if (Res.second) { |
| 8108 | // It will be analyzed later. |
| 8109 | Vars.push_back(RefExpr); |
| 8110 | Privates.push_back(nullptr); |
| 8111 | LHSs.push_back(nullptr); |
| 8112 | RHSs.push_back(nullptr); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8113 | // Try to find 'declare reduction' corresponding construct before using |
| 8114 | // builtin/overloaded operators. |
| 8115 | QualType Type = Context.DependentTy; |
| 8116 | CXXCastPath BasePath; |
| 8117 | ExprResult DeclareReductionRef = buildDeclareReductionRef( |
| 8118 | *this, ELoc, ERange, DSAStack->getCurScope(), ReductionIdScopeSpec, |
| 8119 | ReductionId, Type, BasePath, IR == ER ? nullptr : *IR); |
| 8120 | if (CurContext->isDependentContext() && |
| 8121 | (DeclareReductionRef.isUnset() || |
| 8122 | isa<UnresolvedLookupExpr>(DeclareReductionRef.get()))) |
| 8123 | ReductionOps.push_back(DeclareReductionRef.get()); |
| 8124 | else |
| 8125 | ReductionOps.push_back(nullptr); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8126 | } |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8127 | ValueDecl *D = Res.first; |
| 8128 | if (!D) |
| 8129 | continue; |
| 8130 | |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8131 | QualType Type; |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8132 | auto *ASE = dyn_cast<ArraySubscriptExpr>(RefExpr->IgnoreParens()); |
| 8133 | auto *OASE = dyn_cast<OMPArraySectionExpr>(RefExpr->IgnoreParens()); |
| 8134 | if (ASE) |
Alexey Bataev | 31300ed | 2016-02-04 11:27:03 +0000 | [diff] [blame] | 8135 | Type = ASE->getType().getNonReferenceType(); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8136 | else if (OASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8137 | auto BaseType = OMPArraySectionExpr::getBaseOriginalType(OASE->getBase()); |
| 8138 | if (auto *ATy = BaseType->getAsArrayTypeUnsafe()) |
| 8139 | Type = ATy->getElementType(); |
| 8140 | else |
| 8141 | Type = BaseType->getPointeeType(); |
Alexey Bataev | 31300ed | 2016-02-04 11:27:03 +0000 | [diff] [blame] | 8142 | Type = Type.getNonReferenceType(); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8143 | } else |
| 8144 | Type = Context.getBaseElementType(D->getType().getNonReferenceType()); |
| 8145 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8146 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8147 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 8148 | // A variable that appears in a private clause must not have an incomplete |
| 8149 | // type or a reference type. |
| 8150 | if (RequireCompleteType(ELoc, Type, |
| 8151 | diag::err_omp_reduction_incomplete_type)) |
| 8152 | continue; |
| 8153 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8154 | // A list item that appears in a reduction clause must not be |
| 8155 | // const-qualified. |
| 8156 | if (Type.getNonReferenceType().isConstant(Context)) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8157 | Diag(ELoc, diag::err_omp_const_reduction_list_item) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8158 | << getOpenMPClauseName(OMPC_reduction) << Type << ERange; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8159 | if (!ASE && !OASE) { |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8160 | bool IsDecl = !VD || |
| 8161 | VD->isThisDeclarationADefinition(Context) == |
| 8162 | VarDecl::DeclarationOnly; |
| 8163 | Diag(D->getLocation(), |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8164 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8165 | << D; |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8166 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8167 | continue; |
| 8168 | } |
| 8169 | // OpenMP [2.9.3.6, Restrictions, C/C++, p.4] |
| 8170 | // If a list-item is a reference type then it must bind to the same object |
| 8171 | // for all threads of the team. |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8172 | if (!ASE && !OASE && VD) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8173 | VarDecl *VDDef = VD->getDefinition(); |
Alexey Bataev | 31300ed | 2016-02-04 11:27:03 +0000 | [diff] [blame] | 8174 | if (VD->getType()->isReferenceType() && VDDef) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8175 | DSARefChecker Check(DSAStack); |
| 8176 | if (Check.Visit(VDDef->getInit())) { |
| 8177 | Diag(ELoc, diag::err_omp_reduction_ref_type_arg) << ERange; |
| 8178 | Diag(VDDef->getLocation(), diag::note_defined_here) << VDDef; |
| 8179 | continue; |
| 8180 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8181 | } |
| 8182 | } |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8183 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8184 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 8185 | // in a Construct] |
| 8186 | // Variables with the predetermined data-sharing attributes may not be |
| 8187 | // listed in data-sharing attributes clauses, except for the cases |
| 8188 | // listed below. For these exceptions only, listing a predetermined |
| 8189 | // variable in a data-sharing attribute clause is allowed and overrides |
| 8190 | // the variable's predetermined data-sharing attributes. |
| 8191 | // OpenMP [2.14.3.6, Restrictions, p.3] |
| 8192 | // Any number of reduction clauses can be specified on the directive, |
| 8193 | // but a list item can appear only once in the reduction clauses for that |
| 8194 | // directive. |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8195 | DSAStackTy::DSAVarData DVar; |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8196 | DVar = DSAStack->getTopDSA(D, false); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8197 | if (DVar.CKind == OMPC_reduction) { |
| 8198 | Diag(ELoc, diag::err_omp_once_referenced) |
| 8199 | << getOpenMPClauseName(OMPC_reduction); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8200 | if (DVar.RefExpr) |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8201 | Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_referenced); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8202 | } else if (DVar.CKind != OMPC_unknown) { |
| 8203 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 8204 | << getOpenMPClauseName(DVar.CKind) |
| 8205 | << getOpenMPClauseName(OMPC_reduction); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8206 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8207 | continue; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8208 | } |
| 8209 | |
| 8210 | // OpenMP [2.14.3.6, Restrictions, p.1] |
| 8211 | // A list item that appears in a reduction clause of a worksharing |
| 8212 | // construct must be shared in the parallel regions to which any of the |
| 8213 | // worksharing regions arising from the worksharing construct bind. |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8214 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
| 8215 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 8216 | !isOpenMPParallelDirective(CurrDir)) { |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8217 | DVar = DSAStack->getImplicitDSA(D, true); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8218 | if (DVar.CKind != OMPC_shared) { |
| 8219 | Diag(ELoc, diag::err_omp_required_access) |
| 8220 | << getOpenMPClauseName(OMPC_reduction) |
| 8221 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8222 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8223 | continue; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 8224 | } |
| 8225 | } |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8226 | |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8227 | // Try to find 'declare reduction' corresponding construct before using |
| 8228 | // builtin/overloaded operators. |
| 8229 | CXXCastPath BasePath; |
| 8230 | ExprResult DeclareReductionRef = buildDeclareReductionRef( |
| 8231 | *this, ELoc, ERange, DSAStack->getCurScope(), ReductionIdScopeSpec, |
| 8232 | ReductionId, Type, BasePath, IR == ER ? nullptr : *IR); |
| 8233 | if (DeclareReductionRef.isInvalid()) |
| 8234 | continue; |
| 8235 | if (CurContext->isDependentContext() && |
| 8236 | (DeclareReductionRef.isUnset() || |
| 8237 | isa<UnresolvedLookupExpr>(DeclareReductionRef.get()))) { |
| 8238 | Vars.push_back(RefExpr); |
| 8239 | Privates.push_back(nullptr); |
| 8240 | LHSs.push_back(nullptr); |
| 8241 | RHSs.push_back(nullptr); |
| 8242 | ReductionOps.push_back(DeclareReductionRef.get()); |
| 8243 | continue; |
| 8244 | } |
| 8245 | if (BOK == BO_Comma && DeclareReductionRef.isUnset()) { |
| 8246 | // Not allowed reduction identifier is found. |
| 8247 | Diag(ReductionId.getLocStart(), |
| 8248 | diag::err_omp_unknown_reduction_identifier) |
| 8249 | << Type << ReductionIdRange; |
| 8250 | continue; |
| 8251 | } |
| 8252 | |
| 8253 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
| 8254 | // The type of a list item that appears in a reduction clause must be valid |
| 8255 | // for the reduction-identifier. For a max or min reduction in C, the type |
| 8256 | // of the list item must be an allowed arithmetic data type: char, int, |
| 8257 | // float, double, or _Bool, possibly modified with long, short, signed, or |
| 8258 | // unsigned. For a max or min reduction in C++, the type of the list item |
| 8259 | // must be an allowed arithmetic data type: char, wchar_t, int, float, |
| 8260 | // double, or bool, possibly modified with long, short, signed, or unsigned. |
| 8261 | if (DeclareReductionRef.isUnset()) { |
| 8262 | if ((BOK == BO_GT || BOK == BO_LT) && |
| 8263 | !(Type->isScalarType() || |
| 8264 | (getLangOpts().CPlusPlus && Type->isArithmeticType()))) { |
| 8265 | Diag(ELoc, diag::err_omp_clause_not_arithmetic_type_arg) |
| 8266 | << getLangOpts().CPlusPlus; |
| 8267 | if (!ASE && !OASE) { |
| 8268 | bool IsDecl = !VD || |
| 8269 | VD->isThisDeclarationADefinition(Context) == |
| 8270 | VarDecl::DeclarationOnly; |
| 8271 | Diag(D->getLocation(), |
| 8272 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 8273 | << D; |
| 8274 | } |
| 8275 | continue; |
| 8276 | } |
| 8277 | if ((BOK == BO_OrAssign || BOK == BO_AndAssign || BOK == BO_XorAssign) && |
| 8278 | !getLangOpts().CPlusPlus && Type->isFloatingType()) { |
| 8279 | Diag(ELoc, diag::err_omp_clause_floating_type_arg); |
| 8280 | if (!ASE && !OASE) { |
| 8281 | bool IsDecl = !VD || |
| 8282 | VD->isThisDeclarationADefinition(Context) == |
| 8283 | VarDecl::DeclarationOnly; |
| 8284 | Diag(D->getLocation(), |
| 8285 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 8286 | << D; |
| 8287 | } |
| 8288 | continue; |
| 8289 | } |
| 8290 | } |
| 8291 | |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8292 | Type = Type.getNonLValueExprType(Context).getUnqualifiedType(); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8293 | auto *LHSVD = buildVarDecl(*this, ELoc, Type, ".reduction.lhs", |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8294 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 8295 | auto *RHSVD = buildVarDecl(*this, ELoc, Type, D->getName(), |
| 8296 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8297 | auto PrivateTy = Type; |
Alexey Bataev | 1189bd0 | 2016-01-26 12:20:39 +0000 | [diff] [blame] | 8298 | if (OASE || |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8299 | (!ASE && |
| 8300 | D->getType().getNonReferenceType()->isVariablyModifiedType())) { |
Alexey Bataev | 1189bd0 | 2016-01-26 12:20:39 +0000 | [diff] [blame] | 8301 | // For arays/array sections only: |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8302 | // Create pseudo array type for private copy. The size for this array will |
| 8303 | // be generated during codegen. |
| 8304 | // For array subscripts or single variables Private Ty is the same as Type |
| 8305 | // (type of the variable or single array element). |
| 8306 | PrivateTy = Context.getVariableArrayType( |
| 8307 | Type, new (Context) OpaqueValueExpr(SourceLocation(), |
| 8308 | Context.getSizeType(), VK_RValue), |
| 8309 | ArrayType::Normal, /*IndexTypeQuals=*/0, SourceRange()); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8310 | } else if (!ASE && !OASE && |
| 8311 | Context.getAsArrayType(D->getType().getNonReferenceType())) |
| 8312 | PrivateTy = D->getType().getNonReferenceType(); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8313 | // Private copy. |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8314 | auto *PrivateVD = buildVarDecl(*this, ELoc, PrivateTy, D->getName(), |
| 8315 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8316 | // Add initializer for private variable. |
| 8317 | Expr *Init = nullptr; |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8318 | auto *LHSDRE = buildDeclRefExpr(*this, LHSVD, Type, ELoc); |
| 8319 | auto *RHSDRE = buildDeclRefExpr(*this, RHSVD, Type, ELoc); |
| 8320 | if (DeclareReductionRef.isUsable()) { |
| 8321 | auto *DRDRef = DeclareReductionRef.getAs<DeclRefExpr>(); |
| 8322 | auto *DRD = cast<OMPDeclareReductionDecl>(DRDRef->getDecl()); |
| 8323 | if (DRD->getInitializer()) { |
| 8324 | Init = DRDRef; |
| 8325 | RHSVD->setInit(DRDRef); |
| 8326 | RHSVD->setInitStyle(VarDecl::CallInit); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8327 | } |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8328 | } else { |
| 8329 | switch (BOK) { |
| 8330 | case BO_Add: |
| 8331 | case BO_Xor: |
| 8332 | case BO_Or: |
| 8333 | case BO_LOr: |
| 8334 | // '+', '-', '^', '|', '||' reduction ops - initializer is '0'. |
| 8335 | if (Type->isScalarType() || Type->isAnyComplexType()) |
| 8336 | Init = ActOnIntegerConstant(ELoc, /*Val=*/0).get(); |
| 8337 | break; |
| 8338 | case BO_Mul: |
| 8339 | case BO_LAnd: |
| 8340 | if (Type->isScalarType() || Type->isAnyComplexType()) { |
| 8341 | // '*' and '&&' reduction ops - initializer is '1'. |
| 8342 | Init = ActOnIntegerConstant(ELoc, /*Val=*/1).get(); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8343 | } |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8344 | break; |
| 8345 | case BO_And: { |
| 8346 | // '&' reduction op - initializer is '~0'. |
| 8347 | QualType OrigType = Type; |
| 8348 | if (auto *ComplexTy = OrigType->getAs<ComplexType>()) |
| 8349 | Type = ComplexTy->getElementType(); |
| 8350 | if (Type->isRealFloatingType()) { |
| 8351 | llvm::APFloat InitValue = |
| 8352 | llvm::APFloat::getAllOnesValue(Context.getTypeSize(Type), |
| 8353 | /*isIEEE=*/true); |
| 8354 | Init = FloatingLiteral::Create(Context, InitValue, /*isexact=*/true, |
| 8355 | Type, ELoc); |
| 8356 | } else if (Type->isScalarType()) { |
| 8357 | auto Size = Context.getTypeSize(Type); |
| 8358 | QualType IntTy = Context.getIntTypeForBitwidth(Size, /*Signed=*/0); |
| 8359 | llvm::APInt InitValue = llvm::APInt::getAllOnesValue(Size); |
| 8360 | Init = IntegerLiteral::Create(Context, InitValue, IntTy, ELoc); |
| 8361 | } |
| 8362 | if (Init && OrigType->isAnyComplexType()) { |
| 8363 | // Init = 0xFFFF + 0xFFFFi; |
| 8364 | auto *Im = new (Context) ImaginaryLiteral(Init, OrigType); |
| 8365 | Init = CreateBuiltinBinOp(ELoc, BO_Add, Init, Im).get(); |
| 8366 | } |
| 8367 | Type = OrigType; |
| 8368 | break; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8369 | } |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8370 | case BO_LT: |
| 8371 | case BO_GT: { |
| 8372 | // 'min' reduction op - initializer is 'Largest representable number in |
| 8373 | // the reduction list item type'. |
| 8374 | // 'max' reduction op - initializer is 'Least representable number in |
| 8375 | // the reduction list item type'. |
| 8376 | if (Type->isIntegerType() || Type->isPointerType()) { |
| 8377 | bool IsSigned = Type->hasSignedIntegerRepresentation(); |
| 8378 | auto Size = Context.getTypeSize(Type); |
| 8379 | QualType IntTy = |
| 8380 | Context.getIntTypeForBitwidth(Size, /*Signed=*/IsSigned); |
| 8381 | llvm::APInt InitValue = |
| 8382 | (BOK != BO_LT) |
| 8383 | ? IsSigned ? llvm::APInt::getSignedMinValue(Size) |
| 8384 | : llvm::APInt::getMinValue(Size) |
| 8385 | : IsSigned ? llvm::APInt::getSignedMaxValue(Size) |
| 8386 | : llvm::APInt::getMaxValue(Size); |
| 8387 | Init = IntegerLiteral::Create(Context, InitValue, IntTy, ELoc); |
| 8388 | if (Type->isPointerType()) { |
| 8389 | // Cast to pointer type. |
| 8390 | auto CastExpr = BuildCStyleCastExpr( |
| 8391 | SourceLocation(), Context.getTrivialTypeSourceInfo(Type, ELoc), |
| 8392 | SourceLocation(), Init); |
| 8393 | if (CastExpr.isInvalid()) |
| 8394 | continue; |
| 8395 | Init = CastExpr.get(); |
| 8396 | } |
| 8397 | } else if (Type->isRealFloatingType()) { |
| 8398 | llvm::APFloat InitValue = llvm::APFloat::getLargest( |
| 8399 | Context.getFloatTypeSemantics(Type), BOK != BO_LT); |
| 8400 | Init = FloatingLiteral::Create(Context, InitValue, /*isexact=*/true, |
| 8401 | Type, ELoc); |
| 8402 | } |
| 8403 | break; |
| 8404 | } |
| 8405 | case BO_PtrMemD: |
| 8406 | case BO_PtrMemI: |
| 8407 | case BO_MulAssign: |
| 8408 | case BO_Div: |
| 8409 | case BO_Rem: |
| 8410 | case BO_Sub: |
| 8411 | case BO_Shl: |
| 8412 | case BO_Shr: |
| 8413 | case BO_LE: |
| 8414 | case BO_GE: |
| 8415 | case BO_EQ: |
| 8416 | case BO_NE: |
| 8417 | case BO_AndAssign: |
| 8418 | case BO_XorAssign: |
| 8419 | case BO_OrAssign: |
| 8420 | case BO_Assign: |
| 8421 | case BO_AddAssign: |
| 8422 | case BO_SubAssign: |
| 8423 | case BO_DivAssign: |
| 8424 | case BO_RemAssign: |
| 8425 | case BO_ShlAssign: |
| 8426 | case BO_ShrAssign: |
| 8427 | case BO_Comma: |
| 8428 | llvm_unreachable("Unexpected reduction operation"); |
| 8429 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8430 | } |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8431 | if (Init && DeclareReductionRef.isUnset()) { |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8432 | AddInitializerToDecl(RHSVD, Init, /*DirectInit=*/false, |
| 8433 | /*TypeMayContainAuto=*/false); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8434 | } else if (!Init) |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8435 | ActOnUninitializedDecl(RHSVD, /*TypeMayContainAuto=*/false); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8436 | if (RHSVD->isInvalidDecl()) |
| 8437 | continue; |
| 8438 | if (!RHSVD->hasInit() && DeclareReductionRef.isUnset()) { |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8439 | Diag(ELoc, diag::err_omp_reduction_id_not_compatible) << Type |
| 8440 | << ReductionIdRange; |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8441 | bool IsDecl = |
| 8442 | !VD || |
| 8443 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 8444 | Diag(D->getLocation(), |
| 8445 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 8446 | << D; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8447 | continue; |
| 8448 | } |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8449 | // Store initializer for single element in private copy. Will be used during |
| 8450 | // codegen. |
| 8451 | PrivateVD->setInit(RHSVD->getInit()); |
| 8452 | PrivateVD->setInitStyle(RHSVD->getInitStyle()); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8453 | auto *PrivateDRE = buildDeclRefExpr(*this, PrivateVD, PrivateTy, ELoc); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8454 | ExprResult ReductionOp; |
| 8455 | if (DeclareReductionRef.isUsable()) { |
| 8456 | QualType RedTy = DeclareReductionRef.get()->getType(); |
| 8457 | QualType PtrRedTy = Context.getPointerType(RedTy); |
| 8458 | ExprResult LHS = CreateBuiltinUnaryOp(ELoc, UO_AddrOf, LHSDRE); |
| 8459 | ExprResult RHS = CreateBuiltinUnaryOp(ELoc, UO_AddrOf, RHSDRE); |
| 8460 | if (!BasePath.empty()) { |
| 8461 | LHS = DefaultLvalueConversion(LHS.get()); |
| 8462 | RHS = DefaultLvalueConversion(RHS.get()); |
| 8463 | LHS = ImplicitCastExpr::Create(Context, PtrRedTy, |
| 8464 | CK_UncheckedDerivedToBase, LHS.get(), |
| 8465 | &BasePath, LHS.get()->getValueKind()); |
| 8466 | RHS = ImplicitCastExpr::Create(Context, PtrRedTy, |
| 8467 | CK_UncheckedDerivedToBase, RHS.get(), |
| 8468 | &BasePath, RHS.get()->getValueKind()); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8469 | } |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8470 | FunctionProtoType::ExtProtoInfo EPI; |
| 8471 | QualType Params[] = {PtrRedTy, PtrRedTy}; |
| 8472 | QualType FnTy = Context.getFunctionType(Context.VoidTy, Params, EPI); |
| 8473 | auto *OVE = new (Context) OpaqueValueExpr( |
| 8474 | ELoc, Context.getPointerType(FnTy), VK_RValue, OK_Ordinary, |
| 8475 | DefaultLvalueConversion(DeclareReductionRef.get()).get()); |
| 8476 | Expr *Args[] = {LHS.get(), RHS.get()}; |
| 8477 | ReductionOp = new (Context) |
| 8478 | CallExpr(Context, OVE, Args, Context.VoidTy, VK_RValue, ELoc); |
| 8479 | } else { |
| 8480 | ReductionOp = BuildBinOp(DSAStack->getCurScope(), |
| 8481 | ReductionId.getLocStart(), BOK, LHSDRE, RHSDRE); |
| 8482 | if (ReductionOp.isUsable()) { |
| 8483 | if (BOK != BO_LT && BOK != BO_GT) { |
| 8484 | ReductionOp = |
| 8485 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), |
| 8486 | BO_Assign, LHSDRE, ReductionOp.get()); |
| 8487 | } else { |
| 8488 | auto *ConditionalOp = new (Context) ConditionalOperator( |
| 8489 | ReductionOp.get(), SourceLocation(), LHSDRE, SourceLocation(), |
| 8490 | RHSDRE, Type, VK_LValue, OK_Ordinary); |
| 8491 | ReductionOp = |
| 8492 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), |
| 8493 | BO_Assign, LHSDRE, ConditionalOp); |
| 8494 | } |
| 8495 | ReductionOp = ActOnFinishFullExpr(ReductionOp.get()); |
| 8496 | } |
| 8497 | if (ReductionOp.isInvalid()) |
| 8498 | continue; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8499 | } |
| 8500 | |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8501 | DeclRefExpr *Ref = nullptr; |
| 8502 | Expr *VarsExpr = RefExpr->IgnoreParens(); |
| 8503 | if (!VD) { |
| 8504 | if (ASE || OASE) { |
| 8505 | TransformExprToCaptures RebuildToCapture(*this, D); |
| 8506 | VarsExpr = |
| 8507 | RebuildToCapture.TransformExpr(RefExpr->IgnoreParens()).get(); |
| 8508 | Ref = RebuildToCapture.getCapturedExpr(); |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 8509 | } else { |
| 8510 | VarsExpr = Ref = |
| 8511 | buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false); |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 8512 | } |
| 8513 | if (!IsOpenMPCapturedDecl(D)) { |
| 8514 | ExprCaptures.push_back(Ref->getDecl()); |
| 8515 | if (Ref->getDecl()->hasAttr<OMPCaptureNoInitAttr>()) { |
| 8516 | ExprResult RefRes = DefaultLvalueConversion(Ref); |
| 8517 | if (!RefRes.isUsable()) |
| 8518 | continue; |
| 8519 | ExprResult PostUpdateRes = |
| 8520 | BuildBinOp(DSAStack->getCurScope(), ELoc, BO_Assign, |
| 8521 | SimpleRefExpr, RefRes.get()); |
| 8522 | if (!PostUpdateRes.isUsable()) |
| 8523 | continue; |
| 8524 | ExprPostUpdates.push_back( |
| 8525 | IgnoredValueConversions(PostUpdateRes.get()).get()); |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 8526 | } |
| 8527 | } |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8528 | } |
| 8529 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_reduction, Ref); |
| 8530 | Vars.push_back(VarsExpr); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8531 | Privates.push_back(PrivateDRE); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8532 | LHSs.push_back(LHSDRE); |
| 8533 | RHSs.push_back(RHSDRE); |
| 8534 | ReductionOps.push_back(ReductionOp.get()); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8535 | } |
| 8536 | |
| 8537 | if (Vars.empty()) |
| 8538 | return nullptr; |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 8539 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8540 | return OMPReductionClause::Create( |
| 8541 | Context, StartLoc, LParenLoc, ColonLoc, EndLoc, Vars, |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8542 | ReductionIdScopeSpec.getWithLocInContext(Context), ReductionId, Privates, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 8543 | LHSs, RHSs, ReductionOps, buildPreInits(Context, ExprCaptures), |
| 8544 | buildPostUpdate(*this, ExprPostUpdates)); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8545 | } |
| 8546 | |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 8547 | OMPClause *Sema::ActOnOpenMPLinearClause( |
| 8548 | ArrayRef<Expr *> VarList, Expr *Step, SourceLocation StartLoc, |
| 8549 | SourceLocation LParenLoc, OpenMPLinearClauseKind LinKind, |
| 8550 | SourceLocation LinLoc, SourceLocation ColonLoc, SourceLocation EndLoc) { |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8551 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8552 | SmallVector<Expr *, 8> Privates; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8553 | SmallVector<Expr *, 8> Inits; |
Alexey Bataev | 78849fb | 2016-03-09 09:49:00 +0000 | [diff] [blame] | 8554 | SmallVector<Decl *, 4> ExprCaptures; |
| 8555 | SmallVector<Expr *, 4> ExprPostUpdates; |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 8556 | if ((!LangOpts.CPlusPlus && LinKind != OMPC_LINEAR_val) || |
| 8557 | LinKind == OMPC_LINEAR_unknown) { |
| 8558 | Diag(LinLoc, diag::err_omp_wrong_linear_modifier) << LangOpts.CPlusPlus; |
| 8559 | LinKind = OMPC_LINEAR_val; |
| 8560 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8561 | for (auto &RefExpr : VarList) { |
| 8562 | assert(RefExpr && "NULL expr in OpenMP linear clause."); |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8563 | SourceLocation ELoc; |
| 8564 | SourceRange ERange; |
| 8565 | Expr *SimpleRefExpr = RefExpr; |
| 8566 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange, |
| 8567 | /*AllowArraySection=*/false); |
| 8568 | if (Res.second) { |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8569 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8570 | Vars.push_back(RefExpr); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8571 | Privates.push_back(nullptr); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8572 | Inits.push_back(nullptr); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8573 | } |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8574 | ValueDecl *D = Res.first; |
| 8575 | if (!D) |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8576 | continue; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8577 | |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8578 | QualType Type = D->getType(); |
| 8579 | auto *VD = dyn_cast<VarDecl>(D); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8580 | |
| 8581 | // OpenMP [2.14.3.7, linear clause] |
| 8582 | // A list-item cannot appear in more than one linear clause. |
| 8583 | // A list-item that appears in a linear clause cannot appear in any |
| 8584 | // other data-sharing attribute clause. |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8585 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8586 | if (DVar.RefExpr) { |
| 8587 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 8588 | << getOpenMPClauseName(OMPC_linear); |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8589 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8590 | continue; |
| 8591 | } |
| 8592 | |
| 8593 | // A variable must not have an incomplete type or a reference type. |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8594 | if (RequireCompleteType(ELoc, Type, |
| 8595 | diag::err_omp_linear_incomplete_type)) |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8596 | continue; |
Alexey Bataev | 1185e19 | 2015-08-20 12:15:57 +0000 | [diff] [blame] | 8597 | if ((LinKind == OMPC_LINEAR_uval || LinKind == OMPC_LINEAR_ref) && |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8598 | !Type->isReferenceType()) { |
Alexey Bataev | 1185e19 | 2015-08-20 12:15:57 +0000 | [diff] [blame] | 8599 | Diag(ELoc, diag::err_omp_wrong_linear_modifier_non_reference) |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8600 | << Type << getOpenMPSimpleClauseTypeName(OMPC_linear, LinKind); |
Alexey Bataev | 1185e19 | 2015-08-20 12:15:57 +0000 | [diff] [blame] | 8601 | continue; |
| 8602 | } |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8603 | Type = Type.getNonReferenceType(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8604 | |
| 8605 | // A list item must not be const-qualified. |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8606 | if (Type.isConstant(Context)) { |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8607 | Diag(ELoc, diag::err_omp_const_variable) |
| 8608 | << getOpenMPClauseName(OMPC_linear); |
| 8609 | bool IsDecl = |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8610 | !VD || |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8611 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8612 | Diag(D->getLocation(), |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8613 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8614 | << D; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8615 | continue; |
| 8616 | } |
| 8617 | |
| 8618 | // A list item must be of integral or pointer type. |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8619 | Type = Type.getUnqualifiedType().getCanonicalType(); |
| 8620 | const auto *Ty = Type.getTypePtrOrNull(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8621 | if (!Ty || (!Ty->isDependentType() && !Ty->isIntegralType(Context) && |
| 8622 | !Ty->isPointerType())) { |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8623 | Diag(ELoc, diag::err_omp_linear_expected_int_or_ptr) << Type; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8624 | bool IsDecl = |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8625 | !VD || |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8626 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8627 | Diag(D->getLocation(), |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8628 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8629 | << D; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8630 | continue; |
| 8631 | } |
| 8632 | |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8633 | // Build private copy of original var. |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8634 | auto *Private = buildVarDecl(*this, ELoc, Type, D->getName(), |
| 8635 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 8636 | auto *PrivateRef = buildDeclRefExpr(*this, Private, Type, ELoc); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8637 | // Build var to save initial value. |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8638 | VarDecl *Init = buildVarDecl(*this, ELoc, Type, ".linear.start"); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 8639 | Expr *InitExpr; |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8640 | DeclRefExpr *Ref = nullptr; |
Alexey Bataev | 78849fb | 2016-03-09 09:49:00 +0000 | [diff] [blame] | 8641 | if (!VD) { |
| 8642 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false); |
| 8643 | if (!IsOpenMPCapturedDecl(D)) { |
| 8644 | ExprCaptures.push_back(Ref->getDecl()); |
| 8645 | if (Ref->getDecl()->hasAttr<OMPCaptureNoInitAttr>()) { |
| 8646 | ExprResult RefRes = DefaultLvalueConversion(Ref); |
| 8647 | if (!RefRes.isUsable()) |
| 8648 | continue; |
| 8649 | ExprResult PostUpdateRes = |
| 8650 | BuildBinOp(DSAStack->getCurScope(), ELoc, BO_Assign, |
| 8651 | SimpleRefExpr, RefRes.get()); |
| 8652 | if (!PostUpdateRes.isUsable()) |
| 8653 | continue; |
| 8654 | ExprPostUpdates.push_back( |
| 8655 | IgnoredValueConversions(PostUpdateRes.get()).get()); |
| 8656 | } |
| 8657 | } |
| 8658 | } |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 8659 | if (LinKind == OMPC_LINEAR_uval) |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8660 | InitExpr = VD ? VD->getInit() : SimpleRefExpr; |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 8661 | else |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8662 | InitExpr = VD ? SimpleRefExpr : Ref; |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 8663 | AddInitializerToDecl(Init, DefaultLvalueConversion(InitExpr).get(), |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8664 | /*DirectInit=*/false, /*TypeMayContainAuto=*/false); |
| 8665 | auto InitRef = buildDeclRefExpr(*this, Init, Type, ELoc); |
| 8666 | |
| 8667 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_linear, Ref); |
| 8668 | Vars.push_back(VD ? RefExpr->IgnoreParens() : Ref); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8669 | Privates.push_back(PrivateRef); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8670 | Inits.push_back(InitRef); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8671 | } |
| 8672 | |
| 8673 | if (Vars.empty()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 8674 | return nullptr; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8675 | |
| 8676 | Expr *StepExpr = Step; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8677 | Expr *CalcStepExpr = nullptr; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8678 | if (Step && !Step->isValueDependent() && !Step->isTypeDependent() && |
| 8679 | !Step->isInstantiationDependent() && |
| 8680 | !Step->containsUnexpandedParameterPack()) { |
| 8681 | SourceLocation StepLoc = Step->getLocStart(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 8682 | ExprResult Val = PerformOpenMPImplicitIntegerConversion(StepLoc, Step); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8683 | if (Val.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 8684 | return nullptr; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 8685 | StepExpr = Val.get(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8686 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8687 | // Build var to save the step value. |
| 8688 | VarDecl *SaveVar = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 8689 | buildVarDecl(*this, StepLoc, StepExpr->getType(), ".linear.step"); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8690 | ExprResult SaveRef = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 8691 | buildDeclRefExpr(*this, SaveVar, StepExpr->getType(), StepLoc); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8692 | ExprResult CalcStep = |
| 8693 | BuildBinOp(CurScope, StepLoc, BO_Assign, SaveRef.get(), StepExpr); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 8694 | CalcStep = ActOnFinishFullExpr(CalcStep.get()); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8695 | |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8696 | // Warn about zero linear step (it would be probably better specified as |
| 8697 | // making corresponding variables 'const'). |
| 8698 | llvm::APSInt Result; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8699 | bool IsConstant = StepExpr->isIntegerConstantExpr(Result, Context); |
| 8700 | if (IsConstant && !Result.isNegative() && !Result.isStrictlyPositive()) |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8701 | Diag(StepLoc, diag::warn_omp_linear_step_zero) << Vars[0] |
| 8702 | << (Vars.size() > 1); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8703 | if (!IsConstant && CalcStep.isUsable()) { |
| 8704 | // Calculate the step beforehand instead of doing this on each iteration. |
| 8705 | // (This is not used if the number of iterations may be kfold-ed). |
| 8706 | CalcStepExpr = CalcStep.get(); |
| 8707 | } |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8708 | } |
| 8709 | |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 8710 | return OMPLinearClause::Create(Context, StartLoc, LParenLoc, LinKind, LinLoc, |
| 8711 | ColonLoc, EndLoc, Vars, Privates, Inits, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 8712 | StepExpr, CalcStepExpr, |
| 8713 | buildPreInits(Context, ExprCaptures), |
| 8714 | buildPostUpdate(*this, ExprPostUpdates)); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8715 | } |
| 8716 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 8717 | static bool |
| 8718 | FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV, |
| 8719 | Expr *NumIterations, Sema &SemaRef, Scope *S) { |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8720 | // Walk the vars and build update/final expressions for the CodeGen. |
| 8721 | SmallVector<Expr *, 8> Updates; |
| 8722 | SmallVector<Expr *, 8> Finals; |
| 8723 | Expr *Step = Clause.getStep(); |
| 8724 | Expr *CalcStep = Clause.getCalcStep(); |
| 8725 | // OpenMP [2.14.3.7, linear clause] |
| 8726 | // If linear-step is not specified it is assumed to be 1. |
| 8727 | if (Step == nullptr) |
| 8728 | Step = SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get(); |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 8729 | else if (CalcStep) { |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8730 | Step = cast<BinaryOperator>(CalcStep)->getLHS(); |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 8731 | } |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8732 | bool HasErrors = false; |
| 8733 | auto CurInit = Clause.inits().begin(); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8734 | auto CurPrivate = Clause.privates().begin(); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 8735 | auto LinKind = Clause.getModifier(); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8736 | for (auto &RefExpr : Clause.varlists()) { |
| 8737 | Expr *InitExpr = *CurInit; |
| 8738 | |
| 8739 | // Build privatized reference to the current linear var. |
| 8740 | auto DE = cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 8741 | Expr *CapturedRef; |
| 8742 | if (LinKind == OMPC_LINEAR_uval) |
| 8743 | CapturedRef = cast<VarDecl>(DE->getDecl())->getInit(); |
| 8744 | else |
| 8745 | CapturedRef = |
| 8746 | buildDeclRefExpr(SemaRef, cast<VarDecl>(DE->getDecl()), |
| 8747 | DE->getType().getUnqualifiedType(), DE->getExprLoc(), |
| 8748 | /*RefersToCapture=*/true); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8749 | |
| 8750 | // Build update: Var = InitExpr + IV * Step |
| 8751 | ExprResult Update = |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8752 | BuildCounterUpdate(SemaRef, S, RefExpr->getExprLoc(), *CurPrivate, |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8753 | InitExpr, IV, Step, /* Subtract */ false); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 8754 | Update = SemaRef.ActOnFinishFullExpr(Update.get(), DE->getLocStart(), |
| 8755 | /*DiscardedValue=*/true); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8756 | |
| 8757 | // Build final: Var = InitExpr + NumIterations * Step |
| 8758 | ExprResult Final = |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8759 | BuildCounterUpdate(SemaRef, S, RefExpr->getExprLoc(), CapturedRef, |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 8760 | InitExpr, NumIterations, Step, /* Subtract */ false); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 8761 | Final = SemaRef.ActOnFinishFullExpr(Final.get(), DE->getLocStart(), |
| 8762 | /*DiscardedValue=*/true); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8763 | if (!Update.isUsable() || !Final.isUsable()) { |
| 8764 | Updates.push_back(nullptr); |
| 8765 | Finals.push_back(nullptr); |
| 8766 | HasErrors = true; |
| 8767 | } else { |
| 8768 | Updates.push_back(Update.get()); |
| 8769 | Finals.push_back(Final.get()); |
| 8770 | } |
Richard Trieu | cc3949d | 2016-02-18 22:34:54 +0000 | [diff] [blame] | 8771 | ++CurInit; |
| 8772 | ++CurPrivate; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8773 | } |
| 8774 | Clause.setUpdates(Updates); |
| 8775 | Clause.setFinals(Finals); |
| 8776 | return HasErrors; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8777 | } |
| 8778 | |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 8779 | OMPClause *Sema::ActOnOpenMPAlignedClause( |
| 8780 | ArrayRef<Expr *> VarList, Expr *Alignment, SourceLocation StartLoc, |
| 8781 | SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc) { |
| 8782 | |
| 8783 | SmallVector<Expr *, 8> Vars; |
| 8784 | for (auto &RefExpr : VarList) { |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 8785 | assert(RefExpr && "NULL expr in OpenMP linear clause."); |
| 8786 | SourceLocation ELoc; |
| 8787 | SourceRange ERange; |
| 8788 | Expr *SimpleRefExpr = RefExpr; |
| 8789 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange, |
| 8790 | /*AllowArraySection=*/false); |
| 8791 | if (Res.second) { |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 8792 | // It will be analyzed later. |
| 8793 | Vars.push_back(RefExpr); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 8794 | } |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 8795 | ValueDecl *D = Res.first; |
| 8796 | if (!D) |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 8797 | continue; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 8798 | |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 8799 | QualType QType = D->getType(); |
| 8800 | auto *VD = dyn_cast<VarDecl>(D); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 8801 | |
| 8802 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 8803 | // The type of list items appearing in the aligned clause must be |
| 8804 | // array, pointer, reference to array, or reference to pointer. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8805 | QType = QType.getNonReferenceType().getUnqualifiedType().getCanonicalType(); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 8806 | const Type *Ty = QType.getTypePtrOrNull(); |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 8807 | if (!Ty || (!Ty->isArrayType() && !Ty->isPointerType())) { |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 8808 | Diag(ELoc, diag::err_omp_aligned_expected_array_or_ptr) |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 8809 | << QType << getLangOpts().CPlusPlus << ERange; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 8810 | bool IsDecl = |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 8811 | !VD || |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 8812 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 8813 | Diag(D->getLocation(), |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 8814 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 8815 | << D; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 8816 | continue; |
| 8817 | } |
| 8818 | |
| 8819 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 8820 | // A list-item cannot appear in more than one aligned clause. |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 8821 | if (Expr *PrevRef = DSAStack->addUniqueAligned(D, SimpleRefExpr)) { |
| 8822 | Diag(ELoc, diag::err_omp_aligned_twice) << ERange; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 8823 | Diag(PrevRef->getExprLoc(), diag::note_omp_explicit_dsa) |
| 8824 | << getOpenMPClauseName(OMPC_aligned); |
| 8825 | continue; |
| 8826 | } |
| 8827 | |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 8828 | DeclRefExpr *Ref = nullptr; |
| 8829 | if (!VD && IsOpenMPCapturedDecl(D)) |
| 8830 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/true); |
| 8831 | Vars.push_back(DefaultFunctionArrayConversion( |
| 8832 | (VD || !Ref) ? RefExpr->IgnoreParens() : Ref) |
| 8833 | .get()); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 8834 | } |
| 8835 | |
| 8836 | // OpenMP [2.8.1, simd construct, Description] |
| 8837 | // The parameter of the aligned clause, alignment, must be a constant |
| 8838 | // positive integer expression. |
| 8839 | // If no optional parameter is specified, implementation-defined default |
| 8840 | // alignments for SIMD instructions on the target platforms are assumed. |
| 8841 | if (Alignment != nullptr) { |
| 8842 | ExprResult AlignResult = |
| 8843 | VerifyPositiveIntegerConstantInClause(Alignment, OMPC_aligned); |
| 8844 | if (AlignResult.isInvalid()) |
| 8845 | return nullptr; |
| 8846 | Alignment = AlignResult.get(); |
| 8847 | } |
| 8848 | if (Vars.empty()) |
| 8849 | return nullptr; |
| 8850 | |
| 8851 | return OMPAlignedClause::Create(Context, StartLoc, LParenLoc, ColonLoc, |
| 8852 | EndLoc, Vars, Alignment); |
| 8853 | } |
| 8854 | |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8855 | OMPClause *Sema::ActOnOpenMPCopyinClause(ArrayRef<Expr *> VarList, |
| 8856 | SourceLocation StartLoc, |
| 8857 | SourceLocation LParenLoc, |
| 8858 | SourceLocation EndLoc) { |
| 8859 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 8860 | SmallVector<Expr *, 8> SrcExprs; |
| 8861 | SmallVector<Expr *, 8> DstExprs; |
| 8862 | SmallVector<Expr *, 8> AssignmentOps; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8863 | for (auto &RefExpr : VarList) { |
| 8864 | assert(RefExpr && "NULL expr in OpenMP copyin clause."); |
| 8865 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8866 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8867 | Vars.push_back(RefExpr); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 8868 | SrcExprs.push_back(nullptr); |
| 8869 | DstExprs.push_back(nullptr); |
| 8870 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8871 | continue; |
| 8872 | } |
| 8873 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8874 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8875 | // OpenMP [2.1, C/C++] |
| 8876 | // A list item is a variable name. |
| 8877 | // OpenMP [2.14.4.1, Restrictions, p.1] |
| 8878 | // A list item that appears in a copyin clause must be threadprivate. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8879 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8880 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8881 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr) |
| 8882 | << 0 << RefExpr->getSourceRange(); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8883 | continue; |
| 8884 | } |
| 8885 | |
| 8886 | Decl *D = DE->getDecl(); |
| 8887 | VarDecl *VD = cast<VarDecl>(D); |
| 8888 | |
| 8889 | QualType Type = VD->getType(); |
| 8890 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 8891 | // It will be analyzed later. |
| 8892 | Vars.push_back(DE); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 8893 | SrcExprs.push_back(nullptr); |
| 8894 | DstExprs.push_back(nullptr); |
| 8895 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8896 | continue; |
| 8897 | } |
| 8898 | |
| 8899 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.1] |
| 8900 | // A list item that appears in a copyin clause must be threadprivate. |
| 8901 | if (!DSAStack->isThreadPrivate(VD)) { |
| 8902 | Diag(ELoc, diag::err_omp_required_access) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8903 | << getOpenMPClauseName(OMPC_copyin) |
| 8904 | << getOpenMPDirectiveName(OMPD_threadprivate); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8905 | continue; |
| 8906 | } |
| 8907 | |
| 8908 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.2] |
| 8909 | // A variable of class type (or array thereof) that appears in a |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 8910 | // copyin clause requires an accessible, unambiguous copy assignment |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8911 | // operator for the class type. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8912 | auto ElemType = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 8913 | auto *SrcVD = |
| 8914 | buildVarDecl(*this, DE->getLocStart(), ElemType.getUnqualifiedType(), |
| 8915 | ".copyin.src", VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 8916 | auto *PseudoSrcExpr = buildDeclRefExpr( |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8917 | *this, SrcVD, ElemType.getUnqualifiedType(), DE->getExprLoc()); |
| 8918 | auto *DstVD = |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 8919 | buildVarDecl(*this, DE->getLocStart(), ElemType, ".copyin.dst", |
| 8920 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 8921 | auto *PseudoDstExpr = |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8922 | buildDeclRefExpr(*this, DstVD, ElemType, DE->getExprLoc()); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 8923 | // For arrays generate assignment operation for single element and replace |
| 8924 | // it by the original array element in CodeGen. |
| 8925 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, DE->getExprLoc(), BO_Assign, |
| 8926 | PseudoDstExpr, PseudoSrcExpr); |
| 8927 | if (AssignmentOp.isInvalid()) |
| 8928 | continue; |
| 8929 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), DE->getExprLoc(), |
| 8930 | /*DiscardedValue=*/true); |
| 8931 | if (AssignmentOp.isInvalid()) |
| 8932 | continue; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8933 | |
| 8934 | DSAStack->addDSA(VD, DE, OMPC_copyin); |
| 8935 | Vars.push_back(DE); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 8936 | SrcExprs.push_back(PseudoSrcExpr); |
| 8937 | DstExprs.push_back(PseudoDstExpr); |
| 8938 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8939 | } |
| 8940 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8941 | if (Vars.empty()) |
| 8942 | return nullptr; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8943 | |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 8944 | return OMPCopyinClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
| 8945 | SrcExprs, DstExprs, AssignmentOps); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8946 | } |
| 8947 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8948 | OMPClause *Sema::ActOnOpenMPCopyprivateClause(ArrayRef<Expr *> VarList, |
| 8949 | SourceLocation StartLoc, |
| 8950 | SourceLocation LParenLoc, |
| 8951 | SourceLocation EndLoc) { |
| 8952 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 8953 | SmallVector<Expr *, 8> SrcExprs; |
| 8954 | SmallVector<Expr *, 8> DstExprs; |
| 8955 | SmallVector<Expr *, 8> AssignmentOps; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8956 | for (auto &RefExpr : VarList) { |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 8957 | assert(RefExpr && "NULL expr in OpenMP linear clause."); |
| 8958 | SourceLocation ELoc; |
| 8959 | SourceRange ERange; |
| 8960 | Expr *SimpleRefExpr = RefExpr; |
| 8961 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange, |
| 8962 | /*AllowArraySection=*/false); |
| 8963 | if (Res.second) { |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8964 | // It will be analyzed later. |
| 8965 | Vars.push_back(RefExpr); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 8966 | SrcExprs.push_back(nullptr); |
| 8967 | DstExprs.push_back(nullptr); |
| 8968 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8969 | } |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 8970 | ValueDecl *D = Res.first; |
| 8971 | if (!D) |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8972 | continue; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8973 | |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 8974 | QualType Type = D->getType(); |
| 8975 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8976 | |
| 8977 | // OpenMP [2.14.4.2, Restrictions, p.2] |
| 8978 | // A list item that appears in a copyprivate clause may not appear in a |
| 8979 | // private or firstprivate clause on the single construct. |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 8980 | if (!VD || !DSAStack->isThreadPrivate(VD)) { |
| 8981 | auto DVar = DSAStack->getTopDSA(D, false); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 8982 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_copyprivate && |
| 8983 | DVar.RefExpr) { |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8984 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 8985 | << getOpenMPClauseName(DVar.CKind) |
| 8986 | << getOpenMPClauseName(OMPC_copyprivate); |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 8987 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8988 | continue; |
| 8989 | } |
| 8990 | |
| 8991 | // OpenMP [2.11.4.2, Restrictions, p.1] |
| 8992 | // All list items that appear in a copyprivate clause must be either |
| 8993 | // threadprivate or private in the enclosing context. |
| 8994 | if (DVar.CKind == OMPC_unknown) { |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 8995 | DVar = DSAStack->getImplicitDSA(D, false); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8996 | if (DVar.CKind == OMPC_shared) { |
| 8997 | Diag(ELoc, diag::err_omp_required_access) |
| 8998 | << getOpenMPClauseName(OMPC_copyprivate) |
| 8999 | << "threadprivate or private in the enclosing context"; |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9000 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9001 | continue; |
| 9002 | } |
| 9003 | } |
| 9004 | } |
| 9005 | |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 9006 | // Variably modified types are not supported. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 9007 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType()) { |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 9008 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 9009 | << getOpenMPClauseName(OMPC_copyprivate) << Type |
| 9010 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 9011 | bool IsDecl = |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9012 | !VD || |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 9013 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9014 | Diag(D->getLocation(), |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 9015 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9016 | << D; |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 9017 | continue; |
| 9018 | } |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 9019 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9020 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.2] |
| 9021 | // A variable of class type (or array thereof) that appears in a |
| 9022 | // copyin clause requires an accessible, unambiguous copy assignment |
| 9023 | // operator for the class type. |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 9024 | Type = Context.getBaseElementType(Type.getNonReferenceType()) |
| 9025 | .getUnqualifiedType(); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 9026 | auto *SrcVD = |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9027 | buildVarDecl(*this, RefExpr->getLocStart(), Type, ".copyprivate.src", |
| 9028 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 9029 | auto *PseudoSrcExpr = buildDeclRefExpr(*this, SrcVD, Type, ELoc); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 9030 | auto *DstVD = |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9031 | buildVarDecl(*this, RefExpr->getLocStart(), Type, ".copyprivate.dst", |
| 9032 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 9033 | auto *PseudoDstExpr = |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9034 | buildDeclRefExpr(*this, DstVD, Type, ELoc); |
| 9035 | auto AssignmentOp = BuildBinOp(DSAStack->getCurScope(), ELoc, BO_Assign, |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 9036 | PseudoDstExpr, PseudoSrcExpr); |
| 9037 | if (AssignmentOp.isInvalid()) |
| 9038 | continue; |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9039 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), ELoc, |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 9040 | /*DiscardedValue=*/true); |
| 9041 | if (AssignmentOp.isInvalid()) |
| 9042 | continue; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9043 | |
| 9044 | // No need to mark vars as copyprivate, they are already threadprivate or |
| 9045 | // implicitly private. |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9046 | assert(VD || IsOpenMPCapturedDecl(D)); |
| 9047 | Vars.push_back( |
| 9048 | VD ? RefExpr->IgnoreParens() |
| 9049 | : buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false)); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 9050 | SrcExprs.push_back(PseudoSrcExpr); |
| 9051 | DstExprs.push_back(PseudoDstExpr); |
| 9052 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9053 | } |
| 9054 | |
| 9055 | if (Vars.empty()) |
| 9056 | return nullptr; |
| 9057 | |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 9058 | return OMPCopyprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| 9059 | Vars, SrcExprs, DstExprs, AssignmentOps); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9060 | } |
| 9061 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 9062 | OMPClause *Sema::ActOnOpenMPFlushClause(ArrayRef<Expr *> VarList, |
| 9063 | SourceLocation StartLoc, |
| 9064 | SourceLocation LParenLoc, |
| 9065 | SourceLocation EndLoc) { |
| 9066 | if (VarList.empty()) |
| 9067 | return nullptr; |
| 9068 | |
| 9069 | return OMPFlushClause::Create(Context, StartLoc, LParenLoc, EndLoc, VarList); |
| 9070 | } |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 9071 | |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 9072 | OMPClause * |
| 9073 | Sema::ActOnOpenMPDependClause(OpenMPDependClauseKind DepKind, |
| 9074 | SourceLocation DepLoc, SourceLocation ColonLoc, |
| 9075 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
| 9076 | SourceLocation LParenLoc, SourceLocation EndLoc) { |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 9077 | if (DSAStack->getCurrentDirective() == OMPD_ordered && |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 9078 | DepKind != OMPC_DEPEND_source && DepKind != OMPC_DEPEND_sink) { |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 9079 | Diag(DepLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 9080 | << "'source' or 'sink'" << getOpenMPClauseName(OMPC_depend); |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 9081 | return nullptr; |
| 9082 | } |
| 9083 | if (DSAStack->getCurrentDirective() != OMPD_ordered && |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 9084 | (DepKind == OMPC_DEPEND_unknown || DepKind == OMPC_DEPEND_source || |
| 9085 | DepKind == OMPC_DEPEND_sink)) { |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 9086 | unsigned Except[] = {OMPC_DEPEND_source, OMPC_DEPEND_sink}; |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 9087 | Diag(DepLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 9088 | << getListOfPossibleValues(OMPC_depend, /*First=*/0, |
| 9089 | /*Last=*/OMPC_DEPEND_unknown, Except) |
| 9090 | << getOpenMPClauseName(OMPC_depend); |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 9091 | return nullptr; |
| 9092 | } |
| 9093 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 9094 | llvm::APSInt DepCounter(/*BitWidth=*/32); |
| 9095 | llvm::APSInt TotalDepCount(/*BitWidth=*/32); |
| 9096 | if (DepKind == OMPC_DEPEND_sink) { |
| 9097 | if (auto *OrderedCountExpr = DSAStack->getParentOrderedRegionParam()) { |
| 9098 | TotalDepCount = OrderedCountExpr->EvaluateKnownConstInt(Context); |
| 9099 | TotalDepCount.setIsUnsigned(/*Val=*/true); |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 9100 | } |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 9101 | } |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 9102 | if ((DepKind != OMPC_DEPEND_sink && DepKind != OMPC_DEPEND_source) || |
| 9103 | DSAStack->getParentOrderedRegionParam()) { |
| 9104 | for (auto &RefExpr : VarList) { |
| 9105 | assert(RefExpr && "NULL expr in OpenMP shared clause."); |
| 9106 | if (isa<DependentScopeDeclRefExpr>(RefExpr) || |
| 9107 | (DepKind == OMPC_DEPEND_sink && CurContext->isDependentContext())) { |
| 9108 | // It will be analyzed later. |
| 9109 | Vars.push_back(RefExpr); |
| 9110 | continue; |
| 9111 | } |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 9112 | |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 9113 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 9114 | auto *SimpleExpr = RefExpr->IgnoreParenCasts(); |
| 9115 | if (DepKind == OMPC_DEPEND_sink) { |
| 9116 | if (DepCounter >= TotalDepCount) { |
| 9117 | Diag(ELoc, diag::err_omp_depend_sink_unexpected_expr); |
| 9118 | continue; |
| 9119 | } |
| 9120 | ++DepCounter; |
| 9121 | // OpenMP [2.13.9, Summary] |
| 9122 | // depend(dependence-type : vec), where dependence-type is: |
| 9123 | // 'sink' and where vec is the iteration vector, which has the form: |
| 9124 | // x1 [+- d1], x2 [+- d2 ], . . . , xn [+- dn] |
| 9125 | // where n is the value specified by the ordered clause in the loop |
| 9126 | // directive, xi denotes the loop iteration variable of the i-th nested |
| 9127 | // loop associated with the loop directive, and di is a constant |
| 9128 | // non-negative integer. |
| 9129 | SimpleExpr = SimpleExpr->IgnoreImplicit(); |
| 9130 | auto *DE = dyn_cast<DeclRefExpr>(SimpleExpr); |
| 9131 | if (!DE) { |
| 9132 | OverloadedOperatorKind OOK = OO_None; |
| 9133 | SourceLocation OOLoc; |
| 9134 | Expr *LHS, *RHS; |
| 9135 | if (auto *BO = dyn_cast<BinaryOperator>(SimpleExpr)) { |
| 9136 | OOK = BinaryOperator::getOverloadedOperator(BO->getOpcode()); |
| 9137 | OOLoc = BO->getOperatorLoc(); |
| 9138 | LHS = BO->getLHS()->IgnoreParenImpCasts(); |
| 9139 | RHS = BO->getRHS()->IgnoreParenImpCasts(); |
| 9140 | } else if (auto *OCE = dyn_cast<CXXOperatorCallExpr>(SimpleExpr)) { |
| 9141 | OOK = OCE->getOperator(); |
| 9142 | OOLoc = OCE->getOperatorLoc(); |
| 9143 | LHS = OCE->getArg(/*Arg=*/0)->IgnoreParenImpCasts(); |
| 9144 | RHS = OCE->getArg(/*Arg=*/1)->IgnoreParenImpCasts(); |
| 9145 | } else if (auto *MCE = dyn_cast<CXXMemberCallExpr>(SimpleExpr)) { |
| 9146 | OOK = MCE->getMethodDecl() |
| 9147 | ->getNameInfo() |
| 9148 | .getName() |
| 9149 | .getCXXOverloadedOperator(); |
| 9150 | OOLoc = MCE->getCallee()->getExprLoc(); |
| 9151 | LHS = MCE->getImplicitObjectArgument()->IgnoreParenImpCasts(); |
| 9152 | RHS = MCE->getArg(/*Arg=*/0)->IgnoreParenImpCasts(); |
| 9153 | } else { |
| 9154 | Diag(ELoc, diag::err_omp_depend_sink_wrong_expr); |
| 9155 | continue; |
| 9156 | } |
| 9157 | DE = dyn_cast<DeclRefExpr>(LHS); |
| 9158 | if (!DE) { |
| 9159 | Diag(LHS->getExprLoc(), |
| 9160 | diag::err_omp_depend_sink_expected_loop_iteration) |
| 9161 | << DSAStack->getParentLoopControlVariable( |
| 9162 | DepCounter.getZExtValue()); |
| 9163 | continue; |
| 9164 | } |
| 9165 | if (OOK != OO_Plus && OOK != OO_Minus) { |
| 9166 | Diag(OOLoc, diag::err_omp_depend_sink_expected_plus_minus); |
| 9167 | continue; |
| 9168 | } |
| 9169 | ExprResult Res = VerifyPositiveIntegerConstantInClause( |
| 9170 | RHS, OMPC_depend, /*StrictlyPositive=*/false); |
| 9171 | if (Res.isInvalid()) |
| 9172 | continue; |
| 9173 | } |
| 9174 | auto *VD = dyn_cast<VarDecl>(DE->getDecl()); |
| 9175 | if (!CurContext->isDependentContext() && |
| 9176 | DSAStack->getParentOrderedRegionParam() && |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 9177 | (!VD || |
| 9178 | DepCounter != DSAStack->isParentLoopControlVariable(VD).first)) { |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 9179 | Diag(DE->getExprLoc(), |
| 9180 | diag::err_omp_depend_sink_expected_loop_iteration) |
| 9181 | << DSAStack->getParentLoopControlVariable( |
| 9182 | DepCounter.getZExtValue()); |
| 9183 | continue; |
| 9184 | } |
| 9185 | } else { |
| 9186 | // OpenMP [2.11.1.1, Restrictions, p.3] |
| 9187 | // A variable that is part of another variable (such as a field of a |
| 9188 | // structure) but is not an array element or an array section cannot |
| 9189 | // appear in a depend clause. |
| 9190 | auto *DE = dyn_cast<DeclRefExpr>(SimpleExpr); |
| 9191 | auto *ASE = dyn_cast<ArraySubscriptExpr>(SimpleExpr); |
| 9192 | auto *OASE = dyn_cast<OMPArraySectionExpr>(SimpleExpr); |
| 9193 | if (!RefExpr->IgnoreParenImpCasts()->isLValue() || |
| 9194 | (!ASE && !DE && !OASE) || (DE && !isa<VarDecl>(DE->getDecl())) || |
Alexey Bataev | 31300ed | 2016-02-04 11:27:03 +0000 | [diff] [blame] | 9195 | (ASE && |
| 9196 | !ASE->getBase() |
| 9197 | ->getType() |
| 9198 | .getNonReferenceType() |
| 9199 | ->isPointerType() && |
| 9200 | !ASE->getBase()->getType().getNonReferenceType()->isArrayType())) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 9201 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr_or_array_item) |
| 9202 | << 0 << RefExpr->getSourceRange(); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 9203 | continue; |
| 9204 | } |
| 9205 | } |
| 9206 | |
| 9207 | Vars.push_back(RefExpr->IgnoreParenImpCasts()); |
| 9208 | } |
| 9209 | |
| 9210 | if (!CurContext->isDependentContext() && DepKind == OMPC_DEPEND_sink && |
| 9211 | TotalDepCount > VarList.size() && |
| 9212 | DSAStack->getParentOrderedRegionParam()) { |
| 9213 | Diag(EndLoc, diag::err_omp_depend_sink_expected_loop_iteration) |
| 9214 | << DSAStack->getParentLoopControlVariable(VarList.size() + 1); |
| 9215 | } |
| 9216 | if (DepKind != OMPC_DEPEND_source && DepKind != OMPC_DEPEND_sink && |
| 9217 | Vars.empty()) |
| 9218 | return nullptr; |
| 9219 | } |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 9220 | |
| 9221 | return OMPDependClause::Create(Context, StartLoc, LParenLoc, EndLoc, DepKind, |
| 9222 | DepLoc, ColonLoc, Vars); |
| 9223 | } |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 9224 | |
| 9225 | OMPClause *Sema::ActOnOpenMPDeviceClause(Expr *Device, SourceLocation StartLoc, |
| 9226 | SourceLocation LParenLoc, |
| 9227 | SourceLocation EndLoc) { |
| 9228 | Expr *ValExpr = Device; |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 9229 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 9230 | // OpenMP [2.9.1, Restrictions] |
| 9231 | // The device expression must evaluate to a non-negative integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 9232 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_device, |
| 9233 | /*StrictlyPositive=*/false)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 9234 | return nullptr; |
| 9235 | |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 9236 | return new (Context) OMPDeviceClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 9237 | } |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9238 | |
| 9239 | static bool IsCXXRecordForMappable(Sema &SemaRef, SourceLocation Loc, |
| 9240 | DSAStackTy *Stack, CXXRecordDecl *RD) { |
| 9241 | if (!RD || RD->isInvalidDecl()) |
| 9242 | return true; |
| 9243 | |
Alexey Bataev | c9bd03d | 2015-12-17 06:55:08 +0000 | [diff] [blame] | 9244 | if (auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(RD)) |
| 9245 | if (auto *CTD = CTSD->getSpecializedTemplate()) |
| 9246 | RD = CTD->getTemplatedDecl(); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9247 | auto QTy = SemaRef.Context.getRecordType(RD); |
| 9248 | if (RD->isDynamicClass()) { |
| 9249 | SemaRef.Diag(Loc, diag::err_omp_not_mappable_type) << QTy; |
| 9250 | SemaRef.Diag(RD->getLocation(), diag::note_omp_polymorphic_in_target); |
| 9251 | return false; |
| 9252 | } |
| 9253 | auto *DC = RD; |
| 9254 | bool IsCorrect = true; |
| 9255 | for (auto *I : DC->decls()) { |
| 9256 | if (I) { |
| 9257 | if (auto *MD = dyn_cast<CXXMethodDecl>(I)) { |
| 9258 | if (MD->isStatic()) { |
| 9259 | SemaRef.Diag(Loc, diag::err_omp_not_mappable_type) << QTy; |
| 9260 | SemaRef.Diag(MD->getLocation(), |
| 9261 | diag::note_omp_static_member_in_target); |
| 9262 | IsCorrect = false; |
| 9263 | } |
| 9264 | } else if (auto *VD = dyn_cast<VarDecl>(I)) { |
| 9265 | if (VD->isStaticDataMember()) { |
| 9266 | SemaRef.Diag(Loc, diag::err_omp_not_mappable_type) << QTy; |
| 9267 | SemaRef.Diag(VD->getLocation(), |
| 9268 | diag::note_omp_static_member_in_target); |
| 9269 | IsCorrect = false; |
| 9270 | } |
| 9271 | } |
| 9272 | } |
| 9273 | } |
| 9274 | |
| 9275 | for (auto &I : RD->bases()) { |
| 9276 | if (!IsCXXRecordForMappable(SemaRef, I.getLocStart(), Stack, |
| 9277 | I.getType()->getAsCXXRecordDecl())) |
| 9278 | IsCorrect = false; |
| 9279 | } |
| 9280 | return IsCorrect; |
| 9281 | } |
| 9282 | |
| 9283 | static bool CheckTypeMappable(SourceLocation SL, SourceRange SR, Sema &SemaRef, |
| 9284 | DSAStackTy *Stack, QualType QTy) { |
| 9285 | NamedDecl *ND; |
| 9286 | if (QTy->isIncompleteType(&ND)) { |
| 9287 | SemaRef.Diag(SL, diag::err_incomplete_type) << QTy << SR; |
| 9288 | return false; |
| 9289 | } else if (CXXRecordDecl *RD = dyn_cast_or_null<CXXRecordDecl>(ND)) { |
| 9290 | if (!RD->isInvalidDecl() && |
| 9291 | !IsCXXRecordForMappable(SemaRef, SL, Stack, RD)) |
| 9292 | return false; |
| 9293 | } |
| 9294 | return true; |
| 9295 | } |
| 9296 | |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 9297 | /// \brief Return true if it can be proven that the provided array expression |
| 9298 | /// (array section or array subscript) does NOT specify the whole size of the |
| 9299 | /// array whose base type is \a BaseQTy. |
| 9300 | static bool CheckArrayExpressionDoesNotReferToWholeSize(Sema &SemaRef, |
| 9301 | const Expr *E, |
| 9302 | QualType BaseQTy) { |
| 9303 | auto *OASE = dyn_cast<OMPArraySectionExpr>(E); |
| 9304 | |
| 9305 | // If this is an array subscript, it refers to the whole size if the size of |
| 9306 | // the dimension is constant and equals 1. Also, an array section assumes the |
| 9307 | // format of an array subscript if no colon is used. |
| 9308 | if (isa<ArraySubscriptExpr>(E) || (OASE && OASE->getColonLoc().isInvalid())) { |
| 9309 | if (auto *ATy = dyn_cast<ConstantArrayType>(BaseQTy.getTypePtr())) |
| 9310 | return ATy->getSize().getSExtValue() != 1; |
| 9311 | // Size can't be evaluated statically. |
| 9312 | return false; |
| 9313 | } |
| 9314 | |
| 9315 | assert(OASE && "Expecting array section if not an array subscript."); |
| 9316 | auto *LowerBound = OASE->getLowerBound(); |
| 9317 | auto *Length = OASE->getLength(); |
| 9318 | |
| 9319 | // If there is a lower bound that does not evaluates to zero, we are not |
| 9320 | // convering the whole dimension. |
| 9321 | if (LowerBound) { |
| 9322 | llvm::APSInt ConstLowerBound; |
| 9323 | if (!LowerBound->EvaluateAsInt(ConstLowerBound, SemaRef.getASTContext())) |
| 9324 | return false; // Can't get the integer value as a constant. |
| 9325 | if (ConstLowerBound.getSExtValue()) |
| 9326 | return true; |
| 9327 | } |
| 9328 | |
| 9329 | // If we don't have a length we covering the whole dimension. |
| 9330 | if (!Length) |
| 9331 | return false; |
| 9332 | |
| 9333 | // If the base is a pointer, we don't have a way to get the size of the |
| 9334 | // pointee. |
| 9335 | if (BaseQTy->isPointerType()) |
| 9336 | return false; |
| 9337 | |
| 9338 | // We can only check if the length is the same as the size of the dimension |
| 9339 | // if we have a constant array. |
| 9340 | auto *CATy = dyn_cast<ConstantArrayType>(BaseQTy.getTypePtr()); |
| 9341 | if (!CATy) |
| 9342 | return false; |
| 9343 | |
| 9344 | llvm::APSInt ConstLength; |
| 9345 | if (!Length->EvaluateAsInt(ConstLength, SemaRef.getASTContext())) |
| 9346 | return false; // Can't get the integer value as a constant. |
| 9347 | |
| 9348 | return CATy->getSize().getSExtValue() != ConstLength.getSExtValue(); |
| 9349 | } |
| 9350 | |
| 9351 | // Return true if it can be proven that the provided array expression (array |
| 9352 | // section or array subscript) does NOT specify a single element of the array |
| 9353 | // whose base type is \a BaseQTy. |
| 9354 | static bool CheckArrayExpressionDoesNotReferToUnitySize(Sema &SemaRef, |
| 9355 | const Expr *E, |
| 9356 | QualType BaseQTy) { |
| 9357 | auto *OASE = dyn_cast<OMPArraySectionExpr>(E); |
| 9358 | |
| 9359 | // An array subscript always refer to a single element. Also, an array section |
| 9360 | // assumes the format of an array subscript if no colon is used. |
| 9361 | if (isa<ArraySubscriptExpr>(E) || (OASE && OASE->getColonLoc().isInvalid())) |
| 9362 | return false; |
| 9363 | |
| 9364 | assert(OASE && "Expecting array section if not an array subscript."); |
| 9365 | auto *Length = OASE->getLength(); |
| 9366 | |
| 9367 | // If we don't have a length we have to check if the array has unitary size |
| 9368 | // for this dimension. Also, we should always expect a length if the base type |
| 9369 | // is pointer. |
| 9370 | if (!Length) { |
| 9371 | if (auto *ATy = dyn_cast<ConstantArrayType>(BaseQTy.getTypePtr())) |
| 9372 | return ATy->getSize().getSExtValue() != 1; |
| 9373 | // We cannot assume anything. |
| 9374 | return false; |
| 9375 | } |
| 9376 | |
| 9377 | // Check if the length evaluates to 1. |
| 9378 | llvm::APSInt ConstLength; |
| 9379 | if (!Length->EvaluateAsInt(ConstLength, SemaRef.getASTContext())) |
| 9380 | return false; // Can't get the integer value as a constant. |
| 9381 | |
| 9382 | return ConstLength.getSExtValue() != 1; |
| 9383 | } |
| 9384 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9385 | // Return the expression of the base of the map clause or null if it cannot |
| 9386 | // be determined and do all the necessary checks to see if the expression is |
| 9387 | // valid as a standalone map clause expression. |
| 9388 | static Expr *CheckMapClauseExpressionBase(Sema &SemaRef, Expr *E) { |
| 9389 | SourceLocation ELoc = E->getExprLoc(); |
| 9390 | SourceRange ERange = E->getSourceRange(); |
| 9391 | |
| 9392 | // The base of elements of list in a map clause have to be either: |
| 9393 | // - a reference to variable or field. |
| 9394 | // - a member expression. |
| 9395 | // - an array expression. |
| 9396 | // |
| 9397 | // E.g. if we have the expression 'r.S.Arr[:12]', we want to retrieve the |
| 9398 | // reference to 'r'. |
| 9399 | // |
| 9400 | // If we have: |
| 9401 | // |
| 9402 | // struct SS { |
| 9403 | // Bla S; |
| 9404 | // foo() { |
| 9405 | // #pragma omp target map (S.Arr[:12]); |
| 9406 | // } |
| 9407 | // } |
| 9408 | // |
| 9409 | // We want to retrieve the member expression 'this->S'; |
| 9410 | |
| 9411 | Expr *RelevantExpr = nullptr; |
| 9412 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9413 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.2] |
| 9414 | // If a list item is an array section, it must specify contiguous storage. |
| 9415 | // |
| 9416 | // For this restriction it is sufficient that we make sure only references |
| 9417 | // to variables or fields and array expressions, and that no array sections |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 9418 | // exist except in the rightmost expression (unless they cover the whole |
| 9419 | // dimension of the array). E.g. these would be invalid: |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9420 | // |
| 9421 | // r.ArrS[3:5].Arr[6:7] |
| 9422 | // |
| 9423 | // r.ArrS[3:5].x |
| 9424 | // |
| 9425 | // but these would be valid: |
| 9426 | // r.ArrS[3].Arr[6:7] |
| 9427 | // |
| 9428 | // r.ArrS[3].x |
| 9429 | |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 9430 | bool AllowUnitySizeArraySection = true; |
| 9431 | bool AllowWholeSizeArraySection = true; |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9432 | |
Dmitry Polukhin | 644a925 | 2016-03-11 07:58:34 +0000 | [diff] [blame] | 9433 | while (!RelevantExpr) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9434 | E = E->IgnoreParenImpCasts(); |
| 9435 | |
| 9436 | if (auto *CurE = dyn_cast<DeclRefExpr>(E)) { |
| 9437 | if (!isa<VarDecl>(CurE->getDecl())) |
| 9438 | break; |
| 9439 | |
| 9440 | RelevantExpr = CurE; |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 9441 | |
| 9442 | // If we got a reference to a declaration, we should not expect any array |
| 9443 | // section before that. |
| 9444 | AllowUnitySizeArraySection = false; |
| 9445 | AllowWholeSizeArraySection = false; |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9446 | continue; |
| 9447 | } |
| 9448 | |
| 9449 | if (auto *CurE = dyn_cast<MemberExpr>(E)) { |
| 9450 | auto *BaseE = CurE->getBase()->IgnoreParenImpCasts(); |
| 9451 | |
| 9452 | if (isa<CXXThisExpr>(BaseE)) |
| 9453 | // We found a base expression: this->Val. |
| 9454 | RelevantExpr = CurE; |
| 9455 | else |
| 9456 | E = BaseE; |
| 9457 | |
| 9458 | if (!isa<FieldDecl>(CurE->getMemberDecl())) { |
| 9459 | SemaRef.Diag(ELoc, diag::err_omp_expected_access_to_data_field) |
| 9460 | << CurE->getSourceRange(); |
| 9461 | break; |
| 9462 | } |
| 9463 | |
| 9464 | auto *FD = cast<FieldDecl>(CurE->getMemberDecl()); |
| 9465 | |
| 9466 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C/C++, p.3] |
| 9467 | // A bit-field cannot appear in a map clause. |
| 9468 | // |
| 9469 | if (FD->isBitField()) { |
| 9470 | SemaRef.Diag(ELoc, diag::err_omp_bit_fields_forbidden_in_map_clause) |
| 9471 | << CurE->getSourceRange(); |
| 9472 | break; |
| 9473 | } |
| 9474 | |
| 9475 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] |
| 9476 | // If the type of a list item is a reference to a type T then the type |
| 9477 | // will be considered to be T for all purposes of this clause. |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 9478 | QualType CurType = BaseE->getType().getNonReferenceType(); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9479 | |
| 9480 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C/C++, p.2] |
| 9481 | // A list item cannot be a variable that is a member of a structure with |
| 9482 | // a union type. |
| 9483 | // |
| 9484 | if (auto *RT = CurType->getAs<RecordType>()) |
| 9485 | if (RT->isUnionType()) { |
| 9486 | SemaRef.Diag(ELoc, diag::err_omp_union_type_not_allowed) |
| 9487 | << CurE->getSourceRange(); |
| 9488 | break; |
| 9489 | } |
| 9490 | |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 9491 | // If we got a member expression, we should not expect any array section |
| 9492 | // before that: |
| 9493 | // |
| 9494 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.7] |
| 9495 | // If a list item is an element of a structure, only the rightmost symbol |
| 9496 | // of the variable reference can be an array section. |
| 9497 | // |
| 9498 | AllowUnitySizeArraySection = false; |
| 9499 | AllowWholeSizeArraySection = false; |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9500 | continue; |
| 9501 | } |
| 9502 | |
| 9503 | if (auto *CurE = dyn_cast<ArraySubscriptExpr>(E)) { |
| 9504 | E = CurE->getBase()->IgnoreParenImpCasts(); |
| 9505 | |
| 9506 | if (!E->getType()->isAnyPointerType() && !E->getType()->isArrayType()) { |
| 9507 | SemaRef.Diag(ELoc, diag::err_omp_expected_base_var_name) |
| 9508 | << 0 << CurE->getSourceRange(); |
| 9509 | break; |
| 9510 | } |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 9511 | |
| 9512 | // If we got an array subscript that express the whole dimension we |
| 9513 | // can have any array expressions before. If it only expressing part of |
| 9514 | // the dimension, we can only have unitary-size array expressions. |
| 9515 | if (CheckArrayExpressionDoesNotReferToWholeSize(SemaRef, CurE, |
| 9516 | E->getType())) |
| 9517 | AllowWholeSizeArraySection = false; |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9518 | continue; |
| 9519 | } |
| 9520 | |
| 9521 | if (auto *CurE = dyn_cast<OMPArraySectionExpr>(E)) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9522 | E = CurE->getBase()->IgnoreParenImpCasts(); |
| 9523 | |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 9524 | auto CurType = |
| 9525 | OMPArraySectionExpr::getBaseOriginalType(E).getCanonicalType(); |
| 9526 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9527 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] |
| 9528 | // If the type of a list item is a reference to a type T then the type |
| 9529 | // will be considered to be T for all purposes of this clause. |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9530 | if (CurType->isReferenceType()) |
| 9531 | CurType = CurType->getPointeeType(); |
| 9532 | |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 9533 | bool IsPointer = CurType->isAnyPointerType(); |
| 9534 | |
| 9535 | if (!IsPointer && !CurType->isArrayType()) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9536 | SemaRef.Diag(ELoc, diag::err_omp_expected_base_var_name) |
| 9537 | << 0 << CurE->getSourceRange(); |
| 9538 | break; |
| 9539 | } |
| 9540 | |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 9541 | bool NotWhole = |
| 9542 | CheckArrayExpressionDoesNotReferToWholeSize(SemaRef, CurE, CurType); |
| 9543 | bool NotUnity = |
| 9544 | CheckArrayExpressionDoesNotReferToUnitySize(SemaRef, CurE, CurType); |
| 9545 | |
| 9546 | if (AllowWholeSizeArraySection && AllowUnitySizeArraySection) { |
| 9547 | // Any array section is currently allowed. |
| 9548 | // |
| 9549 | // If this array section refers to the whole dimension we can still |
| 9550 | // accept other array sections before this one, except if the base is a |
| 9551 | // pointer. Otherwise, only unitary sections are accepted. |
| 9552 | if (NotWhole || IsPointer) |
| 9553 | AllowWholeSizeArraySection = false; |
| 9554 | } else if ((AllowUnitySizeArraySection && NotUnity) || |
| 9555 | (AllowWholeSizeArraySection && NotWhole)) { |
| 9556 | // A unity or whole array section is not allowed and that is not |
| 9557 | // compatible with the properties of the current array section. |
| 9558 | SemaRef.Diag( |
| 9559 | ELoc, diag::err_array_section_does_not_specify_contiguous_storage) |
| 9560 | << CurE->getSourceRange(); |
| 9561 | break; |
| 9562 | } |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9563 | continue; |
| 9564 | } |
| 9565 | |
| 9566 | // If nothing else worked, this is not a valid map clause expression. |
| 9567 | SemaRef.Diag(ELoc, |
| 9568 | diag::err_omp_expected_named_var_member_or_array_expression) |
| 9569 | << ERange; |
| 9570 | break; |
| 9571 | } |
| 9572 | |
| 9573 | return RelevantExpr; |
| 9574 | } |
| 9575 | |
| 9576 | // Return true if expression E associated with value VD has conflicts with other |
| 9577 | // map information. |
| 9578 | static bool CheckMapConflicts(Sema &SemaRef, DSAStackTy *DSAS, ValueDecl *VD, |
| 9579 | Expr *E, bool CurrentRegionOnly) { |
| 9580 | assert(VD && E); |
| 9581 | |
| 9582 | // Types used to organize the components of a valid map clause. |
| 9583 | typedef std::pair<Expr *, ValueDecl *> MapExpressionComponent; |
| 9584 | typedef SmallVector<MapExpressionComponent, 4> MapExpressionComponents; |
| 9585 | |
| 9586 | // Helper to extract the components in the map clause expression E and store |
| 9587 | // them into MEC. This assumes that E is a valid map clause expression, i.e. |
| 9588 | // it has already passed the single clause checks. |
| 9589 | auto ExtractMapExpressionComponents = [](Expr *TE, |
| 9590 | MapExpressionComponents &MEC) { |
| 9591 | while (true) { |
| 9592 | TE = TE->IgnoreParenImpCasts(); |
| 9593 | |
| 9594 | if (auto *CurE = dyn_cast<DeclRefExpr>(TE)) { |
| 9595 | MEC.push_back( |
| 9596 | MapExpressionComponent(CurE, cast<VarDecl>(CurE->getDecl()))); |
| 9597 | break; |
| 9598 | } |
| 9599 | |
| 9600 | if (auto *CurE = dyn_cast<MemberExpr>(TE)) { |
| 9601 | auto *BaseE = CurE->getBase()->IgnoreParenImpCasts(); |
| 9602 | |
| 9603 | MEC.push_back(MapExpressionComponent( |
| 9604 | CurE, cast<FieldDecl>(CurE->getMemberDecl()))); |
| 9605 | if (isa<CXXThisExpr>(BaseE)) |
| 9606 | break; |
| 9607 | |
| 9608 | TE = BaseE; |
| 9609 | continue; |
| 9610 | } |
| 9611 | |
| 9612 | if (auto *CurE = dyn_cast<ArraySubscriptExpr>(TE)) { |
| 9613 | MEC.push_back(MapExpressionComponent(CurE, nullptr)); |
| 9614 | TE = CurE->getBase()->IgnoreParenImpCasts(); |
| 9615 | continue; |
| 9616 | } |
| 9617 | |
| 9618 | if (auto *CurE = dyn_cast<OMPArraySectionExpr>(TE)) { |
| 9619 | MEC.push_back(MapExpressionComponent(CurE, nullptr)); |
| 9620 | TE = CurE->getBase()->IgnoreParenImpCasts(); |
| 9621 | continue; |
| 9622 | } |
| 9623 | |
| 9624 | llvm_unreachable( |
| 9625 | "Expecting only valid map clause expressions at this point!"); |
| 9626 | } |
| 9627 | }; |
| 9628 | |
| 9629 | SourceLocation ELoc = E->getExprLoc(); |
| 9630 | SourceRange ERange = E->getSourceRange(); |
| 9631 | |
| 9632 | // In order to easily check the conflicts we need to match each component of |
| 9633 | // the expression under test with the components of the expressions that are |
| 9634 | // already in the stack. |
| 9635 | |
| 9636 | MapExpressionComponents CurComponents; |
| 9637 | ExtractMapExpressionComponents(E, CurComponents); |
| 9638 | |
| 9639 | assert(!CurComponents.empty() && "Map clause expression with no components!"); |
| 9640 | assert(CurComponents.back().second == VD && |
| 9641 | "Map clause expression with unexpected base!"); |
| 9642 | |
| 9643 | // Variables to help detecting enclosing problems in data environment nests. |
| 9644 | bool IsEnclosedByDataEnvironmentExpr = false; |
| 9645 | Expr *EnclosingExpr = nullptr; |
| 9646 | |
| 9647 | bool FoundError = |
| 9648 | DSAS->checkMapInfoForVar(VD, CurrentRegionOnly, [&](Expr *RE) -> bool { |
| 9649 | MapExpressionComponents StackComponents; |
| 9650 | ExtractMapExpressionComponents(RE, StackComponents); |
| 9651 | assert(!StackComponents.empty() && |
| 9652 | "Map clause expression with no components!"); |
| 9653 | assert(StackComponents.back().second == VD && |
| 9654 | "Map clause expression with unexpected base!"); |
| 9655 | |
| 9656 | // Expressions must start from the same base. Here we detect at which |
| 9657 | // point both expressions diverge from each other and see if we can |
| 9658 | // detect if the memory referred to both expressions is contiguous and |
| 9659 | // do not overlap. |
| 9660 | auto CI = CurComponents.rbegin(); |
| 9661 | auto CE = CurComponents.rend(); |
| 9662 | auto SI = StackComponents.rbegin(); |
| 9663 | auto SE = StackComponents.rend(); |
| 9664 | for (; CI != CE && SI != SE; ++CI, ++SI) { |
| 9665 | |
| 9666 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.3] |
| 9667 | // At most one list item can be an array item derived from a given |
| 9668 | // variable in map clauses of the same construct. |
| 9669 | if (CurrentRegionOnly && (isa<ArraySubscriptExpr>(CI->first) || |
| 9670 | isa<OMPArraySectionExpr>(CI->first)) && |
| 9671 | (isa<ArraySubscriptExpr>(SI->first) || |
| 9672 | isa<OMPArraySectionExpr>(SI->first))) { |
| 9673 | SemaRef.Diag(CI->first->getExprLoc(), |
| 9674 | diag::err_omp_multiple_array_items_in_map_clause) |
| 9675 | << CI->first->getSourceRange(); |
| 9676 | ; |
| 9677 | SemaRef.Diag(SI->first->getExprLoc(), diag::note_used_here) |
| 9678 | << SI->first->getSourceRange(); |
| 9679 | return true; |
| 9680 | } |
| 9681 | |
| 9682 | // Do both expressions have the same kind? |
| 9683 | if (CI->first->getStmtClass() != SI->first->getStmtClass()) |
| 9684 | break; |
| 9685 | |
| 9686 | // Are we dealing with different variables/fields? |
| 9687 | if (CI->second != SI->second) |
| 9688 | break; |
| 9689 | } |
| 9690 | |
| 9691 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.4] |
| 9692 | // List items of map clauses in the same construct must not share |
| 9693 | // original storage. |
| 9694 | // |
| 9695 | // If the expressions are exactly the same or one is a subset of the |
| 9696 | // other, it means they are sharing storage. |
| 9697 | if (CI == CE && SI == SE) { |
| 9698 | if (CurrentRegionOnly) { |
| 9699 | SemaRef.Diag(ELoc, diag::err_omp_map_shared_storage) << ERange; |
| 9700 | SemaRef.Diag(RE->getExprLoc(), diag::note_used_here) |
| 9701 | << RE->getSourceRange(); |
| 9702 | return true; |
| 9703 | } else { |
| 9704 | // If we find the same expression in the enclosing data environment, |
| 9705 | // that is legal. |
| 9706 | IsEnclosedByDataEnvironmentExpr = true; |
| 9707 | return false; |
| 9708 | } |
| 9709 | } |
| 9710 | |
| 9711 | QualType DerivedType = std::prev(CI)->first->getType(); |
| 9712 | SourceLocation DerivedLoc = std::prev(CI)->first->getExprLoc(); |
| 9713 | |
| 9714 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] |
| 9715 | // If the type of a list item is a reference to a type T then the type |
| 9716 | // will be considered to be T for all purposes of this clause. |
| 9717 | if (DerivedType->isReferenceType()) |
| 9718 | DerivedType = DerivedType->getPointeeType(); |
| 9719 | |
| 9720 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C/C++, p.1] |
| 9721 | // A variable for which the type is pointer and an array section |
| 9722 | // derived from that variable must not appear as list items of map |
| 9723 | // clauses of the same construct. |
| 9724 | // |
| 9725 | // Also, cover one of the cases in: |
| 9726 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.5] |
| 9727 | // If any part of the original storage of a list item has corresponding |
| 9728 | // storage in the device data environment, all of the original storage |
| 9729 | // must have corresponding storage in the device data environment. |
| 9730 | // |
| 9731 | if (DerivedType->isAnyPointerType()) { |
| 9732 | if (CI == CE || SI == SE) { |
| 9733 | SemaRef.Diag( |
| 9734 | DerivedLoc, |
| 9735 | diag::err_omp_pointer_mapped_along_with_derived_section) |
| 9736 | << DerivedLoc; |
| 9737 | } else { |
| 9738 | assert(CI != CE && SI != SE); |
| 9739 | SemaRef.Diag(DerivedLoc, diag::err_omp_same_pointer_derreferenced) |
| 9740 | << DerivedLoc; |
| 9741 | } |
| 9742 | SemaRef.Diag(RE->getExprLoc(), diag::note_used_here) |
| 9743 | << RE->getSourceRange(); |
| 9744 | return true; |
| 9745 | } |
| 9746 | |
| 9747 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.4] |
| 9748 | // List items of map clauses in the same construct must not share |
| 9749 | // original storage. |
| 9750 | // |
| 9751 | // An expression is a subset of the other. |
| 9752 | if (CurrentRegionOnly && (CI == CE || SI == SE)) { |
| 9753 | SemaRef.Diag(ELoc, diag::err_omp_map_shared_storage) << ERange; |
| 9754 | SemaRef.Diag(RE->getExprLoc(), diag::note_used_here) |
| 9755 | << RE->getSourceRange(); |
| 9756 | return true; |
| 9757 | } |
| 9758 | |
| 9759 | // The current expression uses the same base as other expression in the |
| 9760 | // data environment but does not contain it completelly. |
| 9761 | if (!CurrentRegionOnly && SI != SE) |
| 9762 | EnclosingExpr = RE; |
| 9763 | |
| 9764 | // The current expression is a subset of the expression in the data |
| 9765 | // environment. |
| 9766 | IsEnclosedByDataEnvironmentExpr |= |
| 9767 | (!CurrentRegionOnly && CI != CE && SI == SE); |
| 9768 | |
| 9769 | return false; |
| 9770 | }); |
| 9771 | |
| 9772 | if (CurrentRegionOnly) |
| 9773 | return FoundError; |
| 9774 | |
| 9775 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.5] |
| 9776 | // If any part of the original storage of a list item has corresponding |
| 9777 | // storage in the device data environment, all of the original storage must |
| 9778 | // have corresponding storage in the device data environment. |
| 9779 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.6] |
| 9780 | // If a list item is an element of a structure, and a different element of |
| 9781 | // the structure has a corresponding list item in the device data environment |
| 9782 | // prior to a task encountering the construct associated with the map clause, |
| 9783 | // then the list item must also have a correspnding list item in the device |
| 9784 | // data environment prior to the task encountering the construct. |
| 9785 | // |
| 9786 | if (EnclosingExpr && !IsEnclosedByDataEnvironmentExpr) { |
| 9787 | SemaRef.Diag(ELoc, |
| 9788 | diag::err_omp_original_storage_is_shared_and_does_not_contain) |
| 9789 | << ERange; |
| 9790 | SemaRef.Diag(EnclosingExpr->getExprLoc(), diag::note_used_here) |
| 9791 | << EnclosingExpr->getSourceRange(); |
| 9792 | return true; |
| 9793 | } |
| 9794 | |
| 9795 | return FoundError; |
| 9796 | } |
| 9797 | |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 9798 | OMPClause * |
| 9799 | Sema::ActOnOpenMPMapClause(OpenMPMapClauseKind MapTypeModifier, |
| 9800 | OpenMPMapClauseKind MapType, bool IsMapTypeImplicit, |
| 9801 | SourceLocation MapLoc, SourceLocation ColonLoc, |
| 9802 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
| 9803 | SourceLocation LParenLoc, SourceLocation EndLoc) { |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9804 | SmallVector<Expr *, 4> Vars; |
| 9805 | |
| 9806 | for (auto &RE : VarList) { |
| 9807 | assert(RE && "Null expr in omp map"); |
| 9808 | if (isa<DependentScopeDeclRefExpr>(RE)) { |
| 9809 | // It will be analyzed later. |
| 9810 | Vars.push_back(RE); |
| 9811 | continue; |
| 9812 | } |
| 9813 | SourceLocation ELoc = RE->getExprLoc(); |
| 9814 | |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9815 | auto *VE = RE->IgnoreParenLValueCasts(); |
| 9816 | |
| 9817 | if (VE->isValueDependent() || VE->isTypeDependent() || |
| 9818 | VE->isInstantiationDependent() || |
| 9819 | VE->containsUnexpandedParameterPack()) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9820 | // We can only analyze this information once the missing information is |
| 9821 | // resolved. |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9822 | Vars.push_back(RE); |
| 9823 | continue; |
| 9824 | } |
| 9825 | |
| 9826 | auto *SimpleExpr = RE->IgnoreParenCasts(); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9827 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9828 | if (!RE->IgnoreParenImpCasts()->isLValue()) { |
| 9829 | Diag(ELoc, diag::err_omp_expected_named_var_member_or_array_expression) |
| 9830 | << RE->getSourceRange(); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9831 | continue; |
| 9832 | } |
| 9833 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9834 | // Obtain the array or member expression bases if required. |
| 9835 | auto *BE = CheckMapClauseExpressionBase(*this, SimpleExpr); |
| 9836 | if (!BE) |
| 9837 | continue; |
| 9838 | |
| 9839 | // If the base is a reference to a variable, we rely on that variable for |
| 9840 | // the following checks. If it is a 'this' expression we rely on the field. |
| 9841 | ValueDecl *D = nullptr; |
| 9842 | if (auto *DRE = dyn_cast<DeclRefExpr>(BE)) { |
| 9843 | D = DRE->getDecl(); |
| 9844 | } else { |
| 9845 | auto *ME = cast<MemberExpr>(BE); |
| 9846 | assert(isa<CXXThisExpr>(ME->getBase()) && "Unexpected expression!"); |
| 9847 | D = ME->getMemberDecl(); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9848 | } |
| 9849 | assert(D && "Null decl on map clause."); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9850 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9851 | auto *VD = dyn_cast<VarDecl>(D); |
| 9852 | auto *FD = dyn_cast<FieldDecl>(D); |
| 9853 | |
| 9854 | assert((VD || FD) && "Only variables or fields are expected here!"); |
NAKAMURA Takumi | 6dcb814 | 2016-01-23 01:38:20 +0000 | [diff] [blame] | 9855 | (void)FD; |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9856 | |
| 9857 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.10] |
| 9858 | // threadprivate variables cannot appear in a map clause. |
| 9859 | if (VD && DSAStack->isThreadPrivate(VD)) { |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9860 | auto DVar = DSAStack->getTopDSA(VD, false); |
| 9861 | Diag(ELoc, diag::err_omp_threadprivate_in_map); |
| 9862 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 9863 | continue; |
| 9864 | } |
| 9865 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9866 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.9] |
| 9867 | // A list item cannot appear in both a map clause and a data-sharing |
| 9868 | // attribute clause on the same construct. |
| 9869 | // |
| 9870 | // TODO: Implement this check - it cannot currently be tested because of |
| 9871 | // missing implementation of the other data sharing clauses in target |
| 9872 | // directives. |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9873 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9874 | // Check conflicts with other map clause expressions. We check the conflicts |
| 9875 | // with the current construct separately from the enclosing data |
| 9876 | // environment, because the restrictions are different. |
| 9877 | if (CheckMapConflicts(*this, DSAStack, D, SimpleExpr, |
| 9878 | /*CurrentRegionOnly=*/true)) |
| 9879 | break; |
| 9880 | if (CheckMapConflicts(*this, DSAStack, D, SimpleExpr, |
| 9881 | /*CurrentRegionOnly=*/false)) |
| 9882 | break; |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9883 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9884 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] |
| 9885 | // If the type of a list item is a reference to a type T then the type will |
| 9886 | // be considered to be T for all purposes of this clause. |
| 9887 | QualType Type = D->getType(); |
| 9888 | if (Type->isReferenceType()) |
| 9889 | Type = Type->getPointeeType(); |
| 9890 | |
| 9891 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.9] |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9892 | // A list item must have a mappable type. |
| 9893 | if (!CheckTypeMappable(VE->getExprLoc(), VE->getSourceRange(), *this, |
| 9894 | DSAStack, Type)) |
| 9895 | continue; |
| 9896 | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 9897 | // target enter data |
| 9898 | // OpenMP [2.10.2, Restrictions, p. 99] |
| 9899 | // A map-type must be specified in all map clauses and must be either |
| 9900 | // to or alloc. |
| 9901 | OpenMPDirectiveKind DKind = DSAStack->getCurrentDirective(); |
| 9902 | if (DKind == OMPD_target_enter_data && |
| 9903 | !(MapType == OMPC_MAP_to || MapType == OMPC_MAP_alloc)) { |
| 9904 | Diag(StartLoc, diag::err_omp_invalid_map_type_for_directive) |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 9905 | << (IsMapTypeImplicit ? 1 : 0) |
| 9906 | << getOpenMPSimpleClauseTypeName(OMPC_map, MapType) |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 9907 | << getOpenMPDirectiveName(DKind); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9908 | continue; |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 9909 | } |
| 9910 | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 9911 | // target exit_data |
| 9912 | // OpenMP [2.10.3, Restrictions, p. 102] |
| 9913 | // A map-type must be specified in all map clauses and must be either |
| 9914 | // from, release, or delete. |
| 9915 | DKind = DSAStack->getCurrentDirective(); |
| 9916 | if (DKind == OMPD_target_exit_data && |
| 9917 | !(MapType == OMPC_MAP_from || MapType == OMPC_MAP_release || |
| 9918 | MapType == OMPC_MAP_delete)) { |
| 9919 | Diag(StartLoc, diag::err_omp_invalid_map_type_for_directive) |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 9920 | << (IsMapTypeImplicit ? 1 : 0) |
| 9921 | << getOpenMPSimpleClauseTypeName(OMPC_map, MapType) |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 9922 | << getOpenMPDirectiveName(DKind); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9923 | continue; |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 9924 | } |
| 9925 | |
Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 9926 | // OpenMP 4.5 [2.15.5.1, Restrictions, p.3] |
| 9927 | // A list item cannot appear in both a map clause and a data-sharing |
| 9928 | // attribute clause on the same construct |
| 9929 | if (DKind == OMPD_target && VD) { |
| 9930 | auto DVar = DSAStack->getTopDSA(VD, false); |
| 9931 | if (isOpenMPPrivate(DVar.CKind)) { |
| 9932 | Diag(ELoc, diag::err_omp_variable_in_map_and_dsa) |
| 9933 | << getOpenMPClauseName(DVar.CKind) |
| 9934 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 9935 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
| 9936 | continue; |
| 9937 | } |
| 9938 | } |
| 9939 | |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9940 | Vars.push_back(RE); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9941 | DSAStack->addExprToVarMapInfo(D, RE); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9942 | } |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9943 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9944 | // We need to produce a map clause even if we don't have variables so that |
| 9945 | // other diagnostics related with non-existing map clauses are accurate. |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9946 | return OMPMapClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 9947 | MapTypeModifier, MapType, IsMapTypeImplicit, |
| 9948 | MapLoc); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9949 | } |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 9950 | |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 9951 | QualType Sema::ActOnOpenMPDeclareReductionType(SourceLocation TyLoc, |
| 9952 | TypeResult ParsedType) { |
| 9953 | assert(ParsedType.isUsable()); |
| 9954 | |
| 9955 | QualType ReductionType = GetTypeFromParser(ParsedType.get()); |
| 9956 | if (ReductionType.isNull()) |
| 9957 | return QualType(); |
| 9958 | |
| 9959 | // [OpenMP 4.0], 2.15 declare reduction Directive, Restrictions, C\C++ |
| 9960 | // A type name in a declare reduction directive cannot be a function type, an |
| 9961 | // array type, a reference type, or a type qualified with const, volatile or |
| 9962 | // restrict. |
| 9963 | if (ReductionType.hasQualifiers()) { |
| 9964 | Diag(TyLoc, diag::err_omp_reduction_wrong_type) << 0; |
| 9965 | return QualType(); |
| 9966 | } |
| 9967 | |
| 9968 | if (ReductionType->isFunctionType()) { |
| 9969 | Diag(TyLoc, diag::err_omp_reduction_wrong_type) << 1; |
| 9970 | return QualType(); |
| 9971 | } |
| 9972 | if (ReductionType->isReferenceType()) { |
| 9973 | Diag(TyLoc, diag::err_omp_reduction_wrong_type) << 2; |
| 9974 | return QualType(); |
| 9975 | } |
| 9976 | if (ReductionType->isArrayType()) { |
| 9977 | Diag(TyLoc, diag::err_omp_reduction_wrong_type) << 3; |
| 9978 | return QualType(); |
| 9979 | } |
| 9980 | return ReductionType; |
| 9981 | } |
| 9982 | |
| 9983 | Sema::DeclGroupPtrTy Sema::ActOnOpenMPDeclareReductionDirectiveStart( |
| 9984 | Scope *S, DeclContext *DC, DeclarationName Name, |
| 9985 | ArrayRef<std::pair<QualType, SourceLocation>> ReductionTypes, |
| 9986 | AccessSpecifier AS, Decl *PrevDeclInScope) { |
| 9987 | SmallVector<Decl *, 8> Decls; |
| 9988 | Decls.reserve(ReductionTypes.size()); |
| 9989 | |
| 9990 | LookupResult Lookup(*this, Name, SourceLocation(), LookupOMPReductionName, |
| 9991 | ForRedeclaration); |
| 9992 | // [OpenMP 4.0], 2.15 declare reduction Directive, Restrictions |
| 9993 | // A reduction-identifier may not be re-declared in the current scope for the |
| 9994 | // same type or for a type that is compatible according to the base language |
| 9995 | // rules. |
| 9996 | llvm::DenseMap<QualType, SourceLocation> PreviousRedeclTypes; |
| 9997 | OMPDeclareReductionDecl *PrevDRD = nullptr; |
| 9998 | bool InCompoundScope = true; |
| 9999 | if (S != nullptr) { |
| 10000 | // Find previous declaration with the same name not referenced in other |
| 10001 | // declarations. |
| 10002 | FunctionScopeInfo *ParentFn = getEnclosingFunction(); |
| 10003 | InCompoundScope = |
| 10004 | (ParentFn != nullptr) && !ParentFn->CompoundScopes.empty(); |
| 10005 | LookupName(Lookup, S); |
| 10006 | FilterLookupForScope(Lookup, DC, S, /*ConsiderLinkage=*/false, |
| 10007 | /*AllowInlineNamespace=*/false); |
| 10008 | llvm::DenseMap<OMPDeclareReductionDecl *, bool> UsedAsPrevious; |
| 10009 | auto Filter = Lookup.makeFilter(); |
| 10010 | while (Filter.hasNext()) { |
| 10011 | auto *PrevDecl = cast<OMPDeclareReductionDecl>(Filter.next()); |
| 10012 | if (InCompoundScope) { |
| 10013 | auto I = UsedAsPrevious.find(PrevDecl); |
| 10014 | if (I == UsedAsPrevious.end()) |
| 10015 | UsedAsPrevious[PrevDecl] = false; |
| 10016 | if (auto *D = PrevDecl->getPrevDeclInScope()) |
| 10017 | UsedAsPrevious[D] = true; |
| 10018 | } |
| 10019 | PreviousRedeclTypes[PrevDecl->getType().getCanonicalType()] = |
| 10020 | PrevDecl->getLocation(); |
| 10021 | } |
| 10022 | Filter.done(); |
| 10023 | if (InCompoundScope) { |
| 10024 | for (auto &PrevData : UsedAsPrevious) { |
| 10025 | if (!PrevData.second) { |
| 10026 | PrevDRD = PrevData.first; |
| 10027 | break; |
| 10028 | } |
| 10029 | } |
| 10030 | } |
| 10031 | } else if (PrevDeclInScope != nullptr) { |
| 10032 | auto *PrevDRDInScope = PrevDRD = |
| 10033 | cast<OMPDeclareReductionDecl>(PrevDeclInScope); |
| 10034 | do { |
| 10035 | PreviousRedeclTypes[PrevDRDInScope->getType().getCanonicalType()] = |
| 10036 | PrevDRDInScope->getLocation(); |
| 10037 | PrevDRDInScope = PrevDRDInScope->getPrevDeclInScope(); |
| 10038 | } while (PrevDRDInScope != nullptr); |
| 10039 | } |
| 10040 | for (auto &TyData : ReductionTypes) { |
| 10041 | auto I = PreviousRedeclTypes.find(TyData.first.getCanonicalType()); |
| 10042 | bool Invalid = false; |
| 10043 | if (I != PreviousRedeclTypes.end()) { |
| 10044 | Diag(TyData.second, diag::err_omp_declare_reduction_redefinition) |
| 10045 | << TyData.first; |
| 10046 | Diag(I->second, diag::note_previous_definition); |
| 10047 | Invalid = true; |
| 10048 | } |
| 10049 | PreviousRedeclTypes[TyData.first.getCanonicalType()] = TyData.second; |
| 10050 | auto *DRD = OMPDeclareReductionDecl::Create(Context, DC, TyData.second, |
| 10051 | Name, TyData.first, PrevDRD); |
| 10052 | DC->addDecl(DRD); |
| 10053 | DRD->setAccess(AS); |
| 10054 | Decls.push_back(DRD); |
| 10055 | if (Invalid) |
| 10056 | DRD->setInvalidDecl(); |
| 10057 | else |
| 10058 | PrevDRD = DRD; |
| 10059 | } |
| 10060 | |
| 10061 | return DeclGroupPtrTy::make( |
| 10062 | DeclGroupRef::Create(Context, Decls.begin(), Decls.size())); |
| 10063 | } |
| 10064 | |
| 10065 | void Sema::ActOnOpenMPDeclareReductionCombinerStart(Scope *S, Decl *D) { |
| 10066 | auto *DRD = cast<OMPDeclareReductionDecl>(D); |
| 10067 | |
| 10068 | // Enter new function scope. |
| 10069 | PushFunctionScope(); |
| 10070 | getCurFunction()->setHasBranchProtectedScope(); |
| 10071 | getCurFunction()->setHasOMPDeclareReductionCombiner(); |
| 10072 | |
| 10073 | if (S != nullptr) |
| 10074 | PushDeclContext(S, DRD); |
| 10075 | else |
| 10076 | CurContext = DRD; |
| 10077 | |
| 10078 | PushExpressionEvaluationContext(PotentiallyEvaluated); |
| 10079 | |
| 10080 | QualType ReductionType = DRD->getType(); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 10081 | // Create 'T* omp_parm;T omp_in;'. All references to 'omp_in' will |
| 10082 | // be replaced by '*omp_parm' during codegen. This required because 'omp_in' |
| 10083 | // uses semantics of argument handles by value, but it should be passed by |
| 10084 | // reference. C lang does not support references, so pass all parameters as |
| 10085 | // pointers. |
| 10086 | // Create 'T omp_in;' variable. |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 10087 | auto *OmpInParm = |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 10088 | buildVarDecl(*this, D->getLocation(), ReductionType, "omp_in"); |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 10089 | // Create 'T* omp_parm;T omp_out;'. All references to 'omp_out' will |
| 10090 | // be replaced by '*omp_parm' during codegen. This required because 'omp_out' |
| 10091 | // uses semantics of argument handles by value, but it should be passed by |
| 10092 | // reference. C lang does not support references, so pass all parameters as |
| 10093 | // pointers. |
| 10094 | // Create 'T omp_out;' variable. |
| 10095 | auto *OmpOutParm = |
| 10096 | buildVarDecl(*this, D->getLocation(), ReductionType, "omp_out"); |
| 10097 | if (S != nullptr) { |
| 10098 | PushOnScopeChains(OmpInParm, S); |
| 10099 | PushOnScopeChains(OmpOutParm, S); |
| 10100 | } else { |
| 10101 | DRD->addDecl(OmpInParm); |
| 10102 | DRD->addDecl(OmpOutParm); |
| 10103 | } |
| 10104 | } |
| 10105 | |
| 10106 | void Sema::ActOnOpenMPDeclareReductionCombinerEnd(Decl *D, Expr *Combiner) { |
| 10107 | auto *DRD = cast<OMPDeclareReductionDecl>(D); |
| 10108 | DiscardCleanupsInEvaluationContext(); |
| 10109 | PopExpressionEvaluationContext(); |
| 10110 | |
| 10111 | PopDeclContext(); |
| 10112 | PopFunctionScopeInfo(); |
| 10113 | |
| 10114 | if (Combiner != nullptr) |
| 10115 | DRD->setCombiner(Combiner); |
| 10116 | else |
| 10117 | DRD->setInvalidDecl(); |
| 10118 | } |
| 10119 | |
| 10120 | void Sema::ActOnOpenMPDeclareReductionInitializerStart(Scope *S, Decl *D) { |
| 10121 | auto *DRD = cast<OMPDeclareReductionDecl>(D); |
| 10122 | |
| 10123 | // Enter new function scope. |
| 10124 | PushFunctionScope(); |
| 10125 | getCurFunction()->setHasBranchProtectedScope(); |
| 10126 | |
| 10127 | if (S != nullptr) |
| 10128 | PushDeclContext(S, DRD); |
| 10129 | else |
| 10130 | CurContext = DRD; |
| 10131 | |
| 10132 | PushExpressionEvaluationContext(PotentiallyEvaluated); |
| 10133 | |
| 10134 | QualType ReductionType = DRD->getType(); |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 10135 | // Create 'T* omp_parm;T omp_priv;'. All references to 'omp_priv' will |
| 10136 | // be replaced by '*omp_parm' during codegen. This required because 'omp_priv' |
| 10137 | // uses semantics of argument handles by value, but it should be passed by |
| 10138 | // reference. C lang does not support references, so pass all parameters as |
| 10139 | // pointers. |
| 10140 | // Create 'T omp_priv;' variable. |
| 10141 | auto *OmpPrivParm = |
| 10142 | buildVarDecl(*this, D->getLocation(), ReductionType, "omp_priv"); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 10143 | // Create 'T* omp_parm;T omp_orig;'. All references to 'omp_orig' will |
| 10144 | // be replaced by '*omp_parm' during codegen. This required because 'omp_orig' |
| 10145 | // uses semantics of argument handles by value, but it should be passed by |
| 10146 | // reference. C lang does not support references, so pass all parameters as |
| 10147 | // pointers. |
| 10148 | // Create 'T omp_orig;' variable. |
| 10149 | auto *OmpOrigParm = |
| 10150 | buildVarDecl(*this, D->getLocation(), ReductionType, "omp_orig"); |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 10151 | if (S != nullptr) { |
| 10152 | PushOnScopeChains(OmpPrivParm, S); |
| 10153 | PushOnScopeChains(OmpOrigParm, S); |
| 10154 | } else { |
| 10155 | DRD->addDecl(OmpPrivParm); |
| 10156 | DRD->addDecl(OmpOrigParm); |
| 10157 | } |
| 10158 | } |
| 10159 | |
| 10160 | void Sema::ActOnOpenMPDeclareReductionInitializerEnd(Decl *D, |
| 10161 | Expr *Initializer) { |
| 10162 | auto *DRD = cast<OMPDeclareReductionDecl>(D); |
| 10163 | DiscardCleanupsInEvaluationContext(); |
| 10164 | PopExpressionEvaluationContext(); |
| 10165 | |
| 10166 | PopDeclContext(); |
| 10167 | PopFunctionScopeInfo(); |
| 10168 | |
| 10169 | if (Initializer != nullptr) |
| 10170 | DRD->setInitializer(Initializer); |
| 10171 | else |
| 10172 | DRD->setInvalidDecl(); |
| 10173 | } |
| 10174 | |
| 10175 | Sema::DeclGroupPtrTy Sema::ActOnOpenMPDeclareReductionDirectiveEnd( |
| 10176 | Scope *S, DeclGroupPtrTy DeclReductions, bool IsValid) { |
| 10177 | for (auto *D : DeclReductions.get()) { |
| 10178 | if (IsValid) { |
| 10179 | auto *DRD = cast<OMPDeclareReductionDecl>(D); |
| 10180 | if (S != nullptr) |
| 10181 | PushOnScopeChains(DRD, S, /*AddToContext=*/false); |
| 10182 | } else |
| 10183 | D->setInvalidDecl(); |
| 10184 | } |
| 10185 | return DeclReductions; |
| 10186 | } |
| 10187 | |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 10188 | OMPClause *Sema::ActOnOpenMPNumTeamsClause(Expr *NumTeams, |
| 10189 | SourceLocation StartLoc, |
| 10190 | SourceLocation LParenLoc, |
| 10191 | SourceLocation EndLoc) { |
| 10192 | Expr *ValExpr = NumTeams; |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 10193 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 10194 | // OpenMP [teams Constrcut, Restrictions] |
| 10195 | // The num_teams expression must evaluate to a positive integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 10196 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_num_teams, |
| 10197 | /*StrictlyPositive=*/true)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 10198 | return nullptr; |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 10199 | |
| 10200 | return new (Context) OMPNumTeamsClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 10201 | } |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 10202 | |
| 10203 | OMPClause *Sema::ActOnOpenMPThreadLimitClause(Expr *ThreadLimit, |
| 10204 | SourceLocation StartLoc, |
| 10205 | SourceLocation LParenLoc, |
| 10206 | SourceLocation EndLoc) { |
| 10207 | Expr *ValExpr = ThreadLimit; |
| 10208 | |
| 10209 | // OpenMP [teams Constrcut, Restrictions] |
| 10210 | // The thread_limit expression must evaluate to a positive integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 10211 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_thread_limit, |
| 10212 | /*StrictlyPositive=*/true)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 10213 | return nullptr; |
| 10214 | |
| 10215 | return new (Context) OMPThreadLimitClause(ValExpr, StartLoc, LParenLoc, |
| 10216 | EndLoc); |
| 10217 | } |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 10218 | |
| 10219 | OMPClause *Sema::ActOnOpenMPPriorityClause(Expr *Priority, |
| 10220 | SourceLocation StartLoc, |
| 10221 | SourceLocation LParenLoc, |
| 10222 | SourceLocation EndLoc) { |
| 10223 | Expr *ValExpr = Priority; |
| 10224 | |
| 10225 | // OpenMP [2.9.1, task Constrcut] |
| 10226 | // The priority-value is a non-negative numerical scalar expression. |
| 10227 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_priority, |
| 10228 | /*StrictlyPositive=*/false)) |
| 10229 | return nullptr; |
| 10230 | |
| 10231 | return new (Context) OMPPriorityClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 10232 | } |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 10233 | |
| 10234 | OMPClause *Sema::ActOnOpenMPGrainsizeClause(Expr *Grainsize, |
| 10235 | SourceLocation StartLoc, |
| 10236 | SourceLocation LParenLoc, |
| 10237 | SourceLocation EndLoc) { |
| 10238 | Expr *ValExpr = Grainsize; |
| 10239 | |
| 10240 | // OpenMP [2.9.2, taskloop Constrcut] |
| 10241 | // The parameter of the grainsize clause must be a positive integer |
| 10242 | // expression. |
| 10243 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_grainsize, |
| 10244 | /*StrictlyPositive=*/true)) |
| 10245 | return nullptr; |
| 10246 | |
| 10247 | return new (Context) OMPGrainsizeClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 10248 | } |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 10249 | |
| 10250 | OMPClause *Sema::ActOnOpenMPNumTasksClause(Expr *NumTasks, |
| 10251 | SourceLocation StartLoc, |
| 10252 | SourceLocation LParenLoc, |
| 10253 | SourceLocation EndLoc) { |
| 10254 | Expr *ValExpr = NumTasks; |
| 10255 | |
| 10256 | // OpenMP [2.9.2, taskloop Constrcut] |
| 10257 | // The parameter of the num_tasks clause must be a positive integer |
| 10258 | // expression. |
| 10259 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_num_tasks, |
| 10260 | /*StrictlyPositive=*/true)) |
| 10261 | return nullptr; |
| 10262 | |
| 10263 | return new (Context) OMPNumTasksClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 10264 | } |
| 10265 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 10266 | OMPClause *Sema::ActOnOpenMPHintClause(Expr *Hint, SourceLocation StartLoc, |
| 10267 | SourceLocation LParenLoc, |
| 10268 | SourceLocation EndLoc) { |
| 10269 | // OpenMP [2.13.2, critical construct, Description] |
| 10270 | // ... where hint-expression is an integer constant expression that evaluates |
| 10271 | // to a valid lock hint. |
| 10272 | ExprResult HintExpr = VerifyPositiveIntegerConstantInClause(Hint, OMPC_hint); |
| 10273 | if (HintExpr.isInvalid()) |
| 10274 | return nullptr; |
| 10275 | return new (Context) |
| 10276 | OMPHintClause(HintExpr.get(), StartLoc, LParenLoc, EndLoc); |
| 10277 | } |
| 10278 | |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 10279 | OMPClause *Sema::ActOnOpenMPDistScheduleClause( |
| 10280 | OpenMPDistScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, |
| 10281 | SourceLocation LParenLoc, SourceLocation KindLoc, SourceLocation CommaLoc, |
| 10282 | SourceLocation EndLoc) { |
| 10283 | if (Kind == OMPC_DIST_SCHEDULE_unknown) { |
| 10284 | std::string Values; |
| 10285 | Values += "'"; |
| 10286 | Values += getOpenMPSimpleClauseTypeName(OMPC_dist_schedule, 0); |
| 10287 | Values += "'"; |
| 10288 | Diag(KindLoc, diag::err_omp_unexpected_clause_value) |
| 10289 | << Values << getOpenMPClauseName(OMPC_dist_schedule); |
| 10290 | return nullptr; |
| 10291 | } |
| 10292 | Expr *ValExpr = ChunkSize; |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 10293 | Stmt *HelperValStmt = nullptr; |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 10294 | if (ChunkSize) { |
| 10295 | if (!ChunkSize->isValueDependent() && !ChunkSize->isTypeDependent() && |
| 10296 | !ChunkSize->isInstantiationDependent() && |
| 10297 | !ChunkSize->containsUnexpandedParameterPack()) { |
| 10298 | SourceLocation ChunkSizeLoc = ChunkSize->getLocStart(); |
| 10299 | ExprResult Val = |
| 10300 | PerformOpenMPImplicitIntegerConversion(ChunkSizeLoc, ChunkSize); |
| 10301 | if (Val.isInvalid()) |
| 10302 | return nullptr; |
| 10303 | |
| 10304 | ValExpr = Val.get(); |
| 10305 | |
| 10306 | // OpenMP [2.7.1, Restrictions] |
| 10307 | // chunk_size must be a loop invariant integer expression with a positive |
| 10308 | // value. |
| 10309 | llvm::APSInt Result; |
| 10310 | if (ValExpr->isIntegerConstantExpr(Result, Context)) { |
| 10311 | if (Result.isSigned() && !Result.isStrictlyPositive()) { |
| 10312 | Diag(ChunkSizeLoc, diag::err_omp_negative_expression_in_clause) |
| 10313 | << "dist_schedule" << ChunkSize->getSourceRange(); |
| 10314 | return nullptr; |
| 10315 | } |
| 10316 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective())) { |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 10317 | llvm::MapVector<Expr *, DeclRefExpr *> Captures; |
| 10318 | ValExpr = tryBuildCapture(*this, ValExpr, Captures).get(); |
| 10319 | HelperValStmt = buildPreInits(Context, Captures); |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 10320 | } |
| 10321 | } |
| 10322 | } |
| 10323 | |
| 10324 | return new (Context) |
| 10325 | OMPDistScheduleClause(StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc, |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 10326 | Kind, ValExpr, HelperValStmt); |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 10327 | } |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 10328 | |
| 10329 | OMPClause *Sema::ActOnOpenMPDefaultmapClause( |
| 10330 | OpenMPDefaultmapClauseModifier M, OpenMPDefaultmapClauseKind Kind, |
| 10331 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation MLoc, |
| 10332 | SourceLocation KindLoc, SourceLocation EndLoc) { |
| 10333 | // OpenMP 4.5 only supports 'defaultmap(tofrom: scalar)' |
| 10334 | if (M != OMPC_DEFAULTMAP_MODIFIER_tofrom || |
| 10335 | Kind != OMPC_DEFAULTMAP_scalar) { |
| 10336 | std::string Value; |
| 10337 | SourceLocation Loc; |
| 10338 | Value += "'"; |
| 10339 | if (M != OMPC_DEFAULTMAP_MODIFIER_tofrom) { |
| 10340 | Value += getOpenMPSimpleClauseTypeName(OMPC_defaultmap, |
| 10341 | OMPC_DEFAULTMAP_MODIFIER_tofrom); |
| 10342 | Loc = MLoc; |
| 10343 | } else { |
| 10344 | Value += getOpenMPSimpleClauseTypeName(OMPC_defaultmap, |
| 10345 | OMPC_DEFAULTMAP_scalar); |
| 10346 | Loc = KindLoc; |
| 10347 | } |
| 10348 | Value += "'"; |
| 10349 | Diag(Loc, diag::err_omp_unexpected_clause_value) |
| 10350 | << Value << getOpenMPClauseName(OMPC_defaultmap); |
| 10351 | return nullptr; |
| 10352 | } |
| 10353 | |
| 10354 | return new (Context) |
| 10355 | OMPDefaultmapClause(StartLoc, LParenLoc, MLoc, KindLoc, EndLoc, Kind, M); |
| 10356 | } |