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: |
| 84 | struct DSAInfo { |
| 85 | OpenMPClauseKind Attributes; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 86 | Expr *RefExpr; |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 87 | DeclRefExpr *PrivateCopy; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 88 | }; |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 89 | typedef llvm::DenseMap<ValueDecl *, DSAInfo> DeclSAMapTy; |
| 90 | typedef llvm::DenseMap<ValueDecl *, Expr *> AlignedMapTy; |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 91 | typedef std::pair<unsigned, VarDecl *> LCDeclInfo; |
| 92 | typedef llvm::DenseMap<ValueDecl *, LCDeclInfo> LoopControlVariablesMapTy; |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 93 | typedef llvm::DenseMap< |
| 94 | ValueDecl *, OMPClauseMappableExprCommon::MappableExprComponentLists> |
| 95 | MappedExprComponentsTy; |
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; |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 102 | MappedExprComponentsTy MappedExprComponents; |
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 | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 343 | // Do the check specified in \a Check to all component lists and return true |
| 344 | // if any issue is found. |
| 345 | bool checkMappableExprComponentListsForDecl( |
| 346 | ValueDecl *VD, bool CurrentRegionOnly, |
| 347 | const llvm::function_ref<bool( |
| 348 | OMPClauseMappableExprCommon::MappableExprComponentListRef)> &Check) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 349 | auto SI = Stack.rbegin(); |
| 350 | auto SE = Stack.rend(); |
| 351 | |
| 352 | if (SI == SE) |
| 353 | return false; |
| 354 | |
| 355 | if (CurrentRegionOnly) { |
| 356 | SE = std::next(SI); |
| 357 | } else { |
| 358 | ++SI; |
| 359 | } |
| 360 | |
| 361 | for (; SI != SE; ++SI) { |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 362 | auto MI = SI->MappedExprComponents.find(VD); |
| 363 | if (MI != SI->MappedExprComponents.end()) |
| 364 | for (auto &L : MI->second) |
| 365 | if (Check(L)) |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 366 | return true; |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 367 | } |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 368 | return false; |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 369 | } |
| 370 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 371 | // Create a new mappable expression component list associated with a given |
| 372 | // declaration and initialize it with the provided list of components. |
| 373 | void addMappableExpressionComponents( |
| 374 | ValueDecl *VD, |
| 375 | OMPClauseMappableExprCommon::MappableExprComponentListRef Components) { |
| 376 | assert(Stack.size() > 1 && |
| 377 | "Not expecting to retrieve components from a empty stack!"); |
| 378 | auto &MEC = Stack.back().MappedExprComponents[VD]; |
| 379 | // Create new entry and append the new components there. |
| 380 | MEC.resize(MEC.size() + 1); |
| 381 | MEC.back().append(Components.begin(), Components.end()); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 382 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 383 | }; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 384 | bool isParallelOrTaskRegion(OpenMPDirectiveKind DKind) { |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 385 | return isOpenMPParallelDirective(DKind) || isOpenMPTaskingDirective(DKind) || |
| 386 | isOpenMPTeamsDirective(DKind) || DKind == OMPD_unknown; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 387 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 388 | } // namespace |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 389 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 390 | static ValueDecl *getCanonicalDecl(ValueDecl *D) { |
| 391 | auto *VD = dyn_cast<VarDecl>(D); |
| 392 | auto *FD = dyn_cast<FieldDecl>(D); |
| 393 | if (VD != nullptr) { |
| 394 | VD = VD->getCanonicalDecl(); |
| 395 | D = VD; |
| 396 | } else { |
| 397 | assert(FD); |
| 398 | FD = FD->getCanonicalDecl(); |
| 399 | D = FD; |
| 400 | } |
| 401 | return D; |
| 402 | } |
| 403 | |
Dmitry Polukhin | dc78bc82 | 2016-04-01 09:52:30 +0000 | [diff] [blame] | 404 | DSAStackTy::DSAVarData DSAStackTy::getDSA(StackTy::reverse_iterator& Iter, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 405 | ValueDecl *D) { |
| 406 | D = getCanonicalDecl(D); |
| 407 | auto *VD = dyn_cast<VarDecl>(D); |
| 408 | auto *FD = dyn_cast<FieldDecl>(D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 409 | DSAVarData DVar; |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 410 | if (Iter == std::prev(Stack.rend())) { |
Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 411 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 412 | // in a region but not in construct] |
| 413 | // File-scope or namespace-scope variables referenced in called routines |
| 414 | // in the region are shared unless they appear in a threadprivate |
| 415 | // directive. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 416 | if (VD && !VD->isFunctionOrMethodVarDecl() && !isa<ParmVarDecl>(D)) |
Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 417 | DVar.CKind = OMPC_shared; |
| 418 | |
| 419 | // OpenMP [2.9.1.2, Data-sharing Attribute Rules for Variables Referenced |
| 420 | // in a region but not in construct] |
| 421 | // Variables with static storage duration that are declared in called |
| 422 | // routines in the region are shared. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 423 | if (VD && VD->hasGlobalStorage()) |
| 424 | DVar.CKind = OMPC_shared; |
| 425 | |
| 426 | // Non-static data members are shared by default. |
| 427 | if (FD) |
Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 428 | DVar.CKind = OMPC_shared; |
| 429 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 430 | return DVar; |
| 431 | } |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 432 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 433 | DVar.DKind = Iter->Directive; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 434 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 435 | // in a Construct, C/C++, predetermined, p.1] |
| 436 | // Variables with automatic storage duration that are declared in a scope |
| 437 | // inside the construct are private. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 438 | if (VD && isOpenMPLocal(VD, Iter) && VD->isLocalVarDecl() && |
| 439 | (VD->getStorageClass() == SC_Auto || VD->getStorageClass() == SC_None)) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 440 | DVar.CKind = OMPC_private; |
| 441 | return DVar; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 442 | } |
| 443 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 444 | // Explicitly specified attributes and local variables with predetermined |
| 445 | // attributes. |
| 446 | if (Iter->SharingMap.count(D)) { |
| 447 | DVar.RefExpr = Iter->SharingMap[D].RefExpr; |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 448 | DVar.PrivateCopy = Iter->SharingMap[D].PrivateCopy; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 449 | DVar.CKind = Iter->SharingMap[D].Attributes; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 450 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 451 | return DVar; |
| 452 | } |
| 453 | |
| 454 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 455 | // in a Construct, C/C++, implicitly determined, p.1] |
| 456 | // In a parallel or task construct, the data-sharing attributes of these |
| 457 | // variables are determined by the default clause, if present. |
| 458 | switch (Iter->DefaultAttr) { |
| 459 | case DSA_shared: |
| 460 | DVar.CKind = OMPC_shared; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 461 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 462 | return DVar; |
| 463 | case DSA_none: |
| 464 | return DVar; |
| 465 | case DSA_unspecified: |
| 466 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 467 | // in a Construct, implicitly determined, p.2] |
| 468 | // In a parallel construct, if no default clause is present, these |
| 469 | // variables are shared. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 470 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 471 | if (isOpenMPParallelDirective(DVar.DKind) || |
| 472 | isOpenMPTeamsDirective(DVar.DKind)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 473 | DVar.CKind = OMPC_shared; |
| 474 | return DVar; |
| 475 | } |
| 476 | |
| 477 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 478 | // in a Construct, implicitly determined, p.4] |
| 479 | // In a task construct, if no default clause is present, a variable that in |
| 480 | // the enclosing context is determined to be shared by all implicit tasks |
| 481 | // bound to the current team is shared. |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 482 | if (isOpenMPTaskingDirective(DVar.DKind)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 483 | DSAVarData DVarTemp; |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 484 | for (StackTy::reverse_iterator I = std::next(Iter), EE = Stack.rend(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 485 | I != EE; ++I) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 486 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 487 | // Referenced in a Construct, implicitly determined, p.6] |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 488 | // In a task construct, if no default clause is present, a variable |
| 489 | // whose data-sharing attribute is not determined by the rules above is |
| 490 | // firstprivate. |
| 491 | DVarTemp = getDSA(I, D); |
| 492 | if (DVarTemp.CKind != OMPC_shared) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 493 | DVar.RefExpr = nullptr; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 494 | DVar.CKind = OMPC_firstprivate; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 495 | return DVar; |
| 496 | } |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 497 | if (isParallelOrTaskRegion(I->Directive)) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 498 | break; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 499 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 500 | DVar.CKind = |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 501 | (DVarTemp.CKind == OMPC_unknown) ? OMPC_firstprivate : OMPC_shared; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 502 | return DVar; |
| 503 | } |
| 504 | } |
| 505 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 506 | // in a Construct, implicitly determined, p.3] |
| 507 | // For constructs other than task, if no default clause is present, these |
| 508 | // variables inherit their data-sharing attributes from the enclosing |
| 509 | // context. |
Dmitry Polukhin | dc78bc82 | 2016-04-01 09:52:30 +0000 | [diff] [blame] | 510 | return getDSA(++Iter, D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 511 | } |
| 512 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 513 | Expr *DSAStackTy::addUniqueAligned(ValueDecl *D, Expr *NewDE) { |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 514 | assert(Stack.size() > 1 && "Data sharing attributes stack is empty"); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 515 | D = getCanonicalDecl(D); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 516 | auto It = Stack.back().AlignedMap.find(D); |
| 517 | if (It == Stack.back().AlignedMap.end()) { |
| 518 | assert(NewDE && "Unexpected nullptr expr to be added into aligned map"); |
| 519 | Stack.back().AlignedMap[D] = NewDE; |
| 520 | return nullptr; |
| 521 | } else { |
| 522 | assert(It->second && "Unexpected nullptr expr in the aligned map"); |
| 523 | return It->second; |
| 524 | } |
| 525 | return nullptr; |
| 526 | } |
| 527 | |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 528 | void DSAStackTy::addLoopControlVariable(ValueDecl *D, VarDecl *Capture) { |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 529 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 530 | D = getCanonicalDecl(D); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 531 | Stack.back().LCVMap.insert( |
| 532 | std::make_pair(D, LCDeclInfo(Stack.back().LCVMap.size() + 1, Capture))); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 533 | } |
| 534 | |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 535 | DSAStackTy::LCDeclInfo DSAStackTy::isLoopControlVariable(ValueDecl *D) { |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 536 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 537 | D = getCanonicalDecl(D); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 538 | return Stack.back().LCVMap.count(D) > 0 ? Stack.back().LCVMap[D] |
| 539 | : LCDeclInfo(0, nullptr); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 540 | } |
| 541 | |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 542 | DSAStackTy::LCDeclInfo DSAStackTy::isParentLoopControlVariable(ValueDecl *D) { |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 543 | assert(Stack.size() > 2 && "Data-sharing attributes stack is empty"); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 544 | D = getCanonicalDecl(D); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 545 | return Stack[Stack.size() - 2].LCVMap.count(D) > 0 |
| 546 | ? Stack[Stack.size() - 2].LCVMap[D] |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 547 | : LCDeclInfo(0, nullptr); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 548 | } |
| 549 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 550 | ValueDecl *DSAStackTy::getParentLoopControlVariable(unsigned I) { |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 551 | assert(Stack.size() > 2 && "Data-sharing attributes stack is empty"); |
| 552 | if (Stack[Stack.size() - 2].LCVMap.size() < I) |
| 553 | return nullptr; |
| 554 | for (auto &Pair : Stack[Stack.size() - 2].LCVMap) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 555 | if (Pair.second.first == I) |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 556 | return Pair.first; |
| 557 | } |
| 558 | return nullptr; |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 559 | } |
| 560 | |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 561 | void DSAStackTy::addDSA(ValueDecl *D, Expr *E, OpenMPClauseKind A, |
| 562 | DeclRefExpr *PrivateCopy) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 563 | D = getCanonicalDecl(D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 564 | if (A == OMPC_threadprivate) { |
| 565 | Stack[0].SharingMap[D].Attributes = A; |
| 566 | Stack[0].SharingMap[D].RefExpr = E; |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 567 | Stack[0].SharingMap[D].PrivateCopy = nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 568 | } else { |
| 569 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); |
| 570 | Stack.back().SharingMap[D].Attributes = A; |
| 571 | Stack.back().SharingMap[D].RefExpr = E; |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 572 | Stack.back().SharingMap[D].PrivateCopy = PrivateCopy; |
| 573 | if (PrivateCopy) |
| 574 | addDSA(PrivateCopy->getDecl(), PrivateCopy, A); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 575 | } |
| 576 | } |
| 577 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 578 | bool DSAStackTy::isOpenMPLocal(VarDecl *D, StackTy::reverse_iterator Iter) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 579 | D = D->getCanonicalDecl(); |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 580 | if (Stack.size() > 2) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 581 | reverse_iterator I = Iter, E = std::prev(Stack.rend()); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 582 | Scope *TopScope = nullptr; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 583 | while (I != E && !isParallelOrTaskRegion(I->Directive)) { |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 584 | ++I; |
| 585 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 586 | if (I == E) |
| 587 | return false; |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 588 | TopScope = I->CurScope ? I->CurScope->getParent() : nullptr; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 589 | Scope *CurScope = getCurScope(); |
| 590 | while (CurScope != TopScope && !CurScope->isDeclScope(D)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 591 | CurScope = CurScope->getParent(); |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 592 | } |
| 593 | return CurScope != TopScope; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 594 | } |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 595 | return false; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 596 | } |
| 597 | |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 598 | /// \brief Build a variable declaration for OpenMP loop iteration variable. |
| 599 | static VarDecl *buildVarDecl(Sema &SemaRef, SourceLocation Loc, QualType Type, |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 600 | StringRef Name, const AttrVec *Attrs = nullptr) { |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 601 | DeclContext *DC = SemaRef.CurContext; |
| 602 | IdentifierInfo *II = &SemaRef.PP.getIdentifierTable().get(Name); |
| 603 | TypeSourceInfo *TInfo = SemaRef.Context.getTrivialTypeSourceInfo(Type, Loc); |
| 604 | VarDecl *Decl = |
| 605 | VarDecl::Create(SemaRef.Context, DC, Loc, Loc, II, Type, TInfo, SC_None); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 606 | if (Attrs) { |
| 607 | for (specific_attr_iterator<AlignedAttr> I(Attrs->begin()), E(Attrs->end()); |
| 608 | I != E; ++I) |
| 609 | Decl->addAttr(*I); |
| 610 | } |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 611 | Decl->setImplicit(); |
| 612 | return Decl; |
| 613 | } |
| 614 | |
| 615 | static DeclRefExpr *buildDeclRefExpr(Sema &S, VarDecl *D, QualType Ty, |
| 616 | SourceLocation Loc, |
| 617 | bool RefersToCapture = false) { |
| 618 | D->setReferenced(); |
| 619 | D->markUsed(S.Context); |
| 620 | return DeclRefExpr::Create(S.getASTContext(), NestedNameSpecifierLoc(), |
| 621 | SourceLocation(), D, RefersToCapture, Loc, Ty, |
| 622 | VK_LValue); |
| 623 | } |
| 624 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 625 | DSAStackTy::DSAVarData DSAStackTy::getTopDSA(ValueDecl *D, bool FromParent) { |
| 626 | D = getCanonicalDecl(D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 627 | DSAVarData DVar; |
| 628 | |
| 629 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 630 | // in a Construct, C/C++, predetermined, p.1] |
| 631 | // Variables appearing in threadprivate directives are threadprivate. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 632 | auto *VD = dyn_cast<VarDecl>(D); |
| 633 | if ((VD && VD->getTLSKind() != VarDecl::TLS_None && |
| 634 | !(VD->hasAttr<OMPThreadPrivateDeclAttr>() && |
Samuel Antao | f8b5012 | 2015-07-13 22:54:53 +0000 | [diff] [blame] | 635 | SemaRef.getLangOpts().OpenMPUseTLS && |
| 636 | SemaRef.getASTContext().getTargetInfo().isTLSSupported())) || |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 637 | (VD && VD->getStorageClass() == SC_Register && |
| 638 | VD->hasAttr<AsmLabelAttr>() && !VD->isLocalVarDecl())) { |
| 639 | addDSA(D, buildDeclRefExpr(SemaRef, VD, D->getType().getNonReferenceType(), |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 640 | D->getLocation()), |
Alexey Bataev | f2453a0 | 2015-05-06 07:25:08 +0000 | [diff] [blame] | 641 | OMPC_threadprivate); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 642 | } |
| 643 | if (Stack[0].SharingMap.count(D)) { |
| 644 | DVar.RefExpr = Stack[0].SharingMap[D].RefExpr; |
| 645 | DVar.CKind = OMPC_threadprivate; |
| 646 | return DVar; |
| 647 | } |
| 648 | |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 649 | if (Stack.size() == 1) { |
| 650 | // Not in OpenMP execution region and top scope was already checked. |
| 651 | return DVar; |
| 652 | } |
| 653 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 654 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
Alexey Bataev | dffa93a | 2015-12-10 08:20:58 +0000 | [diff] [blame] | 655 | // in a Construct, C/C++, predetermined, p.4] |
| 656 | // Static data members are shared. |
| 657 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 658 | // in a Construct, C/C++, predetermined, p.7] |
| 659 | // Variables with static storage duration that are declared in a scope |
| 660 | // inside the construct are shared. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 661 | if (VD && VD->isStaticDataMember()) { |
Alexey Bataev | dffa93a | 2015-12-10 08:20:58 +0000 | [diff] [blame] | 662 | DSAVarData DVarTemp = |
| 663 | hasDSA(D, isOpenMPPrivate, MatchesAlways(), FromParent); |
| 664 | if (DVarTemp.CKind != OMPC_unknown && DVarTemp.RefExpr) |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 665 | return DVar; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 666 | |
Alexey Bataev | dffa93a | 2015-12-10 08:20:58 +0000 | [diff] [blame] | 667 | DVar.CKind = OMPC_shared; |
| 668 | return DVar; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 669 | } |
| 670 | |
| 671 | QualType Type = D->getType().getNonReferenceType().getCanonicalType(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 672 | bool IsConstant = Type.isConstant(SemaRef.getASTContext()); |
| 673 | Type = SemaRef.getASTContext().getBaseElementType(Type); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 674 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 675 | // in a Construct, C/C++, predetermined, p.6] |
| 676 | // Variables with const qualified type having no mutable member are |
| 677 | // shared. |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 678 | CXXRecordDecl *RD = |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 679 | SemaRef.getLangOpts().CPlusPlus ? Type->getAsCXXRecordDecl() : nullptr; |
Alexey Bataev | c9bd03d | 2015-12-17 06:55:08 +0000 | [diff] [blame] | 680 | if (auto *CTSD = dyn_cast_or_null<ClassTemplateSpecializationDecl>(RD)) |
| 681 | if (auto *CTD = CTSD->getSpecializedTemplate()) |
| 682 | RD = CTD->getTemplatedDecl(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 683 | if (IsConstant && |
Alexey Bataev | 4bcad7f | 2016-02-10 10:50:12 +0000 | [diff] [blame] | 684 | !(SemaRef.getLangOpts().CPlusPlus && RD && RD->hasDefinition() && |
| 685 | RD->hasMutableFields())) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 686 | // Variables with const-qualified type having no mutable member may be |
| 687 | // listed in a firstprivate clause, even if they are static data members. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 688 | DSAVarData DVarTemp = hasDSA(D, MatchesAnyClause(OMPC_firstprivate), |
| 689 | MatchesAlways(), FromParent); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 690 | if (DVarTemp.CKind == OMPC_firstprivate && DVarTemp.RefExpr) |
| 691 | return DVar; |
| 692 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 693 | DVar.CKind = OMPC_shared; |
| 694 | return DVar; |
| 695 | } |
| 696 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 697 | // Explicitly specified attributes and local variables with predetermined |
| 698 | // attributes. |
Alexey Bataev | dffa93a | 2015-12-10 08:20:58 +0000 | [diff] [blame] | 699 | auto StartI = std::next(Stack.rbegin()); |
| 700 | auto EndI = std::prev(Stack.rend()); |
| 701 | if (FromParent && StartI != EndI) { |
| 702 | StartI = std::next(StartI); |
| 703 | } |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 704 | auto I = std::prev(StartI); |
| 705 | if (I->SharingMap.count(D)) { |
| 706 | DVar.RefExpr = I->SharingMap[D].RefExpr; |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 707 | DVar.PrivateCopy = I->SharingMap[D].PrivateCopy; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 708 | DVar.CKind = I->SharingMap[D].Attributes; |
| 709 | DVar.ImplicitDSALoc = I->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 710 | } |
| 711 | |
| 712 | return DVar; |
| 713 | } |
| 714 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 715 | DSAStackTy::DSAVarData DSAStackTy::getImplicitDSA(ValueDecl *D, |
| 716 | bool FromParent) { |
| 717 | D = getCanonicalDecl(D); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 718 | auto StartI = Stack.rbegin(); |
| 719 | auto EndI = std::prev(Stack.rend()); |
| 720 | if (FromParent && StartI != EndI) { |
| 721 | StartI = std::next(StartI); |
| 722 | } |
| 723 | return getDSA(StartI, D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 724 | } |
| 725 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 726 | template <class ClausesPredicate, class DirectivesPredicate> |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 727 | DSAStackTy::DSAVarData DSAStackTy::hasDSA(ValueDecl *D, ClausesPredicate CPred, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 728 | DirectivesPredicate DPred, |
| 729 | bool FromParent) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 730 | D = getCanonicalDecl(D); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 731 | auto StartI = std::next(Stack.rbegin()); |
Dmitry Polukhin | dc78bc82 | 2016-04-01 09:52:30 +0000 | [diff] [blame] | 732 | auto EndI = Stack.rend(); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 733 | if (FromParent && StartI != EndI) { |
| 734 | StartI = std::next(StartI); |
| 735 | } |
| 736 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
| 737 | if (!DPred(I->Directive) && !isParallelOrTaskRegion(I->Directive)) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 738 | continue; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 739 | DSAVarData DVar = getDSA(I, D); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 740 | if (CPred(DVar.CKind)) |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 741 | return DVar; |
| 742 | } |
| 743 | return DSAVarData(); |
| 744 | } |
| 745 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 746 | template <class ClausesPredicate, class DirectivesPredicate> |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 747 | DSAStackTy::DSAVarData |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 748 | DSAStackTy::hasInnermostDSA(ValueDecl *D, ClausesPredicate CPred, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 749 | DirectivesPredicate DPred, bool FromParent) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 750 | D = getCanonicalDecl(D); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 751 | auto StartI = std::next(Stack.rbegin()); |
Dmitry Polukhin | dc78bc82 | 2016-04-01 09:52:30 +0000 | [diff] [blame] | 752 | auto EndI = Stack.rend(); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 753 | if (FromParent && StartI != EndI) { |
| 754 | StartI = std::next(StartI); |
| 755 | } |
| 756 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 757 | if (!DPred(I->Directive)) |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 758 | break; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 759 | DSAVarData DVar = getDSA(I, D); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 760 | if (CPred(DVar.CKind)) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 761 | return DVar; |
| 762 | return DSAVarData(); |
| 763 | } |
| 764 | return DSAVarData(); |
| 765 | } |
| 766 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 767 | bool DSAStackTy::hasExplicitDSA( |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 768 | ValueDecl *D, const llvm::function_ref<bool(OpenMPClauseKind)> &CPred, |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 769 | unsigned Level) { |
| 770 | if (CPred(ClauseKindMode)) |
| 771 | return true; |
| 772 | if (isClauseParsingMode()) |
| 773 | ++Level; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 774 | D = getCanonicalDecl(D); |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 775 | auto StartI = Stack.rbegin(); |
| 776 | auto EndI = std::prev(Stack.rend()); |
NAKAMURA Takumi | 0332eda | 2015-06-23 10:01:20 +0000 | [diff] [blame] | 777 | if (std::distance(StartI, EndI) <= (int)Level) |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 778 | return false; |
| 779 | std::advance(StartI, Level); |
| 780 | return (StartI->SharingMap.count(D) > 0) && StartI->SharingMap[D].RefExpr && |
| 781 | CPred(StartI->SharingMap[D].Attributes); |
| 782 | } |
| 783 | |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 784 | bool DSAStackTy::hasExplicitDirective( |
| 785 | const llvm::function_ref<bool(OpenMPDirectiveKind)> &DPred, |
| 786 | unsigned Level) { |
| 787 | if (isClauseParsingMode()) |
| 788 | ++Level; |
| 789 | auto StartI = Stack.rbegin(); |
| 790 | auto EndI = std::prev(Stack.rend()); |
| 791 | if (std::distance(StartI, EndI) <= (int)Level) |
| 792 | return false; |
| 793 | std::advance(StartI, Level); |
| 794 | return DPred(StartI->Directive); |
| 795 | } |
| 796 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 797 | template <class NamedDirectivesPredicate> |
| 798 | bool DSAStackTy::hasDirective(NamedDirectivesPredicate DPred, bool FromParent) { |
| 799 | auto StartI = std::next(Stack.rbegin()); |
| 800 | auto EndI = std::prev(Stack.rend()); |
| 801 | if (FromParent && StartI != EndI) { |
| 802 | StartI = std::next(StartI); |
| 803 | } |
| 804 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
| 805 | if (DPred(I->Directive, I->DirectiveName, I->ConstructLoc)) |
| 806 | return true; |
| 807 | } |
| 808 | return false; |
| 809 | } |
| 810 | |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 811 | OpenMPDirectiveKind DSAStackTy::getDirectiveForScope(const Scope *S) const { |
| 812 | for (auto I = Stack.rbegin(), EE = Stack.rend(); I != EE; ++I) |
| 813 | if (I->CurScope == S) |
| 814 | return I->Directive; |
| 815 | return OMPD_unknown; |
| 816 | } |
| 817 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 818 | void Sema::InitDataSharingAttributesStack() { |
| 819 | VarDataSharingAttributesStack = new DSAStackTy(*this); |
| 820 | } |
| 821 | |
| 822 | #define DSAStack static_cast<DSAStackTy *>(VarDataSharingAttributesStack) |
| 823 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 824 | bool Sema::IsOpenMPCapturedByRef(ValueDecl *D, |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 825 | const CapturedRegionScopeInfo *RSI) { |
| 826 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| 827 | |
| 828 | auto &Ctx = getASTContext(); |
| 829 | bool IsByRef = true; |
| 830 | |
| 831 | // Find the directive that is associated with the provided scope. |
| 832 | auto DKind = DSAStack->getDirectiveForScope(RSI->TheScope); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 833 | auto Ty = D->getType(); |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 834 | |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 835 | if (isOpenMPTargetExecutionDirective(DKind)) { |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 836 | // This table summarizes how a given variable should be passed to the device |
| 837 | // given its type and the clauses where it appears. This table is based on |
| 838 | // the description in OpenMP 4.5 [2.10.4, target Construct] and |
| 839 | // OpenMP 4.5 [2.15.5, Data-mapping Attribute Rules and Clauses]. |
| 840 | // |
| 841 | // ========================================================================= |
| 842 | // | type | defaultmap | pvt | first | is_device_ptr | map | res. | |
| 843 | // | |(tofrom:scalar)| | pvt | | | | |
| 844 | // ========================================================================= |
| 845 | // | scl | | | | - | | bycopy| |
| 846 | // | scl | | - | x | - | - | bycopy| |
| 847 | // | scl | | x | - | - | - | null | |
| 848 | // | scl | x | | | - | | byref | |
| 849 | // | scl | x | - | x | - | - | bycopy| |
| 850 | // | scl | x | x | - | - | - | null | |
| 851 | // | scl | | - | - | - | x | byref | |
| 852 | // | scl | x | - | - | - | x | byref | |
| 853 | // |
| 854 | // | agg | n.a. | | | - | | byref | |
| 855 | // | agg | n.a. | - | x | - | - | byref | |
| 856 | // | agg | n.a. | x | - | - | - | null | |
| 857 | // | agg | n.a. | - | - | - | x | byref | |
| 858 | // | agg | n.a. | - | - | - | x[] | byref | |
| 859 | // |
| 860 | // | ptr | n.a. | | | - | | bycopy| |
| 861 | // | ptr | n.a. | - | x | - | - | bycopy| |
| 862 | // | ptr | n.a. | x | - | - | - | null | |
| 863 | // | ptr | n.a. | - | - | - | x | byref | |
| 864 | // | ptr | n.a. | - | - | - | x[] | bycopy| |
| 865 | // | ptr | n.a. | - | - | x | | bycopy| |
| 866 | // | ptr | n.a. | - | - | x | x | bycopy| |
| 867 | // | ptr | n.a. | - | - | x | x[] | bycopy| |
| 868 | // ========================================================================= |
| 869 | // Legend: |
| 870 | // scl - scalar |
| 871 | // ptr - pointer |
| 872 | // agg - aggregate |
| 873 | // x - applies |
| 874 | // - - invalid in this combination |
| 875 | // [] - mapped with an array section |
| 876 | // byref - should be mapped by reference |
| 877 | // byval - should be mapped by value |
| 878 | // null - initialize a local variable to null on the device |
| 879 | // |
| 880 | // Observations: |
| 881 | // - All scalar declarations that show up in a map clause have to be passed |
| 882 | // by reference, because they may have been mapped in the enclosing data |
| 883 | // environment. |
| 884 | // - If the scalar value does not fit the size of uintptr, it has to be |
| 885 | // passed by reference, regardless the result in the table above. |
| 886 | // - For pointers mapped by value that have either an implicit map or an |
| 887 | // array section, the runtime library may pass the NULL value to the |
| 888 | // device instead of the value passed to it by the compiler. |
| 889 | |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 890 | |
| 891 | if (Ty->isReferenceType()) |
| 892 | Ty = Ty->castAs<ReferenceType>()->getPointeeType(); |
Samuel Antao | 86ace55 | 2016-04-27 22:40:57 +0000 | [diff] [blame] | 893 | |
| 894 | // Locate map clauses and see if the variable being captured is referred to |
| 895 | // in any of those clauses. Here we only care about variables, not fields, |
| 896 | // because fields are part of aggregates. |
| 897 | bool IsVariableUsedInMapClause = false; |
| 898 | bool IsVariableAssociatedWithSection = false; |
| 899 | |
| 900 | DSAStack->checkMappableExprComponentListsForDecl( |
| 901 | D, /*CurrentRegionOnly=*/true, |
| 902 | [&](OMPClauseMappableExprCommon::MappableExprComponentListRef |
| 903 | MapExprComponents) { |
| 904 | |
| 905 | auto EI = MapExprComponents.rbegin(); |
| 906 | auto EE = MapExprComponents.rend(); |
| 907 | |
| 908 | assert(EI != EE && "Invalid map expression!"); |
| 909 | |
| 910 | if (isa<DeclRefExpr>(EI->getAssociatedExpression())) |
| 911 | IsVariableUsedInMapClause |= EI->getAssociatedDeclaration() == D; |
| 912 | |
| 913 | ++EI; |
| 914 | if (EI == EE) |
| 915 | return false; |
| 916 | |
| 917 | if (isa<ArraySubscriptExpr>(EI->getAssociatedExpression()) || |
| 918 | isa<OMPArraySectionExpr>(EI->getAssociatedExpression()) || |
| 919 | isa<MemberExpr>(EI->getAssociatedExpression())) { |
| 920 | IsVariableAssociatedWithSection = true; |
| 921 | // There is nothing more we need to know about this variable. |
| 922 | return true; |
| 923 | } |
| 924 | |
| 925 | // Keep looking for more map info. |
| 926 | return false; |
| 927 | }); |
| 928 | |
| 929 | if (IsVariableUsedInMapClause) { |
| 930 | // If variable is identified in a map clause it is always captured by |
| 931 | // reference except if it is a pointer that is dereferenced somehow. |
| 932 | IsByRef = !(Ty->isPointerType() && IsVariableAssociatedWithSection); |
| 933 | } else { |
| 934 | // By default, all the data that has a scalar type is mapped by copy. |
| 935 | IsByRef = !Ty->isScalarType(); |
| 936 | } |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 937 | } |
| 938 | |
Samuel Antao | 86ace55 | 2016-04-27 22:40:57 +0000 | [diff] [blame] | 939 | // When passing data by copy, we need to make sure it fits the uintptr size |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 940 | // and alignment, because the runtime library only deals with uintptr types. |
| 941 | // If it does not fit the uintptr size, we need to pass the data by reference |
| 942 | // instead. |
| 943 | if (!IsByRef && |
| 944 | (Ctx.getTypeSizeInChars(Ty) > |
| 945 | Ctx.getTypeSizeInChars(Ctx.getUIntPtrType()) || |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 946 | Ctx.getDeclAlign(D) > Ctx.getTypeAlignInChars(Ctx.getUIntPtrType()))) |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 947 | IsByRef = true; |
| 948 | |
| 949 | return IsByRef; |
| 950 | } |
| 951 | |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 952 | VarDecl *Sema::IsOpenMPCapturedDecl(ValueDecl *D) { |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 953 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 954 | D = getCanonicalDecl(D); |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 955 | |
| 956 | // If we are attempting to capture a global variable in a directive with |
| 957 | // 'target' we return true so that this global is also mapped to the device. |
| 958 | // |
| 959 | // FIXME: If the declaration is enclosed in a 'declare target' directive, |
| 960 | // then it should not be captured. Therefore, an extra check has to be |
| 961 | // inserted here once support for 'declare target' is added. |
| 962 | // |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 963 | auto *VD = dyn_cast<VarDecl>(D); |
| 964 | if (VD && !VD->hasLocalStorage()) { |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 965 | if (DSAStack->getCurrentDirective() == OMPD_target && |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 966 | !DSAStack->isClauseParsingMode()) |
| 967 | return VD; |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 968 | if (DSAStack->getCurScope() && |
| 969 | DSAStack->hasDirective( |
| 970 | [](OpenMPDirectiveKind K, const DeclarationNameInfo &DNI, |
| 971 | SourceLocation Loc) -> bool { |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 972 | return isOpenMPTargetExecutionDirective(K); |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 973 | }, |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 974 | false)) |
| 975 | return VD; |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 976 | } |
| 977 | |
Alexey Bataev | 48977c3 | 2015-08-04 08:10:48 +0000 | [diff] [blame] | 978 | if (DSAStack->getCurrentDirective() != OMPD_unknown && |
| 979 | (!DSAStack->isClauseParsingMode() || |
| 980 | DSAStack->getParentDirective() != OMPD_unknown)) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 981 | auto &&Info = DSAStack->isLoopControlVariable(D); |
| 982 | if (Info.first || |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 983 | (VD && VD->hasLocalStorage() && |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 984 | isParallelOrTaskRegion(DSAStack->getCurrentDirective())) || |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 985 | (VD && DSAStack->isForceVarCapturing())) |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 986 | return VD ? VD : Info.second; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 987 | auto DVarPrivate = DSAStack->getTopDSA(D, DSAStack->isClauseParsingMode()); |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 988 | if (DVarPrivate.CKind != OMPC_unknown && isOpenMPPrivate(DVarPrivate.CKind)) |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 989 | return VD ? VD : cast<VarDecl>(DVarPrivate.PrivateCopy->getDecl()); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 990 | DVarPrivate = DSAStack->hasDSA(D, isOpenMPPrivate, MatchesAlways(), |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 991 | DSAStack->isClauseParsingMode()); |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 992 | if (DVarPrivate.CKind != OMPC_unknown) |
| 993 | return VD ? VD : cast<VarDecl>(DVarPrivate.PrivateCopy->getDecl()); |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 994 | } |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 995 | return nullptr; |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 996 | } |
| 997 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 998 | bool Sema::isOpenMPPrivateDecl(ValueDecl *D, unsigned Level) { |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 999 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| 1000 | return DSAStack->hasExplicitDSA( |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1001 | D, [](OpenMPClauseKind K) -> bool { return K == OMPC_private; }, Level); |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 1002 | } |
| 1003 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1004 | bool Sema::isOpenMPTargetCapturedDecl(ValueDecl *D, unsigned Level) { |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 1005 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| 1006 | // Return true if the current level is no longer enclosed in a target region. |
| 1007 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1008 | auto *VD = dyn_cast<VarDecl>(D); |
| 1009 | return VD && !VD->hasLocalStorage() && |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 1010 | DSAStack->hasExplicitDirective(isOpenMPTargetExecutionDirective, |
| 1011 | Level); |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 1012 | } |
| 1013 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1014 | void Sema::DestroyDataSharingAttributesStack() { delete DSAStack; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1015 | |
| 1016 | void Sema::StartOpenMPDSABlock(OpenMPDirectiveKind DKind, |
| 1017 | const DeclarationNameInfo &DirName, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1018 | Scope *CurScope, SourceLocation Loc) { |
| 1019 | DSAStack->push(DKind, DirName, CurScope, Loc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1020 | PushExpressionEvaluationContext(PotentiallyEvaluated); |
| 1021 | } |
| 1022 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 1023 | void Sema::StartOpenMPClause(OpenMPClauseKind K) { |
| 1024 | DSAStack->setClauseParsingMode(K); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 1025 | } |
| 1026 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 1027 | void Sema::EndOpenMPClause() { |
| 1028 | DSAStack->setClauseParsingMode(/*K=*/OMPC_unknown); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 1029 | } |
| 1030 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1031 | void Sema::EndOpenMPDSABlock(Stmt *CurDirective) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1032 | // OpenMP [2.14.3.5, Restrictions, C/C++, p.1] |
| 1033 | // A variable of class type (or array thereof) that appears in a lastprivate |
| 1034 | // clause requires an accessible, unambiguous default constructor for the |
| 1035 | // class type, unless the list item is also specified in a firstprivate |
| 1036 | // clause. |
| 1037 | if (auto D = dyn_cast_or_null<OMPExecutableDirective>(CurDirective)) { |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1038 | for (auto *C : D->clauses()) { |
| 1039 | if (auto *Clause = dyn_cast<OMPLastprivateClause>(C)) { |
| 1040 | SmallVector<Expr *, 8> PrivateCopies; |
| 1041 | for (auto *DE : Clause->varlists()) { |
| 1042 | if (DE->isValueDependent() || DE->isTypeDependent()) { |
| 1043 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1044 | continue; |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1045 | } |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 1046 | auto *DRE = cast<DeclRefExpr>(DE->IgnoreParens()); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 1047 | VarDecl *VD = cast<VarDecl>(DRE->getDecl()); |
| 1048 | QualType Type = VD->getType().getNonReferenceType(); |
| 1049 | auto DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1050 | if (DVar.CKind == OMPC_lastprivate) { |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1051 | // Generate helper private variable and initialize it with the |
| 1052 | // default value. The address of the original variable is replaced |
| 1053 | // by the address of the new private variable in CodeGen. This new |
| 1054 | // variable is not added to IdResolver, so the code in the OpenMP |
| 1055 | // region uses original variable for proper diagnostics. |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 1056 | auto *VDPrivate = buildVarDecl( |
| 1057 | *this, DE->getExprLoc(), Type.getUnqualifiedType(), |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 1058 | VD->getName(), VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1059 | ActOnUninitializedDecl(VDPrivate, /*TypeMayContainAuto=*/false); |
| 1060 | if (VDPrivate->isInvalidDecl()) |
| 1061 | continue; |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 1062 | PrivateCopies.push_back(buildDeclRefExpr( |
| 1063 | *this, VDPrivate, DE->getType(), DE->getExprLoc())); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1064 | } else { |
| 1065 | // The variable is also a firstprivate, so initialization sequence |
| 1066 | // for private copy is generated already. |
| 1067 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1068 | } |
| 1069 | } |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1070 | // Set initializers to private copies if no errors were found. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1071 | if (PrivateCopies.size() == Clause->varlist_size()) |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1072 | Clause->setPrivateCopies(PrivateCopies); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1073 | } |
| 1074 | } |
| 1075 | } |
| 1076 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1077 | DSAStack->pop(); |
| 1078 | DiscardCleanupsInEvaluationContext(); |
| 1079 | PopExpressionEvaluationContext(); |
| 1080 | } |
| 1081 | |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 1082 | static bool FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV, |
| 1083 | Expr *NumIterations, Sema &SemaRef, |
| 1084 | Scope *S, DSAStackTy *Stack); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 1085 | |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1086 | namespace { |
| 1087 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1088 | class VarDeclFilterCCC : public CorrectionCandidateCallback { |
| 1089 | private: |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1090 | Sema &SemaRef; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1091 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1092 | public: |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1093 | explicit VarDeclFilterCCC(Sema &S) : SemaRef(S) {} |
Craig Topper | e14c0f8 | 2014-03-12 04:55:44 +0000 | [diff] [blame] | 1094 | bool ValidateCandidate(const TypoCorrection &Candidate) override { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1095 | NamedDecl *ND = Candidate.getCorrectionDecl(); |
| 1096 | if (VarDecl *VD = dyn_cast_or_null<VarDecl>(ND)) { |
| 1097 | return VD->hasGlobalStorage() && |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1098 | SemaRef.isDeclInScope(ND, SemaRef.getCurLexicalContext(), |
| 1099 | SemaRef.getCurScope()); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1100 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1101 | return false; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1102 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1103 | }; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1104 | } // namespace |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1105 | |
| 1106 | ExprResult Sema::ActOnOpenMPIdExpression(Scope *CurScope, |
| 1107 | CXXScopeSpec &ScopeSpec, |
| 1108 | const DeclarationNameInfo &Id) { |
| 1109 | LookupResult Lookup(*this, Id, LookupOrdinaryName); |
| 1110 | LookupParsedName(Lookup, CurScope, &ScopeSpec, true); |
| 1111 | |
| 1112 | if (Lookup.isAmbiguous()) |
| 1113 | return ExprError(); |
| 1114 | |
| 1115 | VarDecl *VD; |
| 1116 | if (!Lookup.isSingleResult()) { |
Kaelyn Takata | 89c881b | 2014-10-27 18:07:29 +0000 | [diff] [blame] | 1117 | if (TypoCorrection Corrected = CorrectTypo( |
| 1118 | Id, LookupOrdinaryName, CurScope, nullptr, |
| 1119 | llvm::make_unique<VarDeclFilterCCC>(*this), CTK_ErrorRecovery)) { |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 1120 | diagnoseTypo(Corrected, |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 1121 | PDiag(Lookup.empty() |
| 1122 | ? diag::err_undeclared_var_use_suggest |
| 1123 | : diag::err_omp_expected_var_arg_suggest) |
| 1124 | << Id.getName()); |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 1125 | VD = Corrected.getCorrectionDeclAs<VarDecl>(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1126 | } else { |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 1127 | Diag(Id.getLoc(), Lookup.empty() ? diag::err_undeclared_var_use |
| 1128 | : diag::err_omp_expected_var_arg) |
| 1129 | << Id.getName(); |
| 1130 | return ExprError(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1131 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1132 | } else { |
| 1133 | if (!(VD = Lookup.getAsSingle<VarDecl>())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1134 | Diag(Id.getLoc(), diag::err_omp_expected_var_arg) << Id.getName(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1135 | Diag(Lookup.getFoundDecl()->getLocation(), diag::note_declared_at); |
| 1136 | return ExprError(); |
| 1137 | } |
| 1138 | } |
| 1139 | Lookup.suppressDiagnostics(); |
| 1140 | |
| 1141 | // OpenMP [2.9.2, Syntax, C/C++] |
| 1142 | // Variables must be file-scope, namespace-scope, or static block-scope. |
| 1143 | if (!VD->hasGlobalStorage()) { |
| 1144 | Diag(Id.getLoc(), diag::err_omp_global_var_arg) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1145 | << getOpenMPDirectiveName(OMPD_threadprivate) << !VD->isStaticLocal(); |
| 1146 | bool IsDecl = |
| 1147 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1148 | Diag(VD->getLocation(), |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1149 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1150 | << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1151 | return ExprError(); |
| 1152 | } |
| 1153 | |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1154 | VarDecl *CanonicalVD = VD->getCanonicalDecl(); |
| 1155 | NamedDecl *ND = cast<NamedDecl>(CanonicalVD); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1156 | // OpenMP [2.9.2, Restrictions, C/C++, p.2] |
| 1157 | // A threadprivate directive for file-scope variables must appear outside |
| 1158 | // any definition or declaration. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1159 | if (CanonicalVD->getDeclContext()->isTranslationUnit() && |
| 1160 | !getCurLexicalContext()->isTranslationUnit()) { |
| 1161 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1162 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1163 | bool IsDecl = |
| 1164 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1165 | Diag(VD->getLocation(), |
| 1166 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1167 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1168 | return ExprError(); |
| 1169 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1170 | // OpenMP [2.9.2, Restrictions, C/C++, p.3] |
| 1171 | // A threadprivate directive for static class member variables must appear |
| 1172 | // in the class definition, in the same scope in which the member |
| 1173 | // variables are declared. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1174 | if (CanonicalVD->isStaticDataMember() && |
| 1175 | !CanonicalVD->getDeclContext()->Equals(getCurLexicalContext())) { |
| 1176 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1177 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1178 | bool IsDecl = |
| 1179 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1180 | Diag(VD->getLocation(), |
| 1181 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1182 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1183 | return ExprError(); |
| 1184 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1185 | // OpenMP [2.9.2, Restrictions, C/C++, p.4] |
| 1186 | // A threadprivate directive for namespace-scope variables must appear |
| 1187 | // outside any definition or declaration other than the namespace |
| 1188 | // definition itself. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1189 | if (CanonicalVD->getDeclContext()->isNamespace() && |
| 1190 | (!getCurLexicalContext()->isFileContext() || |
| 1191 | !getCurLexicalContext()->Encloses(CanonicalVD->getDeclContext()))) { |
| 1192 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1193 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1194 | bool IsDecl = |
| 1195 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1196 | Diag(VD->getLocation(), |
| 1197 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1198 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1199 | return ExprError(); |
| 1200 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1201 | // OpenMP [2.9.2, Restrictions, C/C++, p.6] |
| 1202 | // A threadprivate directive for static block-scope variables must appear |
| 1203 | // in the scope of the variable and not in a nested scope. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1204 | if (CanonicalVD->isStaticLocal() && CurScope && |
| 1205 | !isDeclInScope(ND, getCurLexicalContext(), CurScope)) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1206 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1207 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1208 | bool IsDecl = |
| 1209 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1210 | Diag(VD->getLocation(), |
| 1211 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1212 | << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1213 | return ExprError(); |
| 1214 | } |
| 1215 | |
| 1216 | // OpenMP [2.9.2, Restrictions, C/C++, p.2-6] |
| 1217 | // A threadprivate directive must lexically precede all references to any |
| 1218 | // of the variables in its list. |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 1219 | if (VD->isUsed() && !DSAStack->isThreadPrivate(VD)) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1220 | Diag(Id.getLoc(), diag::err_omp_var_used) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1221 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1222 | return ExprError(); |
| 1223 | } |
| 1224 | |
| 1225 | QualType ExprType = VD->getType().getNonReferenceType(); |
Alexey Bataev | 376b4a4 | 2016-02-09 09:41:09 +0000 | [diff] [blame] | 1226 | return DeclRefExpr::Create(Context, NestedNameSpecifierLoc(), |
| 1227 | SourceLocation(), VD, |
| 1228 | /*RefersToEnclosingVariableOrCapture=*/false, |
| 1229 | Id.getLoc(), ExprType, VK_LValue); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1230 | } |
| 1231 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1232 | Sema::DeclGroupPtrTy |
| 1233 | Sema::ActOnOpenMPThreadprivateDirective(SourceLocation Loc, |
| 1234 | ArrayRef<Expr *> VarList) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1235 | if (OMPThreadPrivateDecl *D = CheckOMPThreadPrivateDecl(Loc, VarList)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1236 | CurContext->addDecl(D); |
| 1237 | return DeclGroupPtrTy::make(DeclGroupRef(D)); |
| 1238 | } |
David Blaikie | 0403cb1 | 2016-01-15 23:43:25 +0000 | [diff] [blame] | 1239 | return nullptr; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1240 | } |
| 1241 | |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1242 | namespace { |
| 1243 | class LocalVarRefChecker : public ConstStmtVisitor<LocalVarRefChecker, bool> { |
| 1244 | Sema &SemaRef; |
| 1245 | |
| 1246 | public: |
| 1247 | bool VisitDeclRefExpr(const DeclRefExpr *E) { |
| 1248 | if (auto VD = dyn_cast<VarDecl>(E->getDecl())) { |
| 1249 | if (VD->hasLocalStorage()) { |
| 1250 | SemaRef.Diag(E->getLocStart(), |
| 1251 | diag::err_omp_local_var_in_threadprivate_init) |
| 1252 | << E->getSourceRange(); |
| 1253 | SemaRef.Diag(VD->getLocation(), diag::note_defined_here) |
| 1254 | << VD << VD->getSourceRange(); |
| 1255 | return true; |
| 1256 | } |
| 1257 | } |
| 1258 | return false; |
| 1259 | } |
| 1260 | bool VisitStmt(const Stmt *S) { |
| 1261 | for (auto Child : S->children()) { |
| 1262 | if (Child && Visit(Child)) |
| 1263 | return true; |
| 1264 | } |
| 1265 | return false; |
| 1266 | } |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 1267 | explicit LocalVarRefChecker(Sema &SemaRef) : SemaRef(SemaRef) {} |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1268 | }; |
| 1269 | } // namespace |
| 1270 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1271 | OMPThreadPrivateDecl * |
| 1272 | Sema::CheckOMPThreadPrivateDecl(SourceLocation Loc, ArrayRef<Expr *> VarList) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1273 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1274 | for (auto &RefExpr : VarList) { |
| 1275 | DeclRefExpr *DE = cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1276 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); |
| 1277 | SourceLocation ILoc = DE->getExprLoc(); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1278 | |
Alexey Bataev | 376b4a4 | 2016-02-09 09:41:09 +0000 | [diff] [blame] | 1279 | // Mark variable as used. |
| 1280 | VD->setReferenced(); |
| 1281 | VD->markUsed(Context); |
| 1282 | |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 1283 | QualType QType = VD->getType(); |
| 1284 | if (QType->isDependentType() || QType->isInstantiationDependentType()) { |
| 1285 | // It will be analyzed later. |
| 1286 | Vars.push_back(DE); |
| 1287 | continue; |
| 1288 | } |
| 1289 | |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1290 | // OpenMP [2.9.2, Restrictions, C/C++, p.10] |
| 1291 | // A threadprivate variable must not have an incomplete type. |
| 1292 | if (RequireCompleteType(ILoc, VD->getType(), |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1293 | diag::err_omp_threadprivate_incomplete_type)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1294 | continue; |
| 1295 | } |
| 1296 | |
| 1297 | // OpenMP [2.9.2, Restrictions, C/C++, p.10] |
| 1298 | // A threadprivate variable must not have a reference type. |
| 1299 | if (VD->getType()->isReferenceType()) { |
| 1300 | Diag(ILoc, diag::err_omp_ref_type_arg) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1301 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD->getType(); |
| 1302 | bool IsDecl = |
| 1303 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1304 | Diag(VD->getLocation(), |
| 1305 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1306 | << VD; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1307 | continue; |
| 1308 | } |
| 1309 | |
Samuel Antao | f8b5012 | 2015-07-13 22:54:53 +0000 | [diff] [blame] | 1310 | // Check if this is a TLS variable. If TLS is not being supported, produce |
| 1311 | // the corresponding diagnostic. |
| 1312 | if ((VD->getTLSKind() != VarDecl::TLS_None && |
| 1313 | !(VD->hasAttr<OMPThreadPrivateDeclAttr>() && |
| 1314 | getLangOpts().OpenMPUseTLS && |
| 1315 | getASTContext().getTargetInfo().isTLSSupported())) || |
Alexey Bataev | 1a8b3f1 | 2015-05-06 06:34:55 +0000 | [diff] [blame] | 1316 | (VD->getStorageClass() == SC_Register && VD->hasAttr<AsmLabelAttr>() && |
| 1317 | !VD->isLocalVarDecl())) { |
Alexey Bataev | 26a3924 | 2015-01-13 03:35:30 +0000 | [diff] [blame] | 1318 | Diag(ILoc, diag::err_omp_var_thread_local) |
| 1319 | << VD << ((VD->getTLSKind() != VarDecl::TLS_None) ? 0 : 1); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1320 | bool IsDecl = |
| 1321 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1322 | Diag(VD->getLocation(), |
| 1323 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1324 | << VD; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1325 | continue; |
| 1326 | } |
| 1327 | |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1328 | // Check if initial value of threadprivate variable reference variable with |
| 1329 | // local storage (it is not supported by runtime). |
| 1330 | if (auto Init = VD->getAnyInitializer()) { |
| 1331 | LocalVarRefChecker Checker(*this); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1332 | if (Checker.Visit(Init)) |
| 1333 | continue; |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1334 | } |
| 1335 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1336 | Vars.push_back(RefExpr); |
Alexey Bataev | d178ad4 | 2014-03-07 08:03:37 +0000 | [diff] [blame] | 1337 | DSAStack->addDSA(VD, DE, OMPC_threadprivate); |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 1338 | VD->addAttr(OMPThreadPrivateDeclAttr::CreateImplicit( |
| 1339 | Context, SourceRange(Loc, Loc))); |
| 1340 | if (auto *ML = Context.getASTMutationListener()) |
| 1341 | ML->DeclarationMarkedOpenMPThreadPrivate(VD); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1342 | } |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 1343 | OMPThreadPrivateDecl *D = nullptr; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 1344 | if (!Vars.empty()) { |
| 1345 | D = OMPThreadPrivateDecl::Create(Context, getCurLexicalContext(), Loc, |
| 1346 | Vars); |
| 1347 | D->setAccess(AS_public); |
| 1348 | } |
| 1349 | return D; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1350 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1351 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1352 | static void ReportOriginalDSA(Sema &SemaRef, DSAStackTy *Stack, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1353 | const ValueDecl *D, DSAStackTy::DSAVarData DVar, |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1354 | bool IsLoopIterVar = false) { |
| 1355 | if (DVar.RefExpr) { |
| 1356 | SemaRef.Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_explicit_dsa) |
| 1357 | << getOpenMPClauseName(DVar.CKind); |
| 1358 | return; |
| 1359 | } |
| 1360 | enum { |
| 1361 | PDSA_StaticMemberShared, |
| 1362 | PDSA_StaticLocalVarShared, |
| 1363 | PDSA_LoopIterVarPrivate, |
| 1364 | PDSA_LoopIterVarLinear, |
| 1365 | PDSA_LoopIterVarLastprivate, |
| 1366 | PDSA_ConstVarShared, |
| 1367 | PDSA_GlobalVarShared, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1368 | PDSA_TaskVarFirstprivate, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1369 | PDSA_LocalVarPrivate, |
| 1370 | PDSA_Implicit |
| 1371 | } Reason = PDSA_Implicit; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1372 | bool ReportHint = false; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1373 | auto ReportLoc = D->getLocation(); |
| 1374 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1375 | if (IsLoopIterVar) { |
| 1376 | if (DVar.CKind == OMPC_private) |
| 1377 | Reason = PDSA_LoopIterVarPrivate; |
| 1378 | else if (DVar.CKind == OMPC_lastprivate) |
| 1379 | Reason = PDSA_LoopIterVarLastprivate; |
| 1380 | else |
| 1381 | Reason = PDSA_LoopIterVarLinear; |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 1382 | } else if (isOpenMPTaskingDirective(DVar.DKind) && |
| 1383 | DVar.CKind == OMPC_firstprivate) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1384 | Reason = PDSA_TaskVarFirstprivate; |
| 1385 | ReportLoc = DVar.ImplicitDSALoc; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1386 | } else if (VD && VD->isStaticLocal()) |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1387 | Reason = PDSA_StaticLocalVarShared; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1388 | else if (VD && VD->isStaticDataMember()) |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1389 | Reason = PDSA_StaticMemberShared; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1390 | else if (VD && VD->isFileVarDecl()) |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1391 | Reason = PDSA_GlobalVarShared; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1392 | else if (D->getType().isConstant(SemaRef.getASTContext())) |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1393 | Reason = PDSA_ConstVarShared; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1394 | else if (VD && VD->isLocalVarDecl() && DVar.CKind == OMPC_private) { |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1395 | ReportHint = true; |
| 1396 | Reason = PDSA_LocalVarPrivate; |
| 1397 | } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1398 | if (Reason != PDSA_Implicit) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1399 | SemaRef.Diag(ReportLoc, diag::note_omp_predetermined_dsa) |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1400 | << Reason << ReportHint |
| 1401 | << getOpenMPDirectiveName(Stack->getCurrentDirective()); |
| 1402 | } else if (DVar.ImplicitDSALoc.isValid()) { |
| 1403 | SemaRef.Diag(DVar.ImplicitDSALoc, diag::note_omp_implicit_dsa) |
| 1404 | << getOpenMPClauseName(DVar.CKind); |
| 1405 | } |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1406 | } |
| 1407 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1408 | namespace { |
| 1409 | class DSAAttrChecker : public StmtVisitor<DSAAttrChecker, void> { |
| 1410 | DSAStackTy *Stack; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1411 | Sema &SemaRef; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1412 | bool ErrorFound; |
| 1413 | CapturedStmt *CS; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1414 | llvm::SmallVector<Expr *, 8> ImplicitFirstprivate; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1415 | llvm::DenseMap<ValueDecl *, Expr *> VarsWithInheritedDSA; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1416 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1417 | public: |
| 1418 | void VisitDeclRefExpr(DeclRefExpr *E) { |
Alexey Bataev | 07b79c2 | 2016-04-29 09:56:11 +0000 | [diff] [blame] | 1419 | if (E->isTypeDependent() || E->isValueDependent() || |
| 1420 | E->containsUnexpandedParameterPack() || E->isInstantiationDependent()) |
| 1421 | return; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1422 | if (auto *VD = dyn_cast<VarDecl>(E->getDecl())) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1423 | // Skip internally declared variables. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1424 | if (VD->isLocalVarDecl() && !CS->capturesVariable(VD)) |
| 1425 | return; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1426 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1427 | auto DVar = Stack->getTopDSA(VD, false); |
| 1428 | // Check if the variable has explicit DSA set and stop analysis if it so. |
| 1429 | if (DVar.RefExpr) return; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1430 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1431 | auto ELoc = E->getExprLoc(); |
| 1432 | auto DKind = Stack->getCurrentDirective(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1433 | // The default(none) clause requires that each variable that is referenced |
| 1434 | // in the construct, and does not have a predetermined data-sharing |
| 1435 | // attribute, must have its data-sharing attribute explicitly determined |
| 1436 | // by being listed in a data-sharing attribute clause. |
| 1437 | if (DVar.CKind == OMPC_unknown && Stack->getDefaultDSA() == DSA_none && |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1438 | isParallelOrTaskRegion(DKind) && |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1439 | VarsWithInheritedDSA.count(VD) == 0) { |
| 1440 | VarsWithInheritedDSA[VD] = E; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1441 | return; |
| 1442 | } |
| 1443 | |
| 1444 | // OpenMP [2.9.3.6, Restrictions, p.2] |
| 1445 | // A list item that appears in a reduction clause of the innermost |
| 1446 | // enclosing worksharing or parallel construct may not be accessed in an |
| 1447 | // explicit task. |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1448 | DVar = Stack->hasInnermostDSA(VD, MatchesAnyClause(OMPC_reduction), |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1449 | [](OpenMPDirectiveKind K) -> bool { |
| 1450 | return isOpenMPParallelDirective(K) || |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1451 | isOpenMPWorksharingDirective(K) || |
| 1452 | isOpenMPTeamsDirective(K); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1453 | }, |
| 1454 | false); |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 1455 | if (isOpenMPTaskingDirective(DKind) && DVar.CKind == OMPC_reduction) { |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1456 | ErrorFound = true; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1457 | SemaRef.Diag(ELoc, diag::err_omp_reduction_in_task); |
| 1458 | ReportOriginalDSA(SemaRef, Stack, VD, DVar); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1459 | return; |
| 1460 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1461 | |
| 1462 | // Define implicit data-sharing attributes for task. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1463 | DVar = Stack->getImplicitDSA(VD, false); |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 1464 | if (isOpenMPTaskingDirective(DKind) && DVar.CKind != OMPC_shared && |
| 1465 | !Stack->isLoopControlVariable(VD).first) |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1466 | ImplicitFirstprivate.push_back(E); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1467 | } |
| 1468 | } |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1469 | void VisitMemberExpr(MemberExpr *E) { |
Alexey Bataev | 07b79c2 | 2016-04-29 09:56:11 +0000 | [diff] [blame] | 1470 | if (E->isTypeDependent() || E->isValueDependent() || |
| 1471 | E->containsUnexpandedParameterPack() || E->isInstantiationDependent()) |
| 1472 | return; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1473 | if (isa<CXXThisExpr>(E->getBase()->IgnoreParens())) { |
| 1474 | if (auto *FD = dyn_cast<FieldDecl>(E->getMemberDecl())) { |
| 1475 | auto DVar = Stack->getTopDSA(FD, false); |
| 1476 | // Check if the variable has explicit DSA set and stop analysis if it |
| 1477 | // so. |
| 1478 | if (DVar.RefExpr) |
| 1479 | return; |
| 1480 | |
| 1481 | auto ELoc = E->getExprLoc(); |
| 1482 | auto DKind = Stack->getCurrentDirective(); |
| 1483 | // OpenMP [2.9.3.6, Restrictions, p.2] |
| 1484 | // A list item that appears in a reduction clause of the innermost |
| 1485 | // enclosing worksharing or parallel construct may not be accessed in |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 1486 | // an explicit task. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1487 | DVar = |
| 1488 | Stack->hasInnermostDSA(FD, MatchesAnyClause(OMPC_reduction), |
| 1489 | [](OpenMPDirectiveKind K) -> bool { |
| 1490 | return isOpenMPParallelDirective(K) || |
| 1491 | isOpenMPWorksharingDirective(K) || |
| 1492 | isOpenMPTeamsDirective(K); |
| 1493 | }, |
| 1494 | false); |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 1495 | if (isOpenMPTaskingDirective(DKind) && DVar.CKind == OMPC_reduction) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1496 | ErrorFound = true; |
| 1497 | SemaRef.Diag(ELoc, diag::err_omp_reduction_in_task); |
| 1498 | ReportOriginalDSA(SemaRef, Stack, FD, DVar); |
| 1499 | return; |
| 1500 | } |
| 1501 | |
| 1502 | // Define implicit data-sharing attributes for task. |
| 1503 | DVar = Stack->getImplicitDSA(FD, false); |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 1504 | if (isOpenMPTaskingDirective(DKind) && DVar.CKind != OMPC_shared && |
| 1505 | !Stack->isLoopControlVariable(FD).first) |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1506 | ImplicitFirstprivate.push_back(E); |
| 1507 | } |
| 1508 | } |
| 1509 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1510 | void VisitOMPExecutableDirective(OMPExecutableDirective *S) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1511 | for (auto *C : S->clauses()) { |
| 1512 | // Skip analysis of arguments of implicitly defined firstprivate clause |
| 1513 | // for task directives. |
| 1514 | if (C && (!isa<OMPFirstprivateClause>(C) || C->getLocStart().isValid())) |
| 1515 | for (auto *CC : C->children()) { |
| 1516 | if (CC) |
| 1517 | Visit(CC); |
| 1518 | } |
| 1519 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1520 | } |
| 1521 | void VisitStmt(Stmt *S) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1522 | for (auto *C : S->children()) { |
| 1523 | if (C && !isa<OMPExecutableDirective>(C)) |
| 1524 | Visit(C); |
| 1525 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1526 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1527 | |
| 1528 | bool isErrorFound() { return ErrorFound; } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1529 | ArrayRef<Expr *> getImplicitFirstprivate() { return ImplicitFirstprivate; } |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1530 | llvm::DenseMap<ValueDecl *, Expr *> &getVarsWithInheritedDSA() { |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1531 | return VarsWithInheritedDSA; |
| 1532 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1533 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1534 | DSAAttrChecker(DSAStackTy *S, Sema &SemaRef, CapturedStmt *CS) |
| 1535 | : Stack(S), SemaRef(SemaRef), ErrorFound(false), CS(CS) {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1536 | }; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1537 | } // namespace |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1538 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1539 | void Sema::ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, Scope *CurScope) { |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1540 | switch (DKind) { |
| 1541 | case OMPD_parallel: { |
| 1542 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1543 | QualType KmpInt32PtrTy = |
| 1544 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1545 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1546 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1547 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1548 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1549 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1550 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1551 | Params); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1552 | break; |
| 1553 | } |
| 1554 | case OMPD_simd: { |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1555 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1556 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1557 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1558 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1559 | Params); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1560 | break; |
| 1561 | } |
| 1562 | case OMPD_for: { |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1563 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1564 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1565 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1566 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1567 | Params); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1568 | break; |
| 1569 | } |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1570 | case OMPD_for_simd: { |
| 1571 | Sema::CapturedParamNameType Params[] = { |
| 1572 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1573 | }; |
| 1574 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1575 | Params); |
| 1576 | break; |
| 1577 | } |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 1578 | case OMPD_sections: { |
| 1579 | Sema::CapturedParamNameType Params[] = { |
| 1580 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1581 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1582 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1583 | Params); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 1584 | break; |
| 1585 | } |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1586 | case OMPD_section: { |
| 1587 | Sema::CapturedParamNameType Params[] = { |
| 1588 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1589 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1590 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1591 | Params); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1592 | break; |
| 1593 | } |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 1594 | case OMPD_single: { |
| 1595 | Sema::CapturedParamNameType Params[] = { |
| 1596 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1597 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1598 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1599 | Params); |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 1600 | break; |
| 1601 | } |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1602 | case OMPD_master: { |
| 1603 | Sema::CapturedParamNameType Params[] = { |
| 1604 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1605 | }; |
| 1606 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1607 | Params); |
| 1608 | break; |
| 1609 | } |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1610 | case OMPD_critical: { |
| 1611 | Sema::CapturedParamNameType Params[] = { |
| 1612 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1613 | }; |
| 1614 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1615 | Params); |
| 1616 | break; |
| 1617 | } |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1618 | case OMPD_parallel_for: { |
| 1619 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1620 | QualType KmpInt32PtrTy = |
| 1621 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1622 | Sema::CapturedParamNameType Params[] = { |
| 1623 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1624 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1625 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1626 | }; |
| 1627 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1628 | Params); |
| 1629 | break; |
| 1630 | } |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1631 | case OMPD_parallel_for_simd: { |
| 1632 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1633 | QualType KmpInt32PtrTy = |
| 1634 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1635 | Sema::CapturedParamNameType Params[] = { |
| 1636 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1637 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1638 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1639 | }; |
| 1640 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1641 | Params); |
| 1642 | break; |
| 1643 | } |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1644 | case OMPD_parallel_sections: { |
Alexey Bataev | 68adb7d | 2015-04-14 03:29:22 +0000 | [diff] [blame] | 1645 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1646 | QualType KmpInt32PtrTy = |
| 1647 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1648 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | 68adb7d | 2015-04-14 03:29:22 +0000 | [diff] [blame] | 1649 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1650 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1651 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1652 | }; |
| 1653 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1654 | Params); |
| 1655 | break; |
| 1656 | } |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1657 | case OMPD_task: { |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1658 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 3ae88e2 | 2015-05-22 08:56:35 +0000 | [diff] [blame] | 1659 | QualType Args[] = {Context.VoidPtrTy.withConst().withRestrict()}; |
| 1660 | FunctionProtoType::ExtProtoInfo EPI; |
| 1661 | EPI.Variadic = true; |
| 1662 | QualType CopyFnType = Context.getFunctionType(Context.VoidTy, Args, EPI); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1663 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1664 | std::make_pair(".global_tid.", KmpInt32Ty), |
Alexey Bataev | 48591dd | 2016-04-20 04:01:36 +0000 | [diff] [blame] | 1665 | std::make_pair(".part_id.", Context.getPointerType(KmpInt32Ty)), |
| 1666 | std::make_pair(".privates.", Context.VoidPtrTy.withConst()), |
| 1667 | std::make_pair(".copy_fn.", |
| 1668 | Context.getPointerType(CopyFnType).withConst()), |
| 1669 | std::make_pair(".task_t.", Context.VoidPtrTy.withConst()), |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1670 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1671 | }; |
| 1672 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1673 | Params); |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1674 | // Mark this captured region as inlined, because we don't use outlined |
| 1675 | // function directly. |
| 1676 | getCurCapturedRegion()->TheCapturedDecl->addAttr( |
| 1677 | AlwaysInlineAttr::CreateImplicit( |
| 1678 | Context, AlwaysInlineAttr::Keyword_forceinline, SourceRange())); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1679 | break; |
| 1680 | } |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1681 | case OMPD_ordered: { |
| 1682 | Sema::CapturedParamNameType Params[] = { |
| 1683 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1684 | }; |
| 1685 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1686 | Params); |
| 1687 | break; |
| 1688 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1689 | case OMPD_atomic: { |
| 1690 | Sema::CapturedParamNameType Params[] = { |
| 1691 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1692 | }; |
| 1693 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1694 | Params); |
| 1695 | break; |
| 1696 | } |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 1697 | case OMPD_target_data: |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 1698 | case OMPD_target: |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 1699 | case OMPD_target_parallel: |
| 1700 | case OMPD_target_parallel_for: { |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1701 | Sema::CapturedParamNameType Params[] = { |
| 1702 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1703 | }; |
| 1704 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1705 | Params); |
| 1706 | break; |
| 1707 | } |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1708 | case OMPD_teams: { |
| 1709 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1710 | QualType KmpInt32PtrTy = |
| 1711 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1712 | Sema::CapturedParamNameType Params[] = { |
| 1713 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1714 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1715 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1716 | }; |
| 1717 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1718 | Params); |
| 1719 | break; |
| 1720 | } |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1721 | case OMPD_taskgroup: { |
| 1722 | Sema::CapturedParamNameType Params[] = { |
| 1723 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1724 | }; |
| 1725 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1726 | Params); |
| 1727 | break; |
| 1728 | } |
Alexey Bataev | 1e73ef3 | 2016-04-28 12:14:51 +0000 | [diff] [blame] | 1729 | case OMPD_taskloop: |
| 1730 | case OMPD_taskloop_simd: { |
Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 1731 | QualType KmpInt32Ty = |
| 1732 | Context.getIntTypeForBitwidth(/*DestWidth=*/32, /*Signed=*/1); |
| 1733 | QualType KmpUInt64Ty = |
| 1734 | Context.getIntTypeForBitwidth(/*DestWidth=*/64, /*Signed=*/0); |
| 1735 | QualType KmpInt64Ty = |
| 1736 | Context.getIntTypeForBitwidth(/*DestWidth=*/64, /*Signed=*/1); |
| 1737 | QualType Args[] = {Context.VoidPtrTy.withConst().withRestrict()}; |
| 1738 | FunctionProtoType::ExtProtoInfo EPI; |
| 1739 | EPI.Variadic = true; |
| 1740 | QualType CopyFnType = Context.getFunctionType(Context.VoidTy, Args, EPI); |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1741 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 1742 | std::make_pair(".global_tid.", KmpInt32Ty), |
| 1743 | std::make_pair(".part_id.", Context.getPointerType(KmpInt32Ty)), |
| 1744 | std::make_pair(".privates.", |
| 1745 | Context.VoidPtrTy.withConst().withRestrict()), |
| 1746 | std::make_pair( |
| 1747 | ".copy_fn.", |
| 1748 | Context.getPointerType(CopyFnType).withConst().withRestrict()), |
| 1749 | std::make_pair(".task_t.", Context.VoidPtrTy.withConst()), |
| 1750 | std::make_pair(".lb.", KmpUInt64Ty), |
| 1751 | std::make_pair(".ub.", KmpUInt64Ty), std::make_pair(".st.", KmpInt64Ty), |
| 1752 | std::make_pair(".liter.", KmpInt32Ty), |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1753 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1754 | }; |
| 1755 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1756 | Params); |
Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 1757 | // Mark this captured region as inlined, because we don't use outlined |
| 1758 | // function directly. |
| 1759 | getCurCapturedRegion()->TheCapturedDecl->addAttr( |
| 1760 | AlwaysInlineAttr::CreateImplicit( |
| 1761 | Context, AlwaysInlineAttr::Keyword_forceinline, SourceRange())); |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1762 | break; |
| 1763 | } |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1764 | case OMPD_distribute: { |
| 1765 | Sema::CapturedParamNameType Params[] = { |
| 1766 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1767 | }; |
| 1768 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1769 | Params); |
| 1770 | break; |
| 1771 | } |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1772 | case OMPD_threadprivate: |
Alexey Bataev | ee9af45 | 2014-11-21 11:33:46 +0000 | [diff] [blame] | 1773 | case OMPD_taskyield: |
| 1774 | case OMPD_barrier: |
| 1775 | case OMPD_taskwait: |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1776 | case OMPD_cancellation_point: |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1777 | case OMPD_cancel: |
Alexey Bataev | ee9af45 | 2014-11-21 11:33:46 +0000 | [diff] [blame] | 1778 | case OMPD_flush: |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1779 | case OMPD_target_enter_data: |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1780 | case OMPD_target_exit_data: |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 1781 | case OMPD_declare_reduction: |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 1782 | case OMPD_declare_simd: |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 1783 | case OMPD_declare_target: |
| 1784 | case OMPD_end_declare_target: |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1785 | llvm_unreachable("OpenMP Directive is not allowed"); |
| 1786 | case OMPD_unknown: |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1787 | llvm_unreachable("Unknown OpenMP directive"); |
| 1788 | } |
| 1789 | } |
| 1790 | |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1791 | static OMPCapturedExprDecl *buildCaptureDecl(Sema &S, IdentifierInfo *Id, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 1792 | Expr *CaptureExpr, bool WithInit, |
| 1793 | bool AsExpression) { |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 1794 | assert(CaptureExpr); |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 1795 | ASTContext &C = S.getASTContext(); |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 1796 | Expr *Init = AsExpression ? CaptureExpr : CaptureExpr->IgnoreImpCasts(); |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 1797 | QualType Ty = Init->getType(); |
| 1798 | if (CaptureExpr->getObjectKind() == OK_Ordinary && CaptureExpr->isGLValue()) { |
| 1799 | if (S.getLangOpts().CPlusPlus) |
| 1800 | Ty = C.getLValueReferenceType(Ty); |
| 1801 | else { |
| 1802 | Ty = C.getPointerType(Ty); |
| 1803 | ExprResult Res = |
| 1804 | S.CreateBuiltinUnaryOp(CaptureExpr->getExprLoc(), UO_AddrOf, Init); |
| 1805 | if (!Res.isUsable()) |
| 1806 | return nullptr; |
| 1807 | Init = Res.get(); |
| 1808 | } |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 1809 | WithInit = true; |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 1810 | } |
| 1811 | auto *CED = OMPCapturedExprDecl::Create(C, S.CurContext, Id, Ty); |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 1812 | if (!WithInit) |
| 1813 | CED->addAttr(OMPCaptureNoInitAttr::CreateImplicit(C, SourceRange())); |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 1814 | S.CurContext->addHiddenDecl(CED); |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 1815 | S.AddInitializerToDecl(CED, Init, /*DirectInit=*/false, |
| 1816 | /*TypeMayContainAuto=*/true); |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1817 | return CED; |
| 1818 | } |
| 1819 | |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 1820 | static DeclRefExpr *buildCapture(Sema &S, ValueDecl *D, Expr *CaptureExpr, |
| 1821 | bool WithInit) { |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 1822 | OMPCapturedExprDecl *CD; |
| 1823 | if (auto *VD = S.IsOpenMPCapturedDecl(D)) |
| 1824 | CD = cast<OMPCapturedExprDecl>(VD); |
| 1825 | else |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 1826 | CD = buildCaptureDecl(S, D->getIdentifier(), CaptureExpr, WithInit, |
| 1827 | /*AsExpression=*/false); |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1828 | return buildDeclRefExpr(S, CD, CD->getType().getNonReferenceType(), |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 1829 | CaptureExpr->getExprLoc()); |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1830 | } |
| 1831 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 1832 | static ExprResult buildCapture(Sema &S, Expr *CaptureExpr, DeclRefExpr *&Ref) { |
| 1833 | if (!Ref) { |
| 1834 | auto *CD = |
| 1835 | buildCaptureDecl(S, &S.getASTContext().Idents.get(".capture_expr."), |
| 1836 | CaptureExpr, /*WithInit=*/true, /*AsExpression=*/true); |
| 1837 | Ref = buildDeclRefExpr(S, CD, CD->getType().getNonReferenceType(), |
| 1838 | CaptureExpr->getExprLoc()); |
| 1839 | } |
| 1840 | ExprResult Res = Ref; |
| 1841 | if (!S.getLangOpts().CPlusPlus && |
| 1842 | CaptureExpr->getObjectKind() == OK_Ordinary && CaptureExpr->isGLValue() && |
| 1843 | Ref->getType()->isPointerType()) |
| 1844 | Res = S.CreateBuiltinUnaryOp(CaptureExpr->getExprLoc(), UO_Deref, Ref); |
| 1845 | if (!Res.isUsable()) |
| 1846 | return ExprError(); |
| 1847 | return CaptureExpr->isGLValue() ? Res : S.DefaultLvalueConversion(Res.get()); |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 1848 | } |
| 1849 | |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1850 | StmtResult Sema::ActOnOpenMPRegionEnd(StmtResult S, |
| 1851 | ArrayRef<OMPClause *> Clauses) { |
| 1852 | if (!S.isUsable()) { |
| 1853 | ActOnCapturedRegionError(); |
| 1854 | return StmtError(); |
| 1855 | } |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1856 | |
| 1857 | OMPOrderedClause *OC = nullptr; |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1858 | OMPScheduleClause *SC = nullptr; |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1859 | SmallVector<OMPLinearClause *, 4> LCs; |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1860 | // This is required for proper codegen. |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1861 | for (auto *Clause : Clauses) { |
Alexey Bataev | 16dc7b6 | 2015-05-20 03:46:04 +0000 | [diff] [blame] | 1862 | if (isOpenMPPrivate(Clause->getClauseKind()) || |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 1863 | Clause->getClauseKind() == OMPC_copyprivate || |
| 1864 | (getLangOpts().OpenMPUseTLS && |
| 1865 | getASTContext().getTargetInfo().isTLSSupported() && |
| 1866 | Clause->getClauseKind() == OMPC_copyin)) { |
| 1867 | DSAStack->setForceVarCapturing(Clause->getClauseKind() == OMPC_copyin); |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1868 | // Mark all variables in private list clauses as used in inner region. |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1869 | for (auto *VarRef : Clause->children()) { |
| 1870 | if (auto *E = cast_or_null<Expr>(VarRef)) { |
Alexey Bataev | 8bf6b3e | 2015-04-02 13:07:08 +0000 | [diff] [blame] | 1871 | MarkDeclarationsReferencedInExpr(E); |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1872 | } |
| 1873 | } |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 1874 | DSAStack->setForceVarCapturing(/*V=*/false); |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1875 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective())) { |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1876 | // Mark all variables in private list clauses as used in inner region. |
| 1877 | // Required for proper codegen of combined directives. |
| 1878 | // TODO: add processing for other clauses. |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1879 | if (auto *C = OMPClauseWithPreInit::get(Clause)) { |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 1880 | if (auto *DS = cast_or_null<DeclStmt>(C->getPreInitStmt())) { |
| 1881 | for (auto *D : DS->decls()) |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1882 | MarkVariableReferenced(D->getLocation(), cast<VarDecl>(D)); |
| 1883 | } |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 1884 | } |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 1885 | if (auto *C = OMPClauseWithPostUpdate::get(Clause)) { |
| 1886 | if (auto *E = C->getPostUpdateExpr()) |
| 1887 | MarkDeclarationsReferencedInExpr(E); |
| 1888 | } |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1889 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1890 | if (Clause->getClauseKind() == OMPC_schedule) |
| 1891 | SC = cast<OMPScheduleClause>(Clause); |
| 1892 | else if (Clause->getClauseKind() == OMPC_ordered) |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1893 | OC = cast<OMPOrderedClause>(Clause); |
| 1894 | else if (Clause->getClauseKind() == OMPC_linear) |
| 1895 | LCs.push_back(cast<OMPLinearClause>(Clause)); |
| 1896 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1897 | bool ErrorFound = false; |
| 1898 | // OpenMP, 2.7.1 Loop Construct, Restrictions |
| 1899 | // The nonmonotonic modifier cannot be specified if an ordered clause is |
| 1900 | // specified. |
| 1901 | if (SC && |
| 1902 | (SC->getFirstScheduleModifier() == OMPC_SCHEDULE_MODIFIER_nonmonotonic || |
| 1903 | SC->getSecondScheduleModifier() == |
| 1904 | OMPC_SCHEDULE_MODIFIER_nonmonotonic) && |
| 1905 | OC) { |
| 1906 | Diag(SC->getFirstScheduleModifier() == OMPC_SCHEDULE_MODIFIER_nonmonotonic |
| 1907 | ? SC->getFirstScheduleModifierLoc() |
| 1908 | : SC->getSecondScheduleModifierLoc(), |
| 1909 | diag::err_omp_schedule_nonmonotonic_ordered) |
| 1910 | << SourceRange(OC->getLocStart(), OC->getLocEnd()); |
| 1911 | ErrorFound = true; |
| 1912 | } |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1913 | if (!LCs.empty() && OC && OC->getNumForLoops()) { |
| 1914 | for (auto *C : LCs) { |
| 1915 | Diag(C->getLocStart(), diag::err_omp_linear_ordered) |
| 1916 | << SourceRange(OC->getLocStart(), OC->getLocEnd()); |
| 1917 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1918 | ErrorFound = true; |
| 1919 | } |
Alexey Bataev | 113438c | 2015-12-30 12:06:23 +0000 | [diff] [blame] | 1920 | if (isOpenMPWorksharingDirective(DSAStack->getCurrentDirective()) && |
| 1921 | isOpenMPSimdDirective(DSAStack->getCurrentDirective()) && OC && |
| 1922 | OC->getNumForLoops()) { |
| 1923 | Diag(OC->getLocStart(), diag::err_omp_ordered_simd) |
| 1924 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 1925 | ErrorFound = true; |
| 1926 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1927 | if (ErrorFound) { |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1928 | ActOnCapturedRegionError(); |
| 1929 | return StmtError(); |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1930 | } |
| 1931 | return ActOnCapturedRegionEnd(S.get()); |
| 1932 | } |
| 1933 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1934 | static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, |
| 1935 | OpenMPDirectiveKind CurrentRegion, |
| 1936 | const DeclarationNameInfo &CurrentName, |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1937 | OpenMPDirectiveKind CancelRegion, |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1938 | SourceLocation StartLoc) { |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1939 | // Allowed nesting of constructs |
| 1940 | // +------------------+-----------------+------------------------------------+ |
| 1941 | // | Parent directive | Child directive | Closely (!), No-Closely(+), Both(*)| |
| 1942 | // +------------------+-----------------+------------------------------------+ |
| 1943 | // | parallel | parallel | * | |
| 1944 | // | parallel | for | * | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1945 | // | parallel | for simd | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1946 | // | parallel | master | * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1947 | // | parallel | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1948 | // | parallel | simd | * | |
| 1949 | // | parallel | sections | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1950 | // | parallel | section | + | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1951 | // | parallel | single | * | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1952 | // | parallel | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1953 | // | parallel |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1954 | // | parallel |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1955 | // | parallel | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1956 | // | parallel | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1957 | // | parallel | barrier | * | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1958 | // | parallel | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1959 | // | parallel | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1960 | // | parallel | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1961 | // | parallel | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1962 | // | parallel | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1963 | // | parallel | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 1964 | // | parallel | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 1965 | // | parallel | target parallel | * | |
| 1966 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1967 | // | parallel | target enter | * | |
| 1968 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1969 | // | parallel | target exit | * | |
| 1970 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1971 | // | parallel | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1972 | // | parallel | cancellation | | |
| 1973 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1974 | // | parallel | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1975 | // | parallel | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1976 | // | parallel | taskloop simd | * | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1977 | // | parallel | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1978 | // +------------------+-----------------+------------------------------------+ |
| 1979 | // | for | parallel | * | |
| 1980 | // | for | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1981 | // | for | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1982 | // | for | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1983 | // | for | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1984 | // | for | simd | * | |
| 1985 | // | for | sections | + | |
| 1986 | // | for | section | + | |
| 1987 | // | for | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1988 | // | for | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1989 | // | for |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1990 | // | for |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1991 | // | for | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1992 | // | for | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1993 | // | for | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1994 | // | for | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1995 | // | for | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1996 | // | for | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1997 | // | for | ordered | * (if construct is ordered) | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1998 | // | for | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1999 | // | for | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2000 | // | for | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2001 | // | for | target parallel | * | |
| 2002 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2003 | // | for | target enter | * | |
| 2004 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2005 | // | for | target exit | * | |
| 2006 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2007 | // | for | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2008 | // | for | cancellation | | |
| 2009 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2010 | // | for | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2011 | // | for | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2012 | // | for | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2013 | // | for | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2014 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2015 | // | master | parallel | * | |
| 2016 | // | master | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2017 | // | master | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2018 | // | master | master | * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2019 | // | master | critical | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2020 | // | master | simd | * | |
| 2021 | // | master | sections | + | |
| 2022 | // | master | section | + | |
| 2023 | // | master | single | + | |
| 2024 | // | master | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2025 | // | master |parallel for simd| * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2026 | // | master |parallel sections| * | |
| 2027 | // | master | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2028 | // | master | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2029 | // | master | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2030 | // | master | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2031 | // | master | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2032 | // | master | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2033 | // | master | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2034 | // | master | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2035 | // | master | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2036 | // | master | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2037 | // | master | target parallel | * | |
| 2038 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2039 | // | master | target enter | * | |
| 2040 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2041 | // | master | target exit | * | |
| 2042 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2043 | // | master | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2044 | // | master | cancellation | | |
| 2045 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2046 | // | master | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2047 | // | master | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2048 | // | master | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2049 | // | master | distribute | | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2050 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2051 | // | critical | parallel | * | |
| 2052 | // | critical | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2053 | // | critical | for simd | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2054 | // | critical | master | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2055 | // | critical | critical | * (should have different names) | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2056 | // | critical | simd | * | |
| 2057 | // | critical | sections | + | |
| 2058 | // | critical | section | + | |
| 2059 | // | critical | single | + | |
| 2060 | // | critical | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2061 | // | critical |parallel for simd| * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2062 | // | critical |parallel sections| * | |
| 2063 | // | critical | task | * | |
| 2064 | // | critical | taskyield | * | |
| 2065 | // | critical | barrier | + | |
| 2066 | // | critical | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2067 | // | critical | taskgroup | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2068 | // | critical | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2069 | // | critical | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2070 | // | critical | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2071 | // | critical | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2072 | // | critical | target parallel | * | |
| 2073 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2074 | // | critical | target enter | * | |
| 2075 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2076 | // | critical | target exit | * | |
| 2077 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2078 | // | critical | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2079 | // | critical | cancellation | | |
| 2080 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2081 | // | critical | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2082 | // | critical | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2083 | // | critical | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2084 | // | critical | distribute | | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2085 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2086 | // | simd | parallel | | |
| 2087 | // | simd | for | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2088 | // | simd | for simd | | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2089 | // | simd | master | | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2090 | // | simd | critical | | |
Alexey Bataev | 1f09221 | 2016-02-02 04:59:52 +0000 | [diff] [blame] | 2091 | // | simd | simd | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2092 | // | simd | sections | | |
| 2093 | // | simd | section | | |
| 2094 | // | simd | single | | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2095 | // | simd | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2096 | // | simd |parallel for simd| | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2097 | // | simd |parallel sections| | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2098 | // | simd | task | | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2099 | // | simd | taskyield | | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2100 | // | simd | barrier | | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2101 | // | simd | taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2102 | // | simd | taskgroup | | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2103 | // | simd | flush | | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2104 | // | simd | ordered | + (with simd clause) | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2105 | // | simd | atomic | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2106 | // | simd | target | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2107 | // | simd | target parallel | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2108 | // | simd | target parallel | | |
| 2109 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2110 | // | simd | target enter | | |
| 2111 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2112 | // | simd | target exit | | |
| 2113 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2114 | // | simd | teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2115 | // | simd | cancellation | | |
| 2116 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2117 | // | simd | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2118 | // | simd | taskloop | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2119 | // | simd | taskloop simd | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2120 | // | simd | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2121 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2122 | // | for simd | parallel | | |
| 2123 | // | for simd | for | | |
| 2124 | // | for simd | for simd | | |
| 2125 | // | for simd | master | | |
| 2126 | // | for simd | critical | | |
Alexey Bataev | 1f09221 | 2016-02-02 04:59:52 +0000 | [diff] [blame] | 2127 | // | for simd | simd | * | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2128 | // | for simd | sections | | |
| 2129 | // | for simd | section | | |
| 2130 | // | for simd | single | | |
| 2131 | // | for simd | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2132 | // | for simd |parallel for simd| | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2133 | // | for simd |parallel sections| | |
| 2134 | // | for simd | task | | |
| 2135 | // | for simd | taskyield | | |
| 2136 | // | for simd | barrier | | |
| 2137 | // | for simd | taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2138 | // | for simd | taskgroup | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2139 | // | for simd | flush | | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2140 | // | for simd | ordered | + (with simd clause) | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2141 | // | for simd | atomic | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2142 | // | for simd | target | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2143 | // | for simd | target parallel | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2144 | // | for simd | target parallel | | |
| 2145 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2146 | // | for simd | target enter | | |
| 2147 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2148 | // | for simd | target exit | | |
| 2149 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2150 | // | for simd | teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2151 | // | for simd | cancellation | | |
| 2152 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2153 | // | for simd | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2154 | // | for simd | taskloop | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2155 | // | for simd | taskloop simd | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2156 | // | for simd | distribute | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2157 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2158 | // | parallel for simd| parallel | | |
| 2159 | // | parallel for simd| for | | |
| 2160 | // | parallel for simd| for simd | | |
| 2161 | // | parallel for simd| master | | |
| 2162 | // | parallel for simd| critical | | |
Alexey Bataev | 1f09221 | 2016-02-02 04:59:52 +0000 | [diff] [blame] | 2163 | // | parallel for simd| simd | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2164 | // | parallel for simd| sections | | |
| 2165 | // | parallel for simd| section | | |
| 2166 | // | parallel for simd| single | | |
| 2167 | // | parallel for simd| parallel for | | |
| 2168 | // | parallel for simd|parallel for simd| | |
| 2169 | // | parallel for simd|parallel sections| | |
| 2170 | // | parallel for simd| task | | |
| 2171 | // | parallel for simd| taskyield | | |
| 2172 | // | parallel for simd| barrier | | |
| 2173 | // | parallel for simd| taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2174 | // | parallel for simd| taskgroup | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2175 | // | parallel for simd| flush | | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2176 | // | parallel for simd| ordered | + (with simd clause) | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2177 | // | parallel for simd| atomic | | |
| 2178 | // | parallel for simd| target | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2179 | // | parallel for simd| target parallel | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2180 | // | parallel for simd| target parallel | | |
| 2181 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2182 | // | parallel for simd| target enter | | |
| 2183 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2184 | // | parallel for simd| target exit | | |
| 2185 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2186 | // | parallel for simd| teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2187 | // | parallel for simd| cancellation | | |
| 2188 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2189 | // | parallel for simd| cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2190 | // | parallel for simd| taskloop | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2191 | // | parallel for simd| taskloop simd | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2192 | // | parallel for simd| distribute | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2193 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2194 | // | sections | parallel | * | |
| 2195 | // | sections | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2196 | // | sections | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2197 | // | sections | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2198 | // | sections | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2199 | // | sections | simd | * | |
| 2200 | // | sections | sections | + | |
| 2201 | // | sections | section | * | |
| 2202 | // | sections | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2203 | // | sections | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2204 | // | sections |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2205 | // | sections |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2206 | // | sections | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2207 | // | sections | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2208 | // | sections | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2209 | // | sections | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2210 | // | sections | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2211 | // | sections | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2212 | // | sections | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2213 | // | sections | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2214 | // | sections | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2215 | // | sections | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2216 | // | sections | target parallel | * | |
| 2217 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2218 | // | sections | target enter | * | |
| 2219 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2220 | // | sections | target exit | * | |
| 2221 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2222 | // | sections | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2223 | // | sections | cancellation | | |
| 2224 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2225 | // | sections | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2226 | // | sections | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2227 | // | sections | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2228 | // | sections | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2229 | // +------------------+-----------------+------------------------------------+ |
| 2230 | // | section | parallel | * | |
| 2231 | // | section | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2232 | // | section | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2233 | // | section | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2234 | // | section | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2235 | // | section | simd | * | |
| 2236 | // | section | sections | + | |
| 2237 | // | section | section | + | |
| 2238 | // | section | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2239 | // | section | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2240 | // | section |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2241 | // | section |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2242 | // | section | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2243 | // | section | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2244 | // | section | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2245 | // | section | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2246 | // | section | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2247 | // | section | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2248 | // | section | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2249 | // | section | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2250 | // | section | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2251 | // | section | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2252 | // | section | target parallel | * | |
| 2253 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2254 | // | section | target enter | * | |
| 2255 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2256 | // | section | target exit | * | |
| 2257 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2258 | // | section | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2259 | // | section | cancellation | | |
| 2260 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2261 | // | section | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2262 | // | section | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2263 | // | section | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2264 | // | section | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2265 | // +------------------+-----------------+------------------------------------+ |
| 2266 | // | single | parallel | * | |
| 2267 | // | single | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2268 | // | single | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2269 | // | single | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2270 | // | single | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2271 | // | single | simd | * | |
| 2272 | // | single | sections | + | |
| 2273 | // | single | section | + | |
| 2274 | // | single | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2275 | // | single | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2276 | // | single |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2277 | // | single |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2278 | // | single | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2279 | // | single | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2280 | // | single | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2281 | // | single | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2282 | // | single | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2283 | // | single | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2284 | // | single | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2285 | // | single | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2286 | // | single | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2287 | // | single | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2288 | // | single | target parallel | * | |
| 2289 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2290 | // | single | target enter | * | |
| 2291 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2292 | // | single | target exit | * | |
| 2293 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2294 | // | single | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2295 | // | single | cancellation | | |
| 2296 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2297 | // | single | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2298 | // | single | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2299 | // | single | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2300 | // | single | distribute | | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2301 | // +------------------+-----------------+------------------------------------+ |
| 2302 | // | parallel for | parallel | * | |
| 2303 | // | parallel for | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2304 | // | parallel for | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2305 | // | parallel for | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2306 | // | parallel for | critical | * | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2307 | // | parallel for | simd | * | |
| 2308 | // | parallel for | sections | + | |
| 2309 | // | parallel for | section | + | |
| 2310 | // | parallel for | single | + | |
| 2311 | // | parallel for | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2312 | // | parallel for |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2313 | // | parallel for |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2314 | // | parallel for | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2315 | // | parallel for | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2316 | // | parallel for | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2317 | // | parallel for | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2318 | // | parallel for | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2319 | // | parallel for | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2320 | // | parallel for | ordered | * (if construct is ordered) | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2321 | // | parallel for | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2322 | // | parallel for | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2323 | // | parallel for | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2324 | // | parallel for | target parallel | * | |
| 2325 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2326 | // | parallel for | target enter | * | |
| 2327 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2328 | // | parallel for | target exit | * | |
| 2329 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2330 | // | parallel for | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2331 | // | parallel for | cancellation | | |
| 2332 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2333 | // | parallel for | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2334 | // | parallel for | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2335 | // | parallel for | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2336 | // | parallel for | distribute | | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2337 | // +------------------+-----------------+------------------------------------+ |
| 2338 | // | parallel sections| parallel | * | |
| 2339 | // | parallel sections| for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2340 | // | parallel sections| for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2341 | // | parallel sections| master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2342 | // | parallel sections| critical | + | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2343 | // | parallel sections| simd | * | |
| 2344 | // | parallel sections| sections | + | |
| 2345 | // | parallel sections| section | * | |
| 2346 | // | parallel sections| single | + | |
| 2347 | // | parallel sections| parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2348 | // | parallel sections|parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2349 | // | parallel sections|parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2350 | // | parallel sections| task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2351 | // | parallel sections| taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2352 | // | parallel sections| barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2353 | // | parallel sections| taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2354 | // | parallel sections| taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2355 | // | parallel sections| flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2356 | // | parallel sections| ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2357 | // | parallel sections| atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2358 | // | parallel sections| target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2359 | // | parallel sections| target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2360 | // | parallel sections| target parallel | * | |
| 2361 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2362 | // | parallel sections| target enter | * | |
| 2363 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2364 | // | parallel sections| target exit | * | |
| 2365 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2366 | // | parallel sections| teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2367 | // | parallel sections| cancellation | | |
| 2368 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2369 | // | parallel sections| cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2370 | // | parallel sections| taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2371 | // | parallel sections| taskloop simd | * | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2372 | // | parallel sections| distribute | | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2373 | // +------------------+-----------------+------------------------------------+ |
| 2374 | // | task | parallel | * | |
| 2375 | // | task | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2376 | // | task | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2377 | // | task | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2378 | // | task | critical | * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2379 | // | task | simd | * | |
| 2380 | // | task | sections | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2381 | // | task | section | + | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2382 | // | task | single | + | |
| 2383 | // | task | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2384 | // | task |parallel for simd| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2385 | // | task |parallel sections| * | |
| 2386 | // | task | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2387 | // | task | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2388 | // | task | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2389 | // | task | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2390 | // | task | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2391 | // | task | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2392 | // | task | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2393 | // | task | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2394 | // | task | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2395 | // | task | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2396 | // | task | target parallel | * | |
| 2397 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2398 | // | task | target enter | * | |
| 2399 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2400 | // | task | target exit | * | |
| 2401 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2402 | // | task | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2403 | // | task | cancellation | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2404 | // | | point | ! | |
| 2405 | // | task | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2406 | // | task | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2407 | // | task | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2408 | // | task | distribute | | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2409 | // +------------------+-----------------+------------------------------------+ |
| 2410 | // | ordered | parallel | * | |
| 2411 | // | ordered | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2412 | // | ordered | for simd | + | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2413 | // | ordered | master | * | |
| 2414 | // | ordered | critical | * | |
| 2415 | // | ordered | simd | * | |
| 2416 | // | ordered | sections | + | |
| 2417 | // | ordered | section | + | |
| 2418 | // | ordered | single | + | |
| 2419 | // | ordered | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2420 | // | ordered |parallel for simd| * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2421 | // | ordered |parallel sections| * | |
| 2422 | // | ordered | task | * | |
| 2423 | // | ordered | taskyield | * | |
| 2424 | // | ordered | barrier | + | |
| 2425 | // | ordered | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2426 | // | ordered | taskgroup | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2427 | // | ordered | flush | * | |
| 2428 | // | ordered | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2429 | // | ordered | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2430 | // | ordered | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2431 | // | ordered | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2432 | // | ordered | target parallel | * | |
| 2433 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2434 | // | ordered | target enter | * | |
| 2435 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2436 | // | ordered | target exit | * | |
| 2437 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2438 | // | ordered | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2439 | // | ordered | cancellation | | |
| 2440 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2441 | // | ordered | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2442 | // | ordered | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2443 | // | ordered | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2444 | // | ordered | distribute | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2445 | // +------------------+-----------------+------------------------------------+ |
| 2446 | // | atomic | parallel | | |
| 2447 | // | atomic | for | | |
| 2448 | // | atomic | for simd | | |
| 2449 | // | atomic | master | | |
| 2450 | // | atomic | critical | | |
| 2451 | // | atomic | simd | | |
| 2452 | // | atomic | sections | | |
| 2453 | // | atomic | section | | |
| 2454 | // | atomic | single | | |
| 2455 | // | atomic | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2456 | // | atomic |parallel for simd| | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2457 | // | atomic |parallel sections| | |
| 2458 | // | atomic | task | | |
| 2459 | // | atomic | taskyield | | |
| 2460 | // | atomic | barrier | | |
| 2461 | // | atomic | taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2462 | // | atomic | taskgroup | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2463 | // | atomic | flush | | |
| 2464 | // | atomic | ordered | | |
| 2465 | // | atomic | atomic | | |
| 2466 | // | atomic | target | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2467 | // | atomic | target parallel | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2468 | // | atomic | target parallel | | |
| 2469 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2470 | // | atomic | target enter | | |
| 2471 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2472 | // | atomic | target exit | | |
| 2473 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2474 | // | atomic | teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2475 | // | atomic | cancellation | | |
| 2476 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2477 | // | atomic | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2478 | // | atomic | taskloop | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2479 | // | atomic | taskloop simd | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2480 | // | atomic | distribute | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2481 | // +------------------+-----------------+------------------------------------+ |
| 2482 | // | target | parallel | * | |
| 2483 | // | target | for | * | |
| 2484 | // | target | for simd | * | |
| 2485 | // | target | master | * | |
| 2486 | // | target | critical | * | |
| 2487 | // | target | simd | * | |
| 2488 | // | target | sections | * | |
| 2489 | // | target | section | * | |
| 2490 | // | target | single | * | |
| 2491 | // | target | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2492 | // | target |parallel for simd| * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2493 | // | target |parallel sections| * | |
| 2494 | // | target | task | * | |
| 2495 | // | target | taskyield | * | |
| 2496 | // | target | barrier | * | |
| 2497 | // | target | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2498 | // | target | taskgroup | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2499 | // | target | flush | * | |
| 2500 | // | target | ordered | * | |
| 2501 | // | target | atomic | * | |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2502 | // | target | target | | |
| 2503 | // | target | target parallel | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2504 | // | target | target parallel | | |
| 2505 | // | | for | | |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2506 | // | target | target enter | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2507 | // | | data | | |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2508 | // | target | target exit | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2509 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2510 | // | target | teams | * | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2511 | // | target | cancellation | | |
| 2512 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2513 | // | target | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2514 | // | target | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2515 | // | target | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2516 | // | target | distribute | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2517 | // +------------------+-----------------+------------------------------------+ |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2518 | // | target parallel | parallel | * | |
| 2519 | // | target parallel | for | * | |
| 2520 | // | target parallel | for simd | * | |
| 2521 | // | target parallel | master | * | |
| 2522 | // | target parallel | critical | * | |
| 2523 | // | target parallel | simd | * | |
| 2524 | // | target parallel | sections | * | |
| 2525 | // | target parallel | section | * | |
| 2526 | // | target parallel | single | * | |
| 2527 | // | target parallel | parallel for | * | |
| 2528 | // | target parallel |parallel for simd| * | |
| 2529 | // | target parallel |parallel sections| * | |
| 2530 | // | target parallel | task | * | |
| 2531 | // | target parallel | taskyield | * | |
| 2532 | // | target parallel | barrier | * | |
| 2533 | // | target parallel | taskwait | * | |
| 2534 | // | target parallel | taskgroup | * | |
| 2535 | // | target parallel | flush | * | |
| 2536 | // | target parallel | ordered | * | |
| 2537 | // | target parallel | atomic | * | |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2538 | // | target parallel | target | | |
| 2539 | // | target parallel | target parallel | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2540 | // | target parallel | target parallel | | |
| 2541 | // | | for | | |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2542 | // | target parallel | target enter | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2543 | // | | data | | |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2544 | // | target parallel | target exit | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2545 | // | | data | | |
| 2546 | // | target parallel | teams | | |
| 2547 | // | target parallel | cancellation | | |
| 2548 | // | | point | ! | |
| 2549 | // | target parallel | cancel | ! | |
| 2550 | // | target parallel | taskloop | * | |
| 2551 | // | target parallel | taskloop simd | * | |
| 2552 | // | target parallel | distribute | | |
| 2553 | // +------------------+-----------------+------------------------------------+ |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2554 | // | target parallel | parallel | * | |
| 2555 | // | for | | | |
| 2556 | // | target parallel | for | * | |
| 2557 | // | for | | | |
| 2558 | // | target parallel | for simd | * | |
| 2559 | // | for | | | |
| 2560 | // | target parallel | master | * | |
| 2561 | // | for | | | |
| 2562 | // | target parallel | critical | * | |
| 2563 | // | for | | | |
| 2564 | // | target parallel | simd | * | |
| 2565 | // | for | | | |
| 2566 | // | target parallel | sections | * | |
| 2567 | // | for | | | |
| 2568 | // | target parallel | section | * | |
| 2569 | // | for | | | |
| 2570 | // | target parallel | single | * | |
| 2571 | // | for | | | |
| 2572 | // | target parallel | parallel for | * | |
| 2573 | // | for | | | |
| 2574 | // | target parallel |parallel for simd| * | |
| 2575 | // | for | | | |
| 2576 | // | target parallel |parallel sections| * | |
| 2577 | // | for | | | |
| 2578 | // | target parallel | task | * | |
| 2579 | // | for | | | |
| 2580 | // | target parallel | taskyield | * | |
| 2581 | // | for | | | |
| 2582 | // | target parallel | barrier | * | |
| 2583 | // | for | | | |
| 2584 | // | target parallel | taskwait | * | |
| 2585 | // | for | | | |
| 2586 | // | target parallel | taskgroup | * | |
| 2587 | // | for | | | |
| 2588 | // | target parallel | flush | * | |
| 2589 | // | for | | | |
| 2590 | // | target parallel | ordered | * | |
| 2591 | // | for | | | |
| 2592 | // | target parallel | atomic | * | |
| 2593 | // | for | | | |
| 2594 | // | target parallel | target | | |
| 2595 | // | for | | | |
| 2596 | // | target parallel | target parallel | | |
| 2597 | // | for | | | |
| 2598 | // | target parallel | target parallel | | |
| 2599 | // | for | for | | |
| 2600 | // | target parallel | target enter | | |
| 2601 | // | for | data | | |
| 2602 | // | target parallel | target exit | | |
| 2603 | // | for | data | | |
| 2604 | // | target parallel | teams | | |
| 2605 | // | for | | | |
| 2606 | // | target parallel | cancellation | | |
| 2607 | // | for | point | ! | |
| 2608 | // | target parallel | cancel | ! | |
| 2609 | // | for | | | |
| 2610 | // | target parallel | taskloop | * | |
| 2611 | // | for | | | |
| 2612 | // | target parallel | taskloop simd | * | |
| 2613 | // | for | | | |
| 2614 | // | target parallel | distribute | | |
| 2615 | // | for | | | |
| 2616 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2617 | // | teams | parallel | * | |
| 2618 | // | teams | for | + | |
| 2619 | // | teams | for simd | + | |
| 2620 | // | teams | master | + | |
| 2621 | // | teams | critical | + | |
| 2622 | // | teams | simd | + | |
| 2623 | // | teams | sections | + | |
| 2624 | // | teams | section | + | |
| 2625 | // | teams | single | + | |
| 2626 | // | teams | parallel for | * | |
| 2627 | // | teams |parallel for simd| * | |
| 2628 | // | teams |parallel sections| * | |
| 2629 | // | teams | task | + | |
| 2630 | // | teams | taskyield | + | |
| 2631 | // | teams | barrier | + | |
| 2632 | // | teams | taskwait | + | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2633 | // | teams | taskgroup | + | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2634 | // | teams | flush | + | |
| 2635 | // | teams | ordered | + | |
| 2636 | // | teams | atomic | + | |
| 2637 | // | teams | target | + | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2638 | // | teams | target parallel | + | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2639 | // | teams | target parallel | + | |
| 2640 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2641 | // | teams | target enter | + | |
| 2642 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2643 | // | teams | target exit | + | |
| 2644 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2645 | // | teams | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2646 | // | teams | cancellation | | |
| 2647 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2648 | // | teams | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2649 | // | teams | taskloop | + | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2650 | // | teams | taskloop simd | + | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2651 | // | teams | distribute | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2652 | // +------------------+-----------------+------------------------------------+ |
| 2653 | // | taskloop | parallel | * | |
| 2654 | // | taskloop | for | + | |
| 2655 | // | taskloop | for simd | + | |
| 2656 | // | taskloop | master | + | |
| 2657 | // | taskloop | critical | * | |
| 2658 | // | taskloop | simd | * | |
| 2659 | // | taskloop | sections | + | |
| 2660 | // | taskloop | section | + | |
| 2661 | // | taskloop | single | + | |
| 2662 | // | taskloop | parallel for | * | |
| 2663 | // | taskloop |parallel for simd| * | |
| 2664 | // | taskloop |parallel sections| * | |
| 2665 | // | taskloop | task | * | |
| 2666 | // | taskloop | taskyield | * | |
| 2667 | // | taskloop | barrier | + | |
| 2668 | // | taskloop | taskwait | * | |
| 2669 | // | taskloop | taskgroup | * | |
| 2670 | // | taskloop | flush | * | |
| 2671 | // | taskloop | ordered | + | |
| 2672 | // | taskloop | atomic | * | |
| 2673 | // | taskloop | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2674 | // | taskloop | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2675 | // | taskloop | target parallel | * | |
| 2676 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2677 | // | taskloop | target enter | * | |
| 2678 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2679 | // | taskloop | target exit | * | |
| 2680 | // | | data | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2681 | // | taskloop | teams | + | |
| 2682 | // | taskloop | cancellation | | |
| 2683 | // | | point | | |
| 2684 | // | taskloop | cancel | | |
| 2685 | // | taskloop | taskloop | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2686 | // | taskloop | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2687 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2688 | // | taskloop simd | parallel | | |
| 2689 | // | taskloop simd | for | | |
| 2690 | // | taskloop simd | for simd | | |
| 2691 | // | taskloop simd | master | | |
| 2692 | // | taskloop simd | critical | | |
Alexey Bataev | 1f09221 | 2016-02-02 04:59:52 +0000 | [diff] [blame] | 2693 | // | taskloop simd | simd | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2694 | // | taskloop simd | sections | | |
| 2695 | // | taskloop simd | section | | |
| 2696 | // | taskloop simd | single | | |
| 2697 | // | taskloop simd | parallel for | | |
| 2698 | // | taskloop simd |parallel for simd| | |
| 2699 | // | taskloop simd |parallel sections| | |
| 2700 | // | taskloop simd | task | | |
| 2701 | // | taskloop simd | taskyield | | |
| 2702 | // | taskloop simd | barrier | | |
| 2703 | // | taskloop simd | taskwait | | |
| 2704 | // | taskloop simd | taskgroup | | |
| 2705 | // | taskloop simd | flush | | |
| 2706 | // | taskloop simd | ordered | + (with simd clause) | |
| 2707 | // | taskloop simd | atomic | | |
| 2708 | // | taskloop simd | target | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2709 | // | taskloop simd | target parallel | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2710 | // | taskloop simd | target parallel | | |
| 2711 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2712 | // | taskloop simd | target enter | | |
| 2713 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2714 | // | taskloop simd | target exit | | |
| 2715 | // | | data | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2716 | // | taskloop simd | teams | | |
| 2717 | // | taskloop simd | cancellation | | |
| 2718 | // | | point | | |
| 2719 | // | taskloop simd | cancel | | |
| 2720 | // | taskloop simd | taskloop | | |
| 2721 | // | taskloop simd | taskloop simd | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2722 | // | taskloop simd | distribute | | |
| 2723 | // +------------------+-----------------+------------------------------------+ |
| 2724 | // | distribute | parallel | * | |
| 2725 | // | distribute | for | * | |
| 2726 | // | distribute | for simd | * | |
| 2727 | // | distribute | master | * | |
| 2728 | // | distribute | critical | * | |
| 2729 | // | distribute | simd | * | |
| 2730 | // | distribute | sections | * | |
| 2731 | // | distribute | section | * | |
| 2732 | // | distribute | single | * | |
| 2733 | // | distribute | parallel for | * | |
| 2734 | // | distribute |parallel for simd| * | |
| 2735 | // | distribute |parallel sections| * | |
| 2736 | // | distribute | task | * | |
| 2737 | // | distribute | taskyield | * | |
| 2738 | // | distribute | barrier | * | |
| 2739 | // | distribute | taskwait | * | |
| 2740 | // | distribute | taskgroup | * | |
| 2741 | // | distribute | flush | * | |
| 2742 | // | distribute | ordered | + | |
| 2743 | // | distribute | atomic | * | |
| 2744 | // | distribute | target | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2745 | // | distribute | target parallel | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2746 | // | distribute | target parallel | | |
| 2747 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2748 | // | distribute | target enter | | |
| 2749 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2750 | // | distribute | target exit | | |
| 2751 | // | | data | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2752 | // | distribute | teams | | |
| 2753 | // | distribute | cancellation | + | |
| 2754 | // | | point | | |
| 2755 | // | distribute | cancel | + | |
| 2756 | // | distribute | taskloop | * | |
| 2757 | // | distribute | taskloop simd | * | |
| 2758 | // | distribute | distribute | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2759 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2760 | if (Stack->getCurScope()) { |
| 2761 | auto ParentRegion = Stack->getParentDirective(); |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2762 | auto OffendingRegion = ParentRegion; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2763 | bool NestingProhibited = false; |
| 2764 | bool CloseNesting = true; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2765 | enum { |
| 2766 | NoRecommend, |
| 2767 | ShouldBeInParallelRegion, |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2768 | ShouldBeInOrderedRegion, |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2769 | ShouldBeInTargetRegion, |
| 2770 | ShouldBeInTeamsRegion |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2771 | } Recommend = NoRecommend; |
Alexey Bataev | 1f09221 | 2016-02-02 04:59:52 +0000 | [diff] [blame] | 2772 | if (isOpenMPSimdDirective(ParentRegion) && CurrentRegion != OMPD_ordered && |
| 2773 | CurrentRegion != OMPD_simd) { |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2774 | // OpenMP [2.16, Nesting of Regions] |
| 2775 | // OpenMP constructs may not be nested inside a simd region. |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2776 | // OpenMP [2.8.1,simd Construct, Restrictions] |
| 2777 | // An ordered construct with the simd clause is the only OpenMP construct |
| 2778 | // that can appear in the simd region. |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2779 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region_simd); |
| 2780 | return true; |
| 2781 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2782 | if (ParentRegion == OMPD_atomic) { |
| 2783 | // OpenMP [2.16, Nesting of Regions] |
| 2784 | // OpenMP constructs may not be nested inside an atomic region. |
| 2785 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region_atomic); |
| 2786 | return true; |
| 2787 | } |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2788 | if (CurrentRegion == OMPD_section) { |
| 2789 | // OpenMP [2.7.2, sections Construct, Restrictions] |
| 2790 | // Orphaned section directives are prohibited. That is, the section |
| 2791 | // directives must appear within the sections construct and must not be |
| 2792 | // encountered elsewhere in the sections region. |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2793 | if (ParentRegion != OMPD_sections && |
| 2794 | ParentRegion != OMPD_parallel_sections) { |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2795 | SemaRef.Diag(StartLoc, diag::err_omp_orphaned_section_directive) |
| 2796 | << (ParentRegion != OMPD_unknown) |
| 2797 | << getOpenMPDirectiveName(ParentRegion); |
| 2798 | return true; |
| 2799 | } |
| 2800 | return false; |
| 2801 | } |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2802 | // Allow some constructs to be orphaned (they could be used in functions, |
| 2803 | // called from OpenMP regions with the required preconditions). |
| 2804 | if (ParentRegion == OMPD_unknown) |
| 2805 | return false; |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2806 | if (CurrentRegion == OMPD_cancellation_point || |
| 2807 | CurrentRegion == OMPD_cancel) { |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2808 | // OpenMP [2.16, Nesting of Regions] |
| 2809 | // A cancellation point construct for which construct-type-clause is |
| 2810 | // taskgroup must be nested inside a task construct. A cancellation |
| 2811 | // point construct for which construct-type-clause is not taskgroup must |
| 2812 | // be closely nested inside an OpenMP construct that matches the type |
| 2813 | // specified in construct-type-clause. |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2814 | // A cancel construct for which construct-type-clause is taskgroup must be |
| 2815 | // nested inside a task construct. A cancel construct for which |
| 2816 | // construct-type-clause is not taskgroup must be closely nested inside an |
| 2817 | // OpenMP construct that matches the type specified in |
| 2818 | // construct-type-clause. |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2819 | NestingProhibited = |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2820 | !((CancelRegion == OMPD_parallel && |
| 2821 | (ParentRegion == OMPD_parallel || |
| 2822 | ParentRegion == OMPD_target_parallel)) || |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 2823 | (CancelRegion == OMPD_for && |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2824 | (ParentRegion == OMPD_for || ParentRegion == OMPD_parallel_for || |
| 2825 | ParentRegion == OMPD_target_parallel_for)) || |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2826 | (CancelRegion == OMPD_taskgroup && ParentRegion == OMPD_task) || |
| 2827 | (CancelRegion == OMPD_sections && |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 2828 | (ParentRegion == OMPD_section || ParentRegion == OMPD_sections || |
| 2829 | ParentRegion == OMPD_parallel_sections))); |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2830 | } else if (CurrentRegion == OMPD_master) { |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2831 | // OpenMP [2.16, Nesting of Regions] |
| 2832 | // A master region may not be closely nested inside a worksharing, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2833 | // atomic, or explicit task region. |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2834 | NestingProhibited = isOpenMPWorksharingDirective(ParentRegion) || |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 2835 | isOpenMPTaskingDirective(ParentRegion); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2836 | } else if (CurrentRegion == OMPD_critical && CurrentName.getName()) { |
| 2837 | // OpenMP [2.16, Nesting of Regions] |
| 2838 | // A critical region may not be nested (closely or otherwise) inside a |
| 2839 | // critical region with the same name. Note that this restriction is not |
| 2840 | // sufficient to prevent deadlock. |
| 2841 | SourceLocation PreviousCriticalLoc; |
| 2842 | bool DeadLock = |
| 2843 | Stack->hasDirective([CurrentName, &PreviousCriticalLoc]( |
| 2844 | OpenMPDirectiveKind K, |
| 2845 | const DeclarationNameInfo &DNI, |
| 2846 | SourceLocation Loc) |
| 2847 | ->bool { |
| 2848 | if (K == OMPD_critical && |
| 2849 | DNI.getName() == CurrentName.getName()) { |
| 2850 | PreviousCriticalLoc = Loc; |
| 2851 | return true; |
| 2852 | } else |
| 2853 | return false; |
| 2854 | }, |
| 2855 | false /* skip top directive */); |
| 2856 | if (DeadLock) { |
| 2857 | SemaRef.Diag(StartLoc, |
| 2858 | diag::err_omp_prohibited_region_critical_same_name) |
| 2859 | << CurrentName.getName(); |
| 2860 | if (PreviousCriticalLoc.isValid()) |
| 2861 | SemaRef.Diag(PreviousCriticalLoc, |
| 2862 | diag::note_omp_previous_critical_region); |
| 2863 | return true; |
| 2864 | } |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2865 | } else if (CurrentRegion == OMPD_barrier) { |
| 2866 | // OpenMP [2.16, Nesting of Regions] |
| 2867 | // A barrier region may not be closely nested inside a worksharing, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2868 | // explicit task, critical, ordered, atomic, or master region. |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 2869 | NestingProhibited = isOpenMPWorksharingDirective(ParentRegion) || |
| 2870 | isOpenMPTaskingDirective(ParentRegion) || |
| 2871 | ParentRegion == OMPD_master || |
| 2872 | ParentRegion == OMPD_critical || |
| 2873 | ParentRegion == OMPD_ordered; |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2874 | } else if (isOpenMPWorksharingDirective(CurrentRegion) && |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2875 | !isOpenMPParallelDirective(CurrentRegion)) { |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2876 | // OpenMP [2.16, Nesting of Regions] |
| 2877 | // A worksharing region may not be closely nested inside a worksharing, |
| 2878 | // explicit task, critical, ordered, atomic, or master region. |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 2879 | NestingProhibited = isOpenMPWorksharingDirective(ParentRegion) || |
| 2880 | isOpenMPTaskingDirective(ParentRegion) || |
| 2881 | ParentRegion == OMPD_master || |
| 2882 | ParentRegion == OMPD_critical || |
| 2883 | ParentRegion == OMPD_ordered; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2884 | Recommend = ShouldBeInParallelRegion; |
| 2885 | } else if (CurrentRegion == OMPD_ordered) { |
| 2886 | // OpenMP [2.16, Nesting of Regions] |
| 2887 | // An ordered region may not be closely nested inside a critical, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2888 | // atomic, or explicit task region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2889 | // An ordered region must be closely nested inside a loop region (or |
| 2890 | // parallel loop region) with an ordered clause. |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2891 | // OpenMP [2.8.1,simd Construct, Restrictions] |
| 2892 | // An ordered construct with the simd clause is the only OpenMP construct |
| 2893 | // that can appear in the simd region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2894 | NestingProhibited = ParentRegion == OMPD_critical || |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 2895 | isOpenMPTaskingDirective(ParentRegion) || |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2896 | !(isOpenMPSimdDirective(ParentRegion) || |
| 2897 | Stack->isParentOrderedRegion()); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2898 | Recommend = ShouldBeInOrderedRegion; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2899 | } else if (isOpenMPTeamsDirective(CurrentRegion)) { |
| 2900 | // OpenMP [2.16, Nesting of Regions] |
| 2901 | // If specified, a teams construct must be contained within a target |
| 2902 | // construct. |
| 2903 | NestingProhibited = ParentRegion != OMPD_target; |
| 2904 | Recommend = ShouldBeInTargetRegion; |
| 2905 | Stack->setParentTeamsRegionLoc(Stack->getConstructLoc()); |
| 2906 | } |
| 2907 | if (!NestingProhibited && isOpenMPTeamsDirective(ParentRegion)) { |
| 2908 | // OpenMP [2.16, Nesting of Regions] |
| 2909 | // distribute, parallel, parallel sections, parallel workshare, and the |
| 2910 | // parallel loop and parallel loop SIMD constructs are the only OpenMP |
| 2911 | // constructs that can be closely nested in the teams region. |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2912 | NestingProhibited = !isOpenMPParallelDirective(CurrentRegion) && |
| 2913 | !isOpenMPDistributeDirective(CurrentRegion); |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2914 | Recommend = ShouldBeInParallelRegion; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2915 | } |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2916 | if (!NestingProhibited && isOpenMPDistributeDirective(CurrentRegion)) { |
| 2917 | // OpenMP 4.5 [2.17 Nesting of Regions] |
| 2918 | // The region associated with the distribute construct must be strictly |
| 2919 | // nested inside a teams region |
| 2920 | NestingProhibited = !isOpenMPTeamsDirective(ParentRegion); |
| 2921 | Recommend = ShouldBeInTeamsRegion; |
| 2922 | } |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2923 | if (!NestingProhibited && |
| 2924 | (isOpenMPTargetExecutionDirective(CurrentRegion) || |
| 2925 | isOpenMPTargetDataManagementDirective(CurrentRegion))) { |
| 2926 | // OpenMP 4.5 [2.17 Nesting of Regions] |
| 2927 | // If a target, target update, target data, target enter data, or |
| 2928 | // target exit data construct is encountered during execution of a |
| 2929 | // target region, the behavior is unspecified. |
| 2930 | NestingProhibited = Stack->hasDirective( |
| 2931 | [&OffendingRegion](OpenMPDirectiveKind K, |
| 2932 | const DeclarationNameInfo &DNI, |
| 2933 | SourceLocation Loc) -> bool { |
| 2934 | if (isOpenMPTargetExecutionDirective(K)) { |
| 2935 | OffendingRegion = K; |
| 2936 | return true; |
| 2937 | } else |
| 2938 | return false; |
| 2939 | }, |
| 2940 | false /* don't skip top directive */); |
| 2941 | CloseNesting = false; |
| 2942 | } |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2943 | if (NestingProhibited) { |
| 2944 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region) |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2945 | << CloseNesting << getOpenMPDirectiveName(OffendingRegion) |
| 2946 | << Recommend << getOpenMPDirectiveName(CurrentRegion); |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2947 | return true; |
| 2948 | } |
| 2949 | } |
| 2950 | return false; |
| 2951 | } |
| 2952 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2953 | static bool checkIfClauses(Sema &S, OpenMPDirectiveKind Kind, |
| 2954 | ArrayRef<OMPClause *> Clauses, |
| 2955 | ArrayRef<OpenMPDirectiveKind> AllowedNameModifiers) { |
| 2956 | bool ErrorFound = false; |
| 2957 | unsigned NamedModifiersNumber = 0; |
| 2958 | SmallVector<const OMPIfClause *, OMPC_unknown + 1> FoundNameModifiers( |
| 2959 | OMPD_unknown + 1); |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2960 | SmallVector<SourceLocation, 4> NameModifierLoc; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2961 | for (const auto *C : Clauses) { |
| 2962 | if (const auto *IC = dyn_cast_or_null<OMPIfClause>(C)) { |
| 2963 | // At most one if clause without a directive-name-modifier can appear on |
| 2964 | // the directive. |
| 2965 | OpenMPDirectiveKind CurNM = IC->getNameModifier(); |
| 2966 | if (FoundNameModifiers[CurNM]) { |
| 2967 | S.Diag(C->getLocStart(), diag::err_omp_more_one_clause) |
| 2968 | << getOpenMPDirectiveName(Kind) << getOpenMPClauseName(OMPC_if) |
| 2969 | << (CurNM != OMPD_unknown) << getOpenMPDirectiveName(CurNM); |
| 2970 | ErrorFound = true; |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2971 | } else if (CurNM != OMPD_unknown) { |
| 2972 | NameModifierLoc.push_back(IC->getNameModifierLoc()); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2973 | ++NamedModifiersNumber; |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2974 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2975 | FoundNameModifiers[CurNM] = IC; |
| 2976 | if (CurNM == OMPD_unknown) |
| 2977 | continue; |
| 2978 | // Check if the specified name modifier is allowed for the current |
| 2979 | // directive. |
| 2980 | // At most one if clause with the particular directive-name-modifier can |
| 2981 | // appear on the directive. |
| 2982 | bool MatchFound = false; |
| 2983 | for (auto NM : AllowedNameModifiers) { |
| 2984 | if (CurNM == NM) { |
| 2985 | MatchFound = true; |
| 2986 | break; |
| 2987 | } |
| 2988 | } |
| 2989 | if (!MatchFound) { |
| 2990 | S.Diag(IC->getNameModifierLoc(), |
| 2991 | diag::err_omp_wrong_if_directive_name_modifier) |
| 2992 | << getOpenMPDirectiveName(CurNM) << getOpenMPDirectiveName(Kind); |
| 2993 | ErrorFound = true; |
| 2994 | } |
| 2995 | } |
| 2996 | } |
| 2997 | // If any if clause on the directive includes a directive-name-modifier then |
| 2998 | // all if clauses on the directive must include a directive-name-modifier. |
| 2999 | if (FoundNameModifiers[OMPD_unknown] && NamedModifiersNumber > 0) { |
| 3000 | if (NamedModifiersNumber == AllowedNameModifiers.size()) { |
| 3001 | S.Diag(FoundNameModifiers[OMPD_unknown]->getLocStart(), |
| 3002 | diag::err_omp_no_more_if_clause); |
| 3003 | } else { |
| 3004 | std::string Values; |
| 3005 | std::string Sep(", "); |
| 3006 | unsigned AllowedCnt = 0; |
| 3007 | unsigned TotalAllowedNum = |
| 3008 | AllowedNameModifiers.size() - NamedModifiersNumber; |
| 3009 | for (unsigned Cnt = 0, End = AllowedNameModifiers.size(); Cnt < End; |
| 3010 | ++Cnt) { |
| 3011 | OpenMPDirectiveKind NM = AllowedNameModifiers[Cnt]; |
| 3012 | if (!FoundNameModifiers[NM]) { |
| 3013 | Values += "'"; |
| 3014 | Values += getOpenMPDirectiveName(NM); |
| 3015 | Values += "'"; |
| 3016 | if (AllowedCnt + 2 == TotalAllowedNum) |
| 3017 | Values += " or "; |
| 3018 | else if (AllowedCnt + 1 != TotalAllowedNum) |
| 3019 | Values += Sep; |
| 3020 | ++AllowedCnt; |
| 3021 | } |
| 3022 | } |
| 3023 | S.Diag(FoundNameModifiers[OMPD_unknown]->getCondition()->getLocStart(), |
| 3024 | diag::err_omp_unnamed_if_clause) |
| 3025 | << (TotalAllowedNum > 1) << Values; |
| 3026 | } |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 3027 | for (auto Loc : NameModifierLoc) { |
| 3028 | S.Diag(Loc, diag::note_omp_previous_named_if_clause); |
| 3029 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3030 | ErrorFound = true; |
| 3031 | } |
| 3032 | return ErrorFound; |
| 3033 | } |
| 3034 | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 3035 | StmtResult Sema::ActOnOpenMPExecutableDirective( |
| 3036 | OpenMPDirectiveKind Kind, const DeclarationNameInfo &DirName, |
| 3037 | OpenMPDirectiveKind CancelRegion, ArrayRef<OMPClause *> Clauses, |
| 3038 | Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3039 | StmtResult Res = StmtError(); |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 3040 | if (CheckNestingOfRegions(*this, DSAStack, Kind, DirName, CancelRegion, |
| 3041 | StartLoc)) |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 3042 | return StmtError(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 3043 | |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 3044 | llvm::SmallVector<OMPClause *, 8> ClausesWithImplicit; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 3045 | llvm::DenseMap<ValueDecl *, Expr *> VarsWithInheritedDSA; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 3046 | bool ErrorFound = false; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 3047 | ClausesWithImplicit.append(Clauses.begin(), Clauses.end()); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 3048 | if (AStmt) { |
| 3049 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 3050 | |
| 3051 | // Check default data sharing attributes for referenced variables. |
| 3052 | DSAAttrChecker DSAChecker(DSAStack, *this, cast<CapturedStmt>(AStmt)); |
| 3053 | DSAChecker.Visit(cast<CapturedStmt>(AStmt)->getCapturedStmt()); |
| 3054 | if (DSAChecker.isErrorFound()) |
| 3055 | return StmtError(); |
| 3056 | // Generate list of implicitly defined firstprivate variables. |
| 3057 | VarsWithInheritedDSA = DSAChecker.getVarsWithInheritedDSA(); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 3058 | |
| 3059 | if (!DSAChecker.getImplicitFirstprivate().empty()) { |
| 3060 | if (OMPClause *Implicit = ActOnOpenMPFirstprivateClause( |
| 3061 | DSAChecker.getImplicitFirstprivate(), SourceLocation(), |
| 3062 | SourceLocation(), SourceLocation())) { |
| 3063 | ClausesWithImplicit.push_back(Implicit); |
| 3064 | ErrorFound = cast<OMPFirstprivateClause>(Implicit)->varlist_size() != |
| 3065 | DSAChecker.getImplicitFirstprivate().size(); |
| 3066 | } else |
| 3067 | ErrorFound = true; |
| 3068 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 3069 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 3070 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3071 | llvm::SmallVector<OpenMPDirectiveKind, 4> AllowedNameModifiers; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3072 | switch (Kind) { |
| 3073 | case OMPD_parallel: |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 3074 | Res = ActOnOpenMPParallelDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3075 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3076 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3077 | break; |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 3078 | case OMPD_simd: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3079 | Res = ActOnOpenMPSimdDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc, |
| 3080 | VarsWithInheritedDSA); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 3081 | break; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3082 | case OMPD_for: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3083 | Res = ActOnOpenMPForDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc, |
| 3084 | VarsWithInheritedDSA); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3085 | break; |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 3086 | case OMPD_for_simd: |
| 3087 | Res = ActOnOpenMPForSimdDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3088 | EndLoc, VarsWithInheritedDSA); |
| 3089 | break; |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 3090 | case OMPD_sections: |
| 3091 | Res = ActOnOpenMPSectionsDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3092 | EndLoc); |
| 3093 | break; |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 3094 | case OMPD_section: |
| 3095 | assert(ClausesWithImplicit.empty() && |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 3096 | "No clauses are allowed for 'omp section' directive"); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 3097 | Res = ActOnOpenMPSectionDirective(AStmt, StartLoc, EndLoc); |
| 3098 | break; |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 3099 | case OMPD_single: |
| 3100 | Res = ActOnOpenMPSingleDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3101 | EndLoc); |
| 3102 | break; |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 3103 | case OMPD_master: |
| 3104 | assert(ClausesWithImplicit.empty() && |
| 3105 | "No clauses are allowed for 'omp master' directive"); |
| 3106 | Res = ActOnOpenMPMasterDirective(AStmt, StartLoc, EndLoc); |
| 3107 | break; |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 3108 | case OMPD_critical: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 3109 | Res = ActOnOpenMPCriticalDirective(DirName, ClausesWithImplicit, AStmt, |
| 3110 | StartLoc, EndLoc); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 3111 | break; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3112 | case OMPD_parallel_for: |
| 3113 | Res = ActOnOpenMPParallelForDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3114 | EndLoc, VarsWithInheritedDSA); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3115 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3116 | break; |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 3117 | case OMPD_parallel_for_simd: |
| 3118 | Res = ActOnOpenMPParallelForSimdDirective( |
| 3119 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3120 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 3121 | break; |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 3122 | case OMPD_parallel_sections: |
| 3123 | Res = ActOnOpenMPParallelSectionsDirective(ClausesWithImplicit, AStmt, |
| 3124 | StartLoc, EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3125 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 3126 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3127 | case OMPD_task: |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 3128 | Res = |
| 3129 | ActOnOpenMPTaskDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3130 | AllowedNameModifiers.push_back(OMPD_task); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 3131 | break; |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 3132 | case OMPD_taskyield: |
| 3133 | assert(ClausesWithImplicit.empty() && |
| 3134 | "No clauses are allowed for 'omp taskyield' directive"); |
| 3135 | assert(AStmt == nullptr && |
| 3136 | "No associated statement allowed for 'omp taskyield' directive"); |
| 3137 | Res = ActOnOpenMPTaskyieldDirective(StartLoc, EndLoc); |
| 3138 | break; |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 3139 | case OMPD_barrier: |
| 3140 | assert(ClausesWithImplicit.empty() && |
| 3141 | "No clauses are allowed for 'omp barrier' directive"); |
| 3142 | assert(AStmt == nullptr && |
| 3143 | "No associated statement allowed for 'omp barrier' directive"); |
| 3144 | Res = ActOnOpenMPBarrierDirective(StartLoc, EndLoc); |
| 3145 | break; |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 3146 | case OMPD_taskwait: |
| 3147 | assert(ClausesWithImplicit.empty() && |
| 3148 | "No clauses are allowed for 'omp taskwait' directive"); |
| 3149 | assert(AStmt == nullptr && |
| 3150 | "No associated statement allowed for 'omp taskwait' directive"); |
| 3151 | Res = ActOnOpenMPTaskwaitDirective(StartLoc, EndLoc); |
| 3152 | break; |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 3153 | case OMPD_taskgroup: |
| 3154 | assert(ClausesWithImplicit.empty() && |
| 3155 | "No clauses are allowed for 'omp taskgroup' directive"); |
| 3156 | Res = ActOnOpenMPTaskgroupDirective(AStmt, StartLoc, EndLoc); |
| 3157 | break; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 3158 | case OMPD_flush: |
| 3159 | assert(AStmt == nullptr && |
| 3160 | "No associated statement allowed for 'omp flush' directive"); |
| 3161 | Res = ActOnOpenMPFlushDirective(ClausesWithImplicit, StartLoc, EndLoc); |
| 3162 | break; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 3163 | case OMPD_ordered: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 3164 | Res = ActOnOpenMPOrderedDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3165 | EndLoc); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 3166 | break; |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 3167 | case OMPD_atomic: |
| 3168 | Res = ActOnOpenMPAtomicDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3169 | EndLoc); |
| 3170 | break; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 3171 | case OMPD_teams: |
| 3172 | Res = |
| 3173 | ActOnOpenMPTeamsDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); |
| 3174 | break; |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 3175 | case OMPD_target: |
| 3176 | Res = ActOnOpenMPTargetDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3177 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3178 | AllowedNameModifiers.push_back(OMPD_target); |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 3179 | break; |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 3180 | case OMPD_target_parallel: |
| 3181 | Res = ActOnOpenMPTargetParallelDirective(ClausesWithImplicit, AStmt, |
| 3182 | StartLoc, EndLoc); |
| 3183 | AllowedNameModifiers.push_back(OMPD_target); |
| 3184 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 3185 | break; |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 3186 | case OMPD_target_parallel_for: |
| 3187 | Res = ActOnOpenMPTargetParallelForDirective( |
| 3188 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 3189 | AllowedNameModifiers.push_back(OMPD_target); |
| 3190 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 3191 | break; |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 3192 | case OMPD_cancellation_point: |
| 3193 | assert(ClausesWithImplicit.empty() && |
| 3194 | "No clauses are allowed for 'omp cancellation point' directive"); |
| 3195 | assert(AStmt == nullptr && "No associated statement allowed for 'omp " |
| 3196 | "cancellation point' directive"); |
| 3197 | Res = ActOnOpenMPCancellationPointDirective(StartLoc, EndLoc, CancelRegion); |
| 3198 | break; |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 3199 | case OMPD_cancel: |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 3200 | assert(AStmt == nullptr && |
| 3201 | "No associated statement allowed for 'omp cancel' directive"); |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 3202 | Res = ActOnOpenMPCancelDirective(ClausesWithImplicit, StartLoc, EndLoc, |
| 3203 | CancelRegion); |
| 3204 | AllowedNameModifiers.push_back(OMPD_cancel); |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 3205 | break; |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 3206 | case OMPD_target_data: |
| 3207 | Res = ActOnOpenMPTargetDataDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3208 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3209 | AllowedNameModifiers.push_back(OMPD_target_data); |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 3210 | break; |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 3211 | case OMPD_target_enter_data: |
| 3212 | Res = ActOnOpenMPTargetEnterDataDirective(ClausesWithImplicit, StartLoc, |
| 3213 | EndLoc); |
| 3214 | AllowedNameModifiers.push_back(OMPD_target_enter_data); |
| 3215 | break; |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 3216 | case OMPD_target_exit_data: |
| 3217 | Res = ActOnOpenMPTargetExitDataDirective(ClausesWithImplicit, StartLoc, |
| 3218 | EndLoc); |
| 3219 | AllowedNameModifiers.push_back(OMPD_target_exit_data); |
| 3220 | break; |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 3221 | case OMPD_taskloop: |
| 3222 | Res = ActOnOpenMPTaskLoopDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3223 | EndLoc, VarsWithInheritedDSA); |
| 3224 | AllowedNameModifiers.push_back(OMPD_taskloop); |
| 3225 | break; |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 3226 | case OMPD_taskloop_simd: |
| 3227 | Res = ActOnOpenMPTaskLoopSimdDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3228 | EndLoc, VarsWithInheritedDSA); |
| 3229 | AllowedNameModifiers.push_back(OMPD_taskloop); |
| 3230 | break; |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 3231 | case OMPD_distribute: |
| 3232 | Res = ActOnOpenMPDistributeDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3233 | EndLoc, VarsWithInheritedDSA); |
| 3234 | break; |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 3235 | case OMPD_declare_target: |
| 3236 | case OMPD_end_declare_target: |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 3237 | case OMPD_threadprivate: |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 3238 | case OMPD_declare_reduction: |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 3239 | case OMPD_declare_simd: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3240 | llvm_unreachable("OpenMP Directive is not allowed"); |
| 3241 | case OMPD_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3242 | llvm_unreachable("Unknown OpenMP directive"); |
| 3243 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 3244 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3245 | for (auto P : VarsWithInheritedDSA) { |
| 3246 | Diag(P.second->getExprLoc(), diag::err_omp_no_dsa_for_variable) |
| 3247 | << P.first << P.second->getSourceRange(); |
| 3248 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3249 | ErrorFound = !VarsWithInheritedDSA.empty() || ErrorFound; |
| 3250 | |
| 3251 | if (!AllowedNameModifiers.empty()) |
| 3252 | ErrorFound = checkIfClauses(*this, Kind, Clauses, AllowedNameModifiers) || |
| 3253 | ErrorFound; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3254 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 3255 | if (ErrorFound) |
| 3256 | return StmtError(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3257 | return Res; |
| 3258 | } |
| 3259 | |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 3260 | Sema::DeclGroupPtrTy Sema::ActOnOpenMPDeclareSimdDirective( |
| 3261 | DeclGroupPtrTy DG, OMPDeclareSimdDeclAttr::BranchStateTy BS, Expr *Simdlen, |
Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 3262 | ArrayRef<Expr *> Uniforms, ArrayRef<Expr *> Aligneds, |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 3263 | ArrayRef<Expr *> Alignments, ArrayRef<Expr *> Linears, |
| 3264 | ArrayRef<unsigned> LinModifiers, ArrayRef<Expr *> Steps, SourceRange SR) { |
Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 3265 | assert(Aligneds.size() == Alignments.size()); |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 3266 | assert(Linears.size() == LinModifiers.size()); |
| 3267 | assert(Linears.size() == Steps.size()); |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 3268 | if (!DG || DG.get().isNull()) |
| 3269 | return DeclGroupPtrTy(); |
| 3270 | |
| 3271 | if (!DG.get().isSingleDecl()) { |
Alexey Bataev | 20dfd77 | 2016-04-04 10:12:15 +0000 | [diff] [blame] | 3272 | Diag(SR.getBegin(), diag::err_omp_single_decl_in_declare_simd); |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 3273 | return DG; |
| 3274 | } |
| 3275 | auto *ADecl = DG.get().getSingleDecl(); |
| 3276 | if (auto *FTD = dyn_cast<FunctionTemplateDecl>(ADecl)) |
| 3277 | ADecl = FTD->getTemplatedDecl(); |
| 3278 | |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 3279 | auto *FD = dyn_cast<FunctionDecl>(ADecl); |
| 3280 | if (!FD) { |
| 3281 | Diag(ADecl->getLocation(), diag::err_omp_function_expected); |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 3282 | return DeclGroupPtrTy(); |
| 3283 | } |
| 3284 | |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 3285 | // OpenMP [2.8.2, declare simd construct, Description] |
| 3286 | // The parameter of the simdlen clause must be a constant positive integer |
| 3287 | // expression. |
| 3288 | ExprResult SL; |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 3289 | if (Simdlen) |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 3290 | SL = VerifyPositiveIntegerConstantInClause(Simdlen, OMPC_simdlen); |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 3291 | // OpenMP [2.8.2, declare simd construct, Description] |
| 3292 | // The special this pointer can be used as if was one of the arguments to the |
| 3293 | // function in any of the linear, aligned, or uniform clauses. |
| 3294 | // The uniform clause declares one or more arguments to have an invariant |
| 3295 | // value for all concurrent invocations of the function in the execution of a |
| 3296 | // single SIMD loop. |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 3297 | llvm::DenseMap<Decl *, Expr *> UniformedArgs; |
| 3298 | Expr *UniformedLinearThis = nullptr; |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 3299 | for (auto *E : Uniforms) { |
| 3300 | E = E->IgnoreParenImpCasts(); |
| 3301 | if (auto *DRE = dyn_cast<DeclRefExpr>(E)) |
| 3302 | if (auto *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl())) |
| 3303 | if (FD->getNumParams() > PVD->getFunctionScopeIndex() && |
| 3304 | FD->getParamDecl(PVD->getFunctionScopeIndex()) |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 3305 | ->getCanonicalDecl() == PVD->getCanonicalDecl()) { |
| 3306 | UniformedArgs.insert(std::make_pair(PVD->getCanonicalDecl(), E)); |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 3307 | continue; |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 3308 | } |
| 3309 | if (isa<CXXThisExpr>(E)) { |
| 3310 | UniformedLinearThis = E; |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 3311 | continue; |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 3312 | } |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 3313 | Diag(E->getExprLoc(), diag::err_omp_param_or_this_in_clause) |
| 3314 | << FD->getDeclName() << (isa<CXXMethodDecl>(ADecl) ? 1 : 0); |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 3315 | } |
Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 3316 | // OpenMP [2.8.2, declare simd construct, Description] |
| 3317 | // The aligned clause declares that the object to which each list item points |
| 3318 | // is aligned to the number of bytes expressed in the optional parameter of |
| 3319 | // the aligned clause. |
| 3320 | // The special this pointer can be used as if was one of the arguments to the |
| 3321 | // function in any of the linear, aligned, or uniform clauses. |
| 3322 | // The type of list items appearing in the aligned clause must be array, |
| 3323 | // pointer, reference to array, or reference to pointer. |
| 3324 | llvm::DenseMap<Decl *, Expr *> AlignedArgs; |
| 3325 | Expr *AlignedThis = nullptr; |
| 3326 | for (auto *E : Aligneds) { |
| 3327 | E = E->IgnoreParenImpCasts(); |
| 3328 | if (auto *DRE = dyn_cast<DeclRefExpr>(E)) |
| 3329 | if (auto *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl())) { |
| 3330 | auto *CanonPVD = PVD->getCanonicalDecl(); |
| 3331 | if (FD->getNumParams() > PVD->getFunctionScopeIndex() && |
| 3332 | FD->getParamDecl(PVD->getFunctionScopeIndex()) |
| 3333 | ->getCanonicalDecl() == CanonPVD) { |
| 3334 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 3335 | // A list-item cannot appear in more than one aligned clause. |
| 3336 | if (AlignedArgs.count(CanonPVD) > 0) { |
| 3337 | Diag(E->getExprLoc(), diag::err_omp_aligned_twice) |
| 3338 | << 1 << E->getSourceRange(); |
| 3339 | Diag(AlignedArgs[CanonPVD]->getExprLoc(), |
| 3340 | diag::note_omp_explicit_dsa) |
| 3341 | << getOpenMPClauseName(OMPC_aligned); |
| 3342 | continue; |
| 3343 | } |
| 3344 | AlignedArgs[CanonPVD] = E; |
| 3345 | QualType QTy = PVD->getType() |
| 3346 | .getNonReferenceType() |
| 3347 | .getUnqualifiedType() |
| 3348 | .getCanonicalType(); |
| 3349 | const Type *Ty = QTy.getTypePtrOrNull(); |
| 3350 | if (!Ty || (!Ty->isArrayType() && !Ty->isPointerType())) { |
| 3351 | Diag(E->getExprLoc(), diag::err_omp_aligned_expected_array_or_ptr) |
| 3352 | << QTy << getLangOpts().CPlusPlus << E->getSourceRange(); |
| 3353 | Diag(PVD->getLocation(), diag::note_previous_decl) << PVD; |
| 3354 | } |
| 3355 | continue; |
| 3356 | } |
| 3357 | } |
| 3358 | if (isa<CXXThisExpr>(E)) { |
| 3359 | if (AlignedThis) { |
| 3360 | Diag(E->getExprLoc(), diag::err_omp_aligned_twice) |
| 3361 | << 2 << E->getSourceRange(); |
| 3362 | Diag(AlignedThis->getExprLoc(), diag::note_omp_explicit_dsa) |
| 3363 | << getOpenMPClauseName(OMPC_aligned); |
| 3364 | } |
| 3365 | AlignedThis = E; |
| 3366 | continue; |
| 3367 | } |
| 3368 | Diag(E->getExprLoc(), diag::err_omp_param_or_this_in_clause) |
| 3369 | << FD->getDeclName() << (isa<CXXMethodDecl>(ADecl) ? 1 : 0); |
| 3370 | } |
| 3371 | // The optional parameter of the aligned clause, alignment, must be a constant |
| 3372 | // positive integer expression. If no optional parameter is specified, |
| 3373 | // implementation-defined default alignments for SIMD instructions on the |
| 3374 | // target platforms are assumed. |
| 3375 | SmallVector<Expr *, 4> NewAligns; |
| 3376 | for (auto *E : Alignments) { |
| 3377 | ExprResult Align; |
| 3378 | if (E) |
| 3379 | Align = VerifyPositiveIntegerConstantInClause(E, OMPC_aligned); |
| 3380 | NewAligns.push_back(Align.get()); |
| 3381 | } |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 3382 | // OpenMP [2.8.2, declare simd construct, Description] |
| 3383 | // The linear clause declares one or more list items to be private to a SIMD |
| 3384 | // lane and to have a linear relationship with respect to the iteration space |
| 3385 | // of a loop. |
| 3386 | // The special this pointer can be used as if was one of the arguments to the |
| 3387 | // function in any of the linear, aligned, or uniform clauses. |
| 3388 | // When a linear-step expression is specified in a linear clause it must be |
| 3389 | // either a constant integer expression or an integer-typed parameter that is |
| 3390 | // specified in a uniform clause on the directive. |
| 3391 | llvm::DenseMap<Decl *, Expr *> LinearArgs; |
| 3392 | const bool IsUniformedThis = UniformedLinearThis != nullptr; |
| 3393 | auto MI = LinModifiers.begin(); |
| 3394 | for (auto *E : Linears) { |
| 3395 | auto LinKind = static_cast<OpenMPLinearClauseKind>(*MI); |
| 3396 | ++MI; |
| 3397 | E = E->IgnoreParenImpCasts(); |
| 3398 | if (auto *DRE = dyn_cast<DeclRefExpr>(E)) |
| 3399 | if (auto *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl())) { |
| 3400 | auto *CanonPVD = PVD->getCanonicalDecl(); |
| 3401 | if (FD->getNumParams() > PVD->getFunctionScopeIndex() && |
| 3402 | FD->getParamDecl(PVD->getFunctionScopeIndex()) |
| 3403 | ->getCanonicalDecl() == CanonPVD) { |
| 3404 | // OpenMP [2.15.3.7, linear Clause, Restrictions] |
| 3405 | // A list-item cannot appear in more than one linear clause. |
| 3406 | if (LinearArgs.count(CanonPVD) > 0) { |
| 3407 | Diag(E->getExprLoc(), diag::err_omp_wrong_dsa) |
| 3408 | << getOpenMPClauseName(OMPC_linear) |
| 3409 | << getOpenMPClauseName(OMPC_linear) << E->getSourceRange(); |
| 3410 | Diag(LinearArgs[CanonPVD]->getExprLoc(), |
| 3411 | diag::note_omp_explicit_dsa) |
| 3412 | << getOpenMPClauseName(OMPC_linear); |
| 3413 | continue; |
| 3414 | } |
| 3415 | // Each argument can appear in at most one uniform or linear clause. |
| 3416 | if (UniformedArgs.count(CanonPVD) > 0) { |
| 3417 | Diag(E->getExprLoc(), diag::err_omp_wrong_dsa) |
| 3418 | << getOpenMPClauseName(OMPC_linear) |
| 3419 | << getOpenMPClauseName(OMPC_uniform) << E->getSourceRange(); |
| 3420 | Diag(UniformedArgs[CanonPVD]->getExprLoc(), |
| 3421 | diag::note_omp_explicit_dsa) |
| 3422 | << getOpenMPClauseName(OMPC_uniform); |
| 3423 | continue; |
| 3424 | } |
| 3425 | LinearArgs[CanonPVD] = E; |
| 3426 | if (E->isValueDependent() || E->isTypeDependent() || |
| 3427 | E->isInstantiationDependent() || |
| 3428 | E->containsUnexpandedParameterPack()) |
| 3429 | continue; |
| 3430 | (void)CheckOpenMPLinearDecl(CanonPVD, E->getExprLoc(), LinKind, |
| 3431 | PVD->getOriginalType()); |
| 3432 | continue; |
| 3433 | } |
| 3434 | } |
| 3435 | if (isa<CXXThisExpr>(E)) { |
| 3436 | if (UniformedLinearThis) { |
| 3437 | Diag(E->getExprLoc(), diag::err_omp_wrong_dsa) |
| 3438 | << getOpenMPClauseName(OMPC_linear) |
| 3439 | << getOpenMPClauseName(IsUniformedThis ? OMPC_uniform : OMPC_linear) |
| 3440 | << E->getSourceRange(); |
| 3441 | Diag(UniformedLinearThis->getExprLoc(), diag::note_omp_explicit_dsa) |
| 3442 | << getOpenMPClauseName(IsUniformedThis ? OMPC_uniform |
| 3443 | : OMPC_linear); |
| 3444 | continue; |
| 3445 | } |
| 3446 | UniformedLinearThis = E; |
| 3447 | if (E->isValueDependent() || E->isTypeDependent() || |
| 3448 | E->isInstantiationDependent() || E->containsUnexpandedParameterPack()) |
| 3449 | continue; |
| 3450 | (void)CheckOpenMPLinearDecl(/*D=*/nullptr, E->getExprLoc(), LinKind, |
| 3451 | E->getType()); |
| 3452 | continue; |
| 3453 | } |
| 3454 | Diag(E->getExprLoc(), diag::err_omp_param_or_this_in_clause) |
| 3455 | << FD->getDeclName() << (isa<CXXMethodDecl>(ADecl) ? 1 : 0); |
| 3456 | } |
| 3457 | Expr *Step = nullptr; |
| 3458 | Expr *NewStep = nullptr; |
| 3459 | SmallVector<Expr *, 4> NewSteps; |
| 3460 | for (auto *E : Steps) { |
| 3461 | // Skip the same step expression, it was checked already. |
| 3462 | if (Step == E || !E) { |
| 3463 | NewSteps.push_back(E ? NewStep : nullptr); |
| 3464 | continue; |
| 3465 | } |
| 3466 | Step = E; |
| 3467 | if (auto *DRE = dyn_cast<DeclRefExpr>(Step)) |
| 3468 | if (auto *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl())) { |
| 3469 | auto *CanonPVD = PVD->getCanonicalDecl(); |
| 3470 | if (UniformedArgs.count(CanonPVD) == 0) { |
| 3471 | Diag(Step->getExprLoc(), diag::err_omp_expected_uniform_param) |
| 3472 | << Step->getSourceRange(); |
| 3473 | } else if (E->isValueDependent() || E->isTypeDependent() || |
| 3474 | E->isInstantiationDependent() || |
| 3475 | E->containsUnexpandedParameterPack() || |
| 3476 | CanonPVD->getType()->hasIntegerRepresentation()) |
| 3477 | NewSteps.push_back(Step); |
| 3478 | else { |
| 3479 | Diag(Step->getExprLoc(), diag::err_omp_expected_int_param) |
| 3480 | << Step->getSourceRange(); |
| 3481 | } |
| 3482 | continue; |
| 3483 | } |
| 3484 | NewStep = Step; |
| 3485 | if (Step && !Step->isValueDependent() && !Step->isTypeDependent() && |
| 3486 | !Step->isInstantiationDependent() && |
| 3487 | !Step->containsUnexpandedParameterPack()) { |
| 3488 | NewStep = PerformOpenMPImplicitIntegerConversion(Step->getExprLoc(), Step) |
| 3489 | .get(); |
| 3490 | if (NewStep) |
| 3491 | NewStep = VerifyIntegerConstantExpression(NewStep).get(); |
| 3492 | } |
| 3493 | NewSteps.push_back(NewStep); |
| 3494 | } |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 3495 | auto *NewAttr = OMPDeclareSimdDeclAttr::CreateImplicit( |
| 3496 | Context, BS, SL.get(), const_cast<Expr **>(Uniforms.data()), |
Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 3497 | Uniforms.size(), const_cast<Expr **>(Aligneds.data()), Aligneds.size(), |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 3498 | const_cast<Expr **>(NewAligns.data()), NewAligns.size(), |
| 3499 | const_cast<Expr **>(Linears.data()), Linears.size(), |
| 3500 | const_cast<unsigned *>(LinModifiers.data()), LinModifiers.size(), |
| 3501 | NewSteps.data(), NewSteps.size(), SR); |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 3502 | ADecl->addAttr(NewAttr); |
| 3503 | return ConvertDeclToDeclGroup(ADecl); |
| 3504 | } |
| 3505 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3506 | StmtResult Sema::ActOnOpenMPParallelDirective(ArrayRef<OMPClause *> Clauses, |
| 3507 | Stmt *AStmt, |
| 3508 | SourceLocation StartLoc, |
| 3509 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3510 | if (!AStmt) |
| 3511 | return StmtError(); |
| 3512 | |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 3513 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 3514 | // 1.2.2 OpenMP Language Terminology |
| 3515 | // Structured block - An executable statement with a single entry at the |
| 3516 | // top and a single exit at the bottom. |
| 3517 | // The point of exit cannot be a branch out of the structured block. |
| 3518 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 3519 | CS->getCapturedDecl()->setNothrow(); |
| 3520 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3521 | getCurFunction()->setHasBranchProtectedScope(); |
| 3522 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 3523 | return OMPParallelDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 3524 | DSAStack->isCancelRegion()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3525 | } |
| 3526 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3527 | namespace { |
| 3528 | /// \brief Helper class for checking canonical form of the OpenMP loops and |
| 3529 | /// extracting iteration space of each loop in the loop nest, that will be used |
| 3530 | /// for IR generation. |
| 3531 | class OpenMPIterationSpaceChecker { |
| 3532 | /// \brief Reference to Sema. |
| 3533 | Sema &SemaRef; |
| 3534 | /// \brief A location for diagnostics (when there is no some better location). |
| 3535 | SourceLocation DefaultLoc; |
| 3536 | /// \brief A location for diagnostics (when increment is not compatible). |
| 3537 | SourceLocation ConditionLoc; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3538 | /// \brief A source location for referring to loop init later. |
| 3539 | SourceRange InitSrcRange; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3540 | /// \brief A source location for referring to condition later. |
| 3541 | SourceRange ConditionSrcRange; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3542 | /// \brief A source location for referring to increment later. |
| 3543 | SourceRange IncrementSrcRange; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3544 | /// \brief Loop variable. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3545 | ValueDecl *LCDecl = nullptr; |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3546 | /// \brief Reference to loop variable. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3547 | Expr *LCRef = nullptr; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3548 | /// \brief Lower bound (initializer for the var). |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3549 | Expr *LB = nullptr; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3550 | /// \brief Upper bound. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3551 | Expr *UB = nullptr; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3552 | /// \brief Loop step (increment). |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3553 | Expr *Step = nullptr; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3554 | /// \brief This flag is true when condition is one of: |
| 3555 | /// Var < UB |
| 3556 | /// Var <= UB |
| 3557 | /// UB > Var |
| 3558 | /// UB >= Var |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3559 | bool TestIsLessOp = false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3560 | /// \brief This flag is true when condition is strict ( < or > ). |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3561 | bool TestIsStrictOp = false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3562 | /// \brief This flag is true when step is subtracted on each iteration. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3563 | bool SubtractStep = false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3564 | |
| 3565 | public: |
| 3566 | OpenMPIterationSpaceChecker(Sema &SemaRef, SourceLocation DefaultLoc) |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3567 | : SemaRef(SemaRef), DefaultLoc(DefaultLoc), ConditionLoc(DefaultLoc) {} |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3568 | /// \brief Check init-expr for canonical loop form and save loop counter |
| 3569 | /// variable - #Var and its initialization value - #LB. |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3570 | bool CheckInit(Stmt *S, bool EmitDiags = true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3571 | /// \brief Check test-expr for canonical form, save upper-bound (#UB), flags |
| 3572 | /// for less/greater and for strict/non-strict comparison. |
| 3573 | bool CheckCond(Expr *S); |
| 3574 | /// \brief Check incr-expr for canonical loop form and return true if it |
| 3575 | /// does not conform, otherwise save loop step (#Step). |
| 3576 | bool CheckInc(Expr *S); |
| 3577 | /// \brief Return the loop counter variable. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3578 | ValueDecl *GetLoopDecl() const { return LCDecl; } |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3579 | /// \brief Return the reference expression to loop counter variable. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3580 | Expr *GetLoopDeclRefExpr() const { return LCRef; } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3581 | /// \brief Source range of the loop init. |
| 3582 | SourceRange GetInitSrcRange() const { return InitSrcRange; } |
| 3583 | /// \brief Source range of the loop condition. |
| 3584 | SourceRange GetConditionSrcRange() const { return ConditionSrcRange; } |
| 3585 | /// \brief Source range of the loop increment. |
| 3586 | SourceRange GetIncrementSrcRange() const { return IncrementSrcRange; } |
| 3587 | /// \brief True if the step should be subtracted. |
| 3588 | bool ShouldSubtractStep() const { return SubtractStep; } |
| 3589 | /// \brief Build the expression to calculate the number of iterations. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3590 | Expr * |
| 3591 | BuildNumIterations(Scope *S, const bool LimitedType, |
| 3592 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) const; |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3593 | /// \brief Build the precondition expression for the loops. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3594 | Expr *BuildPreCond(Scope *S, Expr *Cond, |
| 3595 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) const; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3596 | /// \brief Build reference expression to the counter be used for codegen. |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 3597 | DeclRefExpr *BuildCounterVar(llvm::MapVector<Expr *, DeclRefExpr *> &Captures, |
| 3598 | DSAStackTy &DSA) const; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3599 | /// \brief Build reference expression to the private counter be used for |
| 3600 | /// codegen. |
| 3601 | Expr *BuildPrivateCounterVar() const; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3602 | /// \brief Build initization of the counter be used for codegen. |
| 3603 | Expr *BuildCounterInit() const; |
| 3604 | /// \brief Build step of the counter be used for codegen. |
| 3605 | Expr *BuildCounterStep() const; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3606 | /// \brief Return true if any expression is dependent. |
| 3607 | bool Dependent() const; |
| 3608 | |
| 3609 | private: |
| 3610 | /// \brief Check the right-hand side of an assignment in the increment |
| 3611 | /// expression. |
| 3612 | bool CheckIncRHS(Expr *RHS); |
| 3613 | /// \brief Helper to set loop counter variable and its initializer. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3614 | bool SetLCDeclAndLB(ValueDecl *NewLCDecl, Expr *NewDeclRefExpr, Expr *NewLB); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3615 | /// \brief Helper to set upper bound. |
Craig Topper | e335f25 | 2015-10-04 04:53:55 +0000 | [diff] [blame] | 3616 | bool SetUB(Expr *NewUB, bool LessOp, bool StrictOp, SourceRange SR, |
Craig Topper | 9cd5e4f | 2015-09-21 01:23:32 +0000 | [diff] [blame] | 3617 | SourceLocation SL); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3618 | /// \brief Helper to set loop increment. |
| 3619 | bool SetStep(Expr *NewStep, bool Subtract); |
| 3620 | }; |
| 3621 | |
| 3622 | bool OpenMPIterationSpaceChecker::Dependent() const { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3623 | if (!LCDecl) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3624 | assert(!LB && !UB && !Step); |
| 3625 | return false; |
| 3626 | } |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3627 | return LCDecl->getType()->isDependentType() || |
| 3628 | (LB && LB->isValueDependent()) || (UB && UB->isValueDependent()) || |
| 3629 | (Step && Step->isValueDependent()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3630 | } |
| 3631 | |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3632 | static Expr *getExprAsWritten(Expr *E) { |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3633 | if (auto *ExprTemp = dyn_cast<ExprWithCleanups>(E)) |
| 3634 | E = ExprTemp->getSubExpr(); |
| 3635 | |
| 3636 | if (auto *MTE = dyn_cast<MaterializeTemporaryExpr>(E)) |
| 3637 | E = MTE->GetTemporaryExpr(); |
| 3638 | |
| 3639 | while (auto *Binder = dyn_cast<CXXBindTemporaryExpr>(E)) |
| 3640 | E = Binder->getSubExpr(); |
| 3641 | |
| 3642 | if (auto *ICE = dyn_cast<ImplicitCastExpr>(E)) |
| 3643 | E = ICE->getSubExprAsWritten(); |
| 3644 | return E->IgnoreParens(); |
| 3645 | } |
| 3646 | |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3647 | bool OpenMPIterationSpaceChecker::SetLCDeclAndLB(ValueDecl *NewLCDecl, |
| 3648 | Expr *NewLCRefExpr, |
| 3649 | Expr *NewLB) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3650 | // State consistency checking to ensure correct usage. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3651 | assert(LCDecl == nullptr && LB == nullptr && LCRef == nullptr && |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3652 | UB == nullptr && Step == nullptr && !TestIsLessOp && !TestIsStrictOp); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3653 | if (!NewLCDecl || !NewLB) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3654 | return true; |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3655 | LCDecl = getCanonicalDecl(NewLCDecl); |
| 3656 | LCRef = NewLCRefExpr; |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3657 | if (auto *CE = dyn_cast_or_null<CXXConstructExpr>(NewLB)) |
| 3658 | if (const CXXConstructorDecl *Ctor = CE->getConstructor()) |
Alexey Bataev | 0d08a7f | 2015-07-16 04:19:43 +0000 | [diff] [blame] | 3659 | if ((Ctor->isCopyOrMoveConstructor() || |
| 3660 | Ctor->isConvertingConstructor(/*AllowExplicit=*/false)) && |
| 3661 | CE->getNumArgs() > 0 && CE->getArg(0) != nullptr) |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3662 | NewLB = CE->getArg(0)->IgnoreParenImpCasts(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3663 | LB = NewLB; |
| 3664 | return false; |
| 3665 | } |
| 3666 | |
| 3667 | bool OpenMPIterationSpaceChecker::SetUB(Expr *NewUB, bool LessOp, bool StrictOp, |
Craig Topper | e335f25 | 2015-10-04 04:53:55 +0000 | [diff] [blame] | 3668 | SourceRange SR, SourceLocation SL) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3669 | // State consistency checking to ensure correct usage. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3670 | assert(LCDecl != nullptr && LB != nullptr && UB == nullptr && |
| 3671 | Step == nullptr && !TestIsLessOp && !TestIsStrictOp); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3672 | if (!NewUB) |
| 3673 | return true; |
| 3674 | UB = NewUB; |
| 3675 | TestIsLessOp = LessOp; |
| 3676 | TestIsStrictOp = StrictOp; |
| 3677 | ConditionSrcRange = SR; |
| 3678 | ConditionLoc = SL; |
| 3679 | return false; |
| 3680 | } |
| 3681 | |
| 3682 | bool OpenMPIterationSpaceChecker::SetStep(Expr *NewStep, bool Subtract) { |
| 3683 | // State consistency checking to ensure correct usage. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3684 | assert(LCDecl != nullptr && LB != nullptr && Step == nullptr); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3685 | if (!NewStep) |
| 3686 | return true; |
| 3687 | if (!NewStep->isValueDependent()) { |
| 3688 | // Check that the step is integer expression. |
| 3689 | SourceLocation StepLoc = NewStep->getLocStart(); |
| 3690 | ExprResult Val = |
| 3691 | SemaRef.PerformOpenMPImplicitIntegerConversion(StepLoc, NewStep); |
| 3692 | if (Val.isInvalid()) |
| 3693 | return true; |
| 3694 | NewStep = Val.get(); |
| 3695 | |
| 3696 | // OpenMP [2.6, Canonical Loop Form, Restrictions] |
| 3697 | // If test-expr is of form var relational-op b and relational-op is < or |
| 3698 | // <= then incr-expr must cause var to increase on each iteration of the |
| 3699 | // loop. If test-expr is of form var relational-op b and relational-op is |
| 3700 | // > or >= then incr-expr must cause var to decrease on each iteration of |
| 3701 | // the loop. |
| 3702 | // If test-expr is of form b relational-op var and relational-op is < or |
| 3703 | // <= then incr-expr must cause var to decrease on each iteration of the |
| 3704 | // loop. If test-expr is of form b relational-op var and relational-op is |
| 3705 | // > or >= then incr-expr must cause var to increase on each iteration of |
| 3706 | // the loop. |
| 3707 | llvm::APSInt Result; |
| 3708 | bool IsConstant = NewStep->isIntegerConstantExpr(Result, SemaRef.Context); |
| 3709 | bool IsUnsigned = !NewStep->getType()->hasSignedIntegerRepresentation(); |
| 3710 | bool IsConstNeg = |
| 3711 | IsConstant && Result.isSigned() && (Subtract != Result.isNegative()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3712 | bool IsConstPos = |
| 3713 | IsConstant && Result.isSigned() && (Subtract == Result.isNegative()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3714 | bool IsConstZero = IsConstant && !Result.getBoolValue(); |
| 3715 | if (UB && (IsConstZero || |
| 3716 | (TestIsLessOp ? (IsConstNeg || (IsUnsigned && Subtract)) |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3717 | : (IsConstPos || (IsUnsigned && !Subtract))))) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3718 | SemaRef.Diag(NewStep->getExprLoc(), |
| 3719 | diag::err_omp_loop_incr_not_compatible) |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3720 | << LCDecl << TestIsLessOp << NewStep->getSourceRange(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3721 | SemaRef.Diag(ConditionLoc, |
| 3722 | diag::note_omp_loop_cond_requres_compatible_incr) |
| 3723 | << TestIsLessOp << ConditionSrcRange; |
| 3724 | return true; |
| 3725 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3726 | if (TestIsLessOp == Subtract) { |
| 3727 | NewStep = SemaRef.CreateBuiltinUnaryOp(NewStep->getExprLoc(), UO_Minus, |
| 3728 | NewStep).get(); |
| 3729 | Subtract = !Subtract; |
| 3730 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3731 | } |
| 3732 | |
| 3733 | Step = NewStep; |
| 3734 | SubtractStep = Subtract; |
| 3735 | return false; |
| 3736 | } |
| 3737 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3738 | bool OpenMPIterationSpaceChecker::CheckInit(Stmt *S, bool EmitDiags) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3739 | // Check init-expr for canonical loop form and save loop counter |
| 3740 | // variable - #Var and its initialization value - #LB. |
| 3741 | // OpenMP [2.6] Canonical loop form. init-expr may be one of the following: |
| 3742 | // var = lb |
| 3743 | // integer-type var = lb |
| 3744 | // random-access-iterator-type var = lb |
| 3745 | // pointer-type var = lb |
| 3746 | // |
| 3747 | if (!S) { |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3748 | if (EmitDiags) { |
| 3749 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_init); |
| 3750 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3751 | return true; |
| 3752 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3753 | InitSrcRange = S->getSourceRange(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3754 | if (Expr *E = dyn_cast<Expr>(S)) |
| 3755 | S = E->IgnoreParens(); |
| 3756 | if (auto BO = dyn_cast<BinaryOperator>(S)) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3757 | if (BO->getOpcode() == BO_Assign) { |
| 3758 | auto *LHS = BO->getLHS()->IgnoreParens(); |
| 3759 | if (auto *DRE = dyn_cast<DeclRefExpr>(LHS)) { |
| 3760 | if (auto *CED = dyn_cast<OMPCapturedExprDecl>(DRE->getDecl())) |
| 3761 | if (auto *ME = dyn_cast<MemberExpr>(getExprAsWritten(CED->getInit()))) |
| 3762 | return SetLCDeclAndLB(ME->getMemberDecl(), ME, BO->getRHS()); |
| 3763 | return SetLCDeclAndLB(DRE->getDecl(), DRE, BO->getRHS()); |
| 3764 | } |
| 3765 | if (auto *ME = dyn_cast<MemberExpr>(LHS)) { |
| 3766 | if (ME->isArrow() && |
| 3767 | isa<CXXThisExpr>(ME->getBase()->IgnoreParenImpCasts())) |
| 3768 | return SetLCDeclAndLB(ME->getMemberDecl(), ME, BO->getRHS()); |
| 3769 | } |
| 3770 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3771 | } else if (auto DS = dyn_cast<DeclStmt>(S)) { |
| 3772 | if (DS->isSingleDecl()) { |
| 3773 | if (auto Var = dyn_cast_or_null<VarDecl>(DS->getSingleDecl())) { |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3774 | if (Var->hasInit() && !Var->getType()->isReferenceType()) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3775 | // Accept non-canonical init form here but emit ext. warning. |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3776 | if (Var->getInitStyle() != VarDecl::CInit && EmitDiags) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3777 | SemaRef.Diag(S->getLocStart(), |
| 3778 | diag::ext_omp_loop_not_canonical_init) |
| 3779 | << S->getSourceRange(); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3780 | return SetLCDeclAndLB(Var, nullptr, Var->getInit()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3781 | } |
| 3782 | } |
| 3783 | } |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3784 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
| 3785 | if (CE->getOperator() == OO_Equal) { |
| 3786 | auto *LHS = CE->getArg(0); |
| 3787 | if (auto DRE = dyn_cast<DeclRefExpr>(LHS)) { |
| 3788 | if (auto *CED = dyn_cast<OMPCapturedExprDecl>(DRE->getDecl())) |
| 3789 | if (auto *ME = dyn_cast<MemberExpr>(getExprAsWritten(CED->getInit()))) |
| 3790 | return SetLCDeclAndLB(ME->getMemberDecl(), ME, BO->getRHS()); |
| 3791 | return SetLCDeclAndLB(DRE->getDecl(), DRE, CE->getArg(1)); |
| 3792 | } |
| 3793 | if (auto *ME = dyn_cast<MemberExpr>(LHS)) { |
| 3794 | if (ME->isArrow() && |
| 3795 | isa<CXXThisExpr>(ME->getBase()->IgnoreParenImpCasts())) |
| 3796 | return SetLCDeclAndLB(ME->getMemberDecl(), ME, BO->getRHS()); |
| 3797 | } |
| 3798 | } |
| 3799 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3800 | |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3801 | if (Dependent() || SemaRef.CurContext->isDependentContext()) |
| 3802 | return false; |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3803 | if (EmitDiags) { |
| 3804 | SemaRef.Diag(S->getLocStart(), diag::err_omp_loop_not_canonical_init) |
| 3805 | << S->getSourceRange(); |
| 3806 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3807 | return true; |
| 3808 | } |
| 3809 | |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 3810 | /// \brief Ignore parenthesizes, implicit casts, copy constructor and return the |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3811 | /// variable (which may be the loop variable) if possible. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3812 | static const ValueDecl *GetInitLCDecl(Expr *E) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3813 | if (!E) |
Craig Topper | 4b56692 | 2014-06-09 02:04:02 +0000 | [diff] [blame] | 3814 | return nullptr; |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3815 | E = getExprAsWritten(E); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3816 | if (auto *CE = dyn_cast_or_null<CXXConstructExpr>(E)) |
| 3817 | if (const CXXConstructorDecl *Ctor = CE->getConstructor()) |
Alexey Bataev | 0d08a7f | 2015-07-16 04:19:43 +0000 | [diff] [blame] | 3818 | if ((Ctor->isCopyOrMoveConstructor() || |
| 3819 | Ctor->isConvertingConstructor(/*AllowExplicit=*/false)) && |
| 3820 | CE->getNumArgs() > 0 && CE->getArg(0) != nullptr) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3821 | E = CE->getArg(0)->IgnoreParenImpCasts(); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3822 | if (auto *DRE = dyn_cast_or_null<DeclRefExpr>(E)) { |
| 3823 | if (auto *VD = dyn_cast<VarDecl>(DRE->getDecl())) { |
| 3824 | if (auto *CED = dyn_cast<OMPCapturedExprDecl>(VD)) |
| 3825 | if (auto *ME = dyn_cast<MemberExpr>(getExprAsWritten(CED->getInit()))) |
| 3826 | return getCanonicalDecl(ME->getMemberDecl()); |
| 3827 | return getCanonicalDecl(VD); |
| 3828 | } |
| 3829 | } |
| 3830 | if (auto *ME = dyn_cast_or_null<MemberExpr>(E)) |
| 3831 | if (ME->isArrow() && isa<CXXThisExpr>(ME->getBase()->IgnoreParenImpCasts())) |
| 3832 | return getCanonicalDecl(ME->getMemberDecl()); |
| 3833 | return nullptr; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3834 | } |
| 3835 | |
| 3836 | bool OpenMPIterationSpaceChecker::CheckCond(Expr *S) { |
| 3837 | // Check test-expr for canonical form, save upper-bound UB, flags for |
| 3838 | // less/greater and for strict/non-strict comparison. |
| 3839 | // OpenMP [2.6] Canonical loop form. Test-expr may be one of the following: |
| 3840 | // var relational-op b |
| 3841 | // b relational-op var |
| 3842 | // |
| 3843 | if (!S) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3844 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_cond) << LCDecl; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3845 | return true; |
| 3846 | } |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3847 | S = getExprAsWritten(S); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3848 | SourceLocation CondLoc = S->getLocStart(); |
| 3849 | if (auto BO = dyn_cast<BinaryOperator>(S)) { |
| 3850 | if (BO->isRelationalOp()) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3851 | if (GetInitLCDecl(BO->getLHS()) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3852 | return SetUB(BO->getRHS(), |
| 3853 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_LE), |
| 3854 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_GT), |
| 3855 | BO->getSourceRange(), BO->getOperatorLoc()); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3856 | if (GetInitLCDecl(BO->getRHS()) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3857 | return SetUB(BO->getLHS(), |
| 3858 | (BO->getOpcode() == BO_GT || BO->getOpcode() == BO_GE), |
| 3859 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_GT), |
| 3860 | BO->getSourceRange(), BO->getOperatorLoc()); |
| 3861 | } |
| 3862 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
| 3863 | if (CE->getNumArgs() == 2) { |
| 3864 | auto Op = CE->getOperator(); |
| 3865 | switch (Op) { |
| 3866 | case OO_Greater: |
| 3867 | case OO_GreaterEqual: |
| 3868 | case OO_Less: |
| 3869 | case OO_LessEqual: |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3870 | if (GetInitLCDecl(CE->getArg(0)) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3871 | return SetUB(CE->getArg(1), Op == OO_Less || Op == OO_LessEqual, |
| 3872 | Op == OO_Less || Op == OO_Greater, CE->getSourceRange(), |
| 3873 | CE->getOperatorLoc()); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3874 | if (GetInitLCDecl(CE->getArg(1)) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3875 | return SetUB(CE->getArg(0), Op == OO_Greater || Op == OO_GreaterEqual, |
| 3876 | Op == OO_Less || Op == OO_Greater, CE->getSourceRange(), |
| 3877 | CE->getOperatorLoc()); |
| 3878 | break; |
| 3879 | default: |
| 3880 | break; |
| 3881 | } |
| 3882 | } |
| 3883 | } |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3884 | if (Dependent() || SemaRef.CurContext->isDependentContext()) |
| 3885 | return false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3886 | SemaRef.Diag(CondLoc, diag::err_omp_loop_not_canonical_cond) |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3887 | << S->getSourceRange() << LCDecl; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3888 | return true; |
| 3889 | } |
| 3890 | |
| 3891 | bool OpenMPIterationSpaceChecker::CheckIncRHS(Expr *RHS) { |
| 3892 | // RHS of canonical loop form increment can be: |
| 3893 | // var + incr |
| 3894 | // incr + var |
| 3895 | // var - incr |
| 3896 | // |
| 3897 | RHS = RHS->IgnoreParenImpCasts(); |
| 3898 | if (auto BO = dyn_cast<BinaryOperator>(RHS)) { |
| 3899 | if (BO->isAdditiveOp()) { |
| 3900 | bool IsAdd = BO->getOpcode() == BO_Add; |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3901 | if (GetInitLCDecl(BO->getLHS()) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3902 | return SetStep(BO->getRHS(), !IsAdd); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3903 | if (IsAdd && GetInitLCDecl(BO->getRHS()) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3904 | return SetStep(BO->getLHS(), false); |
| 3905 | } |
| 3906 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(RHS)) { |
| 3907 | bool IsAdd = CE->getOperator() == OO_Plus; |
| 3908 | if ((IsAdd || CE->getOperator() == OO_Minus) && CE->getNumArgs() == 2) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3909 | if (GetInitLCDecl(CE->getArg(0)) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3910 | return SetStep(CE->getArg(1), !IsAdd); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3911 | if (IsAdd && GetInitLCDecl(CE->getArg(1)) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3912 | return SetStep(CE->getArg(0), false); |
| 3913 | } |
| 3914 | } |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3915 | if (Dependent() || SemaRef.CurContext->isDependentContext()) |
| 3916 | return false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3917 | SemaRef.Diag(RHS->getLocStart(), diag::err_omp_loop_not_canonical_incr) |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3918 | << RHS->getSourceRange() << LCDecl; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3919 | return true; |
| 3920 | } |
| 3921 | |
| 3922 | bool OpenMPIterationSpaceChecker::CheckInc(Expr *S) { |
| 3923 | // Check incr-expr for canonical loop form and return true if it |
| 3924 | // does not conform. |
| 3925 | // OpenMP [2.6] Canonical loop form. Test-expr may be one of the following: |
| 3926 | // ++var |
| 3927 | // var++ |
| 3928 | // --var |
| 3929 | // var-- |
| 3930 | // var += incr |
| 3931 | // var -= incr |
| 3932 | // var = var + incr |
| 3933 | // var = incr + var |
| 3934 | // var = var - incr |
| 3935 | // |
| 3936 | if (!S) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3937 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_incr) << LCDecl; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3938 | return true; |
| 3939 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3940 | IncrementSrcRange = S->getSourceRange(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3941 | S = S->IgnoreParens(); |
| 3942 | if (auto UO = dyn_cast<UnaryOperator>(S)) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3943 | if (UO->isIncrementDecrementOp() && |
| 3944 | GetInitLCDecl(UO->getSubExpr()) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3945 | return SetStep( |
| 3946 | SemaRef.ActOnIntegerConstant(UO->getLocStart(), |
| 3947 | (UO->isDecrementOp() ? -1 : 1)).get(), |
| 3948 | false); |
| 3949 | } else if (auto BO = dyn_cast<BinaryOperator>(S)) { |
| 3950 | switch (BO->getOpcode()) { |
| 3951 | case BO_AddAssign: |
| 3952 | case BO_SubAssign: |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3953 | if (GetInitLCDecl(BO->getLHS()) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3954 | return SetStep(BO->getRHS(), BO->getOpcode() == BO_SubAssign); |
| 3955 | break; |
| 3956 | case BO_Assign: |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3957 | if (GetInitLCDecl(BO->getLHS()) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3958 | return CheckIncRHS(BO->getRHS()); |
| 3959 | break; |
| 3960 | default: |
| 3961 | break; |
| 3962 | } |
| 3963 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
| 3964 | switch (CE->getOperator()) { |
| 3965 | case OO_PlusPlus: |
| 3966 | case OO_MinusMinus: |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3967 | if (GetInitLCDecl(CE->getArg(0)) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3968 | return SetStep( |
| 3969 | SemaRef.ActOnIntegerConstant( |
| 3970 | CE->getLocStart(), |
| 3971 | ((CE->getOperator() == OO_MinusMinus) ? -1 : 1)).get(), |
| 3972 | false); |
| 3973 | break; |
| 3974 | case OO_PlusEqual: |
| 3975 | case OO_MinusEqual: |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3976 | if (GetInitLCDecl(CE->getArg(0)) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3977 | return SetStep(CE->getArg(1), CE->getOperator() == OO_MinusEqual); |
| 3978 | break; |
| 3979 | case OO_Equal: |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3980 | if (GetInitLCDecl(CE->getArg(0)) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3981 | return CheckIncRHS(CE->getArg(1)); |
| 3982 | break; |
| 3983 | default: |
| 3984 | break; |
| 3985 | } |
| 3986 | } |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3987 | if (Dependent() || SemaRef.CurContext->isDependentContext()) |
| 3988 | return false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3989 | SemaRef.Diag(S->getLocStart(), diag::err_omp_loop_not_canonical_incr) |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3990 | << S->getSourceRange() << LCDecl; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3991 | return true; |
| 3992 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3993 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3994 | static ExprResult |
| 3995 | tryBuildCapture(Sema &SemaRef, Expr *Capture, |
| 3996 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) { |
| 3997 | if (Capture->isEvaluatable(SemaRef.Context, Expr::SE_AllowSideEffects)) |
| 3998 | return SemaRef.PerformImplicitConversion( |
| 3999 | Capture->IgnoreImpCasts(), Capture->getType(), Sema::AA_Converting, |
| 4000 | /*AllowExplicit=*/true); |
| 4001 | auto I = Captures.find(Capture); |
| 4002 | if (I != Captures.end()) |
| 4003 | return buildCapture(SemaRef, Capture, I->second); |
| 4004 | DeclRefExpr *Ref = nullptr; |
| 4005 | ExprResult Res = buildCapture(SemaRef, Capture, Ref); |
| 4006 | Captures[Capture] = Ref; |
| 4007 | return Res; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4008 | } |
| 4009 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4010 | /// \brief Build the expression to calculate the number of iterations. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4011 | Expr *OpenMPIterationSpaceChecker::BuildNumIterations( |
| 4012 | Scope *S, const bool LimitedType, |
| 4013 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) const { |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4014 | ExprResult Diff; |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4015 | auto VarType = LCDecl->getType().getNonReferenceType(); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4016 | if (VarType->isIntegerType() || VarType->isPointerType() || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4017 | SemaRef.getLangOpts().CPlusPlus) { |
| 4018 | // Upper - Lower |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4019 | auto *UBExpr = TestIsLessOp ? UB : LB; |
| 4020 | auto *LBExpr = TestIsLessOp ? LB : UB; |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4021 | Expr *Upper = tryBuildCapture(SemaRef, UBExpr, Captures).get(); |
| 4022 | Expr *Lower = tryBuildCapture(SemaRef, LBExpr, Captures).get(); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4023 | if (!Upper || !Lower) |
| 4024 | return nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4025 | |
| 4026 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Sub, Upper, Lower); |
| 4027 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4028 | if (!Diff.isUsable() && VarType->getAsCXXRecordDecl()) { |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4029 | // BuildBinOp already emitted error, this one is to point user to upper |
| 4030 | // and lower bound, and to tell what is passed to 'operator-'. |
| 4031 | SemaRef.Diag(Upper->getLocStart(), diag::err_omp_loop_diff_cxx) |
| 4032 | << Upper->getSourceRange() << Lower->getSourceRange(); |
| 4033 | return nullptr; |
| 4034 | } |
| 4035 | } |
| 4036 | |
| 4037 | if (!Diff.isUsable()) |
| 4038 | return nullptr; |
| 4039 | |
| 4040 | // Upper - Lower [- 1] |
| 4041 | if (TestIsStrictOp) |
| 4042 | Diff = SemaRef.BuildBinOp( |
| 4043 | S, DefaultLoc, BO_Sub, Diff.get(), |
| 4044 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 4045 | if (!Diff.isUsable()) |
| 4046 | return nullptr; |
| 4047 | |
| 4048 | // Upper - Lower [- 1] + Step |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4049 | auto NewStep = tryBuildCapture(SemaRef, Step, Captures); |
| 4050 | if (!NewStep.isUsable()) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4051 | return nullptr; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4052 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Add, Diff.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4053 | if (!Diff.isUsable()) |
| 4054 | return nullptr; |
| 4055 | |
| 4056 | // Parentheses (for dumping/debugging purposes only). |
| 4057 | Diff = SemaRef.ActOnParenExpr(DefaultLoc, DefaultLoc, Diff.get()); |
| 4058 | if (!Diff.isUsable()) |
| 4059 | return nullptr; |
| 4060 | |
| 4061 | // (Upper - Lower [- 1] + Step) / Step |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4062 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Div, Diff.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4063 | if (!Diff.isUsable()) |
| 4064 | return nullptr; |
| 4065 | |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 4066 | // OpenMP runtime requires 32-bit or 64-bit loop variables. |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4067 | QualType Type = Diff.get()->getType(); |
| 4068 | auto &C = SemaRef.Context; |
| 4069 | bool UseVarType = VarType->hasIntegerRepresentation() && |
| 4070 | C.getTypeSize(Type) > C.getTypeSize(VarType); |
| 4071 | if (!Type->isIntegerType() || UseVarType) { |
| 4072 | unsigned NewSize = |
| 4073 | UseVarType ? C.getTypeSize(VarType) : C.getTypeSize(Type); |
| 4074 | bool IsSigned = UseVarType ? VarType->hasSignedIntegerRepresentation() |
| 4075 | : Type->hasSignedIntegerRepresentation(); |
| 4076 | Type = C.getIntTypeForBitwidth(NewSize, IsSigned); |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 4077 | if (!SemaRef.Context.hasSameType(Diff.get()->getType(), Type)) { |
| 4078 | Diff = SemaRef.PerformImplicitConversion( |
| 4079 | Diff.get(), Type, Sema::AA_Converting, /*AllowExplicit=*/true); |
| 4080 | if (!Diff.isUsable()) |
| 4081 | return nullptr; |
| 4082 | } |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4083 | } |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 4084 | if (LimitedType) { |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 4085 | unsigned NewSize = (C.getTypeSize(Type) > 32) ? 64 : 32; |
| 4086 | if (NewSize != C.getTypeSize(Type)) { |
| 4087 | if (NewSize < C.getTypeSize(Type)) { |
| 4088 | assert(NewSize == 64 && "incorrect loop var size"); |
| 4089 | SemaRef.Diag(DefaultLoc, diag::warn_omp_loop_64_bit_var) |
| 4090 | << InitSrcRange << ConditionSrcRange; |
| 4091 | } |
| 4092 | QualType NewType = C.getIntTypeForBitwidth( |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4093 | NewSize, Type->hasSignedIntegerRepresentation() || |
| 4094 | C.getTypeSize(Type) < NewSize); |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 4095 | if (!SemaRef.Context.hasSameType(Diff.get()->getType(), NewType)) { |
| 4096 | Diff = SemaRef.PerformImplicitConversion(Diff.get(), NewType, |
| 4097 | Sema::AA_Converting, true); |
| 4098 | if (!Diff.isUsable()) |
| 4099 | return nullptr; |
| 4100 | } |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 4101 | } |
| 4102 | } |
| 4103 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4104 | return Diff.get(); |
| 4105 | } |
| 4106 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4107 | Expr *OpenMPIterationSpaceChecker::BuildPreCond( |
| 4108 | Scope *S, Expr *Cond, |
| 4109 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) const { |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 4110 | // Try to build LB <op> UB, where <op> is <, >, <=, or >=. |
| 4111 | bool Suppress = SemaRef.getDiagnostics().getSuppressAllDiagnostics(); |
| 4112 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(/*Val=*/true); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4113 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4114 | auto NewLB = tryBuildCapture(SemaRef, LB, Captures); |
| 4115 | auto NewUB = tryBuildCapture(SemaRef, UB, Captures); |
| 4116 | if (!NewLB.isUsable() || !NewUB.isUsable()) |
| 4117 | return nullptr; |
| 4118 | |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 4119 | auto CondExpr = SemaRef.BuildBinOp( |
| 4120 | S, DefaultLoc, TestIsLessOp ? (TestIsStrictOp ? BO_LT : BO_LE) |
| 4121 | : (TestIsStrictOp ? BO_GT : BO_GE), |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4122 | NewLB.get(), NewUB.get()); |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 4123 | if (CondExpr.isUsable()) { |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4124 | if (!SemaRef.Context.hasSameUnqualifiedType(CondExpr.get()->getType(), |
| 4125 | SemaRef.Context.BoolTy)) |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 4126 | CondExpr = SemaRef.PerformImplicitConversion( |
| 4127 | CondExpr.get(), SemaRef.Context.BoolTy, /*Action=*/Sema::AA_Casting, |
| 4128 | /*AllowExplicit=*/true); |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 4129 | } |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 4130 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(Suppress); |
| 4131 | // Otherwise use original loop conditon and evaluate it in runtime. |
| 4132 | return CondExpr.isUsable() ? CondExpr.get() : Cond; |
| 4133 | } |
| 4134 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4135 | /// \brief Build reference expression to the counter be used for codegen. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4136 | DeclRefExpr *OpenMPIterationSpaceChecker::BuildCounterVar( |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 4137 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures, DSAStackTy &DSA) const { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4138 | auto *VD = dyn_cast<VarDecl>(LCDecl); |
| 4139 | if (!VD) { |
| 4140 | VD = SemaRef.IsOpenMPCapturedDecl(LCDecl); |
| 4141 | auto *Ref = buildDeclRefExpr( |
| 4142 | SemaRef, VD, VD->getType().getNonReferenceType(), DefaultLoc); |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 4143 | DSAStackTy::DSAVarData Data = DSA.getTopDSA(LCDecl, /*FromParent=*/false); |
| 4144 | // If the loop control decl is explicitly marked as private, do not mark it |
| 4145 | // as captured again. |
| 4146 | if (!isOpenMPPrivate(Data.CKind) || !Data.RefExpr) |
| 4147 | Captures.insert(std::make_pair(LCRef, Ref)); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4148 | return Ref; |
| 4149 | } |
| 4150 | return buildDeclRefExpr(SemaRef, VD, VD->getType().getNonReferenceType(), |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 4151 | DefaultLoc); |
| 4152 | } |
| 4153 | |
| 4154 | Expr *OpenMPIterationSpaceChecker::BuildPrivateCounterVar() const { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4155 | if (LCDecl && !LCDecl->isInvalidDecl()) { |
| 4156 | auto Type = LCDecl->getType().getNonReferenceType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 4157 | auto *PrivateVar = |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4158 | buildVarDecl(SemaRef, DefaultLoc, Type, LCDecl->getName(), |
| 4159 | LCDecl->hasAttrs() ? &LCDecl->getAttrs() : nullptr); |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 4160 | if (PrivateVar->isInvalidDecl()) |
| 4161 | return nullptr; |
| 4162 | return buildDeclRefExpr(SemaRef, PrivateVar, Type, DefaultLoc); |
| 4163 | } |
| 4164 | return nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4165 | } |
| 4166 | |
| 4167 | /// \brief Build initization of the counter be used for codegen. |
| 4168 | Expr *OpenMPIterationSpaceChecker::BuildCounterInit() const { return LB; } |
| 4169 | |
| 4170 | /// \brief Build step of the counter be used for codegen. |
| 4171 | Expr *OpenMPIterationSpaceChecker::BuildCounterStep() const { return Step; } |
| 4172 | |
| 4173 | /// \brief Iteration space of a single for loop. |
| 4174 | struct LoopIterationSpace { |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 4175 | /// \brief Condition of the loop. |
| 4176 | Expr *PreCond; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4177 | /// \brief This expression calculates the number of iterations in the loop. |
| 4178 | /// It is always possible to calculate it before starting the loop. |
| 4179 | Expr *NumIterations; |
| 4180 | /// \brief The loop counter variable. |
| 4181 | Expr *CounterVar; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 4182 | /// \brief Private loop counter variable. |
| 4183 | Expr *PrivateCounterVar; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4184 | /// \brief This is initializer for the initial value of #CounterVar. |
| 4185 | Expr *CounterInit; |
| 4186 | /// \brief This is step for the #CounterVar used to generate its update: |
| 4187 | /// #CounterVar = #CounterInit + #CounterStep * CurrentIteration. |
| 4188 | Expr *CounterStep; |
| 4189 | /// \brief Should step be subtracted? |
| 4190 | bool Subtract; |
| 4191 | /// \brief Source range of the loop init. |
| 4192 | SourceRange InitSrcRange; |
| 4193 | /// \brief Source range of the loop condition. |
| 4194 | SourceRange CondSrcRange; |
| 4195 | /// \brief Source range of the loop increment. |
| 4196 | SourceRange IncSrcRange; |
| 4197 | }; |
| 4198 | |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 4199 | } // namespace |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4200 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 4201 | void Sema::ActOnOpenMPLoopInitialization(SourceLocation ForLoc, Stmt *Init) { |
| 4202 | assert(getLangOpts().OpenMP && "OpenMP is not active."); |
| 4203 | assert(Init && "Expected loop in canonical form."); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 4204 | unsigned AssociatedLoops = DSAStack->getAssociatedLoops(); |
| 4205 | if (AssociatedLoops > 0 && |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 4206 | isOpenMPLoopDirective(DSAStack->getCurrentDirective())) { |
| 4207 | OpenMPIterationSpaceChecker ISC(*this, ForLoc); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4208 | if (!ISC.CheckInit(Init, /*EmitDiags=*/false)) { |
| 4209 | if (auto *D = ISC.GetLoopDecl()) { |
| 4210 | auto *VD = dyn_cast<VarDecl>(D); |
| 4211 | if (!VD) { |
| 4212 | if (auto *Private = IsOpenMPCapturedDecl(D)) |
| 4213 | VD = Private; |
| 4214 | else { |
| 4215 | auto *Ref = buildCapture(*this, D, ISC.GetLoopDeclRefExpr(), |
| 4216 | /*WithInit=*/false); |
| 4217 | VD = cast<VarDecl>(Ref->getDecl()); |
| 4218 | } |
| 4219 | } |
| 4220 | DSAStack->addLoopControlVariable(D, VD); |
| 4221 | } |
| 4222 | } |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 4223 | DSAStack->setAssociatedLoops(AssociatedLoops - 1); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 4224 | } |
| 4225 | } |
| 4226 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4227 | /// \brief Called on a for stmt to check and extract its iteration space |
| 4228 | /// for further processing (such as collapsing). |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4229 | static bool CheckOpenMPIterationSpace( |
| 4230 | OpenMPDirectiveKind DKind, Stmt *S, Sema &SemaRef, DSAStackTy &DSA, |
| 4231 | unsigned CurrentNestedLoopCount, unsigned NestedLoopCount, |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4232 | Expr *CollapseLoopCountExpr, Expr *OrderedLoopCountExpr, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 4233 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4234 | LoopIterationSpace &ResultIterSpace, |
| 4235 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4236 | // OpenMP [2.6, Canonical Loop Form] |
| 4237 | // for (init-expr; test-expr; incr-expr) structured-block |
| 4238 | auto For = dyn_cast_or_null<ForStmt>(S); |
| 4239 | if (!For) { |
| 4240 | SemaRef.Diag(S->getLocStart(), diag::err_omp_not_for) |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4241 | << (CollapseLoopCountExpr != nullptr || OrderedLoopCountExpr != nullptr) |
| 4242 | << getOpenMPDirectiveName(DKind) << NestedLoopCount |
| 4243 | << (CurrentNestedLoopCount > 0) << CurrentNestedLoopCount; |
| 4244 | if (NestedLoopCount > 1) { |
| 4245 | if (CollapseLoopCountExpr && OrderedLoopCountExpr) |
| 4246 | SemaRef.Diag(DSA.getConstructLoc(), |
| 4247 | diag::note_omp_collapse_ordered_expr) |
| 4248 | << 2 << CollapseLoopCountExpr->getSourceRange() |
| 4249 | << OrderedLoopCountExpr->getSourceRange(); |
| 4250 | else if (CollapseLoopCountExpr) |
| 4251 | SemaRef.Diag(CollapseLoopCountExpr->getExprLoc(), |
| 4252 | diag::note_omp_collapse_ordered_expr) |
| 4253 | << 0 << CollapseLoopCountExpr->getSourceRange(); |
| 4254 | else |
| 4255 | SemaRef.Diag(OrderedLoopCountExpr->getExprLoc(), |
| 4256 | diag::note_omp_collapse_ordered_expr) |
| 4257 | << 1 << OrderedLoopCountExpr->getSourceRange(); |
| 4258 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4259 | return true; |
| 4260 | } |
| 4261 | assert(For->getBody()); |
| 4262 | |
| 4263 | OpenMPIterationSpaceChecker ISC(SemaRef, For->getForLoc()); |
| 4264 | |
| 4265 | // Check init. |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 4266 | auto Init = For->getInit(); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4267 | if (ISC.CheckInit(Init)) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4268 | return true; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4269 | |
| 4270 | bool HasErrors = false; |
| 4271 | |
| 4272 | // Check loop variable's type. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4273 | if (auto *LCDecl = ISC.GetLoopDecl()) { |
| 4274 | auto *LoopDeclRefExpr = ISC.GetLoopDeclRefExpr(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4275 | |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4276 | // OpenMP [2.6, Canonical Loop Form] |
| 4277 | // Var is one of the following: |
| 4278 | // A variable of signed or unsigned integer type. |
| 4279 | // For C++, a variable of a random access iterator type. |
| 4280 | // For C, a variable of a pointer type. |
| 4281 | auto VarType = LCDecl->getType().getNonReferenceType(); |
| 4282 | if (!VarType->isDependentType() && !VarType->isIntegerType() && |
| 4283 | !VarType->isPointerType() && |
| 4284 | !(SemaRef.getLangOpts().CPlusPlus && VarType->isOverloadableType())) { |
| 4285 | SemaRef.Diag(Init->getLocStart(), diag::err_omp_loop_variable_type) |
| 4286 | << SemaRef.getLangOpts().CPlusPlus; |
| 4287 | HasErrors = true; |
| 4288 | } |
| 4289 | |
| 4290 | // OpenMP, 2.14.1.1 Data-sharing Attribute Rules for Variables Referenced in |
| 4291 | // a Construct |
| 4292 | // The loop iteration variable(s) in the associated for-loop(s) of a for or |
| 4293 | // parallel for construct is (are) private. |
| 4294 | // The loop iteration variable in the associated for-loop of a simd |
| 4295 | // construct with just one associated for-loop is linear with a |
| 4296 | // constant-linear-step that is the increment of the associated for-loop. |
| 4297 | // Exclude loop var from the list of variables with implicitly defined data |
| 4298 | // sharing attributes. |
| 4299 | VarsWithImplicitDSA.erase(LCDecl); |
| 4300 | |
| 4301 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 4302 | // in a Construct, C/C++]. |
| 4303 | // The loop iteration variable in the associated for-loop of a simd |
| 4304 | // construct with just one associated for-loop may be listed in a linear |
| 4305 | // clause with a constant-linear-step that is the increment of the |
| 4306 | // associated for-loop. |
| 4307 | // The loop iteration variable(s) in the associated for-loop(s) of a for or |
| 4308 | // parallel for construct may be listed in a private or lastprivate clause. |
| 4309 | DSAStackTy::DSAVarData DVar = DSA.getTopDSA(LCDecl, false); |
| 4310 | // If LoopVarRefExpr is nullptr it means the corresponding loop variable is |
| 4311 | // declared in the loop and it is predetermined as a private. |
| 4312 | auto PredeterminedCKind = |
| 4313 | isOpenMPSimdDirective(DKind) |
| 4314 | ? ((NestedLoopCount == 1) ? OMPC_linear : OMPC_lastprivate) |
| 4315 | : OMPC_private; |
| 4316 | if (((isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown && |
| 4317 | DVar.CKind != PredeterminedCKind) || |
| 4318 | ((isOpenMPWorksharingDirective(DKind) || DKind == OMPD_taskloop || |
| 4319 | isOpenMPDistributeDirective(DKind)) && |
| 4320 | !isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown && |
| 4321 | DVar.CKind != OMPC_private && DVar.CKind != OMPC_lastprivate)) && |
| 4322 | (DVar.CKind != OMPC_private || DVar.RefExpr != nullptr)) { |
| 4323 | SemaRef.Diag(Init->getLocStart(), diag::err_omp_loop_var_dsa) |
| 4324 | << getOpenMPClauseName(DVar.CKind) << getOpenMPDirectiveName(DKind) |
| 4325 | << getOpenMPClauseName(PredeterminedCKind); |
| 4326 | if (DVar.RefExpr == nullptr) |
| 4327 | DVar.CKind = PredeterminedCKind; |
| 4328 | ReportOriginalDSA(SemaRef, &DSA, LCDecl, DVar, /*IsLoopIterVar=*/true); |
| 4329 | HasErrors = true; |
| 4330 | } else if (LoopDeclRefExpr != nullptr) { |
| 4331 | // Make the loop iteration variable private (for worksharing constructs), |
| 4332 | // linear (for simd directives with the only one associated loop) or |
| 4333 | // lastprivate (for simd directives with several collapsed or ordered |
| 4334 | // loops). |
| 4335 | if (DVar.CKind == OMPC_unknown) |
| 4336 | DVar = DSA.hasDSA(LCDecl, isOpenMPPrivate, MatchesAlways(), |
| 4337 | /*FromParent=*/false); |
| 4338 | DSA.addDSA(LCDecl, LoopDeclRefExpr, PredeterminedCKind); |
| 4339 | } |
| 4340 | |
| 4341 | assert(isOpenMPLoopDirective(DKind) && "DSA for non-loop vars"); |
| 4342 | |
| 4343 | // Check test-expr. |
| 4344 | HasErrors |= ISC.CheckCond(For->getCond()); |
| 4345 | |
| 4346 | // Check incr-expr. |
| 4347 | HasErrors |= ISC.CheckInc(For->getInc()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4348 | } |
| 4349 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4350 | if (ISC.Dependent() || SemaRef.CurContext->isDependentContext() || HasErrors) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4351 | return HasErrors; |
| 4352 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4353 | // Build the loop's iteration space representation. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4354 | ResultIterSpace.PreCond = |
| 4355 | ISC.BuildPreCond(DSA.getCurScope(), For->getCond(), Captures); |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 4356 | ResultIterSpace.NumIterations = ISC.BuildNumIterations( |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4357 | DSA.getCurScope(), |
| 4358 | (isOpenMPWorksharingDirective(DKind) || |
| 4359 | isOpenMPTaskLoopDirective(DKind) || isOpenMPDistributeDirective(DKind)), |
| 4360 | Captures); |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 4361 | ResultIterSpace.CounterVar = ISC.BuildCounterVar(Captures, DSA); |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 4362 | ResultIterSpace.PrivateCounterVar = ISC.BuildPrivateCounterVar(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4363 | ResultIterSpace.CounterInit = ISC.BuildCounterInit(); |
| 4364 | ResultIterSpace.CounterStep = ISC.BuildCounterStep(); |
| 4365 | ResultIterSpace.InitSrcRange = ISC.GetInitSrcRange(); |
| 4366 | ResultIterSpace.CondSrcRange = ISC.GetConditionSrcRange(); |
| 4367 | ResultIterSpace.IncSrcRange = ISC.GetIncrementSrcRange(); |
| 4368 | ResultIterSpace.Subtract = ISC.ShouldSubtractStep(); |
| 4369 | |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 4370 | HasErrors |= (ResultIterSpace.PreCond == nullptr || |
| 4371 | ResultIterSpace.NumIterations == nullptr || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4372 | ResultIterSpace.CounterVar == nullptr || |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 4373 | ResultIterSpace.PrivateCounterVar == nullptr || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4374 | ResultIterSpace.CounterInit == nullptr || |
| 4375 | ResultIterSpace.CounterStep == nullptr); |
| 4376 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4377 | return HasErrors; |
| 4378 | } |
| 4379 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4380 | /// \brief Build 'VarRef = Start. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4381 | static ExprResult |
| 4382 | BuildCounterInit(Sema &SemaRef, Scope *S, SourceLocation Loc, ExprResult VarRef, |
| 4383 | ExprResult Start, |
| 4384 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) { |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4385 | // Build 'VarRef = Start. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4386 | auto NewStart = tryBuildCapture(SemaRef, Start.get(), Captures); |
| 4387 | if (!NewStart.isUsable()) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4388 | return ExprError(); |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 4389 | if (!SemaRef.Context.hasSameType(NewStart.get()->getType(), |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 4390 | VarRef.get()->getType())) { |
| 4391 | NewStart = SemaRef.PerformImplicitConversion( |
| 4392 | NewStart.get(), VarRef.get()->getType(), Sema::AA_Converting, |
| 4393 | /*AllowExplicit=*/true); |
| 4394 | if (!NewStart.isUsable()) |
| 4395 | return ExprError(); |
| 4396 | } |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4397 | |
| 4398 | auto Init = |
| 4399 | SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), NewStart.get()); |
| 4400 | return Init; |
| 4401 | } |
| 4402 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4403 | /// \brief Build 'VarRef = Start + Iter * Step'. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4404 | static ExprResult |
| 4405 | BuildCounterUpdate(Sema &SemaRef, Scope *S, SourceLocation Loc, |
| 4406 | ExprResult VarRef, ExprResult Start, ExprResult Iter, |
| 4407 | ExprResult Step, bool Subtract, |
| 4408 | llvm::MapVector<Expr *, DeclRefExpr *> *Captures = nullptr) { |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4409 | // Add parentheses (for debugging purposes only). |
| 4410 | Iter = SemaRef.ActOnParenExpr(Loc, Loc, Iter.get()); |
| 4411 | if (!VarRef.isUsable() || !Start.isUsable() || !Iter.isUsable() || |
| 4412 | !Step.isUsable()) |
| 4413 | return ExprError(); |
| 4414 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4415 | ExprResult NewStep = Step; |
| 4416 | if (Captures) |
| 4417 | NewStep = tryBuildCapture(SemaRef, Step.get(), *Captures); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4418 | if (NewStep.isInvalid()) |
| 4419 | return ExprError(); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4420 | ExprResult Update = |
| 4421 | SemaRef.BuildBinOp(S, Loc, BO_Mul, Iter.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4422 | if (!Update.isUsable()) |
| 4423 | return ExprError(); |
| 4424 | |
Alexey Bataev | c0214e0 | 2016-02-16 12:13:49 +0000 | [diff] [blame] | 4425 | // Try to build 'VarRef = Start, VarRef (+|-)= Iter * Step' or |
| 4426 | // 'VarRef = Start (+|-) Iter * Step'. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4427 | ExprResult NewStart = Start; |
| 4428 | if (Captures) |
| 4429 | NewStart = tryBuildCapture(SemaRef, Start.get(), *Captures); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4430 | if (NewStart.isInvalid()) |
| 4431 | return ExprError(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4432 | |
Alexey Bataev | c0214e0 | 2016-02-16 12:13:49 +0000 | [diff] [blame] | 4433 | // First attempt: try to build 'VarRef = Start, VarRef += Iter * Step'. |
| 4434 | ExprResult SavedUpdate = Update; |
| 4435 | ExprResult UpdateVal; |
| 4436 | if (VarRef.get()->getType()->isOverloadableType() || |
| 4437 | NewStart.get()->getType()->isOverloadableType() || |
| 4438 | Update.get()->getType()->isOverloadableType()) { |
| 4439 | bool Suppress = SemaRef.getDiagnostics().getSuppressAllDiagnostics(); |
| 4440 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(/*Val=*/true); |
| 4441 | Update = |
| 4442 | SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), NewStart.get()); |
| 4443 | if (Update.isUsable()) { |
| 4444 | UpdateVal = |
| 4445 | SemaRef.BuildBinOp(S, Loc, Subtract ? BO_SubAssign : BO_AddAssign, |
| 4446 | VarRef.get(), SavedUpdate.get()); |
| 4447 | if (UpdateVal.isUsable()) { |
| 4448 | Update = SemaRef.CreateBuiltinBinOp(Loc, BO_Comma, Update.get(), |
| 4449 | UpdateVal.get()); |
| 4450 | } |
| 4451 | } |
| 4452 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(Suppress); |
| 4453 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4454 | |
Alexey Bataev | c0214e0 | 2016-02-16 12:13:49 +0000 | [diff] [blame] | 4455 | // Second attempt: try to build 'VarRef = Start (+|-) Iter * Step'. |
| 4456 | if (!Update.isUsable() || !UpdateVal.isUsable()) { |
| 4457 | Update = SemaRef.BuildBinOp(S, Loc, Subtract ? BO_Sub : BO_Add, |
| 4458 | NewStart.get(), SavedUpdate.get()); |
| 4459 | if (!Update.isUsable()) |
| 4460 | return ExprError(); |
| 4461 | |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 4462 | if (!SemaRef.Context.hasSameType(Update.get()->getType(), |
| 4463 | VarRef.get()->getType())) { |
| 4464 | Update = SemaRef.PerformImplicitConversion( |
| 4465 | Update.get(), VarRef.get()->getType(), Sema::AA_Converting, true); |
| 4466 | if (!Update.isUsable()) |
| 4467 | return ExprError(); |
| 4468 | } |
Alexey Bataev | c0214e0 | 2016-02-16 12:13:49 +0000 | [diff] [blame] | 4469 | |
| 4470 | Update = SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), Update.get()); |
| 4471 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4472 | return Update; |
| 4473 | } |
| 4474 | |
| 4475 | /// \brief Convert integer expression \a E to make it have at least \a Bits |
| 4476 | /// bits. |
| 4477 | static ExprResult WidenIterationCount(unsigned Bits, Expr *E, |
| 4478 | Sema &SemaRef) { |
| 4479 | if (E == nullptr) |
| 4480 | return ExprError(); |
| 4481 | auto &C = SemaRef.Context; |
| 4482 | QualType OldType = E->getType(); |
| 4483 | unsigned HasBits = C.getTypeSize(OldType); |
| 4484 | if (HasBits >= Bits) |
| 4485 | return ExprResult(E); |
| 4486 | // OK to convert to signed, because new type has more bits than old. |
| 4487 | QualType NewType = C.getIntTypeForBitwidth(Bits, /* Signed */ true); |
| 4488 | return SemaRef.PerformImplicitConversion(E, NewType, Sema::AA_Converting, |
| 4489 | true); |
| 4490 | } |
| 4491 | |
| 4492 | /// \brief Check if the given expression \a E is a constant integer that fits |
| 4493 | /// into \a Bits bits. |
| 4494 | static bool FitsInto(unsigned Bits, bool Signed, Expr *E, Sema &SemaRef) { |
| 4495 | if (E == nullptr) |
| 4496 | return false; |
| 4497 | llvm::APSInt Result; |
| 4498 | if (E->isIntegerConstantExpr(Result, SemaRef.Context)) |
| 4499 | return Signed ? Result.isSignedIntN(Bits) : Result.isIntN(Bits); |
| 4500 | return false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4501 | } |
| 4502 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4503 | /// Build preinits statement for the given declarations. |
| 4504 | static Stmt *buildPreInits(ASTContext &Context, |
| 4505 | SmallVectorImpl<Decl *> &PreInits) { |
| 4506 | if (!PreInits.empty()) { |
| 4507 | return new (Context) DeclStmt( |
| 4508 | DeclGroupRef::Create(Context, PreInits.begin(), PreInits.size()), |
| 4509 | SourceLocation(), SourceLocation()); |
| 4510 | } |
| 4511 | return nullptr; |
| 4512 | } |
| 4513 | |
| 4514 | /// Build preinits statement for the given declarations. |
| 4515 | static Stmt *buildPreInits(ASTContext &Context, |
| 4516 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) { |
| 4517 | if (!Captures.empty()) { |
| 4518 | SmallVector<Decl *, 16> PreInits; |
| 4519 | for (auto &Pair : Captures) |
| 4520 | PreInits.push_back(Pair.second->getDecl()); |
| 4521 | return buildPreInits(Context, PreInits); |
| 4522 | } |
| 4523 | return nullptr; |
| 4524 | } |
| 4525 | |
| 4526 | /// Build postupdate expression for the given list of postupdates expressions. |
| 4527 | static Expr *buildPostUpdate(Sema &S, ArrayRef<Expr *> PostUpdates) { |
| 4528 | Expr *PostUpdate = nullptr; |
| 4529 | if (!PostUpdates.empty()) { |
| 4530 | for (auto *E : PostUpdates) { |
| 4531 | Expr *ConvE = S.BuildCStyleCastExpr( |
| 4532 | E->getExprLoc(), |
| 4533 | S.Context.getTrivialTypeSourceInfo(S.Context.VoidTy), |
| 4534 | E->getExprLoc(), E) |
| 4535 | .get(); |
| 4536 | PostUpdate = PostUpdate |
| 4537 | ? S.CreateBuiltinBinOp(ConvE->getExprLoc(), BO_Comma, |
| 4538 | PostUpdate, ConvE) |
| 4539 | .get() |
| 4540 | : ConvE; |
| 4541 | } |
| 4542 | } |
| 4543 | return PostUpdate; |
| 4544 | } |
| 4545 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4546 | /// \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] | 4547 | /// \return Returns 0 if one of the collapsed stmts is not canonical for loop, |
| 4548 | /// number of collapsed loops otherwise. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4549 | static unsigned |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4550 | CheckOpenMPLoop(OpenMPDirectiveKind DKind, Expr *CollapseLoopCountExpr, |
| 4551 | Expr *OrderedLoopCountExpr, Stmt *AStmt, Sema &SemaRef, |
| 4552 | DSAStackTy &DSA, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 4553 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA, |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4554 | OMPLoopDirective::HelperExprs &Built) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 4555 | unsigned NestedLoopCount = 1; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4556 | if (CollapseLoopCountExpr) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 4557 | // Found 'collapse' clause - calculate collapse number. |
| 4558 | llvm::APSInt Result; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4559 | if (CollapseLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext())) |
Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 4560 | NestedLoopCount = Result.getLimitedValue(); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4561 | } |
| 4562 | if (OrderedLoopCountExpr) { |
| 4563 | // Found 'ordered' clause - calculate collapse number. |
| 4564 | llvm::APSInt Result; |
Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 4565 | if (OrderedLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext())) { |
| 4566 | if (Result.getLimitedValue() < NestedLoopCount) { |
| 4567 | SemaRef.Diag(OrderedLoopCountExpr->getExprLoc(), |
| 4568 | diag::err_omp_wrong_ordered_loop_count) |
| 4569 | << OrderedLoopCountExpr->getSourceRange(); |
| 4570 | SemaRef.Diag(CollapseLoopCountExpr->getExprLoc(), |
| 4571 | diag::note_collapse_loop_count) |
| 4572 | << CollapseLoopCountExpr->getSourceRange(); |
| 4573 | } |
| 4574 | NestedLoopCount = Result.getLimitedValue(); |
| 4575 | } |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 4576 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4577 | // This is helper routine for loop directives (e.g., 'for', 'simd', |
| 4578 | // 'for simd', etc.). |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4579 | llvm::MapVector<Expr *, DeclRefExpr *> Captures; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4580 | SmallVector<LoopIterationSpace, 4> IterSpaces; |
| 4581 | IterSpaces.resize(NestedLoopCount); |
| 4582 | Stmt *CurStmt = AStmt->IgnoreContainers(/* IgnoreCaptured */ true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4583 | for (unsigned Cnt = 0; Cnt < NestedLoopCount; ++Cnt) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 4584 | if (CheckOpenMPIterationSpace(DKind, CurStmt, SemaRef, DSA, Cnt, |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4585 | NestedLoopCount, CollapseLoopCountExpr, |
| 4586 | OrderedLoopCountExpr, VarsWithImplicitDSA, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4587 | IterSpaces[Cnt], Captures)) |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 4588 | return 0; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4589 | // 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] | 4590 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 4591 | // All loops associated with the construct must be perfectly nested; that |
| 4592 | // is, there must be no intervening code nor any OpenMP directive between |
| 4593 | // any two loops. |
| 4594 | CurStmt = cast<ForStmt>(CurStmt)->getBody()->IgnoreContainers(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4595 | } |
| 4596 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4597 | Built.clear(/* size */ NestedLoopCount); |
| 4598 | |
| 4599 | if (SemaRef.CurContext->isDependentContext()) |
| 4600 | return NestedLoopCount; |
| 4601 | |
| 4602 | // An example of what is generated for the following code: |
| 4603 | // |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4604 | // #pragma omp simd collapse(2) ordered(2) |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4605 | // for (i = 0; i < NI; ++i) |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4606 | // for (k = 0; k < NK; ++k) |
| 4607 | // for (j = J0; j < NJ; j+=2) { |
| 4608 | // <loop body> |
| 4609 | // } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4610 | // |
| 4611 | // We generate the code below. |
| 4612 | // Note: the loop body may be outlined in CodeGen. |
| 4613 | // Note: some counters may be C++ classes, operator- is used to find number of |
| 4614 | // iterations and operator+= to calculate counter value. |
| 4615 | // Note: decltype(NumIterations) must be integer type (in 'omp for', only i32 |
| 4616 | // or i64 is currently supported). |
| 4617 | // |
| 4618 | // #define NumIterations (NI * ((NJ - J0 - 1 + 2) / 2)) |
| 4619 | // for (int[32|64]_t IV = 0; IV < NumIterations; ++IV ) { |
| 4620 | // .local.i = IV / ((NJ - J0 - 1 + 2) / 2); |
| 4621 | // .local.j = J0 + (IV % ((NJ - J0 - 1 + 2) / 2)) * 2; |
| 4622 | // // similar updates for vars in clauses (e.g. 'linear') |
| 4623 | // <loop body (using local i and j)> |
| 4624 | // } |
| 4625 | // i = NI; // assign final values of counters |
| 4626 | // j = NJ; |
| 4627 | // |
| 4628 | |
| 4629 | // Last iteration number is (I1 * I2 * ... In) - 1, where I1, I2 ... In are |
| 4630 | // the iteration counts of the collapsed for loops. |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 4631 | // Precondition tests if there is at least one iteration (all conditions are |
| 4632 | // true). |
| 4633 | auto PreCond = ExprResult(IterSpaces[0].PreCond); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4634 | auto N0 = IterSpaces[0].NumIterations; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4635 | ExprResult LastIteration32 = WidenIterationCount( |
| 4636 | 32 /* Bits */, SemaRef.PerformImplicitConversion( |
| 4637 | N0->IgnoreImpCasts(), N0->getType(), |
| 4638 | Sema::AA_Converting, /*AllowExplicit=*/true) |
| 4639 | .get(), |
| 4640 | SemaRef); |
| 4641 | ExprResult LastIteration64 = WidenIterationCount( |
| 4642 | 64 /* Bits */, SemaRef.PerformImplicitConversion( |
| 4643 | N0->IgnoreImpCasts(), N0->getType(), |
| 4644 | Sema::AA_Converting, /*AllowExplicit=*/true) |
| 4645 | .get(), |
| 4646 | SemaRef); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4647 | |
| 4648 | if (!LastIteration32.isUsable() || !LastIteration64.isUsable()) |
| 4649 | return NestedLoopCount; |
| 4650 | |
| 4651 | auto &C = SemaRef.Context; |
| 4652 | bool AllCountsNeedLessThan32Bits = C.getTypeSize(N0->getType()) < 32; |
| 4653 | |
| 4654 | Scope *CurScope = DSA.getCurScope(); |
| 4655 | for (unsigned Cnt = 1; Cnt < NestedLoopCount; ++Cnt) { |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 4656 | if (PreCond.isUsable()) { |
| 4657 | PreCond = SemaRef.BuildBinOp(CurScope, SourceLocation(), BO_LAnd, |
| 4658 | PreCond.get(), IterSpaces[Cnt].PreCond); |
| 4659 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4660 | auto N = IterSpaces[Cnt].NumIterations; |
| 4661 | AllCountsNeedLessThan32Bits &= C.getTypeSize(N->getType()) < 32; |
| 4662 | if (LastIteration32.isUsable()) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4663 | LastIteration32 = SemaRef.BuildBinOp( |
| 4664 | CurScope, SourceLocation(), BO_Mul, LastIteration32.get(), |
| 4665 | SemaRef.PerformImplicitConversion(N->IgnoreImpCasts(), N->getType(), |
| 4666 | Sema::AA_Converting, |
| 4667 | /*AllowExplicit=*/true) |
| 4668 | .get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4669 | if (LastIteration64.isUsable()) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4670 | LastIteration64 = SemaRef.BuildBinOp( |
| 4671 | CurScope, SourceLocation(), BO_Mul, LastIteration64.get(), |
| 4672 | SemaRef.PerformImplicitConversion(N->IgnoreImpCasts(), N->getType(), |
| 4673 | Sema::AA_Converting, |
| 4674 | /*AllowExplicit=*/true) |
| 4675 | .get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4676 | } |
| 4677 | |
| 4678 | // Choose either the 32-bit or 64-bit version. |
| 4679 | ExprResult LastIteration = LastIteration64; |
| 4680 | if (LastIteration32.isUsable() && |
| 4681 | C.getTypeSize(LastIteration32.get()->getType()) == 32 && |
| 4682 | (AllCountsNeedLessThan32Bits || NestedLoopCount == 1 || |
| 4683 | FitsInto( |
| 4684 | 32 /* Bits */, |
| 4685 | LastIteration32.get()->getType()->hasSignedIntegerRepresentation(), |
| 4686 | LastIteration64.get(), SemaRef))) |
| 4687 | LastIteration = LastIteration32; |
Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 4688 | QualType VType = LastIteration.get()->getType(); |
| 4689 | QualType RealVType = VType; |
| 4690 | QualType StrideVType = VType; |
| 4691 | if (isOpenMPTaskLoopDirective(DKind)) { |
| 4692 | VType = |
| 4693 | SemaRef.Context.getIntTypeForBitwidth(/*DestWidth=*/64, /*Signed=*/0); |
| 4694 | StrideVType = |
| 4695 | SemaRef.Context.getIntTypeForBitwidth(/*DestWidth=*/64, /*Signed=*/1); |
| 4696 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4697 | |
| 4698 | if (!LastIteration.isUsable()) |
| 4699 | return 0; |
| 4700 | |
| 4701 | // Save the number of iterations. |
| 4702 | ExprResult NumIterations = LastIteration; |
| 4703 | { |
| 4704 | LastIteration = SemaRef.BuildBinOp( |
| 4705 | CurScope, SourceLocation(), BO_Sub, LastIteration.get(), |
| 4706 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 4707 | if (!LastIteration.isUsable()) |
| 4708 | return 0; |
| 4709 | } |
| 4710 | |
| 4711 | // Calculate the last iteration number beforehand instead of doing this on |
| 4712 | // each iteration. Do not do this if the number of iterations may be kfold-ed. |
| 4713 | llvm::APSInt Result; |
| 4714 | bool IsConstant = |
| 4715 | LastIteration.get()->isIntegerConstantExpr(Result, SemaRef.Context); |
| 4716 | ExprResult CalcLastIteration; |
| 4717 | if (!IsConstant) { |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4718 | ExprResult SaveRef = |
| 4719 | tryBuildCapture(SemaRef, LastIteration.get(), Captures); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4720 | LastIteration = SaveRef; |
| 4721 | |
| 4722 | // Prepare SaveRef + 1. |
| 4723 | NumIterations = SemaRef.BuildBinOp( |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4724 | CurScope, SourceLocation(), BO_Add, SaveRef.get(), |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4725 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 4726 | if (!NumIterations.isUsable()) |
| 4727 | return 0; |
| 4728 | } |
| 4729 | |
| 4730 | SourceLocation InitLoc = IterSpaces[0].InitSrcRange.getBegin(); |
| 4731 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4732 | // Build variables passed into runtime, nesessary for worksharing directives. |
| 4733 | ExprResult LB, UB, IL, ST, EUB; |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 4734 | if (isOpenMPWorksharingDirective(DKind) || isOpenMPTaskLoopDirective(DKind) || |
| 4735 | isOpenMPDistributeDirective(DKind)) { |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4736 | // Lower bound variable, initialized with zero. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4737 | VarDecl *LBDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.lb"); |
| 4738 | LB = buildDeclRefExpr(SemaRef, LBDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4739 | SemaRef.AddInitializerToDecl( |
| 4740 | LBDecl, SemaRef.ActOnIntegerConstant(InitLoc, 0).get(), |
| 4741 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 4742 | |
| 4743 | // Upper bound variable, initialized with last iteration number. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4744 | VarDecl *UBDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.ub"); |
| 4745 | UB = buildDeclRefExpr(SemaRef, UBDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4746 | SemaRef.AddInitializerToDecl(UBDecl, LastIteration.get(), |
| 4747 | /*DirectInit*/ false, |
| 4748 | /*TypeMayContainAuto*/ false); |
| 4749 | |
| 4750 | // A 32-bit variable-flag where runtime returns 1 for the last iteration. |
| 4751 | // This will be used to implement clause 'lastprivate'. |
| 4752 | QualType Int32Ty = SemaRef.Context.getIntTypeForBitwidth(32, true); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4753 | VarDecl *ILDecl = buildVarDecl(SemaRef, InitLoc, Int32Ty, ".omp.is_last"); |
| 4754 | IL = buildDeclRefExpr(SemaRef, ILDecl, Int32Ty, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4755 | SemaRef.AddInitializerToDecl( |
| 4756 | ILDecl, SemaRef.ActOnIntegerConstant(InitLoc, 0).get(), |
| 4757 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 4758 | |
| 4759 | // Stride variable returned by runtime (we initialize it to 1 by default). |
Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 4760 | VarDecl *STDecl = |
| 4761 | buildVarDecl(SemaRef, InitLoc, StrideVType, ".omp.stride"); |
| 4762 | ST = buildDeclRefExpr(SemaRef, STDecl, StrideVType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4763 | SemaRef.AddInitializerToDecl( |
| 4764 | STDecl, SemaRef.ActOnIntegerConstant(InitLoc, 1).get(), |
| 4765 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 4766 | |
| 4767 | // Build expression: UB = min(UB, LastIteration) |
| 4768 | // It is nesessary for CodeGen of directives with static scheduling. |
| 4769 | ExprResult IsUBGreater = SemaRef.BuildBinOp(CurScope, InitLoc, BO_GT, |
| 4770 | UB.get(), LastIteration.get()); |
| 4771 | ExprResult CondOp = SemaRef.ActOnConditionalOp( |
| 4772 | InitLoc, InitLoc, IsUBGreater.get(), LastIteration.get(), UB.get()); |
| 4773 | EUB = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, UB.get(), |
| 4774 | CondOp.get()); |
| 4775 | EUB = SemaRef.ActOnFinishFullExpr(EUB.get()); |
| 4776 | } |
| 4777 | |
| 4778 | // Build the iteration variable and its initialization before loop. |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4779 | ExprResult IV; |
| 4780 | ExprResult Init; |
| 4781 | { |
Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 4782 | VarDecl *IVDecl = buildVarDecl(SemaRef, InitLoc, RealVType, ".omp.iv"); |
| 4783 | IV = buildDeclRefExpr(SemaRef, IVDecl, RealVType, InitLoc); |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 4784 | Expr *RHS = (isOpenMPWorksharingDirective(DKind) || |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 4785 | isOpenMPTaskLoopDirective(DKind) || |
| 4786 | isOpenMPDistributeDirective(DKind)) |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4787 | ? LB.get() |
| 4788 | : SemaRef.ActOnIntegerConstant(SourceLocation(), 0).get(); |
| 4789 | Init = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, IV.get(), RHS); |
| 4790 | Init = SemaRef.ActOnFinishFullExpr(Init.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4791 | } |
| 4792 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4793 | // Loop condition (IV < NumIterations) or (IV <= UB) for worksharing loops. |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4794 | SourceLocation CondLoc; |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4795 | ExprResult Cond = |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 4796 | (isOpenMPWorksharingDirective(DKind) || |
| 4797 | isOpenMPTaskLoopDirective(DKind) || isOpenMPDistributeDirective(DKind)) |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4798 | ? SemaRef.BuildBinOp(CurScope, CondLoc, BO_LE, IV.get(), UB.get()) |
| 4799 | : SemaRef.BuildBinOp(CurScope, CondLoc, BO_LT, IV.get(), |
| 4800 | NumIterations.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4801 | |
| 4802 | // Loop increment (IV = IV + 1) |
| 4803 | SourceLocation IncLoc; |
| 4804 | ExprResult Inc = |
| 4805 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, IV.get(), |
| 4806 | SemaRef.ActOnIntegerConstant(IncLoc, 1).get()); |
| 4807 | if (!Inc.isUsable()) |
| 4808 | return 0; |
| 4809 | Inc = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, IV.get(), Inc.get()); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4810 | Inc = SemaRef.ActOnFinishFullExpr(Inc.get()); |
| 4811 | if (!Inc.isUsable()) |
| 4812 | return 0; |
| 4813 | |
| 4814 | // Increments for worksharing loops (LB = LB + ST; UB = UB + ST). |
| 4815 | // Used for directives with static scheduling. |
| 4816 | ExprResult NextLB, NextUB; |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 4817 | if (isOpenMPWorksharingDirective(DKind) || isOpenMPTaskLoopDirective(DKind) || |
| 4818 | isOpenMPDistributeDirective(DKind)) { |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4819 | // LB + ST |
| 4820 | NextLB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, LB.get(), ST.get()); |
| 4821 | if (!NextLB.isUsable()) |
| 4822 | return 0; |
| 4823 | // LB = LB + ST |
| 4824 | NextLB = |
| 4825 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, LB.get(), NextLB.get()); |
| 4826 | NextLB = SemaRef.ActOnFinishFullExpr(NextLB.get()); |
| 4827 | if (!NextLB.isUsable()) |
| 4828 | return 0; |
| 4829 | // UB + ST |
| 4830 | NextUB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, UB.get(), ST.get()); |
| 4831 | if (!NextUB.isUsable()) |
| 4832 | return 0; |
| 4833 | // UB = UB + ST |
| 4834 | NextUB = |
| 4835 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, UB.get(), NextUB.get()); |
| 4836 | NextUB = SemaRef.ActOnFinishFullExpr(NextUB.get()); |
| 4837 | if (!NextUB.isUsable()) |
| 4838 | return 0; |
| 4839 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4840 | |
| 4841 | // Build updates and final values of the loop counters. |
| 4842 | bool HasErrors = false; |
| 4843 | Built.Counters.resize(NestedLoopCount); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4844 | Built.Inits.resize(NestedLoopCount); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4845 | Built.Updates.resize(NestedLoopCount); |
| 4846 | Built.Finals.resize(NestedLoopCount); |
| 4847 | { |
| 4848 | ExprResult Div; |
| 4849 | // Go from inner nested loop to outer. |
| 4850 | for (int Cnt = NestedLoopCount - 1; Cnt >= 0; --Cnt) { |
| 4851 | LoopIterationSpace &IS = IterSpaces[Cnt]; |
| 4852 | SourceLocation UpdLoc = IS.IncSrcRange.getBegin(); |
| 4853 | // Build: Iter = (IV / Div) % IS.NumIters |
| 4854 | // where Div is product of previous iterations' IS.NumIters. |
| 4855 | ExprResult Iter; |
| 4856 | if (Div.isUsable()) { |
| 4857 | Iter = |
| 4858 | SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Div, IV.get(), Div.get()); |
| 4859 | } else { |
| 4860 | Iter = IV; |
| 4861 | assert((Cnt == (int)NestedLoopCount - 1) && |
| 4862 | "unusable div expected on first iteration only"); |
| 4863 | } |
| 4864 | |
| 4865 | if (Cnt != 0 && Iter.isUsable()) |
| 4866 | Iter = SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Rem, Iter.get(), |
| 4867 | IS.NumIterations); |
| 4868 | if (!Iter.isUsable()) { |
| 4869 | HasErrors = true; |
| 4870 | break; |
| 4871 | } |
| 4872 | |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4873 | // Build update: IS.CounterVar(Private) = IS.Start + Iter * IS.Step |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 4874 | auto *VD = cast<VarDecl>(cast<DeclRefExpr>(IS.CounterVar)->getDecl()); |
| 4875 | auto *CounterVar = buildDeclRefExpr(SemaRef, VD, IS.CounterVar->getType(), |
| 4876 | IS.CounterVar->getExprLoc(), |
| 4877 | /*RefersToCapture=*/true); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4878 | ExprResult Init = BuildCounterInit(SemaRef, CurScope, UpdLoc, CounterVar, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4879 | IS.CounterInit, Captures); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4880 | if (!Init.isUsable()) { |
| 4881 | HasErrors = true; |
| 4882 | break; |
| 4883 | } |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4884 | ExprResult Update = BuildCounterUpdate( |
| 4885 | SemaRef, CurScope, UpdLoc, CounterVar, IS.CounterInit, Iter, |
| 4886 | IS.CounterStep, IS.Subtract, &Captures); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4887 | if (!Update.isUsable()) { |
| 4888 | HasErrors = true; |
| 4889 | break; |
| 4890 | } |
| 4891 | |
| 4892 | // Build final: IS.CounterVar = IS.Start + IS.NumIters * IS.Step |
| 4893 | ExprResult Final = BuildCounterUpdate( |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4894 | SemaRef, CurScope, UpdLoc, CounterVar, IS.CounterInit, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4895 | IS.NumIterations, IS.CounterStep, IS.Subtract, &Captures); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4896 | if (!Final.isUsable()) { |
| 4897 | HasErrors = true; |
| 4898 | break; |
| 4899 | } |
| 4900 | |
| 4901 | // Build Div for the next iteration: Div <- Div * IS.NumIters |
| 4902 | if (Cnt != 0) { |
| 4903 | if (Div.isUnset()) |
| 4904 | Div = IS.NumIterations; |
| 4905 | else |
| 4906 | Div = SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Mul, Div.get(), |
| 4907 | IS.NumIterations); |
| 4908 | |
| 4909 | // Add parentheses (for debugging purposes only). |
| 4910 | if (Div.isUsable()) |
| 4911 | Div = SemaRef.ActOnParenExpr(UpdLoc, UpdLoc, Div.get()); |
| 4912 | if (!Div.isUsable()) { |
| 4913 | HasErrors = true; |
| 4914 | break; |
| 4915 | } |
| 4916 | } |
| 4917 | if (!Update.isUsable() || !Final.isUsable()) { |
| 4918 | HasErrors = true; |
| 4919 | break; |
| 4920 | } |
| 4921 | // Save results |
| 4922 | Built.Counters[Cnt] = IS.CounterVar; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 4923 | Built.PrivateCounters[Cnt] = IS.PrivateCounterVar; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4924 | Built.Inits[Cnt] = Init.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4925 | Built.Updates[Cnt] = Update.get(); |
| 4926 | Built.Finals[Cnt] = Final.get(); |
| 4927 | } |
| 4928 | } |
| 4929 | |
| 4930 | if (HasErrors) |
| 4931 | return 0; |
| 4932 | |
| 4933 | // Save results |
| 4934 | Built.IterationVarRef = IV.get(); |
| 4935 | Built.LastIteration = LastIteration.get(); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 4936 | Built.NumIterations = NumIterations.get(); |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 4937 | Built.CalcLastIteration = |
| 4938 | SemaRef.ActOnFinishFullExpr(CalcLastIteration.get()).get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4939 | Built.PreCond = PreCond.get(); |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4940 | Built.PreInits = buildPreInits(C, Captures); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4941 | Built.Cond = Cond.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4942 | Built.Init = Init.get(); |
| 4943 | Built.Inc = Inc.get(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4944 | Built.LB = LB.get(); |
| 4945 | Built.UB = UB.get(); |
| 4946 | Built.IL = IL.get(); |
| 4947 | Built.ST = ST.get(); |
| 4948 | Built.EUB = EUB.get(); |
| 4949 | Built.NLB = NextLB.get(); |
| 4950 | Built.NUB = NextUB.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4951 | |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 4952 | return NestedLoopCount; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4953 | } |
| 4954 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4955 | static Expr *getCollapseNumberExpr(ArrayRef<OMPClause *> Clauses) { |
Benjamin Kramer | fc600dc | 2015-08-30 15:12:28 +0000 | [diff] [blame] | 4956 | auto CollapseClauses = |
| 4957 | OMPExecutableDirective::getClausesOfKind<OMPCollapseClause>(Clauses); |
| 4958 | if (CollapseClauses.begin() != CollapseClauses.end()) |
| 4959 | return (*CollapseClauses.begin())->getNumForLoops(); |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 4960 | return nullptr; |
| 4961 | } |
| 4962 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4963 | static Expr *getOrderedNumberExpr(ArrayRef<OMPClause *> Clauses) { |
Benjamin Kramer | fc600dc | 2015-08-30 15:12:28 +0000 | [diff] [blame] | 4964 | auto OrderedClauses = |
| 4965 | OMPExecutableDirective::getClausesOfKind<OMPOrderedClause>(Clauses); |
| 4966 | if (OrderedClauses.begin() != OrderedClauses.end()) |
| 4967 | return (*OrderedClauses.begin())->getNumForLoops(); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4968 | return nullptr; |
| 4969 | } |
| 4970 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 4971 | static bool checkSimdlenSafelenValues(Sema &S, const Expr *Simdlen, |
| 4972 | const Expr *Safelen) { |
| 4973 | llvm::APSInt SimdlenRes, SafelenRes; |
| 4974 | if (Simdlen->isValueDependent() || Simdlen->isTypeDependent() || |
| 4975 | Simdlen->isInstantiationDependent() || |
| 4976 | Simdlen->containsUnexpandedParameterPack()) |
| 4977 | return false; |
| 4978 | if (Safelen->isValueDependent() || Safelen->isTypeDependent() || |
| 4979 | Safelen->isInstantiationDependent() || |
| 4980 | Safelen->containsUnexpandedParameterPack()) |
| 4981 | return false; |
| 4982 | Simdlen->EvaluateAsInt(SimdlenRes, S.Context); |
| 4983 | Safelen->EvaluateAsInt(SafelenRes, S.Context); |
| 4984 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 4985 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 4986 | // parameter must be less than or equal to the value of the safelen parameter. |
| 4987 | if (SimdlenRes > SafelenRes) { |
| 4988 | S.Diag(Simdlen->getExprLoc(), diag::err_omp_wrong_simdlen_safelen_values) |
| 4989 | << Simdlen->getSourceRange() << Safelen->getSourceRange(); |
| 4990 | return true; |
| 4991 | } |
| 4992 | return false; |
| 4993 | } |
| 4994 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4995 | StmtResult Sema::ActOnOpenMPSimdDirective( |
| 4996 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4997 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 4998 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4999 | if (!AStmt) |
| 5000 | return StmtError(); |
| 5001 | |
| 5002 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5003 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5004 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 5005 | // define the nested loops number. |
| 5006 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 5007 | OMPD_simd, getCollapseNumberExpr(Clauses), getOrderedNumberExpr(Clauses), |
| 5008 | AStmt, *this, *DSAStack, VarsWithImplicitDSA, B); |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 5009 | if (NestedLoopCount == 0) |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 5010 | return StmtError(); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 5011 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5012 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 5013 | "omp simd loop exprs were not built"); |
| 5014 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 5015 | if (!CurContext->isDependentContext()) { |
| 5016 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 5017 | for (auto C : Clauses) { |
| 5018 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 5019 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 5020 | B.NumIterations, *this, CurScope, |
| 5021 | DSAStack)) |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 5022 | return StmtError(); |
| 5023 | } |
| 5024 | } |
| 5025 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 5026 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 5027 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 5028 | // parameter must be less than or equal to the value of the safelen parameter. |
| 5029 | OMPSafelenClause *Safelen = nullptr; |
| 5030 | OMPSimdlenClause *Simdlen = nullptr; |
| 5031 | for (auto *Clause : Clauses) { |
| 5032 | if (Clause->getClauseKind() == OMPC_safelen) |
| 5033 | Safelen = cast<OMPSafelenClause>(Clause); |
| 5034 | else if (Clause->getClauseKind() == OMPC_simdlen) |
| 5035 | Simdlen = cast<OMPSimdlenClause>(Clause); |
| 5036 | if (Safelen && Simdlen) |
| 5037 | break; |
| 5038 | } |
| 5039 | if (Simdlen && Safelen && |
| 5040 | checkSimdlenSafelenValues(*this, Simdlen->getSimdlen(), |
| 5041 | Safelen->getSafelen())) |
| 5042 | return StmtError(); |
| 5043 | |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 5044 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5045 | return OMPSimdDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| 5046 | Clauses, AStmt, B); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 5047 | } |
| 5048 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 5049 | StmtResult Sema::ActOnOpenMPForDirective( |
| 5050 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 5051 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 5052 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5053 | if (!AStmt) |
| 5054 | return StmtError(); |
| 5055 | |
| 5056 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5057 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5058 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 5059 | // define the nested loops number. |
| 5060 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 5061 | OMPD_for, getCollapseNumberExpr(Clauses), getOrderedNumberExpr(Clauses), |
| 5062 | AStmt, *this, *DSAStack, VarsWithImplicitDSA, B); |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 5063 | if (NestedLoopCount == 0) |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 5064 | return StmtError(); |
| 5065 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5066 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 5067 | "omp for loop exprs were not built"); |
| 5068 | |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 5069 | if (!CurContext->isDependentContext()) { |
| 5070 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 5071 | for (auto C : Clauses) { |
| 5072 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 5073 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 5074 | B.NumIterations, *this, CurScope, |
| 5075 | DSAStack)) |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 5076 | return StmtError(); |
| 5077 | } |
| 5078 | } |
| 5079 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 5080 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5081 | return OMPForDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 5082 | Clauses, AStmt, B, DSAStack->isCancelRegion()); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 5083 | } |
| 5084 | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 5085 | StmtResult Sema::ActOnOpenMPForSimdDirective( |
| 5086 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 5087 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 5088 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
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"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5093 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5094 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 5095 | // define the nested loops number. |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 5096 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5097 | CheckOpenMPLoop(OMPD_for_simd, getCollapseNumberExpr(Clauses), |
| 5098 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 5099 | VarsWithImplicitDSA, B); |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 5100 | if (NestedLoopCount == 0) |
| 5101 | return StmtError(); |
| 5102 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5103 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 5104 | "omp for simd loop exprs were not built"); |
| 5105 | |
Alexey Bataev | 58e5bdb | 2015-06-18 04:45:29 +0000 | [diff] [blame] | 5106 | if (!CurContext->isDependentContext()) { |
| 5107 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 5108 | for (auto C : Clauses) { |
| 5109 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 5110 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 5111 | B.NumIterations, *this, CurScope, |
| 5112 | DSAStack)) |
Alexey Bataev | 58e5bdb | 2015-06-18 04:45:29 +0000 | [diff] [blame] | 5113 | return StmtError(); |
| 5114 | } |
| 5115 | } |
| 5116 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 5117 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 5118 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 5119 | // parameter must be less than or equal to the value of the safelen parameter. |
| 5120 | OMPSafelenClause *Safelen = nullptr; |
| 5121 | OMPSimdlenClause *Simdlen = nullptr; |
| 5122 | for (auto *Clause : Clauses) { |
| 5123 | if (Clause->getClauseKind() == OMPC_safelen) |
| 5124 | Safelen = cast<OMPSafelenClause>(Clause); |
| 5125 | else if (Clause->getClauseKind() == OMPC_simdlen) |
| 5126 | Simdlen = cast<OMPSimdlenClause>(Clause); |
| 5127 | if (Safelen && Simdlen) |
| 5128 | break; |
| 5129 | } |
| 5130 | if (Simdlen && Safelen && |
| 5131 | checkSimdlenSafelenValues(*this, Simdlen->getSimdlen(), |
| 5132 | Safelen->getSafelen())) |
| 5133 | return StmtError(); |
| 5134 | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 5135 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5136 | return OMPForSimdDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| 5137 | Clauses, AStmt, B); |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 5138 | } |
| 5139 | |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 5140 | StmtResult Sema::ActOnOpenMPSectionsDirective(ArrayRef<OMPClause *> Clauses, |
| 5141 | Stmt *AStmt, |
| 5142 | SourceLocation StartLoc, |
| 5143 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5144 | if (!AStmt) |
| 5145 | return StmtError(); |
| 5146 | |
| 5147 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 5148 | auto BaseStmt = AStmt; |
| 5149 | while (CapturedStmt *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt)) |
| 5150 | BaseStmt = CS->getCapturedStmt(); |
| 5151 | if (auto C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) { |
| 5152 | auto S = C->children(); |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 5153 | if (S.begin() == S.end()) |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 5154 | return StmtError(); |
| 5155 | // All associated statements must be '#pragma omp section' except for |
| 5156 | // the first one. |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 5157 | for (Stmt *SectionStmt : llvm::make_range(std::next(S.begin()), S.end())) { |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 5158 | if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) { |
| 5159 | if (SectionStmt) |
| 5160 | Diag(SectionStmt->getLocStart(), |
| 5161 | diag::err_omp_sections_substmt_not_section); |
| 5162 | return StmtError(); |
| 5163 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 5164 | cast<OMPSectionDirective>(SectionStmt) |
| 5165 | ->setHasCancel(DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 5166 | } |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 5167 | } else { |
| 5168 | Diag(AStmt->getLocStart(), diag::err_omp_sections_not_compound_stmt); |
| 5169 | return StmtError(); |
| 5170 | } |
| 5171 | |
| 5172 | getCurFunction()->setHasBranchProtectedScope(); |
| 5173 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 5174 | return OMPSectionsDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 5175 | DSAStack->isCancelRegion()); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 5176 | } |
| 5177 | |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 5178 | StmtResult Sema::ActOnOpenMPSectionDirective(Stmt *AStmt, |
| 5179 | SourceLocation StartLoc, |
| 5180 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5181 | if (!AStmt) |
| 5182 | return StmtError(); |
| 5183 | |
| 5184 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 5185 | |
| 5186 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 5187 | DSAStack->setParentCancelRegion(DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 5188 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 5189 | return OMPSectionDirective::Create(Context, StartLoc, EndLoc, AStmt, |
| 5190 | DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 5191 | } |
| 5192 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 5193 | StmtResult Sema::ActOnOpenMPSingleDirective(ArrayRef<OMPClause *> Clauses, |
| 5194 | Stmt *AStmt, |
| 5195 | SourceLocation StartLoc, |
| 5196 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5197 | if (!AStmt) |
| 5198 | return StmtError(); |
| 5199 | |
| 5200 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 74a05c9 | 2014-07-15 02:55:09 +0000 | [diff] [blame] | 5201 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 5202 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | 74a05c9 | 2014-07-15 02:55:09 +0000 | [diff] [blame] | 5203 | |
Alexey Bataev | 3255bf3 | 2015-01-19 05:20:46 +0000 | [diff] [blame] | 5204 | // OpenMP [2.7.3, single Construct, Restrictions] |
| 5205 | // The copyprivate clause must not be used with the nowait clause. |
| 5206 | OMPClause *Nowait = nullptr; |
| 5207 | OMPClause *Copyprivate = nullptr; |
| 5208 | for (auto *Clause : Clauses) { |
| 5209 | if (Clause->getClauseKind() == OMPC_nowait) |
| 5210 | Nowait = Clause; |
| 5211 | else if (Clause->getClauseKind() == OMPC_copyprivate) |
| 5212 | Copyprivate = Clause; |
| 5213 | if (Copyprivate && Nowait) { |
| 5214 | Diag(Copyprivate->getLocStart(), |
| 5215 | diag::err_omp_single_copyprivate_with_nowait); |
| 5216 | Diag(Nowait->getLocStart(), diag::note_omp_nowait_clause_here); |
| 5217 | return StmtError(); |
| 5218 | } |
| 5219 | } |
| 5220 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 5221 | return OMPSingleDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 5222 | } |
| 5223 | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 5224 | StmtResult Sema::ActOnOpenMPMasterDirective(Stmt *AStmt, |
| 5225 | SourceLocation StartLoc, |
| 5226 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5227 | if (!AStmt) |
| 5228 | return StmtError(); |
| 5229 | |
| 5230 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 5231 | |
| 5232 | getCurFunction()->setHasBranchProtectedScope(); |
| 5233 | |
| 5234 | return OMPMasterDirective::Create(Context, StartLoc, EndLoc, AStmt); |
| 5235 | } |
| 5236 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 5237 | StmtResult Sema::ActOnOpenMPCriticalDirective( |
| 5238 | const DeclarationNameInfo &DirName, ArrayRef<OMPClause *> Clauses, |
| 5239 | Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5240 | if (!AStmt) |
| 5241 | return StmtError(); |
| 5242 | |
| 5243 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 5244 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 5245 | bool ErrorFound = false; |
| 5246 | llvm::APSInt Hint; |
| 5247 | SourceLocation HintLoc; |
| 5248 | bool DependentHint = false; |
| 5249 | for (auto *C : Clauses) { |
| 5250 | if (C->getClauseKind() == OMPC_hint) { |
| 5251 | if (!DirName.getName()) { |
| 5252 | Diag(C->getLocStart(), diag::err_omp_hint_clause_no_name); |
| 5253 | ErrorFound = true; |
| 5254 | } |
| 5255 | Expr *E = cast<OMPHintClause>(C)->getHint(); |
| 5256 | if (E->isTypeDependent() || E->isValueDependent() || |
| 5257 | E->isInstantiationDependent()) |
| 5258 | DependentHint = true; |
| 5259 | else { |
| 5260 | Hint = E->EvaluateKnownConstInt(Context); |
| 5261 | HintLoc = C->getLocStart(); |
| 5262 | } |
| 5263 | } |
| 5264 | } |
| 5265 | if (ErrorFound) |
| 5266 | return StmtError(); |
| 5267 | auto Pair = DSAStack->getCriticalWithHint(DirName); |
| 5268 | if (Pair.first && DirName.getName() && !DependentHint) { |
| 5269 | if (llvm::APSInt::compareValues(Hint, Pair.second) != 0) { |
| 5270 | Diag(StartLoc, diag::err_omp_critical_with_hint); |
| 5271 | if (HintLoc.isValid()) { |
| 5272 | Diag(HintLoc, diag::note_omp_critical_hint_here) |
| 5273 | << 0 << Hint.toString(/*Radix=*/10, /*Signed=*/false); |
| 5274 | } else |
| 5275 | Diag(StartLoc, diag::note_omp_critical_no_hint) << 0; |
| 5276 | if (auto *C = Pair.first->getSingleClause<OMPHintClause>()) { |
| 5277 | Diag(C->getLocStart(), diag::note_omp_critical_hint_here) |
| 5278 | << 1 |
| 5279 | << C->getHint()->EvaluateKnownConstInt(Context).toString( |
| 5280 | /*Radix=*/10, /*Signed=*/false); |
| 5281 | } else |
| 5282 | Diag(Pair.first->getLocStart(), diag::note_omp_critical_no_hint) << 1; |
| 5283 | } |
| 5284 | } |
| 5285 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 5286 | getCurFunction()->setHasBranchProtectedScope(); |
| 5287 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 5288 | auto *Dir = OMPCriticalDirective::Create(Context, DirName, StartLoc, EndLoc, |
| 5289 | Clauses, AStmt); |
| 5290 | if (!Pair.first && DirName.getName() && !DependentHint) |
| 5291 | DSAStack->addCriticalWithHint(Dir, Hint); |
| 5292 | return Dir; |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 5293 | } |
| 5294 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 5295 | StmtResult Sema::ActOnOpenMPParallelForDirective( |
| 5296 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 5297 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 5298 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5299 | if (!AStmt) |
| 5300 | return StmtError(); |
| 5301 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 5302 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 5303 | // 1.2.2 OpenMP Language Terminology |
| 5304 | // Structured block - An executable statement with a single entry at the |
| 5305 | // top and a single exit at the bottom. |
| 5306 | // The point of exit cannot be a branch out of the structured block. |
| 5307 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5308 | CS->getCapturedDecl()->setNothrow(); |
| 5309 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5310 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5311 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 5312 | // define the nested loops number. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 5313 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5314 | CheckOpenMPLoop(OMPD_parallel_for, getCollapseNumberExpr(Clauses), |
| 5315 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 5316 | VarsWithImplicitDSA, B); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 5317 | if (NestedLoopCount == 0) |
| 5318 | return StmtError(); |
| 5319 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5320 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 5321 | "omp parallel for loop exprs were not built"); |
| 5322 | |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 5323 | if (!CurContext->isDependentContext()) { |
| 5324 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 5325 | for (auto C : Clauses) { |
| 5326 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 5327 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 5328 | B.NumIterations, *this, CurScope, |
| 5329 | DSAStack)) |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 5330 | return StmtError(); |
| 5331 | } |
| 5332 | } |
| 5333 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 5334 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5335 | return OMPParallelForDirective::Create(Context, StartLoc, EndLoc, |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 5336 | NestedLoopCount, Clauses, AStmt, B, |
| 5337 | DSAStack->isCancelRegion()); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 5338 | } |
| 5339 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 5340 | StmtResult Sema::ActOnOpenMPParallelForSimdDirective( |
| 5341 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 5342 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 5343 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5344 | if (!AStmt) |
| 5345 | return StmtError(); |
| 5346 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 5347 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 5348 | // 1.2.2 OpenMP Language Terminology |
| 5349 | // Structured block - An executable statement with a single entry at the |
| 5350 | // top and a single exit at the bottom. |
| 5351 | // The point of exit cannot be a branch out of the structured block. |
| 5352 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5353 | CS->getCapturedDecl()->setNothrow(); |
| 5354 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5355 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5356 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 5357 | // define the nested loops number. |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 5358 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5359 | CheckOpenMPLoop(OMPD_parallel_for_simd, getCollapseNumberExpr(Clauses), |
| 5360 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 5361 | VarsWithImplicitDSA, B); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 5362 | if (NestedLoopCount == 0) |
| 5363 | return StmtError(); |
| 5364 | |
Alexey Bataev | 3b5b5c4 | 2015-06-18 10:10:12 +0000 | [diff] [blame] | 5365 | if (!CurContext->isDependentContext()) { |
| 5366 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 5367 | for (auto C : Clauses) { |
| 5368 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 5369 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 5370 | B.NumIterations, *this, CurScope, |
| 5371 | DSAStack)) |
Alexey Bataev | 3b5b5c4 | 2015-06-18 10:10:12 +0000 | [diff] [blame] | 5372 | return StmtError(); |
| 5373 | } |
| 5374 | } |
| 5375 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 5376 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 5377 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 5378 | // parameter must be less than or equal to the value of the safelen parameter. |
| 5379 | OMPSafelenClause *Safelen = nullptr; |
| 5380 | OMPSimdlenClause *Simdlen = nullptr; |
| 5381 | for (auto *Clause : Clauses) { |
| 5382 | if (Clause->getClauseKind() == OMPC_safelen) |
| 5383 | Safelen = cast<OMPSafelenClause>(Clause); |
| 5384 | else if (Clause->getClauseKind() == OMPC_simdlen) |
| 5385 | Simdlen = cast<OMPSimdlenClause>(Clause); |
| 5386 | if (Safelen && Simdlen) |
| 5387 | break; |
| 5388 | } |
| 5389 | if (Simdlen && Safelen && |
| 5390 | checkSimdlenSafelenValues(*this, Simdlen->getSimdlen(), |
| 5391 | Safelen->getSafelen())) |
| 5392 | return StmtError(); |
| 5393 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 5394 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5395 | return OMPParallelForSimdDirective::Create( |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5396 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 5397 | } |
| 5398 | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 5399 | StmtResult |
| 5400 | Sema::ActOnOpenMPParallelSectionsDirective(ArrayRef<OMPClause *> Clauses, |
| 5401 | Stmt *AStmt, SourceLocation StartLoc, |
| 5402 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5403 | if (!AStmt) |
| 5404 | return StmtError(); |
| 5405 | |
| 5406 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 5407 | auto BaseStmt = AStmt; |
| 5408 | while (CapturedStmt *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt)) |
| 5409 | BaseStmt = CS->getCapturedStmt(); |
| 5410 | if (auto C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) { |
| 5411 | auto S = C->children(); |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 5412 | if (S.begin() == S.end()) |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 5413 | return StmtError(); |
| 5414 | // All associated statements must be '#pragma omp section' except for |
| 5415 | // the first one. |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 5416 | for (Stmt *SectionStmt : llvm::make_range(std::next(S.begin()), S.end())) { |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 5417 | if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) { |
| 5418 | if (SectionStmt) |
| 5419 | Diag(SectionStmt->getLocStart(), |
| 5420 | diag::err_omp_parallel_sections_substmt_not_section); |
| 5421 | return StmtError(); |
| 5422 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 5423 | cast<OMPSectionDirective>(SectionStmt) |
| 5424 | ->setHasCancel(DSAStack->isCancelRegion()); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 5425 | } |
| 5426 | } else { |
| 5427 | Diag(AStmt->getLocStart(), |
| 5428 | diag::err_omp_parallel_sections_not_compound_stmt); |
| 5429 | return StmtError(); |
| 5430 | } |
| 5431 | |
| 5432 | getCurFunction()->setHasBranchProtectedScope(); |
| 5433 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 5434 | return OMPParallelSectionsDirective::Create( |
| 5435 | Context, StartLoc, EndLoc, Clauses, AStmt, DSAStack->isCancelRegion()); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 5436 | } |
| 5437 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5438 | StmtResult Sema::ActOnOpenMPTaskDirective(ArrayRef<OMPClause *> Clauses, |
| 5439 | Stmt *AStmt, SourceLocation StartLoc, |
| 5440 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5441 | if (!AStmt) |
| 5442 | return StmtError(); |
| 5443 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5444 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 5445 | // 1.2.2 OpenMP Language Terminology |
| 5446 | // Structured block - An executable statement with a single entry at the |
| 5447 | // top and a single exit at the bottom. |
| 5448 | // The point of exit cannot be a branch out of the structured block. |
| 5449 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5450 | CS->getCapturedDecl()->setNothrow(); |
| 5451 | |
| 5452 | getCurFunction()->setHasBranchProtectedScope(); |
| 5453 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 5454 | return OMPTaskDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 5455 | DSAStack->isCancelRegion()); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5456 | } |
| 5457 | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 5458 | StmtResult Sema::ActOnOpenMPTaskyieldDirective(SourceLocation StartLoc, |
| 5459 | SourceLocation EndLoc) { |
| 5460 | return OMPTaskyieldDirective::Create(Context, StartLoc, EndLoc); |
| 5461 | } |
| 5462 | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 5463 | StmtResult Sema::ActOnOpenMPBarrierDirective(SourceLocation StartLoc, |
| 5464 | SourceLocation EndLoc) { |
| 5465 | return OMPBarrierDirective::Create(Context, StartLoc, EndLoc); |
| 5466 | } |
| 5467 | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 5468 | StmtResult Sema::ActOnOpenMPTaskwaitDirective(SourceLocation StartLoc, |
| 5469 | SourceLocation EndLoc) { |
| 5470 | return OMPTaskwaitDirective::Create(Context, StartLoc, EndLoc); |
| 5471 | } |
| 5472 | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 5473 | StmtResult Sema::ActOnOpenMPTaskgroupDirective(Stmt *AStmt, |
| 5474 | SourceLocation StartLoc, |
| 5475 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5476 | if (!AStmt) |
| 5477 | return StmtError(); |
| 5478 | |
| 5479 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 5480 | |
| 5481 | getCurFunction()->setHasBranchProtectedScope(); |
| 5482 | |
| 5483 | return OMPTaskgroupDirective::Create(Context, StartLoc, EndLoc, AStmt); |
| 5484 | } |
| 5485 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 5486 | StmtResult Sema::ActOnOpenMPFlushDirective(ArrayRef<OMPClause *> Clauses, |
| 5487 | SourceLocation StartLoc, |
| 5488 | SourceLocation EndLoc) { |
| 5489 | assert(Clauses.size() <= 1 && "Extra clauses in flush directive"); |
| 5490 | return OMPFlushDirective::Create(Context, StartLoc, EndLoc, Clauses); |
| 5491 | } |
| 5492 | |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5493 | StmtResult Sema::ActOnOpenMPOrderedDirective(ArrayRef<OMPClause *> Clauses, |
| 5494 | Stmt *AStmt, |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 5495 | SourceLocation StartLoc, |
| 5496 | SourceLocation EndLoc) { |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5497 | OMPClause *DependFound = nullptr; |
| 5498 | OMPClause *DependSourceClause = nullptr; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 5499 | OMPClause *DependSinkClause = nullptr; |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5500 | bool ErrorFound = false; |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5501 | OMPThreadsClause *TC = nullptr; |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5502 | OMPSIMDClause *SC = nullptr; |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5503 | for (auto *C : Clauses) { |
| 5504 | if (auto *DC = dyn_cast<OMPDependClause>(C)) { |
| 5505 | DependFound = C; |
| 5506 | if (DC->getDependencyKind() == OMPC_DEPEND_source) { |
| 5507 | if (DependSourceClause) { |
| 5508 | Diag(C->getLocStart(), diag::err_omp_more_one_clause) |
| 5509 | << getOpenMPDirectiveName(OMPD_ordered) |
| 5510 | << getOpenMPClauseName(OMPC_depend) << 2; |
| 5511 | ErrorFound = true; |
| 5512 | } else |
| 5513 | DependSourceClause = C; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 5514 | if (DependSinkClause) { |
| 5515 | Diag(C->getLocStart(), diag::err_omp_depend_sink_source_not_allowed) |
| 5516 | << 0; |
| 5517 | ErrorFound = true; |
| 5518 | } |
| 5519 | } else if (DC->getDependencyKind() == OMPC_DEPEND_sink) { |
| 5520 | if (DependSourceClause) { |
| 5521 | Diag(C->getLocStart(), diag::err_omp_depend_sink_source_not_allowed) |
| 5522 | << 1; |
| 5523 | ErrorFound = true; |
| 5524 | } |
| 5525 | DependSinkClause = C; |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5526 | } |
| 5527 | } else if (C->getClauseKind() == OMPC_threads) |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5528 | TC = cast<OMPThreadsClause>(C); |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5529 | else if (C->getClauseKind() == OMPC_simd) |
| 5530 | SC = cast<OMPSIMDClause>(C); |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5531 | } |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5532 | if (!ErrorFound && !SC && |
| 5533 | isOpenMPSimdDirective(DSAStack->getParentDirective())) { |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5534 | // OpenMP [2.8.1,simd Construct, Restrictions] |
| 5535 | // An ordered construct with the simd clause is the only OpenMP construct |
| 5536 | // that can appear in the simd region. |
| 5537 | Diag(StartLoc, diag::err_omp_prohibited_region_simd); |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5538 | ErrorFound = true; |
| 5539 | } else if (DependFound && (TC || SC)) { |
| 5540 | Diag(DependFound->getLocStart(), diag::err_omp_depend_clause_thread_simd) |
| 5541 | << getOpenMPClauseName(TC ? TC->getClauseKind() : SC->getClauseKind()); |
| 5542 | ErrorFound = true; |
| 5543 | } else if (DependFound && !DSAStack->getParentOrderedRegionParam()) { |
| 5544 | Diag(DependFound->getLocStart(), |
| 5545 | diag::err_omp_ordered_directive_without_param); |
| 5546 | ErrorFound = true; |
| 5547 | } else if (TC || Clauses.empty()) { |
| 5548 | if (auto *Param = DSAStack->getParentOrderedRegionParam()) { |
| 5549 | SourceLocation ErrLoc = TC ? TC->getLocStart() : StartLoc; |
| 5550 | Diag(ErrLoc, diag::err_omp_ordered_directive_with_param) |
| 5551 | << (TC != nullptr); |
| 5552 | Diag(Param->getLocStart(), diag::note_omp_ordered_param); |
| 5553 | ErrorFound = true; |
| 5554 | } |
| 5555 | } |
| 5556 | if ((!AStmt && !DependFound) || ErrorFound) |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5557 | return StmtError(); |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5558 | |
| 5559 | if (AStmt) { |
| 5560 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 5561 | |
| 5562 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5563 | } |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5564 | |
| 5565 | return OMPOrderedDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 5566 | } |
| 5567 | |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5568 | namespace { |
| 5569 | /// \brief Helper class for checking expression in 'omp atomic [update]' |
| 5570 | /// construct. |
| 5571 | class OpenMPAtomicUpdateChecker { |
| 5572 | /// \brief Error results for atomic update expressions. |
| 5573 | enum ExprAnalysisErrorCode { |
| 5574 | /// \brief A statement is not an expression statement. |
| 5575 | NotAnExpression, |
| 5576 | /// \brief Expression is not builtin binary or unary operation. |
| 5577 | NotABinaryOrUnaryExpression, |
| 5578 | /// \brief Unary operation is not post-/pre- increment/decrement operation. |
| 5579 | NotAnUnaryIncDecExpression, |
| 5580 | /// \brief An expression is not of scalar type. |
| 5581 | NotAScalarType, |
| 5582 | /// \brief A binary operation is not an assignment operation. |
| 5583 | NotAnAssignmentOp, |
| 5584 | /// \brief RHS part of the binary operation is not a binary expression. |
| 5585 | NotABinaryExpression, |
| 5586 | /// \brief RHS part is not additive/multiplicative/shift/biwise binary |
| 5587 | /// expression. |
| 5588 | NotABinaryOperator, |
| 5589 | /// \brief RHS binary operation does not have reference to the updated LHS |
| 5590 | /// part. |
| 5591 | NotAnUpdateExpression, |
| 5592 | /// \brief No errors is found. |
| 5593 | NoError |
| 5594 | }; |
| 5595 | /// \brief Reference to Sema. |
| 5596 | Sema &SemaRef; |
| 5597 | /// \brief A location for note diagnostics (when error is found). |
| 5598 | SourceLocation NoteLoc; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5599 | /// \brief 'x' lvalue part of the source atomic expression. |
| 5600 | Expr *X; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5601 | /// \brief 'expr' rvalue part of the source atomic expression. |
| 5602 | Expr *E; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5603 | /// \brief Helper expression of the form |
| 5604 | /// 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or |
| 5605 | /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'. |
| 5606 | Expr *UpdateExpr; |
| 5607 | /// \brief Is 'x' a LHS in a RHS part of full update expression. It is |
| 5608 | /// important for non-associative operations. |
| 5609 | bool IsXLHSInRHSPart; |
| 5610 | BinaryOperatorKind Op; |
| 5611 | SourceLocation OpLoc; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5612 | /// \brief true if the source expression is a postfix unary operation, false |
| 5613 | /// if it is a prefix unary operation. |
| 5614 | bool IsPostfixUpdate; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5615 | |
| 5616 | public: |
| 5617 | OpenMPAtomicUpdateChecker(Sema &SemaRef) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5618 | : SemaRef(SemaRef), X(nullptr), E(nullptr), UpdateExpr(nullptr), |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5619 | IsXLHSInRHSPart(false), Op(BO_PtrMemD), IsPostfixUpdate(false) {} |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5620 | /// \brief Check specified statement that it is suitable for 'atomic update' |
| 5621 | /// constructs and extract 'x', 'expr' and Operation from the original |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5622 | /// expression. If DiagId and NoteId == 0, then only check is performed |
| 5623 | /// without error notification. |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5624 | /// \param DiagId Diagnostic which should be emitted if error is found. |
| 5625 | /// \param NoteId Diagnostic note for the main error message. |
| 5626 | /// \return true if statement is not an update expression, false otherwise. |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5627 | bool checkStatement(Stmt *S, unsigned DiagId = 0, unsigned NoteId = 0); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5628 | /// \brief Return the 'x' lvalue part of the source atomic expression. |
| 5629 | Expr *getX() const { return X; } |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5630 | /// \brief Return the 'expr' rvalue part of the source atomic expression. |
| 5631 | Expr *getExpr() const { return E; } |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5632 | /// \brief Return the update expression used in calculation of the updated |
| 5633 | /// value. Always has form 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or |
| 5634 | /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'. |
| 5635 | Expr *getUpdateExpr() const { return UpdateExpr; } |
| 5636 | /// \brief Return true if 'x' is LHS in RHS part of full update expression, |
| 5637 | /// false otherwise. |
| 5638 | bool isXLHSInRHSPart() const { return IsXLHSInRHSPart; } |
| 5639 | |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5640 | /// \brief true if the source expression is a postfix unary operation, false |
| 5641 | /// if it is a prefix unary operation. |
| 5642 | bool isPostfixUpdate() const { return IsPostfixUpdate; } |
| 5643 | |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5644 | private: |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5645 | bool checkBinaryOperation(BinaryOperator *AtomicBinOp, unsigned DiagId = 0, |
| 5646 | unsigned NoteId = 0); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5647 | }; |
| 5648 | } // namespace |
| 5649 | |
| 5650 | bool OpenMPAtomicUpdateChecker::checkBinaryOperation( |
| 5651 | BinaryOperator *AtomicBinOp, unsigned DiagId, unsigned NoteId) { |
| 5652 | ExprAnalysisErrorCode ErrorFound = NoError; |
| 5653 | SourceLocation ErrorLoc, NoteLoc; |
| 5654 | SourceRange ErrorRange, NoteRange; |
| 5655 | // Allowed constructs are: |
| 5656 | // x = x binop expr; |
| 5657 | // x = expr binop x; |
| 5658 | if (AtomicBinOp->getOpcode() == BO_Assign) { |
| 5659 | X = AtomicBinOp->getLHS(); |
| 5660 | if (auto *AtomicInnerBinOp = dyn_cast<BinaryOperator>( |
| 5661 | AtomicBinOp->getRHS()->IgnoreParenImpCasts())) { |
| 5662 | if (AtomicInnerBinOp->isMultiplicativeOp() || |
| 5663 | AtomicInnerBinOp->isAdditiveOp() || AtomicInnerBinOp->isShiftOp() || |
| 5664 | AtomicInnerBinOp->isBitwiseOp()) { |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5665 | Op = AtomicInnerBinOp->getOpcode(); |
| 5666 | OpLoc = AtomicInnerBinOp->getOperatorLoc(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5667 | auto *LHS = AtomicInnerBinOp->getLHS(); |
| 5668 | auto *RHS = AtomicInnerBinOp->getRHS(); |
| 5669 | llvm::FoldingSetNodeID XId, LHSId, RHSId; |
| 5670 | X->IgnoreParenImpCasts()->Profile(XId, SemaRef.getASTContext(), |
| 5671 | /*Canonical=*/true); |
| 5672 | LHS->IgnoreParenImpCasts()->Profile(LHSId, SemaRef.getASTContext(), |
| 5673 | /*Canonical=*/true); |
| 5674 | RHS->IgnoreParenImpCasts()->Profile(RHSId, SemaRef.getASTContext(), |
| 5675 | /*Canonical=*/true); |
| 5676 | if (XId == LHSId) { |
| 5677 | E = RHS; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5678 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5679 | } else if (XId == RHSId) { |
| 5680 | E = LHS; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5681 | IsXLHSInRHSPart = false; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5682 | } else { |
| 5683 | ErrorLoc = AtomicInnerBinOp->getExprLoc(); |
| 5684 | ErrorRange = AtomicInnerBinOp->getSourceRange(); |
| 5685 | NoteLoc = X->getExprLoc(); |
| 5686 | NoteRange = X->getSourceRange(); |
| 5687 | ErrorFound = NotAnUpdateExpression; |
| 5688 | } |
| 5689 | } else { |
| 5690 | ErrorLoc = AtomicInnerBinOp->getExprLoc(); |
| 5691 | ErrorRange = AtomicInnerBinOp->getSourceRange(); |
| 5692 | NoteLoc = AtomicInnerBinOp->getOperatorLoc(); |
| 5693 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 5694 | ErrorFound = NotABinaryOperator; |
| 5695 | } |
| 5696 | } else { |
| 5697 | NoteLoc = ErrorLoc = AtomicBinOp->getRHS()->getExprLoc(); |
| 5698 | NoteRange = ErrorRange = AtomicBinOp->getRHS()->getSourceRange(); |
| 5699 | ErrorFound = NotABinaryExpression; |
| 5700 | } |
| 5701 | } else { |
| 5702 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5703 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5704 | NoteLoc = AtomicBinOp->getOperatorLoc(); |
| 5705 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 5706 | ErrorFound = NotAnAssignmentOp; |
| 5707 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5708 | if (ErrorFound != NoError && DiagId != 0 && NoteId != 0) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5709 | SemaRef.Diag(ErrorLoc, DiagId) << ErrorRange; |
| 5710 | SemaRef.Diag(NoteLoc, NoteId) << ErrorFound << NoteRange; |
| 5711 | return true; |
| 5712 | } else if (SemaRef.CurContext->isDependentContext()) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5713 | E = X = UpdateExpr = nullptr; |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5714 | return ErrorFound != NoError; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5715 | } |
| 5716 | |
| 5717 | bool OpenMPAtomicUpdateChecker::checkStatement(Stmt *S, unsigned DiagId, |
| 5718 | unsigned NoteId) { |
| 5719 | ExprAnalysisErrorCode ErrorFound = NoError; |
| 5720 | SourceLocation ErrorLoc, NoteLoc; |
| 5721 | SourceRange ErrorRange, NoteRange; |
| 5722 | // Allowed constructs are: |
| 5723 | // x++; |
| 5724 | // x--; |
| 5725 | // ++x; |
| 5726 | // --x; |
| 5727 | // x binop= expr; |
| 5728 | // x = x binop expr; |
| 5729 | // x = expr binop x; |
| 5730 | if (auto *AtomicBody = dyn_cast<Expr>(S)) { |
| 5731 | AtomicBody = AtomicBody->IgnoreParenImpCasts(); |
| 5732 | if (AtomicBody->getType()->isScalarType() || |
| 5733 | AtomicBody->isInstantiationDependent()) { |
| 5734 | if (auto *AtomicCompAssignOp = dyn_cast<CompoundAssignOperator>( |
| 5735 | AtomicBody->IgnoreParenImpCasts())) { |
| 5736 | // Check for Compound Assignment Operation |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5737 | Op = BinaryOperator::getOpForCompoundAssignment( |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5738 | AtomicCompAssignOp->getOpcode()); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5739 | OpLoc = AtomicCompAssignOp->getOperatorLoc(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5740 | E = AtomicCompAssignOp->getRHS(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5741 | X = AtomicCompAssignOp->getLHS(); |
| 5742 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5743 | } else if (auto *AtomicBinOp = dyn_cast<BinaryOperator>( |
| 5744 | AtomicBody->IgnoreParenImpCasts())) { |
| 5745 | // Check for Binary Operation |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5746 | if(checkBinaryOperation(AtomicBinOp, DiagId, NoteId)) |
| 5747 | return true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5748 | } else if (auto *AtomicUnaryOp = |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5749 | dyn_cast<UnaryOperator>(AtomicBody->IgnoreParenImpCasts())) { |
| 5750 | // Check for Unary Operation |
| 5751 | if (AtomicUnaryOp->isIncrementDecrementOp()) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5752 | IsPostfixUpdate = AtomicUnaryOp->isPostfix(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5753 | Op = AtomicUnaryOp->isIncrementOp() ? BO_Add : BO_Sub; |
| 5754 | OpLoc = AtomicUnaryOp->getOperatorLoc(); |
| 5755 | X = AtomicUnaryOp->getSubExpr(); |
| 5756 | E = SemaRef.ActOnIntegerConstant(OpLoc, /*uint64_t Val=*/1).get(); |
| 5757 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5758 | } else { |
| 5759 | ErrorFound = NotAnUnaryIncDecExpression; |
| 5760 | ErrorLoc = AtomicUnaryOp->getExprLoc(); |
| 5761 | ErrorRange = AtomicUnaryOp->getSourceRange(); |
| 5762 | NoteLoc = AtomicUnaryOp->getOperatorLoc(); |
| 5763 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 5764 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5765 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5766 | ErrorFound = NotABinaryOrUnaryExpression; |
| 5767 | NoteLoc = ErrorLoc = AtomicBody->getExprLoc(); |
| 5768 | NoteRange = ErrorRange = AtomicBody->getSourceRange(); |
| 5769 | } |
| 5770 | } else { |
| 5771 | ErrorFound = NotAScalarType; |
| 5772 | NoteLoc = ErrorLoc = AtomicBody->getLocStart(); |
| 5773 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
| 5774 | } |
| 5775 | } else { |
| 5776 | ErrorFound = NotAnExpression; |
| 5777 | NoteLoc = ErrorLoc = S->getLocStart(); |
| 5778 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
| 5779 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5780 | if (ErrorFound != NoError && DiagId != 0 && NoteId != 0) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5781 | SemaRef.Diag(ErrorLoc, DiagId) << ErrorRange; |
| 5782 | SemaRef.Diag(NoteLoc, NoteId) << ErrorFound << NoteRange; |
| 5783 | return true; |
| 5784 | } else if (SemaRef.CurContext->isDependentContext()) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5785 | E = X = UpdateExpr = nullptr; |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5786 | if (ErrorFound == NoError && E && X) { |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5787 | // Build an update expression of form 'OpaqueValueExpr(x) binop |
| 5788 | // OpaqueValueExpr(expr)' or 'OpaqueValueExpr(expr) binop |
| 5789 | // OpaqueValueExpr(x)' and then cast it to the type of the 'x' expression. |
| 5790 | auto *OVEX = new (SemaRef.getASTContext()) |
| 5791 | OpaqueValueExpr(X->getExprLoc(), X->getType(), VK_RValue); |
| 5792 | auto *OVEExpr = new (SemaRef.getASTContext()) |
| 5793 | OpaqueValueExpr(E->getExprLoc(), E->getType(), VK_RValue); |
| 5794 | auto Update = |
| 5795 | SemaRef.CreateBuiltinBinOp(OpLoc, Op, IsXLHSInRHSPart ? OVEX : OVEExpr, |
| 5796 | IsXLHSInRHSPart ? OVEExpr : OVEX); |
| 5797 | if (Update.isInvalid()) |
| 5798 | return true; |
| 5799 | Update = SemaRef.PerformImplicitConversion(Update.get(), X->getType(), |
| 5800 | Sema::AA_Casting); |
| 5801 | if (Update.isInvalid()) |
| 5802 | return true; |
| 5803 | UpdateExpr = Update.get(); |
| 5804 | } |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5805 | return ErrorFound != NoError; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5806 | } |
| 5807 | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 5808 | StmtResult Sema::ActOnOpenMPAtomicDirective(ArrayRef<OMPClause *> Clauses, |
| 5809 | Stmt *AStmt, |
| 5810 | SourceLocation StartLoc, |
| 5811 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5812 | if (!AStmt) |
| 5813 | return StmtError(); |
| 5814 | |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5815 | auto CS = cast<CapturedStmt>(AStmt); |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 5816 | // 1.2.2 OpenMP Language Terminology |
| 5817 | // Structured block - An executable statement with a single entry at the |
| 5818 | // top and a single exit at the bottom. |
| 5819 | // The point of exit cannot be a branch out of the structured block. |
| 5820 | // longjmp() and throw() must not violate the entry/exit criteria. |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5821 | OpenMPClauseKind AtomicKind = OMPC_unknown; |
| 5822 | SourceLocation AtomicKindLoc; |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5823 | for (auto *C : Clauses) { |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5824 | if (C->getClauseKind() == OMPC_read || C->getClauseKind() == OMPC_write || |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5825 | C->getClauseKind() == OMPC_update || |
| 5826 | C->getClauseKind() == OMPC_capture) { |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5827 | if (AtomicKind != OMPC_unknown) { |
| 5828 | Diag(C->getLocStart(), diag::err_omp_atomic_several_clauses) |
| 5829 | << SourceRange(C->getLocStart(), C->getLocEnd()); |
| 5830 | Diag(AtomicKindLoc, diag::note_omp_atomic_previous_clause) |
| 5831 | << getOpenMPClauseName(AtomicKind); |
| 5832 | } else { |
| 5833 | AtomicKind = C->getClauseKind(); |
| 5834 | AtomicKindLoc = C->getLocStart(); |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5835 | } |
| 5836 | } |
| 5837 | } |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5838 | |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5839 | auto Body = CS->getCapturedStmt(); |
Alexey Bataev | 10fec57 | 2015-03-11 04:48:56 +0000 | [diff] [blame] | 5840 | if (auto *EWC = dyn_cast<ExprWithCleanups>(Body)) |
| 5841 | Body = EWC->getSubExpr(); |
| 5842 | |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5843 | Expr *X = nullptr; |
| 5844 | Expr *V = nullptr; |
| 5845 | Expr *E = nullptr; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5846 | Expr *UE = nullptr; |
| 5847 | bool IsXLHSInRHSPart = false; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5848 | bool IsPostfixUpdate = false; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5849 | // OpenMP [2.12.6, atomic Construct] |
| 5850 | // In the next expressions: |
| 5851 | // * x and v (as applicable) are both l-value expressions with scalar type. |
| 5852 | // * During the execution of an atomic region, multiple syntactic |
| 5853 | // occurrences of x must designate the same storage location. |
| 5854 | // * Neither of v and expr (as applicable) may access the storage location |
| 5855 | // designated by x. |
| 5856 | // * Neither of x and expr (as applicable) may access the storage location |
| 5857 | // designated by v. |
| 5858 | // * expr is an expression with scalar type. |
| 5859 | // * binop is one of +, *, -, /, &, ^, |, <<, or >>. |
| 5860 | // * binop, binop=, ++, and -- are not overloaded operators. |
| 5861 | // * The expression x binop expr must be numerically equivalent to x binop |
| 5862 | // (expr). This requirement is satisfied if the operators in expr have |
| 5863 | // precedence greater than binop, or by using parentheses around expr or |
| 5864 | // subexpressions of expr. |
| 5865 | // * The expression expr binop x must be numerically equivalent to (expr) |
| 5866 | // binop x. This requirement is satisfied if the operators in expr have |
| 5867 | // precedence equal to or greater than binop, or by using parentheses around |
| 5868 | // expr or subexpressions of expr. |
| 5869 | // * For forms that allow multiple occurrences of x, the number of times |
| 5870 | // that x is evaluated is unspecified. |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5871 | if (AtomicKind == OMPC_read) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5872 | enum { |
| 5873 | NotAnExpression, |
| 5874 | NotAnAssignmentOp, |
| 5875 | NotAScalarType, |
| 5876 | NotAnLValue, |
| 5877 | NoError |
| 5878 | } ErrorFound = NoError; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5879 | SourceLocation ErrorLoc, NoteLoc; |
| 5880 | SourceRange ErrorRange, NoteRange; |
| 5881 | // If clause is read: |
| 5882 | // v = x; |
| 5883 | if (auto AtomicBody = dyn_cast<Expr>(Body)) { |
| 5884 | auto AtomicBinOp = |
| 5885 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 5886 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
| 5887 | X = AtomicBinOp->getRHS()->IgnoreParenImpCasts(); |
| 5888 | V = AtomicBinOp->getLHS()->IgnoreParenImpCasts(); |
| 5889 | if ((X->isInstantiationDependent() || X->getType()->isScalarType()) && |
| 5890 | (V->isInstantiationDependent() || V->getType()->isScalarType())) { |
| 5891 | if (!X->isLValue() || !V->isLValue()) { |
| 5892 | auto NotLValueExpr = X->isLValue() ? V : X; |
| 5893 | ErrorFound = NotAnLValue; |
| 5894 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5895 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5896 | NoteLoc = NotLValueExpr->getExprLoc(); |
| 5897 | NoteRange = NotLValueExpr->getSourceRange(); |
| 5898 | } |
| 5899 | } else if (!X->isInstantiationDependent() || |
| 5900 | !V->isInstantiationDependent()) { |
| 5901 | auto NotScalarExpr = |
| 5902 | (X->isInstantiationDependent() || X->getType()->isScalarType()) |
| 5903 | ? V |
| 5904 | : X; |
| 5905 | ErrorFound = NotAScalarType; |
| 5906 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5907 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5908 | NoteLoc = NotScalarExpr->getExprLoc(); |
| 5909 | NoteRange = NotScalarExpr->getSourceRange(); |
| 5910 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5911 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5912 | ErrorFound = NotAnAssignmentOp; |
| 5913 | ErrorLoc = AtomicBody->getExprLoc(); |
| 5914 | ErrorRange = AtomicBody->getSourceRange(); |
| 5915 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 5916 | : AtomicBody->getExprLoc(); |
| 5917 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 5918 | : AtomicBody->getSourceRange(); |
| 5919 | } |
| 5920 | } else { |
| 5921 | ErrorFound = NotAnExpression; |
| 5922 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 5923 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5924 | } |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5925 | if (ErrorFound != NoError) { |
| 5926 | Diag(ErrorLoc, diag::err_omp_atomic_read_not_expression_statement) |
| 5927 | << ErrorRange; |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5928 | Diag(NoteLoc, diag::note_omp_atomic_read_write) << ErrorFound |
| 5929 | << NoteRange; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5930 | return StmtError(); |
| 5931 | } else if (CurContext->isDependentContext()) |
| 5932 | V = X = nullptr; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5933 | } else if (AtomicKind == OMPC_write) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5934 | enum { |
| 5935 | NotAnExpression, |
| 5936 | NotAnAssignmentOp, |
| 5937 | NotAScalarType, |
| 5938 | NotAnLValue, |
| 5939 | NoError |
| 5940 | } ErrorFound = NoError; |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5941 | SourceLocation ErrorLoc, NoteLoc; |
| 5942 | SourceRange ErrorRange, NoteRange; |
| 5943 | // If clause is write: |
| 5944 | // x = expr; |
| 5945 | if (auto AtomicBody = dyn_cast<Expr>(Body)) { |
| 5946 | auto AtomicBinOp = |
| 5947 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 5948 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
Alexey Bataev | b832926 | 2015-02-27 06:33:30 +0000 | [diff] [blame] | 5949 | X = AtomicBinOp->getLHS(); |
| 5950 | E = AtomicBinOp->getRHS(); |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5951 | if ((X->isInstantiationDependent() || X->getType()->isScalarType()) && |
| 5952 | (E->isInstantiationDependent() || E->getType()->isScalarType())) { |
| 5953 | if (!X->isLValue()) { |
| 5954 | ErrorFound = NotAnLValue; |
| 5955 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5956 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5957 | NoteLoc = X->getExprLoc(); |
| 5958 | NoteRange = X->getSourceRange(); |
| 5959 | } |
| 5960 | } else if (!X->isInstantiationDependent() || |
| 5961 | !E->isInstantiationDependent()) { |
| 5962 | auto NotScalarExpr = |
| 5963 | (X->isInstantiationDependent() || X->getType()->isScalarType()) |
| 5964 | ? E |
| 5965 | : X; |
| 5966 | ErrorFound = NotAScalarType; |
| 5967 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5968 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5969 | NoteLoc = NotScalarExpr->getExprLoc(); |
| 5970 | NoteRange = NotScalarExpr->getSourceRange(); |
| 5971 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5972 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5973 | ErrorFound = NotAnAssignmentOp; |
| 5974 | ErrorLoc = AtomicBody->getExprLoc(); |
| 5975 | ErrorRange = AtomicBody->getSourceRange(); |
| 5976 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 5977 | : AtomicBody->getExprLoc(); |
| 5978 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 5979 | : AtomicBody->getSourceRange(); |
| 5980 | } |
| 5981 | } else { |
| 5982 | ErrorFound = NotAnExpression; |
| 5983 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 5984 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5985 | } |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5986 | if (ErrorFound != NoError) { |
| 5987 | Diag(ErrorLoc, diag::err_omp_atomic_write_not_expression_statement) |
| 5988 | << ErrorRange; |
| 5989 | Diag(NoteLoc, diag::note_omp_atomic_read_write) << ErrorFound |
| 5990 | << NoteRange; |
| 5991 | return StmtError(); |
| 5992 | } else if (CurContext->isDependentContext()) |
| 5993 | E = X = nullptr; |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5994 | } else if (AtomicKind == OMPC_update || AtomicKind == OMPC_unknown) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5995 | // If clause is update: |
| 5996 | // x++; |
| 5997 | // x--; |
| 5998 | // ++x; |
| 5999 | // --x; |
| 6000 | // x binop= expr; |
| 6001 | // x = x binop expr; |
| 6002 | // x = expr binop x; |
| 6003 | OpenMPAtomicUpdateChecker Checker(*this); |
| 6004 | if (Checker.checkStatement( |
| 6005 | Body, (AtomicKind == OMPC_update) |
| 6006 | ? diag::err_omp_atomic_update_not_expression_statement |
| 6007 | : diag::err_omp_atomic_not_expression_statement, |
| 6008 | diag::note_omp_atomic_update)) |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6009 | return StmtError(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6010 | if (!CurContext->isDependentContext()) { |
| 6011 | E = Checker.getExpr(); |
| 6012 | X = Checker.getX(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6013 | UE = Checker.getUpdateExpr(); |
| 6014 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6015 | } |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6016 | } else if (AtomicKind == OMPC_capture) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6017 | enum { |
| 6018 | NotAnAssignmentOp, |
| 6019 | NotACompoundStatement, |
| 6020 | NotTwoSubstatements, |
| 6021 | NotASpecificExpression, |
| 6022 | NoError |
| 6023 | } ErrorFound = NoError; |
| 6024 | SourceLocation ErrorLoc, NoteLoc; |
| 6025 | SourceRange ErrorRange, NoteRange; |
| 6026 | if (auto *AtomicBody = dyn_cast<Expr>(Body)) { |
| 6027 | // If clause is a capture: |
| 6028 | // v = x++; |
| 6029 | // v = x--; |
| 6030 | // v = ++x; |
| 6031 | // v = --x; |
| 6032 | // v = x binop= expr; |
| 6033 | // v = x = x binop expr; |
| 6034 | // v = x = expr binop x; |
| 6035 | auto *AtomicBinOp = |
| 6036 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 6037 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
| 6038 | V = AtomicBinOp->getLHS(); |
| 6039 | Body = AtomicBinOp->getRHS()->IgnoreParenImpCasts(); |
| 6040 | OpenMPAtomicUpdateChecker Checker(*this); |
| 6041 | if (Checker.checkStatement( |
| 6042 | Body, diag::err_omp_atomic_capture_not_expression_statement, |
| 6043 | diag::note_omp_atomic_update)) |
| 6044 | return StmtError(); |
| 6045 | E = Checker.getExpr(); |
| 6046 | X = Checker.getX(); |
| 6047 | UE = Checker.getUpdateExpr(); |
| 6048 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
| 6049 | IsPostfixUpdate = Checker.isPostfixUpdate(); |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 6050 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6051 | ErrorLoc = AtomicBody->getExprLoc(); |
| 6052 | ErrorRange = AtomicBody->getSourceRange(); |
| 6053 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 6054 | : AtomicBody->getExprLoc(); |
| 6055 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 6056 | : AtomicBody->getSourceRange(); |
| 6057 | ErrorFound = NotAnAssignmentOp; |
| 6058 | } |
| 6059 | if (ErrorFound != NoError) { |
| 6060 | Diag(ErrorLoc, diag::err_omp_atomic_capture_not_expression_statement) |
| 6061 | << ErrorRange; |
| 6062 | Diag(NoteLoc, diag::note_omp_atomic_capture) << ErrorFound << NoteRange; |
| 6063 | return StmtError(); |
| 6064 | } else if (CurContext->isDependentContext()) { |
| 6065 | UE = V = E = X = nullptr; |
| 6066 | } |
| 6067 | } else { |
| 6068 | // If clause is a capture: |
| 6069 | // { v = x; x = expr; } |
| 6070 | // { v = x; x++; } |
| 6071 | // { v = x; x--; } |
| 6072 | // { v = x; ++x; } |
| 6073 | // { v = x; --x; } |
| 6074 | // { v = x; x binop= expr; } |
| 6075 | // { v = x; x = x binop expr; } |
| 6076 | // { v = x; x = expr binop x; } |
| 6077 | // { x++; v = x; } |
| 6078 | // { x--; v = x; } |
| 6079 | // { ++x; v = x; } |
| 6080 | // { --x; v = x; } |
| 6081 | // { x binop= expr; v = x; } |
| 6082 | // { x = x binop expr; v = x; } |
| 6083 | // { x = expr binop x; v = x; } |
| 6084 | if (auto *CS = dyn_cast<CompoundStmt>(Body)) { |
| 6085 | // Check that this is { expr1; expr2; } |
| 6086 | if (CS->size() == 2) { |
| 6087 | auto *First = CS->body_front(); |
| 6088 | auto *Second = CS->body_back(); |
| 6089 | if (auto *EWC = dyn_cast<ExprWithCleanups>(First)) |
| 6090 | First = EWC->getSubExpr()->IgnoreParenImpCasts(); |
| 6091 | if (auto *EWC = dyn_cast<ExprWithCleanups>(Second)) |
| 6092 | Second = EWC->getSubExpr()->IgnoreParenImpCasts(); |
| 6093 | // Need to find what subexpression is 'v' and what is 'x'. |
| 6094 | OpenMPAtomicUpdateChecker Checker(*this); |
| 6095 | bool IsUpdateExprFound = !Checker.checkStatement(Second); |
| 6096 | BinaryOperator *BinOp = nullptr; |
| 6097 | if (IsUpdateExprFound) { |
| 6098 | BinOp = dyn_cast<BinaryOperator>(First); |
| 6099 | IsUpdateExprFound = BinOp && BinOp->getOpcode() == BO_Assign; |
| 6100 | } |
| 6101 | if (IsUpdateExprFound && !CurContext->isDependentContext()) { |
| 6102 | // { v = x; x++; } |
| 6103 | // { v = x; x--; } |
| 6104 | // { v = x; ++x; } |
| 6105 | // { v = x; --x; } |
| 6106 | // { v = x; x binop= expr; } |
| 6107 | // { v = x; x = x binop expr; } |
| 6108 | // { v = x; x = expr binop x; } |
| 6109 | // Check that the first expression has form v = x. |
| 6110 | auto *PossibleX = BinOp->getRHS()->IgnoreParenImpCasts(); |
| 6111 | llvm::FoldingSetNodeID XId, PossibleXId; |
| 6112 | Checker.getX()->Profile(XId, Context, /*Canonical=*/true); |
| 6113 | PossibleX->Profile(PossibleXId, Context, /*Canonical=*/true); |
| 6114 | IsUpdateExprFound = XId == PossibleXId; |
| 6115 | if (IsUpdateExprFound) { |
| 6116 | V = BinOp->getLHS(); |
| 6117 | X = Checker.getX(); |
| 6118 | E = Checker.getExpr(); |
| 6119 | UE = Checker.getUpdateExpr(); |
| 6120 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 6121 | IsPostfixUpdate = true; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6122 | } |
| 6123 | } |
| 6124 | if (!IsUpdateExprFound) { |
| 6125 | IsUpdateExprFound = !Checker.checkStatement(First); |
| 6126 | BinOp = nullptr; |
| 6127 | if (IsUpdateExprFound) { |
| 6128 | BinOp = dyn_cast<BinaryOperator>(Second); |
| 6129 | IsUpdateExprFound = BinOp && BinOp->getOpcode() == BO_Assign; |
| 6130 | } |
| 6131 | if (IsUpdateExprFound && !CurContext->isDependentContext()) { |
| 6132 | // { x++; v = x; } |
| 6133 | // { x--; v = x; } |
| 6134 | // { ++x; v = x; } |
| 6135 | // { --x; v = x; } |
| 6136 | // { x binop= expr; v = x; } |
| 6137 | // { x = x binop expr; v = x; } |
| 6138 | // { x = expr binop x; v = x; } |
| 6139 | // Check that the second expression has form v = x. |
| 6140 | auto *PossibleX = BinOp->getRHS()->IgnoreParenImpCasts(); |
| 6141 | llvm::FoldingSetNodeID XId, PossibleXId; |
| 6142 | Checker.getX()->Profile(XId, Context, /*Canonical=*/true); |
| 6143 | PossibleX->Profile(PossibleXId, Context, /*Canonical=*/true); |
| 6144 | IsUpdateExprFound = XId == PossibleXId; |
| 6145 | if (IsUpdateExprFound) { |
| 6146 | V = BinOp->getLHS(); |
| 6147 | X = Checker.getX(); |
| 6148 | E = Checker.getExpr(); |
| 6149 | UE = Checker.getUpdateExpr(); |
| 6150 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 6151 | IsPostfixUpdate = false; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6152 | } |
| 6153 | } |
| 6154 | } |
| 6155 | if (!IsUpdateExprFound) { |
| 6156 | // { v = x; x = expr; } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 6157 | auto *FirstExpr = dyn_cast<Expr>(First); |
| 6158 | auto *SecondExpr = dyn_cast<Expr>(Second); |
| 6159 | if (!FirstExpr || !SecondExpr || |
| 6160 | !(FirstExpr->isInstantiationDependent() || |
| 6161 | SecondExpr->isInstantiationDependent())) { |
| 6162 | auto *FirstBinOp = dyn_cast<BinaryOperator>(First); |
| 6163 | if (!FirstBinOp || FirstBinOp->getOpcode() != BO_Assign) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6164 | ErrorFound = NotAnAssignmentOp; |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 6165 | NoteLoc = ErrorLoc = FirstBinOp ? FirstBinOp->getOperatorLoc() |
| 6166 | : First->getLocStart(); |
| 6167 | NoteRange = ErrorRange = FirstBinOp |
| 6168 | ? FirstBinOp->getSourceRange() |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6169 | : SourceRange(ErrorLoc, ErrorLoc); |
| 6170 | } else { |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 6171 | auto *SecondBinOp = dyn_cast<BinaryOperator>(Second); |
| 6172 | if (!SecondBinOp || SecondBinOp->getOpcode() != BO_Assign) { |
| 6173 | ErrorFound = NotAnAssignmentOp; |
| 6174 | NoteLoc = ErrorLoc = SecondBinOp |
| 6175 | ? SecondBinOp->getOperatorLoc() |
| 6176 | : Second->getLocStart(); |
| 6177 | NoteRange = ErrorRange = |
| 6178 | SecondBinOp ? SecondBinOp->getSourceRange() |
| 6179 | : SourceRange(ErrorLoc, ErrorLoc); |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6180 | } else { |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 6181 | auto *PossibleXRHSInFirst = |
| 6182 | FirstBinOp->getRHS()->IgnoreParenImpCasts(); |
| 6183 | auto *PossibleXLHSInSecond = |
| 6184 | SecondBinOp->getLHS()->IgnoreParenImpCasts(); |
| 6185 | llvm::FoldingSetNodeID X1Id, X2Id; |
| 6186 | PossibleXRHSInFirst->Profile(X1Id, Context, |
| 6187 | /*Canonical=*/true); |
| 6188 | PossibleXLHSInSecond->Profile(X2Id, Context, |
| 6189 | /*Canonical=*/true); |
| 6190 | IsUpdateExprFound = X1Id == X2Id; |
| 6191 | if (IsUpdateExprFound) { |
| 6192 | V = FirstBinOp->getLHS(); |
| 6193 | X = SecondBinOp->getLHS(); |
| 6194 | E = SecondBinOp->getRHS(); |
| 6195 | UE = nullptr; |
| 6196 | IsXLHSInRHSPart = false; |
| 6197 | IsPostfixUpdate = true; |
| 6198 | } else { |
| 6199 | ErrorFound = NotASpecificExpression; |
| 6200 | ErrorLoc = FirstBinOp->getExprLoc(); |
| 6201 | ErrorRange = FirstBinOp->getSourceRange(); |
| 6202 | NoteLoc = SecondBinOp->getLHS()->getExprLoc(); |
| 6203 | NoteRange = SecondBinOp->getRHS()->getSourceRange(); |
| 6204 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6205 | } |
| 6206 | } |
| 6207 | } |
| 6208 | } |
| 6209 | } else { |
| 6210 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 6211 | NoteRange = ErrorRange = |
| 6212 | SourceRange(Body->getLocStart(), Body->getLocStart()); |
| 6213 | ErrorFound = NotTwoSubstatements; |
| 6214 | } |
| 6215 | } else { |
| 6216 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 6217 | NoteRange = ErrorRange = |
| 6218 | SourceRange(Body->getLocStart(), Body->getLocStart()); |
| 6219 | ErrorFound = NotACompoundStatement; |
| 6220 | } |
| 6221 | if (ErrorFound != NoError) { |
| 6222 | Diag(ErrorLoc, diag::err_omp_atomic_capture_not_compound_statement) |
| 6223 | << ErrorRange; |
| 6224 | Diag(NoteLoc, diag::note_omp_atomic_capture) << ErrorFound << NoteRange; |
| 6225 | return StmtError(); |
| 6226 | } else if (CurContext->isDependentContext()) { |
| 6227 | UE = V = E = X = nullptr; |
| 6228 | } |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6229 | } |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6230 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 6231 | |
| 6232 | getCurFunction()->setHasBranchProtectedScope(); |
| 6233 | |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 6234 | return OMPAtomicDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6235 | X, V, E, UE, IsXLHSInRHSPart, |
| 6236 | IsPostfixUpdate); |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 6237 | } |
| 6238 | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 6239 | StmtResult Sema::ActOnOpenMPTargetDirective(ArrayRef<OMPClause *> Clauses, |
| 6240 | Stmt *AStmt, |
| 6241 | SourceLocation StartLoc, |
| 6242 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6243 | if (!AStmt) |
| 6244 | return StmtError(); |
| 6245 | |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 6246 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6247 | // 1.2.2 OpenMP Language Terminology |
| 6248 | // Structured block - An executable statement with a single entry at the |
| 6249 | // top and a single exit at the bottom. |
| 6250 | // The point of exit cannot be a branch out of the structured block. |
| 6251 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6252 | CS->getCapturedDecl()->setNothrow(); |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 6253 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 6254 | // OpenMP [2.16, Nesting of Regions] |
| 6255 | // If specified, a teams construct must be contained within a target |
| 6256 | // construct. That target construct must contain no statements or directives |
| 6257 | // outside of the teams construct. |
| 6258 | if (DSAStack->hasInnerTeamsRegion()) { |
| 6259 | auto S = AStmt->IgnoreContainers(/*IgnoreCaptured*/ true); |
| 6260 | bool OMPTeamsFound = true; |
| 6261 | if (auto *CS = dyn_cast<CompoundStmt>(S)) { |
| 6262 | auto I = CS->body_begin(); |
| 6263 | while (I != CS->body_end()) { |
| 6264 | auto OED = dyn_cast<OMPExecutableDirective>(*I); |
| 6265 | if (!OED || !isOpenMPTeamsDirective(OED->getDirectiveKind())) { |
| 6266 | OMPTeamsFound = false; |
| 6267 | break; |
| 6268 | } |
| 6269 | ++I; |
| 6270 | } |
| 6271 | assert(I != CS->body_end() && "Not found statement"); |
| 6272 | S = *I; |
| 6273 | } |
| 6274 | if (!OMPTeamsFound) { |
| 6275 | Diag(StartLoc, diag::err_omp_target_contains_not_only_teams); |
| 6276 | Diag(DSAStack->getInnerTeamsRegionLoc(), |
| 6277 | diag::note_omp_nested_teams_construct_here); |
| 6278 | Diag(S->getLocStart(), diag::note_omp_nested_statement_here) |
| 6279 | << isa<OMPExecutableDirective>(S); |
| 6280 | return StmtError(); |
| 6281 | } |
| 6282 | } |
| 6283 | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 6284 | getCurFunction()->setHasBranchProtectedScope(); |
| 6285 | |
| 6286 | return OMPTargetDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 6287 | } |
| 6288 | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 6289 | StmtResult |
| 6290 | Sema::ActOnOpenMPTargetParallelDirective(ArrayRef<OMPClause *> Clauses, |
| 6291 | Stmt *AStmt, SourceLocation StartLoc, |
| 6292 | SourceLocation EndLoc) { |
| 6293 | if (!AStmt) |
| 6294 | return StmtError(); |
| 6295 | |
| 6296 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6297 | // 1.2.2 OpenMP Language Terminology |
| 6298 | // Structured block - An executable statement with a single entry at the |
| 6299 | // top and a single exit at the bottom. |
| 6300 | // The point of exit cannot be a branch out of the structured block. |
| 6301 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6302 | CS->getCapturedDecl()->setNothrow(); |
| 6303 | |
| 6304 | getCurFunction()->setHasBranchProtectedScope(); |
| 6305 | |
| 6306 | return OMPTargetParallelDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 6307 | AStmt); |
| 6308 | } |
| 6309 | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 6310 | StmtResult Sema::ActOnOpenMPTargetParallelForDirective( |
| 6311 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6312 | SourceLocation EndLoc, |
| 6313 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 6314 | if (!AStmt) |
| 6315 | return StmtError(); |
| 6316 | |
| 6317 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6318 | // 1.2.2 OpenMP Language Terminology |
| 6319 | // Structured block - An executable statement with a single entry at the |
| 6320 | // top and a single exit at the bottom. |
| 6321 | // The point of exit cannot be a branch out of the structured block. |
| 6322 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6323 | CS->getCapturedDecl()->setNothrow(); |
| 6324 | |
| 6325 | OMPLoopDirective::HelperExprs B; |
| 6326 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 6327 | // define the nested loops number. |
| 6328 | unsigned NestedLoopCount = |
| 6329 | CheckOpenMPLoop(OMPD_target_parallel_for, getCollapseNumberExpr(Clauses), |
| 6330 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 6331 | VarsWithImplicitDSA, B); |
| 6332 | if (NestedLoopCount == 0) |
| 6333 | return StmtError(); |
| 6334 | |
| 6335 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6336 | "omp target parallel for loop exprs were not built"); |
| 6337 | |
| 6338 | if (!CurContext->isDependentContext()) { |
| 6339 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 6340 | for (auto C : Clauses) { |
| 6341 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 6342 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 6343 | B.NumIterations, *this, CurScope, |
| 6344 | DSAStack)) |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 6345 | return StmtError(); |
| 6346 | } |
| 6347 | } |
| 6348 | |
| 6349 | getCurFunction()->setHasBranchProtectedScope(); |
| 6350 | return OMPTargetParallelForDirective::Create(Context, StartLoc, EndLoc, |
| 6351 | NestedLoopCount, Clauses, AStmt, |
| 6352 | B, DSAStack->isCancelRegion()); |
| 6353 | } |
| 6354 | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 6355 | /// \brief Check for existence of a map clause in the list of clauses. |
| 6356 | static bool HasMapClause(ArrayRef<OMPClause *> Clauses) { |
| 6357 | for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end(); |
| 6358 | I != E; ++I) { |
| 6359 | if (*I != nullptr && (*I)->getClauseKind() == OMPC_map) { |
| 6360 | return true; |
| 6361 | } |
| 6362 | } |
| 6363 | |
| 6364 | return false; |
| 6365 | } |
| 6366 | |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 6367 | StmtResult Sema::ActOnOpenMPTargetDataDirective(ArrayRef<OMPClause *> Clauses, |
| 6368 | Stmt *AStmt, |
| 6369 | SourceLocation StartLoc, |
| 6370 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6371 | if (!AStmt) |
| 6372 | return StmtError(); |
| 6373 | |
| 6374 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 6375 | |
Arpith Chacko Jacob | 46a04bb | 2016-01-21 19:57:55 +0000 | [diff] [blame] | 6376 | // OpenMP [2.10.1, Restrictions, p. 97] |
| 6377 | // At least one map clause must appear on the directive. |
| 6378 | if (!HasMapClause(Clauses)) { |
| 6379 | Diag(StartLoc, diag::err_omp_no_map_for_directive) << |
| 6380 | getOpenMPDirectiveName(OMPD_target_data); |
| 6381 | return StmtError(); |
| 6382 | } |
| 6383 | |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 6384 | getCurFunction()->setHasBranchProtectedScope(); |
| 6385 | |
| 6386 | return OMPTargetDataDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 6387 | AStmt); |
| 6388 | } |
| 6389 | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 6390 | StmtResult |
| 6391 | Sema::ActOnOpenMPTargetEnterDataDirective(ArrayRef<OMPClause *> Clauses, |
| 6392 | SourceLocation StartLoc, |
| 6393 | SourceLocation EndLoc) { |
| 6394 | // OpenMP [2.10.2, Restrictions, p. 99] |
| 6395 | // At least one map clause must appear on the directive. |
| 6396 | if (!HasMapClause(Clauses)) { |
| 6397 | Diag(StartLoc, diag::err_omp_no_map_for_directive) |
| 6398 | << getOpenMPDirectiveName(OMPD_target_enter_data); |
| 6399 | return StmtError(); |
| 6400 | } |
| 6401 | |
| 6402 | return OMPTargetEnterDataDirective::Create(Context, StartLoc, EndLoc, |
| 6403 | Clauses); |
| 6404 | } |
| 6405 | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 6406 | StmtResult |
| 6407 | Sema::ActOnOpenMPTargetExitDataDirective(ArrayRef<OMPClause *> Clauses, |
| 6408 | SourceLocation StartLoc, |
| 6409 | SourceLocation EndLoc) { |
| 6410 | // OpenMP [2.10.3, Restrictions, p. 102] |
| 6411 | // At least one map clause must appear on the directive. |
| 6412 | if (!HasMapClause(Clauses)) { |
| 6413 | Diag(StartLoc, diag::err_omp_no_map_for_directive) |
| 6414 | << getOpenMPDirectiveName(OMPD_target_exit_data); |
| 6415 | return StmtError(); |
| 6416 | } |
| 6417 | |
| 6418 | return OMPTargetExitDataDirective::Create(Context, StartLoc, EndLoc, Clauses); |
| 6419 | } |
| 6420 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 6421 | StmtResult Sema::ActOnOpenMPTeamsDirective(ArrayRef<OMPClause *> Clauses, |
| 6422 | Stmt *AStmt, SourceLocation StartLoc, |
| 6423 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6424 | if (!AStmt) |
| 6425 | return StmtError(); |
| 6426 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 6427 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6428 | // 1.2.2 OpenMP Language Terminology |
| 6429 | // Structured block - An executable statement with a single entry at the |
| 6430 | // top and a single exit at the bottom. |
| 6431 | // The point of exit cannot be a branch out of the structured block. |
| 6432 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6433 | CS->getCapturedDecl()->setNothrow(); |
| 6434 | |
| 6435 | getCurFunction()->setHasBranchProtectedScope(); |
| 6436 | |
| 6437 | return OMPTeamsDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 6438 | } |
| 6439 | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 6440 | StmtResult |
| 6441 | Sema::ActOnOpenMPCancellationPointDirective(SourceLocation StartLoc, |
| 6442 | SourceLocation EndLoc, |
| 6443 | OpenMPDirectiveKind CancelRegion) { |
| 6444 | if (CancelRegion != OMPD_parallel && CancelRegion != OMPD_for && |
| 6445 | CancelRegion != OMPD_sections && CancelRegion != OMPD_taskgroup) { |
| 6446 | Diag(StartLoc, diag::err_omp_wrong_cancel_region) |
| 6447 | << getOpenMPDirectiveName(CancelRegion); |
| 6448 | return StmtError(); |
| 6449 | } |
| 6450 | if (DSAStack->isParentNowaitRegion()) { |
| 6451 | Diag(StartLoc, diag::err_omp_parent_cancel_region_nowait) << 0; |
| 6452 | return StmtError(); |
| 6453 | } |
| 6454 | if (DSAStack->isParentOrderedRegion()) { |
| 6455 | Diag(StartLoc, diag::err_omp_parent_cancel_region_ordered) << 0; |
| 6456 | return StmtError(); |
| 6457 | } |
| 6458 | return OMPCancellationPointDirective::Create(Context, StartLoc, EndLoc, |
| 6459 | CancelRegion); |
| 6460 | } |
| 6461 | |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 6462 | StmtResult Sema::ActOnOpenMPCancelDirective(ArrayRef<OMPClause *> Clauses, |
| 6463 | SourceLocation StartLoc, |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 6464 | SourceLocation EndLoc, |
| 6465 | OpenMPDirectiveKind CancelRegion) { |
| 6466 | if (CancelRegion != OMPD_parallel && CancelRegion != OMPD_for && |
| 6467 | CancelRegion != OMPD_sections && CancelRegion != OMPD_taskgroup) { |
| 6468 | Diag(StartLoc, diag::err_omp_wrong_cancel_region) |
| 6469 | << getOpenMPDirectiveName(CancelRegion); |
| 6470 | return StmtError(); |
| 6471 | } |
| 6472 | if (DSAStack->isParentNowaitRegion()) { |
| 6473 | Diag(StartLoc, diag::err_omp_parent_cancel_region_nowait) << 1; |
| 6474 | return StmtError(); |
| 6475 | } |
| 6476 | if (DSAStack->isParentOrderedRegion()) { |
| 6477 | Diag(StartLoc, diag::err_omp_parent_cancel_region_ordered) << 1; |
| 6478 | return StmtError(); |
| 6479 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 6480 | DSAStack->setParentCancelRegion(/*Cancel=*/true); |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 6481 | return OMPCancelDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 6482 | CancelRegion); |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 6483 | } |
| 6484 | |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6485 | static bool checkGrainsizeNumTasksClauses(Sema &S, |
| 6486 | ArrayRef<OMPClause *> Clauses) { |
| 6487 | OMPClause *PrevClause = nullptr; |
| 6488 | bool ErrorFound = false; |
| 6489 | for (auto *C : Clauses) { |
| 6490 | if (C->getClauseKind() == OMPC_grainsize || |
| 6491 | C->getClauseKind() == OMPC_num_tasks) { |
| 6492 | if (!PrevClause) |
| 6493 | PrevClause = C; |
| 6494 | else if (PrevClause->getClauseKind() != C->getClauseKind()) { |
| 6495 | S.Diag(C->getLocStart(), |
| 6496 | diag::err_omp_grainsize_num_tasks_mutually_exclusive) |
| 6497 | << getOpenMPClauseName(C->getClauseKind()) |
| 6498 | << getOpenMPClauseName(PrevClause->getClauseKind()); |
| 6499 | S.Diag(PrevClause->getLocStart(), |
| 6500 | diag::note_omp_previous_grainsize_num_tasks) |
| 6501 | << getOpenMPClauseName(PrevClause->getClauseKind()); |
| 6502 | ErrorFound = true; |
| 6503 | } |
| 6504 | } |
| 6505 | } |
| 6506 | return ErrorFound; |
| 6507 | } |
| 6508 | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 6509 | StmtResult Sema::ActOnOpenMPTaskLoopDirective( |
| 6510 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6511 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 6512 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 6513 | if (!AStmt) |
| 6514 | return StmtError(); |
| 6515 | |
| 6516 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 6517 | OMPLoopDirective::HelperExprs B; |
| 6518 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 6519 | // define the nested loops number. |
| 6520 | unsigned NestedLoopCount = |
| 6521 | CheckOpenMPLoop(OMPD_taskloop, getCollapseNumberExpr(Clauses), |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 6522 | /*OrderedLoopCountExpr=*/nullptr, AStmt, *this, *DSAStack, |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 6523 | VarsWithImplicitDSA, B); |
| 6524 | if (NestedLoopCount == 0) |
| 6525 | return StmtError(); |
| 6526 | |
| 6527 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6528 | "omp for loop exprs were not built"); |
| 6529 | |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6530 | // OpenMP, [2.9.2 taskloop Construct, Restrictions] |
| 6531 | // The grainsize clause and num_tasks clause are mutually exclusive and may |
| 6532 | // not appear on the same taskloop directive. |
| 6533 | if (checkGrainsizeNumTasksClauses(*this, Clauses)) |
| 6534 | return StmtError(); |
| 6535 | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 6536 | getCurFunction()->setHasBranchProtectedScope(); |
| 6537 | return OMPTaskLoopDirective::Create(Context, StartLoc, EndLoc, |
| 6538 | NestedLoopCount, Clauses, AStmt, B); |
| 6539 | } |
| 6540 | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 6541 | StmtResult Sema::ActOnOpenMPTaskLoopSimdDirective( |
| 6542 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6543 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 6544 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 6545 | if (!AStmt) |
| 6546 | return StmtError(); |
| 6547 | |
| 6548 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 6549 | OMPLoopDirective::HelperExprs B; |
| 6550 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 6551 | // define the nested loops number. |
| 6552 | unsigned NestedLoopCount = |
| 6553 | CheckOpenMPLoop(OMPD_taskloop_simd, getCollapseNumberExpr(Clauses), |
| 6554 | /*OrderedLoopCountExpr=*/nullptr, AStmt, *this, *DSAStack, |
| 6555 | VarsWithImplicitDSA, B); |
| 6556 | if (NestedLoopCount == 0) |
| 6557 | return StmtError(); |
| 6558 | |
| 6559 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6560 | "omp for loop exprs were not built"); |
| 6561 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 6562 | if (!CurContext->isDependentContext()) { |
| 6563 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 6564 | for (auto C : Clauses) { |
| 6565 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 6566 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 6567 | B.NumIterations, *this, CurScope, |
| 6568 | DSAStack)) |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 6569 | return StmtError(); |
| 6570 | } |
| 6571 | } |
| 6572 | |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6573 | // OpenMP, [2.9.2 taskloop Construct, Restrictions] |
| 6574 | // The grainsize clause and num_tasks clause are mutually exclusive and may |
| 6575 | // not appear on the same taskloop directive. |
| 6576 | if (checkGrainsizeNumTasksClauses(*this, Clauses)) |
| 6577 | return StmtError(); |
| 6578 | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 6579 | getCurFunction()->setHasBranchProtectedScope(); |
| 6580 | return OMPTaskLoopSimdDirective::Create(Context, StartLoc, EndLoc, |
| 6581 | NestedLoopCount, Clauses, AStmt, B); |
| 6582 | } |
| 6583 | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 6584 | StmtResult Sema::ActOnOpenMPDistributeDirective( |
| 6585 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6586 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 6587 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 6588 | if (!AStmt) |
| 6589 | return StmtError(); |
| 6590 | |
| 6591 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 6592 | OMPLoopDirective::HelperExprs B; |
| 6593 | // In presence of clause 'collapse' with number of loops, it will |
| 6594 | // define the nested loops number. |
| 6595 | unsigned NestedLoopCount = |
| 6596 | CheckOpenMPLoop(OMPD_distribute, getCollapseNumberExpr(Clauses), |
| 6597 | nullptr /*ordered not a clause on distribute*/, AStmt, |
| 6598 | *this, *DSAStack, VarsWithImplicitDSA, B); |
| 6599 | if (NestedLoopCount == 0) |
| 6600 | return StmtError(); |
| 6601 | |
| 6602 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6603 | "omp for loop exprs were not built"); |
| 6604 | |
| 6605 | getCurFunction()->setHasBranchProtectedScope(); |
| 6606 | return OMPDistributeDirective::Create(Context, StartLoc, EndLoc, |
| 6607 | NestedLoopCount, Clauses, AStmt, B); |
| 6608 | } |
| 6609 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6610 | OMPClause *Sema::ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, Expr *Expr, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6611 | SourceLocation StartLoc, |
| 6612 | SourceLocation LParenLoc, |
| 6613 | SourceLocation EndLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6614 | OMPClause *Res = nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6615 | switch (Kind) { |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 6616 | case OMPC_final: |
| 6617 | Res = ActOnOpenMPFinalClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6618 | break; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6619 | case OMPC_num_threads: |
| 6620 | Res = ActOnOpenMPNumThreadsClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6621 | break; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6622 | case OMPC_safelen: |
| 6623 | Res = ActOnOpenMPSafelenClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6624 | break; |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 6625 | case OMPC_simdlen: |
| 6626 | Res = ActOnOpenMPSimdlenClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6627 | break; |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6628 | case OMPC_collapse: |
| 6629 | Res = ActOnOpenMPCollapseClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6630 | break; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 6631 | case OMPC_ordered: |
| 6632 | Res = ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Expr); |
| 6633 | break; |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 6634 | case OMPC_device: |
| 6635 | Res = ActOnOpenMPDeviceClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6636 | break; |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 6637 | case OMPC_num_teams: |
| 6638 | Res = ActOnOpenMPNumTeamsClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6639 | break; |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6640 | case OMPC_thread_limit: |
| 6641 | Res = ActOnOpenMPThreadLimitClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6642 | break; |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6643 | case OMPC_priority: |
| 6644 | Res = ActOnOpenMPPriorityClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6645 | break; |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 6646 | case OMPC_grainsize: |
| 6647 | Res = ActOnOpenMPGrainsizeClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6648 | break; |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6649 | case OMPC_num_tasks: |
| 6650 | Res = ActOnOpenMPNumTasksClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6651 | break; |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 6652 | case OMPC_hint: |
| 6653 | Res = ActOnOpenMPHintClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6654 | break; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6655 | case OMPC_if: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6656 | case OMPC_default: |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6657 | case OMPC_proc_bind: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6658 | case OMPC_schedule: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6659 | case OMPC_private: |
| 6660 | case OMPC_firstprivate: |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6661 | case OMPC_lastprivate: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6662 | case OMPC_shared: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6663 | case OMPC_reduction: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6664 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 6665 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6666 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6667 | case OMPC_copyprivate: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6668 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 6669 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 6670 | case OMPC_mergeable: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6671 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 6672 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6673 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6674 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6675 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6676 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 6677 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6678 | case OMPC_depend: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6679 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6680 | case OMPC_simd: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 6681 | case OMPC_map: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 6682 | case OMPC_nogroup: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 6683 | case OMPC_dist_schedule: |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 6684 | case OMPC_defaultmap: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6685 | case OMPC_unknown: |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 6686 | case OMPC_uniform: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6687 | llvm_unreachable("Clause is not allowed."); |
| 6688 | } |
| 6689 | return Res; |
| 6690 | } |
| 6691 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6692 | OMPClause *Sema::ActOnOpenMPIfClause(OpenMPDirectiveKind NameModifier, |
| 6693 | Expr *Condition, SourceLocation StartLoc, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6694 | SourceLocation LParenLoc, |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6695 | SourceLocation NameModifierLoc, |
| 6696 | SourceLocation ColonLoc, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6697 | SourceLocation EndLoc) { |
| 6698 | Expr *ValExpr = Condition; |
| 6699 | if (!Condition->isValueDependent() && !Condition->isTypeDependent() && |
| 6700 | !Condition->isInstantiationDependent() && |
| 6701 | !Condition->containsUnexpandedParameterPack()) { |
| 6702 | ExprResult Val = ActOnBooleanCondition(DSAStack->getCurScope(), |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6703 | Condition->getExprLoc(), Condition); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6704 | if (Val.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6705 | return nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6706 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6707 | ValExpr = Val.get(); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6708 | } |
| 6709 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6710 | return new (Context) OMPIfClause(NameModifier, ValExpr, StartLoc, LParenLoc, |
| 6711 | NameModifierLoc, ColonLoc, EndLoc); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6712 | } |
| 6713 | |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 6714 | OMPClause *Sema::ActOnOpenMPFinalClause(Expr *Condition, |
| 6715 | SourceLocation StartLoc, |
| 6716 | SourceLocation LParenLoc, |
| 6717 | SourceLocation EndLoc) { |
| 6718 | Expr *ValExpr = Condition; |
| 6719 | if (!Condition->isValueDependent() && !Condition->isTypeDependent() && |
| 6720 | !Condition->isInstantiationDependent() && |
| 6721 | !Condition->containsUnexpandedParameterPack()) { |
| 6722 | ExprResult Val = ActOnBooleanCondition(DSAStack->getCurScope(), |
| 6723 | Condition->getExprLoc(), Condition); |
| 6724 | if (Val.isInvalid()) |
| 6725 | return nullptr; |
| 6726 | |
| 6727 | ValExpr = Val.get(); |
| 6728 | } |
| 6729 | |
| 6730 | return new (Context) OMPFinalClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 6731 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 6732 | ExprResult Sema::PerformOpenMPImplicitIntegerConversion(SourceLocation Loc, |
| 6733 | Expr *Op) { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6734 | if (!Op) |
| 6735 | return ExprError(); |
| 6736 | |
| 6737 | class IntConvertDiagnoser : public ICEConvertDiagnoser { |
| 6738 | public: |
| 6739 | IntConvertDiagnoser() |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6740 | : ICEConvertDiagnoser(/*AllowScopedEnumerations*/ false, false, true) {} |
Craig Topper | e14c0f8 | 2014-03-12 04:55:44 +0000 | [diff] [blame] | 6741 | SemaDiagnosticBuilder diagnoseNotInt(Sema &S, SourceLocation Loc, |
| 6742 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6743 | return S.Diag(Loc, diag::err_omp_not_integral) << T; |
| 6744 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6745 | SemaDiagnosticBuilder diagnoseIncomplete(Sema &S, SourceLocation Loc, |
| 6746 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6747 | return S.Diag(Loc, diag::err_omp_incomplete_type) << T; |
| 6748 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6749 | SemaDiagnosticBuilder diagnoseExplicitConv(Sema &S, SourceLocation Loc, |
| 6750 | QualType T, |
| 6751 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6752 | return S.Diag(Loc, diag::err_omp_explicit_conversion) << T << ConvTy; |
| 6753 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6754 | SemaDiagnosticBuilder noteExplicitConv(Sema &S, CXXConversionDecl *Conv, |
| 6755 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6756 | return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6757 | << ConvTy->isEnumeralType() << ConvTy; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6758 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6759 | SemaDiagnosticBuilder diagnoseAmbiguous(Sema &S, SourceLocation Loc, |
| 6760 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6761 | return S.Diag(Loc, diag::err_omp_ambiguous_conversion) << T; |
| 6762 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6763 | SemaDiagnosticBuilder noteAmbiguous(Sema &S, CXXConversionDecl *Conv, |
| 6764 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6765 | return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6766 | << ConvTy->isEnumeralType() << ConvTy; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6767 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6768 | SemaDiagnosticBuilder diagnoseConversion(Sema &, SourceLocation, QualType, |
| 6769 | QualType) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6770 | llvm_unreachable("conversion functions are permitted"); |
| 6771 | } |
| 6772 | } ConvertDiagnoser; |
| 6773 | return PerformContextualImplicitConversion(Loc, Op, ConvertDiagnoser); |
| 6774 | } |
| 6775 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6776 | static bool IsNonNegativeIntegerValue(Expr *&ValExpr, Sema &SemaRef, |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6777 | OpenMPClauseKind CKind, |
| 6778 | bool StrictlyPositive) { |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6779 | if (!ValExpr->isTypeDependent() && !ValExpr->isValueDependent() && |
| 6780 | !ValExpr->isInstantiationDependent()) { |
| 6781 | SourceLocation Loc = ValExpr->getExprLoc(); |
| 6782 | ExprResult Value = |
| 6783 | SemaRef.PerformOpenMPImplicitIntegerConversion(Loc, ValExpr); |
| 6784 | if (Value.isInvalid()) |
| 6785 | return false; |
| 6786 | |
| 6787 | ValExpr = Value.get(); |
| 6788 | // The expression must evaluate to a non-negative integer value. |
| 6789 | llvm::APSInt Result; |
| 6790 | if (ValExpr->isIntegerConstantExpr(Result, SemaRef.Context) && |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6791 | Result.isSigned() && |
| 6792 | !((!StrictlyPositive && Result.isNonNegative()) || |
| 6793 | (StrictlyPositive && Result.isStrictlyPositive()))) { |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6794 | SemaRef.Diag(Loc, diag::err_omp_negative_expression_in_clause) |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6795 | << getOpenMPClauseName(CKind) << (StrictlyPositive ? 1 : 0) |
| 6796 | << ValExpr->getSourceRange(); |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6797 | return false; |
| 6798 | } |
| 6799 | } |
| 6800 | return true; |
| 6801 | } |
| 6802 | |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6803 | OMPClause *Sema::ActOnOpenMPNumThreadsClause(Expr *NumThreads, |
| 6804 | SourceLocation StartLoc, |
| 6805 | SourceLocation LParenLoc, |
| 6806 | SourceLocation EndLoc) { |
| 6807 | Expr *ValExpr = NumThreads; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6808 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6809 | // OpenMP [2.5, Restrictions] |
| 6810 | // The num_threads expression must evaluate to a positive integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6811 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_num_threads, |
| 6812 | /*StrictlyPositive=*/true)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6813 | return nullptr; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6814 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6815 | return new (Context) |
| 6816 | OMPNumThreadsClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6817 | } |
| 6818 | |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6819 | ExprResult Sema::VerifyPositiveIntegerConstantInClause(Expr *E, |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 6820 | OpenMPClauseKind CKind, |
| 6821 | bool StrictlyPositive) { |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6822 | if (!E) |
| 6823 | return ExprError(); |
| 6824 | if (E->isValueDependent() || E->isTypeDependent() || |
| 6825 | E->isInstantiationDependent() || E->containsUnexpandedParameterPack()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6826 | return E; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6827 | llvm::APSInt Result; |
| 6828 | ExprResult ICE = VerifyIntegerConstantExpression(E, &Result); |
| 6829 | if (ICE.isInvalid()) |
| 6830 | return ExprError(); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 6831 | if ((StrictlyPositive && !Result.isStrictlyPositive()) || |
| 6832 | (!StrictlyPositive && !Result.isNonNegative())) { |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6833 | Diag(E->getExprLoc(), diag::err_omp_negative_expression_in_clause) |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 6834 | << getOpenMPClauseName(CKind) << (StrictlyPositive ? 1 : 0) |
| 6835 | << E->getSourceRange(); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6836 | return ExprError(); |
| 6837 | } |
Alexander Musman | 09184fe | 2014-09-30 05:29:28 +0000 | [diff] [blame] | 6838 | if (CKind == OMPC_aligned && !Result.isPowerOf2()) { |
| 6839 | Diag(E->getExprLoc(), diag::warn_omp_alignment_not_power_of_two) |
| 6840 | << E->getSourceRange(); |
| 6841 | return ExprError(); |
| 6842 | } |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 6843 | if (CKind == OMPC_collapse && DSAStack->getAssociatedLoops() == 1) |
| 6844 | DSAStack->setAssociatedLoops(Result.getExtValue()); |
Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 6845 | else if (CKind == OMPC_ordered) |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 6846 | DSAStack->setAssociatedLoops(Result.getExtValue()); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6847 | return ICE; |
| 6848 | } |
| 6849 | |
| 6850 | OMPClause *Sema::ActOnOpenMPSafelenClause(Expr *Len, SourceLocation StartLoc, |
| 6851 | SourceLocation LParenLoc, |
| 6852 | SourceLocation EndLoc) { |
| 6853 | // OpenMP [2.8.1, simd construct, Description] |
| 6854 | // The parameter of the safelen clause must be a constant |
| 6855 | // positive integer expression. |
| 6856 | ExprResult Safelen = VerifyPositiveIntegerConstantInClause(Len, OMPC_safelen); |
| 6857 | if (Safelen.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6858 | return nullptr; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6859 | return new (Context) |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6860 | OMPSafelenClause(Safelen.get(), StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6861 | } |
| 6862 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 6863 | OMPClause *Sema::ActOnOpenMPSimdlenClause(Expr *Len, SourceLocation StartLoc, |
| 6864 | SourceLocation LParenLoc, |
| 6865 | SourceLocation EndLoc) { |
| 6866 | // OpenMP [2.8.1, simd construct, Description] |
| 6867 | // The parameter of the simdlen clause must be a constant |
| 6868 | // positive integer expression. |
| 6869 | ExprResult Simdlen = VerifyPositiveIntegerConstantInClause(Len, OMPC_simdlen); |
| 6870 | if (Simdlen.isInvalid()) |
| 6871 | return nullptr; |
| 6872 | return new (Context) |
| 6873 | OMPSimdlenClause(Simdlen.get(), StartLoc, LParenLoc, EndLoc); |
| 6874 | } |
| 6875 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6876 | OMPClause *Sema::ActOnOpenMPCollapseClause(Expr *NumForLoops, |
| 6877 | SourceLocation StartLoc, |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6878 | SourceLocation LParenLoc, |
| 6879 | SourceLocation EndLoc) { |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6880 | // OpenMP [2.7.1, loop construct, Description] |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6881 | // OpenMP [2.8.1, simd construct, Description] |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6882 | // OpenMP [2.9.6, distribute construct, Description] |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6883 | // The parameter of the collapse clause must be a constant |
| 6884 | // positive integer expression. |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6885 | ExprResult NumForLoopsResult = |
| 6886 | VerifyPositiveIntegerConstantInClause(NumForLoops, OMPC_collapse); |
| 6887 | if (NumForLoopsResult.isInvalid()) |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6888 | return nullptr; |
| 6889 | return new (Context) |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6890 | OMPCollapseClause(NumForLoopsResult.get(), StartLoc, LParenLoc, EndLoc); |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6891 | } |
| 6892 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 6893 | OMPClause *Sema::ActOnOpenMPOrderedClause(SourceLocation StartLoc, |
| 6894 | SourceLocation EndLoc, |
| 6895 | SourceLocation LParenLoc, |
| 6896 | Expr *NumForLoops) { |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 6897 | // OpenMP [2.7.1, loop construct, Description] |
| 6898 | // OpenMP [2.8.1, simd construct, Description] |
| 6899 | // OpenMP [2.9.6, distribute construct, Description] |
| 6900 | // The parameter of the ordered clause must be a constant |
| 6901 | // positive integer expression if any. |
| 6902 | if (NumForLoops && LParenLoc.isValid()) { |
| 6903 | ExprResult NumForLoopsResult = |
| 6904 | VerifyPositiveIntegerConstantInClause(NumForLoops, OMPC_ordered); |
| 6905 | if (NumForLoopsResult.isInvalid()) |
| 6906 | return nullptr; |
| 6907 | NumForLoops = NumForLoopsResult.get(); |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6908 | } else |
| 6909 | NumForLoops = nullptr; |
| 6910 | DSAStack->setOrderedRegion(/*IsOrdered=*/true, NumForLoops); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 6911 | return new (Context) |
| 6912 | OMPOrderedClause(NumForLoops, StartLoc, LParenLoc, EndLoc); |
| 6913 | } |
| 6914 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6915 | OMPClause *Sema::ActOnOpenMPSimpleClause( |
| 6916 | OpenMPClauseKind Kind, unsigned Argument, SourceLocation ArgumentLoc, |
| 6917 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6918 | OMPClause *Res = nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6919 | switch (Kind) { |
| 6920 | case OMPC_default: |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6921 | Res = |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6922 | ActOnOpenMPDefaultClause(static_cast<OpenMPDefaultClauseKind>(Argument), |
| 6923 | ArgumentLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6924 | break; |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6925 | case OMPC_proc_bind: |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6926 | Res = ActOnOpenMPProcBindClause( |
| 6927 | static_cast<OpenMPProcBindClauseKind>(Argument), ArgumentLoc, StartLoc, |
| 6928 | LParenLoc, EndLoc); |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6929 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6930 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 6931 | case OMPC_final: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6932 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6933 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 6934 | case OMPC_simdlen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6935 | case OMPC_collapse: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6936 | case OMPC_schedule: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6937 | case OMPC_private: |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6938 | case OMPC_firstprivate: |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6939 | case OMPC_lastprivate: |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6940 | case OMPC_shared: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6941 | case OMPC_reduction: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6942 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 6943 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6944 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6945 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6946 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6947 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 6948 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 6949 | case OMPC_mergeable: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6950 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 6951 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6952 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6953 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6954 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6955 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 6956 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6957 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 6958 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6959 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6960 | case OMPC_simd: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 6961 | case OMPC_map: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 6962 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6963 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6964 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 6965 | case OMPC_grainsize: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 6966 | case OMPC_nogroup: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6967 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 6968 | case OMPC_hint: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 6969 | case OMPC_dist_schedule: |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 6970 | case OMPC_defaultmap: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6971 | case OMPC_unknown: |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 6972 | case OMPC_uniform: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6973 | llvm_unreachable("Clause is not allowed."); |
| 6974 | } |
| 6975 | return Res; |
| 6976 | } |
| 6977 | |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6978 | static std::string |
| 6979 | getListOfPossibleValues(OpenMPClauseKind K, unsigned First, unsigned Last, |
| 6980 | ArrayRef<unsigned> Exclude = llvm::None) { |
| 6981 | std::string Values; |
| 6982 | unsigned Bound = Last >= 2 ? Last - 2 : 0; |
| 6983 | unsigned Skipped = Exclude.size(); |
| 6984 | auto S = Exclude.begin(), E = Exclude.end(); |
| 6985 | for (unsigned i = First; i < Last; ++i) { |
| 6986 | if (std::find(S, E, i) != E) { |
| 6987 | --Skipped; |
| 6988 | continue; |
| 6989 | } |
| 6990 | Values += "'"; |
| 6991 | Values += getOpenMPSimpleClauseTypeName(K, i); |
| 6992 | Values += "'"; |
| 6993 | if (i == Bound - Skipped) |
| 6994 | Values += " or "; |
| 6995 | else if (i != Bound + 1 - Skipped) |
| 6996 | Values += ", "; |
| 6997 | } |
| 6998 | return Values; |
| 6999 | } |
| 7000 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7001 | OMPClause *Sema::ActOnOpenMPDefaultClause(OpenMPDefaultClauseKind Kind, |
| 7002 | SourceLocation KindKwLoc, |
| 7003 | SourceLocation StartLoc, |
| 7004 | SourceLocation LParenLoc, |
| 7005 | SourceLocation EndLoc) { |
| 7006 | if (Kind == OMPC_DEFAULT_unknown) { |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 7007 | static_assert(OMPC_DEFAULT_unknown > 0, |
| 7008 | "OMPC_DEFAULT_unknown not greater than 0"); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7009 | Diag(KindKwLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7010 | << getListOfPossibleValues(OMPC_default, /*First=*/0, |
| 7011 | /*Last=*/OMPC_DEFAULT_unknown) |
| 7012 | << getOpenMPClauseName(OMPC_default); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 7013 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7014 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7015 | switch (Kind) { |
| 7016 | case OMPC_DEFAULT_none: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7017 | DSAStack->setDefaultDSANone(KindKwLoc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7018 | break; |
| 7019 | case OMPC_DEFAULT_shared: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7020 | DSAStack->setDefaultDSAShared(KindKwLoc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7021 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7022 | case OMPC_DEFAULT_unknown: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7023 | llvm_unreachable("Clause kind is not allowed."); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7024 | break; |
| 7025 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7026 | return new (Context) |
| 7027 | OMPDefaultClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7028 | } |
| 7029 | |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 7030 | OMPClause *Sema::ActOnOpenMPProcBindClause(OpenMPProcBindClauseKind Kind, |
| 7031 | SourceLocation KindKwLoc, |
| 7032 | SourceLocation StartLoc, |
| 7033 | SourceLocation LParenLoc, |
| 7034 | SourceLocation EndLoc) { |
| 7035 | if (Kind == OMPC_PROC_BIND_unknown) { |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 7036 | Diag(KindKwLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7037 | << getListOfPossibleValues(OMPC_proc_bind, /*First=*/0, |
| 7038 | /*Last=*/OMPC_PROC_BIND_unknown) |
| 7039 | << getOpenMPClauseName(OMPC_proc_bind); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 7040 | return nullptr; |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 7041 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7042 | return new (Context) |
| 7043 | OMPProcBindClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 7044 | } |
| 7045 | |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7046 | OMPClause *Sema::ActOnOpenMPSingleExprWithArgClause( |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7047 | OpenMPClauseKind Kind, ArrayRef<unsigned> Argument, Expr *Expr, |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7048 | SourceLocation StartLoc, SourceLocation LParenLoc, |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7049 | ArrayRef<SourceLocation> ArgumentLoc, SourceLocation DelimLoc, |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7050 | SourceLocation EndLoc) { |
| 7051 | OMPClause *Res = nullptr; |
| 7052 | switch (Kind) { |
| 7053 | case OMPC_schedule: |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7054 | enum { Modifier1, Modifier2, ScheduleKind, NumberOfElements }; |
| 7055 | assert(Argument.size() == NumberOfElements && |
| 7056 | ArgumentLoc.size() == NumberOfElements); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7057 | Res = ActOnOpenMPScheduleClause( |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7058 | static_cast<OpenMPScheduleClauseModifier>(Argument[Modifier1]), |
| 7059 | static_cast<OpenMPScheduleClauseModifier>(Argument[Modifier2]), |
| 7060 | static_cast<OpenMPScheduleClauseKind>(Argument[ScheduleKind]), Expr, |
| 7061 | StartLoc, LParenLoc, ArgumentLoc[Modifier1], ArgumentLoc[Modifier2], |
| 7062 | ArgumentLoc[ScheduleKind], DelimLoc, EndLoc); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7063 | break; |
| 7064 | case OMPC_if: |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7065 | assert(Argument.size() == 1 && ArgumentLoc.size() == 1); |
| 7066 | Res = ActOnOpenMPIfClause(static_cast<OpenMPDirectiveKind>(Argument.back()), |
| 7067 | Expr, StartLoc, LParenLoc, ArgumentLoc.back(), |
| 7068 | DelimLoc, EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 7069 | break; |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 7070 | case OMPC_dist_schedule: |
| 7071 | Res = ActOnOpenMPDistScheduleClause( |
| 7072 | static_cast<OpenMPDistScheduleClauseKind>(Argument.back()), Expr, |
| 7073 | StartLoc, LParenLoc, ArgumentLoc.back(), DelimLoc, EndLoc); |
| 7074 | break; |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 7075 | case OMPC_defaultmap: |
| 7076 | enum { Modifier, DefaultmapKind }; |
| 7077 | Res = ActOnOpenMPDefaultmapClause( |
| 7078 | static_cast<OpenMPDefaultmapClauseModifier>(Argument[Modifier]), |
| 7079 | static_cast<OpenMPDefaultmapClauseKind>(Argument[DefaultmapKind]), |
| 7080 | StartLoc, LParenLoc, ArgumentLoc[Modifier], |
| 7081 | ArgumentLoc[DefaultmapKind], EndLoc); |
| 7082 | break; |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 7083 | case OMPC_final: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7084 | case OMPC_num_threads: |
| 7085 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 7086 | case OMPC_simdlen: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7087 | case OMPC_collapse: |
| 7088 | case OMPC_default: |
| 7089 | case OMPC_proc_bind: |
| 7090 | case OMPC_private: |
| 7091 | case OMPC_firstprivate: |
| 7092 | case OMPC_lastprivate: |
| 7093 | case OMPC_shared: |
| 7094 | case OMPC_reduction: |
| 7095 | case OMPC_linear: |
| 7096 | case OMPC_aligned: |
| 7097 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7098 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7099 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 7100 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 7101 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 7102 | case OMPC_mergeable: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7103 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 7104 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 7105 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 7106 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 7107 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 7108 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 7109 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 7110 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 7111 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 7112 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 7113 | case OMPC_simd: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 7114 | case OMPC_map: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 7115 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7116 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 7117 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 7118 | case OMPC_grainsize: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 7119 | case OMPC_nogroup: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 7120 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 7121 | case OMPC_hint: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7122 | case OMPC_unknown: |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 7123 | case OMPC_uniform: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7124 | llvm_unreachable("Clause is not allowed."); |
| 7125 | } |
| 7126 | return Res; |
| 7127 | } |
| 7128 | |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7129 | static bool checkScheduleModifiers(Sema &S, OpenMPScheduleClauseModifier M1, |
| 7130 | OpenMPScheduleClauseModifier M2, |
| 7131 | SourceLocation M1Loc, SourceLocation M2Loc) { |
| 7132 | if (M1 == OMPC_SCHEDULE_MODIFIER_unknown && M1Loc.isValid()) { |
| 7133 | SmallVector<unsigned, 2> Excluded; |
| 7134 | if (M2 != OMPC_SCHEDULE_MODIFIER_unknown) |
| 7135 | Excluded.push_back(M2); |
| 7136 | if (M2 == OMPC_SCHEDULE_MODIFIER_nonmonotonic) |
| 7137 | Excluded.push_back(OMPC_SCHEDULE_MODIFIER_monotonic); |
| 7138 | if (M2 == OMPC_SCHEDULE_MODIFIER_monotonic) |
| 7139 | Excluded.push_back(OMPC_SCHEDULE_MODIFIER_nonmonotonic); |
| 7140 | S.Diag(M1Loc, diag::err_omp_unexpected_clause_value) |
| 7141 | << getListOfPossibleValues(OMPC_schedule, |
| 7142 | /*First=*/OMPC_SCHEDULE_MODIFIER_unknown + 1, |
| 7143 | /*Last=*/OMPC_SCHEDULE_MODIFIER_last, |
| 7144 | Excluded) |
| 7145 | << getOpenMPClauseName(OMPC_schedule); |
| 7146 | return true; |
| 7147 | } |
| 7148 | return false; |
| 7149 | } |
| 7150 | |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7151 | OMPClause *Sema::ActOnOpenMPScheduleClause( |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7152 | OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2, |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7153 | OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7154 | SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc, |
| 7155 | SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) { |
| 7156 | if (checkScheduleModifiers(*this, M1, M2, M1Loc, M2Loc) || |
| 7157 | checkScheduleModifiers(*this, M2, M1, M2Loc, M1Loc)) |
| 7158 | return nullptr; |
| 7159 | // OpenMP, 2.7.1, Loop Construct, Restrictions |
| 7160 | // Either the monotonic modifier or the nonmonotonic modifier can be specified |
| 7161 | // but not both. |
| 7162 | if ((M1 == M2 && M1 != OMPC_SCHEDULE_MODIFIER_unknown) || |
| 7163 | (M1 == OMPC_SCHEDULE_MODIFIER_monotonic && |
| 7164 | M2 == OMPC_SCHEDULE_MODIFIER_nonmonotonic) || |
| 7165 | (M1 == OMPC_SCHEDULE_MODIFIER_nonmonotonic && |
| 7166 | M2 == OMPC_SCHEDULE_MODIFIER_monotonic)) { |
| 7167 | Diag(M2Loc, diag::err_omp_unexpected_schedule_modifier) |
| 7168 | << getOpenMPSimpleClauseTypeName(OMPC_schedule, M2) |
| 7169 | << getOpenMPSimpleClauseTypeName(OMPC_schedule, M1); |
| 7170 | return nullptr; |
| 7171 | } |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7172 | if (Kind == OMPC_SCHEDULE_unknown) { |
| 7173 | std::string Values; |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7174 | if (M1Loc.isInvalid() && M2Loc.isInvalid()) { |
| 7175 | unsigned Exclude[] = {OMPC_SCHEDULE_unknown}; |
| 7176 | Values = getListOfPossibleValues(OMPC_schedule, /*First=*/0, |
| 7177 | /*Last=*/OMPC_SCHEDULE_MODIFIER_last, |
| 7178 | Exclude); |
| 7179 | } else { |
| 7180 | Values = getListOfPossibleValues(OMPC_schedule, /*First=*/0, |
| 7181 | /*Last=*/OMPC_SCHEDULE_unknown); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7182 | } |
| 7183 | Diag(KindLoc, diag::err_omp_unexpected_clause_value) |
| 7184 | << Values << getOpenMPClauseName(OMPC_schedule); |
| 7185 | return nullptr; |
| 7186 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7187 | // OpenMP, 2.7.1, Loop Construct, Restrictions |
| 7188 | // The nonmonotonic modifier can only be specified with schedule(dynamic) or |
| 7189 | // schedule(guided). |
| 7190 | if ((M1 == OMPC_SCHEDULE_MODIFIER_nonmonotonic || |
| 7191 | M2 == OMPC_SCHEDULE_MODIFIER_nonmonotonic) && |
| 7192 | Kind != OMPC_SCHEDULE_dynamic && Kind != OMPC_SCHEDULE_guided) { |
| 7193 | Diag(M1 == OMPC_SCHEDULE_MODIFIER_nonmonotonic ? M1Loc : M2Loc, |
| 7194 | diag::err_omp_schedule_nonmonotonic_static); |
| 7195 | return nullptr; |
| 7196 | } |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7197 | Expr *ValExpr = ChunkSize; |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 7198 | Stmt *HelperValStmt = nullptr; |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7199 | if (ChunkSize) { |
| 7200 | if (!ChunkSize->isValueDependent() && !ChunkSize->isTypeDependent() && |
| 7201 | !ChunkSize->isInstantiationDependent() && |
| 7202 | !ChunkSize->containsUnexpandedParameterPack()) { |
| 7203 | SourceLocation ChunkSizeLoc = ChunkSize->getLocStart(); |
| 7204 | ExprResult Val = |
| 7205 | PerformOpenMPImplicitIntegerConversion(ChunkSizeLoc, ChunkSize); |
| 7206 | if (Val.isInvalid()) |
| 7207 | return nullptr; |
| 7208 | |
| 7209 | ValExpr = Val.get(); |
| 7210 | |
| 7211 | // OpenMP [2.7.1, Restrictions] |
| 7212 | // chunk_size must be a loop invariant integer expression with a positive |
| 7213 | // value. |
| 7214 | llvm::APSInt Result; |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 7215 | if (ValExpr->isIntegerConstantExpr(Result, Context)) { |
| 7216 | if (Result.isSigned() && !Result.isStrictlyPositive()) { |
| 7217 | Diag(ChunkSizeLoc, diag::err_omp_negative_expression_in_clause) |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 7218 | << "schedule" << 1 << ChunkSize->getSourceRange(); |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 7219 | return nullptr; |
| 7220 | } |
| 7221 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective())) { |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 7222 | llvm::MapVector<Expr *, DeclRefExpr *> Captures; |
| 7223 | ValExpr = tryBuildCapture(*this, ValExpr, Captures).get(); |
| 7224 | HelperValStmt = buildPreInits(Context, Captures); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7225 | } |
| 7226 | } |
| 7227 | } |
| 7228 | |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7229 | return new (Context) |
| 7230 | OMPScheduleClause(StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc, Kind, |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 7231 | ValExpr, HelperValStmt, M1, M1Loc, M2, M2Loc); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7232 | } |
| 7233 | |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7234 | OMPClause *Sema::ActOnOpenMPClause(OpenMPClauseKind Kind, |
| 7235 | SourceLocation StartLoc, |
| 7236 | SourceLocation EndLoc) { |
| 7237 | OMPClause *Res = nullptr; |
| 7238 | switch (Kind) { |
| 7239 | case OMPC_ordered: |
| 7240 | Res = ActOnOpenMPOrderedClause(StartLoc, EndLoc); |
| 7241 | break; |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 7242 | case OMPC_nowait: |
| 7243 | Res = ActOnOpenMPNowaitClause(StartLoc, EndLoc); |
| 7244 | break; |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 7245 | case OMPC_untied: |
| 7246 | Res = ActOnOpenMPUntiedClause(StartLoc, EndLoc); |
| 7247 | break; |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 7248 | case OMPC_mergeable: |
| 7249 | Res = ActOnOpenMPMergeableClause(StartLoc, EndLoc); |
| 7250 | break; |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 7251 | case OMPC_read: |
| 7252 | Res = ActOnOpenMPReadClause(StartLoc, EndLoc); |
| 7253 | break; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 7254 | case OMPC_write: |
| 7255 | Res = ActOnOpenMPWriteClause(StartLoc, EndLoc); |
| 7256 | break; |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 7257 | case OMPC_update: |
| 7258 | Res = ActOnOpenMPUpdateClause(StartLoc, EndLoc); |
| 7259 | break; |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 7260 | case OMPC_capture: |
| 7261 | Res = ActOnOpenMPCaptureClause(StartLoc, EndLoc); |
| 7262 | break; |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 7263 | case OMPC_seq_cst: |
| 7264 | Res = ActOnOpenMPSeqCstClause(StartLoc, EndLoc); |
| 7265 | break; |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 7266 | case OMPC_threads: |
| 7267 | Res = ActOnOpenMPThreadsClause(StartLoc, EndLoc); |
| 7268 | break; |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 7269 | case OMPC_simd: |
| 7270 | Res = ActOnOpenMPSIMDClause(StartLoc, EndLoc); |
| 7271 | break; |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 7272 | case OMPC_nogroup: |
| 7273 | Res = ActOnOpenMPNogroupClause(StartLoc, EndLoc); |
| 7274 | break; |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7275 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 7276 | case OMPC_final: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7277 | case OMPC_num_threads: |
| 7278 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 7279 | case OMPC_simdlen: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7280 | case OMPC_collapse: |
| 7281 | case OMPC_schedule: |
| 7282 | case OMPC_private: |
| 7283 | case OMPC_firstprivate: |
| 7284 | case OMPC_lastprivate: |
| 7285 | case OMPC_shared: |
| 7286 | case OMPC_reduction: |
| 7287 | case OMPC_linear: |
| 7288 | case OMPC_aligned: |
| 7289 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7290 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7291 | case OMPC_default: |
| 7292 | case OMPC_proc_bind: |
| 7293 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 7294 | case OMPC_flush: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 7295 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 7296 | case OMPC_device: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 7297 | case OMPC_map: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 7298 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7299 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 7300 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 7301 | case OMPC_grainsize: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 7302 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 7303 | case OMPC_hint: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 7304 | case OMPC_dist_schedule: |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 7305 | case OMPC_defaultmap: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7306 | case OMPC_unknown: |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 7307 | case OMPC_uniform: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7308 | llvm_unreachable("Clause is not allowed."); |
| 7309 | } |
| 7310 | return Res; |
| 7311 | } |
| 7312 | |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 7313 | OMPClause *Sema::ActOnOpenMPNowaitClause(SourceLocation StartLoc, |
| 7314 | SourceLocation EndLoc) { |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 7315 | DSAStack->setNowaitRegion(); |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 7316 | return new (Context) OMPNowaitClause(StartLoc, EndLoc); |
| 7317 | } |
| 7318 | |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 7319 | OMPClause *Sema::ActOnOpenMPUntiedClause(SourceLocation StartLoc, |
| 7320 | SourceLocation EndLoc) { |
| 7321 | return new (Context) OMPUntiedClause(StartLoc, EndLoc); |
| 7322 | } |
| 7323 | |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 7324 | OMPClause *Sema::ActOnOpenMPMergeableClause(SourceLocation StartLoc, |
| 7325 | SourceLocation EndLoc) { |
| 7326 | return new (Context) OMPMergeableClause(StartLoc, EndLoc); |
| 7327 | } |
| 7328 | |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 7329 | OMPClause *Sema::ActOnOpenMPReadClause(SourceLocation StartLoc, |
| 7330 | SourceLocation EndLoc) { |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 7331 | return new (Context) OMPReadClause(StartLoc, EndLoc); |
| 7332 | } |
| 7333 | |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 7334 | OMPClause *Sema::ActOnOpenMPWriteClause(SourceLocation StartLoc, |
| 7335 | SourceLocation EndLoc) { |
| 7336 | return new (Context) OMPWriteClause(StartLoc, EndLoc); |
| 7337 | } |
| 7338 | |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 7339 | OMPClause *Sema::ActOnOpenMPUpdateClause(SourceLocation StartLoc, |
| 7340 | SourceLocation EndLoc) { |
| 7341 | return new (Context) OMPUpdateClause(StartLoc, EndLoc); |
| 7342 | } |
| 7343 | |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 7344 | OMPClause *Sema::ActOnOpenMPCaptureClause(SourceLocation StartLoc, |
| 7345 | SourceLocation EndLoc) { |
| 7346 | return new (Context) OMPCaptureClause(StartLoc, EndLoc); |
| 7347 | } |
| 7348 | |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 7349 | OMPClause *Sema::ActOnOpenMPSeqCstClause(SourceLocation StartLoc, |
| 7350 | SourceLocation EndLoc) { |
| 7351 | return new (Context) OMPSeqCstClause(StartLoc, EndLoc); |
| 7352 | } |
| 7353 | |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 7354 | OMPClause *Sema::ActOnOpenMPThreadsClause(SourceLocation StartLoc, |
| 7355 | SourceLocation EndLoc) { |
| 7356 | return new (Context) OMPThreadsClause(StartLoc, EndLoc); |
| 7357 | } |
| 7358 | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 7359 | OMPClause *Sema::ActOnOpenMPSIMDClause(SourceLocation StartLoc, |
| 7360 | SourceLocation EndLoc) { |
| 7361 | return new (Context) OMPSIMDClause(StartLoc, EndLoc); |
| 7362 | } |
| 7363 | |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 7364 | OMPClause *Sema::ActOnOpenMPNogroupClause(SourceLocation StartLoc, |
| 7365 | SourceLocation EndLoc) { |
| 7366 | return new (Context) OMPNogroupClause(StartLoc, EndLoc); |
| 7367 | } |
| 7368 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7369 | OMPClause *Sema::ActOnOpenMPVarListClause( |
| 7370 | OpenMPClauseKind Kind, ArrayRef<Expr *> VarList, Expr *TailExpr, |
| 7371 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, |
| 7372 | SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 7373 | const DeclarationNameInfo &ReductionId, OpenMPDependClauseKind DepKind, |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 7374 | OpenMPLinearClauseKind LinKind, OpenMPMapClauseKind MapTypeModifier, |
| 7375 | OpenMPMapClauseKind MapType, bool IsMapTypeImplicit, |
| 7376 | SourceLocation DepLinMapLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 7377 | OMPClause *Res = nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7378 | switch (Kind) { |
| 7379 | case OMPC_private: |
| 7380 | Res = ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7381 | break; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7382 | case OMPC_firstprivate: |
| 7383 | Res = ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7384 | break; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7385 | case OMPC_lastprivate: |
| 7386 | Res = ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7387 | break; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7388 | case OMPC_shared: |
| 7389 | Res = ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7390 | break; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7391 | case OMPC_reduction: |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 7392 | Res = ActOnOpenMPReductionClause(VarList, StartLoc, LParenLoc, ColonLoc, |
| 7393 | EndLoc, ReductionIdScopeSpec, ReductionId); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7394 | break; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7395 | case OMPC_linear: |
| 7396 | Res = ActOnOpenMPLinearClause(VarList, TailExpr, StartLoc, LParenLoc, |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 7397 | LinKind, DepLinMapLoc, ColonLoc, EndLoc); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7398 | break; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 7399 | case OMPC_aligned: |
| 7400 | Res = ActOnOpenMPAlignedClause(VarList, TailExpr, StartLoc, LParenLoc, |
| 7401 | ColonLoc, EndLoc); |
| 7402 | break; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7403 | case OMPC_copyin: |
| 7404 | Res = ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7405 | break; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7406 | case OMPC_copyprivate: |
| 7407 | Res = ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7408 | break; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 7409 | case OMPC_flush: |
| 7410 | Res = ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7411 | break; |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 7412 | case OMPC_depend: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 7413 | Res = ActOnOpenMPDependClause(DepKind, DepLinMapLoc, ColonLoc, VarList, |
| 7414 | StartLoc, LParenLoc, EndLoc); |
| 7415 | break; |
| 7416 | case OMPC_map: |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 7417 | Res = ActOnOpenMPMapClause(MapTypeModifier, MapType, IsMapTypeImplicit, |
| 7418 | DepLinMapLoc, ColonLoc, VarList, StartLoc, |
| 7419 | LParenLoc, EndLoc); |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 7420 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7421 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 7422 | case OMPC_final: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7423 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 7424 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 7425 | case OMPC_simdlen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 7426 | case OMPC_collapse: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7427 | case OMPC_default: |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 7428 | case OMPC_proc_bind: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7429 | case OMPC_schedule: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7430 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 7431 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 7432 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 7433 | case OMPC_mergeable: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7434 | case OMPC_threadprivate: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 7435 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 7436 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 7437 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 7438 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 7439 | case OMPC_seq_cst: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 7440 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 7441 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 7442 | case OMPC_simd: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 7443 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7444 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 7445 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 7446 | case OMPC_grainsize: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 7447 | case OMPC_nogroup: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 7448 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 7449 | case OMPC_hint: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 7450 | case OMPC_dist_schedule: |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 7451 | case OMPC_defaultmap: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7452 | case OMPC_unknown: |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 7453 | case OMPC_uniform: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7454 | llvm_unreachable("Clause is not allowed."); |
| 7455 | } |
| 7456 | return Res; |
| 7457 | } |
| 7458 | |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 7459 | ExprResult Sema::getOpenMPCapturedExpr(VarDecl *Capture, ExprValueKind VK, |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 7460 | ExprObjectKind OK, SourceLocation Loc) { |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 7461 | ExprResult Res = BuildDeclRefExpr( |
| 7462 | Capture, Capture->getType().getNonReferenceType(), VK_LValue, Loc); |
| 7463 | if (!Res.isUsable()) |
| 7464 | return ExprError(); |
| 7465 | if (OK == OK_Ordinary && !getLangOpts().CPlusPlus) { |
| 7466 | Res = CreateBuiltinUnaryOp(Loc, UO_Deref, Res.get()); |
| 7467 | if (!Res.isUsable()) |
| 7468 | return ExprError(); |
| 7469 | } |
| 7470 | if (VK != VK_LValue && Res.get()->isGLValue()) { |
| 7471 | Res = DefaultLvalueConversion(Res.get()); |
| 7472 | if (!Res.isUsable()) |
| 7473 | return ExprError(); |
| 7474 | } |
| 7475 | return Res; |
| 7476 | } |
| 7477 | |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7478 | static std::pair<ValueDecl *, bool> |
| 7479 | getPrivateItem(Sema &S, Expr *&RefExpr, SourceLocation &ELoc, |
| 7480 | SourceRange &ERange, bool AllowArraySection = false) { |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7481 | if (RefExpr->isTypeDependent() || RefExpr->isValueDependent() || |
| 7482 | RefExpr->containsUnexpandedParameterPack()) |
| 7483 | return std::make_pair(nullptr, true); |
| 7484 | |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7485 | // OpenMP [3.1, C/C++] |
| 7486 | // A list item is a variable name. |
| 7487 | // OpenMP [2.9.3.3, Restrictions, p.1] |
| 7488 | // A variable that is part of another variable (as an array or |
| 7489 | // structure element) cannot appear in a private clause. |
| 7490 | RefExpr = RefExpr->IgnoreParens(); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7491 | enum { |
| 7492 | NoArrayExpr = -1, |
| 7493 | ArraySubscript = 0, |
| 7494 | OMPArraySection = 1 |
| 7495 | } IsArrayExpr = NoArrayExpr; |
| 7496 | if (AllowArraySection) { |
| 7497 | if (auto *ASE = dyn_cast_or_null<ArraySubscriptExpr>(RefExpr)) { |
| 7498 | auto *Base = ASE->getBase()->IgnoreParenImpCasts(); |
| 7499 | while (auto *TempASE = dyn_cast<ArraySubscriptExpr>(Base)) |
| 7500 | Base = TempASE->getBase()->IgnoreParenImpCasts(); |
| 7501 | RefExpr = Base; |
| 7502 | IsArrayExpr = ArraySubscript; |
| 7503 | } else if (auto *OASE = dyn_cast_or_null<OMPArraySectionExpr>(RefExpr)) { |
| 7504 | auto *Base = OASE->getBase()->IgnoreParenImpCasts(); |
| 7505 | while (auto *TempOASE = dyn_cast<OMPArraySectionExpr>(Base)) |
| 7506 | Base = TempOASE->getBase()->IgnoreParenImpCasts(); |
| 7507 | while (auto *TempASE = dyn_cast<ArraySubscriptExpr>(Base)) |
| 7508 | Base = TempASE->getBase()->IgnoreParenImpCasts(); |
| 7509 | RefExpr = Base; |
| 7510 | IsArrayExpr = OMPArraySection; |
| 7511 | } |
| 7512 | } |
| 7513 | ELoc = RefExpr->getExprLoc(); |
| 7514 | ERange = RefExpr->getSourceRange(); |
| 7515 | RefExpr = RefExpr->IgnoreParenImpCasts(); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7516 | auto *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr); |
| 7517 | auto *ME = dyn_cast_or_null<MemberExpr>(RefExpr); |
| 7518 | if ((!DE || !isa<VarDecl>(DE->getDecl())) && |
| 7519 | (S.getCurrentThisType().isNull() || !ME || |
| 7520 | !isa<CXXThisExpr>(ME->getBase()->IgnoreParenImpCasts()) || |
| 7521 | !isa<FieldDecl>(ME->getMemberDecl()))) { |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7522 | if (IsArrayExpr != NoArrayExpr) |
| 7523 | S.Diag(ELoc, diag::err_omp_expected_base_var_name) << IsArrayExpr |
| 7524 | << ERange; |
| 7525 | else { |
| 7526 | S.Diag(ELoc, |
| 7527 | AllowArraySection |
| 7528 | ? diag::err_omp_expected_var_name_member_expr_or_array_item |
| 7529 | : diag::err_omp_expected_var_name_member_expr) |
| 7530 | << (S.getCurrentThisType().isNull() ? 0 : 1) << ERange; |
| 7531 | } |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7532 | return std::make_pair(nullptr, false); |
| 7533 | } |
| 7534 | return std::make_pair(DE ? DE->getDecl() : ME->getMemberDecl(), false); |
| 7535 | } |
| 7536 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7537 | OMPClause *Sema::ActOnOpenMPPrivateClause(ArrayRef<Expr *> VarList, |
| 7538 | SourceLocation StartLoc, |
| 7539 | SourceLocation LParenLoc, |
| 7540 | SourceLocation EndLoc) { |
| 7541 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 7542 | SmallVector<Expr *, 8> PrivateCopies; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7543 | for (auto &RefExpr : VarList) { |
| 7544 | assert(RefExpr && "NULL expr in OpenMP private clause."); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7545 | SourceLocation ELoc; |
| 7546 | SourceRange ERange; |
| 7547 | Expr *SimpleRefExpr = RefExpr; |
| 7548 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7549 | if (Res.second) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7550 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7551 | Vars.push_back(RefExpr); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 7552 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7553 | } |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7554 | ValueDecl *D = Res.first; |
| 7555 | if (!D) |
| 7556 | continue; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7557 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7558 | QualType Type = D->getType(); |
| 7559 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7560 | |
| 7561 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 7562 | // A variable that appears in a private clause must not have an incomplete |
| 7563 | // type or a reference type. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7564 | if (RequireCompleteType(ELoc, Type, diag::err_omp_private_incomplete_type)) |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7565 | continue; |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7566 | Type = Type.getNonReferenceType(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7567 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7568 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 7569 | // in a Construct] |
| 7570 | // Variables with the predetermined data-sharing attributes may not be |
| 7571 | // listed in data-sharing attributes clauses, except for the cases |
| 7572 | // listed below. For these exceptions only, listing a predetermined |
| 7573 | // variable in a data-sharing attribute clause is allowed and overrides |
| 7574 | // the variable's predetermined data-sharing attributes. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7575 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7576 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_private) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7577 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 7578 | << getOpenMPClauseName(OMPC_private); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7579 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7580 | continue; |
| 7581 | } |
| 7582 | |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7583 | // Variably modified types are not supported for tasks. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 7584 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType() && |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 7585 | isOpenMPTaskingDirective(DSAStack->getCurrentDirective())) { |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7586 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
| 7587 | << getOpenMPClauseName(OMPC_private) << Type |
| 7588 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 7589 | bool IsDecl = |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7590 | !VD || |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7591 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7592 | Diag(D->getLocation(), |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7593 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7594 | << D; |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7595 | continue; |
| 7596 | } |
| 7597 | |
Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 7598 | // OpenMP 4.5 [2.15.5.1, Restrictions, p.3] |
| 7599 | // A list item cannot appear in both a map clause and a data-sharing |
| 7600 | // attribute clause on the same construct |
| 7601 | if (DSAStack->getCurrentDirective() == OMPD_target) { |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 7602 | if (DSAStack->checkMappableExprComponentListsForDecl( |
| 7603 | VD, /* CurrentRegionOnly = */ true, |
| 7604 | [&](OMPClauseMappableExprCommon::MappableExprComponentListRef) |
| 7605 | -> bool { return true; })) { |
Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 7606 | Diag(ELoc, diag::err_omp_variable_in_map_and_dsa) |
| 7607 | << getOpenMPClauseName(OMPC_private) |
| 7608 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 7609 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
| 7610 | continue; |
| 7611 | } |
| 7612 | } |
| 7613 | |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7614 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.1] |
| 7615 | // A variable of class type (or array thereof) that appears in a private |
| 7616 | // clause requires an accessible, unambiguous default constructor for the |
| 7617 | // class type. |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 7618 | // Generate helper private variable and initialize it with the default |
| 7619 | // value. The address of the original variable is replaced by the address of |
| 7620 | // the new private variable in CodeGen. This new variable is not added to |
| 7621 | // IdResolver, so the code in the OpenMP region uses original variable for |
| 7622 | // proper diagnostics. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7623 | Type = Type.getUnqualifiedType(); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7624 | auto VDPrivate = buildVarDecl(*this, ELoc, Type, D->getName(), |
| 7625 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7626 | ActOnUninitializedDecl(VDPrivate, /*TypeMayContainAuto=*/false); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 7627 | if (VDPrivate->isInvalidDecl()) |
| 7628 | continue; |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7629 | auto VDPrivateRefExpr = buildDeclRefExpr( |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7630 | *this, VDPrivate, RefExpr->getType().getUnqualifiedType(), ELoc); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 7631 | |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 7632 | DeclRefExpr *Ref = nullptr; |
| 7633 | if (!VD) |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 7634 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false); |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 7635 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_private, Ref); |
| 7636 | Vars.push_back(VD ? RefExpr->IgnoreParens() : Ref); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 7637 | PrivateCopies.push_back(VDPrivateRefExpr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7638 | } |
| 7639 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7640 | if (Vars.empty()) |
| 7641 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7642 | |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 7643 | return OMPPrivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
| 7644 | PrivateCopies); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7645 | } |
| 7646 | |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7647 | namespace { |
| 7648 | class DiagsUninitializedSeveretyRAII { |
| 7649 | private: |
| 7650 | DiagnosticsEngine &Diags; |
| 7651 | SourceLocation SavedLoc; |
| 7652 | bool IsIgnored; |
| 7653 | |
| 7654 | public: |
| 7655 | DiagsUninitializedSeveretyRAII(DiagnosticsEngine &Diags, SourceLocation Loc, |
| 7656 | bool IsIgnored) |
| 7657 | : Diags(Diags), SavedLoc(Loc), IsIgnored(IsIgnored) { |
| 7658 | if (!IsIgnored) { |
| 7659 | Diags.setSeverity(/*Diag*/ diag::warn_uninit_self_reference_in_init, |
| 7660 | /*Map*/ diag::Severity::Ignored, Loc); |
| 7661 | } |
| 7662 | } |
| 7663 | ~DiagsUninitializedSeveretyRAII() { |
| 7664 | if (!IsIgnored) |
| 7665 | Diags.popMappings(SavedLoc); |
| 7666 | } |
| 7667 | }; |
Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 7668 | } |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7669 | |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7670 | OMPClause *Sema::ActOnOpenMPFirstprivateClause(ArrayRef<Expr *> VarList, |
| 7671 | SourceLocation StartLoc, |
| 7672 | SourceLocation LParenLoc, |
| 7673 | SourceLocation EndLoc) { |
| 7674 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7675 | SmallVector<Expr *, 8> PrivateCopies; |
| 7676 | SmallVector<Expr *, 8> Inits; |
Alexey Bataev | 417089f | 2016-02-17 13:19:37 +0000 | [diff] [blame] | 7677 | SmallVector<Decl *, 4> ExprCaptures; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7678 | bool IsImplicitClause = |
| 7679 | StartLoc.isInvalid() && LParenLoc.isInvalid() && EndLoc.isInvalid(); |
| 7680 | auto ImplicitClauseLoc = DSAStack->getConstructLoc(); |
| 7681 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7682 | for (auto &RefExpr : VarList) { |
| 7683 | assert(RefExpr && "NULL expr in OpenMP firstprivate clause."); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7684 | SourceLocation ELoc; |
| 7685 | SourceRange ERange; |
| 7686 | Expr *SimpleRefExpr = RefExpr; |
| 7687 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7688 | if (Res.second) { |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7689 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7690 | Vars.push_back(RefExpr); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7691 | PrivateCopies.push_back(nullptr); |
| 7692 | Inits.push_back(nullptr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7693 | } |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7694 | ValueDecl *D = Res.first; |
| 7695 | if (!D) |
| 7696 | continue; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7697 | |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7698 | ELoc = IsImplicitClause ? ImplicitClauseLoc : ELoc; |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7699 | QualType Type = D->getType(); |
| 7700 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7701 | |
| 7702 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 7703 | // A variable that appears in a private clause must not have an incomplete |
| 7704 | // type or a reference type. |
| 7705 | if (RequireCompleteType(ELoc, Type, |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7706 | diag::err_omp_firstprivate_incomplete_type)) |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7707 | continue; |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7708 | Type = Type.getNonReferenceType(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7709 | |
| 7710 | // OpenMP [2.9.3.4, Restrictions, C/C++, p.1] |
| 7711 | // 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] | 7712 | // clause requires an accessible, unambiguous copy constructor for the |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7713 | // class type. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7714 | auto ElemType = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7715 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7716 | // If an implicit firstprivate variable found it was checked already. |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 7717 | DSAStackTy::DSAVarData TopDVar; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7718 | if (!IsImplicitClause) { |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7719 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 7720 | TopDVar = DVar; |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7721 | bool IsConstant = ElemType.isConstant(Context); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7722 | // OpenMP [2.4.13, Data-sharing Attribute Clauses] |
| 7723 | // A list item that specifies a given variable may not appear in more |
| 7724 | // than one clause on the same directive, except that a variable may be |
| 7725 | // specified in both firstprivate and lastprivate clauses. |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7726 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_firstprivate && |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7727 | DVar.CKind != OMPC_lastprivate && DVar.RefExpr) { |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7728 | Diag(ELoc, diag::err_omp_wrong_dsa) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7729 | << getOpenMPClauseName(DVar.CKind) |
| 7730 | << getOpenMPClauseName(OMPC_firstprivate); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7731 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7732 | continue; |
| 7733 | } |
| 7734 | |
| 7735 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 7736 | // in a Construct] |
| 7737 | // Variables with the predetermined data-sharing attributes may not be |
| 7738 | // listed in data-sharing attributes clauses, except for the cases |
| 7739 | // listed below. For these exceptions only, listing a predetermined |
| 7740 | // variable in a data-sharing attribute clause is allowed and overrides |
| 7741 | // the variable's predetermined data-sharing attributes. |
| 7742 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 7743 | // in a Construct, C/C++, p.2] |
| 7744 | // Variables with const-qualified type having no mutable member may be |
| 7745 | // listed in a firstprivate clause, even if they are static data members. |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7746 | if (!(IsConstant || (VD && VD->isStaticDataMember())) && !DVar.RefExpr && |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7747 | DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared) { |
| 7748 | Diag(ELoc, diag::err_omp_wrong_dsa) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7749 | << getOpenMPClauseName(DVar.CKind) |
| 7750 | << getOpenMPClauseName(OMPC_firstprivate); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7751 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7752 | continue; |
| 7753 | } |
| 7754 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7755 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7756 | // OpenMP [2.9.3.4, Restrictions, p.2] |
| 7757 | // A list item that is private within a parallel region must not appear |
| 7758 | // in a firstprivate clause on a worksharing construct if any of the |
| 7759 | // worksharing regions arising from the worksharing construct ever bind |
| 7760 | // to any of the parallel regions arising from the parallel construct. |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 7761 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 7762 | !isOpenMPParallelDirective(CurrDir)) { |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7763 | DVar = DSAStack->getImplicitDSA(D, true); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7764 | if (DVar.CKind != OMPC_shared && |
| 7765 | (isOpenMPParallelDirective(DVar.DKind) || |
| 7766 | DVar.DKind == OMPD_unknown)) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7767 | Diag(ELoc, diag::err_omp_required_access) |
| 7768 | << getOpenMPClauseName(OMPC_firstprivate) |
| 7769 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7770 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7771 | continue; |
| 7772 | } |
| 7773 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7774 | // OpenMP [2.9.3.4, Restrictions, p.3] |
| 7775 | // A list item that appears in a reduction clause of a parallel construct |
| 7776 | // must not appear in a firstprivate clause on a worksharing or task |
| 7777 | // construct if any of the worksharing or task regions arising from the |
| 7778 | // worksharing or task construct ever bind to any of the parallel regions |
| 7779 | // arising from the parallel construct. |
| 7780 | // OpenMP [2.9.3.4, Restrictions, p.4] |
| 7781 | // A list item that appears in a reduction clause in worksharing |
| 7782 | // construct must not appear in a firstprivate clause in a task construct |
| 7783 | // encountered during execution of any of the worksharing regions arising |
| 7784 | // from the worksharing construct. |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 7785 | if (isOpenMPTaskingDirective(CurrDir)) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7786 | DVar = |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7787 | DSAStack->hasInnermostDSA(D, MatchesAnyClause(OMPC_reduction), |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7788 | [](OpenMPDirectiveKind K) -> bool { |
| 7789 | return isOpenMPParallelDirective(K) || |
| 7790 | isOpenMPWorksharingDirective(K); |
| 7791 | }, |
| 7792 | false); |
| 7793 | if (DVar.CKind == OMPC_reduction && |
| 7794 | (isOpenMPParallelDirective(DVar.DKind) || |
| 7795 | isOpenMPWorksharingDirective(DVar.DKind))) { |
| 7796 | Diag(ELoc, diag::err_omp_parallel_reduction_in_task_firstprivate) |
| 7797 | << getOpenMPDirectiveName(DVar.DKind); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7798 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7799 | continue; |
| 7800 | } |
| 7801 | } |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7802 | |
| 7803 | // OpenMP 4.5 [2.15.3.4, Restrictions, p.3] |
| 7804 | // A list item that is private within a teams region must not appear in a |
| 7805 | // firstprivate clause on a distribute construct if any of the distribute |
| 7806 | // regions arising from the distribute construct ever bind to any of the |
| 7807 | // teams regions arising from the teams construct. |
| 7808 | // OpenMP 4.5 [2.15.3.4, Restrictions, p.3] |
| 7809 | // A list item that appears in a reduction clause of a teams construct |
| 7810 | // must not appear in a firstprivate clause on a distribute construct if |
| 7811 | // any of the distribute regions arising from the distribute construct |
| 7812 | // ever bind to any of the teams regions arising from the teams construct. |
| 7813 | // OpenMP 4.5 [2.10.8, Distribute Construct, p.3] |
| 7814 | // A list item may appear in a firstprivate or lastprivate clause but not |
| 7815 | // both. |
| 7816 | if (CurrDir == OMPD_distribute) { |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7817 | DVar = DSAStack->hasInnermostDSA(D, MatchesAnyClause(OMPC_private), |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7818 | [](OpenMPDirectiveKind K) -> bool { |
| 7819 | return isOpenMPTeamsDirective(K); |
| 7820 | }, |
| 7821 | false); |
| 7822 | if (DVar.CKind == OMPC_private && isOpenMPTeamsDirective(DVar.DKind)) { |
| 7823 | Diag(ELoc, diag::err_omp_firstprivate_distribute_private_teams); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7824 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7825 | continue; |
| 7826 | } |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7827 | DVar = DSAStack->hasInnermostDSA(D, MatchesAnyClause(OMPC_reduction), |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7828 | [](OpenMPDirectiveKind K) -> bool { |
| 7829 | return isOpenMPTeamsDirective(K); |
| 7830 | }, |
| 7831 | false); |
| 7832 | if (DVar.CKind == OMPC_reduction && |
| 7833 | isOpenMPTeamsDirective(DVar.DKind)) { |
| 7834 | Diag(ELoc, diag::err_omp_firstprivate_distribute_in_teams_reduction); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7835 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7836 | continue; |
| 7837 | } |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7838 | DVar = DSAStack->getTopDSA(D, false); |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7839 | if (DVar.CKind == OMPC_lastprivate) { |
| 7840 | Diag(ELoc, diag::err_omp_firstprivate_and_lastprivate_in_distribute); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7841 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7842 | continue; |
| 7843 | } |
| 7844 | } |
Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 7845 | // OpenMP 4.5 [2.15.5.1, Restrictions, p.3] |
| 7846 | // A list item cannot appear in both a map clause and a data-sharing |
| 7847 | // attribute clause on the same construct |
| 7848 | if (CurrDir == OMPD_target) { |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 7849 | if (DSAStack->checkMappableExprComponentListsForDecl( |
| 7850 | VD, /* CurrentRegionOnly = */ true, |
| 7851 | [&](OMPClauseMappableExprCommon::MappableExprComponentListRef) |
| 7852 | -> bool { return true; })) { |
Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 7853 | Diag(ELoc, diag::err_omp_variable_in_map_and_dsa) |
| 7854 | << getOpenMPClauseName(OMPC_firstprivate) |
| 7855 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 7856 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
| 7857 | continue; |
| 7858 | } |
| 7859 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7860 | } |
| 7861 | |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7862 | // Variably modified types are not supported for tasks. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 7863 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType() && |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 7864 | isOpenMPTaskingDirective(DSAStack->getCurrentDirective())) { |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7865 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
| 7866 | << getOpenMPClauseName(OMPC_firstprivate) << Type |
| 7867 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 7868 | bool IsDecl = |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7869 | !VD || |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7870 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7871 | Diag(D->getLocation(), |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7872 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7873 | << D; |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7874 | continue; |
| 7875 | } |
| 7876 | |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7877 | Type = Type.getUnqualifiedType(); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7878 | auto VDPrivate = buildVarDecl(*this, ELoc, Type, D->getName(), |
| 7879 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7880 | // Generate helper private variable and initialize it with the value of the |
| 7881 | // original variable. The address of the original variable is replaced by |
| 7882 | // the address of the new private variable in the CodeGen. This new variable |
| 7883 | // is not added to IdResolver, so the code in the OpenMP region uses |
| 7884 | // original variable for proper diagnostics and variable capturing. |
| 7885 | Expr *VDInitRefExpr = nullptr; |
| 7886 | // For arrays generate initializer for single element and replace it by the |
| 7887 | // original array element in CodeGen. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7888 | if (Type->isArrayType()) { |
| 7889 | auto VDInit = |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7890 | buildVarDecl(*this, RefExpr->getExprLoc(), ElemType, D->getName()); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7891 | VDInitRefExpr = buildDeclRefExpr(*this, VDInit, ElemType, ELoc); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7892 | auto Init = DefaultLvalueConversion(VDInitRefExpr).get(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7893 | ElemType = ElemType.getUnqualifiedType(); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7894 | auto *VDInitTemp = buildVarDecl(*this, RefExpr->getExprLoc(), ElemType, |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7895 | ".firstprivate.temp"); |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 7896 | InitializedEntity Entity = |
| 7897 | InitializedEntity::InitializeVariable(VDInitTemp); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7898 | InitializationKind Kind = InitializationKind::CreateCopy(ELoc, ELoc); |
| 7899 | |
| 7900 | InitializationSequence InitSeq(*this, Entity, Kind, Init); |
| 7901 | ExprResult Result = InitSeq.Perform(*this, Entity, Kind, Init); |
| 7902 | if (Result.isInvalid()) |
| 7903 | VDPrivate->setInvalidDecl(); |
| 7904 | else |
| 7905 | VDPrivate->setInit(Result.getAs<Expr>()); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7906 | // Remove temp variable declaration. |
| 7907 | Context.Deallocate(VDInitTemp); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7908 | } else { |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7909 | auto *VDInit = buildVarDecl(*this, RefExpr->getExprLoc(), Type, |
| 7910 | ".firstprivate.temp"); |
| 7911 | VDInitRefExpr = buildDeclRefExpr(*this, VDInit, RefExpr->getType(), |
| 7912 | RefExpr->getExprLoc()); |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 7913 | AddInitializerToDecl(VDPrivate, |
| 7914 | DefaultLvalueConversion(VDInitRefExpr).get(), |
| 7915 | /*DirectInit=*/false, /*TypeMayContainAuto=*/false); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7916 | } |
| 7917 | if (VDPrivate->isInvalidDecl()) { |
| 7918 | if (IsImplicitClause) { |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7919 | Diag(RefExpr->getExprLoc(), |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7920 | diag::note_omp_task_predetermined_firstprivate_here); |
| 7921 | } |
| 7922 | continue; |
| 7923 | } |
| 7924 | CurContext->addDecl(VDPrivate); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7925 | auto VDPrivateRefExpr = buildDeclRefExpr( |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7926 | *this, VDPrivate, RefExpr->getType().getUnqualifiedType(), |
| 7927 | RefExpr->getExprLoc()); |
| 7928 | DeclRefExpr *Ref = nullptr; |
Alexey Bataev | 417089f | 2016-02-17 13:19:37 +0000 | [diff] [blame] | 7929 | if (!VD) { |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 7930 | if (TopDVar.CKind == OMPC_lastprivate) |
| 7931 | Ref = TopDVar.PrivateCopy; |
| 7932 | else { |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 7933 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/true); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 7934 | if (!IsOpenMPCapturedDecl(D)) |
| 7935 | ExprCaptures.push_back(Ref->getDecl()); |
| 7936 | } |
Alexey Bataev | 417089f | 2016-02-17 13:19:37 +0000 | [diff] [blame] | 7937 | } |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7938 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_firstprivate, Ref); |
| 7939 | Vars.push_back(VD ? RefExpr->IgnoreParens() : Ref); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7940 | PrivateCopies.push_back(VDPrivateRefExpr); |
| 7941 | Inits.push_back(VDInitRefExpr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7942 | } |
| 7943 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7944 | if (Vars.empty()) |
| 7945 | return nullptr; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7946 | |
| 7947 | return OMPFirstprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 7948 | Vars, PrivateCopies, Inits, |
| 7949 | buildPreInits(Context, ExprCaptures)); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7950 | } |
| 7951 | |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7952 | OMPClause *Sema::ActOnOpenMPLastprivateClause(ArrayRef<Expr *> VarList, |
| 7953 | SourceLocation StartLoc, |
| 7954 | SourceLocation LParenLoc, |
| 7955 | SourceLocation EndLoc) { |
| 7956 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7957 | SmallVector<Expr *, 8> SrcExprs; |
| 7958 | SmallVector<Expr *, 8> DstExprs; |
| 7959 | SmallVector<Expr *, 8> AssignmentOps; |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 7960 | SmallVector<Decl *, 4> ExprCaptures; |
| 7961 | SmallVector<Expr *, 4> ExprPostUpdates; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7962 | for (auto &RefExpr : VarList) { |
| 7963 | assert(RefExpr && "NULL expr in OpenMP lastprivate clause."); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7964 | SourceLocation ELoc; |
| 7965 | SourceRange ERange; |
| 7966 | Expr *SimpleRefExpr = RefExpr; |
| 7967 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7968 | if (Res.second) { |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7969 | // It will be analyzed later. |
| 7970 | Vars.push_back(RefExpr); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7971 | SrcExprs.push_back(nullptr); |
| 7972 | DstExprs.push_back(nullptr); |
| 7973 | AssignmentOps.push_back(nullptr); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7974 | } |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7975 | ValueDecl *D = Res.first; |
| 7976 | if (!D) |
| 7977 | continue; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7978 | |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7979 | QualType Type = D->getType(); |
| 7980 | auto *VD = dyn_cast<VarDecl>(D); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7981 | |
| 7982 | // OpenMP [2.14.3.5, Restrictions, C/C++, p.2] |
| 7983 | // A variable that appears in a lastprivate clause must not have an |
| 7984 | // incomplete type or a reference type. |
| 7985 | if (RequireCompleteType(ELoc, Type, |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7986 | diag::err_omp_lastprivate_incomplete_type)) |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7987 | continue; |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7988 | Type = Type.getNonReferenceType(); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7989 | |
| 7990 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 7991 | // in a Construct] |
| 7992 | // Variables with the predetermined data-sharing attributes may not be |
| 7993 | // listed in data-sharing attributes clauses, except for the cases |
| 7994 | // listed below. |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7995 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7996 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_lastprivate && |
| 7997 | DVar.CKind != OMPC_firstprivate && |
| 7998 | (DVar.CKind != OMPC_private || DVar.RefExpr != nullptr)) { |
| 7999 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 8000 | << getOpenMPClauseName(DVar.CKind) |
| 8001 | << getOpenMPClauseName(OMPC_lastprivate); |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8002 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8003 | continue; |
| 8004 | } |
| 8005 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 8006 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
| 8007 | // OpenMP [2.14.3.5, Restrictions, p.2] |
| 8008 | // A list item that is private within a parallel region, or that appears in |
| 8009 | // the reduction clause of a parallel construct, must not appear in a |
| 8010 | // lastprivate clause on a worksharing construct if any of the corresponding |
| 8011 | // worksharing regions ever binds to any of the corresponding parallel |
| 8012 | // regions. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 8013 | DSAStackTy::DSAVarData TopDVar = DVar; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 8014 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 8015 | !isOpenMPParallelDirective(CurrDir)) { |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8016 | DVar = DSAStack->getImplicitDSA(D, true); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 8017 | if (DVar.CKind != OMPC_shared) { |
| 8018 | Diag(ELoc, diag::err_omp_required_access) |
| 8019 | << getOpenMPClauseName(OMPC_lastprivate) |
| 8020 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8021 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 8022 | continue; |
| 8023 | } |
| 8024 | } |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8025 | |
| 8026 | // OpenMP 4.5 [2.10.8, Distribute Construct, p.3] |
| 8027 | // A list item may appear in a firstprivate or lastprivate clause but not |
| 8028 | // both. |
| 8029 | if (CurrDir == OMPD_distribute) { |
| 8030 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
| 8031 | if (DVar.CKind == OMPC_firstprivate) { |
| 8032 | Diag(ELoc, diag::err_omp_firstprivate_and_lastprivate_in_distribute); |
| 8033 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
| 8034 | continue; |
| 8035 | } |
| 8036 | } |
| 8037 | |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8038 | // OpenMP [2.14.3.5, Restrictions, C++, p.1,2] |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 8039 | // A variable of class type (or array thereof) that appears in a |
| 8040 | // lastprivate clause requires an accessible, unambiguous default |
| 8041 | // constructor for the class type, unless the list item is also specified |
| 8042 | // in a firstprivate clause. |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8043 | // A variable of class type (or array thereof) that appears in a |
| 8044 | // lastprivate clause requires an accessible, unambiguous copy assignment |
| 8045 | // operator for the class type. |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 8046 | Type = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8047 | auto *SrcVD = buildVarDecl(*this, ERange.getBegin(), |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 8048 | Type.getUnqualifiedType(), ".lastprivate.src", |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8049 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 8050 | auto *PseudoSrcExpr = |
| 8051 | buildDeclRefExpr(*this, SrcVD, Type.getUnqualifiedType(), ELoc); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 8052 | auto *DstVD = |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8053 | buildVarDecl(*this, ERange.getBegin(), Type, ".lastprivate.dst", |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8054 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 8055 | auto *PseudoDstExpr = buildDeclRefExpr(*this, DstVD, Type, ELoc); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 8056 | // For arrays generate assignment operation for single element and replace |
| 8057 | // it by the original array element in CodeGen. |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8058 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, ELoc, BO_Assign, |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 8059 | PseudoDstExpr, PseudoSrcExpr); |
| 8060 | if (AssignmentOp.isInvalid()) |
| 8061 | continue; |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8062 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), ELoc, |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 8063 | /*DiscardedValue=*/true); |
| 8064 | if (AssignmentOp.isInvalid()) |
| 8065 | continue; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8066 | |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8067 | DeclRefExpr *Ref = nullptr; |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8068 | if (!VD) { |
| 8069 | if (TopDVar.CKind == OMPC_firstprivate) |
| 8070 | Ref = TopDVar.PrivateCopy; |
| 8071 | else { |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 8072 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8073 | if (!IsOpenMPCapturedDecl(D)) |
| 8074 | ExprCaptures.push_back(Ref->getDecl()); |
| 8075 | } |
| 8076 | if (TopDVar.CKind == OMPC_firstprivate || |
| 8077 | (!IsOpenMPCapturedDecl(D) && |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8078 | Ref->getDecl()->hasAttr<OMPCaptureNoInitAttr>())) { |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8079 | ExprResult RefRes = DefaultLvalueConversion(Ref); |
| 8080 | if (!RefRes.isUsable()) |
| 8081 | continue; |
| 8082 | ExprResult PostUpdateRes = |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8083 | BuildBinOp(DSAStack->getCurScope(), ELoc, BO_Assign, SimpleRefExpr, |
| 8084 | RefRes.get()); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8085 | if (!PostUpdateRes.isUsable()) |
| 8086 | continue; |
Alexey Bataev | 78849fb | 2016-03-09 09:49:00 +0000 | [diff] [blame] | 8087 | ExprPostUpdates.push_back( |
| 8088 | IgnoredValueConversions(PostUpdateRes.get()).get()); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8089 | } |
| 8090 | } |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 8091 | if (TopDVar.CKind != OMPC_firstprivate) |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8092 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_lastprivate, Ref); |
| 8093 | Vars.push_back(VD ? RefExpr->IgnoreParens() : Ref); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 8094 | SrcExprs.push_back(PseudoSrcExpr); |
| 8095 | DstExprs.push_back(PseudoDstExpr); |
| 8096 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8097 | } |
| 8098 | |
| 8099 | if (Vars.empty()) |
| 8100 | return nullptr; |
| 8101 | |
| 8102 | return OMPLastprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8103 | Vars, SrcExprs, DstExprs, AssignmentOps, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 8104 | buildPreInits(Context, ExprCaptures), |
| 8105 | buildPostUpdate(*this, ExprPostUpdates)); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8106 | } |
| 8107 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8108 | OMPClause *Sema::ActOnOpenMPSharedClause(ArrayRef<Expr *> VarList, |
| 8109 | SourceLocation StartLoc, |
| 8110 | SourceLocation LParenLoc, |
| 8111 | SourceLocation EndLoc) { |
| 8112 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8113 | for (auto &RefExpr : VarList) { |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 8114 | assert(RefExpr && "NULL expr in OpenMP lastprivate clause."); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8115 | SourceLocation ELoc; |
| 8116 | SourceRange ERange; |
| 8117 | Expr *SimpleRefExpr = RefExpr; |
| 8118 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 8119 | if (Res.second) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8120 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8121 | Vars.push_back(RefExpr); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8122 | } |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 8123 | ValueDecl *D = Res.first; |
| 8124 | if (!D) |
| 8125 | continue; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8126 | |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 8127 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8128 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 8129 | // in a Construct] |
| 8130 | // Variables with the predetermined data-sharing attributes may not be |
| 8131 | // listed in data-sharing attributes clauses, except for the cases |
| 8132 | // listed below. For these exceptions only, listing a predetermined |
| 8133 | // variable in a data-sharing attribute clause is allowed and overrides |
| 8134 | // the variable's predetermined data-sharing attributes. |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 8135 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8136 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared && |
| 8137 | DVar.RefExpr) { |
| 8138 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 8139 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 8140 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8141 | continue; |
| 8142 | } |
| 8143 | |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 8144 | DeclRefExpr *Ref = nullptr; |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 8145 | if (!VD && IsOpenMPCapturedDecl(D)) |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 8146 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/true); |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 8147 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_shared, Ref); |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 8148 | Vars.push_back((VD || !Ref) ? RefExpr->IgnoreParens() : Ref); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8149 | } |
| 8150 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8151 | if (Vars.empty()) |
| 8152 | return nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8153 | |
| 8154 | return OMPSharedClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars); |
| 8155 | } |
| 8156 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8157 | namespace { |
| 8158 | class DSARefChecker : public StmtVisitor<DSARefChecker, bool> { |
| 8159 | DSAStackTy *Stack; |
| 8160 | |
| 8161 | public: |
| 8162 | bool VisitDeclRefExpr(DeclRefExpr *E) { |
| 8163 | if (VarDecl *VD = dyn_cast<VarDecl>(E->getDecl())) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 8164 | DSAStackTy::DSAVarData DVar = Stack->getTopDSA(VD, false); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8165 | if (DVar.CKind == OMPC_shared && !DVar.RefExpr) |
| 8166 | return false; |
| 8167 | if (DVar.CKind != OMPC_unknown) |
| 8168 | return true; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 8169 | DSAStackTy::DSAVarData DVarPrivate = |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 8170 | Stack->hasDSA(VD, isOpenMPPrivate, MatchesAlways(), false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 8171 | if (DVarPrivate.CKind != OMPC_unknown) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8172 | return true; |
| 8173 | return false; |
| 8174 | } |
| 8175 | return false; |
| 8176 | } |
| 8177 | bool VisitStmt(Stmt *S) { |
| 8178 | for (auto Child : S->children()) { |
| 8179 | if (Child && Visit(Child)) |
| 8180 | return true; |
| 8181 | } |
| 8182 | return false; |
| 8183 | } |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 8184 | explicit DSARefChecker(DSAStackTy *S) : Stack(S) {} |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8185 | }; |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 8186 | } // namespace |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8187 | |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8188 | namespace { |
| 8189 | // Transform MemberExpression for specified FieldDecl of current class to |
| 8190 | // DeclRefExpr to specified OMPCapturedExprDecl. |
| 8191 | class TransformExprToCaptures : public TreeTransform<TransformExprToCaptures> { |
| 8192 | typedef TreeTransform<TransformExprToCaptures> BaseTransform; |
| 8193 | ValueDecl *Field; |
| 8194 | DeclRefExpr *CapturedExpr; |
| 8195 | |
| 8196 | public: |
| 8197 | TransformExprToCaptures(Sema &SemaRef, ValueDecl *FieldDecl) |
| 8198 | : BaseTransform(SemaRef), Field(FieldDecl), CapturedExpr(nullptr) {} |
| 8199 | |
| 8200 | ExprResult TransformMemberExpr(MemberExpr *E) { |
| 8201 | if (isa<CXXThisExpr>(E->getBase()->IgnoreParenImpCasts()) && |
| 8202 | E->getMemberDecl() == Field) { |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 8203 | CapturedExpr = buildCapture(SemaRef, Field, E, /*WithInit=*/false); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8204 | return CapturedExpr; |
| 8205 | } |
| 8206 | return BaseTransform::TransformMemberExpr(E); |
| 8207 | } |
| 8208 | DeclRefExpr *getCapturedExpr() { return CapturedExpr; } |
| 8209 | }; |
| 8210 | } // namespace |
| 8211 | |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8212 | template <typename T> |
| 8213 | static T filterLookupForUDR(SmallVectorImpl<UnresolvedSet<8>> &Lookups, |
| 8214 | const llvm::function_ref<T(ValueDecl *)> &Gen) { |
| 8215 | for (auto &Set : Lookups) { |
| 8216 | for (auto *D : Set) { |
| 8217 | if (auto Res = Gen(cast<ValueDecl>(D))) |
| 8218 | return Res; |
| 8219 | } |
| 8220 | } |
| 8221 | return T(); |
| 8222 | } |
| 8223 | |
| 8224 | static ExprResult |
| 8225 | buildDeclareReductionRef(Sema &SemaRef, SourceLocation Loc, SourceRange Range, |
| 8226 | Scope *S, CXXScopeSpec &ReductionIdScopeSpec, |
| 8227 | const DeclarationNameInfo &ReductionId, QualType Ty, |
| 8228 | CXXCastPath &BasePath, Expr *UnresolvedReduction) { |
| 8229 | if (ReductionIdScopeSpec.isInvalid()) |
| 8230 | return ExprError(); |
| 8231 | SmallVector<UnresolvedSet<8>, 4> Lookups; |
| 8232 | if (S) { |
| 8233 | LookupResult Lookup(SemaRef, ReductionId, Sema::LookupOMPReductionName); |
| 8234 | Lookup.suppressDiagnostics(); |
| 8235 | while (S && SemaRef.LookupParsedName(Lookup, S, &ReductionIdScopeSpec)) { |
| 8236 | auto *D = Lookup.getRepresentativeDecl(); |
| 8237 | do { |
| 8238 | S = S->getParent(); |
| 8239 | } while (S && !S->isDeclScope(D)); |
| 8240 | if (S) |
| 8241 | S = S->getParent(); |
| 8242 | Lookups.push_back(UnresolvedSet<8>()); |
| 8243 | Lookups.back().append(Lookup.begin(), Lookup.end()); |
| 8244 | Lookup.clear(); |
| 8245 | } |
| 8246 | } else if (auto *ULE = |
| 8247 | cast_or_null<UnresolvedLookupExpr>(UnresolvedReduction)) { |
| 8248 | Lookups.push_back(UnresolvedSet<8>()); |
| 8249 | Decl *PrevD = nullptr; |
| 8250 | for(auto *D : ULE->decls()) { |
| 8251 | if (D == PrevD) |
| 8252 | Lookups.push_back(UnresolvedSet<8>()); |
| 8253 | else if (auto *DRD = cast<OMPDeclareReductionDecl>(D)) |
| 8254 | Lookups.back().addDecl(DRD); |
| 8255 | PrevD = D; |
| 8256 | } |
| 8257 | } |
| 8258 | if (Ty->isDependentType() || Ty->isInstantiationDependentType() || |
| 8259 | Ty->containsUnexpandedParameterPack() || |
| 8260 | filterLookupForUDR<bool>(Lookups, [](ValueDecl *D) -> bool { |
| 8261 | return !D->isInvalidDecl() && |
| 8262 | (D->getType()->isDependentType() || |
| 8263 | D->getType()->isInstantiationDependentType() || |
| 8264 | D->getType()->containsUnexpandedParameterPack()); |
| 8265 | })) { |
| 8266 | UnresolvedSet<8> ResSet; |
| 8267 | for (auto &Set : Lookups) { |
| 8268 | ResSet.append(Set.begin(), Set.end()); |
| 8269 | // The last item marks the end of all declarations at the specified scope. |
| 8270 | ResSet.addDecl(Set[Set.size() - 1]); |
| 8271 | } |
| 8272 | return UnresolvedLookupExpr::Create( |
| 8273 | SemaRef.Context, /*NamingClass=*/nullptr, |
| 8274 | ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), ReductionId, |
| 8275 | /*ADL=*/true, /*Overloaded=*/true, ResSet.begin(), ResSet.end()); |
| 8276 | } |
| 8277 | if (auto *VD = filterLookupForUDR<ValueDecl *>( |
| 8278 | Lookups, [&SemaRef, Ty](ValueDecl *D) -> ValueDecl * { |
| 8279 | if (!D->isInvalidDecl() && |
| 8280 | SemaRef.Context.hasSameType(D->getType(), Ty)) |
| 8281 | return D; |
| 8282 | return nullptr; |
| 8283 | })) |
| 8284 | return SemaRef.BuildDeclRefExpr(VD, Ty, VK_LValue, Loc); |
| 8285 | if (auto *VD = filterLookupForUDR<ValueDecl *>( |
| 8286 | Lookups, [&SemaRef, Ty, Loc](ValueDecl *D) -> ValueDecl * { |
| 8287 | if (!D->isInvalidDecl() && |
| 8288 | SemaRef.IsDerivedFrom(Loc, Ty, D->getType()) && |
| 8289 | !Ty.isMoreQualifiedThan(D->getType())) |
| 8290 | return D; |
| 8291 | return nullptr; |
| 8292 | })) { |
| 8293 | CXXBasePaths Paths(/*FindAmbiguities=*/true, /*RecordPaths=*/true, |
| 8294 | /*DetectVirtual=*/false); |
| 8295 | if (SemaRef.IsDerivedFrom(Loc, Ty, VD->getType(), Paths)) { |
| 8296 | if (!Paths.isAmbiguous(SemaRef.Context.getCanonicalType( |
| 8297 | VD->getType().getUnqualifiedType()))) { |
| 8298 | if (SemaRef.CheckBaseClassAccess(Loc, VD->getType(), Ty, Paths.front(), |
| 8299 | /*DiagID=*/0) != |
| 8300 | Sema::AR_inaccessible) { |
| 8301 | SemaRef.BuildBasePathArray(Paths, BasePath); |
| 8302 | return SemaRef.BuildDeclRefExpr(VD, Ty, VK_LValue, Loc); |
| 8303 | } |
| 8304 | } |
| 8305 | } |
| 8306 | } |
| 8307 | if (ReductionIdScopeSpec.isSet()) { |
| 8308 | SemaRef.Diag(Loc, diag::err_omp_not_resolved_reduction_identifier) << Range; |
| 8309 | return ExprError(); |
| 8310 | } |
| 8311 | return ExprEmpty(); |
| 8312 | } |
| 8313 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8314 | OMPClause *Sema::ActOnOpenMPReductionClause( |
| 8315 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, SourceLocation LParenLoc, |
| 8316 | SourceLocation ColonLoc, SourceLocation EndLoc, |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8317 | CXXScopeSpec &ReductionIdScopeSpec, const DeclarationNameInfo &ReductionId, |
| 8318 | ArrayRef<Expr *> UnresolvedReductions) { |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8319 | auto DN = ReductionId.getName(); |
| 8320 | auto OOK = DN.getCXXOverloadedOperator(); |
| 8321 | BinaryOperatorKind BOK = BO_Comma; |
| 8322 | |
| 8323 | // OpenMP [2.14.3.6, reduction clause] |
| 8324 | // C |
| 8325 | // reduction-identifier is either an identifier or one of the following |
| 8326 | // operators: +, -, *, &, |, ^, && and || |
| 8327 | // C++ |
| 8328 | // reduction-identifier is either an id-expression or one of the following |
| 8329 | // operators: +, -, *, &, |, ^, && and || |
| 8330 | // FIXME: Only 'min' and 'max' identifiers are supported for now. |
| 8331 | switch (OOK) { |
| 8332 | case OO_Plus: |
| 8333 | case OO_Minus: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8334 | BOK = BO_Add; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8335 | break; |
| 8336 | case OO_Star: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8337 | BOK = BO_Mul; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8338 | break; |
| 8339 | case OO_Amp: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8340 | BOK = BO_And; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8341 | break; |
| 8342 | case OO_Pipe: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8343 | BOK = BO_Or; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8344 | break; |
| 8345 | case OO_Caret: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8346 | BOK = BO_Xor; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8347 | break; |
| 8348 | case OO_AmpAmp: |
| 8349 | BOK = BO_LAnd; |
| 8350 | break; |
| 8351 | case OO_PipePipe: |
| 8352 | BOK = BO_LOr; |
| 8353 | break; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8354 | case OO_New: |
| 8355 | case OO_Delete: |
| 8356 | case OO_Array_New: |
| 8357 | case OO_Array_Delete: |
| 8358 | case OO_Slash: |
| 8359 | case OO_Percent: |
| 8360 | case OO_Tilde: |
| 8361 | case OO_Exclaim: |
| 8362 | case OO_Equal: |
| 8363 | case OO_Less: |
| 8364 | case OO_Greater: |
| 8365 | case OO_LessEqual: |
| 8366 | case OO_GreaterEqual: |
| 8367 | case OO_PlusEqual: |
| 8368 | case OO_MinusEqual: |
| 8369 | case OO_StarEqual: |
| 8370 | case OO_SlashEqual: |
| 8371 | case OO_PercentEqual: |
| 8372 | case OO_CaretEqual: |
| 8373 | case OO_AmpEqual: |
| 8374 | case OO_PipeEqual: |
| 8375 | case OO_LessLess: |
| 8376 | case OO_GreaterGreater: |
| 8377 | case OO_LessLessEqual: |
| 8378 | case OO_GreaterGreaterEqual: |
| 8379 | case OO_EqualEqual: |
| 8380 | case OO_ExclaimEqual: |
| 8381 | case OO_PlusPlus: |
| 8382 | case OO_MinusMinus: |
| 8383 | case OO_Comma: |
| 8384 | case OO_ArrowStar: |
| 8385 | case OO_Arrow: |
| 8386 | case OO_Call: |
| 8387 | case OO_Subscript: |
| 8388 | case OO_Conditional: |
Richard Smith | 9be594e | 2015-10-22 05:12:22 +0000 | [diff] [blame] | 8389 | case OO_Coawait: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8390 | case NUM_OVERLOADED_OPERATORS: |
| 8391 | llvm_unreachable("Unexpected reduction identifier"); |
| 8392 | case OO_None: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8393 | if (auto II = DN.getAsIdentifierInfo()) { |
| 8394 | if (II->isStr("max")) |
| 8395 | BOK = BO_GT; |
| 8396 | else if (II->isStr("min")) |
| 8397 | BOK = BO_LT; |
| 8398 | } |
| 8399 | break; |
| 8400 | } |
| 8401 | SourceRange ReductionIdRange; |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8402 | if (ReductionIdScopeSpec.isValid()) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8403 | ReductionIdRange.setBegin(ReductionIdScopeSpec.getBeginLoc()); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8404 | ReductionIdRange.setEnd(ReductionId.getEndLoc()); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8405 | |
| 8406 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8407 | SmallVector<Expr *, 8> Privates; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8408 | SmallVector<Expr *, 8> LHSs; |
| 8409 | SmallVector<Expr *, 8> RHSs; |
| 8410 | SmallVector<Expr *, 8> ReductionOps; |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 8411 | SmallVector<Decl *, 4> ExprCaptures; |
| 8412 | SmallVector<Expr *, 4> ExprPostUpdates; |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8413 | auto IR = UnresolvedReductions.begin(), ER = UnresolvedReductions.end(); |
| 8414 | bool FirstIter = true; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8415 | for (auto RefExpr : VarList) { |
| 8416 | assert(RefExpr && "nullptr expr in OpenMP reduction clause."); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8417 | // OpenMP [2.1, C/C++] |
| 8418 | // A list item is a variable or array section, subject to the restrictions |
| 8419 | // specified in Section 2.4 on page 42 and in each of the sections |
| 8420 | // describing clauses and directives for which a list appears. |
| 8421 | // OpenMP [2.14.3.3, Restrictions, p.1] |
| 8422 | // A variable that is part of another variable (as an array or |
| 8423 | // structure element) cannot appear in a private clause. |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8424 | if (!FirstIter && IR != ER) |
| 8425 | ++IR; |
| 8426 | FirstIter = false; |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8427 | SourceLocation ELoc; |
| 8428 | SourceRange ERange; |
| 8429 | Expr *SimpleRefExpr = RefExpr; |
| 8430 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange, |
| 8431 | /*AllowArraySection=*/true); |
| 8432 | if (Res.second) { |
| 8433 | // It will be analyzed later. |
| 8434 | Vars.push_back(RefExpr); |
| 8435 | Privates.push_back(nullptr); |
| 8436 | LHSs.push_back(nullptr); |
| 8437 | RHSs.push_back(nullptr); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8438 | // Try to find 'declare reduction' corresponding construct before using |
| 8439 | // builtin/overloaded operators. |
| 8440 | QualType Type = Context.DependentTy; |
| 8441 | CXXCastPath BasePath; |
| 8442 | ExprResult DeclareReductionRef = buildDeclareReductionRef( |
| 8443 | *this, ELoc, ERange, DSAStack->getCurScope(), ReductionIdScopeSpec, |
| 8444 | ReductionId, Type, BasePath, IR == ER ? nullptr : *IR); |
| 8445 | if (CurContext->isDependentContext() && |
| 8446 | (DeclareReductionRef.isUnset() || |
| 8447 | isa<UnresolvedLookupExpr>(DeclareReductionRef.get()))) |
| 8448 | ReductionOps.push_back(DeclareReductionRef.get()); |
| 8449 | else |
| 8450 | ReductionOps.push_back(nullptr); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8451 | } |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8452 | ValueDecl *D = Res.first; |
| 8453 | if (!D) |
| 8454 | continue; |
| 8455 | |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8456 | QualType Type; |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8457 | auto *ASE = dyn_cast<ArraySubscriptExpr>(RefExpr->IgnoreParens()); |
| 8458 | auto *OASE = dyn_cast<OMPArraySectionExpr>(RefExpr->IgnoreParens()); |
| 8459 | if (ASE) |
Alexey Bataev | 31300ed | 2016-02-04 11:27:03 +0000 | [diff] [blame] | 8460 | Type = ASE->getType().getNonReferenceType(); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8461 | else if (OASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8462 | auto BaseType = OMPArraySectionExpr::getBaseOriginalType(OASE->getBase()); |
| 8463 | if (auto *ATy = BaseType->getAsArrayTypeUnsafe()) |
| 8464 | Type = ATy->getElementType(); |
| 8465 | else |
| 8466 | Type = BaseType->getPointeeType(); |
Alexey Bataev | 31300ed | 2016-02-04 11:27:03 +0000 | [diff] [blame] | 8467 | Type = Type.getNonReferenceType(); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8468 | } else |
| 8469 | Type = Context.getBaseElementType(D->getType().getNonReferenceType()); |
| 8470 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8471 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8472 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 8473 | // A variable that appears in a private clause must not have an incomplete |
| 8474 | // type or a reference type. |
| 8475 | if (RequireCompleteType(ELoc, Type, |
| 8476 | diag::err_omp_reduction_incomplete_type)) |
| 8477 | continue; |
| 8478 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8479 | // A list item that appears in a reduction clause must not be |
| 8480 | // const-qualified. |
| 8481 | if (Type.getNonReferenceType().isConstant(Context)) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8482 | Diag(ELoc, diag::err_omp_const_reduction_list_item) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8483 | << getOpenMPClauseName(OMPC_reduction) << Type << ERange; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8484 | if (!ASE && !OASE) { |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8485 | bool IsDecl = !VD || |
| 8486 | VD->isThisDeclarationADefinition(Context) == |
| 8487 | VarDecl::DeclarationOnly; |
| 8488 | Diag(D->getLocation(), |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8489 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8490 | << D; |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8491 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8492 | continue; |
| 8493 | } |
| 8494 | // OpenMP [2.9.3.6, Restrictions, C/C++, p.4] |
| 8495 | // If a list-item is a reference type then it must bind to the same object |
| 8496 | // for all threads of the team. |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8497 | if (!ASE && !OASE && VD) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8498 | VarDecl *VDDef = VD->getDefinition(); |
Alexey Bataev | 31300ed | 2016-02-04 11:27:03 +0000 | [diff] [blame] | 8499 | if (VD->getType()->isReferenceType() && VDDef) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8500 | DSARefChecker Check(DSAStack); |
| 8501 | if (Check.Visit(VDDef->getInit())) { |
| 8502 | Diag(ELoc, diag::err_omp_reduction_ref_type_arg) << ERange; |
| 8503 | Diag(VDDef->getLocation(), diag::note_defined_here) << VDDef; |
| 8504 | continue; |
| 8505 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8506 | } |
| 8507 | } |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8508 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8509 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 8510 | // in a Construct] |
| 8511 | // Variables with the predetermined data-sharing attributes may not be |
| 8512 | // listed in data-sharing attributes clauses, except for the cases |
| 8513 | // listed below. For these exceptions only, listing a predetermined |
| 8514 | // variable in a data-sharing attribute clause is allowed and overrides |
| 8515 | // the variable's predetermined data-sharing attributes. |
| 8516 | // OpenMP [2.14.3.6, Restrictions, p.3] |
| 8517 | // Any number of reduction clauses can be specified on the directive, |
| 8518 | // but a list item can appear only once in the reduction clauses for that |
| 8519 | // directive. |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8520 | DSAStackTy::DSAVarData DVar; |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8521 | DVar = DSAStack->getTopDSA(D, false); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8522 | if (DVar.CKind == OMPC_reduction) { |
| 8523 | Diag(ELoc, diag::err_omp_once_referenced) |
| 8524 | << getOpenMPClauseName(OMPC_reduction); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8525 | if (DVar.RefExpr) |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8526 | Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_referenced); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8527 | } else if (DVar.CKind != OMPC_unknown) { |
| 8528 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 8529 | << getOpenMPClauseName(DVar.CKind) |
| 8530 | << getOpenMPClauseName(OMPC_reduction); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8531 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8532 | continue; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8533 | } |
| 8534 | |
| 8535 | // OpenMP [2.14.3.6, Restrictions, p.1] |
| 8536 | // A list item that appears in a reduction clause of a worksharing |
| 8537 | // construct must be shared in the parallel regions to which any of the |
| 8538 | // worksharing regions arising from the worksharing construct bind. |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8539 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
| 8540 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 8541 | !isOpenMPParallelDirective(CurrDir)) { |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8542 | DVar = DSAStack->getImplicitDSA(D, true); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8543 | if (DVar.CKind != OMPC_shared) { |
| 8544 | Diag(ELoc, diag::err_omp_required_access) |
| 8545 | << getOpenMPClauseName(OMPC_reduction) |
| 8546 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8547 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8548 | continue; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 8549 | } |
| 8550 | } |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8551 | |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8552 | // Try to find 'declare reduction' corresponding construct before using |
| 8553 | // builtin/overloaded operators. |
| 8554 | CXXCastPath BasePath; |
| 8555 | ExprResult DeclareReductionRef = buildDeclareReductionRef( |
| 8556 | *this, ELoc, ERange, DSAStack->getCurScope(), ReductionIdScopeSpec, |
| 8557 | ReductionId, Type, BasePath, IR == ER ? nullptr : *IR); |
| 8558 | if (DeclareReductionRef.isInvalid()) |
| 8559 | continue; |
| 8560 | if (CurContext->isDependentContext() && |
| 8561 | (DeclareReductionRef.isUnset() || |
| 8562 | isa<UnresolvedLookupExpr>(DeclareReductionRef.get()))) { |
| 8563 | Vars.push_back(RefExpr); |
| 8564 | Privates.push_back(nullptr); |
| 8565 | LHSs.push_back(nullptr); |
| 8566 | RHSs.push_back(nullptr); |
| 8567 | ReductionOps.push_back(DeclareReductionRef.get()); |
| 8568 | continue; |
| 8569 | } |
| 8570 | if (BOK == BO_Comma && DeclareReductionRef.isUnset()) { |
| 8571 | // Not allowed reduction identifier is found. |
| 8572 | Diag(ReductionId.getLocStart(), |
| 8573 | diag::err_omp_unknown_reduction_identifier) |
| 8574 | << Type << ReductionIdRange; |
| 8575 | continue; |
| 8576 | } |
| 8577 | |
| 8578 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
| 8579 | // The type of a list item that appears in a reduction clause must be valid |
| 8580 | // for the reduction-identifier. For a max or min reduction in C, the type |
| 8581 | // of the list item must be an allowed arithmetic data type: char, int, |
| 8582 | // float, double, or _Bool, possibly modified with long, short, signed, or |
| 8583 | // unsigned. For a max or min reduction in C++, the type of the list item |
| 8584 | // must be an allowed arithmetic data type: char, wchar_t, int, float, |
| 8585 | // double, or bool, possibly modified with long, short, signed, or unsigned. |
| 8586 | if (DeclareReductionRef.isUnset()) { |
| 8587 | if ((BOK == BO_GT || BOK == BO_LT) && |
| 8588 | !(Type->isScalarType() || |
| 8589 | (getLangOpts().CPlusPlus && Type->isArithmeticType()))) { |
| 8590 | Diag(ELoc, diag::err_omp_clause_not_arithmetic_type_arg) |
| 8591 | << getLangOpts().CPlusPlus; |
| 8592 | if (!ASE && !OASE) { |
| 8593 | bool IsDecl = !VD || |
| 8594 | VD->isThisDeclarationADefinition(Context) == |
| 8595 | VarDecl::DeclarationOnly; |
| 8596 | Diag(D->getLocation(), |
| 8597 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 8598 | << D; |
| 8599 | } |
| 8600 | continue; |
| 8601 | } |
| 8602 | if ((BOK == BO_OrAssign || BOK == BO_AndAssign || BOK == BO_XorAssign) && |
| 8603 | !getLangOpts().CPlusPlus && Type->isFloatingType()) { |
| 8604 | Diag(ELoc, diag::err_omp_clause_floating_type_arg); |
| 8605 | if (!ASE && !OASE) { |
| 8606 | bool IsDecl = !VD || |
| 8607 | VD->isThisDeclarationADefinition(Context) == |
| 8608 | VarDecl::DeclarationOnly; |
| 8609 | Diag(D->getLocation(), |
| 8610 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 8611 | << D; |
| 8612 | } |
| 8613 | continue; |
| 8614 | } |
| 8615 | } |
| 8616 | |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8617 | Type = Type.getNonLValueExprType(Context).getUnqualifiedType(); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8618 | auto *LHSVD = buildVarDecl(*this, ELoc, Type, ".reduction.lhs", |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8619 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 8620 | auto *RHSVD = buildVarDecl(*this, ELoc, Type, D->getName(), |
| 8621 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8622 | auto PrivateTy = Type; |
Alexey Bataev | 1189bd0 | 2016-01-26 12:20:39 +0000 | [diff] [blame] | 8623 | if (OASE || |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8624 | (!ASE && |
| 8625 | D->getType().getNonReferenceType()->isVariablyModifiedType())) { |
Alexey Bataev | 1189bd0 | 2016-01-26 12:20:39 +0000 | [diff] [blame] | 8626 | // For arays/array sections only: |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8627 | // Create pseudo array type for private copy. The size for this array will |
| 8628 | // be generated during codegen. |
| 8629 | // For array subscripts or single variables Private Ty is the same as Type |
| 8630 | // (type of the variable or single array element). |
| 8631 | PrivateTy = Context.getVariableArrayType( |
| 8632 | Type, new (Context) OpaqueValueExpr(SourceLocation(), |
| 8633 | Context.getSizeType(), VK_RValue), |
| 8634 | ArrayType::Normal, /*IndexTypeQuals=*/0, SourceRange()); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8635 | } else if (!ASE && !OASE && |
| 8636 | Context.getAsArrayType(D->getType().getNonReferenceType())) |
| 8637 | PrivateTy = D->getType().getNonReferenceType(); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8638 | // Private copy. |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8639 | auto *PrivateVD = buildVarDecl(*this, ELoc, PrivateTy, D->getName(), |
| 8640 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8641 | // Add initializer for private variable. |
| 8642 | Expr *Init = nullptr; |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8643 | auto *LHSDRE = buildDeclRefExpr(*this, LHSVD, Type, ELoc); |
| 8644 | auto *RHSDRE = buildDeclRefExpr(*this, RHSVD, Type, ELoc); |
| 8645 | if (DeclareReductionRef.isUsable()) { |
| 8646 | auto *DRDRef = DeclareReductionRef.getAs<DeclRefExpr>(); |
| 8647 | auto *DRD = cast<OMPDeclareReductionDecl>(DRDRef->getDecl()); |
| 8648 | if (DRD->getInitializer()) { |
| 8649 | Init = DRDRef; |
| 8650 | RHSVD->setInit(DRDRef); |
| 8651 | RHSVD->setInitStyle(VarDecl::CallInit); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8652 | } |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8653 | } else { |
| 8654 | switch (BOK) { |
| 8655 | case BO_Add: |
| 8656 | case BO_Xor: |
| 8657 | case BO_Or: |
| 8658 | case BO_LOr: |
| 8659 | // '+', '-', '^', '|', '||' reduction ops - initializer is '0'. |
| 8660 | if (Type->isScalarType() || Type->isAnyComplexType()) |
| 8661 | Init = ActOnIntegerConstant(ELoc, /*Val=*/0).get(); |
| 8662 | break; |
| 8663 | case BO_Mul: |
| 8664 | case BO_LAnd: |
| 8665 | if (Type->isScalarType() || Type->isAnyComplexType()) { |
| 8666 | // '*' and '&&' reduction ops - initializer is '1'. |
| 8667 | Init = ActOnIntegerConstant(ELoc, /*Val=*/1).get(); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8668 | } |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8669 | break; |
| 8670 | case BO_And: { |
| 8671 | // '&' reduction op - initializer is '~0'. |
| 8672 | QualType OrigType = Type; |
| 8673 | if (auto *ComplexTy = OrigType->getAs<ComplexType>()) |
| 8674 | Type = ComplexTy->getElementType(); |
| 8675 | if (Type->isRealFloatingType()) { |
| 8676 | llvm::APFloat InitValue = |
| 8677 | llvm::APFloat::getAllOnesValue(Context.getTypeSize(Type), |
| 8678 | /*isIEEE=*/true); |
| 8679 | Init = FloatingLiteral::Create(Context, InitValue, /*isexact=*/true, |
| 8680 | Type, ELoc); |
| 8681 | } else if (Type->isScalarType()) { |
| 8682 | auto Size = Context.getTypeSize(Type); |
| 8683 | QualType IntTy = Context.getIntTypeForBitwidth(Size, /*Signed=*/0); |
| 8684 | llvm::APInt InitValue = llvm::APInt::getAllOnesValue(Size); |
| 8685 | Init = IntegerLiteral::Create(Context, InitValue, IntTy, ELoc); |
| 8686 | } |
| 8687 | if (Init && OrigType->isAnyComplexType()) { |
| 8688 | // Init = 0xFFFF + 0xFFFFi; |
| 8689 | auto *Im = new (Context) ImaginaryLiteral(Init, OrigType); |
| 8690 | Init = CreateBuiltinBinOp(ELoc, BO_Add, Init, Im).get(); |
| 8691 | } |
| 8692 | Type = OrigType; |
| 8693 | break; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8694 | } |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8695 | case BO_LT: |
| 8696 | case BO_GT: { |
| 8697 | // 'min' reduction op - initializer is 'Largest representable number in |
| 8698 | // the reduction list item type'. |
| 8699 | // 'max' reduction op - initializer is 'Least representable number in |
| 8700 | // the reduction list item type'. |
| 8701 | if (Type->isIntegerType() || Type->isPointerType()) { |
| 8702 | bool IsSigned = Type->hasSignedIntegerRepresentation(); |
| 8703 | auto Size = Context.getTypeSize(Type); |
| 8704 | QualType IntTy = |
| 8705 | Context.getIntTypeForBitwidth(Size, /*Signed=*/IsSigned); |
| 8706 | llvm::APInt InitValue = |
| 8707 | (BOK != BO_LT) |
| 8708 | ? IsSigned ? llvm::APInt::getSignedMinValue(Size) |
| 8709 | : llvm::APInt::getMinValue(Size) |
| 8710 | : IsSigned ? llvm::APInt::getSignedMaxValue(Size) |
| 8711 | : llvm::APInt::getMaxValue(Size); |
| 8712 | Init = IntegerLiteral::Create(Context, InitValue, IntTy, ELoc); |
| 8713 | if (Type->isPointerType()) { |
| 8714 | // Cast to pointer type. |
| 8715 | auto CastExpr = BuildCStyleCastExpr( |
| 8716 | SourceLocation(), Context.getTrivialTypeSourceInfo(Type, ELoc), |
| 8717 | SourceLocation(), Init); |
| 8718 | if (CastExpr.isInvalid()) |
| 8719 | continue; |
| 8720 | Init = CastExpr.get(); |
| 8721 | } |
| 8722 | } else if (Type->isRealFloatingType()) { |
| 8723 | llvm::APFloat InitValue = llvm::APFloat::getLargest( |
| 8724 | Context.getFloatTypeSemantics(Type), BOK != BO_LT); |
| 8725 | Init = FloatingLiteral::Create(Context, InitValue, /*isexact=*/true, |
| 8726 | Type, ELoc); |
| 8727 | } |
| 8728 | break; |
| 8729 | } |
| 8730 | case BO_PtrMemD: |
| 8731 | case BO_PtrMemI: |
| 8732 | case BO_MulAssign: |
| 8733 | case BO_Div: |
| 8734 | case BO_Rem: |
| 8735 | case BO_Sub: |
| 8736 | case BO_Shl: |
| 8737 | case BO_Shr: |
| 8738 | case BO_LE: |
| 8739 | case BO_GE: |
| 8740 | case BO_EQ: |
| 8741 | case BO_NE: |
| 8742 | case BO_AndAssign: |
| 8743 | case BO_XorAssign: |
| 8744 | case BO_OrAssign: |
| 8745 | case BO_Assign: |
| 8746 | case BO_AddAssign: |
| 8747 | case BO_SubAssign: |
| 8748 | case BO_DivAssign: |
| 8749 | case BO_RemAssign: |
| 8750 | case BO_ShlAssign: |
| 8751 | case BO_ShrAssign: |
| 8752 | case BO_Comma: |
| 8753 | llvm_unreachable("Unexpected reduction operation"); |
| 8754 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8755 | } |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8756 | if (Init && DeclareReductionRef.isUnset()) { |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8757 | AddInitializerToDecl(RHSVD, Init, /*DirectInit=*/false, |
| 8758 | /*TypeMayContainAuto=*/false); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8759 | } else if (!Init) |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8760 | ActOnUninitializedDecl(RHSVD, /*TypeMayContainAuto=*/false); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8761 | if (RHSVD->isInvalidDecl()) |
| 8762 | continue; |
| 8763 | if (!RHSVD->hasInit() && DeclareReductionRef.isUnset()) { |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8764 | Diag(ELoc, diag::err_omp_reduction_id_not_compatible) << Type |
| 8765 | << ReductionIdRange; |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8766 | bool IsDecl = |
| 8767 | !VD || |
| 8768 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 8769 | Diag(D->getLocation(), |
| 8770 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 8771 | << D; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8772 | continue; |
| 8773 | } |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8774 | // Store initializer for single element in private copy. Will be used during |
| 8775 | // codegen. |
| 8776 | PrivateVD->setInit(RHSVD->getInit()); |
| 8777 | PrivateVD->setInitStyle(RHSVD->getInitStyle()); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8778 | auto *PrivateDRE = buildDeclRefExpr(*this, PrivateVD, PrivateTy, ELoc); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8779 | ExprResult ReductionOp; |
| 8780 | if (DeclareReductionRef.isUsable()) { |
| 8781 | QualType RedTy = DeclareReductionRef.get()->getType(); |
| 8782 | QualType PtrRedTy = Context.getPointerType(RedTy); |
| 8783 | ExprResult LHS = CreateBuiltinUnaryOp(ELoc, UO_AddrOf, LHSDRE); |
| 8784 | ExprResult RHS = CreateBuiltinUnaryOp(ELoc, UO_AddrOf, RHSDRE); |
| 8785 | if (!BasePath.empty()) { |
| 8786 | LHS = DefaultLvalueConversion(LHS.get()); |
| 8787 | RHS = DefaultLvalueConversion(RHS.get()); |
| 8788 | LHS = ImplicitCastExpr::Create(Context, PtrRedTy, |
| 8789 | CK_UncheckedDerivedToBase, LHS.get(), |
| 8790 | &BasePath, LHS.get()->getValueKind()); |
| 8791 | RHS = ImplicitCastExpr::Create(Context, PtrRedTy, |
| 8792 | CK_UncheckedDerivedToBase, RHS.get(), |
| 8793 | &BasePath, RHS.get()->getValueKind()); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8794 | } |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8795 | FunctionProtoType::ExtProtoInfo EPI; |
| 8796 | QualType Params[] = {PtrRedTy, PtrRedTy}; |
| 8797 | QualType FnTy = Context.getFunctionType(Context.VoidTy, Params, EPI); |
| 8798 | auto *OVE = new (Context) OpaqueValueExpr( |
| 8799 | ELoc, Context.getPointerType(FnTy), VK_RValue, OK_Ordinary, |
| 8800 | DefaultLvalueConversion(DeclareReductionRef.get()).get()); |
| 8801 | Expr *Args[] = {LHS.get(), RHS.get()}; |
| 8802 | ReductionOp = new (Context) |
| 8803 | CallExpr(Context, OVE, Args, Context.VoidTy, VK_RValue, ELoc); |
| 8804 | } else { |
| 8805 | ReductionOp = BuildBinOp(DSAStack->getCurScope(), |
| 8806 | ReductionId.getLocStart(), BOK, LHSDRE, RHSDRE); |
| 8807 | if (ReductionOp.isUsable()) { |
| 8808 | if (BOK != BO_LT && BOK != BO_GT) { |
| 8809 | ReductionOp = |
| 8810 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), |
| 8811 | BO_Assign, LHSDRE, ReductionOp.get()); |
| 8812 | } else { |
| 8813 | auto *ConditionalOp = new (Context) ConditionalOperator( |
| 8814 | ReductionOp.get(), SourceLocation(), LHSDRE, SourceLocation(), |
| 8815 | RHSDRE, Type, VK_LValue, OK_Ordinary); |
| 8816 | ReductionOp = |
| 8817 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), |
| 8818 | BO_Assign, LHSDRE, ConditionalOp); |
| 8819 | } |
| 8820 | ReductionOp = ActOnFinishFullExpr(ReductionOp.get()); |
| 8821 | } |
| 8822 | if (ReductionOp.isInvalid()) |
| 8823 | continue; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8824 | } |
| 8825 | |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8826 | DeclRefExpr *Ref = nullptr; |
| 8827 | Expr *VarsExpr = RefExpr->IgnoreParens(); |
| 8828 | if (!VD) { |
| 8829 | if (ASE || OASE) { |
| 8830 | TransformExprToCaptures RebuildToCapture(*this, D); |
| 8831 | VarsExpr = |
| 8832 | RebuildToCapture.TransformExpr(RefExpr->IgnoreParens()).get(); |
| 8833 | Ref = RebuildToCapture.getCapturedExpr(); |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 8834 | } else { |
| 8835 | VarsExpr = Ref = |
| 8836 | buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false); |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 8837 | } |
| 8838 | if (!IsOpenMPCapturedDecl(D)) { |
| 8839 | ExprCaptures.push_back(Ref->getDecl()); |
| 8840 | if (Ref->getDecl()->hasAttr<OMPCaptureNoInitAttr>()) { |
| 8841 | ExprResult RefRes = DefaultLvalueConversion(Ref); |
| 8842 | if (!RefRes.isUsable()) |
| 8843 | continue; |
| 8844 | ExprResult PostUpdateRes = |
| 8845 | BuildBinOp(DSAStack->getCurScope(), ELoc, BO_Assign, |
| 8846 | SimpleRefExpr, RefRes.get()); |
| 8847 | if (!PostUpdateRes.isUsable()) |
| 8848 | continue; |
| 8849 | ExprPostUpdates.push_back( |
| 8850 | IgnoredValueConversions(PostUpdateRes.get()).get()); |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 8851 | } |
| 8852 | } |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8853 | } |
| 8854 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_reduction, Ref); |
| 8855 | Vars.push_back(VarsExpr); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8856 | Privates.push_back(PrivateDRE); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8857 | LHSs.push_back(LHSDRE); |
| 8858 | RHSs.push_back(RHSDRE); |
| 8859 | ReductionOps.push_back(ReductionOp.get()); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8860 | } |
| 8861 | |
| 8862 | if (Vars.empty()) |
| 8863 | return nullptr; |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 8864 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8865 | return OMPReductionClause::Create( |
| 8866 | Context, StartLoc, LParenLoc, ColonLoc, EndLoc, Vars, |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8867 | ReductionIdScopeSpec.getWithLocInContext(Context), ReductionId, Privates, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 8868 | LHSs, RHSs, ReductionOps, buildPreInits(Context, ExprCaptures), |
| 8869 | buildPostUpdate(*this, ExprPostUpdates)); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8870 | } |
| 8871 | |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 8872 | bool Sema::CheckOpenMPLinearModifier(OpenMPLinearClauseKind LinKind, |
| 8873 | SourceLocation LinLoc) { |
| 8874 | if ((!LangOpts.CPlusPlus && LinKind != OMPC_LINEAR_val) || |
| 8875 | LinKind == OMPC_LINEAR_unknown) { |
| 8876 | Diag(LinLoc, diag::err_omp_wrong_linear_modifier) << LangOpts.CPlusPlus; |
| 8877 | return true; |
| 8878 | } |
| 8879 | return false; |
| 8880 | } |
| 8881 | |
| 8882 | bool Sema::CheckOpenMPLinearDecl(ValueDecl *D, SourceLocation ELoc, |
| 8883 | OpenMPLinearClauseKind LinKind, |
| 8884 | QualType Type) { |
| 8885 | auto *VD = dyn_cast_or_null<VarDecl>(D); |
| 8886 | // A variable must not have an incomplete type or a reference type. |
| 8887 | if (RequireCompleteType(ELoc, Type, diag::err_omp_linear_incomplete_type)) |
| 8888 | return true; |
| 8889 | if ((LinKind == OMPC_LINEAR_uval || LinKind == OMPC_LINEAR_ref) && |
| 8890 | !Type->isReferenceType()) { |
| 8891 | Diag(ELoc, diag::err_omp_wrong_linear_modifier_non_reference) |
| 8892 | << Type << getOpenMPSimpleClauseTypeName(OMPC_linear, LinKind); |
| 8893 | return true; |
| 8894 | } |
| 8895 | Type = Type.getNonReferenceType(); |
| 8896 | |
| 8897 | // A list item must not be const-qualified. |
| 8898 | if (Type.isConstant(Context)) { |
| 8899 | Diag(ELoc, diag::err_omp_const_variable) |
| 8900 | << getOpenMPClauseName(OMPC_linear); |
| 8901 | if (D) { |
| 8902 | bool IsDecl = |
| 8903 | !VD || |
| 8904 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 8905 | Diag(D->getLocation(), |
| 8906 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 8907 | << D; |
| 8908 | } |
| 8909 | return true; |
| 8910 | } |
| 8911 | |
| 8912 | // A list item must be of integral or pointer type. |
| 8913 | Type = Type.getUnqualifiedType().getCanonicalType(); |
| 8914 | const auto *Ty = Type.getTypePtrOrNull(); |
| 8915 | if (!Ty || (!Ty->isDependentType() && !Ty->isIntegralType(Context) && |
| 8916 | !Ty->isPointerType())) { |
| 8917 | Diag(ELoc, diag::err_omp_linear_expected_int_or_ptr) << Type; |
| 8918 | if (D) { |
| 8919 | bool IsDecl = |
| 8920 | !VD || |
| 8921 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 8922 | Diag(D->getLocation(), |
| 8923 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 8924 | << D; |
| 8925 | } |
| 8926 | return true; |
| 8927 | } |
| 8928 | return false; |
| 8929 | } |
| 8930 | |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 8931 | OMPClause *Sema::ActOnOpenMPLinearClause( |
| 8932 | ArrayRef<Expr *> VarList, Expr *Step, SourceLocation StartLoc, |
| 8933 | SourceLocation LParenLoc, OpenMPLinearClauseKind LinKind, |
| 8934 | SourceLocation LinLoc, SourceLocation ColonLoc, SourceLocation EndLoc) { |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8935 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8936 | SmallVector<Expr *, 8> Privates; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8937 | SmallVector<Expr *, 8> Inits; |
Alexey Bataev | 78849fb | 2016-03-09 09:49:00 +0000 | [diff] [blame] | 8938 | SmallVector<Decl *, 4> ExprCaptures; |
| 8939 | SmallVector<Expr *, 4> ExprPostUpdates; |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 8940 | if (CheckOpenMPLinearModifier(LinKind, LinLoc)) |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 8941 | LinKind = OMPC_LINEAR_val; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8942 | for (auto &RefExpr : VarList) { |
| 8943 | assert(RefExpr && "NULL expr in OpenMP linear clause."); |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8944 | SourceLocation ELoc; |
| 8945 | SourceRange ERange; |
| 8946 | Expr *SimpleRefExpr = RefExpr; |
| 8947 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange, |
| 8948 | /*AllowArraySection=*/false); |
| 8949 | if (Res.second) { |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8950 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8951 | Vars.push_back(RefExpr); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8952 | Privates.push_back(nullptr); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8953 | Inits.push_back(nullptr); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8954 | } |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8955 | ValueDecl *D = Res.first; |
| 8956 | if (!D) |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8957 | continue; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8958 | |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8959 | QualType Type = D->getType(); |
| 8960 | auto *VD = dyn_cast<VarDecl>(D); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8961 | |
| 8962 | // OpenMP [2.14.3.7, linear clause] |
| 8963 | // A list-item cannot appear in more than one linear clause. |
| 8964 | // A list-item that appears in a linear clause cannot appear in any |
| 8965 | // other data-sharing attribute clause. |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8966 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8967 | if (DVar.RefExpr) { |
| 8968 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 8969 | << getOpenMPClauseName(OMPC_linear); |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8970 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8971 | continue; |
| 8972 | } |
| 8973 | |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 8974 | if (CheckOpenMPLinearDecl(D, ELoc, LinKind, Type)) |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8975 | continue; |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 8976 | Type = Type.getNonReferenceType().getUnqualifiedType().getCanonicalType(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8977 | |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8978 | // Build private copy of original var. |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8979 | auto *Private = buildVarDecl(*this, ELoc, Type, D->getName(), |
| 8980 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 8981 | auto *PrivateRef = buildDeclRefExpr(*this, Private, Type, ELoc); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8982 | // Build var to save initial value. |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8983 | VarDecl *Init = buildVarDecl(*this, ELoc, Type, ".linear.start"); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 8984 | Expr *InitExpr; |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8985 | DeclRefExpr *Ref = nullptr; |
Alexey Bataev | 78849fb | 2016-03-09 09:49:00 +0000 | [diff] [blame] | 8986 | if (!VD) { |
| 8987 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false); |
| 8988 | if (!IsOpenMPCapturedDecl(D)) { |
| 8989 | ExprCaptures.push_back(Ref->getDecl()); |
| 8990 | if (Ref->getDecl()->hasAttr<OMPCaptureNoInitAttr>()) { |
| 8991 | ExprResult RefRes = DefaultLvalueConversion(Ref); |
| 8992 | if (!RefRes.isUsable()) |
| 8993 | continue; |
| 8994 | ExprResult PostUpdateRes = |
| 8995 | BuildBinOp(DSAStack->getCurScope(), ELoc, BO_Assign, |
| 8996 | SimpleRefExpr, RefRes.get()); |
| 8997 | if (!PostUpdateRes.isUsable()) |
| 8998 | continue; |
| 8999 | ExprPostUpdates.push_back( |
| 9000 | IgnoredValueConversions(PostUpdateRes.get()).get()); |
| 9001 | } |
| 9002 | } |
| 9003 | } |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 9004 | if (LinKind == OMPC_LINEAR_uval) |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 9005 | InitExpr = VD ? VD->getInit() : SimpleRefExpr; |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 9006 | else |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 9007 | InitExpr = VD ? SimpleRefExpr : Ref; |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 9008 | AddInitializerToDecl(Init, DefaultLvalueConversion(InitExpr).get(), |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 9009 | /*DirectInit=*/false, /*TypeMayContainAuto=*/false); |
| 9010 | auto InitRef = buildDeclRefExpr(*this, Init, Type, ELoc); |
| 9011 | |
| 9012 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_linear, Ref); |
| 9013 | Vars.push_back(VD ? RefExpr->IgnoreParens() : Ref); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 9014 | Privates.push_back(PrivateRef); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9015 | Inits.push_back(InitRef); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9016 | } |
| 9017 | |
| 9018 | if (Vars.empty()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 9019 | return nullptr; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9020 | |
| 9021 | Expr *StepExpr = Step; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9022 | Expr *CalcStepExpr = nullptr; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9023 | if (Step && !Step->isValueDependent() && !Step->isTypeDependent() && |
| 9024 | !Step->isInstantiationDependent() && |
| 9025 | !Step->containsUnexpandedParameterPack()) { |
| 9026 | SourceLocation StepLoc = Step->getLocStart(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 9027 | ExprResult Val = PerformOpenMPImplicitIntegerConversion(StepLoc, Step); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9028 | if (Val.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 9029 | return nullptr; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 9030 | StepExpr = Val.get(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9031 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9032 | // Build var to save the step value. |
| 9033 | VarDecl *SaveVar = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 9034 | buildVarDecl(*this, StepLoc, StepExpr->getType(), ".linear.step"); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9035 | ExprResult SaveRef = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 9036 | buildDeclRefExpr(*this, SaveVar, StepExpr->getType(), StepLoc); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9037 | ExprResult CalcStep = |
| 9038 | BuildBinOp(CurScope, StepLoc, BO_Assign, SaveRef.get(), StepExpr); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 9039 | CalcStep = ActOnFinishFullExpr(CalcStep.get()); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9040 | |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9041 | // Warn about zero linear step (it would be probably better specified as |
| 9042 | // making corresponding variables 'const'). |
| 9043 | llvm::APSInt Result; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9044 | bool IsConstant = StepExpr->isIntegerConstantExpr(Result, Context); |
| 9045 | if (IsConstant && !Result.isNegative() && !Result.isStrictlyPositive()) |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9046 | Diag(StepLoc, diag::warn_omp_linear_step_zero) << Vars[0] |
| 9047 | << (Vars.size() > 1); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9048 | if (!IsConstant && CalcStep.isUsable()) { |
| 9049 | // Calculate the step beforehand instead of doing this on each iteration. |
| 9050 | // (This is not used if the number of iterations may be kfold-ed). |
| 9051 | CalcStepExpr = CalcStep.get(); |
| 9052 | } |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9053 | } |
| 9054 | |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 9055 | return OMPLinearClause::Create(Context, StartLoc, LParenLoc, LinKind, LinLoc, |
| 9056 | ColonLoc, EndLoc, Vars, Privates, Inits, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 9057 | StepExpr, CalcStepExpr, |
| 9058 | buildPreInits(Context, ExprCaptures), |
| 9059 | buildPostUpdate(*this, ExprPostUpdates)); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9060 | } |
| 9061 | |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 9062 | static bool FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV, |
| 9063 | Expr *NumIterations, Sema &SemaRef, |
| 9064 | Scope *S, DSAStackTy *Stack) { |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9065 | // Walk the vars and build update/final expressions for the CodeGen. |
| 9066 | SmallVector<Expr *, 8> Updates; |
| 9067 | SmallVector<Expr *, 8> Finals; |
| 9068 | Expr *Step = Clause.getStep(); |
| 9069 | Expr *CalcStep = Clause.getCalcStep(); |
| 9070 | // OpenMP [2.14.3.7, linear clause] |
| 9071 | // If linear-step is not specified it is assumed to be 1. |
| 9072 | if (Step == nullptr) |
| 9073 | Step = SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get(); |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 9074 | else if (CalcStep) { |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9075 | Step = cast<BinaryOperator>(CalcStep)->getLHS(); |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 9076 | } |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9077 | bool HasErrors = false; |
| 9078 | auto CurInit = Clause.inits().begin(); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 9079 | auto CurPrivate = Clause.privates().begin(); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 9080 | auto LinKind = Clause.getModifier(); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9081 | for (auto &RefExpr : Clause.varlists()) { |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 9082 | SourceLocation ELoc; |
| 9083 | SourceRange ERange; |
| 9084 | Expr *SimpleRefExpr = RefExpr; |
| 9085 | auto Res = getPrivateItem(SemaRef, SimpleRefExpr, ELoc, ERange, |
| 9086 | /*AllowArraySection=*/false); |
| 9087 | ValueDecl *D = Res.first; |
| 9088 | if (Res.second || !D) { |
| 9089 | Updates.push_back(nullptr); |
| 9090 | Finals.push_back(nullptr); |
| 9091 | HasErrors = true; |
| 9092 | continue; |
| 9093 | } |
| 9094 | if (auto *CED = dyn_cast<OMPCapturedExprDecl>(D)) { |
| 9095 | D = cast<MemberExpr>(CED->getInit()->IgnoreParenImpCasts()) |
| 9096 | ->getMemberDecl(); |
| 9097 | } |
| 9098 | auto &&Info = Stack->isLoopControlVariable(D); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9099 | Expr *InitExpr = *CurInit; |
| 9100 | |
| 9101 | // Build privatized reference to the current linear var. |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 9102 | auto DE = cast<DeclRefExpr>(SimpleRefExpr); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 9103 | Expr *CapturedRef; |
| 9104 | if (LinKind == OMPC_LINEAR_uval) |
| 9105 | CapturedRef = cast<VarDecl>(DE->getDecl())->getInit(); |
| 9106 | else |
| 9107 | CapturedRef = |
| 9108 | buildDeclRefExpr(SemaRef, cast<VarDecl>(DE->getDecl()), |
| 9109 | DE->getType().getUnqualifiedType(), DE->getExprLoc(), |
| 9110 | /*RefersToCapture=*/true); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9111 | |
| 9112 | // Build update: Var = InitExpr + IV * Step |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 9113 | ExprResult Update; |
| 9114 | if (!Info.first) { |
| 9115 | Update = |
| 9116 | BuildCounterUpdate(SemaRef, S, RefExpr->getExprLoc(), *CurPrivate, |
| 9117 | InitExpr, IV, Step, /* Subtract */ false); |
| 9118 | } else |
| 9119 | Update = *CurPrivate; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 9120 | Update = SemaRef.ActOnFinishFullExpr(Update.get(), DE->getLocStart(), |
| 9121 | /*DiscardedValue=*/true); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9122 | |
| 9123 | // Build final: Var = InitExpr + NumIterations * Step |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 9124 | ExprResult Final; |
| 9125 | if (!Info.first) { |
| 9126 | Final = BuildCounterUpdate(SemaRef, S, RefExpr->getExprLoc(), CapturedRef, |
| 9127 | InitExpr, NumIterations, Step, |
| 9128 | /* Subtract */ false); |
| 9129 | } else |
| 9130 | Final = *CurPrivate; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 9131 | Final = SemaRef.ActOnFinishFullExpr(Final.get(), DE->getLocStart(), |
| 9132 | /*DiscardedValue=*/true); |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 9133 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9134 | if (!Update.isUsable() || !Final.isUsable()) { |
| 9135 | Updates.push_back(nullptr); |
| 9136 | Finals.push_back(nullptr); |
| 9137 | HasErrors = true; |
| 9138 | } else { |
| 9139 | Updates.push_back(Update.get()); |
| 9140 | Finals.push_back(Final.get()); |
| 9141 | } |
Richard Trieu | cc3949d | 2016-02-18 22:34:54 +0000 | [diff] [blame] | 9142 | ++CurInit; |
| 9143 | ++CurPrivate; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9144 | } |
| 9145 | Clause.setUpdates(Updates); |
| 9146 | Clause.setFinals(Finals); |
| 9147 | return HasErrors; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9148 | } |
| 9149 | |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9150 | OMPClause *Sema::ActOnOpenMPAlignedClause( |
| 9151 | ArrayRef<Expr *> VarList, Expr *Alignment, SourceLocation StartLoc, |
| 9152 | SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc) { |
| 9153 | |
| 9154 | SmallVector<Expr *, 8> Vars; |
| 9155 | for (auto &RefExpr : VarList) { |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 9156 | assert(RefExpr && "NULL expr in OpenMP linear clause."); |
| 9157 | SourceLocation ELoc; |
| 9158 | SourceRange ERange; |
| 9159 | Expr *SimpleRefExpr = RefExpr; |
| 9160 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange, |
| 9161 | /*AllowArraySection=*/false); |
| 9162 | if (Res.second) { |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9163 | // It will be analyzed later. |
| 9164 | Vars.push_back(RefExpr); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9165 | } |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 9166 | ValueDecl *D = Res.first; |
| 9167 | if (!D) |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9168 | continue; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9169 | |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 9170 | QualType QType = D->getType(); |
| 9171 | auto *VD = dyn_cast<VarDecl>(D); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9172 | |
| 9173 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 9174 | // The type of list items appearing in the aligned clause must be |
| 9175 | // array, pointer, reference to array, or reference to pointer. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 9176 | QType = QType.getNonReferenceType().getUnqualifiedType().getCanonicalType(); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9177 | const Type *Ty = QType.getTypePtrOrNull(); |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 9178 | if (!Ty || (!Ty->isArrayType() && !Ty->isPointerType())) { |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9179 | Diag(ELoc, diag::err_omp_aligned_expected_array_or_ptr) |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 9180 | << QType << getLangOpts().CPlusPlus << ERange; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9181 | bool IsDecl = |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 9182 | !VD || |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9183 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 9184 | Diag(D->getLocation(), |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9185 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 9186 | << D; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9187 | continue; |
| 9188 | } |
| 9189 | |
| 9190 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 9191 | // A list-item cannot appear in more than one aligned clause. |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 9192 | if (Expr *PrevRef = DSAStack->addUniqueAligned(D, SimpleRefExpr)) { |
Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 9193 | Diag(ELoc, diag::err_omp_aligned_twice) << 0 << ERange; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9194 | Diag(PrevRef->getExprLoc(), diag::note_omp_explicit_dsa) |
| 9195 | << getOpenMPClauseName(OMPC_aligned); |
| 9196 | continue; |
| 9197 | } |
| 9198 | |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 9199 | DeclRefExpr *Ref = nullptr; |
| 9200 | if (!VD && IsOpenMPCapturedDecl(D)) |
| 9201 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/true); |
| 9202 | Vars.push_back(DefaultFunctionArrayConversion( |
| 9203 | (VD || !Ref) ? RefExpr->IgnoreParens() : Ref) |
| 9204 | .get()); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9205 | } |
| 9206 | |
| 9207 | // OpenMP [2.8.1, simd construct, Description] |
| 9208 | // The parameter of the aligned clause, alignment, must be a constant |
| 9209 | // positive integer expression. |
| 9210 | // If no optional parameter is specified, implementation-defined default |
| 9211 | // alignments for SIMD instructions on the target platforms are assumed. |
| 9212 | if (Alignment != nullptr) { |
| 9213 | ExprResult AlignResult = |
| 9214 | VerifyPositiveIntegerConstantInClause(Alignment, OMPC_aligned); |
| 9215 | if (AlignResult.isInvalid()) |
| 9216 | return nullptr; |
| 9217 | Alignment = AlignResult.get(); |
| 9218 | } |
| 9219 | if (Vars.empty()) |
| 9220 | return nullptr; |
| 9221 | |
| 9222 | return OMPAlignedClause::Create(Context, StartLoc, LParenLoc, ColonLoc, |
| 9223 | EndLoc, Vars, Alignment); |
| 9224 | } |
| 9225 | |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9226 | OMPClause *Sema::ActOnOpenMPCopyinClause(ArrayRef<Expr *> VarList, |
| 9227 | SourceLocation StartLoc, |
| 9228 | SourceLocation LParenLoc, |
| 9229 | SourceLocation EndLoc) { |
| 9230 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 9231 | SmallVector<Expr *, 8> SrcExprs; |
| 9232 | SmallVector<Expr *, 8> DstExprs; |
| 9233 | SmallVector<Expr *, 8> AssignmentOps; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9234 | for (auto &RefExpr : VarList) { |
| 9235 | assert(RefExpr && "NULL expr in OpenMP copyin clause."); |
| 9236 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9237 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9238 | Vars.push_back(RefExpr); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 9239 | SrcExprs.push_back(nullptr); |
| 9240 | DstExprs.push_back(nullptr); |
| 9241 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9242 | continue; |
| 9243 | } |
| 9244 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9245 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9246 | // OpenMP [2.1, C/C++] |
| 9247 | // A list item is a variable name. |
| 9248 | // OpenMP [2.14.4.1, Restrictions, p.1] |
| 9249 | // A list item that appears in a copyin clause must be threadprivate. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9250 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9251 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 9252 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr) |
| 9253 | << 0 << RefExpr->getSourceRange(); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9254 | continue; |
| 9255 | } |
| 9256 | |
| 9257 | Decl *D = DE->getDecl(); |
| 9258 | VarDecl *VD = cast<VarDecl>(D); |
| 9259 | |
| 9260 | QualType Type = VD->getType(); |
| 9261 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 9262 | // It will be analyzed later. |
| 9263 | Vars.push_back(DE); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 9264 | SrcExprs.push_back(nullptr); |
| 9265 | DstExprs.push_back(nullptr); |
| 9266 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9267 | continue; |
| 9268 | } |
| 9269 | |
| 9270 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.1] |
| 9271 | // A list item that appears in a copyin clause must be threadprivate. |
| 9272 | if (!DSAStack->isThreadPrivate(VD)) { |
| 9273 | Diag(ELoc, diag::err_omp_required_access) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9274 | << getOpenMPClauseName(OMPC_copyin) |
| 9275 | << getOpenMPDirectiveName(OMPD_threadprivate); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9276 | continue; |
| 9277 | } |
| 9278 | |
| 9279 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.2] |
| 9280 | // A variable of class type (or array thereof) that appears in a |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 9281 | // copyin clause requires an accessible, unambiguous copy assignment |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9282 | // operator for the class type. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 9283 | auto ElemType = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 9284 | auto *SrcVD = |
| 9285 | buildVarDecl(*this, DE->getLocStart(), ElemType.getUnqualifiedType(), |
| 9286 | ".copyin.src", VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 9287 | auto *PseudoSrcExpr = buildDeclRefExpr( |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 9288 | *this, SrcVD, ElemType.getUnqualifiedType(), DE->getExprLoc()); |
| 9289 | auto *DstVD = |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 9290 | buildVarDecl(*this, DE->getLocStart(), ElemType, ".copyin.dst", |
| 9291 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 9292 | auto *PseudoDstExpr = |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 9293 | buildDeclRefExpr(*this, DstVD, ElemType, DE->getExprLoc()); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 9294 | // For arrays generate assignment operation for single element and replace |
| 9295 | // it by the original array element in CodeGen. |
| 9296 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, DE->getExprLoc(), BO_Assign, |
| 9297 | PseudoDstExpr, PseudoSrcExpr); |
| 9298 | if (AssignmentOp.isInvalid()) |
| 9299 | continue; |
| 9300 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), DE->getExprLoc(), |
| 9301 | /*DiscardedValue=*/true); |
| 9302 | if (AssignmentOp.isInvalid()) |
| 9303 | continue; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9304 | |
| 9305 | DSAStack->addDSA(VD, DE, OMPC_copyin); |
| 9306 | Vars.push_back(DE); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 9307 | SrcExprs.push_back(PseudoSrcExpr); |
| 9308 | DstExprs.push_back(PseudoDstExpr); |
| 9309 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9310 | } |
| 9311 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9312 | if (Vars.empty()) |
| 9313 | return nullptr; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9314 | |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 9315 | return OMPCopyinClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
| 9316 | SrcExprs, DstExprs, AssignmentOps); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9317 | } |
| 9318 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9319 | OMPClause *Sema::ActOnOpenMPCopyprivateClause(ArrayRef<Expr *> VarList, |
| 9320 | SourceLocation StartLoc, |
| 9321 | SourceLocation LParenLoc, |
| 9322 | SourceLocation EndLoc) { |
| 9323 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 9324 | SmallVector<Expr *, 8> SrcExprs; |
| 9325 | SmallVector<Expr *, 8> DstExprs; |
| 9326 | SmallVector<Expr *, 8> AssignmentOps; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9327 | for (auto &RefExpr : VarList) { |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9328 | assert(RefExpr && "NULL expr in OpenMP linear clause."); |
| 9329 | SourceLocation ELoc; |
| 9330 | SourceRange ERange; |
| 9331 | Expr *SimpleRefExpr = RefExpr; |
| 9332 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange, |
| 9333 | /*AllowArraySection=*/false); |
| 9334 | if (Res.second) { |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9335 | // It will be analyzed later. |
| 9336 | Vars.push_back(RefExpr); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 9337 | SrcExprs.push_back(nullptr); |
| 9338 | DstExprs.push_back(nullptr); |
| 9339 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9340 | } |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9341 | ValueDecl *D = Res.first; |
| 9342 | if (!D) |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9343 | continue; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9344 | |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9345 | QualType Type = D->getType(); |
| 9346 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9347 | |
| 9348 | // OpenMP [2.14.4.2, Restrictions, p.2] |
| 9349 | // A list item that appears in a copyprivate clause may not appear in a |
| 9350 | // private or firstprivate clause on the single construct. |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9351 | if (!VD || !DSAStack->isThreadPrivate(VD)) { |
| 9352 | auto DVar = DSAStack->getTopDSA(D, false); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 9353 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_copyprivate && |
| 9354 | DVar.RefExpr) { |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9355 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 9356 | << getOpenMPClauseName(DVar.CKind) |
| 9357 | << getOpenMPClauseName(OMPC_copyprivate); |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9358 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9359 | continue; |
| 9360 | } |
| 9361 | |
| 9362 | // OpenMP [2.11.4.2, Restrictions, p.1] |
| 9363 | // All list items that appear in a copyprivate clause must be either |
| 9364 | // threadprivate or private in the enclosing context. |
| 9365 | if (DVar.CKind == OMPC_unknown) { |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9366 | DVar = DSAStack->getImplicitDSA(D, false); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9367 | if (DVar.CKind == OMPC_shared) { |
| 9368 | Diag(ELoc, diag::err_omp_required_access) |
| 9369 | << getOpenMPClauseName(OMPC_copyprivate) |
| 9370 | << "threadprivate or private in the enclosing context"; |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9371 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9372 | continue; |
| 9373 | } |
| 9374 | } |
| 9375 | } |
| 9376 | |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 9377 | // Variably modified types are not supported. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 9378 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType()) { |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 9379 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 9380 | << getOpenMPClauseName(OMPC_copyprivate) << Type |
| 9381 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 9382 | bool IsDecl = |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9383 | !VD || |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 9384 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9385 | Diag(D->getLocation(), |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 9386 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9387 | << D; |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 9388 | continue; |
| 9389 | } |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 9390 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9391 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.2] |
| 9392 | // A variable of class type (or array thereof) that appears in a |
| 9393 | // copyin clause requires an accessible, unambiguous copy assignment |
| 9394 | // operator for the class type. |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 9395 | Type = Context.getBaseElementType(Type.getNonReferenceType()) |
| 9396 | .getUnqualifiedType(); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 9397 | auto *SrcVD = |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9398 | buildVarDecl(*this, RefExpr->getLocStart(), Type, ".copyprivate.src", |
| 9399 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 9400 | auto *PseudoSrcExpr = buildDeclRefExpr(*this, SrcVD, Type, ELoc); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 9401 | auto *DstVD = |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9402 | buildVarDecl(*this, RefExpr->getLocStart(), Type, ".copyprivate.dst", |
| 9403 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 9404 | auto *PseudoDstExpr = |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9405 | buildDeclRefExpr(*this, DstVD, Type, ELoc); |
| 9406 | auto AssignmentOp = BuildBinOp(DSAStack->getCurScope(), ELoc, BO_Assign, |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 9407 | PseudoDstExpr, PseudoSrcExpr); |
| 9408 | if (AssignmentOp.isInvalid()) |
| 9409 | continue; |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9410 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), ELoc, |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 9411 | /*DiscardedValue=*/true); |
| 9412 | if (AssignmentOp.isInvalid()) |
| 9413 | continue; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9414 | |
| 9415 | // No need to mark vars as copyprivate, they are already threadprivate or |
| 9416 | // implicitly private. |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9417 | assert(VD || IsOpenMPCapturedDecl(D)); |
| 9418 | Vars.push_back( |
| 9419 | VD ? RefExpr->IgnoreParens() |
| 9420 | : buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false)); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 9421 | SrcExprs.push_back(PseudoSrcExpr); |
| 9422 | DstExprs.push_back(PseudoDstExpr); |
| 9423 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9424 | } |
| 9425 | |
| 9426 | if (Vars.empty()) |
| 9427 | return nullptr; |
| 9428 | |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 9429 | return OMPCopyprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| 9430 | Vars, SrcExprs, DstExprs, AssignmentOps); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9431 | } |
| 9432 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 9433 | OMPClause *Sema::ActOnOpenMPFlushClause(ArrayRef<Expr *> VarList, |
| 9434 | SourceLocation StartLoc, |
| 9435 | SourceLocation LParenLoc, |
| 9436 | SourceLocation EndLoc) { |
| 9437 | if (VarList.empty()) |
| 9438 | return nullptr; |
| 9439 | |
| 9440 | return OMPFlushClause::Create(Context, StartLoc, LParenLoc, EndLoc, VarList); |
| 9441 | } |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 9442 | |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 9443 | OMPClause * |
| 9444 | Sema::ActOnOpenMPDependClause(OpenMPDependClauseKind DepKind, |
| 9445 | SourceLocation DepLoc, SourceLocation ColonLoc, |
| 9446 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
| 9447 | SourceLocation LParenLoc, SourceLocation EndLoc) { |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 9448 | if (DSAStack->getCurrentDirective() == OMPD_ordered && |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 9449 | DepKind != OMPC_DEPEND_source && DepKind != OMPC_DEPEND_sink) { |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 9450 | Diag(DepLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 9451 | << "'source' or 'sink'" << getOpenMPClauseName(OMPC_depend); |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 9452 | return nullptr; |
| 9453 | } |
| 9454 | if (DSAStack->getCurrentDirective() != OMPD_ordered && |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 9455 | (DepKind == OMPC_DEPEND_unknown || DepKind == OMPC_DEPEND_source || |
| 9456 | DepKind == OMPC_DEPEND_sink)) { |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 9457 | unsigned Except[] = {OMPC_DEPEND_source, OMPC_DEPEND_sink}; |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 9458 | Diag(DepLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 9459 | << getListOfPossibleValues(OMPC_depend, /*First=*/0, |
| 9460 | /*Last=*/OMPC_DEPEND_unknown, Except) |
| 9461 | << getOpenMPClauseName(OMPC_depend); |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 9462 | return nullptr; |
| 9463 | } |
| 9464 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 9465 | llvm::APSInt DepCounter(/*BitWidth=*/32); |
| 9466 | llvm::APSInt TotalDepCount(/*BitWidth=*/32); |
| 9467 | if (DepKind == OMPC_DEPEND_sink) { |
| 9468 | if (auto *OrderedCountExpr = DSAStack->getParentOrderedRegionParam()) { |
| 9469 | TotalDepCount = OrderedCountExpr->EvaluateKnownConstInt(Context); |
| 9470 | TotalDepCount.setIsUnsigned(/*Val=*/true); |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 9471 | } |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 9472 | } |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 9473 | if ((DepKind != OMPC_DEPEND_sink && DepKind != OMPC_DEPEND_source) || |
| 9474 | DSAStack->getParentOrderedRegionParam()) { |
| 9475 | for (auto &RefExpr : VarList) { |
| 9476 | assert(RefExpr && "NULL expr in OpenMP shared clause."); |
| 9477 | if (isa<DependentScopeDeclRefExpr>(RefExpr) || |
| 9478 | (DepKind == OMPC_DEPEND_sink && CurContext->isDependentContext())) { |
| 9479 | // It will be analyzed later. |
| 9480 | Vars.push_back(RefExpr); |
| 9481 | continue; |
| 9482 | } |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 9483 | |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 9484 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 9485 | auto *SimpleExpr = RefExpr->IgnoreParenCasts(); |
| 9486 | if (DepKind == OMPC_DEPEND_sink) { |
| 9487 | if (DepCounter >= TotalDepCount) { |
| 9488 | Diag(ELoc, diag::err_omp_depend_sink_unexpected_expr); |
| 9489 | continue; |
| 9490 | } |
| 9491 | ++DepCounter; |
| 9492 | // OpenMP [2.13.9, Summary] |
| 9493 | // depend(dependence-type : vec), where dependence-type is: |
| 9494 | // 'sink' and where vec is the iteration vector, which has the form: |
| 9495 | // x1 [+- d1], x2 [+- d2 ], . . . , xn [+- dn] |
| 9496 | // where n is the value specified by the ordered clause in the loop |
| 9497 | // directive, xi denotes the loop iteration variable of the i-th nested |
| 9498 | // loop associated with the loop directive, and di is a constant |
| 9499 | // non-negative integer. |
| 9500 | SimpleExpr = SimpleExpr->IgnoreImplicit(); |
| 9501 | auto *DE = dyn_cast<DeclRefExpr>(SimpleExpr); |
| 9502 | if (!DE) { |
| 9503 | OverloadedOperatorKind OOK = OO_None; |
| 9504 | SourceLocation OOLoc; |
| 9505 | Expr *LHS, *RHS; |
| 9506 | if (auto *BO = dyn_cast<BinaryOperator>(SimpleExpr)) { |
| 9507 | OOK = BinaryOperator::getOverloadedOperator(BO->getOpcode()); |
| 9508 | OOLoc = BO->getOperatorLoc(); |
| 9509 | LHS = BO->getLHS()->IgnoreParenImpCasts(); |
| 9510 | RHS = BO->getRHS()->IgnoreParenImpCasts(); |
| 9511 | } else if (auto *OCE = dyn_cast<CXXOperatorCallExpr>(SimpleExpr)) { |
| 9512 | OOK = OCE->getOperator(); |
| 9513 | OOLoc = OCE->getOperatorLoc(); |
| 9514 | LHS = OCE->getArg(/*Arg=*/0)->IgnoreParenImpCasts(); |
| 9515 | RHS = OCE->getArg(/*Arg=*/1)->IgnoreParenImpCasts(); |
| 9516 | } else if (auto *MCE = dyn_cast<CXXMemberCallExpr>(SimpleExpr)) { |
| 9517 | OOK = MCE->getMethodDecl() |
| 9518 | ->getNameInfo() |
| 9519 | .getName() |
| 9520 | .getCXXOverloadedOperator(); |
| 9521 | OOLoc = MCE->getCallee()->getExprLoc(); |
| 9522 | LHS = MCE->getImplicitObjectArgument()->IgnoreParenImpCasts(); |
| 9523 | RHS = MCE->getArg(/*Arg=*/0)->IgnoreParenImpCasts(); |
| 9524 | } else { |
| 9525 | Diag(ELoc, diag::err_omp_depend_sink_wrong_expr); |
| 9526 | continue; |
| 9527 | } |
| 9528 | DE = dyn_cast<DeclRefExpr>(LHS); |
| 9529 | if (!DE) { |
| 9530 | Diag(LHS->getExprLoc(), |
| 9531 | diag::err_omp_depend_sink_expected_loop_iteration) |
| 9532 | << DSAStack->getParentLoopControlVariable( |
| 9533 | DepCounter.getZExtValue()); |
| 9534 | continue; |
| 9535 | } |
| 9536 | if (OOK != OO_Plus && OOK != OO_Minus) { |
| 9537 | Diag(OOLoc, diag::err_omp_depend_sink_expected_plus_minus); |
| 9538 | continue; |
| 9539 | } |
| 9540 | ExprResult Res = VerifyPositiveIntegerConstantInClause( |
| 9541 | RHS, OMPC_depend, /*StrictlyPositive=*/false); |
| 9542 | if (Res.isInvalid()) |
| 9543 | continue; |
| 9544 | } |
| 9545 | auto *VD = dyn_cast<VarDecl>(DE->getDecl()); |
| 9546 | if (!CurContext->isDependentContext() && |
| 9547 | DSAStack->getParentOrderedRegionParam() && |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 9548 | (!VD || |
| 9549 | DepCounter != DSAStack->isParentLoopControlVariable(VD).first)) { |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 9550 | Diag(DE->getExprLoc(), |
| 9551 | diag::err_omp_depend_sink_expected_loop_iteration) |
| 9552 | << DSAStack->getParentLoopControlVariable( |
| 9553 | DepCounter.getZExtValue()); |
| 9554 | continue; |
| 9555 | } |
| 9556 | } else { |
| 9557 | // OpenMP [2.11.1.1, Restrictions, p.3] |
| 9558 | // A variable that is part of another variable (such as a field of a |
| 9559 | // structure) but is not an array element or an array section cannot |
| 9560 | // appear in a depend clause. |
| 9561 | auto *DE = dyn_cast<DeclRefExpr>(SimpleExpr); |
| 9562 | auto *ASE = dyn_cast<ArraySubscriptExpr>(SimpleExpr); |
| 9563 | auto *OASE = dyn_cast<OMPArraySectionExpr>(SimpleExpr); |
| 9564 | if (!RefExpr->IgnoreParenImpCasts()->isLValue() || |
| 9565 | (!ASE && !DE && !OASE) || (DE && !isa<VarDecl>(DE->getDecl())) || |
Alexey Bataev | 31300ed | 2016-02-04 11:27:03 +0000 | [diff] [blame] | 9566 | (ASE && |
| 9567 | !ASE->getBase() |
| 9568 | ->getType() |
| 9569 | .getNonReferenceType() |
| 9570 | ->isPointerType() && |
| 9571 | !ASE->getBase()->getType().getNonReferenceType()->isArrayType())) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 9572 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr_or_array_item) |
| 9573 | << 0 << RefExpr->getSourceRange(); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 9574 | continue; |
| 9575 | } |
| 9576 | } |
| 9577 | |
| 9578 | Vars.push_back(RefExpr->IgnoreParenImpCasts()); |
| 9579 | } |
| 9580 | |
| 9581 | if (!CurContext->isDependentContext() && DepKind == OMPC_DEPEND_sink && |
| 9582 | TotalDepCount > VarList.size() && |
| 9583 | DSAStack->getParentOrderedRegionParam()) { |
| 9584 | Diag(EndLoc, diag::err_omp_depend_sink_expected_loop_iteration) |
| 9585 | << DSAStack->getParentLoopControlVariable(VarList.size() + 1); |
| 9586 | } |
| 9587 | if (DepKind != OMPC_DEPEND_source && DepKind != OMPC_DEPEND_sink && |
| 9588 | Vars.empty()) |
| 9589 | return nullptr; |
| 9590 | } |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 9591 | |
| 9592 | return OMPDependClause::Create(Context, StartLoc, LParenLoc, EndLoc, DepKind, |
| 9593 | DepLoc, ColonLoc, Vars); |
| 9594 | } |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 9595 | |
| 9596 | OMPClause *Sema::ActOnOpenMPDeviceClause(Expr *Device, SourceLocation StartLoc, |
| 9597 | SourceLocation LParenLoc, |
| 9598 | SourceLocation EndLoc) { |
| 9599 | Expr *ValExpr = Device; |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 9600 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 9601 | // OpenMP [2.9.1, Restrictions] |
| 9602 | // The device expression must evaluate to a non-negative integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 9603 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_device, |
| 9604 | /*StrictlyPositive=*/false)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 9605 | return nullptr; |
| 9606 | |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 9607 | return new (Context) OMPDeviceClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 9608 | } |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9609 | |
| 9610 | static bool IsCXXRecordForMappable(Sema &SemaRef, SourceLocation Loc, |
| 9611 | DSAStackTy *Stack, CXXRecordDecl *RD) { |
| 9612 | if (!RD || RD->isInvalidDecl()) |
| 9613 | return true; |
| 9614 | |
Alexey Bataev | c9bd03d | 2015-12-17 06:55:08 +0000 | [diff] [blame] | 9615 | if (auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(RD)) |
| 9616 | if (auto *CTD = CTSD->getSpecializedTemplate()) |
| 9617 | RD = CTD->getTemplatedDecl(); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9618 | auto QTy = SemaRef.Context.getRecordType(RD); |
| 9619 | if (RD->isDynamicClass()) { |
| 9620 | SemaRef.Diag(Loc, diag::err_omp_not_mappable_type) << QTy; |
| 9621 | SemaRef.Diag(RD->getLocation(), diag::note_omp_polymorphic_in_target); |
| 9622 | return false; |
| 9623 | } |
| 9624 | auto *DC = RD; |
| 9625 | bool IsCorrect = true; |
| 9626 | for (auto *I : DC->decls()) { |
| 9627 | if (I) { |
| 9628 | if (auto *MD = dyn_cast<CXXMethodDecl>(I)) { |
| 9629 | if (MD->isStatic()) { |
| 9630 | SemaRef.Diag(Loc, diag::err_omp_not_mappable_type) << QTy; |
| 9631 | SemaRef.Diag(MD->getLocation(), |
| 9632 | diag::note_omp_static_member_in_target); |
| 9633 | IsCorrect = false; |
| 9634 | } |
| 9635 | } else if (auto *VD = dyn_cast<VarDecl>(I)) { |
| 9636 | if (VD->isStaticDataMember()) { |
| 9637 | SemaRef.Diag(Loc, diag::err_omp_not_mappable_type) << QTy; |
| 9638 | SemaRef.Diag(VD->getLocation(), |
| 9639 | diag::note_omp_static_member_in_target); |
| 9640 | IsCorrect = false; |
| 9641 | } |
| 9642 | } |
| 9643 | } |
| 9644 | } |
| 9645 | |
| 9646 | for (auto &I : RD->bases()) { |
| 9647 | if (!IsCXXRecordForMappable(SemaRef, I.getLocStart(), Stack, |
| 9648 | I.getType()->getAsCXXRecordDecl())) |
| 9649 | IsCorrect = false; |
| 9650 | } |
| 9651 | return IsCorrect; |
| 9652 | } |
| 9653 | |
| 9654 | static bool CheckTypeMappable(SourceLocation SL, SourceRange SR, Sema &SemaRef, |
| 9655 | DSAStackTy *Stack, QualType QTy) { |
| 9656 | NamedDecl *ND; |
| 9657 | if (QTy->isIncompleteType(&ND)) { |
| 9658 | SemaRef.Diag(SL, diag::err_incomplete_type) << QTy << SR; |
| 9659 | return false; |
| 9660 | } else if (CXXRecordDecl *RD = dyn_cast_or_null<CXXRecordDecl>(ND)) { |
| 9661 | if (!RD->isInvalidDecl() && |
| 9662 | !IsCXXRecordForMappable(SemaRef, SL, Stack, RD)) |
| 9663 | return false; |
| 9664 | } |
| 9665 | return true; |
| 9666 | } |
| 9667 | |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 9668 | /// \brief Return true if it can be proven that the provided array expression |
| 9669 | /// (array section or array subscript) does NOT specify the whole size of the |
| 9670 | /// array whose base type is \a BaseQTy. |
| 9671 | static bool CheckArrayExpressionDoesNotReferToWholeSize(Sema &SemaRef, |
| 9672 | const Expr *E, |
| 9673 | QualType BaseQTy) { |
| 9674 | auto *OASE = dyn_cast<OMPArraySectionExpr>(E); |
| 9675 | |
| 9676 | // If this is an array subscript, it refers to the whole size if the size of |
| 9677 | // the dimension is constant and equals 1. Also, an array section assumes the |
| 9678 | // format of an array subscript if no colon is used. |
| 9679 | if (isa<ArraySubscriptExpr>(E) || (OASE && OASE->getColonLoc().isInvalid())) { |
| 9680 | if (auto *ATy = dyn_cast<ConstantArrayType>(BaseQTy.getTypePtr())) |
| 9681 | return ATy->getSize().getSExtValue() != 1; |
| 9682 | // Size can't be evaluated statically. |
| 9683 | return false; |
| 9684 | } |
| 9685 | |
| 9686 | assert(OASE && "Expecting array section if not an array subscript."); |
| 9687 | auto *LowerBound = OASE->getLowerBound(); |
| 9688 | auto *Length = OASE->getLength(); |
| 9689 | |
| 9690 | // If there is a lower bound that does not evaluates to zero, we are not |
| 9691 | // convering the whole dimension. |
| 9692 | if (LowerBound) { |
| 9693 | llvm::APSInt ConstLowerBound; |
| 9694 | if (!LowerBound->EvaluateAsInt(ConstLowerBound, SemaRef.getASTContext())) |
| 9695 | return false; // Can't get the integer value as a constant. |
| 9696 | if (ConstLowerBound.getSExtValue()) |
| 9697 | return true; |
| 9698 | } |
| 9699 | |
| 9700 | // If we don't have a length we covering the whole dimension. |
| 9701 | if (!Length) |
| 9702 | return false; |
| 9703 | |
| 9704 | // If the base is a pointer, we don't have a way to get the size of the |
| 9705 | // pointee. |
| 9706 | if (BaseQTy->isPointerType()) |
| 9707 | return false; |
| 9708 | |
| 9709 | // We can only check if the length is the same as the size of the dimension |
| 9710 | // if we have a constant array. |
| 9711 | auto *CATy = dyn_cast<ConstantArrayType>(BaseQTy.getTypePtr()); |
| 9712 | if (!CATy) |
| 9713 | return false; |
| 9714 | |
| 9715 | llvm::APSInt ConstLength; |
| 9716 | if (!Length->EvaluateAsInt(ConstLength, SemaRef.getASTContext())) |
| 9717 | return false; // Can't get the integer value as a constant. |
| 9718 | |
| 9719 | return CATy->getSize().getSExtValue() != ConstLength.getSExtValue(); |
| 9720 | } |
| 9721 | |
| 9722 | // Return true if it can be proven that the provided array expression (array |
| 9723 | // section or array subscript) does NOT specify a single element of the array |
| 9724 | // whose base type is \a BaseQTy. |
| 9725 | static bool CheckArrayExpressionDoesNotReferToUnitySize(Sema &SemaRef, |
| 9726 | const Expr *E, |
| 9727 | QualType BaseQTy) { |
| 9728 | auto *OASE = dyn_cast<OMPArraySectionExpr>(E); |
| 9729 | |
| 9730 | // An array subscript always refer to a single element. Also, an array section |
| 9731 | // assumes the format of an array subscript if no colon is used. |
| 9732 | if (isa<ArraySubscriptExpr>(E) || (OASE && OASE->getColonLoc().isInvalid())) |
| 9733 | return false; |
| 9734 | |
| 9735 | assert(OASE && "Expecting array section if not an array subscript."); |
| 9736 | auto *Length = OASE->getLength(); |
| 9737 | |
| 9738 | // If we don't have a length we have to check if the array has unitary size |
| 9739 | // for this dimension. Also, we should always expect a length if the base type |
| 9740 | // is pointer. |
| 9741 | if (!Length) { |
| 9742 | if (auto *ATy = dyn_cast<ConstantArrayType>(BaseQTy.getTypePtr())) |
| 9743 | return ATy->getSize().getSExtValue() != 1; |
| 9744 | // We cannot assume anything. |
| 9745 | return false; |
| 9746 | } |
| 9747 | |
| 9748 | // Check if the length evaluates to 1. |
| 9749 | llvm::APSInt ConstLength; |
| 9750 | if (!Length->EvaluateAsInt(ConstLength, SemaRef.getASTContext())) |
| 9751 | return false; // Can't get the integer value as a constant. |
| 9752 | |
| 9753 | return ConstLength.getSExtValue() != 1; |
| 9754 | } |
| 9755 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9756 | // Return the expression of the base of the map clause or null if it cannot |
| 9757 | // be determined and do all the necessary checks to see if the expression is |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 9758 | // valid as a standalone map clause expression. In the process, record all the |
| 9759 | // components of the expression. |
| 9760 | static Expr *CheckMapClauseExpressionBase( |
| 9761 | Sema &SemaRef, Expr *E, |
| 9762 | OMPClauseMappableExprCommon::MappableExprComponentList &CurComponents) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9763 | SourceLocation ELoc = E->getExprLoc(); |
| 9764 | SourceRange ERange = E->getSourceRange(); |
| 9765 | |
| 9766 | // The base of elements of list in a map clause have to be either: |
| 9767 | // - a reference to variable or field. |
| 9768 | // - a member expression. |
| 9769 | // - an array expression. |
| 9770 | // |
| 9771 | // E.g. if we have the expression 'r.S.Arr[:12]', we want to retrieve the |
| 9772 | // reference to 'r'. |
| 9773 | // |
| 9774 | // If we have: |
| 9775 | // |
| 9776 | // struct SS { |
| 9777 | // Bla S; |
| 9778 | // foo() { |
| 9779 | // #pragma omp target map (S.Arr[:12]); |
| 9780 | // } |
| 9781 | // } |
| 9782 | // |
| 9783 | // We want to retrieve the member expression 'this->S'; |
| 9784 | |
| 9785 | Expr *RelevantExpr = nullptr; |
| 9786 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9787 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.2] |
| 9788 | // If a list item is an array section, it must specify contiguous storage. |
| 9789 | // |
| 9790 | // For this restriction it is sufficient that we make sure only references |
| 9791 | // to variables or fields and array expressions, and that no array sections |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 9792 | // exist except in the rightmost expression (unless they cover the whole |
| 9793 | // dimension of the array). E.g. these would be invalid: |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9794 | // |
| 9795 | // r.ArrS[3:5].Arr[6:7] |
| 9796 | // |
| 9797 | // r.ArrS[3:5].x |
| 9798 | // |
| 9799 | // but these would be valid: |
| 9800 | // r.ArrS[3].Arr[6:7] |
| 9801 | // |
| 9802 | // r.ArrS[3].x |
| 9803 | |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 9804 | bool AllowUnitySizeArraySection = true; |
| 9805 | bool AllowWholeSizeArraySection = true; |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9806 | |
Dmitry Polukhin | 644a925 | 2016-03-11 07:58:34 +0000 | [diff] [blame] | 9807 | while (!RelevantExpr) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9808 | E = E->IgnoreParenImpCasts(); |
| 9809 | |
| 9810 | if (auto *CurE = dyn_cast<DeclRefExpr>(E)) { |
| 9811 | if (!isa<VarDecl>(CurE->getDecl())) |
| 9812 | break; |
| 9813 | |
| 9814 | RelevantExpr = CurE; |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 9815 | |
| 9816 | // If we got a reference to a declaration, we should not expect any array |
| 9817 | // section before that. |
| 9818 | AllowUnitySizeArraySection = false; |
| 9819 | AllowWholeSizeArraySection = false; |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 9820 | |
| 9821 | // Record the component. |
| 9822 | CurComponents.push_back(OMPClauseMappableExprCommon::MappableComponent( |
| 9823 | CurE, CurE->getDecl())); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9824 | continue; |
| 9825 | } |
| 9826 | |
| 9827 | if (auto *CurE = dyn_cast<MemberExpr>(E)) { |
| 9828 | auto *BaseE = CurE->getBase()->IgnoreParenImpCasts(); |
| 9829 | |
| 9830 | if (isa<CXXThisExpr>(BaseE)) |
| 9831 | // We found a base expression: this->Val. |
| 9832 | RelevantExpr = CurE; |
| 9833 | else |
| 9834 | E = BaseE; |
| 9835 | |
| 9836 | if (!isa<FieldDecl>(CurE->getMemberDecl())) { |
| 9837 | SemaRef.Diag(ELoc, diag::err_omp_expected_access_to_data_field) |
| 9838 | << CurE->getSourceRange(); |
| 9839 | break; |
| 9840 | } |
| 9841 | |
| 9842 | auto *FD = cast<FieldDecl>(CurE->getMemberDecl()); |
| 9843 | |
| 9844 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C/C++, p.3] |
| 9845 | // A bit-field cannot appear in a map clause. |
| 9846 | // |
| 9847 | if (FD->isBitField()) { |
| 9848 | SemaRef.Diag(ELoc, diag::err_omp_bit_fields_forbidden_in_map_clause) |
| 9849 | << CurE->getSourceRange(); |
| 9850 | break; |
| 9851 | } |
| 9852 | |
| 9853 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] |
| 9854 | // If the type of a list item is a reference to a type T then the type |
| 9855 | // will be considered to be T for all purposes of this clause. |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 9856 | QualType CurType = BaseE->getType().getNonReferenceType(); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9857 | |
| 9858 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C/C++, p.2] |
| 9859 | // A list item cannot be a variable that is a member of a structure with |
| 9860 | // a union type. |
| 9861 | // |
| 9862 | if (auto *RT = CurType->getAs<RecordType>()) |
| 9863 | if (RT->isUnionType()) { |
| 9864 | SemaRef.Diag(ELoc, diag::err_omp_union_type_not_allowed) |
| 9865 | << CurE->getSourceRange(); |
| 9866 | break; |
| 9867 | } |
| 9868 | |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 9869 | // If we got a member expression, we should not expect any array section |
| 9870 | // before that: |
| 9871 | // |
| 9872 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.7] |
| 9873 | // If a list item is an element of a structure, only the rightmost symbol |
| 9874 | // of the variable reference can be an array section. |
| 9875 | // |
| 9876 | AllowUnitySizeArraySection = false; |
| 9877 | AllowWholeSizeArraySection = false; |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 9878 | |
| 9879 | // Record the component. |
| 9880 | CurComponents.push_back( |
| 9881 | OMPClauseMappableExprCommon::MappableComponent(CurE, FD)); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9882 | continue; |
| 9883 | } |
| 9884 | |
| 9885 | if (auto *CurE = dyn_cast<ArraySubscriptExpr>(E)) { |
| 9886 | E = CurE->getBase()->IgnoreParenImpCasts(); |
| 9887 | |
| 9888 | if (!E->getType()->isAnyPointerType() && !E->getType()->isArrayType()) { |
| 9889 | SemaRef.Diag(ELoc, diag::err_omp_expected_base_var_name) |
| 9890 | << 0 << CurE->getSourceRange(); |
| 9891 | break; |
| 9892 | } |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 9893 | |
| 9894 | // If we got an array subscript that express the whole dimension we |
| 9895 | // can have any array expressions before. If it only expressing part of |
| 9896 | // the dimension, we can only have unitary-size array expressions. |
| 9897 | if (CheckArrayExpressionDoesNotReferToWholeSize(SemaRef, CurE, |
| 9898 | E->getType())) |
| 9899 | AllowWholeSizeArraySection = false; |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 9900 | |
| 9901 | // Record the component - we don't have any declaration associated. |
| 9902 | CurComponents.push_back( |
| 9903 | OMPClauseMappableExprCommon::MappableComponent(CurE, nullptr)); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9904 | continue; |
| 9905 | } |
| 9906 | |
| 9907 | if (auto *CurE = dyn_cast<OMPArraySectionExpr>(E)) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9908 | E = CurE->getBase()->IgnoreParenImpCasts(); |
| 9909 | |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 9910 | auto CurType = |
| 9911 | OMPArraySectionExpr::getBaseOriginalType(E).getCanonicalType(); |
| 9912 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9913 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] |
| 9914 | // If the type of a list item is a reference to a type T then the type |
| 9915 | // will be considered to be T for all purposes of this clause. |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9916 | if (CurType->isReferenceType()) |
| 9917 | CurType = CurType->getPointeeType(); |
| 9918 | |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 9919 | bool IsPointer = CurType->isAnyPointerType(); |
| 9920 | |
| 9921 | if (!IsPointer && !CurType->isArrayType()) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9922 | SemaRef.Diag(ELoc, diag::err_omp_expected_base_var_name) |
| 9923 | << 0 << CurE->getSourceRange(); |
| 9924 | break; |
| 9925 | } |
| 9926 | |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 9927 | bool NotWhole = |
| 9928 | CheckArrayExpressionDoesNotReferToWholeSize(SemaRef, CurE, CurType); |
| 9929 | bool NotUnity = |
| 9930 | CheckArrayExpressionDoesNotReferToUnitySize(SemaRef, CurE, CurType); |
| 9931 | |
| 9932 | if (AllowWholeSizeArraySection && AllowUnitySizeArraySection) { |
| 9933 | // Any array section is currently allowed. |
| 9934 | // |
| 9935 | // If this array section refers to the whole dimension we can still |
| 9936 | // accept other array sections before this one, except if the base is a |
| 9937 | // pointer. Otherwise, only unitary sections are accepted. |
| 9938 | if (NotWhole || IsPointer) |
| 9939 | AllowWholeSizeArraySection = false; |
| 9940 | } else if ((AllowUnitySizeArraySection && NotUnity) || |
| 9941 | (AllowWholeSizeArraySection && NotWhole)) { |
| 9942 | // A unity or whole array section is not allowed and that is not |
| 9943 | // compatible with the properties of the current array section. |
| 9944 | SemaRef.Diag( |
| 9945 | ELoc, diag::err_array_section_does_not_specify_contiguous_storage) |
| 9946 | << CurE->getSourceRange(); |
| 9947 | break; |
| 9948 | } |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 9949 | |
| 9950 | // Record the component - we don't have any declaration associated. |
| 9951 | CurComponents.push_back( |
| 9952 | OMPClauseMappableExprCommon::MappableComponent(CurE, nullptr)); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9953 | continue; |
| 9954 | } |
| 9955 | |
| 9956 | // If nothing else worked, this is not a valid map clause expression. |
| 9957 | SemaRef.Diag(ELoc, |
| 9958 | diag::err_omp_expected_named_var_member_or_array_expression) |
| 9959 | << ERange; |
| 9960 | break; |
| 9961 | } |
| 9962 | |
| 9963 | return RelevantExpr; |
| 9964 | } |
| 9965 | |
| 9966 | // Return true if expression E associated with value VD has conflicts with other |
| 9967 | // map information. |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 9968 | static bool CheckMapConflicts( |
| 9969 | Sema &SemaRef, DSAStackTy *DSAS, ValueDecl *VD, Expr *E, |
| 9970 | bool CurrentRegionOnly, |
| 9971 | OMPClauseMappableExprCommon::MappableExprComponentListRef CurComponents) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9972 | assert(VD && E); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9973 | SourceLocation ELoc = E->getExprLoc(); |
| 9974 | SourceRange ERange = E->getSourceRange(); |
| 9975 | |
| 9976 | // In order to easily check the conflicts we need to match each component of |
| 9977 | // the expression under test with the components of the expressions that are |
| 9978 | // already in the stack. |
| 9979 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9980 | assert(!CurComponents.empty() && "Map clause expression with no components!"); |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 9981 | assert(CurComponents.back().getAssociatedDeclaration() == VD && |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9982 | "Map clause expression with unexpected base!"); |
| 9983 | |
| 9984 | // Variables to help detecting enclosing problems in data environment nests. |
| 9985 | bool IsEnclosedByDataEnvironmentExpr = false; |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 9986 | const Expr *EnclosingExpr = nullptr; |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9987 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 9988 | bool FoundError = DSAS->checkMappableExprComponentListsForDecl( |
| 9989 | VD, CurrentRegionOnly, |
| 9990 | [&](OMPClauseMappableExprCommon::MappableExprComponentListRef |
| 9991 | StackComponents) -> bool { |
| 9992 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9993 | assert(!StackComponents.empty() && |
| 9994 | "Map clause expression with no components!"); |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 9995 | assert(StackComponents.back().getAssociatedDeclaration() == VD && |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9996 | "Map clause expression with unexpected base!"); |
| 9997 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 9998 | // The whole expression in the stack. |
| 9999 | auto *RE = StackComponents.front().getAssociatedExpression(); |
| 10000 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10001 | // Expressions must start from the same base. Here we detect at which |
| 10002 | // point both expressions diverge from each other and see if we can |
| 10003 | // detect if the memory referred to both expressions is contiguous and |
| 10004 | // do not overlap. |
| 10005 | auto CI = CurComponents.rbegin(); |
| 10006 | auto CE = CurComponents.rend(); |
| 10007 | auto SI = StackComponents.rbegin(); |
| 10008 | auto SE = StackComponents.rend(); |
| 10009 | for (; CI != CE && SI != SE; ++CI, ++SI) { |
| 10010 | |
| 10011 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.3] |
| 10012 | // At most one list item can be an array item derived from a given |
| 10013 | // variable in map clauses of the same construct. |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10014 | if (CurrentRegionOnly && |
| 10015 | (isa<ArraySubscriptExpr>(CI->getAssociatedExpression()) || |
| 10016 | isa<OMPArraySectionExpr>(CI->getAssociatedExpression())) && |
| 10017 | (isa<ArraySubscriptExpr>(SI->getAssociatedExpression()) || |
| 10018 | isa<OMPArraySectionExpr>(SI->getAssociatedExpression()))) { |
| 10019 | SemaRef.Diag(CI->getAssociatedExpression()->getExprLoc(), |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10020 | diag::err_omp_multiple_array_items_in_map_clause) |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10021 | << CI->getAssociatedExpression()->getSourceRange(); |
| 10022 | SemaRef.Diag(SI->getAssociatedExpression()->getExprLoc(), |
| 10023 | diag::note_used_here) |
| 10024 | << SI->getAssociatedExpression()->getSourceRange(); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10025 | return true; |
| 10026 | } |
| 10027 | |
| 10028 | // Do both expressions have the same kind? |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10029 | if (CI->getAssociatedExpression()->getStmtClass() != |
| 10030 | SI->getAssociatedExpression()->getStmtClass()) |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10031 | break; |
| 10032 | |
| 10033 | // Are we dealing with different variables/fields? |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10034 | if (CI->getAssociatedDeclaration() != SI->getAssociatedDeclaration()) |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10035 | break; |
| 10036 | } |
| 10037 | |
| 10038 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.4] |
| 10039 | // List items of map clauses in the same construct must not share |
| 10040 | // original storage. |
| 10041 | // |
| 10042 | // If the expressions are exactly the same or one is a subset of the |
| 10043 | // other, it means they are sharing storage. |
| 10044 | if (CI == CE && SI == SE) { |
| 10045 | if (CurrentRegionOnly) { |
| 10046 | SemaRef.Diag(ELoc, diag::err_omp_map_shared_storage) << ERange; |
| 10047 | SemaRef.Diag(RE->getExprLoc(), diag::note_used_here) |
| 10048 | << RE->getSourceRange(); |
| 10049 | return true; |
| 10050 | } else { |
| 10051 | // If we find the same expression in the enclosing data environment, |
| 10052 | // that is legal. |
| 10053 | IsEnclosedByDataEnvironmentExpr = true; |
| 10054 | return false; |
| 10055 | } |
| 10056 | } |
| 10057 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10058 | QualType DerivedType = |
| 10059 | std::prev(CI)->getAssociatedDeclaration()->getType(); |
| 10060 | SourceLocation DerivedLoc = |
| 10061 | std::prev(CI)->getAssociatedExpression()->getExprLoc(); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10062 | |
| 10063 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] |
| 10064 | // If the type of a list item is a reference to a type T then the type |
| 10065 | // will be considered to be T for all purposes of this clause. |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10066 | DerivedType = DerivedType.getNonReferenceType(); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10067 | |
| 10068 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C/C++, p.1] |
| 10069 | // A variable for which the type is pointer and an array section |
| 10070 | // derived from that variable must not appear as list items of map |
| 10071 | // clauses of the same construct. |
| 10072 | // |
| 10073 | // Also, cover one of the cases in: |
| 10074 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.5] |
| 10075 | // If any part of the original storage of a list item has corresponding |
| 10076 | // storage in the device data environment, all of the original storage |
| 10077 | // must have corresponding storage in the device data environment. |
| 10078 | // |
| 10079 | if (DerivedType->isAnyPointerType()) { |
| 10080 | if (CI == CE || SI == SE) { |
| 10081 | SemaRef.Diag( |
| 10082 | DerivedLoc, |
| 10083 | diag::err_omp_pointer_mapped_along_with_derived_section) |
| 10084 | << DerivedLoc; |
| 10085 | } else { |
| 10086 | assert(CI != CE && SI != SE); |
| 10087 | SemaRef.Diag(DerivedLoc, diag::err_omp_same_pointer_derreferenced) |
| 10088 | << DerivedLoc; |
| 10089 | } |
| 10090 | SemaRef.Diag(RE->getExprLoc(), diag::note_used_here) |
| 10091 | << RE->getSourceRange(); |
| 10092 | return true; |
| 10093 | } |
| 10094 | |
| 10095 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.4] |
| 10096 | // List items of map clauses in the same construct must not share |
| 10097 | // original storage. |
| 10098 | // |
| 10099 | // An expression is a subset of the other. |
| 10100 | if (CurrentRegionOnly && (CI == CE || SI == SE)) { |
| 10101 | SemaRef.Diag(ELoc, diag::err_omp_map_shared_storage) << ERange; |
| 10102 | SemaRef.Diag(RE->getExprLoc(), diag::note_used_here) |
| 10103 | << RE->getSourceRange(); |
| 10104 | return true; |
| 10105 | } |
| 10106 | |
| 10107 | // The current expression uses the same base as other expression in the |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10108 | // data environment but does not contain it completely. |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10109 | if (!CurrentRegionOnly && SI != SE) |
| 10110 | EnclosingExpr = RE; |
| 10111 | |
| 10112 | // The current expression is a subset of the expression in the data |
| 10113 | // environment. |
| 10114 | IsEnclosedByDataEnvironmentExpr |= |
| 10115 | (!CurrentRegionOnly && CI != CE && SI == SE); |
| 10116 | |
| 10117 | return false; |
| 10118 | }); |
| 10119 | |
| 10120 | if (CurrentRegionOnly) |
| 10121 | return FoundError; |
| 10122 | |
| 10123 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.5] |
| 10124 | // If any part of the original storage of a list item has corresponding |
| 10125 | // storage in the device data environment, all of the original storage must |
| 10126 | // have corresponding storage in the device data environment. |
| 10127 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.6] |
| 10128 | // If a list item is an element of a structure, and a different element of |
| 10129 | // the structure has a corresponding list item in the device data environment |
| 10130 | // prior to a task encountering the construct associated with the map clause, |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10131 | // then the list item must also have a corresponding list item in the device |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10132 | // data environment prior to the task encountering the construct. |
| 10133 | // |
| 10134 | if (EnclosingExpr && !IsEnclosedByDataEnvironmentExpr) { |
| 10135 | SemaRef.Diag(ELoc, |
| 10136 | diag::err_omp_original_storage_is_shared_and_does_not_contain) |
| 10137 | << ERange; |
| 10138 | SemaRef.Diag(EnclosingExpr->getExprLoc(), diag::note_used_here) |
| 10139 | << EnclosingExpr->getSourceRange(); |
| 10140 | return true; |
| 10141 | } |
| 10142 | |
| 10143 | return FoundError; |
| 10144 | } |
| 10145 | |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 10146 | OMPClause * |
| 10147 | Sema::ActOnOpenMPMapClause(OpenMPMapClauseKind MapTypeModifier, |
| 10148 | OpenMPMapClauseKind MapType, bool IsMapTypeImplicit, |
| 10149 | SourceLocation MapLoc, SourceLocation ColonLoc, |
| 10150 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
| 10151 | SourceLocation LParenLoc, SourceLocation EndLoc) { |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10152 | SmallVector<Expr *, 4> Vars; |
| 10153 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10154 | // Keep track of the mappable components and base declarations in this clause. |
| 10155 | // Each entry in the list is going to have a list of components associated. We |
| 10156 | // record each set of the components so that we can build the clause later on. |
| 10157 | // In the end we should have the same amount of declarations and component |
| 10158 | // lists. |
| 10159 | OMPClauseMappableExprCommon::MappableExprComponentLists ClauseComponents; |
| 10160 | SmallVector<ValueDecl *, 16> ClauseBaseDeclarations; |
| 10161 | |
| 10162 | ClauseComponents.reserve(VarList.size()); |
| 10163 | ClauseBaseDeclarations.reserve(VarList.size()); |
| 10164 | |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10165 | for (auto &RE : VarList) { |
| 10166 | assert(RE && "Null expr in omp map"); |
| 10167 | if (isa<DependentScopeDeclRefExpr>(RE)) { |
| 10168 | // It will be analyzed later. |
| 10169 | Vars.push_back(RE); |
| 10170 | continue; |
| 10171 | } |
| 10172 | SourceLocation ELoc = RE->getExprLoc(); |
| 10173 | |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10174 | auto *VE = RE->IgnoreParenLValueCasts(); |
| 10175 | |
| 10176 | if (VE->isValueDependent() || VE->isTypeDependent() || |
| 10177 | VE->isInstantiationDependent() || |
| 10178 | VE->containsUnexpandedParameterPack()) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10179 | // We can only analyze this information once the missing information is |
| 10180 | // resolved. |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10181 | Vars.push_back(RE); |
| 10182 | continue; |
| 10183 | } |
| 10184 | |
| 10185 | auto *SimpleExpr = RE->IgnoreParenCasts(); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10186 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10187 | if (!RE->IgnoreParenImpCasts()->isLValue()) { |
| 10188 | Diag(ELoc, diag::err_omp_expected_named_var_member_or_array_expression) |
| 10189 | << RE->getSourceRange(); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10190 | continue; |
| 10191 | } |
| 10192 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10193 | OMPClauseMappableExprCommon::MappableExprComponentList CurComponents; |
| 10194 | ValueDecl *CurDeclaration = nullptr; |
| 10195 | |
| 10196 | // Obtain the array or member expression bases if required. Also, fill the |
| 10197 | // components array with all the components identified in the process. |
| 10198 | auto *BE = CheckMapClauseExpressionBase(*this, SimpleExpr, CurComponents); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10199 | if (!BE) |
| 10200 | continue; |
| 10201 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10202 | assert(!CurComponents.empty() && |
| 10203 | "Invalid mappable expression information."); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10204 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10205 | // For the following checks, we rely on the base declaration which is |
| 10206 | // expected to be associated with the last component. The declaration is |
| 10207 | // expected to be a variable or a field (if 'this' is being mapped). |
| 10208 | CurDeclaration = CurComponents.back().getAssociatedDeclaration(); |
| 10209 | assert(CurDeclaration && "Null decl on map clause."); |
| 10210 | assert( |
| 10211 | CurDeclaration->isCanonicalDecl() && |
| 10212 | "Expecting components to have associated only canonical declarations."); |
| 10213 | |
| 10214 | auto *VD = dyn_cast<VarDecl>(CurDeclaration); |
| 10215 | auto *FD = dyn_cast<FieldDecl>(CurDeclaration); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10216 | |
| 10217 | assert((VD || FD) && "Only variables or fields are expected here!"); |
NAKAMURA Takumi | 6dcb814 | 2016-01-23 01:38:20 +0000 | [diff] [blame] | 10218 | (void)FD; |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10219 | |
| 10220 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.10] |
| 10221 | // threadprivate variables cannot appear in a map clause. |
| 10222 | if (VD && DSAStack->isThreadPrivate(VD)) { |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10223 | auto DVar = DSAStack->getTopDSA(VD, false); |
| 10224 | Diag(ELoc, diag::err_omp_threadprivate_in_map); |
| 10225 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 10226 | continue; |
| 10227 | } |
| 10228 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10229 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.9] |
| 10230 | // A list item cannot appear in both a map clause and a data-sharing |
| 10231 | // attribute clause on the same construct. |
| 10232 | // |
| 10233 | // TODO: Implement this check - it cannot currently be tested because of |
| 10234 | // missing implementation of the other data sharing clauses in target |
| 10235 | // directives. |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10236 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10237 | // Check conflicts with other map clause expressions. We check the conflicts |
| 10238 | // with the current construct separately from the enclosing data |
| 10239 | // environment, because the restrictions are different. |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10240 | if (CheckMapConflicts(*this, DSAStack, CurDeclaration, SimpleExpr, |
| 10241 | /*CurrentRegionOnly=*/true, CurComponents)) |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10242 | break; |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10243 | if (CheckMapConflicts(*this, DSAStack, CurDeclaration, SimpleExpr, |
| 10244 | /*CurrentRegionOnly=*/false, CurComponents)) |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10245 | break; |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10246 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10247 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] |
| 10248 | // If the type of a list item is a reference to a type T then the type will |
| 10249 | // be considered to be T for all purposes of this clause. |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10250 | QualType Type = CurDeclaration->getType().getNonReferenceType(); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10251 | |
| 10252 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.9] |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10253 | // A list item must have a mappable type. |
| 10254 | if (!CheckTypeMappable(VE->getExprLoc(), VE->getSourceRange(), *this, |
| 10255 | DSAStack, Type)) |
| 10256 | continue; |
| 10257 | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 10258 | // target enter data |
| 10259 | // OpenMP [2.10.2, Restrictions, p. 99] |
| 10260 | // A map-type must be specified in all map clauses and must be either |
| 10261 | // to or alloc. |
| 10262 | OpenMPDirectiveKind DKind = DSAStack->getCurrentDirective(); |
| 10263 | if (DKind == OMPD_target_enter_data && |
| 10264 | !(MapType == OMPC_MAP_to || MapType == OMPC_MAP_alloc)) { |
| 10265 | Diag(StartLoc, diag::err_omp_invalid_map_type_for_directive) |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 10266 | << (IsMapTypeImplicit ? 1 : 0) |
| 10267 | << getOpenMPSimpleClauseTypeName(OMPC_map, MapType) |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 10268 | << getOpenMPDirectiveName(DKind); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10269 | continue; |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 10270 | } |
| 10271 | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 10272 | // target exit_data |
| 10273 | // OpenMP [2.10.3, Restrictions, p. 102] |
| 10274 | // A map-type must be specified in all map clauses and must be either |
| 10275 | // from, release, or delete. |
| 10276 | DKind = DSAStack->getCurrentDirective(); |
| 10277 | if (DKind == OMPD_target_exit_data && |
| 10278 | !(MapType == OMPC_MAP_from || MapType == OMPC_MAP_release || |
| 10279 | MapType == OMPC_MAP_delete)) { |
| 10280 | Diag(StartLoc, diag::err_omp_invalid_map_type_for_directive) |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 10281 | << (IsMapTypeImplicit ? 1 : 0) |
| 10282 | << getOpenMPSimpleClauseTypeName(OMPC_map, MapType) |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 10283 | << getOpenMPDirectiveName(DKind); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10284 | continue; |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 10285 | } |
| 10286 | |
Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 10287 | // OpenMP 4.5 [2.15.5.1, Restrictions, p.3] |
| 10288 | // A list item cannot appear in both a map clause and a data-sharing |
| 10289 | // attribute clause on the same construct |
| 10290 | if (DKind == OMPD_target && VD) { |
| 10291 | auto DVar = DSAStack->getTopDSA(VD, false); |
| 10292 | if (isOpenMPPrivate(DVar.CKind)) { |
| 10293 | Diag(ELoc, diag::err_omp_variable_in_map_and_dsa) |
| 10294 | << getOpenMPClauseName(DVar.CKind) |
| 10295 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10296 | ReportOriginalDSA(*this, DSAStack, CurDeclaration, DVar); |
Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 10297 | continue; |
| 10298 | } |
| 10299 | } |
| 10300 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10301 | // Save the current expression. |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10302 | Vars.push_back(RE); |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10303 | |
| 10304 | // Store the components in the stack so that they can be used to check |
| 10305 | // against other clauses later on. |
| 10306 | DSAStack->addMappableExpressionComponents(CurDeclaration, CurComponents); |
| 10307 | |
| 10308 | // Save the components and declaration to create the clause. For purposes of |
| 10309 | // the clause creation, any component list that has has base 'this' uses |
| 10310 | // null has |
| 10311 | ClauseComponents.resize(ClauseComponents.size() + 1); |
| 10312 | ClauseComponents.back().append(CurComponents.begin(), CurComponents.end()); |
| 10313 | ClauseBaseDeclarations.push_back(isa<MemberExpr>(BE) ? nullptr |
| 10314 | : CurDeclaration); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10315 | } |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10316 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10317 | // We need to produce a map clause even if we don't have variables so that |
| 10318 | // other diagnostics related with non-existing map clauses are accurate. |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10319 | return OMPMapClause::Create( |
| 10320 | Context, StartLoc, LParenLoc, EndLoc, Vars, ClauseBaseDeclarations, |
| 10321 | ClauseComponents, MapTypeModifier, MapType, IsMapTypeImplicit, MapLoc); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10322 | } |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 10323 | |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 10324 | QualType Sema::ActOnOpenMPDeclareReductionType(SourceLocation TyLoc, |
| 10325 | TypeResult ParsedType) { |
| 10326 | assert(ParsedType.isUsable()); |
| 10327 | |
| 10328 | QualType ReductionType = GetTypeFromParser(ParsedType.get()); |
| 10329 | if (ReductionType.isNull()) |
| 10330 | return QualType(); |
| 10331 | |
| 10332 | // [OpenMP 4.0], 2.15 declare reduction Directive, Restrictions, C\C++ |
| 10333 | // A type name in a declare reduction directive cannot be a function type, an |
| 10334 | // array type, a reference type, or a type qualified with const, volatile or |
| 10335 | // restrict. |
| 10336 | if (ReductionType.hasQualifiers()) { |
| 10337 | Diag(TyLoc, diag::err_omp_reduction_wrong_type) << 0; |
| 10338 | return QualType(); |
| 10339 | } |
| 10340 | |
| 10341 | if (ReductionType->isFunctionType()) { |
| 10342 | Diag(TyLoc, diag::err_omp_reduction_wrong_type) << 1; |
| 10343 | return QualType(); |
| 10344 | } |
| 10345 | if (ReductionType->isReferenceType()) { |
| 10346 | Diag(TyLoc, diag::err_omp_reduction_wrong_type) << 2; |
| 10347 | return QualType(); |
| 10348 | } |
| 10349 | if (ReductionType->isArrayType()) { |
| 10350 | Diag(TyLoc, diag::err_omp_reduction_wrong_type) << 3; |
| 10351 | return QualType(); |
| 10352 | } |
| 10353 | return ReductionType; |
| 10354 | } |
| 10355 | |
| 10356 | Sema::DeclGroupPtrTy Sema::ActOnOpenMPDeclareReductionDirectiveStart( |
| 10357 | Scope *S, DeclContext *DC, DeclarationName Name, |
| 10358 | ArrayRef<std::pair<QualType, SourceLocation>> ReductionTypes, |
| 10359 | AccessSpecifier AS, Decl *PrevDeclInScope) { |
| 10360 | SmallVector<Decl *, 8> Decls; |
| 10361 | Decls.reserve(ReductionTypes.size()); |
| 10362 | |
| 10363 | LookupResult Lookup(*this, Name, SourceLocation(), LookupOMPReductionName, |
| 10364 | ForRedeclaration); |
| 10365 | // [OpenMP 4.0], 2.15 declare reduction Directive, Restrictions |
| 10366 | // A reduction-identifier may not be re-declared in the current scope for the |
| 10367 | // same type or for a type that is compatible according to the base language |
| 10368 | // rules. |
| 10369 | llvm::DenseMap<QualType, SourceLocation> PreviousRedeclTypes; |
| 10370 | OMPDeclareReductionDecl *PrevDRD = nullptr; |
| 10371 | bool InCompoundScope = true; |
| 10372 | if (S != nullptr) { |
| 10373 | // Find previous declaration with the same name not referenced in other |
| 10374 | // declarations. |
| 10375 | FunctionScopeInfo *ParentFn = getEnclosingFunction(); |
| 10376 | InCompoundScope = |
| 10377 | (ParentFn != nullptr) && !ParentFn->CompoundScopes.empty(); |
| 10378 | LookupName(Lookup, S); |
| 10379 | FilterLookupForScope(Lookup, DC, S, /*ConsiderLinkage=*/false, |
| 10380 | /*AllowInlineNamespace=*/false); |
| 10381 | llvm::DenseMap<OMPDeclareReductionDecl *, bool> UsedAsPrevious; |
| 10382 | auto Filter = Lookup.makeFilter(); |
| 10383 | while (Filter.hasNext()) { |
| 10384 | auto *PrevDecl = cast<OMPDeclareReductionDecl>(Filter.next()); |
| 10385 | if (InCompoundScope) { |
| 10386 | auto I = UsedAsPrevious.find(PrevDecl); |
| 10387 | if (I == UsedAsPrevious.end()) |
| 10388 | UsedAsPrevious[PrevDecl] = false; |
| 10389 | if (auto *D = PrevDecl->getPrevDeclInScope()) |
| 10390 | UsedAsPrevious[D] = true; |
| 10391 | } |
| 10392 | PreviousRedeclTypes[PrevDecl->getType().getCanonicalType()] = |
| 10393 | PrevDecl->getLocation(); |
| 10394 | } |
| 10395 | Filter.done(); |
| 10396 | if (InCompoundScope) { |
| 10397 | for (auto &PrevData : UsedAsPrevious) { |
| 10398 | if (!PrevData.second) { |
| 10399 | PrevDRD = PrevData.first; |
| 10400 | break; |
| 10401 | } |
| 10402 | } |
| 10403 | } |
| 10404 | } else if (PrevDeclInScope != nullptr) { |
| 10405 | auto *PrevDRDInScope = PrevDRD = |
| 10406 | cast<OMPDeclareReductionDecl>(PrevDeclInScope); |
| 10407 | do { |
| 10408 | PreviousRedeclTypes[PrevDRDInScope->getType().getCanonicalType()] = |
| 10409 | PrevDRDInScope->getLocation(); |
| 10410 | PrevDRDInScope = PrevDRDInScope->getPrevDeclInScope(); |
| 10411 | } while (PrevDRDInScope != nullptr); |
| 10412 | } |
| 10413 | for (auto &TyData : ReductionTypes) { |
| 10414 | auto I = PreviousRedeclTypes.find(TyData.first.getCanonicalType()); |
| 10415 | bool Invalid = false; |
| 10416 | if (I != PreviousRedeclTypes.end()) { |
| 10417 | Diag(TyData.second, diag::err_omp_declare_reduction_redefinition) |
| 10418 | << TyData.first; |
| 10419 | Diag(I->second, diag::note_previous_definition); |
| 10420 | Invalid = true; |
| 10421 | } |
| 10422 | PreviousRedeclTypes[TyData.first.getCanonicalType()] = TyData.second; |
| 10423 | auto *DRD = OMPDeclareReductionDecl::Create(Context, DC, TyData.second, |
| 10424 | Name, TyData.first, PrevDRD); |
| 10425 | DC->addDecl(DRD); |
| 10426 | DRD->setAccess(AS); |
| 10427 | Decls.push_back(DRD); |
| 10428 | if (Invalid) |
| 10429 | DRD->setInvalidDecl(); |
| 10430 | else |
| 10431 | PrevDRD = DRD; |
| 10432 | } |
| 10433 | |
| 10434 | return DeclGroupPtrTy::make( |
| 10435 | DeclGroupRef::Create(Context, Decls.begin(), Decls.size())); |
| 10436 | } |
| 10437 | |
| 10438 | void Sema::ActOnOpenMPDeclareReductionCombinerStart(Scope *S, Decl *D) { |
| 10439 | auto *DRD = cast<OMPDeclareReductionDecl>(D); |
| 10440 | |
| 10441 | // Enter new function scope. |
| 10442 | PushFunctionScope(); |
| 10443 | getCurFunction()->setHasBranchProtectedScope(); |
| 10444 | getCurFunction()->setHasOMPDeclareReductionCombiner(); |
| 10445 | |
| 10446 | if (S != nullptr) |
| 10447 | PushDeclContext(S, DRD); |
| 10448 | else |
| 10449 | CurContext = DRD; |
| 10450 | |
| 10451 | PushExpressionEvaluationContext(PotentiallyEvaluated); |
| 10452 | |
| 10453 | QualType ReductionType = DRD->getType(); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 10454 | // Create 'T* omp_parm;T omp_in;'. All references to 'omp_in' will |
| 10455 | // be replaced by '*omp_parm' during codegen. This required because 'omp_in' |
| 10456 | // uses semantics of argument handles by value, but it should be passed by |
| 10457 | // reference. C lang does not support references, so pass all parameters as |
| 10458 | // pointers. |
| 10459 | // Create 'T omp_in;' variable. |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 10460 | auto *OmpInParm = |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 10461 | buildVarDecl(*this, D->getLocation(), ReductionType, "omp_in"); |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 10462 | // Create 'T* omp_parm;T omp_out;'. All references to 'omp_out' will |
| 10463 | // be replaced by '*omp_parm' during codegen. This required because 'omp_out' |
| 10464 | // uses semantics of argument handles by value, but it should be passed by |
| 10465 | // reference. C lang does not support references, so pass all parameters as |
| 10466 | // pointers. |
| 10467 | // Create 'T omp_out;' variable. |
| 10468 | auto *OmpOutParm = |
| 10469 | buildVarDecl(*this, D->getLocation(), ReductionType, "omp_out"); |
| 10470 | if (S != nullptr) { |
| 10471 | PushOnScopeChains(OmpInParm, S); |
| 10472 | PushOnScopeChains(OmpOutParm, S); |
| 10473 | } else { |
| 10474 | DRD->addDecl(OmpInParm); |
| 10475 | DRD->addDecl(OmpOutParm); |
| 10476 | } |
| 10477 | } |
| 10478 | |
| 10479 | void Sema::ActOnOpenMPDeclareReductionCombinerEnd(Decl *D, Expr *Combiner) { |
| 10480 | auto *DRD = cast<OMPDeclareReductionDecl>(D); |
| 10481 | DiscardCleanupsInEvaluationContext(); |
| 10482 | PopExpressionEvaluationContext(); |
| 10483 | |
| 10484 | PopDeclContext(); |
| 10485 | PopFunctionScopeInfo(); |
| 10486 | |
| 10487 | if (Combiner != nullptr) |
| 10488 | DRD->setCombiner(Combiner); |
| 10489 | else |
| 10490 | DRD->setInvalidDecl(); |
| 10491 | } |
| 10492 | |
| 10493 | void Sema::ActOnOpenMPDeclareReductionInitializerStart(Scope *S, Decl *D) { |
| 10494 | auto *DRD = cast<OMPDeclareReductionDecl>(D); |
| 10495 | |
| 10496 | // Enter new function scope. |
| 10497 | PushFunctionScope(); |
| 10498 | getCurFunction()->setHasBranchProtectedScope(); |
| 10499 | |
| 10500 | if (S != nullptr) |
| 10501 | PushDeclContext(S, DRD); |
| 10502 | else |
| 10503 | CurContext = DRD; |
| 10504 | |
| 10505 | PushExpressionEvaluationContext(PotentiallyEvaluated); |
| 10506 | |
| 10507 | QualType ReductionType = DRD->getType(); |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 10508 | // Create 'T* omp_parm;T omp_priv;'. All references to 'omp_priv' will |
| 10509 | // be replaced by '*omp_parm' during codegen. This required because 'omp_priv' |
| 10510 | // uses semantics of argument handles by value, but it should be passed by |
| 10511 | // reference. C lang does not support references, so pass all parameters as |
| 10512 | // pointers. |
| 10513 | // Create 'T omp_priv;' variable. |
| 10514 | auto *OmpPrivParm = |
| 10515 | buildVarDecl(*this, D->getLocation(), ReductionType, "omp_priv"); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 10516 | // Create 'T* omp_parm;T omp_orig;'. All references to 'omp_orig' will |
| 10517 | // be replaced by '*omp_parm' during codegen. This required because 'omp_orig' |
| 10518 | // uses semantics of argument handles by value, but it should be passed by |
| 10519 | // reference. C lang does not support references, so pass all parameters as |
| 10520 | // pointers. |
| 10521 | // Create 'T omp_orig;' variable. |
| 10522 | auto *OmpOrigParm = |
| 10523 | buildVarDecl(*this, D->getLocation(), ReductionType, "omp_orig"); |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 10524 | if (S != nullptr) { |
| 10525 | PushOnScopeChains(OmpPrivParm, S); |
| 10526 | PushOnScopeChains(OmpOrigParm, S); |
| 10527 | } else { |
| 10528 | DRD->addDecl(OmpPrivParm); |
| 10529 | DRD->addDecl(OmpOrigParm); |
| 10530 | } |
| 10531 | } |
| 10532 | |
| 10533 | void Sema::ActOnOpenMPDeclareReductionInitializerEnd(Decl *D, |
| 10534 | Expr *Initializer) { |
| 10535 | auto *DRD = cast<OMPDeclareReductionDecl>(D); |
| 10536 | DiscardCleanupsInEvaluationContext(); |
| 10537 | PopExpressionEvaluationContext(); |
| 10538 | |
| 10539 | PopDeclContext(); |
| 10540 | PopFunctionScopeInfo(); |
| 10541 | |
| 10542 | if (Initializer != nullptr) |
| 10543 | DRD->setInitializer(Initializer); |
| 10544 | else |
| 10545 | DRD->setInvalidDecl(); |
| 10546 | } |
| 10547 | |
| 10548 | Sema::DeclGroupPtrTy Sema::ActOnOpenMPDeclareReductionDirectiveEnd( |
| 10549 | Scope *S, DeclGroupPtrTy DeclReductions, bool IsValid) { |
| 10550 | for (auto *D : DeclReductions.get()) { |
| 10551 | if (IsValid) { |
| 10552 | auto *DRD = cast<OMPDeclareReductionDecl>(D); |
| 10553 | if (S != nullptr) |
| 10554 | PushOnScopeChains(DRD, S, /*AddToContext=*/false); |
| 10555 | } else |
| 10556 | D->setInvalidDecl(); |
| 10557 | } |
| 10558 | return DeclReductions; |
| 10559 | } |
| 10560 | |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 10561 | OMPClause *Sema::ActOnOpenMPNumTeamsClause(Expr *NumTeams, |
| 10562 | SourceLocation StartLoc, |
| 10563 | SourceLocation LParenLoc, |
| 10564 | SourceLocation EndLoc) { |
| 10565 | Expr *ValExpr = NumTeams; |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 10566 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 10567 | // OpenMP [teams Constrcut, Restrictions] |
| 10568 | // The num_teams expression must evaluate to a positive integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 10569 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_num_teams, |
| 10570 | /*StrictlyPositive=*/true)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 10571 | return nullptr; |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 10572 | |
| 10573 | return new (Context) OMPNumTeamsClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 10574 | } |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 10575 | |
| 10576 | OMPClause *Sema::ActOnOpenMPThreadLimitClause(Expr *ThreadLimit, |
| 10577 | SourceLocation StartLoc, |
| 10578 | SourceLocation LParenLoc, |
| 10579 | SourceLocation EndLoc) { |
| 10580 | Expr *ValExpr = ThreadLimit; |
| 10581 | |
| 10582 | // OpenMP [teams Constrcut, Restrictions] |
| 10583 | // The thread_limit expression must evaluate to a positive integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 10584 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_thread_limit, |
| 10585 | /*StrictlyPositive=*/true)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 10586 | return nullptr; |
| 10587 | |
| 10588 | return new (Context) OMPThreadLimitClause(ValExpr, StartLoc, LParenLoc, |
| 10589 | EndLoc); |
| 10590 | } |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 10591 | |
| 10592 | OMPClause *Sema::ActOnOpenMPPriorityClause(Expr *Priority, |
| 10593 | SourceLocation StartLoc, |
| 10594 | SourceLocation LParenLoc, |
| 10595 | SourceLocation EndLoc) { |
| 10596 | Expr *ValExpr = Priority; |
| 10597 | |
| 10598 | // OpenMP [2.9.1, task Constrcut] |
| 10599 | // The priority-value is a non-negative numerical scalar expression. |
| 10600 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_priority, |
| 10601 | /*StrictlyPositive=*/false)) |
| 10602 | return nullptr; |
| 10603 | |
| 10604 | return new (Context) OMPPriorityClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 10605 | } |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 10606 | |
| 10607 | OMPClause *Sema::ActOnOpenMPGrainsizeClause(Expr *Grainsize, |
| 10608 | SourceLocation StartLoc, |
| 10609 | SourceLocation LParenLoc, |
| 10610 | SourceLocation EndLoc) { |
| 10611 | Expr *ValExpr = Grainsize; |
| 10612 | |
| 10613 | // OpenMP [2.9.2, taskloop Constrcut] |
| 10614 | // The parameter of the grainsize clause must be a positive integer |
| 10615 | // expression. |
| 10616 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_grainsize, |
| 10617 | /*StrictlyPositive=*/true)) |
| 10618 | return nullptr; |
| 10619 | |
| 10620 | return new (Context) OMPGrainsizeClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 10621 | } |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 10622 | |
| 10623 | OMPClause *Sema::ActOnOpenMPNumTasksClause(Expr *NumTasks, |
| 10624 | SourceLocation StartLoc, |
| 10625 | SourceLocation LParenLoc, |
| 10626 | SourceLocation EndLoc) { |
| 10627 | Expr *ValExpr = NumTasks; |
| 10628 | |
| 10629 | // OpenMP [2.9.2, taskloop Constrcut] |
| 10630 | // The parameter of the num_tasks clause must be a positive integer |
| 10631 | // expression. |
| 10632 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_num_tasks, |
| 10633 | /*StrictlyPositive=*/true)) |
| 10634 | return nullptr; |
| 10635 | |
| 10636 | return new (Context) OMPNumTasksClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 10637 | } |
| 10638 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 10639 | OMPClause *Sema::ActOnOpenMPHintClause(Expr *Hint, SourceLocation StartLoc, |
| 10640 | SourceLocation LParenLoc, |
| 10641 | SourceLocation EndLoc) { |
| 10642 | // OpenMP [2.13.2, critical construct, Description] |
| 10643 | // ... where hint-expression is an integer constant expression that evaluates |
| 10644 | // to a valid lock hint. |
| 10645 | ExprResult HintExpr = VerifyPositiveIntegerConstantInClause(Hint, OMPC_hint); |
| 10646 | if (HintExpr.isInvalid()) |
| 10647 | return nullptr; |
| 10648 | return new (Context) |
| 10649 | OMPHintClause(HintExpr.get(), StartLoc, LParenLoc, EndLoc); |
| 10650 | } |
| 10651 | |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 10652 | OMPClause *Sema::ActOnOpenMPDistScheduleClause( |
| 10653 | OpenMPDistScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, |
| 10654 | SourceLocation LParenLoc, SourceLocation KindLoc, SourceLocation CommaLoc, |
| 10655 | SourceLocation EndLoc) { |
| 10656 | if (Kind == OMPC_DIST_SCHEDULE_unknown) { |
| 10657 | std::string Values; |
| 10658 | Values += "'"; |
| 10659 | Values += getOpenMPSimpleClauseTypeName(OMPC_dist_schedule, 0); |
| 10660 | Values += "'"; |
| 10661 | Diag(KindLoc, diag::err_omp_unexpected_clause_value) |
| 10662 | << Values << getOpenMPClauseName(OMPC_dist_schedule); |
| 10663 | return nullptr; |
| 10664 | } |
| 10665 | Expr *ValExpr = ChunkSize; |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 10666 | Stmt *HelperValStmt = nullptr; |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 10667 | if (ChunkSize) { |
| 10668 | if (!ChunkSize->isValueDependent() && !ChunkSize->isTypeDependent() && |
| 10669 | !ChunkSize->isInstantiationDependent() && |
| 10670 | !ChunkSize->containsUnexpandedParameterPack()) { |
| 10671 | SourceLocation ChunkSizeLoc = ChunkSize->getLocStart(); |
| 10672 | ExprResult Val = |
| 10673 | PerformOpenMPImplicitIntegerConversion(ChunkSizeLoc, ChunkSize); |
| 10674 | if (Val.isInvalid()) |
| 10675 | return nullptr; |
| 10676 | |
| 10677 | ValExpr = Val.get(); |
| 10678 | |
| 10679 | // OpenMP [2.7.1, Restrictions] |
| 10680 | // chunk_size must be a loop invariant integer expression with a positive |
| 10681 | // value. |
| 10682 | llvm::APSInt Result; |
| 10683 | if (ValExpr->isIntegerConstantExpr(Result, Context)) { |
| 10684 | if (Result.isSigned() && !Result.isStrictlyPositive()) { |
| 10685 | Diag(ChunkSizeLoc, diag::err_omp_negative_expression_in_clause) |
| 10686 | << "dist_schedule" << ChunkSize->getSourceRange(); |
| 10687 | return nullptr; |
| 10688 | } |
| 10689 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective())) { |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 10690 | llvm::MapVector<Expr *, DeclRefExpr *> Captures; |
| 10691 | ValExpr = tryBuildCapture(*this, ValExpr, Captures).get(); |
| 10692 | HelperValStmt = buildPreInits(Context, Captures); |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 10693 | } |
| 10694 | } |
| 10695 | } |
| 10696 | |
| 10697 | return new (Context) |
| 10698 | OMPDistScheduleClause(StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc, |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 10699 | Kind, ValExpr, HelperValStmt); |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 10700 | } |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 10701 | |
| 10702 | OMPClause *Sema::ActOnOpenMPDefaultmapClause( |
| 10703 | OpenMPDefaultmapClauseModifier M, OpenMPDefaultmapClauseKind Kind, |
| 10704 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation MLoc, |
| 10705 | SourceLocation KindLoc, SourceLocation EndLoc) { |
| 10706 | // OpenMP 4.5 only supports 'defaultmap(tofrom: scalar)' |
| 10707 | if (M != OMPC_DEFAULTMAP_MODIFIER_tofrom || |
| 10708 | Kind != OMPC_DEFAULTMAP_scalar) { |
| 10709 | std::string Value; |
| 10710 | SourceLocation Loc; |
| 10711 | Value += "'"; |
| 10712 | if (M != OMPC_DEFAULTMAP_MODIFIER_tofrom) { |
| 10713 | Value += getOpenMPSimpleClauseTypeName(OMPC_defaultmap, |
| 10714 | OMPC_DEFAULTMAP_MODIFIER_tofrom); |
| 10715 | Loc = MLoc; |
| 10716 | } else { |
| 10717 | Value += getOpenMPSimpleClauseTypeName(OMPC_defaultmap, |
| 10718 | OMPC_DEFAULTMAP_scalar); |
| 10719 | Loc = KindLoc; |
| 10720 | } |
| 10721 | Value += "'"; |
| 10722 | Diag(Loc, diag::err_omp_unexpected_clause_value) |
| 10723 | << Value << getOpenMPClauseName(OMPC_defaultmap); |
| 10724 | return nullptr; |
| 10725 | } |
| 10726 | |
| 10727 | return new (Context) |
| 10728 | OMPDefaultmapClause(StartLoc, LParenLoc, MLoc, KindLoc, EndLoc, Kind, M); |
| 10729 | } |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 10730 | |
| 10731 | bool Sema::ActOnStartOpenMPDeclareTargetDirective(SourceLocation Loc) { |
| 10732 | DeclContext *CurLexicalContext = getCurLexicalContext(); |
| 10733 | if (!CurLexicalContext->isFileContext() && |
| 10734 | !CurLexicalContext->isExternCContext() && |
| 10735 | !CurLexicalContext->isExternCXXContext()) { |
| 10736 | Diag(Loc, diag::err_omp_region_not_file_context); |
| 10737 | return false; |
| 10738 | } |
| 10739 | if (IsInOpenMPDeclareTargetContext) { |
| 10740 | Diag(Loc, diag::err_omp_enclosed_declare_target); |
| 10741 | return false; |
| 10742 | } |
| 10743 | |
| 10744 | IsInOpenMPDeclareTargetContext = true; |
| 10745 | return true; |
| 10746 | } |
| 10747 | |
| 10748 | void Sema::ActOnFinishOpenMPDeclareTargetDirective() { |
| 10749 | assert(IsInOpenMPDeclareTargetContext && |
| 10750 | "Unexpected ActOnFinishOpenMPDeclareTargetDirective"); |
| 10751 | |
| 10752 | IsInOpenMPDeclareTargetContext = false; |
| 10753 | } |
| 10754 | |
| 10755 | static void checkDeclInTargetContext(SourceLocation SL, SourceRange SR, |
| 10756 | Sema &SemaRef, Decl *D) { |
| 10757 | if (!D) |
| 10758 | return; |
| 10759 | Decl *LD = nullptr; |
| 10760 | if (isa<TagDecl>(D)) { |
| 10761 | LD = cast<TagDecl>(D)->getDefinition(); |
| 10762 | } else if (isa<VarDecl>(D)) { |
| 10763 | LD = cast<VarDecl>(D)->getDefinition(); |
| 10764 | |
| 10765 | // If this is an implicit variable that is legal and we do not need to do |
| 10766 | // anything. |
| 10767 | if (cast<VarDecl>(D)->isImplicit()) { |
| 10768 | D->addAttr(OMPDeclareTargetDeclAttr::CreateImplicit(SemaRef.Context)); |
| 10769 | if (ASTMutationListener *ML = SemaRef.Context.getASTMutationListener()) |
| 10770 | ML->DeclarationMarkedOpenMPDeclareTarget(D); |
| 10771 | return; |
| 10772 | } |
| 10773 | |
| 10774 | } else if (isa<FunctionDecl>(D)) { |
| 10775 | const FunctionDecl *FD = nullptr; |
| 10776 | if (cast<FunctionDecl>(D)->hasBody(FD)) |
| 10777 | LD = const_cast<FunctionDecl *>(FD); |
| 10778 | |
| 10779 | // If the definition is associated with the current declaration in the |
| 10780 | // target region (it can be e.g. a lambda) that is legal and we do not need |
| 10781 | // to do anything else. |
| 10782 | if (LD == D) { |
| 10783 | D->addAttr(OMPDeclareTargetDeclAttr::CreateImplicit(SemaRef.Context)); |
| 10784 | if (ASTMutationListener *ML = SemaRef.Context.getASTMutationListener()) |
| 10785 | ML->DeclarationMarkedOpenMPDeclareTarget(D); |
| 10786 | return; |
| 10787 | } |
| 10788 | } |
| 10789 | if (!LD) |
| 10790 | LD = D; |
| 10791 | if (LD && !LD->hasAttr<OMPDeclareTargetDeclAttr>() && |
| 10792 | (isa<VarDecl>(LD) || isa<FunctionDecl>(LD))) { |
| 10793 | // Outlined declaration is not declared target. |
| 10794 | if (LD->isOutOfLine()) { |
| 10795 | SemaRef.Diag(LD->getLocation(), diag::warn_omp_not_in_target_context); |
| 10796 | SemaRef.Diag(SL, diag::note_used_here) << SR; |
| 10797 | } else { |
| 10798 | DeclContext *DC = LD->getDeclContext(); |
| 10799 | while (DC) { |
| 10800 | if (isa<FunctionDecl>(DC) && |
| 10801 | cast<FunctionDecl>(DC)->hasAttr<OMPDeclareTargetDeclAttr>()) |
| 10802 | break; |
| 10803 | DC = DC->getParent(); |
| 10804 | } |
| 10805 | if (DC) |
| 10806 | return; |
| 10807 | |
| 10808 | // Is not declared in target context. |
| 10809 | SemaRef.Diag(LD->getLocation(), diag::warn_omp_not_in_target_context); |
| 10810 | SemaRef.Diag(SL, diag::note_used_here) << SR; |
| 10811 | } |
| 10812 | // Mark decl as declared target to prevent further diagnostic. |
| 10813 | D->addAttr(OMPDeclareTargetDeclAttr::CreateImplicit(SemaRef.Context)); |
| 10814 | if (ASTMutationListener *ML = SemaRef.Context.getASTMutationListener()) |
| 10815 | ML->DeclarationMarkedOpenMPDeclareTarget(D); |
| 10816 | } |
| 10817 | } |
| 10818 | |
| 10819 | static bool checkValueDeclInTarget(SourceLocation SL, SourceRange SR, |
| 10820 | Sema &SemaRef, DSAStackTy *Stack, |
| 10821 | ValueDecl *VD) { |
| 10822 | if (VD->hasAttr<OMPDeclareTargetDeclAttr>()) |
| 10823 | return true; |
| 10824 | if (!CheckTypeMappable(SL, SR, SemaRef, Stack, VD->getType())) |
| 10825 | return false; |
| 10826 | return true; |
| 10827 | } |
| 10828 | |
| 10829 | void Sema::checkDeclIsAllowedInOpenMPTarget(Expr *E, Decl *D) { |
| 10830 | if (!D || D->isInvalidDecl()) |
| 10831 | return; |
| 10832 | SourceRange SR = E ? E->getSourceRange() : D->getSourceRange(); |
| 10833 | SourceLocation SL = E ? E->getLocStart() : D->getLocation(); |
| 10834 | // 2.10.6: threadprivate variable cannot appear in a declare target directive. |
| 10835 | if (VarDecl *VD = dyn_cast<VarDecl>(D)) { |
| 10836 | if (DSAStack->isThreadPrivate(VD)) { |
| 10837 | Diag(SL, diag::err_omp_threadprivate_in_target); |
| 10838 | ReportOriginalDSA(*this, DSAStack, VD, DSAStack->getTopDSA(VD, false)); |
| 10839 | return; |
| 10840 | } |
| 10841 | } |
| 10842 | if (ValueDecl *VD = dyn_cast<ValueDecl>(D)) { |
| 10843 | // Problem if any with var declared with incomplete type will be reported |
| 10844 | // as normal, so no need to check it here. |
| 10845 | if ((E || !VD->getType()->isIncompleteType()) && |
| 10846 | !checkValueDeclInTarget(SL, SR, *this, DSAStack, VD)) { |
| 10847 | // Mark decl as declared target to prevent further diagnostic. |
| 10848 | if (isa<VarDecl>(VD) || isa<FunctionDecl>(VD)) { |
| 10849 | VD->addAttr(OMPDeclareTargetDeclAttr::CreateImplicit(Context)); |
| 10850 | if (ASTMutationListener *ML = Context.getASTMutationListener()) |
| 10851 | ML->DeclarationMarkedOpenMPDeclareTarget(VD); |
| 10852 | } |
| 10853 | return; |
| 10854 | } |
| 10855 | } |
| 10856 | if (!E) { |
| 10857 | // Checking declaration inside declare target region. |
| 10858 | if (!D->hasAttr<OMPDeclareTargetDeclAttr>() && |
| 10859 | (isa<VarDecl>(D) || isa<FunctionDecl>(D))) { |
| 10860 | D->addAttr(OMPDeclareTargetDeclAttr::CreateImplicit(Context)); |
| 10861 | if (ASTMutationListener *ML = Context.getASTMutationListener()) |
| 10862 | ML->DeclarationMarkedOpenMPDeclareTarget(D); |
| 10863 | } |
| 10864 | return; |
| 10865 | } |
| 10866 | checkDeclInTargetContext(E->getExprLoc(), E->getSourceRange(), *this, D); |
| 10867 | } |