Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1 | //===--- SemaOpenMP.cpp - Semantic Analysis for OpenMP constructs ---------===// |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | /// \file |
| 10 | /// \brief This file implements semantic analysis for OpenMP directives and |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 11 | /// clauses. |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 12 | /// |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 15 | #include "TreeTransform.h" |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 16 | #include "clang/AST/ASTContext.h" |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 17 | #include "clang/AST/ASTMutationListener.h" |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 18 | #include "clang/AST/Decl.h" |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 19 | #include "clang/AST/DeclCXX.h" |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 20 | #include "clang/AST/DeclOpenMP.h" |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 21 | #include "clang/AST/StmtCXX.h" |
| 22 | #include "clang/AST/StmtOpenMP.h" |
| 23 | #include "clang/AST/StmtVisitor.h" |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 24 | #include "clang/Basic/OpenMPKinds.h" |
Samuel Antao | f8b5012 | 2015-07-13 22:54:53 +0000 | [diff] [blame] | 25 | #include "clang/Basic/TargetInfo.h" |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 26 | #include "clang/Lex/Preprocessor.h" |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 27 | #include "clang/Sema/Initialization.h" |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 28 | #include "clang/Sema/Lookup.h" |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 29 | #include "clang/Sema/Scope.h" |
| 30 | #include "clang/Sema/ScopeInfo.h" |
Chandler Carruth | 5553d0d | 2014-01-07 11:51:46 +0000 | [diff] [blame] | 31 | #include "clang/Sema/SemaInternal.h" |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 32 | using namespace clang; |
| 33 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 34 | //===----------------------------------------------------------------------===// |
| 35 | // Stack of data-sharing attributes for variables |
| 36 | //===----------------------------------------------------------------------===// |
| 37 | |
| 38 | namespace { |
| 39 | /// \brief Default data sharing attributes, which can be applied to directive. |
| 40 | enum DefaultDataSharingAttributes { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 41 | DSA_unspecified = 0, /// \brief Data sharing attribute not specified. |
| 42 | DSA_none = 1 << 0, /// \brief Default data sharing attribute 'none'. |
| 43 | DSA_shared = 1 << 1 /// \brief Default data sharing attribute 'shared'. |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 44 | }; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 45 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 46 | template <class T> struct MatchesAny { |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 47 | explicit MatchesAny(ArrayRef<T> Arr) : Arr(std::move(Arr)) {} |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 48 | bool operator()(T Kind) { |
| 49 | for (auto KindEl : Arr) |
| 50 | if (KindEl == Kind) |
| 51 | return true; |
| 52 | return false; |
| 53 | } |
| 54 | |
| 55 | private: |
| 56 | ArrayRef<T> Arr; |
| 57 | }; |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 58 | struct MatchesAlways { |
Angel Garcia Gomez | 637d1e6 | 2015-10-20 13:23:58 +0000 | [diff] [blame] | 59 | MatchesAlways() {} |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 60 | template <class T> bool operator()(T) { return true; } |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 61 | }; |
| 62 | |
| 63 | typedef MatchesAny<OpenMPClauseKind> MatchesAnyClause; |
| 64 | typedef MatchesAny<OpenMPDirectiveKind> MatchesAnyDirective; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 65 | |
| 66 | /// \brief Stack for tracking declarations used in OpenMP directives and |
| 67 | /// clauses and their data-sharing attributes. |
| 68 | class DSAStackTy { |
| 69 | public: |
| 70 | struct DSAVarData { |
| 71 | OpenMPDirectiveKind DKind; |
| 72 | OpenMPClauseKind CKind; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 73 | Expr *RefExpr; |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 74 | DeclRefExpr *PrivateCopy; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 75 | SourceLocation ImplicitDSALoc; |
| 76 | DSAVarData() |
| 77 | : DKind(OMPD_unknown), CKind(OMPC_unknown), RefExpr(nullptr), |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 78 | PrivateCopy(nullptr), ImplicitDSALoc() {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 79 | }; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 80 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 81 | private: |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 82 | typedef SmallVector<Expr *, 4> MapInfo; |
| 83 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 84 | struct DSAInfo { |
| 85 | OpenMPClauseKind Attributes; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 86 | Expr *RefExpr; |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 87 | DeclRefExpr *PrivateCopy; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 88 | }; |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 89 | typedef llvm::DenseMap<ValueDecl *, DSAInfo> DeclSAMapTy; |
| 90 | typedef llvm::DenseMap<ValueDecl *, Expr *> AlignedMapTy; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 91 | typedef llvm::DenseMap<ValueDecl *, unsigned> LoopControlVariablesMapTy; |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 92 | typedef llvm::DenseMap<ValueDecl *, MapInfo> MappedDeclsTy; |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 93 | typedef llvm::StringMap<std::pair<OMPCriticalDirective *, llvm::APSInt>> |
| 94 | CriticalsWithHintsTy; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 95 | |
| 96 | struct SharingMapTy { |
| 97 | DeclSAMapTy SharingMap; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 98 | AlignedMapTy AlignedMap; |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 99 | MappedDeclsTy MappedDecls; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 100 | LoopControlVariablesMapTy LCVMap; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 101 | DefaultDataSharingAttributes DefaultAttr; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 102 | SourceLocation DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 103 | OpenMPDirectiveKind Directive; |
| 104 | DeclarationNameInfo DirectiveName; |
| 105 | Scope *CurScope; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 106 | SourceLocation ConstructLoc; |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 107 | /// \brief first argument (Expr *) contains optional argument of the |
| 108 | /// 'ordered' clause, the second one is true if the regions has 'ordered' |
| 109 | /// clause, false otherwise. |
| 110 | llvm::PointerIntPair<Expr *, 1, bool> OrderedRegion; |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 111 | bool NowaitRegion; |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 112 | bool CancelRegion; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 113 | unsigned AssociatedLoops; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 114 | SourceLocation InnerTeamsRegionLoc; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 115 | SharingMapTy(OpenMPDirectiveKind DKind, DeclarationNameInfo Name, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 116 | Scope *CurScope, SourceLocation Loc) |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 117 | : SharingMap(), AlignedMap(), LCVMap(), DefaultAttr(DSA_unspecified), |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 118 | Directive(DKind), DirectiveName(std::move(Name)), CurScope(CurScope), |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 119 | ConstructLoc(Loc), OrderedRegion(), NowaitRegion(false), |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 120 | CancelRegion(false), AssociatedLoops(1), InnerTeamsRegionLoc() {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 121 | SharingMapTy() |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 122 | : SharingMap(), AlignedMap(), LCVMap(), DefaultAttr(DSA_unspecified), |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 123 | Directive(OMPD_unknown), DirectiveName(), CurScope(nullptr), |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 124 | ConstructLoc(), OrderedRegion(), NowaitRegion(false), |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 125 | CancelRegion(false), AssociatedLoops(1), InnerTeamsRegionLoc() {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 126 | }; |
| 127 | |
Axel Naumann | 323862e | 2016-02-03 10:45:22 +0000 | [diff] [blame] | 128 | typedef SmallVector<SharingMapTy, 4> StackTy; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 129 | |
| 130 | /// \brief Stack of used declaration and their data-sharing attributes. |
| 131 | StackTy Stack; |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 132 | /// \brief true, if check for DSA must be from parent directive, false, if |
| 133 | /// from current directive. |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 134 | OpenMPClauseKind ClauseKindMode; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 135 | Sema &SemaRef; |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 136 | bool ForceCapturing; |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 137 | CriticalsWithHintsTy Criticals; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 138 | |
| 139 | typedef SmallVector<SharingMapTy, 8>::reverse_iterator reverse_iterator; |
| 140 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 141 | DSAVarData getDSA(StackTy::reverse_iterator Iter, ValueDecl *D); |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 142 | |
| 143 | /// \brief Checks if the variable is a local for OpenMP region. |
| 144 | bool isOpenMPLocal(VarDecl *D, StackTy::reverse_iterator Iter); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 145 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 146 | public: |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 147 | explicit DSAStackTy(Sema &S) |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 148 | : Stack(1), ClauseKindMode(OMPC_unknown), SemaRef(S), |
| 149 | ForceCapturing(false) {} |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 150 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 151 | bool isClauseParsingMode() const { return ClauseKindMode != OMPC_unknown; } |
| 152 | void setClauseParsingMode(OpenMPClauseKind K) { ClauseKindMode = K; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 153 | |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 154 | bool isForceVarCapturing() const { return ForceCapturing; } |
| 155 | void setForceVarCapturing(bool V) { ForceCapturing = V; } |
| 156 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 157 | void push(OpenMPDirectiveKind DKind, const DeclarationNameInfo &DirName, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 158 | Scope *CurScope, SourceLocation Loc) { |
| 159 | Stack.push_back(SharingMapTy(DKind, DirName, CurScope, Loc)); |
| 160 | Stack.back().DefaultAttrLoc = Loc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | void pop() { |
| 164 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty!"); |
| 165 | Stack.pop_back(); |
| 166 | } |
| 167 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 168 | void addCriticalWithHint(OMPCriticalDirective *D, llvm::APSInt Hint) { |
| 169 | Criticals[D->getDirectiveName().getAsString()] = std::make_pair(D, Hint); |
| 170 | } |
| 171 | const std::pair<OMPCriticalDirective *, llvm::APSInt> |
| 172 | getCriticalWithHint(const DeclarationNameInfo &Name) const { |
| 173 | auto I = Criticals.find(Name.getAsString()); |
| 174 | if (I != Criticals.end()) |
| 175 | return I->second; |
| 176 | return std::make_pair(nullptr, llvm::APSInt()); |
| 177 | } |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 178 | /// \brief If 'aligned' declaration for given variable \a D was not seen yet, |
Alp Toker | 15e62a3 | 2014-06-06 12:02:07 +0000 | [diff] [blame] | 179 | /// add it and return NULL; otherwise return previous occurrence's expression |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 180 | /// for diagnostics. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 181 | Expr *addUniqueAligned(ValueDecl *D, Expr *NewDE); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 182 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 183 | /// \brief Register specified variable as loop control variable. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 184 | void addLoopControlVariable(ValueDecl *D); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 185 | /// \brief Check if the specified variable is a loop control variable for |
| 186 | /// current region. |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 187 | /// \return The index of the loop control variable in the list of associated |
| 188 | /// for-loops (from outer to inner). |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 189 | unsigned isLoopControlVariable(ValueDecl *D); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 190 | /// \brief Check if the specified variable is a loop control variable for |
| 191 | /// parent region. |
| 192 | /// \return The index of the loop control variable in the list of associated |
| 193 | /// for-loops (from outer to inner). |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 194 | unsigned isParentLoopControlVariable(ValueDecl *D); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 195 | /// \brief Get the loop control variable for the I-th loop (or nullptr) in |
| 196 | /// parent directive. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 197 | ValueDecl *getParentLoopControlVariable(unsigned I); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 198 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 199 | /// \brief Adds explicit data sharing attribute to the specified declaration. |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 200 | void addDSA(ValueDecl *D, Expr *E, OpenMPClauseKind A, |
| 201 | DeclRefExpr *PrivateCopy = nullptr); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 202 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 203 | /// \brief Returns data sharing attributes from top of the stack for the |
| 204 | /// specified declaration. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 205 | DSAVarData getTopDSA(ValueDecl *D, bool FromParent); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 206 | /// \brief Returns data-sharing attributes for the specified declaration. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 207 | DSAVarData getImplicitDSA(ValueDecl *D, bool FromParent); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 208 | /// \brief Checks if the specified variables has data-sharing attributes which |
| 209 | /// match specified \a CPred predicate in any directive which matches \a DPred |
| 210 | /// predicate. |
| 211 | template <class ClausesPredicate, class DirectivesPredicate> |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 212 | DSAVarData hasDSA(ValueDecl *D, ClausesPredicate CPred, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 213 | DirectivesPredicate DPred, bool FromParent); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 214 | /// \brief Checks if the specified variables has data-sharing attributes which |
| 215 | /// match specified \a CPred predicate in any innermost directive which |
| 216 | /// matches \a DPred predicate. |
| 217 | template <class ClausesPredicate, class DirectivesPredicate> |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 218 | DSAVarData hasInnermostDSA(ValueDecl *D, ClausesPredicate CPred, |
| 219 | DirectivesPredicate DPred, bool FromParent); |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 220 | /// \brief Checks if the specified variables has explicit data-sharing |
| 221 | /// attributes which match specified \a CPred predicate at the specified |
| 222 | /// OpenMP region. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 223 | bool hasExplicitDSA(ValueDecl *D, |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 224 | const llvm::function_ref<bool(OpenMPClauseKind)> &CPred, |
| 225 | unsigned Level); |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 226 | |
| 227 | /// \brief Returns true if the directive at level \Level matches in the |
| 228 | /// specified \a DPred predicate. |
| 229 | bool hasExplicitDirective( |
| 230 | const llvm::function_ref<bool(OpenMPDirectiveKind)> &DPred, |
| 231 | unsigned Level); |
| 232 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 233 | /// \brief Finds a directive which matches specified \a DPred predicate. |
| 234 | template <class NamedDirectivesPredicate> |
| 235 | bool hasDirective(NamedDirectivesPredicate DPred, bool FromParent); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 236 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 237 | /// \brief Returns currently analyzed directive. |
| 238 | OpenMPDirectiveKind getCurrentDirective() const { |
| 239 | return Stack.back().Directive; |
| 240 | } |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 241 | /// \brief Returns parent directive. |
| 242 | OpenMPDirectiveKind getParentDirective() const { |
| 243 | if (Stack.size() > 2) |
| 244 | return Stack[Stack.size() - 2].Directive; |
| 245 | return OMPD_unknown; |
| 246 | } |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 247 | /// \brief Return the directive associated with the provided scope. |
| 248 | OpenMPDirectiveKind getDirectiveForScope(const Scope *S) const; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 249 | |
| 250 | /// \brief Set default data sharing attribute to none. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 251 | void setDefaultDSANone(SourceLocation Loc) { |
| 252 | Stack.back().DefaultAttr = DSA_none; |
| 253 | Stack.back().DefaultAttrLoc = Loc; |
| 254 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 255 | /// \brief Set default data sharing attribute to shared. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 256 | void setDefaultDSAShared(SourceLocation Loc) { |
| 257 | Stack.back().DefaultAttr = DSA_shared; |
| 258 | Stack.back().DefaultAttrLoc = Loc; |
| 259 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 260 | |
| 261 | DefaultDataSharingAttributes getDefaultDSA() const { |
| 262 | return Stack.back().DefaultAttr; |
| 263 | } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 264 | SourceLocation getDefaultDSALocation() const { |
| 265 | return Stack.back().DefaultAttrLoc; |
| 266 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 267 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 268 | /// \brief Checks if the specified variable is a threadprivate. |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 269 | bool isThreadPrivate(VarDecl *D) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 270 | DSAVarData DVar = getTopDSA(D, false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 271 | return isOpenMPThreadPrivate(DVar.CKind); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 272 | } |
| 273 | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 274 | /// \brief Marks current region as ordered (it has an 'ordered' clause). |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 275 | void setOrderedRegion(bool IsOrdered, Expr *Param) { |
| 276 | Stack.back().OrderedRegion.setInt(IsOrdered); |
| 277 | Stack.back().OrderedRegion.setPointer(Param); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 278 | } |
| 279 | /// \brief Returns true, if parent region is ordered (has associated |
| 280 | /// 'ordered' clause), false - otherwise. |
| 281 | bool isParentOrderedRegion() const { |
| 282 | if (Stack.size() > 2) |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 283 | return Stack[Stack.size() - 2].OrderedRegion.getInt(); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 284 | return false; |
| 285 | } |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 286 | /// \brief Returns optional parameter for the ordered region. |
| 287 | Expr *getParentOrderedRegionParam() const { |
| 288 | if (Stack.size() > 2) |
| 289 | return Stack[Stack.size() - 2].OrderedRegion.getPointer(); |
| 290 | return nullptr; |
| 291 | } |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 292 | /// \brief Marks current region as nowait (it has a 'nowait' clause). |
| 293 | void setNowaitRegion(bool IsNowait = true) { |
| 294 | Stack.back().NowaitRegion = IsNowait; |
| 295 | } |
| 296 | /// \brief Returns true, if parent region is nowait (has associated |
| 297 | /// 'nowait' clause), false - otherwise. |
| 298 | bool isParentNowaitRegion() const { |
| 299 | if (Stack.size() > 2) |
| 300 | return Stack[Stack.size() - 2].NowaitRegion; |
| 301 | return false; |
| 302 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 303 | /// \brief Marks parent region as cancel region. |
| 304 | void setParentCancelRegion(bool Cancel = true) { |
| 305 | if (Stack.size() > 2) |
| 306 | Stack[Stack.size() - 2].CancelRegion = |
| 307 | Stack[Stack.size() - 2].CancelRegion || Cancel; |
| 308 | } |
| 309 | /// \brief Return true if current region has inner cancel construct. |
| 310 | bool isCancelRegion() const { |
| 311 | return Stack.back().CancelRegion; |
| 312 | } |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 313 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 314 | /// \brief Set collapse value for the region. |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 315 | void setAssociatedLoops(unsigned Val) { Stack.back().AssociatedLoops = Val; } |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 316 | /// \brief Return collapse value for region. |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 317 | unsigned getAssociatedLoops() const { return Stack.back().AssociatedLoops; } |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 318 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 319 | /// \brief Marks current target region as one with closely nested teams |
| 320 | /// region. |
| 321 | void setParentTeamsRegionLoc(SourceLocation TeamsRegionLoc) { |
| 322 | if (Stack.size() > 2) |
| 323 | Stack[Stack.size() - 2].InnerTeamsRegionLoc = TeamsRegionLoc; |
| 324 | } |
| 325 | /// \brief Returns true, if current region has closely nested teams region. |
| 326 | bool hasInnerTeamsRegion() const { |
| 327 | return getInnerTeamsRegionLoc().isValid(); |
| 328 | } |
| 329 | /// \brief Returns location of the nested teams region (if any). |
| 330 | SourceLocation getInnerTeamsRegionLoc() const { |
| 331 | if (Stack.size() > 1) |
| 332 | return Stack.back().InnerTeamsRegionLoc; |
| 333 | return SourceLocation(); |
| 334 | } |
| 335 | |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 336 | Scope *getCurScope() const { return Stack.back().CurScope; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 337 | Scope *getCurScope() { return Stack.back().CurScope; } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 338 | SourceLocation getConstructLoc() { return Stack.back().ConstructLoc; } |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 339 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 340 | // Do the check specified in MapInfoCheck and return true if any issue is |
| 341 | // found. |
| 342 | template <class MapInfoCheck> |
| 343 | bool checkMapInfoForVar(ValueDecl *VD, bool CurrentRegionOnly, |
| 344 | MapInfoCheck Check) { |
| 345 | auto SI = Stack.rbegin(); |
| 346 | auto SE = Stack.rend(); |
| 347 | |
| 348 | if (SI == SE) |
| 349 | return false; |
| 350 | |
| 351 | if (CurrentRegionOnly) { |
| 352 | SE = std::next(SI); |
| 353 | } else { |
| 354 | ++SI; |
| 355 | } |
| 356 | |
| 357 | for (; SI != SE; ++SI) { |
| 358 | auto MI = SI->MappedDecls.find(VD); |
| 359 | if (MI != SI->MappedDecls.end()) { |
| 360 | for (Expr *E : MI->second) { |
| 361 | if (Check(E)) |
| 362 | return true; |
| 363 | } |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 364 | } |
| 365 | } |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 366 | return false; |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 367 | } |
| 368 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 369 | void addExprToVarMapInfo(ValueDecl *VD, Expr *E) { |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 370 | if (Stack.size() > 1) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 371 | Stack.back().MappedDecls[VD].push_back(E); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 372 | } |
| 373 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 374 | }; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 375 | bool isParallelOrTaskRegion(OpenMPDirectiveKind DKind) { |
| 376 | return isOpenMPParallelDirective(DKind) || DKind == OMPD_task || |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 377 | isOpenMPTeamsDirective(DKind) || DKind == OMPD_unknown || |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 378 | isOpenMPTaskLoopDirective(DKind); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 379 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 380 | } // namespace |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 381 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 382 | static ValueDecl *getCanonicalDecl(ValueDecl *D) { |
| 383 | auto *VD = dyn_cast<VarDecl>(D); |
| 384 | auto *FD = dyn_cast<FieldDecl>(D); |
| 385 | if (VD != nullptr) { |
| 386 | VD = VD->getCanonicalDecl(); |
| 387 | D = VD; |
| 388 | } else { |
| 389 | assert(FD); |
| 390 | FD = FD->getCanonicalDecl(); |
| 391 | D = FD; |
| 392 | } |
| 393 | return D; |
| 394 | } |
| 395 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 396 | DSAStackTy::DSAVarData DSAStackTy::getDSA(StackTy::reverse_iterator Iter, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 397 | ValueDecl *D) { |
| 398 | D = getCanonicalDecl(D); |
| 399 | auto *VD = dyn_cast<VarDecl>(D); |
| 400 | auto *FD = dyn_cast<FieldDecl>(D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 401 | DSAVarData DVar; |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 402 | if (Iter == std::prev(Stack.rend())) { |
Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 403 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 404 | // in a region but not in construct] |
| 405 | // File-scope or namespace-scope variables referenced in called routines |
| 406 | // in the region are shared unless they appear in a threadprivate |
| 407 | // directive. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 408 | if (VD && !VD->isFunctionOrMethodVarDecl() && !isa<ParmVarDecl>(D)) |
Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 409 | DVar.CKind = OMPC_shared; |
| 410 | |
| 411 | // OpenMP [2.9.1.2, Data-sharing Attribute Rules for Variables Referenced |
| 412 | // in a region but not in construct] |
| 413 | // Variables with static storage duration that are declared in called |
| 414 | // routines in the region are shared. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 415 | if (VD && VD->hasGlobalStorage()) |
| 416 | DVar.CKind = OMPC_shared; |
| 417 | |
| 418 | // Non-static data members are shared by default. |
| 419 | if (FD) |
Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 420 | DVar.CKind = OMPC_shared; |
| 421 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 422 | return DVar; |
| 423 | } |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 424 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 425 | DVar.DKind = Iter->Directive; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 426 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 427 | // in a Construct, C/C++, predetermined, p.1] |
| 428 | // Variables with automatic storage duration that are declared in a scope |
| 429 | // inside the construct are private. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 430 | if (VD && isOpenMPLocal(VD, Iter) && VD->isLocalVarDecl() && |
| 431 | (VD->getStorageClass() == SC_Auto || VD->getStorageClass() == SC_None)) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 432 | DVar.CKind = OMPC_private; |
| 433 | return DVar; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 434 | } |
| 435 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 436 | // Explicitly specified attributes and local variables with predetermined |
| 437 | // attributes. |
| 438 | if (Iter->SharingMap.count(D)) { |
| 439 | DVar.RefExpr = Iter->SharingMap[D].RefExpr; |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 440 | DVar.PrivateCopy = Iter->SharingMap[D].PrivateCopy; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 441 | DVar.CKind = Iter->SharingMap[D].Attributes; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 442 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 443 | return DVar; |
| 444 | } |
| 445 | |
| 446 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 447 | // in a Construct, C/C++, implicitly determined, p.1] |
| 448 | // In a parallel or task construct, the data-sharing attributes of these |
| 449 | // variables are determined by the default clause, if present. |
| 450 | switch (Iter->DefaultAttr) { |
| 451 | case DSA_shared: |
| 452 | DVar.CKind = OMPC_shared; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 453 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 454 | return DVar; |
| 455 | case DSA_none: |
| 456 | return DVar; |
| 457 | case DSA_unspecified: |
| 458 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 459 | // in a Construct, implicitly determined, p.2] |
| 460 | // In a parallel construct, if no default clause is present, these |
| 461 | // variables are shared. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 462 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 463 | if (isOpenMPParallelDirective(DVar.DKind) || |
| 464 | isOpenMPTeamsDirective(DVar.DKind)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 465 | DVar.CKind = OMPC_shared; |
| 466 | return DVar; |
| 467 | } |
| 468 | |
| 469 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 470 | // in a Construct, implicitly determined, p.4] |
| 471 | // In a task construct, if no default clause is present, a variable that in |
| 472 | // the enclosing context is determined to be shared by all implicit tasks |
| 473 | // bound to the current team is shared. |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 474 | if (DVar.DKind == OMPD_task) { |
| 475 | DSAVarData DVarTemp; |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 476 | for (StackTy::reverse_iterator I = std::next(Iter), EE = Stack.rend(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 477 | I != EE; ++I) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 478 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables |
| 479 | // Referenced |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 480 | // in a Construct, implicitly determined, p.6] |
| 481 | // In a task construct, if no default clause is present, a variable |
| 482 | // whose data-sharing attribute is not determined by the rules above is |
| 483 | // firstprivate. |
| 484 | DVarTemp = getDSA(I, D); |
| 485 | if (DVarTemp.CKind != OMPC_shared) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 486 | DVar.RefExpr = nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 487 | DVar.DKind = OMPD_task; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 488 | DVar.CKind = OMPC_firstprivate; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 489 | return DVar; |
| 490 | } |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 491 | if (isParallelOrTaskRegion(I->Directive)) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 492 | break; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 493 | } |
| 494 | DVar.DKind = OMPD_task; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 495 | DVar.CKind = |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 496 | (DVarTemp.CKind == OMPC_unknown) ? OMPC_firstprivate : OMPC_shared; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 497 | return DVar; |
| 498 | } |
| 499 | } |
| 500 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 501 | // in a Construct, implicitly determined, p.3] |
| 502 | // For constructs other than task, if no default clause is present, these |
| 503 | // variables inherit their data-sharing attributes from the enclosing |
| 504 | // context. |
Benjamin Kramer | 167e999 | 2014-03-02 12:20:24 +0000 | [diff] [blame] | 505 | return getDSA(std::next(Iter), D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 506 | } |
| 507 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 508 | Expr *DSAStackTy::addUniqueAligned(ValueDecl *D, Expr *NewDE) { |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 509 | assert(Stack.size() > 1 && "Data sharing attributes stack is empty"); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 510 | D = getCanonicalDecl(D); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 511 | auto It = Stack.back().AlignedMap.find(D); |
| 512 | if (It == Stack.back().AlignedMap.end()) { |
| 513 | assert(NewDE && "Unexpected nullptr expr to be added into aligned map"); |
| 514 | Stack.back().AlignedMap[D] = NewDE; |
| 515 | return nullptr; |
| 516 | } else { |
| 517 | assert(It->second && "Unexpected nullptr expr in the aligned map"); |
| 518 | return It->second; |
| 519 | } |
| 520 | return nullptr; |
| 521 | } |
| 522 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 523 | void DSAStackTy::addLoopControlVariable(ValueDecl *D) { |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 524 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 525 | D = getCanonicalDecl(D); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 526 | Stack.back().LCVMap.insert(std::make_pair(D, Stack.back().LCVMap.size() + 1)); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 527 | } |
| 528 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 529 | unsigned DSAStackTy::isLoopControlVariable(ValueDecl *D) { |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 530 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 531 | D = getCanonicalDecl(D); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 532 | return Stack.back().LCVMap.count(D) > 0 ? Stack.back().LCVMap[D] : 0; |
| 533 | } |
| 534 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 535 | unsigned DSAStackTy::isParentLoopControlVariable(ValueDecl *D) { |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 536 | assert(Stack.size() > 2 && "Data-sharing attributes stack is empty"); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 537 | D = getCanonicalDecl(D); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 538 | return Stack[Stack.size() - 2].LCVMap.count(D) > 0 |
| 539 | ? Stack[Stack.size() - 2].LCVMap[D] |
| 540 | : 0; |
| 541 | } |
| 542 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 543 | ValueDecl *DSAStackTy::getParentLoopControlVariable(unsigned I) { |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 544 | assert(Stack.size() > 2 && "Data-sharing attributes stack is empty"); |
| 545 | if (Stack[Stack.size() - 2].LCVMap.size() < I) |
| 546 | return nullptr; |
| 547 | for (auto &Pair : Stack[Stack.size() - 2].LCVMap) { |
| 548 | if (Pair.second == I) |
| 549 | return Pair.first; |
| 550 | } |
| 551 | return nullptr; |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 552 | } |
| 553 | |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 554 | void DSAStackTy::addDSA(ValueDecl *D, Expr *E, OpenMPClauseKind A, |
| 555 | DeclRefExpr *PrivateCopy) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 556 | D = getCanonicalDecl(D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 557 | if (A == OMPC_threadprivate) { |
| 558 | Stack[0].SharingMap[D].Attributes = A; |
| 559 | Stack[0].SharingMap[D].RefExpr = E; |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 560 | Stack[0].SharingMap[D].PrivateCopy = nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 561 | } else { |
| 562 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); |
| 563 | Stack.back().SharingMap[D].Attributes = A; |
| 564 | Stack.back().SharingMap[D].RefExpr = E; |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 565 | Stack.back().SharingMap[D].PrivateCopy = PrivateCopy; |
| 566 | if (PrivateCopy) |
| 567 | addDSA(PrivateCopy->getDecl(), PrivateCopy, A); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 568 | } |
| 569 | } |
| 570 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 571 | bool DSAStackTy::isOpenMPLocal(VarDecl *D, StackTy::reverse_iterator Iter) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 572 | D = D->getCanonicalDecl(); |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 573 | if (Stack.size() > 2) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 574 | reverse_iterator I = Iter, E = std::prev(Stack.rend()); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 575 | Scope *TopScope = nullptr; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 576 | while (I != E && !isParallelOrTaskRegion(I->Directive)) { |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 577 | ++I; |
| 578 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 579 | if (I == E) |
| 580 | return false; |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 581 | TopScope = I->CurScope ? I->CurScope->getParent() : nullptr; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 582 | Scope *CurScope = getCurScope(); |
| 583 | while (CurScope != TopScope && !CurScope->isDeclScope(D)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 584 | CurScope = CurScope->getParent(); |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 585 | } |
| 586 | return CurScope != TopScope; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 587 | } |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 588 | return false; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 589 | } |
| 590 | |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 591 | /// \brief Build a variable declaration for OpenMP loop iteration variable. |
| 592 | static VarDecl *buildVarDecl(Sema &SemaRef, SourceLocation Loc, QualType Type, |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 593 | StringRef Name, const AttrVec *Attrs = nullptr) { |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 594 | DeclContext *DC = SemaRef.CurContext; |
| 595 | IdentifierInfo *II = &SemaRef.PP.getIdentifierTable().get(Name); |
| 596 | TypeSourceInfo *TInfo = SemaRef.Context.getTrivialTypeSourceInfo(Type, Loc); |
| 597 | VarDecl *Decl = |
| 598 | VarDecl::Create(SemaRef.Context, DC, Loc, Loc, II, Type, TInfo, SC_None); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 599 | if (Attrs) { |
| 600 | for (specific_attr_iterator<AlignedAttr> I(Attrs->begin()), E(Attrs->end()); |
| 601 | I != E; ++I) |
| 602 | Decl->addAttr(*I); |
| 603 | } |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 604 | Decl->setImplicit(); |
| 605 | return Decl; |
| 606 | } |
| 607 | |
| 608 | static DeclRefExpr *buildDeclRefExpr(Sema &S, VarDecl *D, QualType Ty, |
| 609 | SourceLocation Loc, |
| 610 | bool RefersToCapture = false) { |
| 611 | D->setReferenced(); |
| 612 | D->markUsed(S.Context); |
| 613 | return DeclRefExpr::Create(S.getASTContext(), NestedNameSpecifierLoc(), |
| 614 | SourceLocation(), D, RefersToCapture, Loc, Ty, |
| 615 | VK_LValue); |
| 616 | } |
| 617 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 618 | DSAStackTy::DSAVarData DSAStackTy::getTopDSA(ValueDecl *D, bool FromParent) { |
| 619 | D = getCanonicalDecl(D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 620 | DSAVarData DVar; |
| 621 | |
| 622 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 623 | // in a Construct, C/C++, predetermined, p.1] |
| 624 | // Variables appearing in threadprivate directives are threadprivate. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 625 | auto *VD = dyn_cast<VarDecl>(D); |
| 626 | if ((VD && VD->getTLSKind() != VarDecl::TLS_None && |
| 627 | !(VD->hasAttr<OMPThreadPrivateDeclAttr>() && |
Samuel Antao | f8b5012 | 2015-07-13 22:54:53 +0000 | [diff] [blame] | 628 | SemaRef.getLangOpts().OpenMPUseTLS && |
| 629 | SemaRef.getASTContext().getTargetInfo().isTLSSupported())) || |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 630 | (VD && VD->getStorageClass() == SC_Register && |
| 631 | VD->hasAttr<AsmLabelAttr>() && !VD->isLocalVarDecl())) { |
| 632 | addDSA(D, buildDeclRefExpr(SemaRef, VD, D->getType().getNonReferenceType(), |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 633 | D->getLocation()), |
Alexey Bataev | f2453a0 | 2015-05-06 07:25:08 +0000 | [diff] [blame] | 634 | OMPC_threadprivate); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 635 | } |
| 636 | if (Stack[0].SharingMap.count(D)) { |
| 637 | DVar.RefExpr = Stack[0].SharingMap[D].RefExpr; |
| 638 | DVar.CKind = OMPC_threadprivate; |
| 639 | return DVar; |
| 640 | } |
| 641 | |
| 642 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
Alexey Bataev | dffa93a | 2015-12-10 08:20:58 +0000 | [diff] [blame] | 643 | // in a Construct, C/C++, predetermined, p.4] |
| 644 | // Static data members are shared. |
| 645 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 646 | // in a Construct, C/C++, predetermined, p.7] |
| 647 | // Variables with static storage duration that are declared in a scope |
| 648 | // inside the construct are shared. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 649 | if (VD && VD->isStaticDataMember()) { |
Alexey Bataev | dffa93a | 2015-12-10 08:20:58 +0000 | [diff] [blame] | 650 | DSAVarData DVarTemp = |
| 651 | hasDSA(D, isOpenMPPrivate, MatchesAlways(), FromParent); |
| 652 | if (DVarTemp.CKind != OMPC_unknown && DVarTemp.RefExpr) |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 653 | return DVar; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 654 | |
Alexey Bataev | dffa93a | 2015-12-10 08:20:58 +0000 | [diff] [blame] | 655 | DVar.CKind = OMPC_shared; |
| 656 | return DVar; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 657 | } |
| 658 | |
| 659 | QualType Type = D->getType().getNonReferenceType().getCanonicalType(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 660 | bool IsConstant = Type.isConstant(SemaRef.getASTContext()); |
| 661 | Type = SemaRef.getASTContext().getBaseElementType(Type); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 662 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 663 | // in a Construct, C/C++, predetermined, p.6] |
| 664 | // Variables with const qualified type having no mutable member are |
| 665 | // shared. |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 666 | CXXRecordDecl *RD = |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 667 | SemaRef.getLangOpts().CPlusPlus ? Type->getAsCXXRecordDecl() : nullptr; |
Alexey Bataev | c9bd03d | 2015-12-17 06:55:08 +0000 | [diff] [blame] | 668 | if (auto *CTSD = dyn_cast_or_null<ClassTemplateSpecializationDecl>(RD)) |
| 669 | if (auto *CTD = CTSD->getSpecializedTemplate()) |
| 670 | RD = CTD->getTemplatedDecl(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 671 | if (IsConstant && |
Alexey Bataev | 4bcad7f | 2016-02-10 10:50:12 +0000 | [diff] [blame^] | 672 | !(SemaRef.getLangOpts().CPlusPlus && RD && RD->hasDefinition() && |
| 673 | RD->hasMutableFields())) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 674 | // Variables with const-qualified type having no mutable member may be |
| 675 | // listed in a firstprivate clause, even if they are static data members. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 676 | DSAVarData DVarTemp = hasDSA(D, MatchesAnyClause(OMPC_firstprivate), |
| 677 | MatchesAlways(), FromParent); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 678 | if (DVarTemp.CKind == OMPC_firstprivate && DVarTemp.RefExpr) |
| 679 | return DVar; |
| 680 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 681 | DVar.CKind = OMPC_shared; |
| 682 | return DVar; |
| 683 | } |
| 684 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 685 | // Explicitly specified attributes and local variables with predetermined |
| 686 | // attributes. |
Alexey Bataev | dffa93a | 2015-12-10 08:20:58 +0000 | [diff] [blame] | 687 | auto StartI = std::next(Stack.rbegin()); |
| 688 | auto EndI = std::prev(Stack.rend()); |
| 689 | if (FromParent && StartI != EndI) { |
| 690 | StartI = std::next(StartI); |
| 691 | } |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 692 | auto I = std::prev(StartI); |
| 693 | if (I->SharingMap.count(D)) { |
| 694 | DVar.RefExpr = I->SharingMap[D].RefExpr; |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 695 | DVar.PrivateCopy = I->SharingMap[D].PrivateCopy; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 696 | DVar.CKind = I->SharingMap[D].Attributes; |
| 697 | DVar.ImplicitDSALoc = I->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 698 | } |
| 699 | |
| 700 | return DVar; |
| 701 | } |
| 702 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 703 | DSAStackTy::DSAVarData DSAStackTy::getImplicitDSA(ValueDecl *D, |
| 704 | bool FromParent) { |
| 705 | D = getCanonicalDecl(D); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 706 | auto StartI = Stack.rbegin(); |
| 707 | auto EndI = std::prev(Stack.rend()); |
| 708 | if (FromParent && StartI != EndI) { |
| 709 | StartI = std::next(StartI); |
| 710 | } |
| 711 | return getDSA(StartI, D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 712 | } |
| 713 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 714 | template <class ClausesPredicate, class DirectivesPredicate> |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 715 | DSAStackTy::DSAVarData DSAStackTy::hasDSA(ValueDecl *D, ClausesPredicate CPred, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 716 | DirectivesPredicate DPred, |
| 717 | bool FromParent) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 718 | D = getCanonicalDecl(D); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 719 | auto StartI = std::next(Stack.rbegin()); |
| 720 | auto EndI = std::prev(Stack.rend()); |
| 721 | if (FromParent && StartI != EndI) { |
| 722 | StartI = std::next(StartI); |
| 723 | } |
| 724 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
| 725 | if (!DPred(I->Directive) && !isParallelOrTaskRegion(I->Directive)) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 726 | continue; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 727 | DSAVarData DVar = getDSA(I, D); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 728 | if (CPred(DVar.CKind)) |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 729 | return DVar; |
| 730 | } |
| 731 | return DSAVarData(); |
| 732 | } |
| 733 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 734 | template <class ClausesPredicate, class DirectivesPredicate> |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 735 | DSAStackTy::DSAVarData |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 736 | DSAStackTy::hasInnermostDSA(ValueDecl *D, ClausesPredicate CPred, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 737 | DirectivesPredicate DPred, bool FromParent) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 738 | D = getCanonicalDecl(D); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 739 | auto StartI = std::next(Stack.rbegin()); |
| 740 | auto EndI = std::prev(Stack.rend()); |
| 741 | if (FromParent && StartI != EndI) { |
| 742 | StartI = std::next(StartI); |
| 743 | } |
| 744 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 745 | if (!DPred(I->Directive)) |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 746 | break; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 747 | DSAVarData DVar = getDSA(I, D); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 748 | if (CPred(DVar.CKind)) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 749 | return DVar; |
| 750 | return DSAVarData(); |
| 751 | } |
| 752 | return DSAVarData(); |
| 753 | } |
| 754 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 755 | bool DSAStackTy::hasExplicitDSA( |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 756 | ValueDecl *D, const llvm::function_ref<bool(OpenMPClauseKind)> &CPred, |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 757 | unsigned Level) { |
| 758 | if (CPred(ClauseKindMode)) |
| 759 | return true; |
| 760 | if (isClauseParsingMode()) |
| 761 | ++Level; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 762 | D = getCanonicalDecl(D); |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 763 | auto StartI = Stack.rbegin(); |
| 764 | auto EndI = std::prev(Stack.rend()); |
NAKAMURA Takumi | 0332eda | 2015-06-23 10:01:20 +0000 | [diff] [blame] | 765 | if (std::distance(StartI, EndI) <= (int)Level) |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 766 | return false; |
| 767 | std::advance(StartI, Level); |
| 768 | return (StartI->SharingMap.count(D) > 0) && StartI->SharingMap[D].RefExpr && |
| 769 | CPred(StartI->SharingMap[D].Attributes); |
| 770 | } |
| 771 | |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 772 | bool DSAStackTy::hasExplicitDirective( |
| 773 | const llvm::function_ref<bool(OpenMPDirectiveKind)> &DPred, |
| 774 | unsigned Level) { |
| 775 | if (isClauseParsingMode()) |
| 776 | ++Level; |
| 777 | auto StartI = Stack.rbegin(); |
| 778 | auto EndI = std::prev(Stack.rend()); |
| 779 | if (std::distance(StartI, EndI) <= (int)Level) |
| 780 | return false; |
| 781 | std::advance(StartI, Level); |
| 782 | return DPred(StartI->Directive); |
| 783 | } |
| 784 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 785 | template <class NamedDirectivesPredicate> |
| 786 | bool DSAStackTy::hasDirective(NamedDirectivesPredicate DPred, bool FromParent) { |
| 787 | auto StartI = std::next(Stack.rbegin()); |
| 788 | auto EndI = std::prev(Stack.rend()); |
| 789 | if (FromParent && StartI != EndI) { |
| 790 | StartI = std::next(StartI); |
| 791 | } |
| 792 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
| 793 | if (DPred(I->Directive, I->DirectiveName, I->ConstructLoc)) |
| 794 | return true; |
| 795 | } |
| 796 | return false; |
| 797 | } |
| 798 | |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 799 | OpenMPDirectiveKind DSAStackTy::getDirectiveForScope(const Scope *S) const { |
| 800 | for (auto I = Stack.rbegin(), EE = Stack.rend(); I != EE; ++I) |
| 801 | if (I->CurScope == S) |
| 802 | return I->Directive; |
| 803 | return OMPD_unknown; |
| 804 | } |
| 805 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 806 | void Sema::InitDataSharingAttributesStack() { |
| 807 | VarDataSharingAttributesStack = new DSAStackTy(*this); |
| 808 | } |
| 809 | |
| 810 | #define DSAStack static_cast<DSAStackTy *>(VarDataSharingAttributesStack) |
| 811 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 812 | bool Sema::IsOpenMPCapturedByRef(ValueDecl *D, |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 813 | const CapturedRegionScopeInfo *RSI) { |
| 814 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| 815 | |
| 816 | auto &Ctx = getASTContext(); |
| 817 | bool IsByRef = true; |
| 818 | |
| 819 | // Find the directive that is associated with the provided scope. |
| 820 | auto DKind = DSAStack->getDirectiveForScope(RSI->TheScope); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 821 | auto Ty = D->getType(); |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 822 | |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 823 | if (isOpenMPTargetExecutionDirective(DKind)) { |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 824 | // This table summarizes how a given variable should be passed to the device |
| 825 | // given its type and the clauses where it appears. This table is based on |
| 826 | // the description in OpenMP 4.5 [2.10.4, target Construct] and |
| 827 | // OpenMP 4.5 [2.15.5, Data-mapping Attribute Rules and Clauses]. |
| 828 | // |
| 829 | // ========================================================================= |
| 830 | // | type | defaultmap | pvt | first | is_device_ptr | map | res. | |
| 831 | // | |(tofrom:scalar)| | pvt | | | | |
| 832 | // ========================================================================= |
| 833 | // | scl | | | | - | | bycopy| |
| 834 | // | scl | | - | x | - | - | bycopy| |
| 835 | // | scl | | x | - | - | - | null | |
| 836 | // | scl | x | | | - | | byref | |
| 837 | // | scl | x | - | x | - | - | bycopy| |
| 838 | // | scl | x | x | - | - | - | null | |
| 839 | // | scl | | - | - | - | x | byref | |
| 840 | // | scl | x | - | - | - | x | byref | |
| 841 | // |
| 842 | // | agg | n.a. | | | - | | byref | |
| 843 | // | agg | n.a. | - | x | - | - | byref | |
| 844 | // | agg | n.a. | x | - | - | - | null | |
| 845 | // | agg | n.a. | - | - | - | x | byref | |
| 846 | // | agg | n.a. | - | - | - | x[] | byref | |
| 847 | // |
| 848 | // | ptr | n.a. | | | - | | bycopy| |
| 849 | // | ptr | n.a. | - | x | - | - | bycopy| |
| 850 | // | ptr | n.a. | x | - | - | - | null | |
| 851 | // | ptr | n.a. | - | - | - | x | byref | |
| 852 | // | ptr | n.a. | - | - | - | x[] | bycopy| |
| 853 | // | ptr | n.a. | - | - | x | | bycopy| |
| 854 | // | ptr | n.a. | - | - | x | x | bycopy| |
| 855 | // | ptr | n.a. | - | - | x | x[] | bycopy| |
| 856 | // ========================================================================= |
| 857 | // Legend: |
| 858 | // scl - scalar |
| 859 | // ptr - pointer |
| 860 | // agg - aggregate |
| 861 | // x - applies |
| 862 | // - - invalid in this combination |
| 863 | // [] - mapped with an array section |
| 864 | // byref - should be mapped by reference |
| 865 | // byval - should be mapped by value |
| 866 | // null - initialize a local variable to null on the device |
| 867 | // |
| 868 | // Observations: |
| 869 | // - All scalar declarations that show up in a map clause have to be passed |
| 870 | // by reference, because they may have been mapped in the enclosing data |
| 871 | // environment. |
| 872 | // - If the scalar value does not fit the size of uintptr, it has to be |
| 873 | // passed by reference, regardless the result in the table above. |
| 874 | // - For pointers mapped by value that have either an implicit map or an |
| 875 | // array section, the runtime library may pass the NULL value to the |
| 876 | // device instead of the value passed to it by the compiler. |
| 877 | |
| 878 | // FIXME: Right now, only implicit maps are implemented. Properly mapping |
| 879 | // values requires having the map, private, and firstprivate clauses SEMA |
| 880 | // and parsing in place, which we don't yet. |
| 881 | |
| 882 | if (Ty->isReferenceType()) |
| 883 | Ty = Ty->castAs<ReferenceType>()->getPointeeType(); |
| 884 | IsByRef = !Ty->isScalarType(); |
| 885 | } |
| 886 | |
| 887 | // When passing data by value, we need to make sure it fits the uintptr size |
| 888 | // and alignment, because the runtime library only deals with uintptr types. |
| 889 | // If it does not fit the uintptr size, we need to pass the data by reference |
| 890 | // instead. |
| 891 | if (!IsByRef && |
| 892 | (Ctx.getTypeSizeInChars(Ty) > |
| 893 | Ctx.getTypeSizeInChars(Ctx.getUIntPtrType()) || |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 894 | Ctx.getDeclAlign(D) > Ctx.getTypeAlignInChars(Ctx.getUIntPtrType()))) |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 895 | IsByRef = true; |
| 896 | |
| 897 | return IsByRef; |
| 898 | } |
| 899 | |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 900 | VarDecl *Sema::IsOpenMPCapturedDecl(ValueDecl *D) { |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 901 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 902 | D = getCanonicalDecl(D); |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 903 | |
| 904 | // If we are attempting to capture a global variable in a directive with |
| 905 | // 'target' we return true so that this global is also mapped to the device. |
| 906 | // |
| 907 | // FIXME: If the declaration is enclosed in a 'declare target' directive, |
| 908 | // then it should not be captured. Therefore, an extra check has to be |
| 909 | // inserted here once support for 'declare target' is added. |
| 910 | // |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 911 | auto *VD = dyn_cast<VarDecl>(D); |
| 912 | if (VD && !VD->hasLocalStorage()) { |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 913 | if (DSAStack->getCurrentDirective() == OMPD_target && |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 914 | !DSAStack->isClauseParsingMode()) |
| 915 | return VD; |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 916 | if (DSAStack->getCurScope() && |
| 917 | DSAStack->hasDirective( |
| 918 | [](OpenMPDirectiveKind K, const DeclarationNameInfo &DNI, |
| 919 | SourceLocation Loc) -> bool { |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 920 | return isOpenMPTargetExecutionDirective(K); |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 921 | }, |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 922 | false)) |
| 923 | return VD; |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 924 | } |
| 925 | |
Alexey Bataev | 48977c3 | 2015-08-04 08:10:48 +0000 | [diff] [blame] | 926 | if (DSAStack->getCurrentDirective() != OMPD_unknown && |
| 927 | (!DSAStack->isClauseParsingMode() || |
| 928 | DSAStack->getParentDirective() != OMPD_unknown)) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 929 | if (DSAStack->isLoopControlVariable(D) || |
| 930 | (VD && VD->hasLocalStorage() && |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 931 | isParallelOrTaskRegion(DSAStack->getCurrentDirective())) || |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 932 | (VD && DSAStack->isForceVarCapturing())) |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 933 | return VD; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 934 | auto DVarPrivate = DSAStack->getTopDSA(D, DSAStack->isClauseParsingMode()); |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 935 | if (DVarPrivate.CKind != OMPC_unknown && isOpenMPPrivate(DVarPrivate.CKind)) |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 936 | return VD ? VD : cast<VarDecl>(DVarPrivate.PrivateCopy->getDecl()); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 937 | DVarPrivate = DSAStack->hasDSA(D, isOpenMPPrivate, MatchesAlways(), |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 938 | DSAStack->isClauseParsingMode()); |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 939 | if (DVarPrivate.CKind != OMPC_unknown) |
| 940 | return VD ? VD : cast<VarDecl>(DVarPrivate.PrivateCopy->getDecl()); |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 941 | } |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 942 | return nullptr; |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 943 | } |
| 944 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 945 | bool Sema::isOpenMPPrivateDecl(ValueDecl *D, unsigned Level) { |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 946 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| 947 | return DSAStack->hasExplicitDSA( |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 948 | D, [](OpenMPClauseKind K) -> bool { return K == OMPC_private; }, Level); |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 949 | } |
| 950 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 951 | bool Sema::isOpenMPTargetCapturedDecl(ValueDecl *D, unsigned Level) { |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 952 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| 953 | // Return true if the current level is no longer enclosed in a target region. |
| 954 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 955 | auto *VD = dyn_cast<VarDecl>(D); |
| 956 | return VD && !VD->hasLocalStorage() && |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 957 | DSAStack->hasExplicitDirective(isOpenMPTargetExecutionDirective, |
| 958 | Level); |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 959 | } |
| 960 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 961 | void Sema::DestroyDataSharingAttributesStack() { delete DSAStack; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 962 | |
| 963 | void Sema::StartOpenMPDSABlock(OpenMPDirectiveKind DKind, |
| 964 | const DeclarationNameInfo &DirName, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 965 | Scope *CurScope, SourceLocation Loc) { |
| 966 | DSAStack->push(DKind, DirName, CurScope, Loc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 967 | PushExpressionEvaluationContext(PotentiallyEvaluated); |
| 968 | } |
| 969 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 970 | void Sema::StartOpenMPClause(OpenMPClauseKind K) { |
| 971 | DSAStack->setClauseParsingMode(K); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 972 | } |
| 973 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 974 | void Sema::EndOpenMPClause() { |
| 975 | DSAStack->setClauseParsingMode(/*K=*/OMPC_unknown); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 976 | } |
| 977 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 978 | void Sema::EndOpenMPDSABlock(Stmt *CurDirective) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 979 | // OpenMP [2.14.3.5, Restrictions, C/C++, p.1] |
| 980 | // A variable of class type (or array thereof) that appears in a lastprivate |
| 981 | // clause requires an accessible, unambiguous default constructor for the |
| 982 | // class type, unless the list item is also specified in a firstprivate |
| 983 | // clause. |
| 984 | if (auto D = dyn_cast_or_null<OMPExecutableDirective>(CurDirective)) { |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 985 | for (auto *C : D->clauses()) { |
| 986 | if (auto *Clause = dyn_cast<OMPLastprivateClause>(C)) { |
| 987 | SmallVector<Expr *, 8> PrivateCopies; |
| 988 | for (auto *DE : Clause->varlists()) { |
| 989 | if (DE->isValueDependent() || DE->isTypeDependent()) { |
| 990 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 991 | continue; |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 992 | } |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 993 | DE = DE->IgnoreParens(); |
| 994 | VarDecl *VD = nullptr; |
| 995 | FieldDecl *FD = nullptr; |
| 996 | ValueDecl *D; |
| 997 | if (auto *DRE = dyn_cast<DeclRefExpr>(DE)) { |
| 998 | VD = cast<VarDecl>(DRE->getDecl()); |
| 999 | D = VD; |
| 1000 | } else { |
| 1001 | assert(isa<MemberExpr>(DE)); |
| 1002 | FD = cast<FieldDecl>(cast<MemberExpr>(DE)->getMemberDecl()); |
| 1003 | D = FD; |
| 1004 | } |
| 1005 | QualType Type = D->getType().getNonReferenceType(); |
| 1006 | auto DVar = DSAStack->getTopDSA(D, false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1007 | if (DVar.CKind == OMPC_lastprivate) { |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1008 | // Generate helper private variable and initialize it with the |
| 1009 | // default value. The address of the original variable is replaced |
| 1010 | // by the address of the new private variable in CodeGen. This new |
| 1011 | // variable is not added to IdResolver, so the code in the OpenMP |
| 1012 | // region uses original variable for proper diagnostics. |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 1013 | auto *VDPrivate = buildVarDecl( |
| 1014 | *this, DE->getExprLoc(), Type.getUnqualifiedType(), |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1015 | D->getName(), D->hasAttrs() ? &D->getAttrs() : nullptr); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1016 | ActOnUninitializedDecl(VDPrivate, /*TypeMayContainAuto=*/false); |
| 1017 | if (VDPrivate->isInvalidDecl()) |
| 1018 | continue; |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 1019 | PrivateCopies.push_back(buildDeclRefExpr( |
| 1020 | *this, VDPrivate, DE->getType(), DE->getExprLoc())); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1021 | } else { |
| 1022 | // The variable is also a firstprivate, so initialization sequence |
| 1023 | // for private copy is generated already. |
| 1024 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1025 | } |
| 1026 | } |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1027 | // Set initializers to private copies if no errors were found. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1028 | if (PrivateCopies.size() == Clause->varlist_size()) |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1029 | Clause->setPrivateCopies(PrivateCopies); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1030 | } |
| 1031 | } |
| 1032 | } |
| 1033 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1034 | DSAStack->pop(); |
| 1035 | DiscardCleanupsInEvaluationContext(); |
| 1036 | PopExpressionEvaluationContext(); |
| 1037 | } |
| 1038 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 1039 | static bool FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV, |
| 1040 | Expr *NumIterations, Sema &SemaRef, |
| 1041 | Scope *S); |
| 1042 | |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1043 | namespace { |
| 1044 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1045 | class VarDeclFilterCCC : public CorrectionCandidateCallback { |
| 1046 | private: |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1047 | Sema &SemaRef; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1048 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1049 | public: |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1050 | explicit VarDeclFilterCCC(Sema &S) : SemaRef(S) {} |
Craig Topper | e14c0f8 | 2014-03-12 04:55:44 +0000 | [diff] [blame] | 1051 | bool ValidateCandidate(const TypoCorrection &Candidate) override { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1052 | NamedDecl *ND = Candidate.getCorrectionDecl(); |
| 1053 | if (VarDecl *VD = dyn_cast_or_null<VarDecl>(ND)) { |
| 1054 | return VD->hasGlobalStorage() && |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1055 | SemaRef.isDeclInScope(ND, SemaRef.getCurLexicalContext(), |
| 1056 | SemaRef.getCurScope()); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1057 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1058 | return false; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1059 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1060 | }; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1061 | } // namespace |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1062 | |
| 1063 | ExprResult Sema::ActOnOpenMPIdExpression(Scope *CurScope, |
| 1064 | CXXScopeSpec &ScopeSpec, |
| 1065 | const DeclarationNameInfo &Id) { |
| 1066 | LookupResult Lookup(*this, Id, LookupOrdinaryName); |
| 1067 | LookupParsedName(Lookup, CurScope, &ScopeSpec, true); |
| 1068 | |
| 1069 | if (Lookup.isAmbiguous()) |
| 1070 | return ExprError(); |
| 1071 | |
| 1072 | VarDecl *VD; |
| 1073 | if (!Lookup.isSingleResult()) { |
Kaelyn Takata | 89c881b | 2014-10-27 18:07:29 +0000 | [diff] [blame] | 1074 | if (TypoCorrection Corrected = CorrectTypo( |
| 1075 | Id, LookupOrdinaryName, CurScope, nullptr, |
| 1076 | llvm::make_unique<VarDeclFilterCCC>(*this), CTK_ErrorRecovery)) { |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 1077 | diagnoseTypo(Corrected, |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 1078 | PDiag(Lookup.empty() |
| 1079 | ? diag::err_undeclared_var_use_suggest |
| 1080 | : diag::err_omp_expected_var_arg_suggest) |
| 1081 | << Id.getName()); |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 1082 | VD = Corrected.getCorrectionDeclAs<VarDecl>(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1083 | } else { |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 1084 | Diag(Id.getLoc(), Lookup.empty() ? diag::err_undeclared_var_use |
| 1085 | : diag::err_omp_expected_var_arg) |
| 1086 | << Id.getName(); |
| 1087 | return ExprError(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1088 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1089 | } else { |
| 1090 | if (!(VD = Lookup.getAsSingle<VarDecl>())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1091 | Diag(Id.getLoc(), diag::err_omp_expected_var_arg) << Id.getName(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1092 | Diag(Lookup.getFoundDecl()->getLocation(), diag::note_declared_at); |
| 1093 | return ExprError(); |
| 1094 | } |
| 1095 | } |
| 1096 | Lookup.suppressDiagnostics(); |
| 1097 | |
| 1098 | // OpenMP [2.9.2, Syntax, C/C++] |
| 1099 | // Variables must be file-scope, namespace-scope, or static block-scope. |
| 1100 | if (!VD->hasGlobalStorage()) { |
| 1101 | Diag(Id.getLoc(), diag::err_omp_global_var_arg) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1102 | << getOpenMPDirectiveName(OMPD_threadprivate) << !VD->isStaticLocal(); |
| 1103 | bool IsDecl = |
| 1104 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1105 | Diag(VD->getLocation(), |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1106 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1107 | << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1108 | return ExprError(); |
| 1109 | } |
| 1110 | |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1111 | VarDecl *CanonicalVD = VD->getCanonicalDecl(); |
| 1112 | NamedDecl *ND = cast<NamedDecl>(CanonicalVD); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1113 | // OpenMP [2.9.2, Restrictions, C/C++, p.2] |
| 1114 | // A threadprivate directive for file-scope variables must appear outside |
| 1115 | // any definition or declaration. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1116 | if (CanonicalVD->getDeclContext()->isTranslationUnit() && |
| 1117 | !getCurLexicalContext()->isTranslationUnit()) { |
| 1118 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1119 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1120 | bool IsDecl = |
| 1121 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1122 | Diag(VD->getLocation(), |
| 1123 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1124 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1125 | return ExprError(); |
| 1126 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1127 | // OpenMP [2.9.2, Restrictions, C/C++, p.3] |
| 1128 | // A threadprivate directive for static class member variables must appear |
| 1129 | // in the class definition, in the same scope in which the member |
| 1130 | // variables are declared. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1131 | if (CanonicalVD->isStaticDataMember() && |
| 1132 | !CanonicalVD->getDeclContext()->Equals(getCurLexicalContext())) { |
| 1133 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1134 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1135 | bool IsDecl = |
| 1136 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1137 | Diag(VD->getLocation(), |
| 1138 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1139 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1140 | return ExprError(); |
| 1141 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1142 | // OpenMP [2.9.2, Restrictions, C/C++, p.4] |
| 1143 | // A threadprivate directive for namespace-scope variables must appear |
| 1144 | // outside any definition or declaration other than the namespace |
| 1145 | // definition itself. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1146 | if (CanonicalVD->getDeclContext()->isNamespace() && |
| 1147 | (!getCurLexicalContext()->isFileContext() || |
| 1148 | !getCurLexicalContext()->Encloses(CanonicalVD->getDeclContext()))) { |
| 1149 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1150 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1151 | bool IsDecl = |
| 1152 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1153 | Diag(VD->getLocation(), |
| 1154 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1155 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1156 | return ExprError(); |
| 1157 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1158 | // OpenMP [2.9.2, Restrictions, C/C++, p.6] |
| 1159 | // A threadprivate directive for static block-scope variables must appear |
| 1160 | // in the scope of the variable and not in a nested scope. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1161 | if (CanonicalVD->isStaticLocal() && CurScope && |
| 1162 | !isDeclInScope(ND, getCurLexicalContext(), CurScope)) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1163 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1164 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1165 | bool IsDecl = |
| 1166 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1167 | Diag(VD->getLocation(), |
| 1168 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1169 | << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1170 | return ExprError(); |
| 1171 | } |
| 1172 | |
| 1173 | // OpenMP [2.9.2, Restrictions, C/C++, p.2-6] |
| 1174 | // A threadprivate directive must lexically precede all references to any |
| 1175 | // of the variables in its list. |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 1176 | if (VD->isUsed() && !DSAStack->isThreadPrivate(VD)) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1177 | Diag(Id.getLoc(), diag::err_omp_var_used) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1178 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1179 | return ExprError(); |
| 1180 | } |
| 1181 | |
| 1182 | QualType ExprType = VD->getType().getNonReferenceType(); |
Alexey Bataev | 376b4a4 | 2016-02-09 09:41:09 +0000 | [diff] [blame] | 1183 | return DeclRefExpr::Create(Context, NestedNameSpecifierLoc(), |
| 1184 | SourceLocation(), VD, |
| 1185 | /*RefersToEnclosingVariableOrCapture=*/false, |
| 1186 | Id.getLoc(), ExprType, VK_LValue); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1187 | } |
| 1188 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1189 | Sema::DeclGroupPtrTy |
| 1190 | Sema::ActOnOpenMPThreadprivateDirective(SourceLocation Loc, |
| 1191 | ArrayRef<Expr *> VarList) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1192 | if (OMPThreadPrivateDecl *D = CheckOMPThreadPrivateDecl(Loc, VarList)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1193 | CurContext->addDecl(D); |
| 1194 | return DeclGroupPtrTy::make(DeclGroupRef(D)); |
| 1195 | } |
David Blaikie | 0403cb1 | 2016-01-15 23:43:25 +0000 | [diff] [blame] | 1196 | return nullptr; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1197 | } |
| 1198 | |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1199 | namespace { |
| 1200 | class LocalVarRefChecker : public ConstStmtVisitor<LocalVarRefChecker, bool> { |
| 1201 | Sema &SemaRef; |
| 1202 | |
| 1203 | public: |
| 1204 | bool VisitDeclRefExpr(const DeclRefExpr *E) { |
| 1205 | if (auto VD = dyn_cast<VarDecl>(E->getDecl())) { |
| 1206 | if (VD->hasLocalStorage()) { |
| 1207 | SemaRef.Diag(E->getLocStart(), |
| 1208 | diag::err_omp_local_var_in_threadprivate_init) |
| 1209 | << E->getSourceRange(); |
| 1210 | SemaRef.Diag(VD->getLocation(), diag::note_defined_here) |
| 1211 | << VD << VD->getSourceRange(); |
| 1212 | return true; |
| 1213 | } |
| 1214 | } |
| 1215 | return false; |
| 1216 | } |
| 1217 | bool VisitStmt(const Stmt *S) { |
| 1218 | for (auto Child : S->children()) { |
| 1219 | if (Child && Visit(Child)) |
| 1220 | return true; |
| 1221 | } |
| 1222 | return false; |
| 1223 | } |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 1224 | explicit LocalVarRefChecker(Sema &SemaRef) : SemaRef(SemaRef) {} |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1225 | }; |
| 1226 | } // namespace |
| 1227 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1228 | OMPThreadPrivateDecl * |
| 1229 | Sema::CheckOMPThreadPrivateDecl(SourceLocation Loc, ArrayRef<Expr *> VarList) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1230 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1231 | for (auto &RefExpr : VarList) { |
| 1232 | DeclRefExpr *DE = cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1233 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); |
| 1234 | SourceLocation ILoc = DE->getExprLoc(); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1235 | |
Alexey Bataev | 376b4a4 | 2016-02-09 09:41:09 +0000 | [diff] [blame] | 1236 | // Mark variable as used. |
| 1237 | VD->setReferenced(); |
| 1238 | VD->markUsed(Context); |
| 1239 | |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 1240 | QualType QType = VD->getType(); |
| 1241 | if (QType->isDependentType() || QType->isInstantiationDependentType()) { |
| 1242 | // It will be analyzed later. |
| 1243 | Vars.push_back(DE); |
| 1244 | continue; |
| 1245 | } |
| 1246 | |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1247 | // OpenMP [2.9.2, Restrictions, C/C++, p.10] |
| 1248 | // A threadprivate variable must not have an incomplete type. |
| 1249 | if (RequireCompleteType(ILoc, VD->getType(), |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1250 | diag::err_omp_threadprivate_incomplete_type)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1251 | continue; |
| 1252 | } |
| 1253 | |
| 1254 | // OpenMP [2.9.2, Restrictions, C/C++, p.10] |
| 1255 | // A threadprivate variable must not have a reference type. |
| 1256 | if (VD->getType()->isReferenceType()) { |
| 1257 | Diag(ILoc, diag::err_omp_ref_type_arg) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1258 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD->getType(); |
| 1259 | bool IsDecl = |
| 1260 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1261 | Diag(VD->getLocation(), |
| 1262 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1263 | << VD; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1264 | continue; |
| 1265 | } |
| 1266 | |
Samuel Antao | f8b5012 | 2015-07-13 22:54:53 +0000 | [diff] [blame] | 1267 | // Check if this is a TLS variable. If TLS is not being supported, produce |
| 1268 | // the corresponding diagnostic. |
| 1269 | if ((VD->getTLSKind() != VarDecl::TLS_None && |
| 1270 | !(VD->hasAttr<OMPThreadPrivateDeclAttr>() && |
| 1271 | getLangOpts().OpenMPUseTLS && |
| 1272 | getASTContext().getTargetInfo().isTLSSupported())) || |
Alexey Bataev | 1a8b3f1 | 2015-05-06 06:34:55 +0000 | [diff] [blame] | 1273 | (VD->getStorageClass() == SC_Register && VD->hasAttr<AsmLabelAttr>() && |
| 1274 | !VD->isLocalVarDecl())) { |
Alexey Bataev | 26a3924 | 2015-01-13 03:35:30 +0000 | [diff] [blame] | 1275 | Diag(ILoc, diag::err_omp_var_thread_local) |
| 1276 | << VD << ((VD->getTLSKind() != VarDecl::TLS_None) ? 0 : 1); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1277 | bool IsDecl = |
| 1278 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1279 | Diag(VD->getLocation(), |
| 1280 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1281 | << VD; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1282 | continue; |
| 1283 | } |
| 1284 | |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1285 | // Check if initial value of threadprivate variable reference variable with |
| 1286 | // local storage (it is not supported by runtime). |
| 1287 | if (auto Init = VD->getAnyInitializer()) { |
| 1288 | LocalVarRefChecker Checker(*this); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1289 | if (Checker.Visit(Init)) |
| 1290 | continue; |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1291 | } |
| 1292 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1293 | Vars.push_back(RefExpr); |
Alexey Bataev | d178ad4 | 2014-03-07 08:03:37 +0000 | [diff] [blame] | 1294 | DSAStack->addDSA(VD, DE, OMPC_threadprivate); |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 1295 | VD->addAttr(OMPThreadPrivateDeclAttr::CreateImplicit( |
| 1296 | Context, SourceRange(Loc, Loc))); |
| 1297 | if (auto *ML = Context.getASTMutationListener()) |
| 1298 | ML->DeclarationMarkedOpenMPThreadPrivate(VD); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1299 | } |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 1300 | OMPThreadPrivateDecl *D = nullptr; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 1301 | if (!Vars.empty()) { |
| 1302 | D = OMPThreadPrivateDecl::Create(Context, getCurLexicalContext(), Loc, |
| 1303 | Vars); |
| 1304 | D->setAccess(AS_public); |
| 1305 | } |
| 1306 | return D; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1307 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1308 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1309 | static void ReportOriginalDSA(Sema &SemaRef, DSAStackTy *Stack, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1310 | const ValueDecl *D, DSAStackTy::DSAVarData DVar, |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1311 | bool IsLoopIterVar = false) { |
| 1312 | if (DVar.RefExpr) { |
| 1313 | SemaRef.Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_explicit_dsa) |
| 1314 | << getOpenMPClauseName(DVar.CKind); |
| 1315 | return; |
| 1316 | } |
| 1317 | enum { |
| 1318 | PDSA_StaticMemberShared, |
| 1319 | PDSA_StaticLocalVarShared, |
| 1320 | PDSA_LoopIterVarPrivate, |
| 1321 | PDSA_LoopIterVarLinear, |
| 1322 | PDSA_LoopIterVarLastprivate, |
| 1323 | PDSA_ConstVarShared, |
| 1324 | PDSA_GlobalVarShared, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1325 | PDSA_TaskVarFirstprivate, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1326 | PDSA_LocalVarPrivate, |
| 1327 | PDSA_Implicit |
| 1328 | } Reason = PDSA_Implicit; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1329 | bool ReportHint = false; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1330 | auto ReportLoc = D->getLocation(); |
| 1331 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1332 | if (IsLoopIterVar) { |
| 1333 | if (DVar.CKind == OMPC_private) |
| 1334 | Reason = PDSA_LoopIterVarPrivate; |
| 1335 | else if (DVar.CKind == OMPC_lastprivate) |
| 1336 | Reason = PDSA_LoopIterVarLastprivate; |
| 1337 | else |
| 1338 | Reason = PDSA_LoopIterVarLinear; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1339 | } else if (DVar.DKind == OMPD_task && DVar.CKind == OMPC_firstprivate) { |
| 1340 | Reason = PDSA_TaskVarFirstprivate; |
| 1341 | ReportLoc = DVar.ImplicitDSALoc; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1342 | } else if (VD && VD->isStaticLocal()) |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1343 | Reason = PDSA_StaticLocalVarShared; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1344 | else if (VD && VD->isStaticDataMember()) |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1345 | Reason = PDSA_StaticMemberShared; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1346 | else if (VD && VD->isFileVarDecl()) |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1347 | Reason = PDSA_GlobalVarShared; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1348 | else if (D->getType().isConstant(SemaRef.getASTContext())) |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1349 | Reason = PDSA_ConstVarShared; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1350 | else if (VD && VD->isLocalVarDecl() && DVar.CKind == OMPC_private) { |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1351 | ReportHint = true; |
| 1352 | Reason = PDSA_LocalVarPrivate; |
| 1353 | } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1354 | if (Reason != PDSA_Implicit) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1355 | SemaRef.Diag(ReportLoc, diag::note_omp_predetermined_dsa) |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1356 | << Reason << ReportHint |
| 1357 | << getOpenMPDirectiveName(Stack->getCurrentDirective()); |
| 1358 | } else if (DVar.ImplicitDSALoc.isValid()) { |
| 1359 | SemaRef.Diag(DVar.ImplicitDSALoc, diag::note_omp_implicit_dsa) |
| 1360 | << getOpenMPClauseName(DVar.CKind); |
| 1361 | } |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1362 | } |
| 1363 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1364 | namespace { |
| 1365 | class DSAAttrChecker : public StmtVisitor<DSAAttrChecker, void> { |
| 1366 | DSAStackTy *Stack; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1367 | Sema &SemaRef; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1368 | bool ErrorFound; |
| 1369 | CapturedStmt *CS; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1370 | llvm::SmallVector<Expr *, 8> ImplicitFirstprivate; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1371 | llvm::DenseMap<ValueDecl *, Expr *> VarsWithInheritedDSA; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1372 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1373 | public: |
| 1374 | void VisitDeclRefExpr(DeclRefExpr *E) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1375 | if (auto *VD = dyn_cast<VarDecl>(E->getDecl())) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1376 | // Skip internally declared variables. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1377 | if (VD->isLocalVarDecl() && !CS->capturesVariable(VD)) |
| 1378 | return; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1379 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1380 | auto DVar = Stack->getTopDSA(VD, false); |
| 1381 | // Check if the variable has explicit DSA set and stop analysis if it so. |
| 1382 | if (DVar.RefExpr) return; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1383 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1384 | auto ELoc = E->getExprLoc(); |
| 1385 | auto DKind = Stack->getCurrentDirective(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1386 | // The default(none) clause requires that each variable that is referenced |
| 1387 | // in the construct, and does not have a predetermined data-sharing |
| 1388 | // attribute, must have its data-sharing attribute explicitly determined |
| 1389 | // by being listed in a data-sharing attribute clause. |
| 1390 | if (DVar.CKind == OMPC_unknown && Stack->getDefaultDSA() == DSA_none && |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1391 | isParallelOrTaskRegion(DKind) && |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1392 | VarsWithInheritedDSA.count(VD) == 0) { |
| 1393 | VarsWithInheritedDSA[VD] = E; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1394 | return; |
| 1395 | } |
| 1396 | |
| 1397 | // OpenMP [2.9.3.6, Restrictions, p.2] |
| 1398 | // A list item that appears in a reduction clause of the innermost |
| 1399 | // enclosing worksharing or parallel construct may not be accessed in an |
| 1400 | // explicit task. |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1401 | DVar = Stack->hasInnermostDSA(VD, MatchesAnyClause(OMPC_reduction), |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1402 | [](OpenMPDirectiveKind K) -> bool { |
| 1403 | return isOpenMPParallelDirective(K) || |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1404 | isOpenMPWorksharingDirective(K) || |
| 1405 | isOpenMPTeamsDirective(K); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1406 | }, |
| 1407 | false); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1408 | if (DKind == OMPD_task && DVar.CKind == OMPC_reduction) { |
| 1409 | ErrorFound = true; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1410 | SemaRef.Diag(ELoc, diag::err_omp_reduction_in_task); |
| 1411 | ReportOriginalDSA(SemaRef, Stack, VD, DVar); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1412 | return; |
| 1413 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1414 | |
| 1415 | // Define implicit data-sharing attributes for task. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1416 | DVar = Stack->getImplicitDSA(VD, false); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1417 | if (DKind == OMPD_task && DVar.CKind != OMPC_shared) |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1418 | ImplicitFirstprivate.push_back(E); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1419 | } |
| 1420 | } |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1421 | void VisitMemberExpr(MemberExpr *E) { |
| 1422 | if (isa<CXXThisExpr>(E->getBase()->IgnoreParens())) { |
| 1423 | if (auto *FD = dyn_cast<FieldDecl>(E->getMemberDecl())) { |
| 1424 | auto DVar = Stack->getTopDSA(FD, false); |
| 1425 | // Check if the variable has explicit DSA set and stop analysis if it |
| 1426 | // so. |
| 1427 | if (DVar.RefExpr) |
| 1428 | return; |
| 1429 | |
| 1430 | auto ELoc = E->getExprLoc(); |
| 1431 | auto DKind = Stack->getCurrentDirective(); |
| 1432 | // OpenMP [2.9.3.6, Restrictions, p.2] |
| 1433 | // A list item that appears in a reduction clause of the innermost |
| 1434 | // enclosing worksharing or parallel construct may not be accessed in |
| 1435 | // an |
| 1436 | // explicit task. |
| 1437 | DVar = |
| 1438 | Stack->hasInnermostDSA(FD, MatchesAnyClause(OMPC_reduction), |
| 1439 | [](OpenMPDirectiveKind K) -> bool { |
| 1440 | return isOpenMPParallelDirective(K) || |
| 1441 | isOpenMPWorksharingDirective(K) || |
| 1442 | isOpenMPTeamsDirective(K); |
| 1443 | }, |
| 1444 | false); |
| 1445 | if (DKind == OMPD_task && DVar.CKind == OMPC_reduction) { |
| 1446 | ErrorFound = true; |
| 1447 | SemaRef.Diag(ELoc, diag::err_omp_reduction_in_task); |
| 1448 | ReportOriginalDSA(SemaRef, Stack, FD, DVar); |
| 1449 | return; |
| 1450 | } |
| 1451 | |
| 1452 | // Define implicit data-sharing attributes for task. |
| 1453 | DVar = Stack->getImplicitDSA(FD, false); |
| 1454 | if (DKind == OMPD_task && DVar.CKind != OMPC_shared) |
| 1455 | ImplicitFirstprivate.push_back(E); |
| 1456 | } |
| 1457 | } |
| 1458 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1459 | void VisitOMPExecutableDirective(OMPExecutableDirective *S) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1460 | for (auto *C : S->clauses()) { |
| 1461 | // Skip analysis of arguments of implicitly defined firstprivate clause |
| 1462 | // for task directives. |
| 1463 | if (C && (!isa<OMPFirstprivateClause>(C) || C->getLocStart().isValid())) |
| 1464 | for (auto *CC : C->children()) { |
| 1465 | if (CC) |
| 1466 | Visit(CC); |
| 1467 | } |
| 1468 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1469 | } |
| 1470 | void VisitStmt(Stmt *S) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1471 | for (auto *C : S->children()) { |
| 1472 | if (C && !isa<OMPExecutableDirective>(C)) |
| 1473 | Visit(C); |
| 1474 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1475 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1476 | |
| 1477 | bool isErrorFound() { return ErrorFound; } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1478 | ArrayRef<Expr *> getImplicitFirstprivate() { return ImplicitFirstprivate; } |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1479 | llvm::DenseMap<ValueDecl *, Expr *> &getVarsWithInheritedDSA() { |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1480 | return VarsWithInheritedDSA; |
| 1481 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1482 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1483 | DSAAttrChecker(DSAStackTy *S, Sema &SemaRef, CapturedStmt *CS) |
| 1484 | : Stack(S), SemaRef(SemaRef), ErrorFound(false), CS(CS) {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1485 | }; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1486 | } // namespace |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1487 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1488 | void Sema::ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, Scope *CurScope) { |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1489 | switch (DKind) { |
| 1490 | case OMPD_parallel: { |
| 1491 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1492 | QualType KmpInt32PtrTy = |
| 1493 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1494 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1495 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1496 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1497 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1498 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1499 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1500 | Params); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1501 | break; |
| 1502 | } |
| 1503 | case OMPD_simd: { |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1504 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1505 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1506 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1507 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1508 | Params); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1509 | break; |
| 1510 | } |
| 1511 | case OMPD_for: { |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1512 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1513 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1514 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1515 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1516 | Params); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1517 | break; |
| 1518 | } |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1519 | case OMPD_for_simd: { |
| 1520 | Sema::CapturedParamNameType Params[] = { |
| 1521 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1522 | }; |
| 1523 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1524 | Params); |
| 1525 | break; |
| 1526 | } |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 1527 | case OMPD_sections: { |
| 1528 | Sema::CapturedParamNameType Params[] = { |
| 1529 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1530 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1531 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1532 | Params); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 1533 | break; |
| 1534 | } |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1535 | case OMPD_section: { |
| 1536 | Sema::CapturedParamNameType Params[] = { |
| 1537 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1538 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1539 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1540 | Params); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1541 | break; |
| 1542 | } |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 1543 | case OMPD_single: { |
| 1544 | Sema::CapturedParamNameType Params[] = { |
| 1545 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1546 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1547 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1548 | Params); |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 1549 | break; |
| 1550 | } |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1551 | case OMPD_master: { |
| 1552 | Sema::CapturedParamNameType Params[] = { |
| 1553 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1554 | }; |
| 1555 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1556 | Params); |
| 1557 | break; |
| 1558 | } |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1559 | case OMPD_critical: { |
| 1560 | Sema::CapturedParamNameType Params[] = { |
| 1561 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1562 | }; |
| 1563 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1564 | Params); |
| 1565 | break; |
| 1566 | } |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1567 | case OMPD_parallel_for: { |
| 1568 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1569 | QualType KmpInt32PtrTy = |
| 1570 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1571 | Sema::CapturedParamNameType Params[] = { |
| 1572 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1573 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1574 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1575 | }; |
| 1576 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1577 | Params); |
| 1578 | break; |
| 1579 | } |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1580 | case OMPD_parallel_for_simd: { |
| 1581 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1582 | QualType KmpInt32PtrTy = |
| 1583 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1584 | Sema::CapturedParamNameType Params[] = { |
| 1585 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1586 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1587 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1588 | }; |
| 1589 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1590 | Params); |
| 1591 | break; |
| 1592 | } |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1593 | case OMPD_parallel_sections: { |
Alexey Bataev | 68adb7d | 2015-04-14 03:29:22 +0000 | [diff] [blame] | 1594 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1595 | QualType KmpInt32PtrTy = |
| 1596 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1597 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | 68adb7d | 2015-04-14 03:29:22 +0000 | [diff] [blame] | 1598 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1599 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1600 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1601 | }; |
| 1602 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1603 | Params); |
| 1604 | break; |
| 1605 | } |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1606 | case OMPD_task: { |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1607 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 3ae88e2 | 2015-05-22 08:56:35 +0000 | [diff] [blame] | 1608 | QualType Args[] = {Context.VoidPtrTy.withConst().withRestrict()}; |
| 1609 | FunctionProtoType::ExtProtoInfo EPI; |
| 1610 | EPI.Variadic = true; |
| 1611 | QualType CopyFnType = Context.getFunctionType(Context.VoidTy, Args, EPI); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1612 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1613 | std::make_pair(".global_tid.", KmpInt32Ty), |
| 1614 | std::make_pair(".part_id.", KmpInt32Ty), |
Alexey Bataev | 3ae88e2 | 2015-05-22 08:56:35 +0000 | [diff] [blame] | 1615 | std::make_pair(".privates.", |
| 1616 | Context.VoidPtrTy.withConst().withRestrict()), |
| 1617 | std::make_pair( |
| 1618 | ".copy_fn.", |
| 1619 | Context.getPointerType(CopyFnType).withConst().withRestrict()), |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1620 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1621 | }; |
| 1622 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1623 | Params); |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1624 | // Mark this captured region as inlined, because we don't use outlined |
| 1625 | // function directly. |
| 1626 | getCurCapturedRegion()->TheCapturedDecl->addAttr( |
| 1627 | AlwaysInlineAttr::CreateImplicit( |
| 1628 | Context, AlwaysInlineAttr::Keyword_forceinline, SourceRange())); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1629 | break; |
| 1630 | } |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1631 | case OMPD_ordered: { |
| 1632 | Sema::CapturedParamNameType Params[] = { |
| 1633 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1634 | }; |
| 1635 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1636 | Params); |
| 1637 | break; |
| 1638 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1639 | case OMPD_atomic: { |
| 1640 | Sema::CapturedParamNameType Params[] = { |
| 1641 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1642 | }; |
| 1643 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1644 | Params); |
| 1645 | break; |
| 1646 | } |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 1647 | case OMPD_target_data: |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 1648 | case OMPD_target: |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 1649 | case OMPD_target_parallel: |
| 1650 | case OMPD_target_parallel_for: { |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1651 | Sema::CapturedParamNameType Params[] = { |
| 1652 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1653 | }; |
| 1654 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1655 | Params); |
| 1656 | break; |
| 1657 | } |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1658 | case OMPD_teams: { |
| 1659 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1660 | QualType KmpInt32PtrTy = |
| 1661 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1662 | Sema::CapturedParamNameType Params[] = { |
| 1663 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1664 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1665 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1666 | }; |
| 1667 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1668 | Params); |
| 1669 | break; |
| 1670 | } |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1671 | case OMPD_taskgroup: { |
| 1672 | Sema::CapturedParamNameType Params[] = { |
| 1673 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1674 | }; |
| 1675 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1676 | Params); |
| 1677 | break; |
| 1678 | } |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1679 | case OMPD_taskloop: { |
| 1680 | Sema::CapturedParamNameType Params[] = { |
| 1681 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1682 | }; |
| 1683 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1684 | Params); |
| 1685 | break; |
| 1686 | } |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1687 | case OMPD_taskloop_simd: { |
| 1688 | Sema::CapturedParamNameType Params[] = { |
| 1689 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1690 | }; |
| 1691 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1692 | Params); |
| 1693 | break; |
| 1694 | } |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1695 | case OMPD_distribute: { |
| 1696 | Sema::CapturedParamNameType Params[] = { |
| 1697 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1698 | }; |
| 1699 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1700 | Params); |
| 1701 | break; |
| 1702 | } |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1703 | case OMPD_threadprivate: |
Alexey Bataev | ee9af45 | 2014-11-21 11:33:46 +0000 | [diff] [blame] | 1704 | case OMPD_taskyield: |
| 1705 | case OMPD_barrier: |
| 1706 | case OMPD_taskwait: |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1707 | case OMPD_cancellation_point: |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1708 | case OMPD_cancel: |
Alexey Bataev | ee9af45 | 2014-11-21 11:33:46 +0000 | [diff] [blame] | 1709 | case OMPD_flush: |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1710 | case OMPD_target_enter_data: |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1711 | case OMPD_target_exit_data: |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1712 | llvm_unreachable("OpenMP Directive is not allowed"); |
| 1713 | case OMPD_unknown: |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1714 | llvm_unreachable("Unknown OpenMP directive"); |
| 1715 | } |
| 1716 | } |
| 1717 | |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1718 | StmtResult Sema::ActOnOpenMPRegionEnd(StmtResult S, |
| 1719 | ArrayRef<OMPClause *> Clauses) { |
| 1720 | if (!S.isUsable()) { |
| 1721 | ActOnCapturedRegionError(); |
| 1722 | return StmtError(); |
| 1723 | } |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1724 | |
| 1725 | OMPOrderedClause *OC = nullptr; |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1726 | OMPScheduleClause *SC = nullptr; |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1727 | SmallVector<OMPLinearClause *, 4> LCs; |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1728 | // This is required for proper codegen. |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1729 | for (auto *Clause : Clauses) { |
Alexey Bataev | 16dc7b6 | 2015-05-20 03:46:04 +0000 | [diff] [blame] | 1730 | if (isOpenMPPrivate(Clause->getClauseKind()) || |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 1731 | Clause->getClauseKind() == OMPC_copyprivate || |
| 1732 | (getLangOpts().OpenMPUseTLS && |
| 1733 | getASTContext().getTargetInfo().isTLSSupported() && |
| 1734 | Clause->getClauseKind() == OMPC_copyin)) { |
| 1735 | DSAStack->setForceVarCapturing(Clause->getClauseKind() == OMPC_copyin); |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1736 | // Mark all variables in private list clauses as used in inner region. |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1737 | for (auto *VarRef : Clause->children()) { |
| 1738 | if (auto *E = cast_or_null<Expr>(VarRef)) { |
Alexey Bataev | 8bf6b3e | 2015-04-02 13:07:08 +0000 | [diff] [blame] | 1739 | MarkDeclarationsReferencedInExpr(E); |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1740 | } |
| 1741 | } |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 1742 | DSAStack->setForceVarCapturing(/*V=*/false); |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1743 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective()) && |
| 1744 | Clause->getClauseKind() == OMPC_schedule) { |
| 1745 | // Mark all variables in private list clauses as used in inner region. |
| 1746 | // Required for proper codegen of combined directives. |
| 1747 | // TODO: add processing for other clauses. |
| 1748 | if (auto *E = cast_or_null<Expr>( |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1749 | cast<OMPScheduleClause>(Clause)->getHelperChunkSize())) |
| 1750 | MarkDeclarationsReferencedInExpr(E); |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1751 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1752 | if (Clause->getClauseKind() == OMPC_schedule) |
| 1753 | SC = cast<OMPScheduleClause>(Clause); |
| 1754 | else if (Clause->getClauseKind() == OMPC_ordered) |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1755 | OC = cast<OMPOrderedClause>(Clause); |
| 1756 | else if (Clause->getClauseKind() == OMPC_linear) |
| 1757 | LCs.push_back(cast<OMPLinearClause>(Clause)); |
| 1758 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1759 | bool ErrorFound = false; |
| 1760 | // OpenMP, 2.7.1 Loop Construct, Restrictions |
| 1761 | // The nonmonotonic modifier cannot be specified if an ordered clause is |
| 1762 | // specified. |
| 1763 | if (SC && |
| 1764 | (SC->getFirstScheduleModifier() == OMPC_SCHEDULE_MODIFIER_nonmonotonic || |
| 1765 | SC->getSecondScheduleModifier() == |
| 1766 | OMPC_SCHEDULE_MODIFIER_nonmonotonic) && |
| 1767 | OC) { |
| 1768 | Diag(SC->getFirstScheduleModifier() == OMPC_SCHEDULE_MODIFIER_nonmonotonic |
| 1769 | ? SC->getFirstScheduleModifierLoc() |
| 1770 | : SC->getSecondScheduleModifierLoc(), |
| 1771 | diag::err_omp_schedule_nonmonotonic_ordered) |
| 1772 | << SourceRange(OC->getLocStart(), OC->getLocEnd()); |
| 1773 | ErrorFound = true; |
| 1774 | } |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1775 | if (!LCs.empty() && OC && OC->getNumForLoops()) { |
| 1776 | for (auto *C : LCs) { |
| 1777 | Diag(C->getLocStart(), diag::err_omp_linear_ordered) |
| 1778 | << SourceRange(OC->getLocStart(), OC->getLocEnd()); |
| 1779 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1780 | ErrorFound = true; |
| 1781 | } |
Alexey Bataev | 113438c | 2015-12-30 12:06:23 +0000 | [diff] [blame] | 1782 | if (isOpenMPWorksharingDirective(DSAStack->getCurrentDirective()) && |
| 1783 | isOpenMPSimdDirective(DSAStack->getCurrentDirective()) && OC && |
| 1784 | OC->getNumForLoops()) { |
| 1785 | Diag(OC->getLocStart(), diag::err_omp_ordered_simd) |
| 1786 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 1787 | ErrorFound = true; |
| 1788 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1789 | if (ErrorFound) { |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1790 | ActOnCapturedRegionError(); |
| 1791 | return StmtError(); |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1792 | } |
| 1793 | return ActOnCapturedRegionEnd(S.get()); |
| 1794 | } |
| 1795 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1796 | static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, |
| 1797 | OpenMPDirectiveKind CurrentRegion, |
| 1798 | const DeclarationNameInfo &CurrentName, |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1799 | OpenMPDirectiveKind CancelRegion, |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1800 | SourceLocation StartLoc) { |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1801 | // Allowed nesting of constructs |
| 1802 | // +------------------+-----------------+------------------------------------+ |
| 1803 | // | Parent directive | Child directive | Closely (!), No-Closely(+), Both(*)| |
| 1804 | // +------------------+-----------------+------------------------------------+ |
| 1805 | // | parallel | parallel | * | |
| 1806 | // | parallel | for | * | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1807 | // | parallel | for simd | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1808 | // | parallel | master | * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1809 | // | parallel | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1810 | // | parallel | simd | * | |
| 1811 | // | parallel | sections | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1812 | // | parallel | section | + | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1813 | // | parallel | single | * | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1814 | // | parallel | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1815 | // | parallel |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1816 | // | parallel |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1817 | // | parallel | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1818 | // | parallel | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1819 | // | parallel | barrier | * | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1820 | // | parallel | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1821 | // | parallel | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1822 | // | parallel | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1823 | // | parallel | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1824 | // | parallel | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1825 | // | parallel | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 1826 | // | parallel | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 1827 | // | parallel | target parallel | * | |
| 1828 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1829 | // | parallel | target enter | * | |
| 1830 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1831 | // | parallel | target exit | * | |
| 1832 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1833 | // | parallel | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1834 | // | parallel | cancellation | | |
| 1835 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1836 | // | parallel | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1837 | // | parallel | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1838 | // | parallel | taskloop simd | * | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1839 | // | parallel | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1840 | // +------------------+-----------------+------------------------------------+ |
| 1841 | // | for | parallel | * | |
| 1842 | // | for | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1843 | // | for | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1844 | // | for | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1845 | // | for | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1846 | // | for | simd | * | |
| 1847 | // | for | sections | + | |
| 1848 | // | for | section | + | |
| 1849 | // | for | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1850 | // | for | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1851 | // | for |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1852 | // | for |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1853 | // | for | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1854 | // | for | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1855 | // | for | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1856 | // | for | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1857 | // | for | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1858 | // | for | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1859 | // | for | ordered | * (if construct is ordered) | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1860 | // | for | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1861 | // | for | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 1862 | // | for | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 1863 | // | for | target parallel | * | |
| 1864 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1865 | // | for | target enter | * | |
| 1866 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1867 | // | for | target exit | * | |
| 1868 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1869 | // | for | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1870 | // | for | cancellation | | |
| 1871 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1872 | // | for | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1873 | // | for | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1874 | // | for | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1875 | // | for | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1876 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1877 | // | master | parallel | * | |
| 1878 | // | master | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1879 | // | master | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1880 | // | master | master | * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1881 | // | master | critical | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1882 | // | master | simd | * | |
| 1883 | // | master | sections | + | |
| 1884 | // | master | section | + | |
| 1885 | // | master | single | + | |
| 1886 | // | master | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1887 | // | master |parallel for simd| * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1888 | // | master |parallel sections| * | |
| 1889 | // | master | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1890 | // | master | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1891 | // | master | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1892 | // | master | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1893 | // | master | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1894 | // | master | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1895 | // | master | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1896 | // | master | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1897 | // | master | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 1898 | // | master | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 1899 | // | master | target parallel | * | |
| 1900 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1901 | // | master | target enter | * | |
| 1902 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1903 | // | master | target exit | * | |
| 1904 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1905 | // | master | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1906 | // | master | cancellation | | |
| 1907 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1908 | // | master | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1909 | // | master | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1910 | // | master | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1911 | // | master | distribute | | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1912 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1913 | // | critical | parallel | * | |
| 1914 | // | critical | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1915 | // | critical | for simd | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1916 | // | critical | master | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1917 | // | critical | critical | * (should have different names) | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1918 | // | critical | simd | * | |
| 1919 | // | critical | sections | + | |
| 1920 | // | critical | section | + | |
| 1921 | // | critical | single | + | |
| 1922 | // | critical | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1923 | // | critical |parallel for simd| * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1924 | // | critical |parallel sections| * | |
| 1925 | // | critical | task | * | |
| 1926 | // | critical | taskyield | * | |
| 1927 | // | critical | barrier | + | |
| 1928 | // | critical | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1929 | // | critical | taskgroup | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1930 | // | critical | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1931 | // | critical | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1932 | // | critical | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 1933 | // | critical | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 1934 | // | critical | target parallel | * | |
| 1935 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1936 | // | critical | target enter | * | |
| 1937 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1938 | // | critical | target exit | * | |
| 1939 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1940 | // | critical | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1941 | // | critical | cancellation | | |
| 1942 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1943 | // | critical | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1944 | // | critical | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1945 | // | critical | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1946 | // | critical | distribute | | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1947 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1948 | // | simd | parallel | | |
| 1949 | // | simd | for | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1950 | // | simd | for simd | | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1951 | // | simd | master | | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1952 | // | simd | critical | | |
Alexey Bataev | 1f09221 | 2016-02-02 04:59:52 +0000 | [diff] [blame] | 1953 | // | simd | simd | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1954 | // | simd | sections | | |
| 1955 | // | simd | section | | |
| 1956 | // | simd | single | | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1957 | // | simd | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1958 | // | simd |parallel for simd| | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1959 | // | simd |parallel sections| | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1960 | // | simd | task | | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1961 | // | simd | taskyield | | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1962 | // | simd | barrier | | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1963 | // | simd | taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1964 | // | simd | taskgroup | | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1965 | // | simd | flush | | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 1966 | // | simd | ordered | + (with simd clause) | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1967 | // | simd | atomic | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1968 | // | simd | target | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 1969 | // | simd | target parallel | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 1970 | // | simd | target parallel | | |
| 1971 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1972 | // | simd | target enter | | |
| 1973 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1974 | // | simd | target exit | | |
| 1975 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1976 | // | simd | teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1977 | // | simd | cancellation | | |
| 1978 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1979 | // | simd | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1980 | // | simd | taskloop | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1981 | // | simd | taskloop simd | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1982 | // | simd | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1983 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1984 | // | for simd | parallel | | |
| 1985 | // | for simd | for | | |
| 1986 | // | for simd | for simd | | |
| 1987 | // | for simd | master | | |
| 1988 | // | for simd | critical | | |
Alexey Bataev | 1f09221 | 2016-02-02 04:59:52 +0000 | [diff] [blame] | 1989 | // | for simd | simd | * | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1990 | // | for simd | sections | | |
| 1991 | // | for simd | section | | |
| 1992 | // | for simd | single | | |
| 1993 | // | for simd | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1994 | // | for simd |parallel for simd| | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1995 | // | for simd |parallel sections| | |
| 1996 | // | for simd | task | | |
| 1997 | // | for simd | taskyield | | |
| 1998 | // | for simd | barrier | | |
| 1999 | // | for simd | taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2000 | // | for simd | taskgroup | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2001 | // | for simd | flush | | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2002 | // | for simd | ordered | + (with simd clause) | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2003 | // | for simd | atomic | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2004 | // | for simd | target | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2005 | // | for simd | target parallel | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2006 | // | for simd | target parallel | | |
| 2007 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2008 | // | for simd | target enter | | |
| 2009 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2010 | // | for simd | target exit | | |
| 2011 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2012 | // | for simd | teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2013 | // | for simd | cancellation | | |
| 2014 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2015 | // | for simd | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2016 | // | for simd | taskloop | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2017 | // | for simd | taskloop simd | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2018 | // | for simd | distribute | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2019 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2020 | // | parallel for simd| parallel | | |
| 2021 | // | parallel for simd| for | | |
| 2022 | // | parallel for simd| for simd | | |
| 2023 | // | parallel for simd| master | | |
| 2024 | // | parallel for simd| critical | | |
Alexey Bataev | 1f09221 | 2016-02-02 04:59:52 +0000 | [diff] [blame] | 2025 | // | parallel for simd| simd | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2026 | // | parallel for simd| sections | | |
| 2027 | // | parallel for simd| section | | |
| 2028 | // | parallel for simd| single | | |
| 2029 | // | parallel for simd| parallel for | | |
| 2030 | // | parallel for simd|parallel for simd| | |
| 2031 | // | parallel for simd|parallel sections| | |
| 2032 | // | parallel for simd| task | | |
| 2033 | // | parallel for simd| taskyield | | |
| 2034 | // | parallel for simd| barrier | | |
| 2035 | // | parallel for simd| taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2036 | // | parallel for simd| taskgroup | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2037 | // | parallel for simd| flush | | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2038 | // | parallel for simd| ordered | + (with simd clause) | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2039 | // | parallel for simd| atomic | | |
| 2040 | // | parallel for simd| target | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2041 | // | parallel for simd| target parallel | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2042 | // | parallel for simd| target parallel | | |
| 2043 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2044 | // | parallel for simd| target enter | | |
| 2045 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2046 | // | parallel for simd| target exit | | |
| 2047 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2048 | // | parallel for simd| teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2049 | // | parallel for simd| cancellation | | |
| 2050 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2051 | // | parallel for simd| cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2052 | // | parallel for simd| taskloop | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2053 | // | parallel for simd| taskloop simd | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2054 | // | parallel for simd| distribute | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2055 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2056 | // | sections | parallel | * | |
| 2057 | // | sections | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2058 | // | sections | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2059 | // | sections | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2060 | // | sections | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2061 | // | sections | simd | * | |
| 2062 | // | sections | sections | + | |
| 2063 | // | sections | section | * | |
| 2064 | // | sections | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2065 | // | sections | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2066 | // | sections |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2067 | // | sections |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2068 | // | sections | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2069 | // | sections | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2070 | // | sections | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2071 | // | sections | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2072 | // | sections | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2073 | // | sections | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2074 | // | sections | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2075 | // | sections | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2076 | // | sections | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2077 | // | sections | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2078 | // | sections | target parallel | * | |
| 2079 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2080 | // | sections | target enter | * | |
| 2081 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2082 | // | sections | target exit | * | |
| 2083 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2084 | // | sections | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2085 | // | sections | cancellation | | |
| 2086 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2087 | // | sections | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2088 | // | sections | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2089 | // | sections | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2090 | // | sections | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2091 | // +------------------+-----------------+------------------------------------+ |
| 2092 | // | section | parallel | * | |
| 2093 | // | section | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2094 | // | section | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2095 | // | section | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2096 | // | section | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2097 | // | section | simd | * | |
| 2098 | // | section | sections | + | |
| 2099 | // | section | section | + | |
| 2100 | // | section | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2101 | // | section | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2102 | // | section |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2103 | // | section |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2104 | // | section | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2105 | // | section | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2106 | // | section | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2107 | // | section | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2108 | // | section | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2109 | // | section | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2110 | // | section | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2111 | // | section | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2112 | // | section | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2113 | // | section | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2114 | // | section | target parallel | * | |
| 2115 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2116 | // | section | target enter | * | |
| 2117 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2118 | // | section | target exit | * | |
| 2119 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2120 | // | section | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2121 | // | section | cancellation | | |
| 2122 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2123 | // | section | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2124 | // | section | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2125 | // | section | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2126 | // | section | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2127 | // +------------------+-----------------+------------------------------------+ |
| 2128 | // | single | parallel | * | |
| 2129 | // | single | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2130 | // | single | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2131 | // | single | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2132 | // | single | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2133 | // | single | simd | * | |
| 2134 | // | single | sections | + | |
| 2135 | // | single | section | + | |
| 2136 | // | single | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2137 | // | single | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2138 | // | single |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2139 | // | single |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2140 | // | single | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2141 | // | single | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2142 | // | single | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2143 | // | single | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2144 | // | single | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2145 | // | single | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2146 | // | single | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2147 | // | single | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2148 | // | single | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2149 | // | single | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2150 | // | single | target parallel | * | |
| 2151 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2152 | // | single | target enter | * | |
| 2153 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2154 | // | single | target exit | * | |
| 2155 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2156 | // | single | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2157 | // | single | cancellation | | |
| 2158 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2159 | // | single | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2160 | // | single | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2161 | // | single | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2162 | // | single | distribute | | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2163 | // +------------------+-----------------+------------------------------------+ |
| 2164 | // | parallel for | parallel | * | |
| 2165 | // | parallel for | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2166 | // | parallel for | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2167 | // | parallel for | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2168 | // | parallel for | critical | * | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2169 | // | parallel for | simd | * | |
| 2170 | // | parallel for | sections | + | |
| 2171 | // | parallel for | section | + | |
| 2172 | // | parallel for | single | + | |
| 2173 | // | parallel for | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2174 | // | parallel for |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2175 | // | parallel for |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2176 | // | parallel for | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2177 | // | parallel for | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2178 | // | parallel for | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2179 | // | parallel for | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2180 | // | parallel for | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2181 | // | parallel for | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2182 | // | parallel for | ordered | * (if construct is ordered) | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2183 | // | parallel for | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2184 | // | parallel for | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2185 | // | parallel for | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2186 | // | parallel for | target parallel | * | |
| 2187 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2188 | // | parallel for | target enter | * | |
| 2189 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2190 | // | parallel for | target exit | * | |
| 2191 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2192 | // | parallel for | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2193 | // | parallel for | cancellation | | |
| 2194 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2195 | // | parallel for | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2196 | // | parallel for | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2197 | // | parallel for | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2198 | // | parallel for | distribute | | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2199 | // +------------------+-----------------+------------------------------------+ |
| 2200 | // | parallel sections| parallel | * | |
| 2201 | // | parallel sections| for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2202 | // | parallel sections| for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2203 | // | parallel sections| master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2204 | // | parallel sections| critical | + | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2205 | // | parallel sections| simd | * | |
| 2206 | // | parallel sections| sections | + | |
| 2207 | // | parallel sections| section | * | |
| 2208 | // | parallel sections| single | + | |
| 2209 | // | parallel sections| parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2210 | // | parallel sections|parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2211 | // | parallel sections|parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2212 | // | parallel sections| task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2213 | // | parallel sections| taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2214 | // | parallel sections| barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2215 | // | parallel sections| taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2216 | // | parallel sections| taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2217 | // | parallel sections| flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2218 | // | parallel sections| ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2219 | // | parallel sections| atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2220 | // | parallel sections| target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2221 | // | parallel sections| target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2222 | // | parallel sections| target parallel | * | |
| 2223 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2224 | // | parallel sections| target enter | * | |
| 2225 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2226 | // | parallel sections| target exit | * | |
| 2227 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2228 | // | parallel sections| teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2229 | // | parallel sections| cancellation | | |
| 2230 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2231 | // | parallel sections| cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2232 | // | parallel sections| taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2233 | // | parallel sections| taskloop simd | * | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2234 | // | parallel sections| distribute | | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2235 | // +------------------+-----------------+------------------------------------+ |
| 2236 | // | task | parallel | * | |
| 2237 | // | task | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2238 | // | task | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2239 | // | task | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2240 | // | task | critical | * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2241 | // | task | simd | * | |
| 2242 | // | task | sections | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2243 | // | task | section | + | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2244 | // | task | single | + | |
| 2245 | // | task | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2246 | // | task |parallel for simd| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2247 | // | task |parallel sections| * | |
| 2248 | // | task | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2249 | // | task | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2250 | // | task | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2251 | // | task | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2252 | // | task | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2253 | // | task | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2254 | // | task | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2255 | // | task | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2256 | // | task | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2257 | // | task | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2258 | // | task | target parallel | * | |
| 2259 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2260 | // | task | target enter | * | |
| 2261 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2262 | // | task | target exit | * | |
| 2263 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2264 | // | task | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2265 | // | task | cancellation | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2266 | // | | point | ! | |
| 2267 | // | task | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2268 | // | task | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2269 | // | task | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2270 | // | task | distribute | | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2271 | // +------------------+-----------------+------------------------------------+ |
| 2272 | // | ordered | parallel | * | |
| 2273 | // | ordered | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2274 | // | ordered | for simd | + | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2275 | // | ordered | master | * | |
| 2276 | // | ordered | critical | * | |
| 2277 | // | ordered | simd | * | |
| 2278 | // | ordered | sections | + | |
| 2279 | // | ordered | section | + | |
| 2280 | // | ordered | single | + | |
| 2281 | // | ordered | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2282 | // | ordered |parallel for simd| * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2283 | // | ordered |parallel sections| * | |
| 2284 | // | ordered | task | * | |
| 2285 | // | ordered | taskyield | * | |
| 2286 | // | ordered | barrier | + | |
| 2287 | // | ordered | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2288 | // | ordered | taskgroup | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2289 | // | ordered | flush | * | |
| 2290 | // | ordered | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2291 | // | ordered | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2292 | // | ordered | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2293 | // | ordered | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2294 | // | ordered | target parallel | * | |
| 2295 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2296 | // | ordered | target enter | * | |
| 2297 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2298 | // | ordered | target exit | * | |
| 2299 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2300 | // | ordered | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2301 | // | ordered | cancellation | | |
| 2302 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2303 | // | ordered | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2304 | // | ordered | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2305 | // | ordered | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2306 | // | ordered | distribute | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2307 | // +------------------+-----------------+------------------------------------+ |
| 2308 | // | atomic | parallel | | |
| 2309 | // | atomic | for | | |
| 2310 | // | atomic | for simd | | |
| 2311 | // | atomic | master | | |
| 2312 | // | atomic | critical | | |
| 2313 | // | atomic | simd | | |
| 2314 | // | atomic | sections | | |
| 2315 | // | atomic | section | | |
| 2316 | // | atomic | single | | |
| 2317 | // | atomic | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2318 | // | atomic |parallel for simd| | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2319 | // | atomic |parallel sections| | |
| 2320 | // | atomic | task | | |
| 2321 | // | atomic | taskyield | | |
| 2322 | // | atomic | barrier | | |
| 2323 | // | atomic | taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2324 | // | atomic | taskgroup | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2325 | // | atomic | flush | | |
| 2326 | // | atomic | ordered | | |
| 2327 | // | atomic | atomic | | |
| 2328 | // | atomic | target | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2329 | // | atomic | target parallel | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2330 | // | atomic | target parallel | | |
| 2331 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2332 | // | atomic | target enter | | |
| 2333 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2334 | // | atomic | target exit | | |
| 2335 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2336 | // | atomic | teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2337 | // | atomic | cancellation | | |
| 2338 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2339 | // | atomic | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2340 | // | atomic | taskloop | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2341 | // | atomic | taskloop simd | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2342 | // | atomic | distribute | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2343 | // +------------------+-----------------+------------------------------------+ |
| 2344 | // | target | parallel | * | |
| 2345 | // | target | for | * | |
| 2346 | // | target | for simd | * | |
| 2347 | // | target | master | * | |
| 2348 | // | target | critical | * | |
| 2349 | // | target | simd | * | |
| 2350 | // | target | sections | * | |
| 2351 | // | target | section | * | |
| 2352 | // | target | single | * | |
| 2353 | // | target | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2354 | // | target |parallel for simd| * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2355 | // | target |parallel sections| * | |
| 2356 | // | target | task | * | |
| 2357 | // | target | taskyield | * | |
| 2358 | // | target | barrier | * | |
| 2359 | // | target | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2360 | // | target | taskgroup | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2361 | // | target | flush | * | |
| 2362 | // | target | ordered | * | |
| 2363 | // | target | atomic | * | |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2364 | // | target | target | | |
| 2365 | // | target | target parallel | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2366 | // | target | target parallel | | |
| 2367 | // | | for | | |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2368 | // | target | target enter | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2369 | // | | data | | |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2370 | // | target | target exit | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2371 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2372 | // | target | teams | * | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2373 | // | target | cancellation | | |
| 2374 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2375 | // | target | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2376 | // | target | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2377 | // | target | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2378 | // | target | distribute | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2379 | // +------------------+-----------------+------------------------------------+ |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2380 | // | target parallel | parallel | * | |
| 2381 | // | target parallel | for | * | |
| 2382 | // | target parallel | for simd | * | |
| 2383 | // | target parallel | master | * | |
| 2384 | // | target parallel | critical | * | |
| 2385 | // | target parallel | simd | * | |
| 2386 | // | target parallel | sections | * | |
| 2387 | // | target parallel | section | * | |
| 2388 | // | target parallel | single | * | |
| 2389 | // | target parallel | parallel for | * | |
| 2390 | // | target parallel |parallel for simd| * | |
| 2391 | // | target parallel |parallel sections| * | |
| 2392 | // | target parallel | task | * | |
| 2393 | // | target parallel | taskyield | * | |
| 2394 | // | target parallel | barrier | * | |
| 2395 | // | target parallel | taskwait | * | |
| 2396 | // | target parallel | taskgroup | * | |
| 2397 | // | target parallel | flush | * | |
| 2398 | // | target parallel | ordered | * | |
| 2399 | // | target parallel | atomic | * | |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2400 | // | target parallel | target | | |
| 2401 | // | target parallel | target parallel | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2402 | // | target parallel | target parallel | | |
| 2403 | // | | for | | |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2404 | // | target parallel | target enter | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2405 | // | | data | | |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2406 | // | target parallel | target exit | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2407 | // | | data | | |
| 2408 | // | target parallel | teams | | |
| 2409 | // | target parallel | cancellation | | |
| 2410 | // | | point | ! | |
| 2411 | // | target parallel | cancel | ! | |
| 2412 | // | target parallel | taskloop | * | |
| 2413 | // | target parallel | taskloop simd | * | |
| 2414 | // | target parallel | distribute | | |
| 2415 | // +------------------+-----------------+------------------------------------+ |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2416 | // | target parallel | parallel | * | |
| 2417 | // | for | | | |
| 2418 | // | target parallel | for | * | |
| 2419 | // | for | | | |
| 2420 | // | target parallel | for simd | * | |
| 2421 | // | for | | | |
| 2422 | // | target parallel | master | * | |
| 2423 | // | for | | | |
| 2424 | // | target parallel | critical | * | |
| 2425 | // | for | | | |
| 2426 | // | target parallel | simd | * | |
| 2427 | // | for | | | |
| 2428 | // | target parallel | sections | * | |
| 2429 | // | for | | | |
| 2430 | // | target parallel | section | * | |
| 2431 | // | for | | | |
| 2432 | // | target parallel | single | * | |
| 2433 | // | for | | | |
| 2434 | // | target parallel | parallel for | * | |
| 2435 | // | for | | | |
| 2436 | // | target parallel |parallel for simd| * | |
| 2437 | // | for | | | |
| 2438 | // | target parallel |parallel sections| * | |
| 2439 | // | for | | | |
| 2440 | // | target parallel | task | * | |
| 2441 | // | for | | | |
| 2442 | // | target parallel | taskyield | * | |
| 2443 | // | for | | | |
| 2444 | // | target parallel | barrier | * | |
| 2445 | // | for | | | |
| 2446 | // | target parallel | taskwait | * | |
| 2447 | // | for | | | |
| 2448 | // | target parallel | taskgroup | * | |
| 2449 | // | for | | | |
| 2450 | // | target parallel | flush | * | |
| 2451 | // | for | | | |
| 2452 | // | target parallel | ordered | * | |
| 2453 | // | for | | | |
| 2454 | // | target parallel | atomic | * | |
| 2455 | // | for | | | |
| 2456 | // | target parallel | target | | |
| 2457 | // | for | | | |
| 2458 | // | target parallel | target parallel | | |
| 2459 | // | for | | | |
| 2460 | // | target parallel | target parallel | | |
| 2461 | // | for | for | | |
| 2462 | // | target parallel | target enter | | |
| 2463 | // | for | data | | |
| 2464 | // | target parallel | target exit | | |
| 2465 | // | for | data | | |
| 2466 | // | target parallel | teams | | |
| 2467 | // | for | | | |
| 2468 | // | target parallel | cancellation | | |
| 2469 | // | for | point | ! | |
| 2470 | // | target parallel | cancel | ! | |
| 2471 | // | for | | | |
| 2472 | // | target parallel | taskloop | * | |
| 2473 | // | for | | | |
| 2474 | // | target parallel | taskloop simd | * | |
| 2475 | // | for | | | |
| 2476 | // | target parallel | distribute | | |
| 2477 | // | for | | | |
| 2478 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2479 | // | teams | parallel | * | |
| 2480 | // | teams | for | + | |
| 2481 | // | teams | for simd | + | |
| 2482 | // | teams | master | + | |
| 2483 | // | teams | critical | + | |
| 2484 | // | teams | simd | + | |
| 2485 | // | teams | sections | + | |
| 2486 | // | teams | section | + | |
| 2487 | // | teams | single | + | |
| 2488 | // | teams | parallel for | * | |
| 2489 | // | teams |parallel for simd| * | |
| 2490 | // | teams |parallel sections| * | |
| 2491 | // | teams | task | + | |
| 2492 | // | teams | taskyield | + | |
| 2493 | // | teams | barrier | + | |
| 2494 | // | teams | taskwait | + | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2495 | // | teams | taskgroup | + | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2496 | // | teams | flush | + | |
| 2497 | // | teams | ordered | + | |
| 2498 | // | teams | atomic | + | |
| 2499 | // | teams | target | + | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2500 | // | teams | target parallel | + | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2501 | // | teams | target parallel | + | |
| 2502 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2503 | // | teams | target enter | + | |
| 2504 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2505 | // | teams | target exit | + | |
| 2506 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2507 | // | teams | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2508 | // | teams | cancellation | | |
| 2509 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2510 | // | teams | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2511 | // | teams | taskloop | + | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2512 | // | teams | taskloop simd | + | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2513 | // | teams | distribute | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2514 | // +------------------+-----------------+------------------------------------+ |
| 2515 | // | taskloop | parallel | * | |
| 2516 | // | taskloop | for | + | |
| 2517 | // | taskloop | for simd | + | |
| 2518 | // | taskloop | master | + | |
| 2519 | // | taskloop | critical | * | |
| 2520 | // | taskloop | simd | * | |
| 2521 | // | taskloop | sections | + | |
| 2522 | // | taskloop | section | + | |
| 2523 | // | taskloop | single | + | |
| 2524 | // | taskloop | parallel for | * | |
| 2525 | // | taskloop |parallel for simd| * | |
| 2526 | // | taskloop |parallel sections| * | |
| 2527 | // | taskloop | task | * | |
| 2528 | // | taskloop | taskyield | * | |
| 2529 | // | taskloop | barrier | + | |
| 2530 | // | taskloop | taskwait | * | |
| 2531 | // | taskloop | taskgroup | * | |
| 2532 | // | taskloop | flush | * | |
| 2533 | // | taskloop | ordered | + | |
| 2534 | // | taskloop | atomic | * | |
| 2535 | // | taskloop | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2536 | // | taskloop | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2537 | // | taskloop | target parallel | * | |
| 2538 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2539 | // | taskloop | target enter | * | |
| 2540 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2541 | // | taskloop | target exit | * | |
| 2542 | // | | data | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2543 | // | taskloop | teams | + | |
| 2544 | // | taskloop | cancellation | | |
| 2545 | // | | point | | |
| 2546 | // | taskloop | cancel | | |
| 2547 | // | taskloop | taskloop | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2548 | // | taskloop | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2549 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2550 | // | taskloop simd | parallel | | |
| 2551 | // | taskloop simd | for | | |
| 2552 | // | taskloop simd | for simd | | |
| 2553 | // | taskloop simd | master | | |
| 2554 | // | taskloop simd | critical | | |
Alexey Bataev | 1f09221 | 2016-02-02 04:59:52 +0000 | [diff] [blame] | 2555 | // | taskloop simd | simd | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2556 | // | taskloop simd | sections | | |
| 2557 | // | taskloop simd | section | | |
| 2558 | // | taskloop simd | single | | |
| 2559 | // | taskloop simd | parallel for | | |
| 2560 | // | taskloop simd |parallel for simd| | |
| 2561 | // | taskloop simd |parallel sections| | |
| 2562 | // | taskloop simd | task | | |
| 2563 | // | taskloop simd | taskyield | | |
| 2564 | // | taskloop simd | barrier | | |
| 2565 | // | taskloop simd | taskwait | | |
| 2566 | // | taskloop simd | taskgroup | | |
| 2567 | // | taskloop simd | flush | | |
| 2568 | // | taskloop simd | ordered | + (with simd clause) | |
| 2569 | // | taskloop simd | atomic | | |
| 2570 | // | taskloop simd | target | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2571 | // | taskloop simd | target parallel | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2572 | // | taskloop simd | target parallel | | |
| 2573 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2574 | // | taskloop simd | target enter | | |
| 2575 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2576 | // | taskloop simd | target exit | | |
| 2577 | // | | data | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2578 | // | taskloop simd | teams | | |
| 2579 | // | taskloop simd | cancellation | | |
| 2580 | // | | point | | |
| 2581 | // | taskloop simd | cancel | | |
| 2582 | // | taskloop simd | taskloop | | |
| 2583 | // | taskloop simd | taskloop simd | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2584 | // | taskloop simd | distribute | | |
| 2585 | // +------------------+-----------------+------------------------------------+ |
| 2586 | // | distribute | parallel | * | |
| 2587 | // | distribute | for | * | |
| 2588 | // | distribute | for simd | * | |
| 2589 | // | distribute | master | * | |
| 2590 | // | distribute | critical | * | |
| 2591 | // | distribute | simd | * | |
| 2592 | // | distribute | sections | * | |
| 2593 | // | distribute | section | * | |
| 2594 | // | distribute | single | * | |
| 2595 | // | distribute | parallel for | * | |
| 2596 | // | distribute |parallel for simd| * | |
| 2597 | // | distribute |parallel sections| * | |
| 2598 | // | distribute | task | * | |
| 2599 | // | distribute | taskyield | * | |
| 2600 | // | distribute | barrier | * | |
| 2601 | // | distribute | taskwait | * | |
| 2602 | // | distribute | taskgroup | * | |
| 2603 | // | distribute | flush | * | |
| 2604 | // | distribute | ordered | + | |
| 2605 | // | distribute | atomic | * | |
| 2606 | // | distribute | target | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2607 | // | distribute | target parallel | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2608 | // | distribute | target parallel | | |
| 2609 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2610 | // | distribute | target enter | | |
| 2611 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2612 | // | distribute | target exit | | |
| 2613 | // | | data | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2614 | // | distribute | teams | | |
| 2615 | // | distribute | cancellation | + | |
| 2616 | // | | point | | |
| 2617 | // | distribute | cancel | + | |
| 2618 | // | distribute | taskloop | * | |
| 2619 | // | distribute | taskloop simd | * | |
| 2620 | // | distribute | distribute | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2621 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2622 | if (Stack->getCurScope()) { |
| 2623 | auto ParentRegion = Stack->getParentDirective(); |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2624 | auto OffendingRegion = ParentRegion; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2625 | bool NestingProhibited = false; |
| 2626 | bool CloseNesting = true; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2627 | enum { |
| 2628 | NoRecommend, |
| 2629 | ShouldBeInParallelRegion, |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2630 | ShouldBeInOrderedRegion, |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2631 | ShouldBeInTargetRegion, |
| 2632 | ShouldBeInTeamsRegion |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2633 | } Recommend = NoRecommend; |
Alexey Bataev | 1f09221 | 2016-02-02 04:59:52 +0000 | [diff] [blame] | 2634 | if (isOpenMPSimdDirective(ParentRegion) && CurrentRegion != OMPD_ordered && |
| 2635 | CurrentRegion != OMPD_simd) { |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2636 | // OpenMP [2.16, Nesting of Regions] |
| 2637 | // OpenMP constructs may not be nested inside a simd region. |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2638 | // OpenMP [2.8.1,simd Construct, Restrictions] |
| 2639 | // An ordered construct with the simd clause is the only OpenMP construct |
| 2640 | // that can appear in the simd region. |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2641 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region_simd); |
| 2642 | return true; |
| 2643 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2644 | if (ParentRegion == OMPD_atomic) { |
| 2645 | // OpenMP [2.16, Nesting of Regions] |
| 2646 | // OpenMP constructs may not be nested inside an atomic region. |
| 2647 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region_atomic); |
| 2648 | return true; |
| 2649 | } |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2650 | if (CurrentRegion == OMPD_section) { |
| 2651 | // OpenMP [2.7.2, sections Construct, Restrictions] |
| 2652 | // Orphaned section directives are prohibited. That is, the section |
| 2653 | // directives must appear within the sections construct and must not be |
| 2654 | // encountered elsewhere in the sections region. |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2655 | if (ParentRegion != OMPD_sections && |
| 2656 | ParentRegion != OMPD_parallel_sections) { |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2657 | SemaRef.Diag(StartLoc, diag::err_omp_orphaned_section_directive) |
| 2658 | << (ParentRegion != OMPD_unknown) |
| 2659 | << getOpenMPDirectiveName(ParentRegion); |
| 2660 | return true; |
| 2661 | } |
| 2662 | return false; |
| 2663 | } |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2664 | // Allow some constructs to be orphaned (they could be used in functions, |
| 2665 | // called from OpenMP regions with the required preconditions). |
| 2666 | if (ParentRegion == OMPD_unknown) |
| 2667 | return false; |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2668 | if (CurrentRegion == OMPD_cancellation_point || |
| 2669 | CurrentRegion == OMPD_cancel) { |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2670 | // OpenMP [2.16, Nesting of Regions] |
| 2671 | // A cancellation point construct for which construct-type-clause is |
| 2672 | // taskgroup must be nested inside a task construct. A cancellation |
| 2673 | // point construct for which construct-type-clause is not taskgroup must |
| 2674 | // be closely nested inside an OpenMP construct that matches the type |
| 2675 | // specified in construct-type-clause. |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2676 | // A cancel construct for which construct-type-clause is taskgroup must be |
| 2677 | // nested inside a task construct. A cancel construct for which |
| 2678 | // construct-type-clause is not taskgroup must be closely nested inside an |
| 2679 | // OpenMP construct that matches the type specified in |
| 2680 | // construct-type-clause. |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2681 | NestingProhibited = |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2682 | !((CancelRegion == OMPD_parallel && |
| 2683 | (ParentRegion == OMPD_parallel || |
| 2684 | ParentRegion == OMPD_target_parallel)) || |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 2685 | (CancelRegion == OMPD_for && |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2686 | (ParentRegion == OMPD_for || ParentRegion == OMPD_parallel_for || |
| 2687 | ParentRegion == OMPD_target_parallel_for)) || |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2688 | (CancelRegion == OMPD_taskgroup && ParentRegion == OMPD_task) || |
| 2689 | (CancelRegion == OMPD_sections && |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 2690 | (ParentRegion == OMPD_section || ParentRegion == OMPD_sections || |
| 2691 | ParentRegion == OMPD_parallel_sections))); |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2692 | } else if (CurrentRegion == OMPD_master) { |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2693 | // OpenMP [2.16, Nesting of Regions] |
| 2694 | // A master region may not be closely nested inside a worksharing, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2695 | // atomic, or explicit task region. |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2696 | NestingProhibited = isOpenMPWorksharingDirective(ParentRegion) || |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2697 | ParentRegion == OMPD_task || |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2698 | isOpenMPTaskLoopDirective(ParentRegion); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2699 | } else if (CurrentRegion == OMPD_critical && CurrentName.getName()) { |
| 2700 | // OpenMP [2.16, Nesting of Regions] |
| 2701 | // A critical region may not be nested (closely or otherwise) inside a |
| 2702 | // critical region with the same name. Note that this restriction is not |
| 2703 | // sufficient to prevent deadlock. |
| 2704 | SourceLocation PreviousCriticalLoc; |
| 2705 | bool DeadLock = |
| 2706 | Stack->hasDirective([CurrentName, &PreviousCriticalLoc]( |
| 2707 | OpenMPDirectiveKind K, |
| 2708 | const DeclarationNameInfo &DNI, |
| 2709 | SourceLocation Loc) |
| 2710 | ->bool { |
| 2711 | if (K == OMPD_critical && |
| 2712 | DNI.getName() == CurrentName.getName()) { |
| 2713 | PreviousCriticalLoc = Loc; |
| 2714 | return true; |
| 2715 | } else |
| 2716 | return false; |
| 2717 | }, |
| 2718 | false /* skip top directive */); |
| 2719 | if (DeadLock) { |
| 2720 | SemaRef.Diag(StartLoc, |
| 2721 | diag::err_omp_prohibited_region_critical_same_name) |
| 2722 | << CurrentName.getName(); |
| 2723 | if (PreviousCriticalLoc.isValid()) |
| 2724 | SemaRef.Diag(PreviousCriticalLoc, |
| 2725 | diag::note_omp_previous_critical_region); |
| 2726 | return true; |
| 2727 | } |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2728 | } else if (CurrentRegion == OMPD_barrier) { |
| 2729 | // OpenMP [2.16, Nesting of Regions] |
| 2730 | // A barrier region may not be closely nested inside a worksharing, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2731 | // explicit task, critical, ordered, atomic, or master region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2732 | NestingProhibited = |
| 2733 | isOpenMPWorksharingDirective(ParentRegion) || |
| 2734 | ParentRegion == OMPD_task || ParentRegion == OMPD_master || |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2735 | ParentRegion == OMPD_critical || ParentRegion == OMPD_ordered || |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2736 | isOpenMPTaskLoopDirective(ParentRegion); |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2737 | } else if (isOpenMPWorksharingDirective(CurrentRegion) && |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2738 | !isOpenMPParallelDirective(CurrentRegion)) { |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2739 | // OpenMP [2.16, Nesting of Regions] |
| 2740 | // A worksharing region may not be closely nested inside a worksharing, |
| 2741 | // explicit task, critical, ordered, atomic, or master region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2742 | NestingProhibited = |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2743 | isOpenMPWorksharingDirective(ParentRegion) || |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2744 | ParentRegion == OMPD_task || ParentRegion == OMPD_master || |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2745 | ParentRegion == OMPD_critical || ParentRegion == OMPD_ordered || |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2746 | isOpenMPTaskLoopDirective(ParentRegion); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2747 | Recommend = ShouldBeInParallelRegion; |
| 2748 | } else if (CurrentRegion == OMPD_ordered) { |
| 2749 | // OpenMP [2.16, Nesting of Regions] |
| 2750 | // An ordered region may not be closely nested inside a critical, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2751 | // atomic, or explicit task region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2752 | // An ordered region must be closely nested inside a loop region (or |
| 2753 | // parallel loop region) with an ordered clause. |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2754 | // OpenMP [2.8.1,simd Construct, Restrictions] |
| 2755 | // An ordered construct with the simd clause is the only OpenMP construct |
| 2756 | // that can appear in the simd region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2757 | NestingProhibited = ParentRegion == OMPD_critical || |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2758 | ParentRegion == OMPD_task || |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2759 | isOpenMPTaskLoopDirective(ParentRegion) || |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2760 | !(isOpenMPSimdDirective(ParentRegion) || |
| 2761 | Stack->isParentOrderedRegion()); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2762 | Recommend = ShouldBeInOrderedRegion; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2763 | } else if (isOpenMPTeamsDirective(CurrentRegion)) { |
| 2764 | // OpenMP [2.16, Nesting of Regions] |
| 2765 | // If specified, a teams construct must be contained within a target |
| 2766 | // construct. |
| 2767 | NestingProhibited = ParentRegion != OMPD_target; |
| 2768 | Recommend = ShouldBeInTargetRegion; |
| 2769 | Stack->setParentTeamsRegionLoc(Stack->getConstructLoc()); |
| 2770 | } |
| 2771 | if (!NestingProhibited && isOpenMPTeamsDirective(ParentRegion)) { |
| 2772 | // OpenMP [2.16, Nesting of Regions] |
| 2773 | // distribute, parallel, parallel sections, parallel workshare, and the |
| 2774 | // parallel loop and parallel loop SIMD constructs are the only OpenMP |
| 2775 | // constructs that can be closely nested in the teams region. |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2776 | NestingProhibited = !isOpenMPParallelDirective(CurrentRegion) && |
| 2777 | !isOpenMPDistributeDirective(CurrentRegion); |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2778 | Recommend = ShouldBeInParallelRegion; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2779 | } |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2780 | if (!NestingProhibited && isOpenMPDistributeDirective(CurrentRegion)) { |
| 2781 | // OpenMP 4.5 [2.17 Nesting of Regions] |
| 2782 | // The region associated with the distribute construct must be strictly |
| 2783 | // nested inside a teams region |
| 2784 | NestingProhibited = !isOpenMPTeamsDirective(ParentRegion); |
| 2785 | Recommend = ShouldBeInTeamsRegion; |
| 2786 | } |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2787 | if (!NestingProhibited && |
| 2788 | (isOpenMPTargetExecutionDirective(CurrentRegion) || |
| 2789 | isOpenMPTargetDataManagementDirective(CurrentRegion))) { |
| 2790 | // OpenMP 4.5 [2.17 Nesting of Regions] |
| 2791 | // If a target, target update, target data, target enter data, or |
| 2792 | // target exit data construct is encountered during execution of a |
| 2793 | // target region, the behavior is unspecified. |
| 2794 | NestingProhibited = Stack->hasDirective( |
| 2795 | [&OffendingRegion](OpenMPDirectiveKind K, |
| 2796 | const DeclarationNameInfo &DNI, |
| 2797 | SourceLocation Loc) -> bool { |
| 2798 | if (isOpenMPTargetExecutionDirective(K)) { |
| 2799 | OffendingRegion = K; |
| 2800 | return true; |
| 2801 | } else |
| 2802 | return false; |
| 2803 | }, |
| 2804 | false /* don't skip top directive */); |
| 2805 | CloseNesting = false; |
| 2806 | } |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2807 | if (NestingProhibited) { |
| 2808 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region) |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2809 | << CloseNesting << getOpenMPDirectiveName(OffendingRegion) |
| 2810 | << Recommend << getOpenMPDirectiveName(CurrentRegion); |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2811 | return true; |
| 2812 | } |
| 2813 | } |
| 2814 | return false; |
| 2815 | } |
| 2816 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2817 | static bool checkIfClauses(Sema &S, OpenMPDirectiveKind Kind, |
| 2818 | ArrayRef<OMPClause *> Clauses, |
| 2819 | ArrayRef<OpenMPDirectiveKind> AllowedNameModifiers) { |
| 2820 | bool ErrorFound = false; |
| 2821 | unsigned NamedModifiersNumber = 0; |
| 2822 | SmallVector<const OMPIfClause *, OMPC_unknown + 1> FoundNameModifiers( |
| 2823 | OMPD_unknown + 1); |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2824 | SmallVector<SourceLocation, 4> NameModifierLoc; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2825 | for (const auto *C : Clauses) { |
| 2826 | if (const auto *IC = dyn_cast_or_null<OMPIfClause>(C)) { |
| 2827 | // At most one if clause without a directive-name-modifier can appear on |
| 2828 | // the directive. |
| 2829 | OpenMPDirectiveKind CurNM = IC->getNameModifier(); |
| 2830 | if (FoundNameModifiers[CurNM]) { |
| 2831 | S.Diag(C->getLocStart(), diag::err_omp_more_one_clause) |
| 2832 | << getOpenMPDirectiveName(Kind) << getOpenMPClauseName(OMPC_if) |
| 2833 | << (CurNM != OMPD_unknown) << getOpenMPDirectiveName(CurNM); |
| 2834 | ErrorFound = true; |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2835 | } else if (CurNM != OMPD_unknown) { |
| 2836 | NameModifierLoc.push_back(IC->getNameModifierLoc()); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2837 | ++NamedModifiersNumber; |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2838 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2839 | FoundNameModifiers[CurNM] = IC; |
| 2840 | if (CurNM == OMPD_unknown) |
| 2841 | continue; |
| 2842 | // Check if the specified name modifier is allowed for the current |
| 2843 | // directive. |
| 2844 | // At most one if clause with the particular directive-name-modifier can |
| 2845 | // appear on the directive. |
| 2846 | bool MatchFound = false; |
| 2847 | for (auto NM : AllowedNameModifiers) { |
| 2848 | if (CurNM == NM) { |
| 2849 | MatchFound = true; |
| 2850 | break; |
| 2851 | } |
| 2852 | } |
| 2853 | if (!MatchFound) { |
| 2854 | S.Diag(IC->getNameModifierLoc(), |
| 2855 | diag::err_omp_wrong_if_directive_name_modifier) |
| 2856 | << getOpenMPDirectiveName(CurNM) << getOpenMPDirectiveName(Kind); |
| 2857 | ErrorFound = true; |
| 2858 | } |
| 2859 | } |
| 2860 | } |
| 2861 | // If any if clause on the directive includes a directive-name-modifier then |
| 2862 | // all if clauses on the directive must include a directive-name-modifier. |
| 2863 | if (FoundNameModifiers[OMPD_unknown] && NamedModifiersNumber > 0) { |
| 2864 | if (NamedModifiersNumber == AllowedNameModifiers.size()) { |
| 2865 | S.Diag(FoundNameModifiers[OMPD_unknown]->getLocStart(), |
| 2866 | diag::err_omp_no_more_if_clause); |
| 2867 | } else { |
| 2868 | std::string Values; |
| 2869 | std::string Sep(", "); |
| 2870 | unsigned AllowedCnt = 0; |
| 2871 | unsigned TotalAllowedNum = |
| 2872 | AllowedNameModifiers.size() - NamedModifiersNumber; |
| 2873 | for (unsigned Cnt = 0, End = AllowedNameModifiers.size(); Cnt < End; |
| 2874 | ++Cnt) { |
| 2875 | OpenMPDirectiveKind NM = AllowedNameModifiers[Cnt]; |
| 2876 | if (!FoundNameModifiers[NM]) { |
| 2877 | Values += "'"; |
| 2878 | Values += getOpenMPDirectiveName(NM); |
| 2879 | Values += "'"; |
| 2880 | if (AllowedCnt + 2 == TotalAllowedNum) |
| 2881 | Values += " or "; |
| 2882 | else if (AllowedCnt + 1 != TotalAllowedNum) |
| 2883 | Values += Sep; |
| 2884 | ++AllowedCnt; |
| 2885 | } |
| 2886 | } |
| 2887 | S.Diag(FoundNameModifiers[OMPD_unknown]->getCondition()->getLocStart(), |
| 2888 | diag::err_omp_unnamed_if_clause) |
| 2889 | << (TotalAllowedNum > 1) << Values; |
| 2890 | } |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2891 | for (auto Loc : NameModifierLoc) { |
| 2892 | S.Diag(Loc, diag::note_omp_previous_named_if_clause); |
| 2893 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2894 | ErrorFound = true; |
| 2895 | } |
| 2896 | return ErrorFound; |
| 2897 | } |
| 2898 | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2899 | StmtResult Sema::ActOnOpenMPExecutableDirective( |
| 2900 | OpenMPDirectiveKind Kind, const DeclarationNameInfo &DirName, |
| 2901 | OpenMPDirectiveKind CancelRegion, ArrayRef<OMPClause *> Clauses, |
| 2902 | Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2903 | StmtResult Res = StmtError(); |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2904 | if (CheckNestingOfRegions(*this, DSAStack, Kind, DirName, CancelRegion, |
| 2905 | StartLoc)) |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2906 | return StmtError(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2907 | |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2908 | llvm::SmallVector<OMPClause *, 8> ClausesWithImplicit; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 2909 | llvm::DenseMap<ValueDecl *, Expr *> VarsWithInheritedDSA; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2910 | bool ErrorFound = false; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2911 | ClausesWithImplicit.append(Clauses.begin(), Clauses.end()); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2912 | if (AStmt) { |
| 2913 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 2914 | |
| 2915 | // Check default data sharing attributes for referenced variables. |
| 2916 | DSAAttrChecker DSAChecker(DSAStack, *this, cast<CapturedStmt>(AStmt)); |
| 2917 | DSAChecker.Visit(cast<CapturedStmt>(AStmt)->getCapturedStmt()); |
| 2918 | if (DSAChecker.isErrorFound()) |
| 2919 | return StmtError(); |
| 2920 | // Generate list of implicitly defined firstprivate variables. |
| 2921 | VarsWithInheritedDSA = DSAChecker.getVarsWithInheritedDSA(); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2922 | |
| 2923 | if (!DSAChecker.getImplicitFirstprivate().empty()) { |
| 2924 | if (OMPClause *Implicit = ActOnOpenMPFirstprivateClause( |
| 2925 | DSAChecker.getImplicitFirstprivate(), SourceLocation(), |
| 2926 | SourceLocation(), SourceLocation())) { |
| 2927 | ClausesWithImplicit.push_back(Implicit); |
| 2928 | ErrorFound = cast<OMPFirstprivateClause>(Implicit)->varlist_size() != |
| 2929 | DSAChecker.getImplicitFirstprivate().size(); |
| 2930 | } else |
| 2931 | ErrorFound = true; |
| 2932 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2933 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2934 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2935 | llvm::SmallVector<OpenMPDirectiveKind, 4> AllowedNameModifiers; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2936 | switch (Kind) { |
| 2937 | case OMPD_parallel: |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2938 | Res = ActOnOpenMPParallelDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2939 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2940 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2941 | break; |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 2942 | case OMPD_simd: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2943 | Res = ActOnOpenMPSimdDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc, |
| 2944 | VarsWithInheritedDSA); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 2945 | break; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2946 | case OMPD_for: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2947 | Res = ActOnOpenMPForDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc, |
| 2948 | VarsWithInheritedDSA); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2949 | break; |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2950 | case OMPD_for_simd: |
| 2951 | Res = ActOnOpenMPForSimdDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2952 | EndLoc, VarsWithInheritedDSA); |
| 2953 | break; |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 2954 | case OMPD_sections: |
| 2955 | Res = ActOnOpenMPSectionsDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2956 | EndLoc); |
| 2957 | break; |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2958 | case OMPD_section: |
| 2959 | assert(ClausesWithImplicit.empty() && |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2960 | "No clauses are allowed for 'omp section' directive"); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2961 | Res = ActOnOpenMPSectionDirective(AStmt, StartLoc, EndLoc); |
| 2962 | break; |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 2963 | case OMPD_single: |
| 2964 | Res = ActOnOpenMPSingleDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2965 | EndLoc); |
| 2966 | break; |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2967 | case OMPD_master: |
| 2968 | assert(ClausesWithImplicit.empty() && |
| 2969 | "No clauses are allowed for 'omp master' directive"); |
| 2970 | Res = ActOnOpenMPMasterDirective(AStmt, StartLoc, EndLoc); |
| 2971 | break; |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2972 | case OMPD_critical: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 2973 | Res = ActOnOpenMPCriticalDirective(DirName, ClausesWithImplicit, AStmt, |
| 2974 | StartLoc, EndLoc); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2975 | break; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2976 | case OMPD_parallel_for: |
| 2977 | Res = ActOnOpenMPParallelForDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2978 | EndLoc, VarsWithInheritedDSA); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2979 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2980 | break; |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2981 | case OMPD_parallel_for_simd: |
| 2982 | Res = ActOnOpenMPParallelForSimdDirective( |
| 2983 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2984 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2985 | break; |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2986 | case OMPD_parallel_sections: |
| 2987 | Res = ActOnOpenMPParallelSectionsDirective(ClausesWithImplicit, AStmt, |
| 2988 | StartLoc, EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2989 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2990 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2991 | case OMPD_task: |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2992 | Res = |
| 2993 | ActOnOpenMPTaskDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2994 | AllowedNameModifiers.push_back(OMPD_task); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2995 | break; |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2996 | case OMPD_taskyield: |
| 2997 | assert(ClausesWithImplicit.empty() && |
| 2998 | "No clauses are allowed for 'omp taskyield' directive"); |
| 2999 | assert(AStmt == nullptr && |
| 3000 | "No associated statement allowed for 'omp taskyield' directive"); |
| 3001 | Res = ActOnOpenMPTaskyieldDirective(StartLoc, EndLoc); |
| 3002 | break; |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 3003 | case OMPD_barrier: |
| 3004 | assert(ClausesWithImplicit.empty() && |
| 3005 | "No clauses are allowed for 'omp barrier' directive"); |
| 3006 | assert(AStmt == nullptr && |
| 3007 | "No associated statement allowed for 'omp barrier' directive"); |
| 3008 | Res = ActOnOpenMPBarrierDirective(StartLoc, EndLoc); |
| 3009 | break; |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 3010 | case OMPD_taskwait: |
| 3011 | assert(ClausesWithImplicit.empty() && |
| 3012 | "No clauses are allowed for 'omp taskwait' directive"); |
| 3013 | assert(AStmt == nullptr && |
| 3014 | "No associated statement allowed for 'omp taskwait' directive"); |
| 3015 | Res = ActOnOpenMPTaskwaitDirective(StartLoc, EndLoc); |
| 3016 | break; |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 3017 | case OMPD_taskgroup: |
| 3018 | assert(ClausesWithImplicit.empty() && |
| 3019 | "No clauses are allowed for 'omp taskgroup' directive"); |
| 3020 | Res = ActOnOpenMPTaskgroupDirective(AStmt, StartLoc, EndLoc); |
| 3021 | break; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 3022 | case OMPD_flush: |
| 3023 | assert(AStmt == nullptr && |
| 3024 | "No associated statement allowed for 'omp flush' directive"); |
| 3025 | Res = ActOnOpenMPFlushDirective(ClausesWithImplicit, StartLoc, EndLoc); |
| 3026 | break; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 3027 | case OMPD_ordered: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 3028 | Res = ActOnOpenMPOrderedDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3029 | EndLoc); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 3030 | break; |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 3031 | case OMPD_atomic: |
| 3032 | Res = ActOnOpenMPAtomicDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3033 | EndLoc); |
| 3034 | break; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 3035 | case OMPD_teams: |
| 3036 | Res = |
| 3037 | ActOnOpenMPTeamsDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); |
| 3038 | break; |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 3039 | case OMPD_target: |
| 3040 | Res = ActOnOpenMPTargetDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3041 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3042 | AllowedNameModifiers.push_back(OMPD_target); |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 3043 | break; |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 3044 | case OMPD_target_parallel: |
| 3045 | Res = ActOnOpenMPTargetParallelDirective(ClausesWithImplicit, AStmt, |
| 3046 | StartLoc, EndLoc); |
| 3047 | AllowedNameModifiers.push_back(OMPD_target); |
| 3048 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 3049 | break; |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 3050 | case OMPD_target_parallel_for: |
| 3051 | Res = ActOnOpenMPTargetParallelForDirective( |
| 3052 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 3053 | AllowedNameModifiers.push_back(OMPD_target); |
| 3054 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 3055 | break; |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 3056 | case OMPD_cancellation_point: |
| 3057 | assert(ClausesWithImplicit.empty() && |
| 3058 | "No clauses are allowed for 'omp cancellation point' directive"); |
| 3059 | assert(AStmt == nullptr && "No associated statement allowed for 'omp " |
| 3060 | "cancellation point' directive"); |
| 3061 | Res = ActOnOpenMPCancellationPointDirective(StartLoc, EndLoc, CancelRegion); |
| 3062 | break; |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 3063 | case OMPD_cancel: |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 3064 | assert(AStmt == nullptr && |
| 3065 | "No associated statement allowed for 'omp cancel' directive"); |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 3066 | Res = ActOnOpenMPCancelDirective(ClausesWithImplicit, StartLoc, EndLoc, |
| 3067 | CancelRegion); |
| 3068 | AllowedNameModifiers.push_back(OMPD_cancel); |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 3069 | break; |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 3070 | case OMPD_target_data: |
| 3071 | Res = ActOnOpenMPTargetDataDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3072 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3073 | AllowedNameModifiers.push_back(OMPD_target_data); |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 3074 | break; |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 3075 | case OMPD_target_enter_data: |
| 3076 | Res = ActOnOpenMPTargetEnterDataDirective(ClausesWithImplicit, StartLoc, |
| 3077 | EndLoc); |
| 3078 | AllowedNameModifiers.push_back(OMPD_target_enter_data); |
| 3079 | break; |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 3080 | case OMPD_target_exit_data: |
| 3081 | Res = ActOnOpenMPTargetExitDataDirective(ClausesWithImplicit, StartLoc, |
| 3082 | EndLoc); |
| 3083 | AllowedNameModifiers.push_back(OMPD_target_exit_data); |
| 3084 | break; |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 3085 | case OMPD_taskloop: |
| 3086 | Res = ActOnOpenMPTaskLoopDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3087 | EndLoc, VarsWithInheritedDSA); |
| 3088 | AllowedNameModifiers.push_back(OMPD_taskloop); |
| 3089 | break; |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 3090 | case OMPD_taskloop_simd: |
| 3091 | Res = ActOnOpenMPTaskLoopSimdDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3092 | EndLoc, VarsWithInheritedDSA); |
| 3093 | AllowedNameModifiers.push_back(OMPD_taskloop); |
| 3094 | break; |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 3095 | case OMPD_distribute: |
| 3096 | Res = ActOnOpenMPDistributeDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3097 | EndLoc, VarsWithInheritedDSA); |
| 3098 | break; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 3099 | case OMPD_threadprivate: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3100 | llvm_unreachable("OpenMP Directive is not allowed"); |
| 3101 | case OMPD_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3102 | llvm_unreachable("Unknown OpenMP directive"); |
| 3103 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 3104 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3105 | for (auto P : VarsWithInheritedDSA) { |
| 3106 | Diag(P.second->getExprLoc(), diag::err_omp_no_dsa_for_variable) |
| 3107 | << P.first << P.second->getSourceRange(); |
| 3108 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3109 | ErrorFound = !VarsWithInheritedDSA.empty() || ErrorFound; |
| 3110 | |
| 3111 | if (!AllowedNameModifiers.empty()) |
| 3112 | ErrorFound = checkIfClauses(*this, Kind, Clauses, AllowedNameModifiers) || |
| 3113 | ErrorFound; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3114 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 3115 | if (ErrorFound) |
| 3116 | return StmtError(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3117 | return Res; |
| 3118 | } |
| 3119 | |
| 3120 | StmtResult Sema::ActOnOpenMPParallelDirective(ArrayRef<OMPClause *> Clauses, |
| 3121 | Stmt *AStmt, |
| 3122 | SourceLocation StartLoc, |
| 3123 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3124 | if (!AStmt) |
| 3125 | return StmtError(); |
| 3126 | |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 3127 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 3128 | // 1.2.2 OpenMP Language Terminology |
| 3129 | // Structured block - An executable statement with a single entry at the |
| 3130 | // top and a single exit at the bottom. |
| 3131 | // The point of exit cannot be a branch out of the structured block. |
| 3132 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 3133 | CS->getCapturedDecl()->setNothrow(); |
| 3134 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3135 | getCurFunction()->setHasBranchProtectedScope(); |
| 3136 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 3137 | return OMPParallelDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 3138 | DSAStack->isCancelRegion()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3139 | } |
| 3140 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3141 | namespace { |
| 3142 | /// \brief Helper class for checking canonical form of the OpenMP loops and |
| 3143 | /// extracting iteration space of each loop in the loop nest, that will be used |
| 3144 | /// for IR generation. |
| 3145 | class OpenMPIterationSpaceChecker { |
| 3146 | /// \brief Reference to Sema. |
| 3147 | Sema &SemaRef; |
| 3148 | /// \brief A location for diagnostics (when there is no some better location). |
| 3149 | SourceLocation DefaultLoc; |
| 3150 | /// \brief A location for diagnostics (when increment is not compatible). |
| 3151 | SourceLocation ConditionLoc; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3152 | /// \brief A source location for referring to loop init later. |
| 3153 | SourceRange InitSrcRange; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3154 | /// \brief A source location for referring to condition later. |
| 3155 | SourceRange ConditionSrcRange; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3156 | /// \brief A source location for referring to increment later. |
| 3157 | SourceRange IncrementSrcRange; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3158 | /// \brief Loop variable. |
| 3159 | VarDecl *Var; |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3160 | /// \brief Reference to loop variable. |
| 3161 | DeclRefExpr *VarRef; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3162 | /// \brief Lower bound (initializer for the var). |
| 3163 | Expr *LB; |
| 3164 | /// \brief Upper bound. |
| 3165 | Expr *UB; |
| 3166 | /// \brief Loop step (increment). |
| 3167 | Expr *Step; |
| 3168 | /// \brief This flag is true when condition is one of: |
| 3169 | /// Var < UB |
| 3170 | /// Var <= UB |
| 3171 | /// UB > Var |
| 3172 | /// UB >= Var |
| 3173 | bool TestIsLessOp; |
| 3174 | /// \brief This flag is true when condition is strict ( < or > ). |
| 3175 | bool TestIsStrictOp; |
| 3176 | /// \brief This flag is true when step is subtracted on each iteration. |
| 3177 | bool SubtractStep; |
| 3178 | |
| 3179 | public: |
| 3180 | OpenMPIterationSpaceChecker(Sema &SemaRef, SourceLocation DefaultLoc) |
| 3181 | : SemaRef(SemaRef), DefaultLoc(DefaultLoc), ConditionLoc(DefaultLoc), |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3182 | InitSrcRange(SourceRange()), ConditionSrcRange(SourceRange()), |
| 3183 | IncrementSrcRange(SourceRange()), Var(nullptr), VarRef(nullptr), |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3184 | LB(nullptr), UB(nullptr), Step(nullptr), TestIsLessOp(false), |
| 3185 | TestIsStrictOp(false), SubtractStep(false) {} |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3186 | /// \brief Check init-expr for canonical loop form and save loop counter |
| 3187 | /// variable - #Var and its initialization value - #LB. |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3188 | bool CheckInit(Stmt *S, bool EmitDiags = true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3189 | /// \brief Check test-expr for canonical form, save upper-bound (#UB), flags |
| 3190 | /// for less/greater and for strict/non-strict comparison. |
| 3191 | bool CheckCond(Expr *S); |
| 3192 | /// \brief Check incr-expr for canonical loop form and return true if it |
| 3193 | /// does not conform, otherwise save loop step (#Step). |
| 3194 | bool CheckInc(Expr *S); |
| 3195 | /// \brief Return the loop counter variable. |
| 3196 | VarDecl *GetLoopVar() const { return Var; } |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3197 | /// \brief Return the reference expression to loop counter variable. |
| 3198 | DeclRefExpr *GetLoopVarRefExpr() const { return VarRef; } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3199 | /// \brief Source range of the loop init. |
| 3200 | SourceRange GetInitSrcRange() const { return InitSrcRange; } |
| 3201 | /// \brief Source range of the loop condition. |
| 3202 | SourceRange GetConditionSrcRange() const { return ConditionSrcRange; } |
| 3203 | /// \brief Source range of the loop increment. |
| 3204 | SourceRange GetIncrementSrcRange() const { return IncrementSrcRange; } |
| 3205 | /// \brief True if the step should be subtracted. |
| 3206 | bool ShouldSubtractStep() const { return SubtractStep; } |
| 3207 | /// \brief Build the expression to calculate the number of iterations. |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3208 | Expr *BuildNumIterations(Scope *S, const bool LimitedType) const; |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3209 | /// \brief Build the precondition expression for the loops. |
| 3210 | Expr *BuildPreCond(Scope *S, Expr *Cond) const; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3211 | /// \brief Build reference expression to the counter be used for codegen. |
| 3212 | Expr *BuildCounterVar() const; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3213 | /// \brief Build reference expression to the private counter be used for |
| 3214 | /// codegen. |
| 3215 | Expr *BuildPrivateCounterVar() const; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3216 | /// \brief Build initization of the counter be used for codegen. |
| 3217 | Expr *BuildCounterInit() const; |
| 3218 | /// \brief Build step of the counter be used for codegen. |
| 3219 | Expr *BuildCounterStep() const; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3220 | /// \brief Return true if any expression is dependent. |
| 3221 | bool Dependent() const; |
| 3222 | |
| 3223 | private: |
| 3224 | /// \brief Check the right-hand side of an assignment in the increment |
| 3225 | /// expression. |
| 3226 | bool CheckIncRHS(Expr *RHS); |
| 3227 | /// \brief Helper to set loop counter variable and its initializer. |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3228 | bool SetVarAndLB(VarDecl *NewVar, DeclRefExpr *NewVarRefExpr, Expr *NewLB); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3229 | /// \brief Helper to set upper bound. |
Craig Topper | e335f25 | 2015-10-04 04:53:55 +0000 | [diff] [blame] | 3230 | bool SetUB(Expr *NewUB, bool LessOp, bool StrictOp, SourceRange SR, |
Craig Topper | 9cd5e4f | 2015-09-21 01:23:32 +0000 | [diff] [blame] | 3231 | SourceLocation SL); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3232 | /// \brief Helper to set loop increment. |
| 3233 | bool SetStep(Expr *NewStep, bool Subtract); |
| 3234 | }; |
| 3235 | |
| 3236 | bool OpenMPIterationSpaceChecker::Dependent() const { |
| 3237 | if (!Var) { |
| 3238 | assert(!LB && !UB && !Step); |
| 3239 | return false; |
| 3240 | } |
| 3241 | return Var->getType()->isDependentType() || (LB && LB->isValueDependent()) || |
| 3242 | (UB && UB->isValueDependent()) || (Step && Step->isValueDependent()); |
| 3243 | } |
| 3244 | |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3245 | template <typename T> |
| 3246 | static T *getExprAsWritten(T *E) { |
| 3247 | if (auto *ExprTemp = dyn_cast<ExprWithCleanups>(E)) |
| 3248 | E = ExprTemp->getSubExpr(); |
| 3249 | |
| 3250 | if (auto *MTE = dyn_cast<MaterializeTemporaryExpr>(E)) |
| 3251 | E = MTE->GetTemporaryExpr(); |
| 3252 | |
| 3253 | while (auto *Binder = dyn_cast<CXXBindTemporaryExpr>(E)) |
| 3254 | E = Binder->getSubExpr(); |
| 3255 | |
| 3256 | if (auto *ICE = dyn_cast<ImplicitCastExpr>(E)) |
| 3257 | E = ICE->getSubExprAsWritten(); |
| 3258 | return E->IgnoreParens(); |
| 3259 | } |
| 3260 | |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3261 | bool OpenMPIterationSpaceChecker::SetVarAndLB(VarDecl *NewVar, |
| 3262 | DeclRefExpr *NewVarRefExpr, |
| 3263 | Expr *NewLB) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3264 | // State consistency checking to ensure correct usage. |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3265 | assert(Var == nullptr && LB == nullptr && VarRef == nullptr && |
| 3266 | UB == nullptr && Step == nullptr && !TestIsLessOp && !TestIsStrictOp); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3267 | if (!NewVar || !NewLB) |
| 3268 | return true; |
| 3269 | Var = NewVar; |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3270 | VarRef = NewVarRefExpr; |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3271 | if (auto *CE = dyn_cast_or_null<CXXConstructExpr>(NewLB)) |
| 3272 | if (const CXXConstructorDecl *Ctor = CE->getConstructor()) |
Alexey Bataev | 0d08a7f | 2015-07-16 04:19:43 +0000 | [diff] [blame] | 3273 | if ((Ctor->isCopyOrMoveConstructor() || |
| 3274 | Ctor->isConvertingConstructor(/*AllowExplicit=*/false)) && |
| 3275 | CE->getNumArgs() > 0 && CE->getArg(0) != nullptr) |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3276 | NewLB = CE->getArg(0)->IgnoreParenImpCasts(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3277 | LB = NewLB; |
| 3278 | return false; |
| 3279 | } |
| 3280 | |
| 3281 | bool OpenMPIterationSpaceChecker::SetUB(Expr *NewUB, bool LessOp, bool StrictOp, |
Craig Topper | e335f25 | 2015-10-04 04:53:55 +0000 | [diff] [blame] | 3282 | SourceRange SR, SourceLocation SL) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3283 | // State consistency checking to ensure correct usage. |
| 3284 | assert(Var != nullptr && LB != nullptr && UB == nullptr && Step == nullptr && |
| 3285 | !TestIsLessOp && !TestIsStrictOp); |
| 3286 | if (!NewUB) |
| 3287 | return true; |
| 3288 | UB = NewUB; |
| 3289 | TestIsLessOp = LessOp; |
| 3290 | TestIsStrictOp = StrictOp; |
| 3291 | ConditionSrcRange = SR; |
| 3292 | ConditionLoc = SL; |
| 3293 | return false; |
| 3294 | } |
| 3295 | |
| 3296 | bool OpenMPIterationSpaceChecker::SetStep(Expr *NewStep, bool Subtract) { |
| 3297 | // State consistency checking to ensure correct usage. |
| 3298 | assert(Var != nullptr && LB != nullptr && Step == nullptr); |
| 3299 | if (!NewStep) |
| 3300 | return true; |
| 3301 | if (!NewStep->isValueDependent()) { |
| 3302 | // Check that the step is integer expression. |
| 3303 | SourceLocation StepLoc = NewStep->getLocStart(); |
| 3304 | ExprResult Val = |
| 3305 | SemaRef.PerformOpenMPImplicitIntegerConversion(StepLoc, NewStep); |
| 3306 | if (Val.isInvalid()) |
| 3307 | return true; |
| 3308 | NewStep = Val.get(); |
| 3309 | |
| 3310 | // OpenMP [2.6, Canonical Loop Form, Restrictions] |
| 3311 | // If test-expr is of form var relational-op b and relational-op is < or |
| 3312 | // <= then incr-expr must cause var to increase on each iteration of the |
| 3313 | // loop. If test-expr is of form var relational-op b and relational-op is |
| 3314 | // > or >= then incr-expr must cause var to decrease on each iteration of |
| 3315 | // the loop. |
| 3316 | // If test-expr is of form b relational-op var and relational-op is < or |
| 3317 | // <= then incr-expr must cause var to decrease on each iteration of the |
| 3318 | // loop. If test-expr is of form b relational-op var and relational-op is |
| 3319 | // > or >= then incr-expr must cause var to increase on each iteration of |
| 3320 | // the loop. |
| 3321 | llvm::APSInt Result; |
| 3322 | bool IsConstant = NewStep->isIntegerConstantExpr(Result, SemaRef.Context); |
| 3323 | bool IsUnsigned = !NewStep->getType()->hasSignedIntegerRepresentation(); |
| 3324 | bool IsConstNeg = |
| 3325 | IsConstant && Result.isSigned() && (Subtract != Result.isNegative()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3326 | bool IsConstPos = |
| 3327 | IsConstant && Result.isSigned() && (Subtract == Result.isNegative()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3328 | bool IsConstZero = IsConstant && !Result.getBoolValue(); |
| 3329 | if (UB && (IsConstZero || |
| 3330 | (TestIsLessOp ? (IsConstNeg || (IsUnsigned && Subtract)) |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3331 | : (IsConstPos || (IsUnsigned && !Subtract))))) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3332 | SemaRef.Diag(NewStep->getExprLoc(), |
| 3333 | diag::err_omp_loop_incr_not_compatible) |
| 3334 | << Var << TestIsLessOp << NewStep->getSourceRange(); |
| 3335 | SemaRef.Diag(ConditionLoc, |
| 3336 | diag::note_omp_loop_cond_requres_compatible_incr) |
| 3337 | << TestIsLessOp << ConditionSrcRange; |
| 3338 | return true; |
| 3339 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3340 | if (TestIsLessOp == Subtract) { |
| 3341 | NewStep = SemaRef.CreateBuiltinUnaryOp(NewStep->getExprLoc(), UO_Minus, |
| 3342 | NewStep).get(); |
| 3343 | Subtract = !Subtract; |
| 3344 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3345 | } |
| 3346 | |
| 3347 | Step = NewStep; |
| 3348 | SubtractStep = Subtract; |
| 3349 | return false; |
| 3350 | } |
| 3351 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3352 | bool OpenMPIterationSpaceChecker::CheckInit(Stmt *S, bool EmitDiags) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3353 | // Check init-expr for canonical loop form and save loop counter |
| 3354 | // variable - #Var and its initialization value - #LB. |
| 3355 | // OpenMP [2.6] Canonical loop form. init-expr may be one of the following: |
| 3356 | // var = lb |
| 3357 | // integer-type var = lb |
| 3358 | // random-access-iterator-type var = lb |
| 3359 | // pointer-type var = lb |
| 3360 | // |
| 3361 | if (!S) { |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3362 | if (EmitDiags) { |
| 3363 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_init); |
| 3364 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3365 | return true; |
| 3366 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3367 | InitSrcRange = S->getSourceRange(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3368 | if (Expr *E = dyn_cast<Expr>(S)) |
| 3369 | S = E->IgnoreParens(); |
| 3370 | if (auto BO = dyn_cast<BinaryOperator>(S)) { |
| 3371 | if (BO->getOpcode() == BO_Assign) |
| 3372 | if (auto DRE = dyn_cast<DeclRefExpr>(BO->getLHS()->IgnoreParens())) |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3373 | return SetVarAndLB(dyn_cast<VarDecl>(DRE->getDecl()), DRE, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3374 | BO->getRHS()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3375 | } else if (auto DS = dyn_cast<DeclStmt>(S)) { |
| 3376 | if (DS->isSingleDecl()) { |
| 3377 | if (auto Var = dyn_cast_or_null<VarDecl>(DS->getSingleDecl())) { |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3378 | if (Var->hasInit() && !Var->getType()->isReferenceType()) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3379 | // Accept non-canonical init form here but emit ext. warning. |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3380 | if (Var->getInitStyle() != VarDecl::CInit && EmitDiags) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3381 | SemaRef.Diag(S->getLocStart(), |
| 3382 | diag::ext_omp_loop_not_canonical_init) |
| 3383 | << S->getSourceRange(); |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3384 | return SetVarAndLB(Var, nullptr, Var->getInit()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3385 | } |
| 3386 | } |
| 3387 | } |
| 3388 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) |
| 3389 | if (CE->getOperator() == OO_Equal) |
| 3390 | if (auto DRE = dyn_cast<DeclRefExpr>(CE->getArg(0))) |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3391 | return SetVarAndLB(dyn_cast<VarDecl>(DRE->getDecl()), DRE, |
| 3392 | CE->getArg(1)); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3393 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3394 | if (EmitDiags) { |
| 3395 | SemaRef.Diag(S->getLocStart(), diag::err_omp_loop_not_canonical_init) |
| 3396 | << S->getSourceRange(); |
| 3397 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3398 | return true; |
| 3399 | } |
| 3400 | |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 3401 | /// \brief Ignore parenthesizes, implicit casts, copy constructor and return the |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3402 | /// variable (which may be the loop variable) if possible. |
| 3403 | static const VarDecl *GetInitVarDecl(const Expr *E) { |
| 3404 | if (!E) |
Craig Topper | 4b56692 | 2014-06-09 02:04:02 +0000 | [diff] [blame] | 3405 | return nullptr; |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3406 | E = getExprAsWritten(E); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3407 | if (auto *CE = dyn_cast_or_null<CXXConstructExpr>(E)) |
| 3408 | if (const CXXConstructorDecl *Ctor = CE->getConstructor()) |
Alexey Bataev | 0d08a7f | 2015-07-16 04:19:43 +0000 | [diff] [blame] | 3409 | if ((Ctor->isCopyOrMoveConstructor() || |
| 3410 | Ctor->isConvertingConstructor(/*AllowExplicit=*/false)) && |
| 3411 | CE->getNumArgs() > 0 && CE->getArg(0) != nullptr) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3412 | E = CE->getArg(0)->IgnoreParenImpCasts(); |
| 3413 | auto DRE = dyn_cast_or_null<DeclRefExpr>(E); |
| 3414 | if (!DRE) |
| 3415 | return nullptr; |
| 3416 | return dyn_cast<VarDecl>(DRE->getDecl()); |
| 3417 | } |
| 3418 | |
| 3419 | bool OpenMPIterationSpaceChecker::CheckCond(Expr *S) { |
| 3420 | // Check test-expr for canonical form, save upper-bound UB, flags for |
| 3421 | // less/greater and for strict/non-strict comparison. |
| 3422 | // OpenMP [2.6] Canonical loop form. Test-expr may be one of the following: |
| 3423 | // var relational-op b |
| 3424 | // b relational-op var |
| 3425 | // |
| 3426 | if (!S) { |
| 3427 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_cond) << Var; |
| 3428 | return true; |
| 3429 | } |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3430 | S = getExprAsWritten(S); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3431 | SourceLocation CondLoc = S->getLocStart(); |
| 3432 | if (auto BO = dyn_cast<BinaryOperator>(S)) { |
| 3433 | if (BO->isRelationalOp()) { |
| 3434 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 3435 | return SetUB(BO->getRHS(), |
| 3436 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_LE), |
| 3437 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_GT), |
| 3438 | BO->getSourceRange(), BO->getOperatorLoc()); |
| 3439 | if (GetInitVarDecl(BO->getRHS()) == Var) |
| 3440 | return SetUB(BO->getLHS(), |
| 3441 | (BO->getOpcode() == BO_GT || BO->getOpcode() == BO_GE), |
| 3442 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_GT), |
| 3443 | BO->getSourceRange(), BO->getOperatorLoc()); |
| 3444 | } |
| 3445 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
| 3446 | if (CE->getNumArgs() == 2) { |
| 3447 | auto Op = CE->getOperator(); |
| 3448 | switch (Op) { |
| 3449 | case OO_Greater: |
| 3450 | case OO_GreaterEqual: |
| 3451 | case OO_Less: |
| 3452 | case OO_LessEqual: |
| 3453 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 3454 | return SetUB(CE->getArg(1), Op == OO_Less || Op == OO_LessEqual, |
| 3455 | Op == OO_Less || Op == OO_Greater, CE->getSourceRange(), |
| 3456 | CE->getOperatorLoc()); |
| 3457 | if (GetInitVarDecl(CE->getArg(1)) == Var) |
| 3458 | return SetUB(CE->getArg(0), Op == OO_Greater || Op == OO_GreaterEqual, |
| 3459 | Op == OO_Less || Op == OO_Greater, CE->getSourceRange(), |
| 3460 | CE->getOperatorLoc()); |
| 3461 | break; |
| 3462 | default: |
| 3463 | break; |
| 3464 | } |
| 3465 | } |
| 3466 | } |
| 3467 | SemaRef.Diag(CondLoc, diag::err_omp_loop_not_canonical_cond) |
| 3468 | << S->getSourceRange() << Var; |
| 3469 | return true; |
| 3470 | } |
| 3471 | |
| 3472 | bool OpenMPIterationSpaceChecker::CheckIncRHS(Expr *RHS) { |
| 3473 | // RHS of canonical loop form increment can be: |
| 3474 | // var + incr |
| 3475 | // incr + var |
| 3476 | // var - incr |
| 3477 | // |
| 3478 | RHS = RHS->IgnoreParenImpCasts(); |
| 3479 | if (auto BO = dyn_cast<BinaryOperator>(RHS)) { |
| 3480 | if (BO->isAdditiveOp()) { |
| 3481 | bool IsAdd = BO->getOpcode() == BO_Add; |
| 3482 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 3483 | return SetStep(BO->getRHS(), !IsAdd); |
| 3484 | if (IsAdd && GetInitVarDecl(BO->getRHS()) == Var) |
| 3485 | return SetStep(BO->getLHS(), false); |
| 3486 | } |
| 3487 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(RHS)) { |
| 3488 | bool IsAdd = CE->getOperator() == OO_Plus; |
| 3489 | if ((IsAdd || CE->getOperator() == OO_Minus) && CE->getNumArgs() == 2) { |
| 3490 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 3491 | return SetStep(CE->getArg(1), !IsAdd); |
| 3492 | if (IsAdd && GetInitVarDecl(CE->getArg(1)) == Var) |
| 3493 | return SetStep(CE->getArg(0), false); |
| 3494 | } |
| 3495 | } |
| 3496 | SemaRef.Diag(RHS->getLocStart(), diag::err_omp_loop_not_canonical_incr) |
| 3497 | << RHS->getSourceRange() << Var; |
| 3498 | return true; |
| 3499 | } |
| 3500 | |
| 3501 | bool OpenMPIterationSpaceChecker::CheckInc(Expr *S) { |
| 3502 | // Check incr-expr for canonical loop form and return true if it |
| 3503 | // does not conform. |
| 3504 | // OpenMP [2.6] Canonical loop form. Test-expr may be one of the following: |
| 3505 | // ++var |
| 3506 | // var++ |
| 3507 | // --var |
| 3508 | // var-- |
| 3509 | // var += incr |
| 3510 | // var -= incr |
| 3511 | // var = var + incr |
| 3512 | // var = incr + var |
| 3513 | // var = var - incr |
| 3514 | // |
| 3515 | if (!S) { |
| 3516 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_incr) << Var; |
| 3517 | return true; |
| 3518 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3519 | IncrementSrcRange = S->getSourceRange(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3520 | S = S->IgnoreParens(); |
| 3521 | if (auto UO = dyn_cast<UnaryOperator>(S)) { |
| 3522 | if (UO->isIncrementDecrementOp() && GetInitVarDecl(UO->getSubExpr()) == Var) |
| 3523 | return SetStep( |
| 3524 | SemaRef.ActOnIntegerConstant(UO->getLocStart(), |
| 3525 | (UO->isDecrementOp() ? -1 : 1)).get(), |
| 3526 | false); |
| 3527 | } else if (auto BO = dyn_cast<BinaryOperator>(S)) { |
| 3528 | switch (BO->getOpcode()) { |
| 3529 | case BO_AddAssign: |
| 3530 | case BO_SubAssign: |
| 3531 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 3532 | return SetStep(BO->getRHS(), BO->getOpcode() == BO_SubAssign); |
| 3533 | break; |
| 3534 | case BO_Assign: |
| 3535 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 3536 | return CheckIncRHS(BO->getRHS()); |
| 3537 | break; |
| 3538 | default: |
| 3539 | break; |
| 3540 | } |
| 3541 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
| 3542 | switch (CE->getOperator()) { |
| 3543 | case OO_PlusPlus: |
| 3544 | case OO_MinusMinus: |
| 3545 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 3546 | return SetStep( |
| 3547 | SemaRef.ActOnIntegerConstant( |
| 3548 | CE->getLocStart(), |
| 3549 | ((CE->getOperator() == OO_MinusMinus) ? -1 : 1)).get(), |
| 3550 | false); |
| 3551 | break; |
| 3552 | case OO_PlusEqual: |
| 3553 | case OO_MinusEqual: |
| 3554 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 3555 | return SetStep(CE->getArg(1), CE->getOperator() == OO_MinusEqual); |
| 3556 | break; |
| 3557 | case OO_Equal: |
| 3558 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 3559 | return CheckIncRHS(CE->getArg(1)); |
| 3560 | break; |
| 3561 | default: |
| 3562 | break; |
| 3563 | } |
| 3564 | } |
| 3565 | SemaRef.Diag(S->getLocStart(), diag::err_omp_loop_not_canonical_incr) |
| 3566 | << S->getSourceRange() << Var; |
| 3567 | return true; |
| 3568 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3569 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3570 | namespace { |
| 3571 | // Transform variables declared in GNU statement expressions to new ones to |
| 3572 | // avoid crash on codegen. |
| 3573 | class TransformToNewDefs : public TreeTransform<TransformToNewDefs> { |
| 3574 | typedef TreeTransform<TransformToNewDefs> BaseTransform; |
| 3575 | |
| 3576 | public: |
| 3577 | TransformToNewDefs(Sema &SemaRef) : BaseTransform(SemaRef) {} |
| 3578 | |
| 3579 | Decl *TransformDefinition(SourceLocation Loc, Decl *D) { |
| 3580 | if (auto *VD = cast<VarDecl>(D)) |
| 3581 | if (!isa<ParmVarDecl>(D) && !isa<VarTemplateSpecializationDecl>(D) && |
| 3582 | !isa<ImplicitParamDecl>(D)) { |
| 3583 | auto *NewVD = VarDecl::Create( |
| 3584 | SemaRef.Context, VD->getDeclContext(), VD->getLocStart(), |
| 3585 | VD->getLocation(), VD->getIdentifier(), VD->getType(), |
| 3586 | VD->getTypeSourceInfo(), VD->getStorageClass()); |
| 3587 | NewVD->setTSCSpec(VD->getTSCSpec()); |
| 3588 | NewVD->setInit(VD->getInit()); |
| 3589 | NewVD->setInitStyle(VD->getInitStyle()); |
| 3590 | NewVD->setExceptionVariable(VD->isExceptionVariable()); |
| 3591 | NewVD->setNRVOVariable(VD->isNRVOVariable()); |
| 3592 | NewVD->setCXXForRangeDecl(VD->isInExternCXXContext()); |
| 3593 | NewVD->setConstexpr(VD->isConstexpr()); |
| 3594 | NewVD->setInitCapture(VD->isInitCapture()); |
| 3595 | NewVD->setPreviousDeclInSameBlockScope( |
| 3596 | VD->isPreviousDeclInSameBlockScope()); |
| 3597 | VD->getDeclContext()->addHiddenDecl(NewVD); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 3598 | if (VD->hasAttrs()) |
| 3599 | NewVD->setAttrs(VD->getAttrs()); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3600 | transformedLocalDecl(VD, NewVD); |
| 3601 | return NewVD; |
| 3602 | } |
| 3603 | return BaseTransform::TransformDefinition(Loc, D); |
| 3604 | } |
| 3605 | |
| 3606 | ExprResult TransformDeclRefExpr(DeclRefExpr *E) { |
| 3607 | if (auto *NewD = TransformDecl(E->getExprLoc(), E->getDecl())) |
| 3608 | if (E->getDecl() != NewD) { |
| 3609 | NewD->setReferenced(); |
| 3610 | NewD->markUsed(SemaRef.Context); |
| 3611 | return DeclRefExpr::Create( |
| 3612 | SemaRef.Context, E->getQualifierLoc(), E->getTemplateKeywordLoc(), |
| 3613 | cast<ValueDecl>(NewD), E->refersToEnclosingVariableOrCapture(), |
| 3614 | E->getNameInfo(), E->getType(), E->getValueKind()); |
| 3615 | } |
| 3616 | return BaseTransform::TransformDeclRefExpr(E); |
| 3617 | } |
| 3618 | }; |
| 3619 | } |
| 3620 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3621 | /// \brief Build the expression to calculate the number of iterations. |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3622 | Expr * |
| 3623 | OpenMPIterationSpaceChecker::BuildNumIterations(Scope *S, |
| 3624 | const bool LimitedType) const { |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3625 | TransformToNewDefs Transform(SemaRef); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3626 | ExprResult Diff; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3627 | auto VarType = Var->getType().getNonReferenceType(); |
| 3628 | if (VarType->isIntegerType() || VarType->isPointerType() || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3629 | SemaRef.getLangOpts().CPlusPlus) { |
| 3630 | // Upper - Lower |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3631 | auto *UBExpr = TestIsLessOp ? UB : LB; |
| 3632 | auto *LBExpr = TestIsLessOp ? LB : UB; |
| 3633 | Expr *Upper = Transform.TransformExpr(UBExpr).get(); |
| 3634 | Expr *Lower = Transform.TransformExpr(LBExpr).get(); |
| 3635 | if (!Upper || !Lower) |
| 3636 | return nullptr; |
| 3637 | Upper = SemaRef.PerformImplicitConversion(Upper, UBExpr->getType(), |
| 3638 | Sema::AA_Converting, |
| 3639 | /*AllowExplicit=*/true) |
| 3640 | .get(); |
| 3641 | Lower = SemaRef.PerformImplicitConversion(Lower, LBExpr->getType(), |
| 3642 | Sema::AA_Converting, |
| 3643 | /*AllowExplicit=*/true) |
| 3644 | .get(); |
| 3645 | if (!Upper || !Lower) |
| 3646 | return nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3647 | |
| 3648 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Sub, Upper, Lower); |
| 3649 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3650 | if (!Diff.isUsable() && VarType->getAsCXXRecordDecl()) { |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3651 | // BuildBinOp already emitted error, this one is to point user to upper |
| 3652 | // and lower bound, and to tell what is passed to 'operator-'. |
| 3653 | SemaRef.Diag(Upper->getLocStart(), diag::err_omp_loop_diff_cxx) |
| 3654 | << Upper->getSourceRange() << Lower->getSourceRange(); |
| 3655 | return nullptr; |
| 3656 | } |
| 3657 | } |
| 3658 | |
| 3659 | if (!Diff.isUsable()) |
| 3660 | return nullptr; |
| 3661 | |
| 3662 | // Upper - Lower [- 1] |
| 3663 | if (TestIsStrictOp) |
| 3664 | Diff = SemaRef.BuildBinOp( |
| 3665 | S, DefaultLoc, BO_Sub, Diff.get(), |
| 3666 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 3667 | if (!Diff.isUsable()) |
| 3668 | return nullptr; |
| 3669 | |
| 3670 | // Upper - Lower [- 1] + Step |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3671 | auto NewStep = Transform.TransformExpr(Step->IgnoreImplicit()); |
| 3672 | if (NewStep.isInvalid()) |
| 3673 | return nullptr; |
| 3674 | NewStep = SemaRef.PerformImplicitConversion( |
| 3675 | NewStep.get(), Step->IgnoreImplicit()->getType(), Sema::AA_Converting, |
| 3676 | /*AllowExplicit=*/true); |
| 3677 | if (NewStep.isInvalid()) |
| 3678 | return nullptr; |
| 3679 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Add, Diff.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3680 | if (!Diff.isUsable()) |
| 3681 | return nullptr; |
| 3682 | |
| 3683 | // Parentheses (for dumping/debugging purposes only). |
| 3684 | Diff = SemaRef.ActOnParenExpr(DefaultLoc, DefaultLoc, Diff.get()); |
| 3685 | if (!Diff.isUsable()) |
| 3686 | return nullptr; |
| 3687 | |
| 3688 | // (Upper - Lower [- 1] + Step) / Step |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3689 | NewStep = Transform.TransformExpr(Step->IgnoreImplicit()); |
| 3690 | if (NewStep.isInvalid()) |
| 3691 | return nullptr; |
| 3692 | NewStep = SemaRef.PerformImplicitConversion( |
| 3693 | NewStep.get(), Step->IgnoreImplicit()->getType(), Sema::AA_Converting, |
| 3694 | /*AllowExplicit=*/true); |
| 3695 | if (NewStep.isInvalid()) |
| 3696 | return nullptr; |
| 3697 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Div, Diff.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3698 | if (!Diff.isUsable()) |
| 3699 | return nullptr; |
| 3700 | |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3701 | // OpenMP runtime requires 32-bit or 64-bit loop variables. |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3702 | QualType Type = Diff.get()->getType(); |
| 3703 | auto &C = SemaRef.Context; |
| 3704 | bool UseVarType = VarType->hasIntegerRepresentation() && |
| 3705 | C.getTypeSize(Type) > C.getTypeSize(VarType); |
| 3706 | if (!Type->isIntegerType() || UseVarType) { |
| 3707 | unsigned NewSize = |
| 3708 | UseVarType ? C.getTypeSize(VarType) : C.getTypeSize(Type); |
| 3709 | bool IsSigned = UseVarType ? VarType->hasSignedIntegerRepresentation() |
| 3710 | : Type->hasSignedIntegerRepresentation(); |
| 3711 | Type = C.getIntTypeForBitwidth(NewSize, IsSigned); |
| 3712 | Diff = SemaRef.PerformImplicitConversion( |
| 3713 | Diff.get(), Type, Sema::AA_Converting, /*AllowExplicit=*/true); |
| 3714 | if (!Diff.isUsable()) |
| 3715 | return nullptr; |
| 3716 | } |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3717 | if (LimitedType) { |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3718 | unsigned NewSize = (C.getTypeSize(Type) > 32) ? 64 : 32; |
| 3719 | if (NewSize != C.getTypeSize(Type)) { |
| 3720 | if (NewSize < C.getTypeSize(Type)) { |
| 3721 | assert(NewSize == 64 && "incorrect loop var size"); |
| 3722 | SemaRef.Diag(DefaultLoc, diag::warn_omp_loop_64_bit_var) |
| 3723 | << InitSrcRange << ConditionSrcRange; |
| 3724 | } |
| 3725 | QualType NewType = C.getIntTypeForBitwidth( |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3726 | NewSize, Type->hasSignedIntegerRepresentation() || |
| 3727 | C.getTypeSize(Type) < NewSize); |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3728 | Diff = SemaRef.PerformImplicitConversion(Diff.get(), NewType, |
| 3729 | Sema::AA_Converting, true); |
| 3730 | if (!Diff.isUsable()) |
| 3731 | return nullptr; |
| 3732 | } |
| 3733 | } |
| 3734 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3735 | return Diff.get(); |
| 3736 | } |
| 3737 | |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3738 | Expr *OpenMPIterationSpaceChecker::BuildPreCond(Scope *S, Expr *Cond) const { |
| 3739 | // Try to build LB <op> UB, where <op> is <, >, <=, or >=. |
| 3740 | bool Suppress = SemaRef.getDiagnostics().getSuppressAllDiagnostics(); |
| 3741 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(/*Val=*/true); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3742 | TransformToNewDefs Transform(SemaRef); |
| 3743 | |
| 3744 | auto NewLB = Transform.TransformExpr(LB); |
| 3745 | auto NewUB = Transform.TransformExpr(UB); |
| 3746 | if (NewLB.isInvalid() || NewUB.isInvalid()) |
| 3747 | return Cond; |
| 3748 | NewLB = SemaRef.PerformImplicitConversion(NewLB.get(), LB->getType(), |
| 3749 | Sema::AA_Converting, |
| 3750 | /*AllowExplicit=*/true); |
| 3751 | NewUB = SemaRef.PerformImplicitConversion(NewUB.get(), UB->getType(), |
| 3752 | Sema::AA_Converting, |
| 3753 | /*AllowExplicit=*/true); |
| 3754 | if (NewLB.isInvalid() || NewUB.isInvalid()) |
| 3755 | return Cond; |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3756 | auto CondExpr = SemaRef.BuildBinOp( |
| 3757 | S, DefaultLoc, TestIsLessOp ? (TestIsStrictOp ? BO_LT : BO_LE) |
| 3758 | : (TestIsStrictOp ? BO_GT : BO_GE), |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3759 | NewLB.get(), NewUB.get()); |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3760 | if (CondExpr.isUsable()) { |
| 3761 | CondExpr = SemaRef.PerformImplicitConversion( |
| 3762 | CondExpr.get(), SemaRef.Context.BoolTy, /*Action=*/Sema::AA_Casting, |
| 3763 | /*AllowExplicit=*/true); |
| 3764 | } |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3765 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(Suppress); |
| 3766 | // Otherwise use original loop conditon and evaluate it in runtime. |
| 3767 | return CondExpr.isUsable() ? CondExpr.get() : Cond; |
| 3768 | } |
| 3769 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3770 | /// \brief Build reference expression to the counter be used for codegen. |
| 3771 | Expr *OpenMPIterationSpaceChecker::BuildCounterVar() const { |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3772 | return buildDeclRefExpr(SemaRef, Var, Var->getType().getNonReferenceType(), |
| 3773 | DefaultLoc); |
| 3774 | } |
| 3775 | |
| 3776 | Expr *OpenMPIterationSpaceChecker::BuildPrivateCounterVar() const { |
| 3777 | if (Var && !Var->isInvalidDecl()) { |
| 3778 | auto Type = Var->getType().getNonReferenceType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 3779 | auto *PrivateVar = |
| 3780 | buildVarDecl(SemaRef, DefaultLoc, Type, Var->getName(), |
| 3781 | Var->hasAttrs() ? &Var->getAttrs() : nullptr); |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3782 | if (PrivateVar->isInvalidDecl()) |
| 3783 | return nullptr; |
| 3784 | return buildDeclRefExpr(SemaRef, PrivateVar, Type, DefaultLoc); |
| 3785 | } |
| 3786 | return nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3787 | } |
| 3788 | |
| 3789 | /// \brief Build initization of the counter be used for codegen. |
| 3790 | Expr *OpenMPIterationSpaceChecker::BuildCounterInit() const { return LB; } |
| 3791 | |
| 3792 | /// \brief Build step of the counter be used for codegen. |
| 3793 | Expr *OpenMPIterationSpaceChecker::BuildCounterStep() const { return Step; } |
| 3794 | |
| 3795 | /// \brief Iteration space of a single for loop. |
| 3796 | struct LoopIterationSpace { |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3797 | /// \brief Condition of the loop. |
| 3798 | Expr *PreCond; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3799 | /// \brief This expression calculates the number of iterations in the loop. |
| 3800 | /// It is always possible to calculate it before starting the loop. |
| 3801 | Expr *NumIterations; |
| 3802 | /// \brief The loop counter variable. |
| 3803 | Expr *CounterVar; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3804 | /// \brief Private loop counter variable. |
| 3805 | Expr *PrivateCounterVar; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3806 | /// \brief This is initializer for the initial value of #CounterVar. |
| 3807 | Expr *CounterInit; |
| 3808 | /// \brief This is step for the #CounterVar used to generate its update: |
| 3809 | /// #CounterVar = #CounterInit + #CounterStep * CurrentIteration. |
| 3810 | Expr *CounterStep; |
| 3811 | /// \brief Should step be subtracted? |
| 3812 | bool Subtract; |
| 3813 | /// \brief Source range of the loop init. |
| 3814 | SourceRange InitSrcRange; |
| 3815 | /// \brief Source range of the loop condition. |
| 3816 | SourceRange CondSrcRange; |
| 3817 | /// \brief Source range of the loop increment. |
| 3818 | SourceRange IncSrcRange; |
| 3819 | }; |
| 3820 | |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 3821 | } // namespace |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3822 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3823 | void Sema::ActOnOpenMPLoopInitialization(SourceLocation ForLoc, Stmt *Init) { |
| 3824 | assert(getLangOpts().OpenMP && "OpenMP is not active."); |
| 3825 | assert(Init && "Expected loop in canonical form."); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 3826 | unsigned AssociatedLoops = DSAStack->getAssociatedLoops(); |
| 3827 | if (AssociatedLoops > 0 && |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3828 | isOpenMPLoopDirective(DSAStack->getCurrentDirective())) { |
| 3829 | OpenMPIterationSpaceChecker ISC(*this, ForLoc); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 3830 | if (!ISC.CheckInit(Init, /*EmitDiags=*/false)) |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3831 | DSAStack->addLoopControlVariable(ISC.GetLoopVar()); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 3832 | DSAStack->setAssociatedLoops(AssociatedLoops - 1); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3833 | } |
| 3834 | } |
| 3835 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3836 | /// \brief Called on a for stmt to check and extract its iteration space |
| 3837 | /// for further processing (such as collapsing). |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3838 | static bool CheckOpenMPIterationSpace( |
| 3839 | OpenMPDirectiveKind DKind, Stmt *S, Sema &SemaRef, DSAStackTy &DSA, |
| 3840 | unsigned CurrentNestedLoopCount, unsigned NestedLoopCount, |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3841 | Expr *CollapseLoopCountExpr, Expr *OrderedLoopCountExpr, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 3842 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3843 | LoopIterationSpace &ResultIterSpace) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3844 | // OpenMP [2.6, Canonical Loop Form] |
| 3845 | // for (init-expr; test-expr; incr-expr) structured-block |
| 3846 | auto For = dyn_cast_or_null<ForStmt>(S); |
| 3847 | if (!For) { |
| 3848 | SemaRef.Diag(S->getLocStart(), diag::err_omp_not_for) |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3849 | << (CollapseLoopCountExpr != nullptr || OrderedLoopCountExpr != nullptr) |
| 3850 | << getOpenMPDirectiveName(DKind) << NestedLoopCount |
| 3851 | << (CurrentNestedLoopCount > 0) << CurrentNestedLoopCount; |
| 3852 | if (NestedLoopCount > 1) { |
| 3853 | if (CollapseLoopCountExpr && OrderedLoopCountExpr) |
| 3854 | SemaRef.Diag(DSA.getConstructLoc(), |
| 3855 | diag::note_omp_collapse_ordered_expr) |
| 3856 | << 2 << CollapseLoopCountExpr->getSourceRange() |
| 3857 | << OrderedLoopCountExpr->getSourceRange(); |
| 3858 | else if (CollapseLoopCountExpr) |
| 3859 | SemaRef.Diag(CollapseLoopCountExpr->getExprLoc(), |
| 3860 | diag::note_omp_collapse_ordered_expr) |
| 3861 | << 0 << CollapseLoopCountExpr->getSourceRange(); |
| 3862 | else |
| 3863 | SemaRef.Diag(OrderedLoopCountExpr->getExprLoc(), |
| 3864 | diag::note_omp_collapse_ordered_expr) |
| 3865 | << 1 << OrderedLoopCountExpr->getSourceRange(); |
| 3866 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3867 | return true; |
| 3868 | } |
| 3869 | assert(For->getBody()); |
| 3870 | |
| 3871 | OpenMPIterationSpaceChecker ISC(SemaRef, For->getForLoc()); |
| 3872 | |
| 3873 | // Check init. |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 3874 | auto Init = For->getInit(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3875 | if (ISC.CheckInit(Init)) { |
| 3876 | return true; |
| 3877 | } |
| 3878 | |
| 3879 | bool HasErrors = false; |
| 3880 | |
| 3881 | // Check loop variable's type. |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 3882 | auto Var = ISC.GetLoopVar(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3883 | |
| 3884 | // OpenMP [2.6, Canonical Loop Form] |
| 3885 | // Var is one of the following: |
| 3886 | // A variable of signed or unsigned integer type. |
| 3887 | // For C++, a variable of a random access iterator type. |
| 3888 | // For C, a variable of a pointer type. |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3889 | auto VarType = Var->getType().getNonReferenceType(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3890 | if (!VarType->isDependentType() && !VarType->isIntegerType() && |
| 3891 | !VarType->isPointerType() && |
| 3892 | !(SemaRef.getLangOpts().CPlusPlus && VarType->isOverloadableType())) { |
| 3893 | SemaRef.Diag(Init->getLocStart(), diag::err_omp_loop_variable_type) |
| 3894 | << SemaRef.getLangOpts().CPlusPlus; |
| 3895 | HasErrors = true; |
| 3896 | } |
| 3897 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3898 | // OpenMP, 2.14.1.1 Data-sharing Attribute Rules for Variables Referenced in a |
| 3899 | // Construct |
| 3900 | // The loop iteration variable(s) in the associated for-loop(s) of a for or |
| 3901 | // parallel for construct is (are) private. |
| 3902 | // The loop iteration variable in the associated for-loop of a simd construct |
| 3903 | // with just one associated for-loop is linear with a constant-linear-step |
| 3904 | // that is the increment of the associated for-loop. |
| 3905 | // Exclude loop var from the list of variables with implicitly defined data |
| 3906 | // sharing attributes. |
Benjamin Kramer | ad8e079 | 2014-10-10 15:32:48 +0000 | [diff] [blame] | 3907 | VarsWithImplicitDSA.erase(Var); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3908 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3909 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced in |
| 3910 | // a Construct, C/C++]. |
Alexey Bataev | cefffae | 2014-06-23 08:21:53 +0000 | [diff] [blame] | 3911 | // The loop iteration variable in the associated for-loop of a simd construct |
| 3912 | // with just one associated for-loop may be listed in a linear clause with a |
| 3913 | // constant-linear-step that is the increment of the associated for-loop. |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3914 | // The loop iteration variable(s) in the associated for-loop(s) of a for or |
| 3915 | // parallel for construct may be listed in a private or lastprivate clause. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 3916 | DSAStackTy::DSAVarData DVar = DSA.getTopDSA(Var, false); |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3917 | auto LoopVarRefExpr = ISC.GetLoopVarRefExpr(); |
| 3918 | // If LoopVarRefExpr is nullptr it means the corresponding loop variable is |
| 3919 | // declared in the loop and it is predetermined as a private. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3920 | auto PredeterminedCKind = |
| 3921 | isOpenMPSimdDirective(DKind) |
| 3922 | ? ((NestedLoopCount == 1) ? OMPC_linear : OMPC_lastprivate) |
| 3923 | : OMPC_private; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3924 | if (((isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown && |
Alexey Bataev | e648e80 | 2015-12-25 13:38:08 +0000 | [diff] [blame] | 3925 | DVar.CKind != PredeterminedCKind) || |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 3926 | ((isOpenMPWorksharingDirective(DKind) || DKind == OMPD_taskloop || |
Alexey Bataev | e648e80 | 2015-12-25 13:38:08 +0000 | [diff] [blame] | 3927 | isOpenMPDistributeDirective(DKind)) && |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 3928 | !isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown && |
Alexey Bataev | e648e80 | 2015-12-25 13:38:08 +0000 | [diff] [blame] | 3929 | DVar.CKind != OMPC_private && DVar.CKind != OMPC_lastprivate)) && |
| 3930 | (DVar.CKind != OMPC_private || DVar.RefExpr != nullptr)) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3931 | SemaRef.Diag(Init->getLocStart(), diag::err_omp_loop_var_dsa) |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3932 | << getOpenMPClauseName(DVar.CKind) << getOpenMPDirectiveName(DKind) |
| 3933 | << getOpenMPClauseName(PredeterminedCKind); |
Alexey Bataev | f2453a0 | 2015-05-06 07:25:08 +0000 | [diff] [blame] | 3934 | if (DVar.RefExpr == nullptr) |
| 3935 | DVar.CKind = PredeterminedCKind; |
| 3936 | ReportOriginalDSA(SemaRef, &DSA, Var, DVar, /*IsLoopIterVar=*/true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3937 | HasErrors = true; |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3938 | } else if (LoopVarRefExpr != nullptr) { |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3939 | // Make the loop iteration variable private (for worksharing constructs), |
| 3940 | // linear (for simd directives with the only one associated loop) or |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3941 | // lastprivate (for simd directives with several collapsed or ordered |
| 3942 | // loops). |
Alexey Bataev | 9aba41c | 2014-11-14 04:08:45 +0000 | [diff] [blame] | 3943 | if (DVar.CKind == OMPC_unknown) |
| 3944 | DVar = DSA.hasDSA(Var, isOpenMPPrivate, MatchesAlways(), |
| 3945 | /*FromParent=*/false); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3946 | DSA.addDSA(Var, LoopVarRefExpr, PredeterminedCKind); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3947 | } |
| 3948 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 3949 | assert(isOpenMPLoopDirective(DKind) && "DSA for non-loop vars"); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 3950 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3951 | // Check test-expr. |
| 3952 | HasErrors |= ISC.CheckCond(For->getCond()); |
| 3953 | |
| 3954 | // Check incr-expr. |
| 3955 | HasErrors |= ISC.CheckInc(For->getInc()); |
| 3956 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3957 | if (ISC.Dependent() || SemaRef.CurContext->isDependentContext() || HasErrors) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3958 | return HasErrors; |
| 3959 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3960 | // Build the loop's iteration space representation. |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3961 | ResultIterSpace.PreCond = ISC.BuildPreCond(DSA.getCurScope(), For->getCond()); |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3962 | ResultIterSpace.NumIterations = ISC.BuildNumIterations( |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 3963 | DSA.getCurScope(), (isOpenMPWorksharingDirective(DKind) || |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 3964 | isOpenMPTaskLoopDirective(DKind) || |
| 3965 | isOpenMPDistributeDirective(DKind))); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3966 | ResultIterSpace.CounterVar = ISC.BuildCounterVar(); |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3967 | ResultIterSpace.PrivateCounterVar = ISC.BuildPrivateCounterVar(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3968 | ResultIterSpace.CounterInit = ISC.BuildCounterInit(); |
| 3969 | ResultIterSpace.CounterStep = ISC.BuildCounterStep(); |
| 3970 | ResultIterSpace.InitSrcRange = ISC.GetInitSrcRange(); |
| 3971 | ResultIterSpace.CondSrcRange = ISC.GetConditionSrcRange(); |
| 3972 | ResultIterSpace.IncSrcRange = ISC.GetIncrementSrcRange(); |
| 3973 | ResultIterSpace.Subtract = ISC.ShouldSubtractStep(); |
| 3974 | |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3975 | HasErrors |= (ResultIterSpace.PreCond == nullptr || |
| 3976 | ResultIterSpace.NumIterations == nullptr || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3977 | ResultIterSpace.CounterVar == nullptr || |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3978 | ResultIterSpace.PrivateCounterVar == nullptr || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3979 | ResultIterSpace.CounterInit == nullptr || |
| 3980 | ResultIterSpace.CounterStep == nullptr); |
| 3981 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3982 | return HasErrors; |
| 3983 | } |
| 3984 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3985 | /// \brief Build 'VarRef = Start. |
| 3986 | static ExprResult BuildCounterInit(Sema &SemaRef, Scope *S, SourceLocation Loc, |
| 3987 | ExprResult VarRef, ExprResult Start) { |
| 3988 | TransformToNewDefs Transform(SemaRef); |
| 3989 | // Build 'VarRef = Start. |
| 3990 | auto NewStart = Transform.TransformExpr(Start.get()->IgnoreImplicit()); |
| 3991 | if (NewStart.isInvalid()) |
| 3992 | return ExprError(); |
| 3993 | NewStart = SemaRef.PerformImplicitConversion( |
| 3994 | NewStart.get(), Start.get()->IgnoreImplicit()->getType(), |
| 3995 | Sema::AA_Converting, |
| 3996 | /*AllowExplicit=*/true); |
| 3997 | if (NewStart.isInvalid()) |
| 3998 | return ExprError(); |
| 3999 | NewStart = SemaRef.PerformImplicitConversion( |
| 4000 | NewStart.get(), VarRef.get()->getType(), Sema::AA_Converting, |
| 4001 | /*AllowExplicit=*/true); |
| 4002 | if (!NewStart.isUsable()) |
| 4003 | return ExprError(); |
| 4004 | |
| 4005 | auto Init = |
| 4006 | SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), NewStart.get()); |
| 4007 | return Init; |
| 4008 | } |
| 4009 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4010 | /// \brief Build 'VarRef = Start + Iter * Step'. |
| 4011 | static ExprResult BuildCounterUpdate(Sema &SemaRef, Scope *S, |
| 4012 | SourceLocation Loc, ExprResult VarRef, |
| 4013 | ExprResult Start, ExprResult Iter, |
| 4014 | ExprResult Step, bool Subtract) { |
| 4015 | // Add parentheses (for debugging purposes only). |
| 4016 | Iter = SemaRef.ActOnParenExpr(Loc, Loc, Iter.get()); |
| 4017 | if (!VarRef.isUsable() || !Start.isUsable() || !Iter.isUsable() || |
| 4018 | !Step.isUsable()) |
| 4019 | return ExprError(); |
| 4020 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4021 | TransformToNewDefs Transform(SemaRef); |
| 4022 | auto NewStep = Transform.TransformExpr(Step.get()->IgnoreImplicit()); |
| 4023 | if (NewStep.isInvalid()) |
| 4024 | return ExprError(); |
| 4025 | NewStep = SemaRef.PerformImplicitConversion( |
| 4026 | NewStep.get(), Step.get()->IgnoreImplicit()->getType(), |
| 4027 | Sema::AA_Converting, |
| 4028 | /*AllowExplicit=*/true); |
| 4029 | if (NewStep.isInvalid()) |
| 4030 | return ExprError(); |
| 4031 | ExprResult Update = |
| 4032 | SemaRef.BuildBinOp(S, Loc, BO_Mul, Iter.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4033 | if (!Update.isUsable()) |
| 4034 | return ExprError(); |
| 4035 | |
| 4036 | // Build 'VarRef = Start + Iter * Step'. |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4037 | auto NewStart = Transform.TransformExpr(Start.get()->IgnoreImplicit()); |
| 4038 | if (NewStart.isInvalid()) |
| 4039 | return ExprError(); |
| 4040 | NewStart = SemaRef.PerformImplicitConversion( |
| 4041 | NewStart.get(), Start.get()->IgnoreImplicit()->getType(), |
| 4042 | Sema::AA_Converting, |
| 4043 | /*AllowExplicit=*/true); |
| 4044 | if (NewStart.isInvalid()) |
| 4045 | return ExprError(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4046 | Update = SemaRef.BuildBinOp(S, Loc, (Subtract ? BO_Sub : BO_Add), |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4047 | NewStart.get(), Update.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4048 | if (!Update.isUsable()) |
| 4049 | return ExprError(); |
| 4050 | |
| 4051 | Update = SemaRef.PerformImplicitConversion( |
| 4052 | Update.get(), VarRef.get()->getType(), Sema::AA_Converting, true); |
| 4053 | if (!Update.isUsable()) |
| 4054 | return ExprError(); |
| 4055 | |
| 4056 | Update = SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), Update.get()); |
| 4057 | return Update; |
| 4058 | } |
| 4059 | |
| 4060 | /// \brief Convert integer expression \a E to make it have at least \a Bits |
| 4061 | /// bits. |
| 4062 | static ExprResult WidenIterationCount(unsigned Bits, Expr *E, |
| 4063 | Sema &SemaRef) { |
| 4064 | if (E == nullptr) |
| 4065 | return ExprError(); |
| 4066 | auto &C = SemaRef.Context; |
| 4067 | QualType OldType = E->getType(); |
| 4068 | unsigned HasBits = C.getTypeSize(OldType); |
| 4069 | if (HasBits >= Bits) |
| 4070 | return ExprResult(E); |
| 4071 | // OK to convert to signed, because new type has more bits than old. |
| 4072 | QualType NewType = C.getIntTypeForBitwidth(Bits, /* Signed */ true); |
| 4073 | return SemaRef.PerformImplicitConversion(E, NewType, Sema::AA_Converting, |
| 4074 | true); |
| 4075 | } |
| 4076 | |
| 4077 | /// \brief Check if the given expression \a E is a constant integer that fits |
| 4078 | /// into \a Bits bits. |
| 4079 | static bool FitsInto(unsigned Bits, bool Signed, Expr *E, Sema &SemaRef) { |
| 4080 | if (E == nullptr) |
| 4081 | return false; |
| 4082 | llvm::APSInt Result; |
| 4083 | if (E->isIntegerConstantExpr(Result, SemaRef.Context)) |
| 4084 | return Signed ? Result.isSignedIntN(Bits) : Result.isIntN(Bits); |
| 4085 | return false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4086 | } |
| 4087 | |
| 4088 | /// \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] | 4089 | /// \return Returns 0 if one of the collapsed stmts is not canonical for loop, |
| 4090 | /// number of collapsed loops otherwise. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4091 | static unsigned |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4092 | CheckOpenMPLoop(OpenMPDirectiveKind DKind, Expr *CollapseLoopCountExpr, |
| 4093 | Expr *OrderedLoopCountExpr, Stmt *AStmt, Sema &SemaRef, |
| 4094 | DSAStackTy &DSA, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 4095 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA, |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4096 | OMPLoopDirective::HelperExprs &Built) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 4097 | unsigned NestedLoopCount = 1; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4098 | if (CollapseLoopCountExpr) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 4099 | // Found 'collapse' clause - calculate collapse number. |
| 4100 | llvm::APSInt Result; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4101 | if (CollapseLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext())) |
Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 4102 | NestedLoopCount = Result.getLimitedValue(); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4103 | } |
| 4104 | if (OrderedLoopCountExpr) { |
| 4105 | // Found 'ordered' clause - calculate collapse number. |
| 4106 | llvm::APSInt Result; |
Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 4107 | if (OrderedLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext())) { |
| 4108 | if (Result.getLimitedValue() < NestedLoopCount) { |
| 4109 | SemaRef.Diag(OrderedLoopCountExpr->getExprLoc(), |
| 4110 | diag::err_omp_wrong_ordered_loop_count) |
| 4111 | << OrderedLoopCountExpr->getSourceRange(); |
| 4112 | SemaRef.Diag(CollapseLoopCountExpr->getExprLoc(), |
| 4113 | diag::note_collapse_loop_count) |
| 4114 | << CollapseLoopCountExpr->getSourceRange(); |
| 4115 | } |
| 4116 | NestedLoopCount = Result.getLimitedValue(); |
| 4117 | } |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 4118 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4119 | // This is helper routine for loop directives (e.g., 'for', 'simd', |
| 4120 | // 'for simd', etc.). |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4121 | SmallVector<LoopIterationSpace, 4> IterSpaces; |
| 4122 | IterSpaces.resize(NestedLoopCount); |
| 4123 | Stmt *CurStmt = AStmt->IgnoreContainers(/* IgnoreCaptured */ true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4124 | for (unsigned Cnt = 0; Cnt < NestedLoopCount; ++Cnt) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 4125 | if (CheckOpenMPIterationSpace(DKind, CurStmt, SemaRef, DSA, Cnt, |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4126 | NestedLoopCount, CollapseLoopCountExpr, |
| 4127 | OrderedLoopCountExpr, VarsWithImplicitDSA, |
| 4128 | IterSpaces[Cnt])) |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 4129 | return 0; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4130 | // 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] | 4131 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 4132 | // All loops associated with the construct must be perfectly nested; that |
| 4133 | // is, there must be no intervening code nor any OpenMP directive between |
| 4134 | // any two loops. |
| 4135 | CurStmt = cast<ForStmt>(CurStmt)->getBody()->IgnoreContainers(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4136 | } |
| 4137 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4138 | Built.clear(/* size */ NestedLoopCount); |
| 4139 | |
| 4140 | if (SemaRef.CurContext->isDependentContext()) |
| 4141 | return NestedLoopCount; |
| 4142 | |
| 4143 | // An example of what is generated for the following code: |
| 4144 | // |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4145 | // #pragma omp simd collapse(2) ordered(2) |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4146 | // for (i = 0; i < NI; ++i) |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4147 | // for (k = 0; k < NK; ++k) |
| 4148 | // for (j = J0; j < NJ; j+=2) { |
| 4149 | // <loop body> |
| 4150 | // } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4151 | // |
| 4152 | // We generate the code below. |
| 4153 | // Note: the loop body may be outlined in CodeGen. |
| 4154 | // Note: some counters may be C++ classes, operator- is used to find number of |
| 4155 | // iterations and operator+= to calculate counter value. |
| 4156 | // Note: decltype(NumIterations) must be integer type (in 'omp for', only i32 |
| 4157 | // or i64 is currently supported). |
| 4158 | // |
| 4159 | // #define NumIterations (NI * ((NJ - J0 - 1 + 2) / 2)) |
| 4160 | // for (int[32|64]_t IV = 0; IV < NumIterations; ++IV ) { |
| 4161 | // .local.i = IV / ((NJ - J0 - 1 + 2) / 2); |
| 4162 | // .local.j = J0 + (IV % ((NJ - J0 - 1 + 2) / 2)) * 2; |
| 4163 | // // similar updates for vars in clauses (e.g. 'linear') |
| 4164 | // <loop body (using local i and j)> |
| 4165 | // } |
| 4166 | // i = NI; // assign final values of counters |
| 4167 | // j = NJ; |
| 4168 | // |
| 4169 | |
| 4170 | // Last iteration number is (I1 * I2 * ... In) - 1, where I1, I2 ... In are |
| 4171 | // the iteration counts of the collapsed for loops. |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 4172 | // Precondition tests if there is at least one iteration (all conditions are |
| 4173 | // true). |
| 4174 | auto PreCond = ExprResult(IterSpaces[0].PreCond); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4175 | auto N0 = IterSpaces[0].NumIterations; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4176 | ExprResult LastIteration32 = WidenIterationCount( |
| 4177 | 32 /* Bits */, SemaRef.PerformImplicitConversion( |
| 4178 | N0->IgnoreImpCasts(), N0->getType(), |
| 4179 | Sema::AA_Converting, /*AllowExplicit=*/true) |
| 4180 | .get(), |
| 4181 | SemaRef); |
| 4182 | ExprResult LastIteration64 = WidenIterationCount( |
| 4183 | 64 /* Bits */, SemaRef.PerformImplicitConversion( |
| 4184 | N0->IgnoreImpCasts(), N0->getType(), |
| 4185 | Sema::AA_Converting, /*AllowExplicit=*/true) |
| 4186 | .get(), |
| 4187 | SemaRef); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4188 | |
| 4189 | if (!LastIteration32.isUsable() || !LastIteration64.isUsable()) |
| 4190 | return NestedLoopCount; |
| 4191 | |
| 4192 | auto &C = SemaRef.Context; |
| 4193 | bool AllCountsNeedLessThan32Bits = C.getTypeSize(N0->getType()) < 32; |
| 4194 | |
| 4195 | Scope *CurScope = DSA.getCurScope(); |
| 4196 | for (unsigned Cnt = 1; Cnt < NestedLoopCount; ++Cnt) { |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 4197 | if (PreCond.isUsable()) { |
| 4198 | PreCond = SemaRef.BuildBinOp(CurScope, SourceLocation(), BO_LAnd, |
| 4199 | PreCond.get(), IterSpaces[Cnt].PreCond); |
| 4200 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4201 | auto N = IterSpaces[Cnt].NumIterations; |
| 4202 | AllCountsNeedLessThan32Bits &= C.getTypeSize(N->getType()) < 32; |
| 4203 | if (LastIteration32.isUsable()) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4204 | LastIteration32 = SemaRef.BuildBinOp( |
| 4205 | CurScope, SourceLocation(), BO_Mul, LastIteration32.get(), |
| 4206 | SemaRef.PerformImplicitConversion(N->IgnoreImpCasts(), N->getType(), |
| 4207 | Sema::AA_Converting, |
| 4208 | /*AllowExplicit=*/true) |
| 4209 | .get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4210 | if (LastIteration64.isUsable()) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4211 | LastIteration64 = SemaRef.BuildBinOp( |
| 4212 | CurScope, SourceLocation(), BO_Mul, LastIteration64.get(), |
| 4213 | SemaRef.PerformImplicitConversion(N->IgnoreImpCasts(), N->getType(), |
| 4214 | Sema::AA_Converting, |
| 4215 | /*AllowExplicit=*/true) |
| 4216 | .get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4217 | } |
| 4218 | |
| 4219 | // Choose either the 32-bit or 64-bit version. |
| 4220 | ExprResult LastIteration = LastIteration64; |
| 4221 | if (LastIteration32.isUsable() && |
| 4222 | C.getTypeSize(LastIteration32.get()->getType()) == 32 && |
| 4223 | (AllCountsNeedLessThan32Bits || NestedLoopCount == 1 || |
| 4224 | FitsInto( |
| 4225 | 32 /* Bits */, |
| 4226 | LastIteration32.get()->getType()->hasSignedIntegerRepresentation(), |
| 4227 | LastIteration64.get(), SemaRef))) |
| 4228 | LastIteration = LastIteration32; |
| 4229 | |
| 4230 | if (!LastIteration.isUsable()) |
| 4231 | return 0; |
| 4232 | |
| 4233 | // Save the number of iterations. |
| 4234 | ExprResult NumIterations = LastIteration; |
| 4235 | { |
| 4236 | LastIteration = SemaRef.BuildBinOp( |
| 4237 | CurScope, SourceLocation(), BO_Sub, LastIteration.get(), |
| 4238 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 4239 | if (!LastIteration.isUsable()) |
| 4240 | return 0; |
| 4241 | } |
| 4242 | |
| 4243 | // Calculate the last iteration number beforehand instead of doing this on |
| 4244 | // each iteration. Do not do this if the number of iterations may be kfold-ed. |
| 4245 | llvm::APSInt Result; |
| 4246 | bool IsConstant = |
| 4247 | LastIteration.get()->isIntegerConstantExpr(Result, SemaRef.Context); |
| 4248 | ExprResult CalcLastIteration; |
| 4249 | if (!IsConstant) { |
| 4250 | SourceLocation SaveLoc; |
| 4251 | VarDecl *SaveVar = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4252 | buildVarDecl(SemaRef, SaveLoc, LastIteration.get()->getType(), |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4253 | ".omp.last.iteration"); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4254 | ExprResult SaveRef = buildDeclRefExpr( |
| 4255 | SemaRef, SaveVar, LastIteration.get()->getType(), SaveLoc); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4256 | CalcLastIteration = SemaRef.BuildBinOp(CurScope, SaveLoc, BO_Assign, |
| 4257 | SaveRef.get(), LastIteration.get()); |
| 4258 | LastIteration = SaveRef; |
| 4259 | |
| 4260 | // Prepare SaveRef + 1. |
| 4261 | NumIterations = SemaRef.BuildBinOp( |
| 4262 | CurScope, SaveLoc, BO_Add, SaveRef.get(), |
| 4263 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 4264 | if (!NumIterations.isUsable()) |
| 4265 | return 0; |
| 4266 | } |
| 4267 | |
| 4268 | SourceLocation InitLoc = IterSpaces[0].InitSrcRange.getBegin(); |
| 4269 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4270 | QualType VType = LastIteration.get()->getType(); |
| 4271 | // Build variables passed into runtime, nesessary for worksharing directives. |
| 4272 | ExprResult LB, UB, IL, ST, EUB; |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 4273 | if (isOpenMPWorksharingDirective(DKind) || isOpenMPTaskLoopDirective(DKind) || |
| 4274 | isOpenMPDistributeDirective(DKind)) { |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4275 | // Lower bound variable, initialized with zero. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4276 | VarDecl *LBDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.lb"); |
| 4277 | LB = buildDeclRefExpr(SemaRef, LBDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4278 | SemaRef.AddInitializerToDecl( |
| 4279 | LBDecl, SemaRef.ActOnIntegerConstant(InitLoc, 0).get(), |
| 4280 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 4281 | |
| 4282 | // Upper bound variable, initialized with last iteration number. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4283 | VarDecl *UBDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.ub"); |
| 4284 | UB = buildDeclRefExpr(SemaRef, UBDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4285 | SemaRef.AddInitializerToDecl(UBDecl, LastIteration.get(), |
| 4286 | /*DirectInit*/ false, |
| 4287 | /*TypeMayContainAuto*/ false); |
| 4288 | |
| 4289 | // A 32-bit variable-flag where runtime returns 1 for the last iteration. |
| 4290 | // This will be used to implement clause 'lastprivate'. |
| 4291 | QualType Int32Ty = SemaRef.Context.getIntTypeForBitwidth(32, true); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4292 | VarDecl *ILDecl = buildVarDecl(SemaRef, InitLoc, Int32Ty, ".omp.is_last"); |
| 4293 | IL = buildDeclRefExpr(SemaRef, ILDecl, Int32Ty, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4294 | SemaRef.AddInitializerToDecl( |
| 4295 | ILDecl, SemaRef.ActOnIntegerConstant(InitLoc, 0).get(), |
| 4296 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 4297 | |
| 4298 | // Stride variable returned by runtime (we initialize it to 1 by default). |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4299 | VarDecl *STDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.stride"); |
| 4300 | ST = buildDeclRefExpr(SemaRef, STDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4301 | SemaRef.AddInitializerToDecl( |
| 4302 | STDecl, SemaRef.ActOnIntegerConstant(InitLoc, 1).get(), |
| 4303 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 4304 | |
| 4305 | // Build expression: UB = min(UB, LastIteration) |
| 4306 | // It is nesessary for CodeGen of directives with static scheduling. |
| 4307 | ExprResult IsUBGreater = SemaRef.BuildBinOp(CurScope, InitLoc, BO_GT, |
| 4308 | UB.get(), LastIteration.get()); |
| 4309 | ExprResult CondOp = SemaRef.ActOnConditionalOp( |
| 4310 | InitLoc, InitLoc, IsUBGreater.get(), LastIteration.get(), UB.get()); |
| 4311 | EUB = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, UB.get(), |
| 4312 | CondOp.get()); |
| 4313 | EUB = SemaRef.ActOnFinishFullExpr(EUB.get()); |
| 4314 | } |
| 4315 | |
| 4316 | // Build the iteration variable and its initialization before loop. |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4317 | ExprResult IV; |
| 4318 | ExprResult Init; |
| 4319 | { |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4320 | VarDecl *IVDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.iv"); |
| 4321 | IV = buildDeclRefExpr(SemaRef, IVDecl, VType, InitLoc); |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 4322 | Expr *RHS = (isOpenMPWorksharingDirective(DKind) || |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 4323 | isOpenMPTaskLoopDirective(DKind) || |
| 4324 | isOpenMPDistributeDirective(DKind)) |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4325 | ? LB.get() |
| 4326 | : SemaRef.ActOnIntegerConstant(SourceLocation(), 0).get(); |
| 4327 | Init = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, IV.get(), RHS); |
| 4328 | Init = SemaRef.ActOnFinishFullExpr(Init.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4329 | } |
| 4330 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4331 | // Loop condition (IV < NumIterations) or (IV <= UB) for worksharing loops. |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4332 | SourceLocation CondLoc; |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4333 | ExprResult Cond = |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 4334 | (isOpenMPWorksharingDirective(DKind) || |
| 4335 | isOpenMPTaskLoopDirective(DKind) || isOpenMPDistributeDirective(DKind)) |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4336 | ? SemaRef.BuildBinOp(CurScope, CondLoc, BO_LE, IV.get(), UB.get()) |
| 4337 | : SemaRef.BuildBinOp(CurScope, CondLoc, BO_LT, IV.get(), |
| 4338 | NumIterations.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4339 | |
| 4340 | // Loop increment (IV = IV + 1) |
| 4341 | SourceLocation IncLoc; |
| 4342 | ExprResult Inc = |
| 4343 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, IV.get(), |
| 4344 | SemaRef.ActOnIntegerConstant(IncLoc, 1).get()); |
| 4345 | if (!Inc.isUsable()) |
| 4346 | return 0; |
| 4347 | Inc = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, IV.get(), Inc.get()); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4348 | Inc = SemaRef.ActOnFinishFullExpr(Inc.get()); |
| 4349 | if (!Inc.isUsable()) |
| 4350 | return 0; |
| 4351 | |
| 4352 | // Increments for worksharing loops (LB = LB + ST; UB = UB + ST). |
| 4353 | // Used for directives with static scheduling. |
| 4354 | ExprResult NextLB, NextUB; |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 4355 | if (isOpenMPWorksharingDirective(DKind) || isOpenMPTaskLoopDirective(DKind) || |
| 4356 | isOpenMPDistributeDirective(DKind)) { |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4357 | // LB + ST |
| 4358 | NextLB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, LB.get(), ST.get()); |
| 4359 | if (!NextLB.isUsable()) |
| 4360 | return 0; |
| 4361 | // LB = LB + ST |
| 4362 | NextLB = |
| 4363 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, LB.get(), NextLB.get()); |
| 4364 | NextLB = SemaRef.ActOnFinishFullExpr(NextLB.get()); |
| 4365 | if (!NextLB.isUsable()) |
| 4366 | return 0; |
| 4367 | // UB + ST |
| 4368 | NextUB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, UB.get(), ST.get()); |
| 4369 | if (!NextUB.isUsable()) |
| 4370 | return 0; |
| 4371 | // UB = UB + ST |
| 4372 | NextUB = |
| 4373 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, UB.get(), NextUB.get()); |
| 4374 | NextUB = SemaRef.ActOnFinishFullExpr(NextUB.get()); |
| 4375 | if (!NextUB.isUsable()) |
| 4376 | return 0; |
| 4377 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4378 | |
| 4379 | // Build updates and final values of the loop counters. |
| 4380 | bool HasErrors = false; |
| 4381 | Built.Counters.resize(NestedLoopCount); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4382 | Built.Inits.resize(NestedLoopCount); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4383 | Built.Updates.resize(NestedLoopCount); |
| 4384 | Built.Finals.resize(NestedLoopCount); |
| 4385 | { |
| 4386 | ExprResult Div; |
| 4387 | // Go from inner nested loop to outer. |
| 4388 | for (int Cnt = NestedLoopCount - 1; Cnt >= 0; --Cnt) { |
| 4389 | LoopIterationSpace &IS = IterSpaces[Cnt]; |
| 4390 | SourceLocation UpdLoc = IS.IncSrcRange.getBegin(); |
| 4391 | // Build: Iter = (IV / Div) % IS.NumIters |
| 4392 | // where Div is product of previous iterations' IS.NumIters. |
| 4393 | ExprResult Iter; |
| 4394 | if (Div.isUsable()) { |
| 4395 | Iter = |
| 4396 | SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Div, IV.get(), Div.get()); |
| 4397 | } else { |
| 4398 | Iter = IV; |
| 4399 | assert((Cnt == (int)NestedLoopCount - 1) && |
| 4400 | "unusable div expected on first iteration only"); |
| 4401 | } |
| 4402 | |
| 4403 | if (Cnt != 0 && Iter.isUsable()) |
| 4404 | Iter = SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Rem, Iter.get(), |
| 4405 | IS.NumIterations); |
| 4406 | if (!Iter.isUsable()) { |
| 4407 | HasErrors = true; |
| 4408 | break; |
| 4409 | } |
| 4410 | |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4411 | // Build update: IS.CounterVar(Private) = IS.Start + Iter * IS.Step |
| 4412 | auto *CounterVar = buildDeclRefExpr( |
| 4413 | SemaRef, cast<VarDecl>(cast<DeclRefExpr>(IS.CounterVar)->getDecl()), |
| 4414 | IS.CounterVar->getType(), IS.CounterVar->getExprLoc(), |
| 4415 | /*RefersToCapture=*/true); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4416 | ExprResult Init = BuildCounterInit(SemaRef, CurScope, UpdLoc, CounterVar, |
| 4417 | IS.CounterInit); |
| 4418 | if (!Init.isUsable()) { |
| 4419 | HasErrors = true; |
| 4420 | break; |
| 4421 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4422 | ExprResult Update = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4423 | BuildCounterUpdate(SemaRef, CurScope, UpdLoc, CounterVar, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4424 | IS.CounterInit, Iter, IS.CounterStep, IS.Subtract); |
| 4425 | if (!Update.isUsable()) { |
| 4426 | HasErrors = true; |
| 4427 | break; |
| 4428 | } |
| 4429 | |
| 4430 | // Build final: IS.CounterVar = IS.Start + IS.NumIters * IS.Step |
| 4431 | ExprResult Final = BuildCounterUpdate( |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4432 | SemaRef, CurScope, UpdLoc, CounterVar, IS.CounterInit, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4433 | IS.NumIterations, IS.CounterStep, IS.Subtract); |
| 4434 | if (!Final.isUsable()) { |
| 4435 | HasErrors = true; |
| 4436 | break; |
| 4437 | } |
| 4438 | |
| 4439 | // Build Div for the next iteration: Div <- Div * IS.NumIters |
| 4440 | if (Cnt != 0) { |
| 4441 | if (Div.isUnset()) |
| 4442 | Div = IS.NumIterations; |
| 4443 | else |
| 4444 | Div = SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Mul, Div.get(), |
| 4445 | IS.NumIterations); |
| 4446 | |
| 4447 | // Add parentheses (for debugging purposes only). |
| 4448 | if (Div.isUsable()) |
| 4449 | Div = SemaRef.ActOnParenExpr(UpdLoc, UpdLoc, Div.get()); |
| 4450 | if (!Div.isUsable()) { |
| 4451 | HasErrors = true; |
| 4452 | break; |
| 4453 | } |
| 4454 | } |
| 4455 | if (!Update.isUsable() || !Final.isUsable()) { |
| 4456 | HasErrors = true; |
| 4457 | break; |
| 4458 | } |
| 4459 | // Save results |
| 4460 | Built.Counters[Cnt] = IS.CounterVar; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 4461 | Built.PrivateCounters[Cnt] = IS.PrivateCounterVar; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4462 | Built.Inits[Cnt] = Init.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4463 | Built.Updates[Cnt] = Update.get(); |
| 4464 | Built.Finals[Cnt] = Final.get(); |
| 4465 | } |
| 4466 | } |
| 4467 | |
| 4468 | if (HasErrors) |
| 4469 | return 0; |
| 4470 | |
| 4471 | // Save results |
| 4472 | Built.IterationVarRef = IV.get(); |
| 4473 | Built.LastIteration = LastIteration.get(); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 4474 | Built.NumIterations = NumIterations.get(); |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 4475 | Built.CalcLastIteration = |
| 4476 | SemaRef.ActOnFinishFullExpr(CalcLastIteration.get()).get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4477 | Built.PreCond = PreCond.get(); |
| 4478 | Built.Cond = Cond.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4479 | Built.Init = Init.get(); |
| 4480 | Built.Inc = Inc.get(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4481 | Built.LB = LB.get(); |
| 4482 | Built.UB = UB.get(); |
| 4483 | Built.IL = IL.get(); |
| 4484 | Built.ST = ST.get(); |
| 4485 | Built.EUB = EUB.get(); |
| 4486 | Built.NLB = NextLB.get(); |
| 4487 | Built.NUB = NextUB.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4488 | |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 4489 | return NestedLoopCount; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4490 | } |
| 4491 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4492 | static Expr *getCollapseNumberExpr(ArrayRef<OMPClause *> Clauses) { |
Benjamin Kramer | fc600dc | 2015-08-30 15:12:28 +0000 | [diff] [blame] | 4493 | auto CollapseClauses = |
| 4494 | OMPExecutableDirective::getClausesOfKind<OMPCollapseClause>(Clauses); |
| 4495 | if (CollapseClauses.begin() != CollapseClauses.end()) |
| 4496 | return (*CollapseClauses.begin())->getNumForLoops(); |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 4497 | return nullptr; |
| 4498 | } |
| 4499 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4500 | static Expr *getOrderedNumberExpr(ArrayRef<OMPClause *> Clauses) { |
Benjamin Kramer | fc600dc | 2015-08-30 15:12:28 +0000 | [diff] [blame] | 4501 | auto OrderedClauses = |
| 4502 | OMPExecutableDirective::getClausesOfKind<OMPOrderedClause>(Clauses); |
| 4503 | if (OrderedClauses.begin() != OrderedClauses.end()) |
| 4504 | return (*OrderedClauses.begin())->getNumForLoops(); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4505 | return nullptr; |
| 4506 | } |
| 4507 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 4508 | static bool checkSimdlenSafelenValues(Sema &S, const Expr *Simdlen, |
| 4509 | const Expr *Safelen) { |
| 4510 | llvm::APSInt SimdlenRes, SafelenRes; |
| 4511 | if (Simdlen->isValueDependent() || Simdlen->isTypeDependent() || |
| 4512 | Simdlen->isInstantiationDependent() || |
| 4513 | Simdlen->containsUnexpandedParameterPack()) |
| 4514 | return false; |
| 4515 | if (Safelen->isValueDependent() || Safelen->isTypeDependent() || |
| 4516 | Safelen->isInstantiationDependent() || |
| 4517 | Safelen->containsUnexpandedParameterPack()) |
| 4518 | return false; |
| 4519 | Simdlen->EvaluateAsInt(SimdlenRes, S.Context); |
| 4520 | Safelen->EvaluateAsInt(SafelenRes, S.Context); |
| 4521 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 4522 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 4523 | // parameter must be less than or equal to the value of the safelen parameter. |
| 4524 | if (SimdlenRes > SafelenRes) { |
| 4525 | S.Diag(Simdlen->getExprLoc(), diag::err_omp_wrong_simdlen_safelen_values) |
| 4526 | << Simdlen->getSourceRange() << Safelen->getSourceRange(); |
| 4527 | return true; |
| 4528 | } |
| 4529 | return false; |
| 4530 | } |
| 4531 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4532 | StmtResult Sema::ActOnOpenMPSimdDirective( |
| 4533 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4534 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 4535 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4536 | if (!AStmt) |
| 4537 | return StmtError(); |
| 4538 | |
| 4539 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4540 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4541 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4542 | // define the nested loops number. |
| 4543 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 4544 | OMPD_simd, getCollapseNumberExpr(Clauses), getOrderedNumberExpr(Clauses), |
| 4545 | AStmt, *this, *DSAStack, VarsWithImplicitDSA, B); |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 4546 | if (NestedLoopCount == 0) |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 4547 | return StmtError(); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 4548 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4549 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 4550 | "omp simd loop exprs were not built"); |
| 4551 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 4552 | if (!CurContext->isDependentContext()) { |
| 4553 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4554 | for (auto C : Clauses) { |
| 4555 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 4556 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 4557 | B.NumIterations, *this, CurScope)) |
| 4558 | return StmtError(); |
| 4559 | } |
| 4560 | } |
| 4561 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 4562 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 4563 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 4564 | // parameter must be less than or equal to the value of the safelen parameter. |
| 4565 | OMPSafelenClause *Safelen = nullptr; |
| 4566 | OMPSimdlenClause *Simdlen = nullptr; |
| 4567 | for (auto *Clause : Clauses) { |
| 4568 | if (Clause->getClauseKind() == OMPC_safelen) |
| 4569 | Safelen = cast<OMPSafelenClause>(Clause); |
| 4570 | else if (Clause->getClauseKind() == OMPC_simdlen) |
| 4571 | Simdlen = cast<OMPSimdlenClause>(Clause); |
| 4572 | if (Safelen && Simdlen) |
| 4573 | break; |
| 4574 | } |
| 4575 | if (Simdlen && Safelen && |
| 4576 | checkSimdlenSafelenValues(*this, Simdlen->getSimdlen(), |
| 4577 | Safelen->getSafelen())) |
| 4578 | return StmtError(); |
| 4579 | |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 4580 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4581 | return OMPSimdDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| 4582 | Clauses, AStmt, B); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 4583 | } |
| 4584 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4585 | StmtResult Sema::ActOnOpenMPForDirective( |
| 4586 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4587 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 4588 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4589 | if (!AStmt) |
| 4590 | return StmtError(); |
| 4591 | |
| 4592 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4593 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4594 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4595 | // define the nested loops number. |
| 4596 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 4597 | OMPD_for, getCollapseNumberExpr(Clauses), getOrderedNumberExpr(Clauses), |
| 4598 | AStmt, *this, *DSAStack, VarsWithImplicitDSA, B); |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 4599 | if (NestedLoopCount == 0) |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4600 | return StmtError(); |
| 4601 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4602 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 4603 | "omp for loop exprs were not built"); |
| 4604 | |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 4605 | if (!CurContext->isDependentContext()) { |
| 4606 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4607 | for (auto C : Clauses) { |
| 4608 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 4609 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 4610 | B.NumIterations, *this, CurScope)) |
| 4611 | return StmtError(); |
| 4612 | } |
| 4613 | } |
| 4614 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4615 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4616 | return OMPForDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4617 | Clauses, AStmt, B, DSAStack->isCancelRegion()); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4618 | } |
| 4619 | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4620 | StmtResult Sema::ActOnOpenMPForSimdDirective( |
| 4621 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4622 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 4623 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4624 | if (!AStmt) |
| 4625 | return StmtError(); |
| 4626 | |
| 4627 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4628 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4629 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4630 | // define the nested loops number. |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4631 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4632 | CheckOpenMPLoop(OMPD_for_simd, getCollapseNumberExpr(Clauses), |
| 4633 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 4634 | VarsWithImplicitDSA, B); |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4635 | if (NestedLoopCount == 0) |
| 4636 | return StmtError(); |
| 4637 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4638 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 4639 | "omp for simd loop exprs were not built"); |
| 4640 | |
Alexey Bataev | 58e5bdb | 2015-06-18 04:45:29 +0000 | [diff] [blame] | 4641 | if (!CurContext->isDependentContext()) { |
| 4642 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4643 | for (auto C : Clauses) { |
| 4644 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 4645 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 4646 | B.NumIterations, *this, CurScope)) |
| 4647 | return StmtError(); |
| 4648 | } |
| 4649 | } |
| 4650 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 4651 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 4652 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 4653 | // parameter must be less than or equal to the value of the safelen parameter. |
| 4654 | OMPSafelenClause *Safelen = nullptr; |
| 4655 | OMPSimdlenClause *Simdlen = nullptr; |
| 4656 | for (auto *Clause : Clauses) { |
| 4657 | if (Clause->getClauseKind() == OMPC_safelen) |
| 4658 | Safelen = cast<OMPSafelenClause>(Clause); |
| 4659 | else if (Clause->getClauseKind() == OMPC_simdlen) |
| 4660 | Simdlen = cast<OMPSimdlenClause>(Clause); |
| 4661 | if (Safelen && Simdlen) |
| 4662 | break; |
| 4663 | } |
| 4664 | if (Simdlen && Safelen && |
| 4665 | checkSimdlenSafelenValues(*this, Simdlen->getSimdlen(), |
| 4666 | Safelen->getSafelen())) |
| 4667 | return StmtError(); |
| 4668 | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4669 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4670 | return OMPForSimdDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| 4671 | Clauses, AStmt, B); |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4672 | } |
| 4673 | |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4674 | StmtResult Sema::ActOnOpenMPSectionsDirective(ArrayRef<OMPClause *> Clauses, |
| 4675 | Stmt *AStmt, |
| 4676 | SourceLocation StartLoc, |
| 4677 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4678 | if (!AStmt) |
| 4679 | return StmtError(); |
| 4680 | |
| 4681 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4682 | auto BaseStmt = AStmt; |
| 4683 | while (CapturedStmt *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt)) |
| 4684 | BaseStmt = CS->getCapturedStmt(); |
| 4685 | if (auto C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) { |
| 4686 | auto S = C->children(); |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 4687 | if (S.begin() == S.end()) |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4688 | return StmtError(); |
| 4689 | // All associated statements must be '#pragma omp section' except for |
| 4690 | // the first one. |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 4691 | for (Stmt *SectionStmt : llvm::make_range(std::next(S.begin()), S.end())) { |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4692 | if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) { |
| 4693 | if (SectionStmt) |
| 4694 | Diag(SectionStmt->getLocStart(), |
| 4695 | diag::err_omp_sections_substmt_not_section); |
| 4696 | return StmtError(); |
| 4697 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4698 | cast<OMPSectionDirective>(SectionStmt) |
| 4699 | ->setHasCancel(DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4700 | } |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4701 | } else { |
| 4702 | Diag(AStmt->getLocStart(), diag::err_omp_sections_not_compound_stmt); |
| 4703 | return StmtError(); |
| 4704 | } |
| 4705 | |
| 4706 | getCurFunction()->setHasBranchProtectedScope(); |
| 4707 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4708 | return OMPSectionsDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 4709 | DSAStack->isCancelRegion()); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4710 | } |
| 4711 | |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4712 | StmtResult Sema::ActOnOpenMPSectionDirective(Stmt *AStmt, |
| 4713 | SourceLocation StartLoc, |
| 4714 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4715 | if (!AStmt) |
| 4716 | return StmtError(); |
| 4717 | |
| 4718 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4719 | |
| 4720 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4721 | DSAStack->setParentCancelRegion(DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4722 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4723 | return OMPSectionDirective::Create(Context, StartLoc, EndLoc, AStmt, |
| 4724 | DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4725 | } |
| 4726 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 4727 | StmtResult Sema::ActOnOpenMPSingleDirective(ArrayRef<OMPClause *> Clauses, |
| 4728 | Stmt *AStmt, |
| 4729 | SourceLocation StartLoc, |
| 4730 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4731 | if (!AStmt) |
| 4732 | return StmtError(); |
| 4733 | |
| 4734 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 74a05c9 | 2014-07-15 02:55:09 +0000 | [diff] [blame] | 4735 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 4736 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | 74a05c9 | 2014-07-15 02:55:09 +0000 | [diff] [blame] | 4737 | |
Alexey Bataev | 3255bf3 | 2015-01-19 05:20:46 +0000 | [diff] [blame] | 4738 | // OpenMP [2.7.3, single Construct, Restrictions] |
| 4739 | // The copyprivate clause must not be used with the nowait clause. |
| 4740 | OMPClause *Nowait = nullptr; |
| 4741 | OMPClause *Copyprivate = nullptr; |
| 4742 | for (auto *Clause : Clauses) { |
| 4743 | if (Clause->getClauseKind() == OMPC_nowait) |
| 4744 | Nowait = Clause; |
| 4745 | else if (Clause->getClauseKind() == OMPC_copyprivate) |
| 4746 | Copyprivate = Clause; |
| 4747 | if (Copyprivate && Nowait) { |
| 4748 | Diag(Copyprivate->getLocStart(), |
| 4749 | diag::err_omp_single_copyprivate_with_nowait); |
| 4750 | Diag(Nowait->getLocStart(), diag::note_omp_nowait_clause_here); |
| 4751 | return StmtError(); |
| 4752 | } |
| 4753 | } |
| 4754 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 4755 | return OMPSingleDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 4756 | } |
| 4757 | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 4758 | StmtResult Sema::ActOnOpenMPMasterDirective(Stmt *AStmt, |
| 4759 | SourceLocation StartLoc, |
| 4760 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4761 | if (!AStmt) |
| 4762 | return StmtError(); |
| 4763 | |
| 4764 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 4765 | |
| 4766 | getCurFunction()->setHasBranchProtectedScope(); |
| 4767 | |
| 4768 | return OMPMasterDirective::Create(Context, StartLoc, EndLoc, AStmt); |
| 4769 | } |
| 4770 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 4771 | StmtResult Sema::ActOnOpenMPCriticalDirective( |
| 4772 | const DeclarationNameInfo &DirName, ArrayRef<OMPClause *> Clauses, |
| 4773 | Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4774 | if (!AStmt) |
| 4775 | return StmtError(); |
| 4776 | |
| 4777 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 4778 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 4779 | bool ErrorFound = false; |
| 4780 | llvm::APSInt Hint; |
| 4781 | SourceLocation HintLoc; |
| 4782 | bool DependentHint = false; |
| 4783 | for (auto *C : Clauses) { |
| 4784 | if (C->getClauseKind() == OMPC_hint) { |
| 4785 | if (!DirName.getName()) { |
| 4786 | Diag(C->getLocStart(), diag::err_omp_hint_clause_no_name); |
| 4787 | ErrorFound = true; |
| 4788 | } |
| 4789 | Expr *E = cast<OMPHintClause>(C)->getHint(); |
| 4790 | if (E->isTypeDependent() || E->isValueDependent() || |
| 4791 | E->isInstantiationDependent()) |
| 4792 | DependentHint = true; |
| 4793 | else { |
| 4794 | Hint = E->EvaluateKnownConstInt(Context); |
| 4795 | HintLoc = C->getLocStart(); |
| 4796 | } |
| 4797 | } |
| 4798 | } |
| 4799 | if (ErrorFound) |
| 4800 | return StmtError(); |
| 4801 | auto Pair = DSAStack->getCriticalWithHint(DirName); |
| 4802 | if (Pair.first && DirName.getName() && !DependentHint) { |
| 4803 | if (llvm::APSInt::compareValues(Hint, Pair.second) != 0) { |
| 4804 | Diag(StartLoc, diag::err_omp_critical_with_hint); |
| 4805 | if (HintLoc.isValid()) { |
| 4806 | Diag(HintLoc, diag::note_omp_critical_hint_here) |
| 4807 | << 0 << Hint.toString(/*Radix=*/10, /*Signed=*/false); |
| 4808 | } else |
| 4809 | Diag(StartLoc, diag::note_omp_critical_no_hint) << 0; |
| 4810 | if (auto *C = Pair.first->getSingleClause<OMPHintClause>()) { |
| 4811 | Diag(C->getLocStart(), diag::note_omp_critical_hint_here) |
| 4812 | << 1 |
| 4813 | << C->getHint()->EvaluateKnownConstInt(Context).toString( |
| 4814 | /*Radix=*/10, /*Signed=*/false); |
| 4815 | } else |
| 4816 | Diag(Pair.first->getLocStart(), diag::note_omp_critical_no_hint) << 1; |
| 4817 | } |
| 4818 | } |
| 4819 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 4820 | getCurFunction()->setHasBranchProtectedScope(); |
| 4821 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 4822 | auto *Dir = OMPCriticalDirective::Create(Context, DirName, StartLoc, EndLoc, |
| 4823 | Clauses, AStmt); |
| 4824 | if (!Pair.first && DirName.getName() && !DependentHint) |
| 4825 | DSAStack->addCriticalWithHint(Dir, Hint); |
| 4826 | return Dir; |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 4827 | } |
| 4828 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4829 | StmtResult Sema::ActOnOpenMPParallelForDirective( |
| 4830 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4831 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 4832 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4833 | if (!AStmt) |
| 4834 | return StmtError(); |
| 4835 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4836 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 4837 | // 1.2.2 OpenMP Language Terminology |
| 4838 | // Structured block - An executable statement with a single entry at the |
| 4839 | // top and a single exit at the bottom. |
| 4840 | // The point of exit cannot be a branch out of the structured block. |
| 4841 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 4842 | CS->getCapturedDecl()->setNothrow(); |
| 4843 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4844 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4845 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4846 | // define the nested loops number. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4847 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4848 | CheckOpenMPLoop(OMPD_parallel_for, getCollapseNumberExpr(Clauses), |
| 4849 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 4850 | VarsWithImplicitDSA, B); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4851 | if (NestedLoopCount == 0) |
| 4852 | return StmtError(); |
| 4853 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4854 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 4855 | "omp parallel for loop exprs were not built"); |
| 4856 | |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 4857 | if (!CurContext->isDependentContext()) { |
| 4858 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4859 | for (auto C : Clauses) { |
| 4860 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 4861 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 4862 | B.NumIterations, *this, CurScope)) |
| 4863 | return StmtError(); |
| 4864 | } |
| 4865 | } |
| 4866 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4867 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4868 | return OMPParallelForDirective::Create(Context, StartLoc, EndLoc, |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4869 | NestedLoopCount, Clauses, AStmt, B, |
| 4870 | DSAStack->isCancelRegion()); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4871 | } |
| 4872 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4873 | StmtResult Sema::ActOnOpenMPParallelForSimdDirective( |
| 4874 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4875 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 4876 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4877 | if (!AStmt) |
| 4878 | return StmtError(); |
| 4879 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4880 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 4881 | // 1.2.2 OpenMP Language Terminology |
| 4882 | // Structured block - An executable statement with a single entry at the |
| 4883 | // top and a single exit at the bottom. |
| 4884 | // The point of exit cannot be a branch out of the structured block. |
| 4885 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 4886 | CS->getCapturedDecl()->setNothrow(); |
| 4887 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4888 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4889 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4890 | // define the nested loops number. |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4891 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4892 | CheckOpenMPLoop(OMPD_parallel_for_simd, getCollapseNumberExpr(Clauses), |
| 4893 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 4894 | VarsWithImplicitDSA, B); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4895 | if (NestedLoopCount == 0) |
| 4896 | return StmtError(); |
| 4897 | |
Alexey Bataev | 3b5b5c4 | 2015-06-18 10:10:12 +0000 | [diff] [blame] | 4898 | if (!CurContext->isDependentContext()) { |
| 4899 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4900 | for (auto C : Clauses) { |
| 4901 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 4902 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 4903 | B.NumIterations, *this, CurScope)) |
| 4904 | return StmtError(); |
| 4905 | } |
| 4906 | } |
| 4907 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 4908 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 4909 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 4910 | // parameter must be less than or equal to the value of the safelen parameter. |
| 4911 | OMPSafelenClause *Safelen = nullptr; |
| 4912 | OMPSimdlenClause *Simdlen = nullptr; |
| 4913 | for (auto *Clause : Clauses) { |
| 4914 | if (Clause->getClauseKind() == OMPC_safelen) |
| 4915 | Safelen = cast<OMPSafelenClause>(Clause); |
| 4916 | else if (Clause->getClauseKind() == OMPC_simdlen) |
| 4917 | Simdlen = cast<OMPSimdlenClause>(Clause); |
| 4918 | if (Safelen && Simdlen) |
| 4919 | break; |
| 4920 | } |
| 4921 | if (Simdlen && Safelen && |
| 4922 | checkSimdlenSafelenValues(*this, Simdlen->getSimdlen(), |
| 4923 | Safelen->getSafelen())) |
| 4924 | return StmtError(); |
| 4925 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4926 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4927 | return OMPParallelForSimdDirective::Create( |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4928 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4929 | } |
| 4930 | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4931 | StmtResult |
| 4932 | Sema::ActOnOpenMPParallelSectionsDirective(ArrayRef<OMPClause *> Clauses, |
| 4933 | Stmt *AStmt, SourceLocation StartLoc, |
| 4934 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4935 | if (!AStmt) |
| 4936 | return StmtError(); |
| 4937 | |
| 4938 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4939 | auto BaseStmt = AStmt; |
| 4940 | while (CapturedStmt *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt)) |
| 4941 | BaseStmt = CS->getCapturedStmt(); |
| 4942 | if (auto C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) { |
| 4943 | auto S = C->children(); |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 4944 | if (S.begin() == S.end()) |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4945 | return StmtError(); |
| 4946 | // All associated statements must be '#pragma omp section' except for |
| 4947 | // the first one. |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 4948 | for (Stmt *SectionStmt : llvm::make_range(std::next(S.begin()), S.end())) { |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4949 | if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) { |
| 4950 | if (SectionStmt) |
| 4951 | Diag(SectionStmt->getLocStart(), |
| 4952 | diag::err_omp_parallel_sections_substmt_not_section); |
| 4953 | return StmtError(); |
| 4954 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4955 | cast<OMPSectionDirective>(SectionStmt) |
| 4956 | ->setHasCancel(DSAStack->isCancelRegion()); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4957 | } |
| 4958 | } else { |
| 4959 | Diag(AStmt->getLocStart(), |
| 4960 | diag::err_omp_parallel_sections_not_compound_stmt); |
| 4961 | return StmtError(); |
| 4962 | } |
| 4963 | |
| 4964 | getCurFunction()->setHasBranchProtectedScope(); |
| 4965 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4966 | return OMPParallelSectionsDirective::Create( |
| 4967 | Context, StartLoc, EndLoc, Clauses, AStmt, DSAStack->isCancelRegion()); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4968 | } |
| 4969 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 4970 | StmtResult Sema::ActOnOpenMPTaskDirective(ArrayRef<OMPClause *> Clauses, |
| 4971 | Stmt *AStmt, SourceLocation StartLoc, |
| 4972 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4973 | if (!AStmt) |
| 4974 | return StmtError(); |
| 4975 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 4976 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 4977 | // 1.2.2 OpenMP Language Terminology |
| 4978 | // Structured block - An executable statement with a single entry at the |
| 4979 | // top and a single exit at the bottom. |
| 4980 | // The point of exit cannot be a branch out of the structured block. |
| 4981 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 4982 | CS->getCapturedDecl()->setNothrow(); |
| 4983 | |
| 4984 | getCurFunction()->setHasBranchProtectedScope(); |
| 4985 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4986 | return OMPTaskDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 4987 | DSAStack->isCancelRegion()); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 4988 | } |
| 4989 | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 4990 | StmtResult Sema::ActOnOpenMPTaskyieldDirective(SourceLocation StartLoc, |
| 4991 | SourceLocation EndLoc) { |
| 4992 | return OMPTaskyieldDirective::Create(Context, StartLoc, EndLoc); |
| 4993 | } |
| 4994 | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 4995 | StmtResult Sema::ActOnOpenMPBarrierDirective(SourceLocation StartLoc, |
| 4996 | SourceLocation EndLoc) { |
| 4997 | return OMPBarrierDirective::Create(Context, StartLoc, EndLoc); |
| 4998 | } |
| 4999 | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 5000 | StmtResult Sema::ActOnOpenMPTaskwaitDirective(SourceLocation StartLoc, |
| 5001 | SourceLocation EndLoc) { |
| 5002 | return OMPTaskwaitDirective::Create(Context, StartLoc, EndLoc); |
| 5003 | } |
| 5004 | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 5005 | StmtResult Sema::ActOnOpenMPTaskgroupDirective(Stmt *AStmt, |
| 5006 | SourceLocation StartLoc, |
| 5007 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5008 | if (!AStmt) |
| 5009 | return StmtError(); |
| 5010 | |
| 5011 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 5012 | |
| 5013 | getCurFunction()->setHasBranchProtectedScope(); |
| 5014 | |
| 5015 | return OMPTaskgroupDirective::Create(Context, StartLoc, EndLoc, AStmt); |
| 5016 | } |
| 5017 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 5018 | StmtResult Sema::ActOnOpenMPFlushDirective(ArrayRef<OMPClause *> Clauses, |
| 5019 | SourceLocation StartLoc, |
| 5020 | SourceLocation EndLoc) { |
| 5021 | assert(Clauses.size() <= 1 && "Extra clauses in flush directive"); |
| 5022 | return OMPFlushDirective::Create(Context, StartLoc, EndLoc, Clauses); |
| 5023 | } |
| 5024 | |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5025 | StmtResult Sema::ActOnOpenMPOrderedDirective(ArrayRef<OMPClause *> Clauses, |
| 5026 | Stmt *AStmt, |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 5027 | SourceLocation StartLoc, |
| 5028 | SourceLocation EndLoc) { |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5029 | OMPClause *DependFound = nullptr; |
| 5030 | OMPClause *DependSourceClause = nullptr; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 5031 | OMPClause *DependSinkClause = nullptr; |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5032 | bool ErrorFound = false; |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5033 | OMPThreadsClause *TC = nullptr; |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5034 | OMPSIMDClause *SC = nullptr; |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5035 | for (auto *C : Clauses) { |
| 5036 | if (auto *DC = dyn_cast<OMPDependClause>(C)) { |
| 5037 | DependFound = C; |
| 5038 | if (DC->getDependencyKind() == OMPC_DEPEND_source) { |
| 5039 | if (DependSourceClause) { |
| 5040 | Diag(C->getLocStart(), diag::err_omp_more_one_clause) |
| 5041 | << getOpenMPDirectiveName(OMPD_ordered) |
| 5042 | << getOpenMPClauseName(OMPC_depend) << 2; |
| 5043 | ErrorFound = true; |
| 5044 | } else |
| 5045 | DependSourceClause = C; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 5046 | if (DependSinkClause) { |
| 5047 | Diag(C->getLocStart(), diag::err_omp_depend_sink_source_not_allowed) |
| 5048 | << 0; |
| 5049 | ErrorFound = true; |
| 5050 | } |
| 5051 | } else if (DC->getDependencyKind() == OMPC_DEPEND_sink) { |
| 5052 | if (DependSourceClause) { |
| 5053 | Diag(C->getLocStart(), diag::err_omp_depend_sink_source_not_allowed) |
| 5054 | << 1; |
| 5055 | ErrorFound = true; |
| 5056 | } |
| 5057 | DependSinkClause = C; |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5058 | } |
| 5059 | } else if (C->getClauseKind() == OMPC_threads) |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5060 | TC = cast<OMPThreadsClause>(C); |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5061 | else if (C->getClauseKind() == OMPC_simd) |
| 5062 | SC = cast<OMPSIMDClause>(C); |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5063 | } |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5064 | if (!ErrorFound && !SC && |
| 5065 | isOpenMPSimdDirective(DSAStack->getParentDirective())) { |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5066 | // OpenMP [2.8.1,simd Construct, Restrictions] |
| 5067 | // An ordered construct with the simd clause is the only OpenMP construct |
| 5068 | // that can appear in the simd region. |
| 5069 | Diag(StartLoc, diag::err_omp_prohibited_region_simd); |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5070 | ErrorFound = true; |
| 5071 | } else if (DependFound && (TC || SC)) { |
| 5072 | Diag(DependFound->getLocStart(), diag::err_omp_depend_clause_thread_simd) |
| 5073 | << getOpenMPClauseName(TC ? TC->getClauseKind() : SC->getClauseKind()); |
| 5074 | ErrorFound = true; |
| 5075 | } else if (DependFound && !DSAStack->getParentOrderedRegionParam()) { |
| 5076 | Diag(DependFound->getLocStart(), |
| 5077 | diag::err_omp_ordered_directive_without_param); |
| 5078 | ErrorFound = true; |
| 5079 | } else if (TC || Clauses.empty()) { |
| 5080 | if (auto *Param = DSAStack->getParentOrderedRegionParam()) { |
| 5081 | SourceLocation ErrLoc = TC ? TC->getLocStart() : StartLoc; |
| 5082 | Diag(ErrLoc, diag::err_omp_ordered_directive_with_param) |
| 5083 | << (TC != nullptr); |
| 5084 | Diag(Param->getLocStart(), diag::note_omp_ordered_param); |
| 5085 | ErrorFound = true; |
| 5086 | } |
| 5087 | } |
| 5088 | if ((!AStmt && !DependFound) || ErrorFound) |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5089 | return StmtError(); |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5090 | |
| 5091 | if (AStmt) { |
| 5092 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 5093 | |
| 5094 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5095 | } |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5096 | |
| 5097 | return OMPOrderedDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 5098 | } |
| 5099 | |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5100 | namespace { |
| 5101 | /// \brief Helper class for checking expression in 'omp atomic [update]' |
| 5102 | /// construct. |
| 5103 | class OpenMPAtomicUpdateChecker { |
| 5104 | /// \brief Error results for atomic update expressions. |
| 5105 | enum ExprAnalysisErrorCode { |
| 5106 | /// \brief A statement is not an expression statement. |
| 5107 | NotAnExpression, |
| 5108 | /// \brief Expression is not builtin binary or unary operation. |
| 5109 | NotABinaryOrUnaryExpression, |
| 5110 | /// \brief Unary operation is not post-/pre- increment/decrement operation. |
| 5111 | NotAnUnaryIncDecExpression, |
| 5112 | /// \brief An expression is not of scalar type. |
| 5113 | NotAScalarType, |
| 5114 | /// \brief A binary operation is not an assignment operation. |
| 5115 | NotAnAssignmentOp, |
| 5116 | /// \brief RHS part of the binary operation is not a binary expression. |
| 5117 | NotABinaryExpression, |
| 5118 | /// \brief RHS part is not additive/multiplicative/shift/biwise binary |
| 5119 | /// expression. |
| 5120 | NotABinaryOperator, |
| 5121 | /// \brief RHS binary operation does not have reference to the updated LHS |
| 5122 | /// part. |
| 5123 | NotAnUpdateExpression, |
| 5124 | /// \brief No errors is found. |
| 5125 | NoError |
| 5126 | }; |
| 5127 | /// \brief Reference to Sema. |
| 5128 | Sema &SemaRef; |
| 5129 | /// \brief A location for note diagnostics (when error is found). |
| 5130 | SourceLocation NoteLoc; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5131 | /// \brief 'x' lvalue part of the source atomic expression. |
| 5132 | Expr *X; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5133 | /// \brief 'expr' rvalue part of the source atomic expression. |
| 5134 | Expr *E; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5135 | /// \brief Helper expression of the form |
| 5136 | /// 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or |
| 5137 | /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'. |
| 5138 | Expr *UpdateExpr; |
| 5139 | /// \brief Is 'x' a LHS in a RHS part of full update expression. It is |
| 5140 | /// important for non-associative operations. |
| 5141 | bool IsXLHSInRHSPart; |
| 5142 | BinaryOperatorKind Op; |
| 5143 | SourceLocation OpLoc; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5144 | /// \brief true if the source expression is a postfix unary operation, false |
| 5145 | /// if it is a prefix unary operation. |
| 5146 | bool IsPostfixUpdate; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5147 | |
| 5148 | public: |
| 5149 | OpenMPAtomicUpdateChecker(Sema &SemaRef) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5150 | : SemaRef(SemaRef), X(nullptr), E(nullptr), UpdateExpr(nullptr), |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5151 | IsXLHSInRHSPart(false), Op(BO_PtrMemD), IsPostfixUpdate(false) {} |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5152 | /// \brief Check specified statement that it is suitable for 'atomic update' |
| 5153 | /// constructs and extract 'x', 'expr' and Operation from the original |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5154 | /// expression. If DiagId and NoteId == 0, then only check is performed |
| 5155 | /// without error notification. |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5156 | /// \param DiagId Diagnostic which should be emitted if error is found. |
| 5157 | /// \param NoteId Diagnostic note for the main error message. |
| 5158 | /// \return true if statement is not an update expression, false otherwise. |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5159 | bool checkStatement(Stmt *S, unsigned DiagId = 0, unsigned NoteId = 0); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5160 | /// \brief Return the 'x' lvalue part of the source atomic expression. |
| 5161 | Expr *getX() const { return X; } |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5162 | /// \brief Return the 'expr' rvalue part of the source atomic expression. |
| 5163 | Expr *getExpr() const { return E; } |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5164 | /// \brief Return the update expression used in calculation of the updated |
| 5165 | /// value. Always has form 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or |
| 5166 | /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'. |
| 5167 | Expr *getUpdateExpr() const { return UpdateExpr; } |
| 5168 | /// \brief Return true if 'x' is LHS in RHS part of full update expression, |
| 5169 | /// false otherwise. |
| 5170 | bool isXLHSInRHSPart() const { return IsXLHSInRHSPart; } |
| 5171 | |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5172 | /// \brief true if the source expression is a postfix unary operation, false |
| 5173 | /// if it is a prefix unary operation. |
| 5174 | bool isPostfixUpdate() const { return IsPostfixUpdate; } |
| 5175 | |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5176 | private: |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5177 | bool checkBinaryOperation(BinaryOperator *AtomicBinOp, unsigned DiagId = 0, |
| 5178 | unsigned NoteId = 0); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5179 | }; |
| 5180 | } // namespace |
| 5181 | |
| 5182 | bool OpenMPAtomicUpdateChecker::checkBinaryOperation( |
| 5183 | BinaryOperator *AtomicBinOp, unsigned DiagId, unsigned NoteId) { |
| 5184 | ExprAnalysisErrorCode ErrorFound = NoError; |
| 5185 | SourceLocation ErrorLoc, NoteLoc; |
| 5186 | SourceRange ErrorRange, NoteRange; |
| 5187 | // Allowed constructs are: |
| 5188 | // x = x binop expr; |
| 5189 | // x = expr binop x; |
| 5190 | if (AtomicBinOp->getOpcode() == BO_Assign) { |
| 5191 | X = AtomicBinOp->getLHS(); |
| 5192 | if (auto *AtomicInnerBinOp = dyn_cast<BinaryOperator>( |
| 5193 | AtomicBinOp->getRHS()->IgnoreParenImpCasts())) { |
| 5194 | if (AtomicInnerBinOp->isMultiplicativeOp() || |
| 5195 | AtomicInnerBinOp->isAdditiveOp() || AtomicInnerBinOp->isShiftOp() || |
| 5196 | AtomicInnerBinOp->isBitwiseOp()) { |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5197 | Op = AtomicInnerBinOp->getOpcode(); |
| 5198 | OpLoc = AtomicInnerBinOp->getOperatorLoc(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5199 | auto *LHS = AtomicInnerBinOp->getLHS(); |
| 5200 | auto *RHS = AtomicInnerBinOp->getRHS(); |
| 5201 | llvm::FoldingSetNodeID XId, LHSId, RHSId; |
| 5202 | X->IgnoreParenImpCasts()->Profile(XId, SemaRef.getASTContext(), |
| 5203 | /*Canonical=*/true); |
| 5204 | LHS->IgnoreParenImpCasts()->Profile(LHSId, SemaRef.getASTContext(), |
| 5205 | /*Canonical=*/true); |
| 5206 | RHS->IgnoreParenImpCasts()->Profile(RHSId, SemaRef.getASTContext(), |
| 5207 | /*Canonical=*/true); |
| 5208 | if (XId == LHSId) { |
| 5209 | E = RHS; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5210 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5211 | } else if (XId == RHSId) { |
| 5212 | E = LHS; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5213 | IsXLHSInRHSPart = false; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5214 | } else { |
| 5215 | ErrorLoc = AtomicInnerBinOp->getExprLoc(); |
| 5216 | ErrorRange = AtomicInnerBinOp->getSourceRange(); |
| 5217 | NoteLoc = X->getExprLoc(); |
| 5218 | NoteRange = X->getSourceRange(); |
| 5219 | ErrorFound = NotAnUpdateExpression; |
| 5220 | } |
| 5221 | } else { |
| 5222 | ErrorLoc = AtomicInnerBinOp->getExprLoc(); |
| 5223 | ErrorRange = AtomicInnerBinOp->getSourceRange(); |
| 5224 | NoteLoc = AtomicInnerBinOp->getOperatorLoc(); |
| 5225 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 5226 | ErrorFound = NotABinaryOperator; |
| 5227 | } |
| 5228 | } else { |
| 5229 | NoteLoc = ErrorLoc = AtomicBinOp->getRHS()->getExprLoc(); |
| 5230 | NoteRange = ErrorRange = AtomicBinOp->getRHS()->getSourceRange(); |
| 5231 | ErrorFound = NotABinaryExpression; |
| 5232 | } |
| 5233 | } else { |
| 5234 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5235 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5236 | NoteLoc = AtomicBinOp->getOperatorLoc(); |
| 5237 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 5238 | ErrorFound = NotAnAssignmentOp; |
| 5239 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5240 | if (ErrorFound != NoError && DiagId != 0 && NoteId != 0) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5241 | SemaRef.Diag(ErrorLoc, DiagId) << ErrorRange; |
| 5242 | SemaRef.Diag(NoteLoc, NoteId) << ErrorFound << NoteRange; |
| 5243 | return true; |
| 5244 | } else if (SemaRef.CurContext->isDependentContext()) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5245 | E = X = UpdateExpr = nullptr; |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5246 | return ErrorFound != NoError; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5247 | } |
| 5248 | |
| 5249 | bool OpenMPAtomicUpdateChecker::checkStatement(Stmt *S, unsigned DiagId, |
| 5250 | unsigned NoteId) { |
| 5251 | ExprAnalysisErrorCode ErrorFound = NoError; |
| 5252 | SourceLocation ErrorLoc, NoteLoc; |
| 5253 | SourceRange ErrorRange, NoteRange; |
| 5254 | // Allowed constructs are: |
| 5255 | // x++; |
| 5256 | // x--; |
| 5257 | // ++x; |
| 5258 | // --x; |
| 5259 | // x binop= expr; |
| 5260 | // x = x binop expr; |
| 5261 | // x = expr binop x; |
| 5262 | if (auto *AtomicBody = dyn_cast<Expr>(S)) { |
| 5263 | AtomicBody = AtomicBody->IgnoreParenImpCasts(); |
| 5264 | if (AtomicBody->getType()->isScalarType() || |
| 5265 | AtomicBody->isInstantiationDependent()) { |
| 5266 | if (auto *AtomicCompAssignOp = dyn_cast<CompoundAssignOperator>( |
| 5267 | AtomicBody->IgnoreParenImpCasts())) { |
| 5268 | // Check for Compound Assignment Operation |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5269 | Op = BinaryOperator::getOpForCompoundAssignment( |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5270 | AtomicCompAssignOp->getOpcode()); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5271 | OpLoc = AtomicCompAssignOp->getOperatorLoc(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5272 | E = AtomicCompAssignOp->getRHS(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5273 | X = AtomicCompAssignOp->getLHS(); |
| 5274 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5275 | } else if (auto *AtomicBinOp = dyn_cast<BinaryOperator>( |
| 5276 | AtomicBody->IgnoreParenImpCasts())) { |
| 5277 | // Check for Binary Operation |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5278 | if(checkBinaryOperation(AtomicBinOp, DiagId, NoteId)) |
| 5279 | return true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5280 | } else if (auto *AtomicUnaryOp = |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5281 | dyn_cast<UnaryOperator>(AtomicBody->IgnoreParenImpCasts())) { |
| 5282 | // Check for Unary Operation |
| 5283 | if (AtomicUnaryOp->isIncrementDecrementOp()) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5284 | IsPostfixUpdate = AtomicUnaryOp->isPostfix(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5285 | Op = AtomicUnaryOp->isIncrementOp() ? BO_Add : BO_Sub; |
| 5286 | OpLoc = AtomicUnaryOp->getOperatorLoc(); |
| 5287 | X = AtomicUnaryOp->getSubExpr(); |
| 5288 | E = SemaRef.ActOnIntegerConstant(OpLoc, /*uint64_t Val=*/1).get(); |
| 5289 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5290 | } else { |
| 5291 | ErrorFound = NotAnUnaryIncDecExpression; |
| 5292 | ErrorLoc = AtomicUnaryOp->getExprLoc(); |
| 5293 | ErrorRange = AtomicUnaryOp->getSourceRange(); |
| 5294 | NoteLoc = AtomicUnaryOp->getOperatorLoc(); |
| 5295 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 5296 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5297 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5298 | ErrorFound = NotABinaryOrUnaryExpression; |
| 5299 | NoteLoc = ErrorLoc = AtomicBody->getExprLoc(); |
| 5300 | NoteRange = ErrorRange = AtomicBody->getSourceRange(); |
| 5301 | } |
| 5302 | } else { |
| 5303 | ErrorFound = NotAScalarType; |
| 5304 | NoteLoc = ErrorLoc = AtomicBody->getLocStart(); |
| 5305 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
| 5306 | } |
| 5307 | } else { |
| 5308 | ErrorFound = NotAnExpression; |
| 5309 | NoteLoc = ErrorLoc = S->getLocStart(); |
| 5310 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
| 5311 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5312 | if (ErrorFound != NoError && DiagId != 0 && NoteId != 0) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5313 | SemaRef.Diag(ErrorLoc, DiagId) << ErrorRange; |
| 5314 | SemaRef.Diag(NoteLoc, NoteId) << ErrorFound << NoteRange; |
| 5315 | return true; |
| 5316 | } else if (SemaRef.CurContext->isDependentContext()) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5317 | E = X = UpdateExpr = nullptr; |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5318 | if (ErrorFound == NoError && E && X) { |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5319 | // Build an update expression of form 'OpaqueValueExpr(x) binop |
| 5320 | // OpaqueValueExpr(expr)' or 'OpaqueValueExpr(expr) binop |
| 5321 | // OpaqueValueExpr(x)' and then cast it to the type of the 'x' expression. |
| 5322 | auto *OVEX = new (SemaRef.getASTContext()) |
| 5323 | OpaqueValueExpr(X->getExprLoc(), X->getType(), VK_RValue); |
| 5324 | auto *OVEExpr = new (SemaRef.getASTContext()) |
| 5325 | OpaqueValueExpr(E->getExprLoc(), E->getType(), VK_RValue); |
| 5326 | auto Update = |
| 5327 | SemaRef.CreateBuiltinBinOp(OpLoc, Op, IsXLHSInRHSPart ? OVEX : OVEExpr, |
| 5328 | IsXLHSInRHSPart ? OVEExpr : OVEX); |
| 5329 | if (Update.isInvalid()) |
| 5330 | return true; |
| 5331 | Update = SemaRef.PerformImplicitConversion(Update.get(), X->getType(), |
| 5332 | Sema::AA_Casting); |
| 5333 | if (Update.isInvalid()) |
| 5334 | return true; |
| 5335 | UpdateExpr = Update.get(); |
| 5336 | } |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5337 | return ErrorFound != NoError; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5338 | } |
| 5339 | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 5340 | StmtResult Sema::ActOnOpenMPAtomicDirective(ArrayRef<OMPClause *> Clauses, |
| 5341 | Stmt *AStmt, |
| 5342 | SourceLocation StartLoc, |
| 5343 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5344 | if (!AStmt) |
| 5345 | return StmtError(); |
| 5346 | |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5347 | auto CS = cast<CapturedStmt>(AStmt); |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 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. |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5353 | OpenMPClauseKind AtomicKind = OMPC_unknown; |
| 5354 | SourceLocation AtomicKindLoc; |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5355 | for (auto *C : Clauses) { |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5356 | if (C->getClauseKind() == OMPC_read || C->getClauseKind() == OMPC_write || |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5357 | C->getClauseKind() == OMPC_update || |
| 5358 | C->getClauseKind() == OMPC_capture) { |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5359 | if (AtomicKind != OMPC_unknown) { |
| 5360 | Diag(C->getLocStart(), diag::err_omp_atomic_several_clauses) |
| 5361 | << SourceRange(C->getLocStart(), C->getLocEnd()); |
| 5362 | Diag(AtomicKindLoc, diag::note_omp_atomic_previous_clause) |
| 5363 | << getOpenMPClauseName(AtomicKind); |
| 5364 | } else { |
| 5365 | AtomicKind = C->getClauseKind(); |
| 5366 | AtomicKindLoc = C->getLocStart(); |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5367 | } |
| 5368 | } |
| 5369 | } |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5370 | |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5371 | auto Body = CS->getCapturedStmt(); |
Alexey Bataev | 10fec57 | 2015-03-11 04:48:56 +0000 | [diff] [blame] | 5372 | if (auto *EWC = dyn_cast<ExprWithCleanups>(Body)) |
| 5373 | Body = EWC->getSubExpr(); |
| 5374 | |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5375 | Expr *X = nullptr; |
| 5376 | Expr *V = nullptr; |
| 5377 | Expr *E = nullptr; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5378 | Expr *UE = nullptr; |
| 5379 | bool IsXLHSInRHSPart = false; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5380 | bool IsPostfixUpdate = false; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5381 | // OpenMP [2.12.6, atomic Construct] |
| 5382 | // In the next expressions: |
| 5383 | // * x and v (as applicable) are both l-value expressions with scalar type. |
| 5384 | // * During the execution of an atomic region, multiple syntactic |
| 5385 | // occurrences of x must designate the same storage location. |
| 5386 | // * Neither of v and expr (as applicable) may access the storage location |
| 5387 | // designated by x. |
| 5388 | // * Neither of x and expr (as applicable) may access the storage location |
| 5389 | // designated by v. |
| 5390 | // * expr is an expression with scalar type. |
| 5391 | // * binop is one of +, *, -, /, &, ^, |, <<, or >>. |
| 5392 | // * binop, binop=, ++, and -- are not overloaded operators. |
| 5393 | // * The expression x binop expr must be numerically equivalent to x binop |
| 5394 | // (expr). This requirement is satisfied if the operators in expr have |
| 5395 | // precedence greater than binop, or by using parentheses around expr or |
| 5396 | // subexpressions of expr. |
| 5397 | // * The expression expr binop x must be numerically equivalent to (expr) |
| 5398 | // binop x. This requirement is satisfied if the operators in expr have |
| 5399 | // precedence equal to or greater than binop, or by using parentheses around |
| 5400 | // expr or subexpressions of expr. |
| 5401 | // * For forms that allow multiple occurrences of x, the number of times |
| 5402 | // that x is evaluated is unspecified. |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5403 | if (AtomicKind == OMPC_read) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5404 | enum { |
| 5405 | NotAnExpression, |
| 5406 | NotAnAssignmentOp, |
| 5407 | NotAScalarType, |
| 5408 | NotAnLValue, |
| 5409 | NoError |
| 5410 | } ErrorFound = NoError; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5411 | SourceLocation ErrorLoc, NoteLoc; |
| 5412 | SourceRange ErrorRange, NoteRange; |
| 5413 | // If clause is read: |
| 5414 | // v = x; |
| 5415 | if (auto AtomicBody = dyn_cast<Expr>(Body)) { |
| 5416 | auto AtomicBinOp = |
| 5417 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 5418 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
| 5419 | X = AtomicBinOp->getRHS()->IgnoreParenImpCasts(); |
| 5420 | V = AtomicBinOp->getLHS()->IgnoreParenImpCasts(); |
| 5421 | if ((X->isInstantiationDependent() || X->getType()->isScalarType()) && |
| 5422 | (V->isInstantiationDependent() || V->getType()->isScalarType())) { |
| 5423 | if (!X->isLValue() || !V->isLValue()) { |
| 5424 | auto NotLValueExpr = X->isLValue() ? V : X; |
| 5425 | ErrorFound = NotAnLValue; |
| 5426 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5427 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5428 | NoteLoc = NotLValueExpr->getExprLoc(); |
| 5429 | NoteRange = NotLValueExpr->getSourceRange(); |
| 5430 | } |
| 5431 | } else if (!X->isInstantiationDependent() || |
| 5432 | !V->isInstantiationDependent()) { |
| 5433 | auto NotScalarExpr = |
| 5434 | (X->isInstantiationDependent() || X->getType()->isScalarType()) |
| 5435 | ? V |
| 5436 | : X; |
| 5437 | ErrorFound = NotAScalarType; |
| 5438 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5439 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5440 | NoteLoc = NotScalarExpr->getExprLoc(); |
| 5441 | NoteRange = NotScalarExpr->getSourceRange(); |
| 5442 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5443 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5444 | ErrorFound = NotAnAssignmentOp; |
| 5445 | ErrorLoc = AtomicBody->getExprLoc(); |
| 5446 | ErrorRange = AtomicBody->getSourceRange(); |
| 5447 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 5448 | : AtomicBody->getExprLoc(); |
| 5449 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 5450 | : AtomicBody->getSourceRange(); |
| 5451 | } |
| 5452 | } else { |
| 5453 | ErrorFound = NotAnExpression; |
| 5454 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 5455 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5456 | } |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5457 | if (ErrorFound != NoError) { |
| 5458 | Diag(ErrorLoc, diag::err_omp_atomic_read_not_expression_statement) |
| 5459 | << ErrorRange; |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5460 | Diag(NoteLoc, diag::note_omp_atomic_read_write) << ErrorFound |
| 5461 | << NoteRange; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5462 | return StmtError(); |
| 5463 | } else if (CurContext->isDependentContext()) |
| 5464 | V = X = nullptr; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5465 | } else if (AtomicKind == OMPC_write) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5466 | enum { |
| 5467 | NotAnExpression, |
| 5468 | NotAnAssignmentOp, |
| 5469 | NotAScalarType, |
| 5470 | NotAnLValue, |
| 5471 | NoError |
| 5472 | } ErrorFound = NoError; |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5473 | SourceLocation ErrorLoc, NoteLoc; |
| 5474 | SourceRange ErrorRange, NoteRange; |
| 5475 | // If clause is write: |
| 5476 | // x = expr; |
| 5477 | if (auto AtomicBody = dyn_cast<Expr>(Body)) { |
| 5478 | auto AtomicBinOp = |
| 5479 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 5480 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
Alexey Bataev | b832926 | 2015-02-27 06:33:30 +0000 | [diff] [blame] | 5481 | X = AtomicBinOp->getLHS(); |
| 5482 | E = AtomicBinOp->getRHS(); |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5483 | if ((X->isInstantiationDependent() || X->getType()->isScalarType()) && |
| 5484 | (E->isInstantiationDependent() || E->getType()->isScalarType())) { |
| 5485 | if (!X->isLValue()) { |
| 5486 | ErrorFound = NotAnLValue; |
| 5487 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5488 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5489 | NoteLoc = X->getExprLoc(); |
| 5490 | NoteRange = X->getSourceRange(); |
| 5491 | } |
| 5492 | } else if (!X->isInstantiationDependent() || |
| 5493 | !E->isInstantiationDependent()) { |
| 5494 | auto NotScalarExpr = |
| 5495 | (X->isInstantiationDependent() || X->getType()->isScalarType()) |
| 5496 | ? E |
| 5497 | : X; |
| 5498 | ErrorFound = NotAScalarType; |
| 5499 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5500 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5501 | NoteLoc = NotScalarExpr->getExprLoc(); |
| 5502 | NoteRange = NotScalarExpr->getSourceRange(); |
| 5503 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5504 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5505 | ErrorFound = NotAnAssignmentOp; |
| 5506 | ErrorLoc = AtomicBody->getExprLoc(); |
| 5507 | ErrorRange = AtomicBody->getSourceRange(); |
| 5508 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 5509 | : AtomicBody->getExprLoc(); |
| 5510 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 5511 | : AtomicBody->getSourceRange(); |
| 5512 | } |
| 5513 | } else { |
| 5514 | ErrorFound = NotAnExpression; |
| 5515 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 5516 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5517 | } |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5518 | if (ErrorFound != NoError) { |
| 5519 | Diag(ErrorLoc, diag::err_omp_atomic_write_not_expression_statement) |
| 5520 | << ErrorRange; |
| 5521 | Diag(NoteLoc, diag::note_omp_atomic_read_write) << ErrorFound |
| 5522 | << NoteRange; |
| 5523 | return StmtError(); |
| 5524 | } else if (CurContext->isDependentContext()) |
| 5525 | E = X = nullptr; |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5526 | } else if (AtomicKind == OMPC_update || AtomicKind == OMPC_unknown) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5527 | // If clause is update: |
| 5528 | // x++; |
| 5529 | // x--; |
| 5530 | // ++x; |
| 5531 | // --x; |
| 5532 | // x binop= expr; |
| 5533 | // x = x binop expr; |
| 5534 | // x = expr binop x; |
| 5535 | OpenMPAtomicUpdateChecker Checker(*this); |
| 5536 | if (Checker.checkStatement( |
| 5537 | Body, (AtomicKind == OMPC_update) |
| 5538 | ? diag::err_omp_atomic_update_not_expression_statement |
| 5539 | : diag::err_omp_atomic_not_expression_statement, |
| 5540 | diag::note_omp_atomic_update)) |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5541 | return StmtError(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5542 | if (!CurContext->isDependentContext()) { |
| 5543 | E = Checker.getExpr(); |
| 5544 | X = Checker.getX(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5545 | UE = Checker.getUpdateExpr(); |
| 5546 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5547 | } |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5548 | } else if (AtomicKind == OMPC_capture) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5549 | enum { |
| 5550 | NotAnAssignmentOp, |
| 5551 | NotACompoundStatement, |
| 5552 | NotTwoSubstatements, |
| 5553 | NotASpecificExpression, |
| 5554 | NoError |
| 5555 | } ErrorFound = NoError; |
| 5556 | SourceLocation ErrorLoc, NoteLoc; |
| 5557 | SourceRange ErrorRange, NoteRange; |
| 5558 | if (auto *AtomicBody = dyn_cast<Expr>(Body)) { |
| 5559 | // If clause is a capture: |
| 5560 | // v = x++; |
| 5561 | // v = x--; |
| 5562 | // v = ++x; |
| 5563 | // v = --x; |
| 5564 | // v = x binop= expr; |
| 5565 | // v = x = x binop expr; |
| 5566 | // v = x = expr binop x; |
| 5567 | auto *AtomicBinOp = |
| 5568 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 5569 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
| 5570 | V = AtomicBinOp->getLHS(); |
| 5571 | Body = AtomicBinOp->getRHS()->IgnoreParenImpCasts(); |
| 5572 | OpenMPAtomicUpdateChecker Checker(*this); |
| 5573 | if (Checker.checkStatement( |
| 5574 | Body, diag::err_omp_atomic_capture_not_expression_statement, |
| 5575 | diag::note_omp_atomic_update)) |
| 5576 | return StmtError(); |
| 5577 | E = Checker.getExpr(); |
| 5578 | X = Checker.getX(); |
| 5579 | UE = Checker.getUpdateExpr(); |
| 5580 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
| 5581 | IsPostfixUpdate = Checker.isPostfixUpdate(); |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5582 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5583 | ErrorLoc = AtomicBody->getExprLoc(); |
| 5584 | ErrorRange = AtomicBody->getSourceRange(); |
| 5585 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 5586 | : AtomicBody->getExprLoc(); |
| 5587 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 5588 | : AtomicBody->getSourceRange(); |
| 5589 | ErrorFound = NotAnAssignmentOp; |
| 5590 | } |
| 5591 | if (ErrorFound != NoError) { |
| 5592 | Diag(ErrorLoc, diag::err_omp_atomic_capture_not_expression_statement) |
| 5593 | << ErrorRange; |
| 5594 | Diag(NoteLoc, diag::note_omp_atomic_capture) << ErrorFound << NoteRange; |
| 5595 | return StmtError(); |
| 5596 | } else if (CurContext->isDependentContext()) { |
| 5597 | UE = V = E = X = nullptr; |
| 5598 | } |
| 5599 | } else { |
| 5600 | // If clause is a capture: |
| 5601 | // { v = x; x = expr; } |
| 5602 | // { v = x; x++; } |
| 5603 | // { v = x; x--; } |
| 5604 | // { v = x; ++x; } |
| 5605 | // { v = x; --x; } |
| 5606 | // { v = x; x binop= expr; } |
| 5607 | // { v = x; x = x binop expr; } |
| 5608 | // { v = x; x = expr binop x; } |
| 5609 | // { x++; v = x; } |
| 5610 | // { x--; v = x; } |
| 5611 | // { ++x; v = x; } |
| 5612 | // { --x; v = x; } |
| 5613 | // { x binop= expr; v = x; } |
| 5614 | // { x = x binop expr; v = x; } |
| 5615 | // { x = expr binop x; v = x; } |
| 5616 | if (auto *CS = dyn_cast<CompoundStmt>(Body)) { |
| 5617 | // Check that this is { expr1; expr2; } |
| 5618 | if (CS->size() == 2) { |
| 5619 | auto *First = CS->body_front(); |
| 5620 | auto *Second = CS->body_back(); |
| 5621 | if (auto *EWC = dyn_cast<ExprWithCleanups>(First)) |
| 5622 | First = EWC->getSubExpr()->IgnoreParenImpCasts(); |
| 5623 | if (auto *EWC = dyn_cast<ExprWithCleanups>(Second)) |
| 5624 | Second = EWC->getSubExpr()->IgnoreParenImpCasts(); |
| 5625 | // Need to find what subexpression is 'v' and what is 'x'. |
| 5626 | OpenMPAtomicUpdateChecker Checker(*this); |
| 5627 | bool IsUpdateExprFound = !Checker.checkStatement(Second); |
| 5628 | BinaryOperator *BinOp = nullptr; |
| 5629 | if (IsUpdateExprFound) { |
| 5630 | BinOp = dyn_cast<BinaryOperator>(First); |
| 5631 | IsUpdateExprFound = BinOp && BinOp->getOpcode() == BO_Assign; |
| 5632 | } |
| 5633 | if (IsUpdateExprFound && !CurContext->isDependentContext()) { |
| 5634 | // { v = x; x++; } |
| 5635 | // { v = x; x--; } |
| 5636 | // { v = x; ++x; } |
| 5637 | // { v = x; --x; } |
| 5638 | // { v = x; x binop= expr; } |
| 5639 | // { v = x; x = x binop expr; } |
| 5640 | // { v = x; x = expr binop x; } |
| 5641 | // Check that the first expression has form v = x. |
| 5642 | auto *PossibleX = BinOp->getRHS()->IgnoreParenImpCasts(); |
| 5643 | llvm::FoldingSetNodeID XId, PossibleXId; |
| 5644 | Checker.getX()->Profile(XId, Context, /*Canonical=*/true); |
| 5645 | PossibleX->Profile(PossibleXId, Context, /*Canonical=*/true); |
| 5646 | IsUpdateExprFound = XId == PossibleXId; |
| 5647 | if (IsUpdateExprFound) { |
| 5648 | V = BinOp->getLHS(); |
| 5649 | X = Checker.getX(); |
| 5650 | E = Checker.getExpr(); |
| 5651 | UE = Checker.getUpdateExpr(); |
| 5652 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5653 | IsPostfixUpdate = true; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5654 | } |
| 5655 | } |
| 5656 | if (!IsUpdateExprFound) { |
| 5657 | IsUpdateExprFound = !Checker.checkStatement(First); |
| 5658 | BinOp = nullptr; |
| 5659 | if (IsUpdateExprFound) { |
| 5660 | BinOp = dyn_cast<BinaryOperator>(Second); |
| 5661 | IsUpdateExprFound = BinOp && BinOp->getOpcode() == BO_Assign; |
| 5662 | } |
| 5663 | if (IsUpdateExprFound && !CurContext->isDependentContext()) { |
| 5664 | // { x++; v = x; } |
| 5665 | // { x--; v = x; } |
| 5666 | // { ++x; v = x; } |
| 5667 | // { --x; v = x; } |
| 5668 | // { x binop= expr; v = x; } |
| 5669 | // { x = x binop expr; v = x; } |
| 5670 | // { x = expr binop x; v = x; } |
| 5671 | // Check that the second expression has form v = x. |
| 5672 | auto *PossibleX = BinOp->getRHS()->IgnoreParenImpCasts(); |
| 5673 | llvm::FoldingSetNodeID XId, PossibleXId; |
| 5674 | Checker.getX()->Profile(XId, Context, /*Canonical=*/true); |
| 5675 | PossibleX->Profile(PossibleXId, Context, /*Canonical=*/true); |
| 5676 | IsUpdateExprFound = XId == PossibleXId; |
| 5677 | if (IsUpdateExprFound) { |
| 5678 | V = BinOp->getLHS(); |
| 5679 | X = Checker.getX(); |
| 5680 | E = Checker.getExpr(); |
| 5681 | UE = Checker.getUpdateExpr(); |
| 5682 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5683 | IsPostfixUpdate = false; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5684 | } |
| 5685 | } |
| 5686 | } |
| 5687 | if (!IsUpdateExprFound) { |
| 5688 | // { v = x; x = expr; } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5689 | auto *FirstExpr = dyn_cast<Expr>(First); |
| 5690 | auto *SecondExpr = dyn_cast<Expr>(Second); |
| 5691 | if (!FirstExpr || !SecondExpr || |
| 5692 | !(FirstExpr->isInstantiationDependent() || |
| 5693 | SecondExpr->isInstantiationDependent())) { |
| 5694 | auto *FirstBinOp = dyn_cast<BinaryOperator>(First); |
| 5695 | if (!FirstBinOp || FirstBinOp->getOpcode() != BO_Assign) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5696 | ErrorFound = NotAnAssignmentOp; |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5697 | NoteLoc = ErrorLoc = FirstBinOp ? FirstBinOp->getOperatorLoc() |
| 5698 | : First->getLocStart(); |
| 5699 | NoteRange = ErrorRange = FirstBinOp |
| 5700 | ? FirstBinOp->getSourceRange() |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5701 | : SourceRange(ErrorLoc, ErrorLoc); |
| 5702 | } else { |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5703 | auto *SecondBinOp = dyn_cast<BinaryOperator>(Second); |
| 5704 | if (!SecondBinOp || SecondBinOp->getOpcode() != BO_Assign) { |
| 5705 | ErrorFound = NotAnAssignmentOp; |
| 5706 | NoteLoc = ErrorLoc = SecondBinOp |
| 5707 | ? SecondBinOp->getOperatorLoc() |
| 5708 | : Second->getLocStart(); |
| 5709 | NoteRange = ErrorRange = |
| 5710 | SecondBinOp ? SecondBinOp->getSourceRange() |
| 5711 | : SourceRange(ErrorLoc, ErrorLoc); |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5712 | } else { |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5713 | auto *PossibleXRHSInFirst = |
| 5714 | FirstBinOp->getRHS()->IgnoreParenImpCasts(); |
| 5715 | auto *PossibleXLHSInSecond = |
| 5716 | SecondBinOp->getLHS()->IgnoreParenImpCasts(); |
| 5717 | llvm::FoldingSetNodeID X1Id, X2Id; |
| 5718 | PossibleXRHSInFirst->Profile(X1Id, Context, |
| 5719 | /*Canonical=*/true); |
| 5720 | PossibleXLHSInSecond->Profile(X2Id, Context, |
| 5721 | /*Canonical=*/true); |
| 5722 | IsUpdateExprFound = X1Id == X2Id; |
| 5723 | if (IsUpdateExprFound) { |
| 5724 | V = FirstBinOp->getLHS(); |
| 5725 | X = SecondBinOp->getLHS(); |
| 5726 | E = SecondBinOp->getRHS(); |
| 5727 | UE = nullptr; |
| 5728 | IsXLHSInRHSPart = false; |
| 5729 | IsPostfixUpdate = true; |
| 5730 | } else { |
| 5731 | ErrorFound = NotASpecificExpression; |
| 5732 | ErrorLoc = FirstBinOp->getExprLoc(); |
| 5733 | ErrorRange = FirstBinOp->getSourceRange(); |
| 5734 | NoteLoc = SecondBinOp->getLHS()->getExprLoc(); |
| 5735 | NoteRange = SecondBinOp->getRHS()->getSourceRange(); |
| 5736 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5737 | } |
| 5738 | } |
| 5739 | } |
| 5740 | } |
| 5741 | } else { |
| 5742 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 5743 | NoteRange = ErrorRange = |
| 5744 | SourceRange(Body->getLocStart(), Body->getLocStart()); |
| 5745 | ErrorFound = NotTwoSubstatements; |
| 5746 | } |
| 5747 | } else { |
| 5748 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 5749 | NoteRange = ErrorRange = |
| 5750 | SourceRange(Body->getLocStart(), Body->getLocStart()); |
| 5751 | ErrorFound = NotACompoundStatement; |
| 5752 | } |
| 5753 | if (ErrorFound != NoError) { |
| 5754 | Diag(ErrorLoc, diag::err_omp_atomic_capture_not_compound_statement) |
| 5755 | << ErrorRange; |
| 5756 | Diag(NoteLoc, diag::note_omp_atomic_capture) << ErrorFound << NoteRange; |
| 5757 | return StmtError(); |
| 5758 | } else if (CurContext->isDependentContext()) { |
| 5759 | UE = V = E = X = nullptr; |
| 5760 | } |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5761 | } |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5762 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 5763 | |
| 5764 | getCurFunction()->setHasBranchProtectedScope(); |
| 5765 | |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5766 | return OMPAtomicDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5767 | X, V, E, UE, IsXLHSInRHSPart, |
| 5768 | IsPostfixUpdate); |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 5769 | } |
| 5770 | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 5771 | StmtResult Sema::ActOnOpenMPTargetDirective(ArrayRef<OMPClause *> Clauses, |
| 5772 | Stmt *AStmt, |
| 5773 | SourceLocation StartLoc, |
| 5774 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5775 | if (!AStmt) |
| 5776 | return StmtError(); |
| 5777 | |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 5778 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 5779 | // 1.2.2 OpenMP Language Terminology |
| 5780 | // Structured block - An executable statement with a single entry at the |
| 5781 | // top and a single exit at the bottom. |
| 5782 | // The point of exit cannot be a branch out of the structured block. |
| 5783 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5784 | CS->getCapturedDecl()->setNothrow(); |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 5785 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 5786 | // OpenMP [2.16, Nesting of Regions] |
| 5787 | // If specified, a teams construct must be contained within a target |
| 5788 | // construct. That target construct must contain no statements or directives |
| 5789 | // outside of the teams construct. |
| 5790 | if (DSAStack->hasInnerTeamsRegion()) { |
| 5791 | auto S = AStmt->IgnoreContainers(/*IgnoreCaptured*/ true); |
| 5792 | bool OMPTeamsFound = true; |
| 5793 | if (auto *CS = dyn_cast<CompoundStmt>(S)) { |
| 5794 | auto I = CS->body_begin(); |
| 5795 | while (I != CS->body_end()) { |
| 5796 | auto OED = dyn_cast<OMPExecutableDirective>(*I); |
| 5797 | if (!OED || !isOpenMPTeamsDirective(OED->getDirectiveKind())) { |
| 5798 | OMPTeamsFound = false; |
| 5799 | break; |
| 5800 | } |
| 5801 | ++I; |
| 5802 | } |
| 5803 | assert(I != CS->body_end() && "Not found statement"); |
| 5804 | S = *I; |
| 5805 | } |
| 5806 | if (!OMPTeamsFound) { |
| 5807 | Diag(StartLoc, diag::err_omp_target_contains_not_only_teams); |
| 5808 | Diag(DSAStack->getInnerTeamsRegionLoc(), |
| 5809 | diag::note_omp_nested_teams_construct_here); |
| 5810 | Diag(S->getLocStart(), diag::note_omp_nested_statement_here) |
| 5811 | << isa<OMPExecutableDirective>(S); |
| 5812 | return StmtError(); |
| 5813 | } |
| 5814 | } |
| 5815 | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 5816 | getCurFunction()->setHasBranchProtectedScope(); |
| 5817 | |
| 5818 | return OMPTargetDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 5819 | } |
| 5820 | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 5821 | StmtResult |
| 5822 | Sema::ActOnOpenMPTargetParallelDirective(ArrayRef<OMPClause *> Clauses, |
| 5823 | Stmt *AStmt, SourceLocation StartLoc, |
| 5824 | SourceLocation EndLoc) { |
| 5825 | if (!AStmt) |
| 5826 | return StmtError(); |
| 5827 | |
| 5828 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 5829 | // 1.2.2 OpenMP Language Terminology |
| 5830 | // Structured block - An executable statement with a single entry at the |
| 5831 | // top and a single exit at the bottom. |
| 5832 | // The point of exit cannot be a branch out of the structured block. |
| 5833 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5834 | CS->getCapturedDecl()->setNothrow(); |
| 5835 | |
| 5836 | getCurFunction()->setHasBranchProtectedScope(); |
| 5837 | |
| 5838 | return OMPTargetParallelDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 5839 | AStmt); |
| 5840 | } |
| 5841 | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 5842 | StmtResult Sema::ActOnOpenMPTargetParallelForDirective( |
| 5843 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 5844 | SourceLocation EndLoc, |
| 5845 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 5846 | if (!AStmt) |
| 5847 | return StmtError(); |
| 5848 | |
| 5849 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 5850 | // 1.2.2 OpenMP Language Terminology |
| 5851 | // Structured block - An executable statement with a single entry at the |
| 5852 | // top and a single exit at the bottom. |
| 5853 | // The point of exit cannot be a branch out of the structured block. |
| 5854 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5855 | CS->getCapturedDecl()->setNothrow(); |
| 5856 | |
| 5857 | OMPLoopDirective::HelperExprs B; |
| 5858 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 5859 | // define the nested loops number. |
| 5860 | unsigned NestedLoopCount = |
| 5861 | CheckOpenMPLoop(OMPD_target_parallel_for, getCollapseNumberExpr(Clauses), |
| 5862 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 5863 | VarsWithImplicitDSA, B); |
| 5864 | if (NestedLoopCount == 0) |
| 5865 | return StmtError(); |
| 5866 | |
| 5867 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 5868 | "omp target parallel for loop exprs were not built"); |
| 5869 | |
| 5870 | if (!CurContext->isDependentContext()) { |
| 5871 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 5872 | for (auto C : Clauses) { |
| 5873 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 5874 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 5875 | B.NumIterations, *this, CurScope)) |
| 5876 | return StmtError(); |
| 5877 | } |
| 5878 | } |
| 5879 | |
| 5880 | getCurFunction()->setHasBranchProtectedScope(); |
| 5881 | return OMPTargetParallelForDirective::Create(Context, StartLoc, EndLoc, |
| 5882 | NestedLoopCount, Clauses, AStmt, |
| 5883 | B, DSAStack->isCancelRegion()); |
| 5884 | } |
| 5885 | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 5886 | /// \brief Check for existence of a map clause in the list of clauses. |
| 5887 | static bool HasMapClause(ArrayRef<OMPClause *> Clauses) { |
| 5888 | for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end(); |
| 5889 | I != E; ++I) { |
| 5890 | if (*I != nullptr && (*I)->getClauseKind() == OMPC_map) { |
| 5891 | return true; |
| 5892 | } |
| 5893 | } |
| 5894 | |
| 5895 | return false; |
| 5896 | } |
| 5897 | |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 5898 | StmtResult Sema::ActOnOpenMPTargetDataDirective(ArrayRef<OMPClause *> Clauses, |
| 5899 | Stmt *AStmt, |
| 5900 | SourceLocation StartLoc, |
| 5901 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5902 | if (!AStmt) |
| 5903 | return StmtError(); |
| 5904 | |
| 5905 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 5906 | |
Arpith Chacko Jacob | 46a04bb | 2016-01-21 19:57:55 +0000 | [diff] [blame] | 5907 | // OpenMP [2.10.1, Restrictions, p. 97] |
| 5908 | // At least one map clause must appear on the directive. |
| 5909 | if (!HasMapClause(Clauses)) { |
| 5910 | Diag(StartLoc, diag::err_omp_no_map_for_directive) << |
| 5911 | getOpenMPDirectiveName(OMPD_target_data); |
| 5912 | return StmtError(); |
| 5913 | } |
| 5914 | |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 5915 | getCurFunction()->setHasBranchProtectedScope(); |
| 5916 | |
| 5917 | return OMPTargetDataDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 5918 | AStmt); |
| 5919 | } |
| 5920 | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 5921 | StmtResult |
| 5922 | Sema::ActOnOpenMPTargetEnterDataDirective(ArrayRef<OMPClause *> Clauses, |
| 5923 | SourceLocation StartLoc, |
| 5924 | SourceLocation EndLoc) { |
| 5925 | // OpenMP [2.10.2, Restrictions, p. 99] |
| 5926 | // At least one map clause must appear on the directive. |
| 5927 | if (!HasMapClause(Clauses)) { |
| 5928 | Diag(StartLoc, diag::err_omp_no_map_for_directive) |
| 5929 | << getOpenMPDirectiveName(OMPD_target_enter_data); |
| 5930 | return StmtError(); |
| 5931 | } |
| 5932 | |
| 5933 | return OMPTargetEnterDataDirective::Create(Context, StartLoc, EndLoc, |
| 5934 | Clauses); |
| 5935 | } |
| 5936 | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 5937 | StmtResult |
| 5938 | Sema::ActOnOpenMPTargetExitDataDirective(ArrayRef<OMPClause *> Clauses, |
| 5939 | SourceLocation StartLoc, |
| 5940 | SourceLocation EndLoc) { |
| 5941 | // OpenMP [2.10.3, Restrictions, p. 102] |
| 5942 | // At least one map clause must appear on the directive. |
| 5943 | if (!HasMapClause(Clauses)) { |
| 5944 | Diag(StartLoc, diag::err_omp_no_map_for_directive) |
| 5945 | << getOpenMPDirectiveName(OMPD_target_exit_data); |
| 5946 | return StmtError(); |
| 5947 | } |
| 5948 | |
| 5949 | return OMPTargetExitDataDirective::Create(Context, StartLoc, EndLoc, Clauses); |
| 5950 | } |
| 5951 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 5952 | StmtResult Sema::ActOnOpenMPTeamsDirective(ArrayRef<OMPClause *> Clauses, |
| 5953 | Stmt *AStmt, SourceLocation StartLoc, |
| 5954 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5955 | if (!AStmt) |
| 5956 | return StmtError(); |
| 5957 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 5958 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 5959 | // 1.2.2 OpenMP Language Terminology |
| 5960 | // Structured block - An executable statement with a single entry at the |
| 5961 | // top and a single exit at the bottom. |
| 5962 | // The point of exit cannot be a branch out of the structured block. |
| 5963 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5964 | CS->getCapturedDecl()->setNothrow(); |
| 5965 | |
| 5966 | getCurFunction()->setHasBranchProtectedScope(); |
| 5967 | |
| 5968 | return OMPTeamsDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 5969 | } |
| 5970 | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 5971 | StmtResult |
| 5972 | Sema::ActOnOpenMPCancellationPointDirective(SourceLocation StartLoc, |
| 5973 | SourceLocation EndLoc, |
| 5974 | OpenMPDirectiveKind CancelRegion) { |
| 5975 | if (CancelRegion != OMPD_parallel && CancelRegion != OMPD_for && |
| 5976 | CancelRegion != OMPD_sections && CancelRegion != OMPD_taskgroup) { |
| 5977 | Diag(StartLoc, diag::err_omp_wrong_cancel_region) |
| 5978 | << getOpenMPDirectiveName(CancelRegion); |
| 5979 | return StmtError(); |
| 5980 | } |
| 5981 | if (DSAStack->isParentNowaitRegion()) { |
| 5982 | Diag(StartLoc, diag::err_omp_parent_cancel_region_nowait) << 0; |
| 5983 | return StmtError(); |
| 5984 | } |
| 5985 | if (DSAStack->isParentOrderedRegion()) { |
| 5986 | Diag(StartLoc, diag::err_omp_parent_cancel_region_ordered) << 0; |
| 5987 | return StmtError(); |
| 5988 | } |
| 5989 | return OMPCancellationPointDirective::Create(Context, StartLoc, EndLoc, |
| 5990 | CancelRegion); |
| 5991 | } |
| 5992 | |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 5993 | StmtResult Sema::ActOnOpenMPCancelDirective(ArrayRef<OMPClause *> Clauses, |
| 5994 | SourceLocation StartLoc, |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 5995 | SourceLocation EndLoc, |
| 5996 | OpenMPDirectiveKind CancelRegion) { |
| 5997 | if (CancelRegion != OMPD_parallel && CancelRegion != OMPD_for && |
| 5998 | CancelRegion != OMPD_sections && CancelRegion != OMPD_taskgroup) { |
| 5999 | Diag(StartLoc, diag::err_omp_wrong_cancel_region) |
| 6000 | << getOpenMPDirectiveName(CancelRegion); |
| 6001 | return StmtError(); |
| 6002 | } |
| 6003 | if (DSAStack->isParentNowaitRegion()) { |
| 6004 | Diag(StartLoc, diag::err_omp_parent_cancel_region_nowait) << 1; |
| 6005 | return StmtError(); |
| 6006 | } |
| 6007 | if (DSAStack->isParentOrderedRegion()) { |
| 6008 | Diag(StartLoc, diag::err_omp_parent_cancel_region_ordered) << 1; |
| 6009 | return StmtError(); |
| 6010 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 6011 | DSAStack->setParentCancelRegion(/*Cancel=*/true); |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 6012 | return OMPCancelDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 6013 | CancelRegion); |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 6014 | } |
| 6015 | |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6016 | static bool checkGrainsizeNumTasksClauses(Sema &S, |
| 6017 | ArrayRef<OMPClause *> Clauses) { |
| 6018 | OMPClause *PrevClause = nullptr; |
| 6019 | bool ErrorFound = false; |
| 6020 | for (auto *C : Clauses) { |
| 6021 | if (C->getClauseKind() == OMPC_grainsize || |
| 6022 | C->getClauseKind() == OMPC_num_tasks) { |
| 6023 | if (!PrevClause) |
| 6024 | PrevClause = C; |
| 6025 | else if (PrevClause->getClauseKind() != C->getClauseKind()) { |
| 6026 | S.Diag(C->getLocStart(), |
| 6027 | diag::err_omp_grainsize_num_tasks_mutually_exclusive) |
| 6028 | << getOpenMPClauseName(C->getClauseKind()) |
| 6029 | << getOpenMPClauseName(PrevClause->getClauseKind()); |
| 6030 | S.Diag(PrevClause->getLocStart(), |
| 6031 | diag::note_omp_previous_grainsize_num_tasks) |
| 6032 | << getOpenMPClauseName(PrevClause->getClauseKind()); |
| 6033 | ErrorFound = true; |
| 6034 | } |
| 6035 | } |
| 6036 | } |
| 6037 | return ErrorFound; |
| 6038 | } |
| 6039 | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 6040 | StmtResult Sema::ActOnOpenMPTaskLoopDirective( |
| 6041 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6042 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 6043 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 6044 | if (!AStmt) |
| 6045 | return StmtError(); |
| 6046 | |
| 6047 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 6048 | OMPLoopDirective::HelperExprs B; |
| 6049 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 6050 | // define the nested loops number. |
| 6051 | unsigned NestedLoopCount = |
| 6052 | CheckOpenMPLoop(OMPD_taskloop, getCollapseNumberExpr(Clauses), |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 6053 | /*OrderedLoopCountExpr=*/nullptr, AStmt, *this, *DSAStack, |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 6054 | VarsWithImplicitDSA, B); |
| 6055 | if (NestedLoopCount == 0) |
| 6056 | return StmtError(); |
| 6057 | |
| 6058 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6059 | "omp for loop exprs were not built"); |
| 6060 | |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6061 | // OpenMP, [2.9.2 taskloop Construct, Restrictions] |
| 6062 | // The grainsize clause and num_tasks clause are mutually exclusive and may |
| 6063 | // not appear on the same taskloop directive. |
| 6064 | if (checkGrainsizeNumTasksClauses(*this, Clauses)) |
| 6065 | return StmtError(); |
| 6066 | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 6067 | getCurFunction()->setHasBranchProtectedScope(); |
| 6068 | return OMPTaskLoopDirective::Create(Context, StartLoc, EndLoc, |
| 6069 | NestedLoopCount, Clauses, AStmt, B); |
| 6070 | } |
| 6071 | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 6072 | StmtResult Sema::ActOnOpenMPTaskLoopSimdDirective( |
| 6073 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6074 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 6075 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 6076 | if (!AStmt) |
| 6077 | return StmtError(); |
| 6078 | |
| 6079 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 6080 | OMPLoopDirective::HelperExprs B; |
| 6081 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 6082 | // define the nested loops number. |
| 6083 | unsigned NestedLoopCount = |
| 6084 | CheckOpenMPLoop(OMPD_taskloop_simd, getCollapseNumberExpr(Clauses), |
| 6085 | /*OrderedLoopCountExpr=*/nullptr, AStmt, *this, *DSAStack, |
| 6086 | VarsWithImplicitDSA, B); |
| 6087 | if (NestedLoopCount == 0) |
| 6088 | return StmtError(); |
| 6089 | |
| 6090 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6091 | "omp for loop exprs were not built"); |
| 6092 | |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6093 | // OpenMP, [2.9.2 taskloop Construct, Restrictions] |
| 6094 | // The grainsize clause and num_tasks clause are mutually exclusive and may |
| 6095 | // not appear on the same taskloop directive. |
| 6096 | if (checkGrainsizeNumTasksClauses(*this, Clauses)) |
| 6097 | return StmtError(); |
| 6098 | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 6099 | getCurFunction()->setHasBranchProtectedScope(); |
| 6100 | return OMPTaskLoopSimdDirective::Create(Context, StartLoc, EndLoc, |
| 6101 | NestedLoopCount, Clauses, AStmt, B); |
| 6102 | } |
| 6103 | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 6104 | StmtResult Sema::ActOnOpenMPDistributeDirective( |
| 6105 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6106 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 6107 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 6108 | if (!AStmt) |
| 6109 | return StmtError(); |
| 6110 | |
| 6111 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 6112 | OMPLoopDirective::HelperExprs B; |
| 6113 | // In presence of clause 'collapse' with number of loops, it will |
| 6114 | // define the nested loops number. |
| 6115 | unsigned NestedLoopCount = |
| 6116 | CheckOpenMPLoop(OMPD_distribute, getCollapseNumberExpr(Clauses), |
| 6117 | nullptr /*ordered not a clause on distribute*/, AStmt, |
| 6118 | *this, *DSAStack, VarsWithImplicitDSA, B); |
| 6119 | if (NestedLoopCount == 0) |
| 6120 | return StmtError(); |
| 6121 | |
| 6122 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6123 | "omp for loop exprs were not built"); |
| 6124 | |
| 6125 | getCurFunction()->setHasBranchProtectedScope(); |
| 6126 | return OMPDistributeDirective::Create(Context, StartLoc, EndLoc, |
| 6127 | NestedLoopCount, Clauses, AStmt, B); |
| 6128 | } |
| 6129 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6130 | OMPClause *Sema::ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, Expr *Expr, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6131 | SourceLocation StartLoc, |
| 6132 | SourceLocation LParenLoc, |
| 6133 | SourceLocation EndLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6134 | OMPClause *Res = nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6135 | switch (Kind) { |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 6136 | case OMPC_final: |
| 6137 | Res = ActOnOpenMPFinalClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6138 | break; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6139 | case OMPC_num_threads: |
| 6140 | Res = ActOnOpenMPNumThreadsClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6141 | break; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6142 | case OMPC_safelen: |
| 6143 | Res = ActOnOpenMPSafelenClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6144 | break; |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 6145 | case OMPC_simdlen: |
| 6146 | Res = ActOnOpenMPSimdlenClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6147 | break; |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6148 | case OMPC_collapse: |
| 6149 | Res = ActOnOpenMPCollapseClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6150 | break; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 6151 | case OMPC_ordered: |
| 6152 | Res = ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Expr); |
| 6153 | break; |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 6154 | case OMPC_device: |
| 6155 | Res = ActOnOpenMPDeviceClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6156 | break; |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 6157 | case OMPC_num_teams: |
| 6158 | Res = ActOnOpenMPNumTeamsClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6159 | break; |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6160 | case OMPC_thread_limit: |
| 6161 | Res = ActOnOpenMPThreadLimitClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6162 | break; |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6163 | case OMPC_priority: |
| 6164 | Res = ActOnOpenMPPriorityClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6165 | break; |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 6166 | case OMPC_grainsize: |
| 6167 | Res = ActOnOpenMPGrainsizeClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6168 | break; |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6169 | case OMPC_num_tasks: |
| 6170 | Res = ActOnOpenMPNumTasksClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6171 | break; |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 6172 | case OMPC_hint: |
| 6173 | Res = ActOnOpenMPHintClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6174 | break; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6175 | case OMPC_if: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6176 | case OMPC_default: |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6177 | case OMPC_proc_bind: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6178 | case OMPC_schedule: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6179 | case OMPC_private: |
| 6180 | case OMPC_firstprivate: |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6181 | case OMPC_lastprivate: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6182 | case OMPC_shared: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6183 | case OMPC_reduction: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6184 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 6185 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6186 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6187 | case OMPC_copyprivate: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6188 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 6189 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 6190 | case OMPC_mergeable: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6191 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 6192 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6193 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6194 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6195 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6196 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 6197 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6198 | case OMPC_depend: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6199 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6200 | case OMPC_simd: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 6201 | case OMPC_map: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 6202 | case OMPC_nogroup: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 6203 | case OMPC_dist_schedule: |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 6204 | case OMPC_defaultmap: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6205 | case OMPC_unknown: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6206 | llvm_unreachable("Clause is not allowed."); |
| 6207 | } |
| 6208 | return Res; |
| 6209 | } |
| 6210 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6211 | OMPClause *Sema::ActOnOpenMPIfClause(OpenMPDirectiveKind NameModifier, |
| 6212 | Expr *Condition, SourceLocation StartLoc, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6213 | SourceLocation LParenLoc, |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6214 | SourceLocation NameModifierLoc, |
| 6215 | SourceLocation ColonLoc, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6216 | SourceLocation EndLoc) { |
| 6217 | Expr *ValExpr = Condition; |
| 6218 | if (!Condition->isValueDependent() && !Condition->isTypeDependent() && |
| 6219 | !Condition->isInstantiationDependent() && |
| 6220 | !Condition->containsUnexpandedParameterPack()) { |
| 6221 | ExprResult Val = ActOnBooleanCondition(DSAStack->getCurScope(), |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6222 | Condition->getExprLoc(), Condition); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6223 | if (Val.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6224 | return nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6225 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6226 | ValExpr = Val.get(); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6227 | } |
| 6228 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6229 | return new (Context) OMPIfClause(NameModifier, ValExpr, StartLoc, LParenLoc, |
| 6230 | NameModifierLoc, ColonLoc, EndLoc); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6231 | } |
| 6232 | |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 6233 | OMPClause *Sema::ActOnOpenMPFinalClause(Expr *Condition, |
| 6234 | SourceLocation StartLoc, |
| 6235 | SourceLocation LParenLoc, |
| 6236 | SourceLocation EndLoc) { |
| 6237 | Expr *ValExpr = Condition; |
| 6238 | if (!Condition->isValueDependent() && !Condition->isTypeDependent() && |
| 6239 | !Condition->isInstantiationDependent() && |
| 6240 | !Condition->containsUnexpandedParameterPack()) { |
| 6241 | ExprResult Val = ActOnBooleanCondition(DSAStack->getCurScope(), |
| 6242 | Condition->getExprLoc(), Condition); |
| 6243 | if (Val.isInvalid()) |
| 6244 | return nullptr; |
| 6245 | |
| 6246 | ValExpr = Val.get(); |
| 6247 | } |
| 6248 | |
| 6249 | return new (Context) OMPFinalClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 6250 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 6251 | ExprResult Sema::PerformOpenMPImplicitIntegerConversion(SourceLocation Loc, |
| 6252 | Expr *Op) { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6253 | if (!Op) |
| 6254 | return ExprError(); |
| 6255 | |
| 6256 | class IntConvertDiagnoser : public ICEConvertDiagnoser { |
| 6257 | public: |
| 6258 | IntConvertDiagnoser() |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6259 | : ICEConvertDiagnoser(/*AllowScopedEnumerations*/ false, false, true) {} |
Craig Topper | e14c0f8 | 2014-03-12 04:55:44 +0000 | [diff] [blame] | 6260 | SemaDiagnosticBuilder diagnoseNotInt(Sema &S, SourceLocation Loc, |
| 6261 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6262 | return S.Diag(Loc, diag::err_omp_not_integral) << T; |
| 6263 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6264 | SemaDiagnosticBuilder diagnoseIncomplete(Sema &S, SourceLocation Loc, |
| 6265 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6266 | return S.Diag(Loc, diag::err_omp_incomplete_type) << T; |
| 6267 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6268 | SemaDiagnosticBuilder diagnoseExplicitConv(Sema &S, SourceLocation Loc, |
| 6269 | QualType T, |
| 6270 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6271 | return S.Diag(Loc, diag::err_omp_explicit_conversion) << T << ConvTy; |
| 6272 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6273 | SemaDiagnosticBuilder noteExplicitConv(Sema &S, CXXConversionDecl *Conv, |
| 6274 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6275 | return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6276 | << ConvTy->isEnumeralType() << ConvTy; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6277 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6278 | SemaDiagnosticBuilder diagnoseAmbiguous(Sema &S, SourceLocation Loc, |
| 6279 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6280 | return S.Diag(Loc, diag::err_omp_ambiguous_conversion) << T; |
| 6281 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6282 | SemaDiagnosticBuilder noteAmbiguous(Sema &S, CXXConversionDecl *Conv, |
| 6283 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6284 | return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6285 | << ConvTy->isEnumeralType() << ConvTy; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6286 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6287 | SemaDiagnosticBuilder diagnoseConversion(Sema &, SourceLocation, QualType, |
| 6288 | QualType) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6289 | llvm_unreachable("conversion functions are permitted"); |
| 6290 | } |
| 6291 | } ConvertDiagnoser; |
| 6292 | return PerformContextualImplicitConversion(Loc, Op, ConvertDiagnoser); |
| 6293 | } |
| 6294 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6295 | static bool IsNonNegativeIntegerValue(Expr *&ValExpr, Sema &SemaRef, |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6296 | OpenMPClauseKind CKind, |
| 6297 | bool StrictlyPositive) { |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6298 | if (!ValExpr->isTypeDependent() && !ValExpr->isValueDependent() && |
| 6299 | !ValExpr->isInstantiationDependent()) { |
| 6300 | SourceLocation Loc = ValExpr->getExprLoc(); |
| 6301 | ExprResult Value = |
| 6302 | SemaRef.PerformOpenMPImplicitIntegerConversion(Loc, ValExpr); |
| 6303 | if (Value.isInvalid()) |
| 6304 | return false; |
| 6305 | |
| 6306 | ValExpr = Value.get(); |
| 6307 | // The expression must evaluate to a non-negative integer value. |
| 6308 | llvm::APSInt Result; |
| 6309 | if (ValExpr->isIntegerConstantExpr(Result, SemaRef.Context) && |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6310 | Result.isSigned() && |
| 6311 | !((!StrictlyPositive && Result.isNonNegative()) || |
| 6312 | (StrictlyPositive && Result.isStrictlyPositive()))) { |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6313 | SemaRef.Diag(Loc, diag::err_omp_negative_expression_in_clause) |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6314 | << getOpenMPClauseName(CKind) << (StrictlyPositive ? 1 : 0) |
| 6315 | << ValExpr->getSourceRange(); |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6316 | return false; |
| 6317 | } |
| 6318 | } |
| 6319 | return true; |
| 6320 | } |
| 6321 | |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6322 | OMPClause *Sema::ActOnOpenMPNumThreadsClause(Expr *NumThreads, |
| 6323 | SourceLocation StartLoc, |
| 6324 | SourceLocation LParenLoc, |
| 6325 | SourceLocation EndLoc) { |
| 6326 | Expr *ValExpr = NumThreads; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6327 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6328 | // OpenMP [2.5, Restrictions] |
| 6329 | // The num_threads expression must evaluate to a positive integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6330 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_num_threads, |
| 6331 | /*StrictlyPositive=*/true)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6332 | return nullptr; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6333 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6334 | return new (Context) |
| 6335 | OMPNumThreadsClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6336 | } |
| 6337 | |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6338 | ExprResult Sema::VerifyPositiveIntegerConstantInClause(Expr *E, |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 6339 | OpenMPClauseKind CKind, |
| 6340 | bool StrictlyPositive) { |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6341 | if (!E) |
| 6342 | return ExprError(); |
| 6343 | if (E->isValueDependent() || E->isTypeDependent() || |
| 6344 | E->isInstantiationDependent() || E->containsUnexpandedParameterPack()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6345 | return E; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6346 | llvm::APSInt Result; |
| 6347 | ExprResult ICE = VerifyIntegerConstantExpression(E, &Result); |
| 6348 | if (ICE.isInvalid()) |
| 6349 | return ExprError(); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 6350 | if ((StrictlyPositive && !Result.isStrictlyPositive()) || |
| 6351 | (!StrictlyPositive && !Result.isNonNegative())) { |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6352 | Diag(E->getExprLoc(), diag::err_omp_negative_expression_in_clause) |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 6353 | << getOpenMPClauseName(CKind) << (StrictlyPositive ? 1 : 0) |
| 6354 | << E->getSourceRange(); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6355 | return ExprError(); |
| 6356 | } |
Alexander Musman | 09184fe | 2014-09-30 05:29:28 +0000 | [diff] [blame] | 6357 | if (CKind == OMPC_aligned && !Result.isPowerOf2()) { |
| 6358 | Diag(E->getExprLoc(), diag::warn_omp_alignment_not_power_of_two) |
| 6359 | << E->getSourceRange(); |
| 6360 | return ExprError(); |
| 6361 | } |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 6362 | if (CKind == OMPC_collapse && DSAStack->getAssociatedLoops() == 1) |
| 6363 | DSAStack->setAssociatedLoops(Result.getExtValue()); |
Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 6364 | else if (CKind == OMPC_ordered) |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 6365 | DSAStack->setAssociatedLoops(Result.getExtValue()); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6366 | return ICE; |
| 6367 | } |
| 6368 | |
| 6369 | OMPClause *Sema::ActOnOpenMPSafelenClause(Expr *Len, SourceLocation StartLoc, |
| 6370 | SourceLocation LParenLoc, |
| 6371 | SourceLocation EndLoc) { |
| 6372 | // OpenMP [2.8.1, simd construct, Description] |
| 6373 | // The parameter of the safelen clause must be a constant |
| 6374 | // positive integer expression. |
| 6375 | ExprResult Safelen = VerifyPositiveIntegerConstantInClause(Len, OMPC_safelen); |
| 6376 | if (Safelen.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6377 | return nullptr; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6378 | return new (Context) |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6379 | OMPSafelenClause(Safelen.get(), StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6380 | } |
| 6381 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 6382 | OMPClause *Sema::ActOnOpenMPSimdlenClause(Expr *Len, SourceLocation StartLoc, |
| 6383 | SourceLocation LParenLoc, |
| 6384 | SourceLocation EndLoc) { |
| 6385 | // OpenMP [2.8.1, simd construct, Description] |
| 6386 | // The parameter of the simdlen clause must be a constant |
| 6387 | // positive integer expression. |
| 6388 | ExprResult Simdlen = VerifyPositiveIntegerConstantInClause(Len, OMPC_simdlen); |
| 6389 | if (Simdlen.isInvalid()) |
| 6390 | return nullptr; |
| 6391 | return new (Context) |
| 6392 | OMPSimdlenClause(Simdlen.get(), StartLoc, LParenLoc, EndLoc); |
| 6393 | } |
| 6394 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6395 | OMPClause *Sema::ActOnOpenMPCollapseClause(Expr *NumForLoops, |
| 6396 | SourceLocation StartLoc, |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6397 | SourceLocation LParenLoc, |
| 6398 | SourceLocation EndLoc) { |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6399 | // OpenMP [2.7.1, loop construct, Description] |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6400 | // OpenMP [2.8.1, simd construct, Description] |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6401 | // OpenMP [2.9.6, distribute construct, Description] |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6402 | // The parameter of the collapse clause must be a constant |
| 6403 | // positive integer expression. |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6404 | ExprResult NumForLoopsResult = |
| 6405 | VerifyPositiveIntegerConstantInClause(NumForLoops, OMPC_collapse); |
| 6406 | if (NumForLoopsResult.isInvalid()) |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6407 | return nullptr; |
| 6408 | return new (Context) |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6409 | OMPCollapseClause(NumForLoopsResult.get(), StartLoc, LParenLoc, EndLoc); |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6410 | } |
| 6411 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 6412 | OMPClause *Sema::ActOnOpenMPOrderedClause(SourceLocation StartLoc, |
| 6413 | SourceLocation EndLoc, |
| 6414 | SourceLocation LParenLoc, |
| 6415 | Expr *NumForLoops) { |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 6416 | // OpenMP [2.7.1, loop construct, Description] |
| 6417 | // OpenMP [2.8.1, simd construct, Description] |
| 6418 | // OpenMP [2.9.6, distribute construct, Description] |
| 6419 | // The parameter of the ordered clause must be a constant |
| 6420 | // positive integer expression if any. |
| 6421 | if (NumForLoops && LParenLoc.isValid()) { |
| 6422 | ExprResult NumForLoopsResult = |
| 6423 | VerifyPositiveIntegerConstantInClause(NumForLoops, OMPC_ordered); |
| 6424 | if (NumForLoopsResult.isInvalid()) |
| 6425 | return nullptr; |
| 6426 | NumForLoops = NumForLoopsResult.get(); |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6427 | } else |
| 6428 | NumForLoops = nullptr; |
| 6429 | DSAStack->setOrderedRegion(/*IsOrdered=*/true, NumForLoops); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 6430 | return new (Context) |
| 6431 | OMPOrderedClause(NumForLoops, StartLoc, LParenLoc, EndLoc); |
| 6432 | } |
| 6433 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6434 | OMPClause *Sema::ActOnOpenMPSimpleClause( |
| 6435 | OpenMPClauseKind Kind, unsigned Argument, SourceLocation ArgumentLoc, |
| 6436 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6437 | OMPClause *Res = nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6438 | switch (Kind) { |
| 6439 | case OMPC_default: |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6440 | Res = |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6441 | ActOnOpenMPDefaultClause(static_cast<OpenMPDefaultClauseKind>(Argument), |
| 6442 | ArgumentLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6443 | break; |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6444 | case OMPC_proc_bind: |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6445 | Res = ActOnOpenMPProcBindClause( |
| 6446 | static_cast<OpenMPProcBindClauseKind>(Argument), ArgumentLoc, StartLoc, |
| 6447 | LParenLoc, EndLoc); |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6448 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6449 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 6450 | case OMPC_final: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6451 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6452 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 6453 | case OMPC_simdlen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6454 | case OMPC_collapse: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6455 | case OMPC_schedule: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6456 | case OMPC_private: |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6457 | case OMPC_firstprivate: |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6458 | case OMPC_lastprivate: |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6459 | case OMPC_shared: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6460 | case OMPC_reduction: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6461 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 6462 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6463 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6464 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6465 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6466 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 6467 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 6468 | case OMPC_mergeable: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6469 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 6470 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6471 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6472 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6473 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6474 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 6475 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6476 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 6477 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6478 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6479 | case OMPC_simd: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 6480 | case OMPC_map: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 6481 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6482 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6483 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 6484 | case OMPC_grainsize: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 6485 | case OMPC_nogroup: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6486 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 6487 | case OMPC_hint: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 6488 | case OMPC_dist_schedule: |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 6489 | case OMPC_defaultmap: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6490 | case OMPC_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6491 | llvm_unreachable("Clause is not allowed."); |
| 6492 | } |
| 6493 | return Res; |
| 6494 | } |
| 6495 | |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6496 | static std::string |
| 6497 | getListOfPossibleValues(OpenMPClauseKind K, unsigned First, unsigned Last, |
| 6498 | ArrayRef<unsigned> Exclude = llvm::None) { |
| 6499 | std::string Values; |
| 6500 | unsigned Bound = Last >= 2 ? Last - 2 : 0; |
| 6501 | unsigned Skipped = Exclude.size(); |
| 6502 | auto S = Exclude.begin(), E = Exclude.end(); |
| 6503 | for (unsigned i = First; i < Last; ++i) { |
| 6504 | if (std::find(S, E, i) != E) { |
| 6505 | --Skipped; |
| 6506 | continue; |
| 6507 | } |
| 6508 | Values += "'"; |
| 6509 | Values += getOpenMPSimpleClauseTypeName(K, i); |
| 6510 | Values += "'"; |
| 6511 | if (i == Bound - Skipped) |
| 6512 | Values += " or "; |
| 6513 | else if (i != Bound + 1 - Skipped) |
| 6514 | Values += ", "; |
| 6515 | } |
| 6516 | return Values; |
| 6517 | } |
| 6518 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6519 | OMPClause *Sema::ActOnOpenMPDefaultClause(OpenMPDefaultClauseKind Kind, |
| 6520 | SourceLocation KindKwLoc, |
| 6521 | SourceLocation StartLoc, |
| 6522 | SourceLocation LParenLoc, |
| 6523 | SourceLocation EndLoc) { |
| 6524 | if (Kind == OMPC_DEFAULT_unknown) { |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 6525 | static_assert(OMPC_DEFAULT_unknown > 0, |
| 6526 | "OMPC_DEFAULT_unknown not greater than 0"); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6527 | Diag(KindKwLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6528 | << getListOfPossibleValues(OMPC_default, /*First=*/0, |
| 6529 | /*Last=*/OMPC_DEFAULT_unknown) |
| 6530 | << getOpenMPClauseName(OMPC_default); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6531 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6532 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6533 | switch (Kind) { |
| 6534 | case OMPC_DEFAULT_none: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6535 | DSAStack->setDefaultDSANone(KindKwLoc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6536 | break; |
| 6537 | case OMPC_DEFAULT_shared: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6538 | DSAStack->setDefaultDSAShared(KindKwLoc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6539 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6540 | case OMPC_DEFAULT_unknown: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6541 | llvm_unreachable("Clause kind is not allowed."); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6542 | break; |
| 6543 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6544 | return new (Context) |
| 6545 | OMPDefaultClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6546 | } |
| 6547 | |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6548 | OMPClause *Sema::ActOnOpenMPProcBindClause(OpenMPProcBindClauseKind Kind, |
| 6549 | SourceLocation KindKwLoc, |
| 6550 | SourceLocation StartLoc, |
| 6551 | SourceLocation LParenLoc, |
| 6552 | SourceLocation EndLoc) { |
| 6553 | if (Kind == OMPC_PROC_BIND_unknown) { |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6554 | Diag(KindKwLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6555 | << getListOfPossibleValues(OMPC_proc_bind, /*First=*/0, |
| 6556 | /*Last=*/OMPC_PROC_BIND_unknown) |
| 6557 | << getOpenMPClauseName(OMPC_proc_bind); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6558 | return nullptr; |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6559 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6560 | return new (Context) |
| 6561 | OMPProcBindClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6562 | } |
| 6563 | |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6564 | OMPClause *Sema::ActOnOpenMPSingleExprWithArgClause( |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6565 | OpenMPClauseKind Kind, ArrayRef<unsigned> Argument, Expr *Expr, |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6566 | SourceLocation StartLoc, SourceLocation LParenLoc, |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6567 | ArrayRef<SourceLocation> ArgumentLoc, SourceLocation DelimLoc, |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6568 | SourceLocation EndLoc) { |
| 6569 | OMPClause *Res = nullptr; |
| 6570 | switch (Kind) { |
| 6571 | case OMPC_schedule: |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6572 | enum { Modifier1, Modifier2, ScheduleKind, NumberOfElements }; |
| 6573 | assert(Argument.size() == NumberOfElements && |
| 6574 | ArgumentLoc.size() == NumberOfElements); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6575 | Res = ActOnOpenMPScheduleClause( |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6576 | static_cast<OpenMPScheduleClauseModifier>(Argument[Modifier1]), |
| 6577 | static_cast<OpenMPScheduleClauseModifier>(Argument[Modifier2]), |
| 6578 | static_cast<OpenMPScheduleClauseKind>(Argument[ScheduleKind]), Expr, |
| 6579 | StartLoc, LParenLoc, ArgumentLoc[Modifier1], ArgumentLoc[Modifier2], |
| 6580 | ArgumentLoc[ScheduleKind], DelimLoc, EndLoc); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6581 | break; |
| 6582 | case OMPC_if: |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6583 | assert(Argument.size() == 1 && ArgumentLoc.size() == 1); |
| 6584 | Res = ActOnOpenMPIfClause(static_cast<OpenMPDirectiveKind>(Argument.back()), |
| 6585 | Expr, StartLoc, LParenLoc, ArgumentLoc.back(), |
| 6586 | DelimLoc, EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6587 | break; |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 6588 | case OMPC_dist_schedule: |
| 6589 | Res = ActOnOpenMPDistScheduleClause( |
| 6590 | static_cast<OpenMPDistScheduleClauseKind>(Argument.back()), Expr, |
| 6591 | StartLoc, LParenLoc, ArgumentLoc.back(), DelimLoc, EndLoc); |
| 6592 | break; |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 6593 | case OMPC_defaultmap: |
| 6594 | enum { Modifier, DefaultmapKind }; |
| 6595 | Res = ActOnOpenMPDefaultmapClause( |
| 6596 | static_cast<OpenMPDefaultmapClauseModifier>(Argument[Modifier]), |
| 6597 | static_cast<OpenMPDefaultmapClauseKind>(Argument[DefaultmapKind]), |
| 6598 | StartLoc, LParenLoc, ArgumentLoc[Modifier], |
| 6599 | ArgumentLoc[DefaultmapKind], EndLoc); |
| 6600 | break; |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 6601 | case OMPC_final: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6602 | case OMPC_num_threads: |
| 6603 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 6604 | case OMPC_simdlen: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6605 | case OMPC_collapse: |
| 6606 | case OMPC_default: |
| 6607 | case OMPC_proc_bind: |
| 6608 | case OMPC_private: |
| 6609 | case OMPC_firstprivate: |
| 6610 | case OMPC_lastprivate: |
| 6611 | case OMPC_shared: |
| 6612 | case OMPC_reduction: |
| 6613 | case OMPC_linear: |
| 6614 | case OMPC_aligned: |
| 6615 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6616 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6617 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6618 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 6619 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 6620 | case OMPC_mergeable: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6621 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 6622 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6623 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6624 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6625 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6626 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 6627 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6628 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 6629 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6630 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6631 | case OMPC_simd: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 6632 | case OMPC_map: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 6633 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6634 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6635 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 6636 | case OMPC_grainsize: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 6637 | case OMPC_nogroup: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6638 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 6639 | case OMPC_hint: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6640 | case OMPC_unknown: |
| 6641 | llvm_unreachable("Clause is not allowed."); |
| 6642 | } |
| 6643 | return Res; |
| 6644 | } |
| 6645 | |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6646 | static bool checkScheduleModifiers(Sema &S, OpenMPScheduleClauseModifier M1, |
| 6647 | OpenMPScheduleClauseModifier M2, |
| 6648 | SourceLocation M1Loc, SourceLocation M2Loc) { |
| 6649 | if (M1 == OMPC_SCHEDULE_MODIFIER_unknown && M1Loc.isValid()) { |
| 6650 | SmallVector<unsigned, 2> Excluded; |
| 6651 | if (M2 != OMPC_SCHEDULE_MODIFIER_unknown) |
| 6652 | Excluded.push_back(M2); |
| 6653 | if (M2 == OMPC_SCHEDULE_MODIFIER_nonmonotonic) |
| 6654 | Excluded.push_back(OMPC_SCHEDULE_MODIFIER_monotonic); |
| 6655 | if (M2 == OMPC_SCHEDULE_MODIFIER_monotonic) |
| 6656 | Excluded.push_back(OMPC_SCHEDULE_MODIFIER_nonmonotonic); |
| 6657 | S.Diag(M1Loc, diag::err_omp_unexpected_clause_value) |
| 6658 | << getListOfPossibleValues(OMPC_schedule, |
| 6659 | /*First=*/OMPC_SCHEDULE_MODIFIER_unknown + 1, |
| 6660 | /*Last=*/OMPC_SCHEDULE_MODIFIER_last, |
| 6661 | Excluded) |
| 6662 | << getOpenMPClauseName(OMPC_schedule); |
| 6663 | return true; |
| 6664 | } |
| 6665 | return false; |
| 6666 | } |
| 6667 | |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6668 | OMPClause *Sema::ActOnOpenMPScheduleClause( |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6669 | OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2, |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6670 | OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6671 | SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc, |
| 6672 | SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) { |
| 6673 | if (checkScheduleModifiers(*this, M1, M2, M1Loc, M2Loc) || |
| 6674 | checkScheduleModifiers(*this, M2, M1, M2Loc, M1Loc)) |
| 6675 | return nullptr; |
| 6676 | // OpenMP, 2.7.1, Loop Construct, Restrictions |
| 6677 | // Either the monotonic modifier or the nonmonotonic modifier can be specified |
| 6678 | // but not both. |
| 6679 | if ((M1 == M2 && M1 != OMPC_SCHEDULE_MODIFIER_unknown) || |
| 6680 | (M1 == OMPC_SCHEDULE_MODIFIER_monotonic && |
| 6681 | M2 == OMPC_SCHEDULE_MODIFIER_nonmonotonic) || |
| 6682 | (M1 == OMPC_SCHEDULE_MODIFIER_nonmonotonic && |
| 6683 | M2 == OMPC_SCHEDULE_MODIFIER_monotonic)) { |
| 6684 | Diag(M2Loc, diag::err_omp_unexpected_schedule_modifier) |
| 6685 | << getOpenMPSimpleClauseTypeName(OMPC_schedule, M2) |
| 6686 | << getOpenMPSimpleClauseTypeName(OMPC_schedule, M1); |
| 6687 | return nullptr; |
| 6688 | } |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6689 | if (Kind == OMPC_SCHEDULE_unknown) { |
| 6690 | std::string Values; |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6691 | if (M1Loc.isInvalid() && M2Loc.isInvalid()) { |
| 6692 | unsigned Exclude[] = {OMPC_SCHEDULE_unknown}; |
| 6693 | Values = getListOfPossibleValues(OMPC_schedule, /*First=*/0, |
| 6694 | /*Last=*/OMPC_SCHEDULE_MODIFIER_last, |
| 6695 | Exclude); |
| 6696 | } else { |
| 6697 | Values = getListOfPossibleValues(OMPC_schedule, /*First=*/0, |
| 6698 | /*Last=*/OMPC_SCHEDULE_unknown); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6699 | } |
| 6700 | Diag(KindLoc, diag::err_omp_unexpected_clause_value) |
| 6701 | << Values << getOpenMPClauseName(OMPC_schedule); |
| 6702 | return nullptr; |
| 6703 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6704 | // OpenMP, 2.7.1, Loop Construct, Restrictions |
| 6705 | // The nonmonotonic modifier can only be specified with schedule(dynamic) or |
| 6706 | // schedule(guided). |
| 6707 | if ((M1 == OMPC_SCHEDULE_MODIFIER_nonmonotonic || |
| 6708 | M2 == OMPC_SCHEDULE_MODIFIER_nonmonotonic) && |
| 6709 | Kind != OMPC_SCHEDULE_dynamic && Kind != OMPC_SCHEDULE_guided) { |
| 6710 | Diag(M1 == OMPC_SCHEDULE_MODIFIER_nonmonotonic ? M1Loc : M2Loc, |
| 6711 | diag::err_omp_schedule_nonmonotonic_static); |
| 6712 | return nullptr; |
| 6713 | } |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6714 | Expr *ValExpr = ChunkSize; |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 6715 | Expr *HelperValExpr = nullptr; |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6716 | if (ChunkSize) { |
| 6717 | if (!ChunkSize->isValueDependent() && !ChunkSize->isTypeDependent() && |
| 6718 | !ChunkSize->isInstantiationDependent() && |
| 6719 | !ChunkSize->containsUnexpandedParameterPack()) { |
| 6720 | SourceLocation ChunkSizeLoc = ChunkSize->getLocStart(); |
| 6721 | ExprResult Val = |
| 6722 | PerformOpenMPImplicitIntegerConversion(ChunkSizeLoc, ChunkSize); |
| 6723 | if (Val.isInvalid()) |
| 6724 | return nullptr; |
| 6725 | |
| 6726 | ValExpr = Val.get(); |
| 6727 | |
| 6728 | // OpenMP [2.7.1, Restrictions] |
| 6729 | // chunk_size must be a loop invariant integer expression with a positive |
| 6730 | // value. |
| 6731 | llvm::APSInt Result; |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 6732 | if (ValExpr->isIntegerConstantExpr(Result, Context)) { |
| 6733 | if (Result.isSigned() && !Result.isStrictlyPositive()) { |
| 6734 | Diag(ChunkSizeLoc, diag::err_omp_negative_expression_in_clause) |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6735 | << "schedule" << 1 << ChunkSize->getSourceRange(); |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 6736 | return nullptr; |
| 6737 | } |
| 6738 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective())) { |
| 6739 | auto *ImpVar = buildVarDecl(*this, ChunkSize->getExprLoc(), |
| 6740 | ChunkSize->getType(), ".chunk."); |
| 6741 | auto *ImpVarRef = buildDeclRefExpr(*this, ImpVar, ChunkSize->getType(), |
| 6742 | ChunkSize->getExprLoc(), |
| 6743 | /*RefersToCapture=*/true); |
| 6744 | HelperValExpr = ImpVarRef; |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6745 | } |
| 6746 | } |
| 6747 | } |
| 6748 | |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6749 | return new (Context) |
| 6750 | OMPScheduleClause(StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc, Kind, |
| 6751 | ValExpr, HelperValExpr, M1, M1Loc, M2, M2Loc); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6752 | } |
| 6753 | |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6754 | OMPClause *Sema::ActOnOpenMPClause(OpenMPClauseKind Kind, |
| 6755 | SourceLocation StartLoc, |
| 6756 | SourceLocation EndLoc) { |
| 6757 | OMPClause *Res = nullptr; |
| 6758 | switch (Kind) { |
| 6759 | case OMPC_ordered: |
| 6760 | Res = ActOnOpenMPOrderedClause(StartLoc, EndLoc); |
| 6761 | break; |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6762 | case OMPC_nowait: |
| 6763 | Res = ActOnOpenMPNowaitClause(StartLoc, EndLoc); |
| 6764 | break; |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 6765 | case OMPC_untied: |
| 6766 | Res = ActOnOpenMPUntiedClause(StartLoc, EndLoc); |
| 6767 | break; |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 6768 | case OMPC_mergeable: |
| 6769 | Res = ActOnOpenMPMergeableClause(StartLoc, EndLoc); |
| 6770 | break; |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6771 | case OMPC_read: |
| 6772 | Res = ActOnOpenMPReadClause(StartLoc, EndLoc); |
| 6773 | break; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6774 | case OMPC_write: |
| 6775 | Res = ActOnOpenMPWriteClause(StartLoc, EndLoc); |
| 6776 | break; |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6777 | case OMPC_update: |
| 6778 | Res = ActOnOpenMPUpdateClause(StartLoc, EndLoc); |
| 6779 | break; |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6780 | case OMPC_capture: |
| 6781 | Res = ActOnOpenMPCaptureClause(StartLoc, EndLoc); |
| 6782 | break; |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 6783 | case OMPC_seq_cst: |
| 6784 | Res = ActOnOpenMPSeqCstClause(StartLoc, EndLoc); |
| 6785 | break; |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6786 | case OMPC_threads: |
| 6787 | Res = ActOnOpenMPThreadsClause(StartLoc, EndLoc); |
| 6788 | break; |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6789 | case OMPC_simd: |
| 6790 | Res = ActOnOpenMPSIMDClause(StartLoc, EndLoc); |
| 6791 | break; |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 6792 | case OMPC_nogroup: |
| 6793 | Res = ActOnOpenMPNogroupClause(StartLoc, EndLoc); |
| 6794 | break; |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6795 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 6796 | case OMPC_final: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6797 | case OMPC_num_threads: |
| 6798 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 6799 | case OMPC_simdlen: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6800 | case OMPC_collapse: |
| 6801 | case OMPC_schedule: |
| 6802 | case OMPC_private: |
| 6803 | case OMPC_firstprivate: |
| 6804 | case OMPC_lastprivate: |
| 6805 | case OMPC_shared: |
| 6806 | case OMPC_reduction: |
| 6807 | case OMPC_linear: |
| 6808 | case OMPC_aligned: |
| 6809 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6810 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6811 | case OMPC_default: |
| 6812 | case OMPC_proc_bind: |
| 6813 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 6814 | case OMPC_flush: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6815 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 6816 | case OMPC_device: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 6817 | case OMPC_map: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 6818 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6819 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6820 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 6821 | case OMPC_grainsize: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6822 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 6823 | case OMPC_hint: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 6824 | case OMPC_dist_schedule: |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 6825 | case OMPC_defaultmap: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6826 | case OMPC_unknown: |
| 6827 | llvm_unreachable("Clause is not allowed."); |
| 6828 | } |
| 6829 | return Res; |
| 6830 | } |
| 6831 | |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6832 | OMPClause *Sema::ActOnOpenMPNowaitClause(SourceLocation StartLoc, |
| 6833 | SourceLocation EndLoc) { |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 6834 | DSAStack->setNowaitRegion(); |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6835 | return new (Context) OMPNowaitClause(StartLoc, EndLoc); |
| 6836 | } |
| 6837 | |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 6838 | OMPClause *Sema::ActOnOpenMPUntiedClause(SourceLocation StartLoc, |
| 6839 | SourceLocation EndLoc) { |
| 6840 | return new (Context) OMPUntiedClause(StartLoc, EndLoc); |
| 6841 | } |
| 6842 | |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 6843 | OMPClause *Sema::ActOnOpenMPMergeableClause(SourceLocation StartLoc, |
| 6844 | SourceLocation EndLoc) { |
| 6845 | return new (Context) OMPMergeableClause(StartLoc, EndLoc); |
| 6846 | } |
| 6847 | |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6848 | OMPClause *Sema::ActOnOpenMPReadClause(SourceLocation StartLoc, |
| 6849 | SourceLocation EndLoc) { |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6850 | return new (Context) OMPReadClause(StartLoc, EndLoc); |
| 6851 | } |
| 6852 | |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6853 | OMPClause *Sema::ActOnOpenMPWriteClause(SourceLocation StartLoc, |
| 6854 | SourceLocation EndLoc) { |
| 6855 | return new (Context) OMPWriteClause(StartLoc, EndLoc); |
| 6856 | } |
| 6857 | |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6858 | OMPClause *Sema::ActOnOpenMPUpdateClause(SourceLocation StartLoc, |
| 6859 | SourceLocation EndLoc) { |
| 6860 | return new (Context) OMPUpdateClause(StartLoc, EndLoc); |
| 6861 | } |
| 6862 | |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6863 | OMPClause *Sema::ActOnOpenMPCaptureClause(SourceLocation StartLoc, |
| 6864 | SourceLocation EndLoc) { |
| 6865 | return new (Context) OMPCaptureClause(StartLoc, EndLoc); |
| 6866 | } |
| 6867 | |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 6868 | OMPClause *Sema::ActOnOpenMPSeqCstClause(SourceLocation StartLoc, |
| 6869 | SourceLocation EndLoc) { |
| 6870 | return new (Context) OMPSeqCstClause(StartLoc, EndLoc); |
| 6871 | } |
| 6872 | |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6873 | OMPClause *Sema::ActOnOpenMPThreadsClause(SourceLocation StartLoc, |
| 6874 | SourceLocation EndLoc) { |
| 6875 | return new (Context) OMPThreadsClause(StartLoc, EndLoc); |
| 6876 | } |
| 6877 | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6878 | OMPClause *Sema::ActOnOpenMPSIMDClause(SourceLocation StartLoc, |
| 6879 | SourceLocation EndLoc) { |
| 6880 | return new (Context) OMPSIMDClause(StartLoc, EndLoc); |
| 6881 | } |
| 6882 | |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 6883 | OMPClause *Sema::ActOnOpenMPNogroupClause(SourceLocation StartLoc, |
| 6884 | SourceLocation EndLoc) { |
| 6885 | return new (Context) OMPNogroupClause(StartLoc, EndLoc); |
| 6886 | } |
| 6887 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6888 | OMPClause *Sema::ActOnOpenMPVarListClause( |
| 6889 | OpenMPClauseKind Kind, ArrayRef<Expr *> VarList, Expr *TailExpr, |
| 6890 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, |
| 6891 | SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6892 | const DeclarationNameInfo &ReductionId, OpenMPDependClauseKind DepKind, |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 6893 | OpenMPLinearClauseKind LinKind, OpenMPMapClauseKind MapTypeModifier, |
| 6894 | OpenMPMapClauseKind MapType, bool IsMapTypeImplicit, |
| 6895 | SourceLocation DepLinMapLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6896 | OMPClause *Res = nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6897 | switch (Kind) { |
| 6898 | case OMPC_private: |
| 6899 | Res = ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 6900 | break; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6901 | case OMPC_firstprivate: |
| 6902 | Res = ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 6903 | break; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6904 | case OMPC_lastprivate: |
| 6905 | Res = ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 6906 | break; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6907 | case OMPC_shared: |
| 6908 | Res = ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 6909 | break; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6910 | case OMPC_reduction: |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 6911 | Res = ActOnOpenMPReductionClause(VarList, StartLoc, LParenLoc, ColonLoc, |
| 6912 | EndLoc, ReductionIdScopeSpec, ReductionId); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6913 | break; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6914 | case OMPC_linear: |
| 6915 | Res = ActOnOpenMPLinearClause(VarList, TailExpr, StartLoc, LParenLoc, |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 6916 | LinKind, DepLinMapLoc, ColonLoc, EndLoc); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6917 | break; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 6918 | case OMPC_aligned: |
| 6919 | Res = ActOnOpenMPAlignedClause(VarList, TailExpr, StartLoc, LParenLoc, |
| 6920 | ColonLoc, EndLoc); |
| 6921 | break; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6922 | case OMPC_copyin: |
| 6923 | Res = ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 6924 | break; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6925 | case OMPC_copyprivate: |
| 6926 | Res = ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 6927 | break; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 6928 | case OMPC_flush: |
| 6929 | Res = ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 6930 | break; |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6931 | case OMPC_depend: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 6932 | Res = ActOnOpenMPDependClause(DepKind, DepLinMapLoc, ColonLoc, VarList, |
| 6933 | StartLoc, LParenLoc, EndLoc); |
| 6934 | break; |
| 6935 | case OMPC_map: |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 6936 | Res = ActOnOpenMPMapClause(MapTypeModifier, MapType, IsMapTypeImplicit, |
| 6937 | DepLinMapLoc, ColonLoc, VarList, StartLoc, |
| 6938 | LParenLoc, EndLoc); |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6939 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6940 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 6941 | case OMPC_final: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6942 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6943 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 6944 | case OMPC_simdlen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6945 | case OMPC_collapse: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6946 | case OMPC_default: |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6947 | case OMPC_proc_bind: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6948 | case OMPC_schedule: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6949 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6950 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 6951 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 6952 | case OMPC_mergeable: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6953 | case OMPC_threadprivate: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6954 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6955 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6956 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6957 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 6958 | case OMPC_seq_cst: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 6959 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6960 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6961 | case OMPC_simd: |
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 | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6972 | llvm_unreachable("Clause is not allowed."); |
| 6973 | } |
| 6974 | return Res; |
| 6975 | } |
| 6976 | |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 6977 | static DeclRefExpr *buildCapture(Sema &S, IdentifierInfo *Id, |
| 6978 | Expr *CaptureExpr) { |
| 6979 | ASTContext &C = S.getASTContext(); |
| 6980 | Expr *Init = CaptureExpr->IgnoreImpCasts(); |
| 6981 | QualType Ty = Init->getType(); |
| 6982 | if (CaptureExpr->getObjectKind() == OK_Ordinary) { |
| 6983 | if (S.getLangOpts().CPlusPlus) |
| 6984 | Ty = C.getLValueReferenceType(Ty); |
| 6985 | else { |
| 6986 | Ty = C.getPointerType(Ty); |
| 6987 | ExprResult Res = |
| 6988 | S.CreateBuiltinUnaryOp(CaptureExpr->getExprLoc(), UO_AddrOf, Init); |
| 6989 | if (!Res.isUsable()) |
| 6990 | return nullptr; |
| 6991 | Init = Res.get(); |
| 6992 | } |
| 6993 | } |
| 6994 | auto *CFD = OMPCapturedFieldDecl::Create(C, S.CurContext, Id, Ty); |
| 6995 | S.CurContext->addHiddenDecl(CFD); |
| 6996 | S.AddInitializerToDecl(CFD, Init, /*DirectInit=*/false, |
| 6997 | /*TypeMayContainAuto=*/true); |
| 6998 | return buildDeclRefExpr(S, CFD, Ty.getNonReferenceType(), SourceLocation()); |
| 6999 | } |
| 7000 | |
| 7001 | ExprResult Sema::getOpenMPCapturedExpr(VarDecl *Capture, ExprValueKind VK, |
| 7002 | ExprObjectKind OK) { |
| 7003 | SourceLocation Loc = Capture->getInit()->getExprLoc(); |
| 7004 | ExprResult Res = BuildDeclRefExpr( |
| 7005 | Capture, Capture->getType().getNonReferenceType(), VK_LValue, Loc); |
| 7006 | if (!Res.isUsable()) |
| 7007 | return ExprError(); |
| 7008 | if (OK == OK_Ordinary && !getLangOpts().CPlusPlus) { |
| 7009 | Res = CreateBuiltinUnaryOp(Loc, UO_Deref, Res.get()); |
| 7010 | if (!Res.isUsable()) |
| 7011 | return ExprError(); |
| 7012 | } |
| 7013 | if (VK != VK_LValue && Res.get()->isGLValue()) { |
| 7014 | Res = DefaultLvalueConversion(Res.get()); |
| 7015 | if (!Res.isUsable()) |
| 7016 | return ExprError(); |
| 7017 | } |
| 7018 | return Res; |
| 7019 | } |
| 7020 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7021 | OMPClause *Sema::ActOnOpenMPPrivateClause(ArrayRef<Expr *> VarList, |
| 7022 | SourceLocation StartLoc, |
| 7023 | SourceLocation LParenLoc, |
| 7024 | SourceLocation EndLoc) { |
| 7025 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 7026 | SmallVector<Expr *, 8> PrivateCopies; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7027 | for (auto &RefExpr : VarList) { |
| 7028 | assert(RefExpr && "NULL expr in OpenMP private clause."); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7029 | if (RefExpr->isTypeDependent() || RefExpr->isValueDependent() || |
| 7030 | RefExpr->containsUnexpandedParameterPack()) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7031 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7032 | Vars.push_back(RefExpr); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 7033 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7034 | continue; |
| 7035 | } |
| 7036 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7037 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Carlo Bertolli | 9e8c6c1 | 2016-01-19 16:53:55 +0000 | [diff] [blame] | 7038 | // OpenMP [3.1, C/C++] |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7039 | // A list item is a variable name. |
| 7040 | // OpenMP [2.9.3.3, Restrictions, p.1] |
| 7041 | // A variable that is part of another variable (as an array or |
| 7042 | // structure element) cannot appear in a private clause. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7043 | auto *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr->IgnoreParens()); |
| 7044 | auto *ME = dyn_cast_or_null<MemberExpr>(RefExpr->IgnoreParens()); |
| 7045 | if ((!DE || !isa<VarDecl>(DE->getDecl())) && |
| 7046 | (getCurrentThisType().isNull() || !ME || |
| 7047 | !isa<CXXThisExpr>(ME->getBase()->IgnoreParenImpCasts()) || |
| 7048 | !isa<FieldDecl>(ME->getMemberDecl()))) { |
| 7049 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr) |
| 7050 | << (getCurrentThisType().isNull() ? 0 : 1) |
| 7051 | << RefExpr->getSourceRange(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7052 | continue; |
| 7053 | } |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7054 | ValueDecl *D = DE ? DE->getDecl() : ME->getMemberDecl(); |
| 7055 | QualType Type = D->getType(); |
| 7056 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7057 | |
| 7058 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 7059 | // A variable that appears in a private clause must not have an incomplete |
| 7060 | // type or a reference type. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7061 | if (RequireCompleteType(ELoc, Type, diag::err_omp_private_incomplete_type)) |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7062 | continue; |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7063 | Type = Type.getNonReferenceType(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7064 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7065 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 7066 | // in a Construct] |
| 7067 | // Variables with the predetermined data-sharing attributes may not be |
| 7068 | // listed in data-sharing attributes clauses, except for the cases |
| 7069 | // listed below. For these exceptions only, listing a predetermined |
| 7070 | // variable in a data-sharing attribute clause is allowed and overrides |
| 7071 | // the variable's predetermined data-sharing attributes. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7072 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7073 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_private) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7074 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 7075 | << getOpenMPClauseName(OMPC_private); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7076 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7077 | continue; |
| 7078 | } |
| 7079 | |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7080 | // Variably modified types are not supported for tasks. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 7081 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType() && |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7082 | DSAStack->getCurrentDirective() == OMPD_task) { |
| 7083 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
| 7084 | << getOpenMPClauseName(OMPC_private) << Type |
| 7085 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 7086 | bool IsDecl = |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7087 | !VD || |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7088 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7089 | Diag(D->getLocation(), |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7090 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7091 | << D; |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7092 | continue; |
| 7093 | } |
| 7094 | |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7095 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.1] |
| 7096 | // A variable of class type (or array thereof) that appears in a private |
| 7097 | // clause requires an accessible, unambiguous default constructor for the |
| 7098 | // class type. |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 7099 | // Generate helper private variable and initialize it with the default |
| 7100 | // value. The address of the original variable is replaced by the address of |
| 7101 | // the new private variable in CodeGen. This new variable is not added to |
| 7102 | // IdResolver, so the code in the OpenMP region uses original variable for |
| 7103 | // proper diagnostics. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7104 | Type = Type.getUnqualifiedType(); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7105 | auto VDPrivate = buildVarDecl(*this, ELoc, Type, D->getName(), |
| 7106 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7107 | ActOnUninitializedDecl(VDPrivate, /*TypeMayContainAuto=*/false); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 7108 | if (VDPrivate->isInvalidDecl()) |
| 7109 | continue; |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7110 | auto VDPrivateRefExpr = buildDeclRefExpr( |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7111 | *this, VDPrivate, RefExpr->getType().getUnqualifiedType(), ELoc); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 7112 | |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 7113 | DeclRefExpr *Ref = nullptr; |
| 7114 | if (!VD) |
| 7115 | Ref = buildCapture(*this, D->getIdentifier(), RefExpr); |
| 7116 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_private, Ref); |
| 7117 | Vars.push_back(VD ? RefExpr->IgnoreParens() : Ref); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 7118 | PrivateCopies.push_back(VDPrivateRefExpr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7119 | } |
| 7120 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7121 | if (Vars.empty()) |
| 7122 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7123 | |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 7124 | return OMPPrivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
| 7125 | PrivateCopies); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7126 | } |
| 7127 | |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7128 | namespace { |
| 7129 | class DiagsUninitializedSeveretyRAII { |
| 7130 | private: |
| 7131 | DiagnosticsEngine &Diags; |
| 7132 | SourceLocation SavedLoc; |
| 7133 | bool IsIgnored; |
| 7134 | |
| 7135 | public: |
| 7136 | DiagsUninitializedSeveretyRAII(DiagnosticsEngine &Diags, SourceLocation Loc, |
| 7137 | bool IsIgnored) |
| 7138 | : Diags(Diags), SavedLoc(Loc), IsIgnored(IsIgnored) { |
| 7139 | if (!IsIgnored) { |
| 7140 | Diags.setSeverity(/*Diag*/ diag::warn_uninit_self_reference_in_init, |
| 7141 | /*Map*/ diag::Severity::Ignored, Loc); |
| 7142 | } |
| 7143 | } |
| 7144 | ~DiagsUninitializedSeveretyRAII() { |
| 7145 | if (!IsIgnored) |
| 7146 | Diags.popMappings(SavedLoc); |
| 7147 | } |
| 7148 | }; |
Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 7149 | } |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7150 | |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7151 | OMPClause *Sema::ActOnOpenMPFirstprivateClause(ArrayRef<Expr *> VarList, |
| 7152 | SourceLocation StartLoc, |
| 7153 | SourceLocation LParenLoc, |
| 7154 | SourceLocation EndLoc) { |
| 7155 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7156 | SmallVector<Expr *, 8> PrivateCopies; |
| 7157 | SmallVector<Expr *, 8> Inits; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7158 | bool IsImplicitClause = |
| 7159 | StartLoc.isInvalid() && LParenLoc.isInvalid() && EndLoc.isInvalid(); |
| 7160 | auto ImplicitClauseLoc = DSAStack->getConstructLoc(); |
| 7161 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7162 | for (auto &RefExpr : VarList) { |
| 7163 | assert(RefExpr && "NULL expr in OpenMP firstprivate clause."); |
| 7164 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7165 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7166 | Vars.push_back(RefExpr); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7167 | PrivateCopies.push_back(nullptr); |
| 7168 | Inits.push_back(nullptr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7169 | continue; |
| 7170 | } |
| 7171 | |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7172 | SourceLocation ELoc = |
| 7173 | IsImplicitClause ? ImplicitClauseLoc : RefExpr->getExprLoc(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7174 | // OpenMP [2.1, C/C++] |
| 7175 | // A list item is a variable name. |
| 7176 | // OpenMP [2.9.3.3, Restrictions, p.1] |
| 7177 | // A variable that is part of another variable (as an array or |
| 7178 | // structure element) cannot appear in a private clause. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7179 | DeclRefExpr *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7180 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7181 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr) |
| 7182 | << 0 << RefExpr->getSourceRange(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7183 | continue; |
| 7184 | } |
| 7185 | Decl *D = DE->getDecl(); |
| 7186 | VarDecl *VD = cast<VarDecl>(D); |
| 7187 | |
| 7188 | QualType Type = VD->getType(); |
| 7189 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 7190 | // It will be analyzed later. |
| 7191 | Vars.push_back(DE); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7192 | PrivateCopies.push_back(nullptr); |
| 7193 | Inits.push_back(nullptr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7194 | continue; |
| 7195 | } |
| 7196 | |
| 7197 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 7198 | // A variable that appears in a private clause must not have an incomplete |
| 7199 | // type or a reference type. |
| 7200 | if (RequireCompleteType(ELoc, Type, |
| 7201 | diag::err_omp_firstprivate_incomplete_type)) { |
| 7202 | continue; |
| 7203 | } |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7204 | Type = Type.getNonReferenceType(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7205 | |
| 7206 | // OpenMP [2.9.3.4, Restrictions, C/C++, p.1] |
| 7207 | // 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] | 7208 | // clause requires an accessible, unambiguous copy constructor for the |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7209 | // class type. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7210 | auto ElemType = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7211 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7212 | // If an implicit firstprivate variable found it was checked already. |
| 7213 | if (!IsImplicitClause) { |
| 7214 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7215 | bool IsConstant = ElemType.isConstant(Context); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7216 | // OpenMP [2.4.13, Data-sharing Attribute Clauses] |
| 7217 | // A list item that specifies a given variable may not appear in more |
| 7218 | // than one clause on the same directive, except that a variable may be |
| 7219 | // specified in both firstprivate and lastprivate clauses. |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7220 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_firstprivate && |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7221 | DVar.CKind != OMPC_lastprivate && DVar.RefExpr) { |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7222 | Diag(ELoc, diag::err_omp_wrong_dsa) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7223 | << getOpenMPClauseName(DVar.CKind) |
| 7224 | << getOpenMPClauseName(OMPC_firstprivate); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 7225 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7226 | continue; |
| 7227 | } |
| 7228 | |
| 7229 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 7230 | // in a Construct] |
| 7231 | // Variables with the predetermined data-sharing attributes may not be |
| 7232 | // listed in data-sharing attributes clauses, except for the cases |
| 7233 | // listed below. For these exceptions only, listing a predetermined |
| 7234 | // variable in a data-sharing attribute clause is allowed and overrides |
| 7235 | // the variable's predetermined data-sharing attributes. |
| 7236 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 7237 | // in a Construct, C/C++, p.2] |
| 7238 | // Variables with const-qualified type having no mutable member may be |
| 7239 | // listed in a firstprivate clause, even if they are static data members. |
| 7240 | if (!(IsConstant || VD->isStaticDataMember()) && !DVar.RefExpr && |
| 7241 | DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared) { |
| 7242 | Diag(ELoc, diag::err_omp_wrong_dsa) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7243 | << getOpenMPClauseName(DVar.CKind) |
| 7244 | << getOpenMPClauseName(OMPC_firstprivate); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 7245 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7246 | continue; |
| 7247 | } |
| 7248 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7249 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7250 | // OpenMP [2.9.3.4, Restrictions, p.2] |
| 7251 | // A list item that is private within a parallel region must not appear |
| 7252 | // in a firstprivate clause on a worksharing construct if any of the |
| 7253 | // worksharing regions arising from the worksharing construct ever bind |
| 7254 | // to any of the parallel regions arising from the parallel construct. |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 7255 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 7256 | !isOpenMPParallelDirective(CurrDir)) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7257 | DVar = DSAStack->getImplicitDSA(VD, true); |
| 7258 | if (DVar.CKind != OMPC_shared && |
| 7259 | (isOpenMPParallelDirective(DVar.DKind) || |
| 7260 | DVar.DKind == OMPD_unknown)) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7261 | Diag(ELoc, diag::err_omp_required_access) |
| 7262 | << getOpenMPClauseName(OMPC_firstprivate) |
| 7263 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 7264 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7265 | continue; |
| 7266 | } |
| 7267 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7268 | // OpenMP [2.9.3.4, Restrictions, p.3] |
| 7269 | // A list item that appears in a reduction clause of a parallel construct |
| 7270 | // must not appear in a firstprivate clause on a worksharing or task |
| 7271 | // construct if any of the worksharing or task regions arising from the |
| 7272 | // worksharing or task construct ever bind to any of the parallel regions |
| 7273 | // arising from the parallel construct. |
| 7274 | // OpenMP [2.9.3.4, Restrictions, p.4] |
| 7275 | // A list item that appears in a reduction clause in worksharing |
| 7276 | // construct must not appear in a firstprivate clause in a task construct |
| 7277 | // encountered during execution of any of the worksharing regions arising |
| 7278 | // from the worksharing construct. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7279 | if (CurrDir == OMPD_task) { |
| 7280 | DVar = |
| 7281 | DSAStack->hasInnermostDSA(VD, MatchesAnyClause(OMPC_reduction), |
| 7282 | [](OpenMPDirectiveKind K) -> bool { |
| 7283 | return isOpenMPParallelDirective(K) || |
| 7284 | isOpenMPWorksharingDirective(K); |
| 7285 | }, |
| 7286 | false); |
| 7287 | if (DVar.CKind == OMPC_reduction && |
| 7288 | (isOpenMPParallelDirective(DVar.DKind) || |
| 7289 | isOpenMPWorksharingDirective(DVar.DKind))) { |
| 7290 | Diag(ELoc, diag::err_omp_parallel_reduction_in_task_firstprivate) |
| 7291 | << getOpenMPDirectiveName(DVar.DKind); |
| 7292 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 7293 | continue; |
| 7294 | } |
| 7295 | } |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7296 | |
| 7297 | // OpenMP 4.5 [2.15.3.4, Restrictions, p.3] |
| 7298 | // A list item that is private within a teams region must not appear in a |
| 7299 | // firstprivate clause on a distribute construct if any of the distribute |
| 7300 | // regions arising from the distribute construct ever bind to any of the |
| 7301 | // teams regions arising from the teams construct. |
| 7302 | // OpenMP 4.5 [2.15.3.4, Restrictions, p.3] |
| 7303 | // A list item that appears in a reduction clause of a teams construct |
| 7304 | // must not appear in a firstprivate clause on a distribute construct if |
| 7305 | // any of the distribute regions arising from the distribute construct |
| 7306 | // ever bind to any of the teams regions arising from the teams construct. |
| 7307 | // OpenMP 4.5 [2.10.8, Distribute Construct, p.3] |
| 7308 | // A list item may appear in a firstprivate or lastprivate clause but not |
| 7309 | // both. |
| 7310 | if (CurrDir == OMPD_distribute) { |
| 7311 | DVar = DSAStack->hasInnermostDSA(VD, MatchesAnyClause(OMPC_private), |
| 7312 | [](OpenMPDirectiveKind K) -> bool { |
| 7313 | return isOpenMPTeamsDirective(K); |
| 7314 | }, |
| 7315 | false); |
| 7316 | if (DVar.CKind == OMPC_private && isOpenMPTeamsDirective(DVar.DKind)) { |
| 7317 | Diag(ELoc, diag::err_omp_firstprivate_distribute_private_teams); |
| 7318 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 7319 | continue; |
| 7320 | } |
| 7321 | DVar = DSAStack->hasInnermostDSA(VD, MatchesAnyClause(OMPC_reduction), |
| 7322 | [](OpenMPDirectiveKind K) -> bool { |
| 7323 | return isOpenMPTeamsDirective(K); |
| 7324 | }, |
| 7325 | false); |
| 7326 | if (DVar.CKind == OMPC_reduction && |
| 7327 | isOpenMPTeamsDirective(DVar.DKind)) { |
| 7328 | Diag(ELoc, diag::err_omp_firstprivate_distribute_in_teams_reduction); |
| 7329 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 7330 | continue; |
| 7331 | } |
| 7332 | DVar = DSAStack->getTopDSA(VD, false); |
| 7333 | if (DVar.CKind == OMPC_lastprivate) { |
| 7334 | Diag(ELoc, diag::err_omp_firstprivate_and_lastprivate_in_distribute); |
| 7335 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 7336 | continue; |
| 7337 | } |
| 7338 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7339 | } |
| 7340 | |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7341 | // Variably modified types are not supported for tasks. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 7342 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType() && |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7343 | DSAStack->getCurrentDirective() == OMPD_task) { |
| 7344 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
| 7345 | << getOpenMPClauseName(OMPC_firstprivate) << Type |
| 7346 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 7347 | bool IsDecl = |
| 7348 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 7349 | Diag(VD->getLocation(), |
| 7350 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7351 | << VD; |
| 7352 | continue; |
| 7353 | } |
| 7354 | |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7355 | Type = Type.getUnqualifiedType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 7356 | auto VDPrivate = buildVarDecl(*this, ELoc, Type, VD->getName(), |
| 7357 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7358 | // Generate helper private variable and initialize it with the value of the |
| 7359 | // original variable. The address of the original variable is replaced by |
| 7360 | // the address of the new private variable in the CodeGen. This new variable |
| 7361 | // is not added to IdResolver, so the code in the OpenMP region uses |
| 7362 | // original variable for proper diagnostics and variable capturing. |
| 7363 | Expr *VDInitRefExpr = nullptr; |
| 7364 | // For arrays generate initializer for single element and replace it by the |
| 7365 | // original array element in CodeGen. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7366 | if (Type->isArrayType()) { |
| 7367 | auto VDInit = |
| 7368 | buildVarDecl(*this, DE->getExprLoc(), ElemType, VD->getName()); |
| 7369 | VDInitRefExpr = buildDeclRefExpr(*this, VDInit, ElemType, ELoc); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7370 | auto Init = DefaultLvalueConversion(VDInitRefExpr).get(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7371 | ElemType = ElemType.getUnqualifiedType(); |
| 7372 | auto *VDInitTemp = buildVarDecl(*this, DE->getLocStart(), ElemType, |
| 7373 | ".firstprivate.temp"); |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 7374 | InitializedEntity Entity = |
| 7375 | InitializedEntity::InitializeVariable(VDInitTemp); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7376 | InitializationKind Kind = InitializationKind::CreateCopy(ELoc, ELoc); |
| 7377 | |
| 7378 | InitializationSequence InitSeq(*this, Entity, Kind, Init); |
| 7379 | ExprResult Result = InitSeq.Perform(*this, Entity, Kind, Init); |
| 7380 | if (Result.isInvalid()) |
| 7381 | VDPrivate->setInvalidDecl(); |
| 7382 | else |
| 7383 | VDPrivate->setInit(Result.getAs<Expr>()); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7384 | // Remove temp variable declaration. |
| 7385 | Context.Deallocate(VDInitTemp); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7386 | } else { |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 7387 | auto *VDInit = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7388 | buildVarDecl(*this, DE->getLocStart(), Type, ".firstprivate.temp"); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7389 | VDInitRefExpr = |
| 7390 | buildDeclRefExpr(*this, VDInit, DE->getType(), DE->getExprLoc()); |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 7391 | AddInitializerToDecl(VDPrivate, |
| 7392 | DefaultLvalueConversion(VDInitRefExpr).get(), |
| 7393 | /*DirectInit=*/false, /*TypeMayContainAuto=*/false); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7394 | } |
| 7395 | if (VDPrivate->isInvalidDecl()) { |
| 7396 | if (IsImplicitClause) { |
| 7397 | Diag(DE->getExprLoc(), |
| 7398 | diag::note_omp_task_predetermined_firstprivate_here); |
| 7399 | } |
| 7400 | continue; |
| 7401 | } |
| 7402 | CurContext->addDecl(VDPrivate); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7403 | auto VDPrivateRefExpr = buildDeclRefExpr( |
| 7404 | *this, VDPrivate, DE->getType().getUnqualifiedType(), DE->getExprLoc()); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7405 | DSAStack->addDSA(VD, DE, OMPC_firstprivate); |
| 7406 | Vars.push_back(DE); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7407 | PrivateCopies.push_back(VDPrivateRefExpr); |
| 7408 | Inits.push_back(VDInitRefExpr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7409 | } |
| 7410 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7411 | if (Vars.empty()) |
| 7412 | return nullptr; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7413 | |
| 7414 | return OMPFirstprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7415 | Vars, PrivateCopies, Inits); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7416 | } |
| 7417 | |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7418 | OMPClause *Sema::ActOnOpenMPLastprivateClause(ArrayRef<Expr *> VarList, |
| 7419 | SourceLocation StartLoc, |
| 7420 | SourceLocation LParenLoc, |
| 7421 | SourceLocation EndLoc) { |
| 7422 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7423 | SmallVector<Expr *, 8> SrcExprs; |
| 7424 | SmallVector<Expr *, 8> DstExprs; |
| 7425 | SmallVector<Expr *, 8> AssignmentOps; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7426 | for (auto &RefExpr : VarList) { |
| 7427 | assert(RefExpr && "NULL expr in OpenMP lastprivate clause."); |
| 7428 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 7429 | // It will be analyzed later. |
| 7430 | Vars.push_back(RefExpr); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7431 | SrcExprs.push_back(nullptr); |
| 7432 | DstExprs.push_back(nullptr); |
| 7433 | AssignmentOps.push_back(nullptr); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7434 | continue; |
| 7435 | } |
| 7436 | |
| 7437 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 7438 | // OpenMP [2.1, C/C++] |
| 7439 | // A list item is a variable name. |
| 7440 | // OpenMP [2.14.3.5, Restrictions, p.1] |
| 7441 | // A variable that is part of another variable (as an array or structure |
| 7442 | // element) cannot appear in a lastprivate clause. |
| 7443 | DeclRefExpr *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr); |
| 7444 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7445 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr) |
| 7446 | << 0 << RefExpr->getSourceRange(); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7447 | continue; |
| 7448 | } |
| 7449 | Decl *D = DE->getDecl(); |
| 7450 | VarDecl *VD = cast<VarDecl>(D); |
| 7451 | |
| 7452 | QualType Type = VD->getType(); |
| 7453 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 7454 | // It will be analyzed later. |
| 7455 | Vars.push_back(DE); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7456 | SrcExprs.push_back(nullptr); |
| 7457 | DstExprs.push_back(nullptr); |
| 7458 | AssignmentOps.push_back(nullptr); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7459 | continue; |
| 7460 | } |
| 7461 | |
| 7462 | // OpenMP [2.14.3.5, Restrictions, C/C++, p.2] |
| 7463 | // A variable that appears in a lastprivate clause must not have an |
| 7464 | // incomplete type or a reference type. |
| 7465 | if (RequireCompleteType(ELoc, Type, |
| 7466 | diag::err_omp_lastprivate_incomplete_type)) { |
| 7467 | continue; |
| 7468 | } |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7469 | Type = Type.getNonReferenceType(); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7470 | |
| 7471 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 7472 | // in a Construct] |
| 7473 | // Variables with the predetermined data-sharing attributes may not be |
| 7474 | // listed in data-sharing attributes clauses, except for the cases |
| 7475 | // listed below. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7476 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7477 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_lastprivate && |
| 7478 | DVar.CKind != OMPC_firstprivate && |
| 7479 | (DVar.CKind != OMPC_private || DVar.RefExpr != nullptr)) { |
| 7480 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 7481 | << getOpenMPClauseName(DVar.CKind) |
| 7482 | << getOpenMPClauseName(OMPC_lastprivate); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 7483 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7484 | continue; |
| 7485 | } |
| 7486 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7487 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
| 7488 | // OpenMP [2.14.3.5, Restrictions, p.2] |
| 7489 | // A list item that is private within a parallel region, or that appears in |
| 7490 | // the reduction clause of a parallel construct, must not appear in a |
| 7491 | // lastprivate clause on a worksharing construct if any of the corresponding |
| 7492 | // worksharing regions ever binds to any of the corresponding parallel |
| 7493 | // regions. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7494 | DSAStackTy::DSAVarData TopDVar = DVar; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 7495 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 7496 | !isOpenMPParallelDirective(CurrDir)) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7497 | DVar = DSAStack->getImplicitDSA(VD, true); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7498 | if (DVar.CKind != OMPC_shared) { |
| 7499 | Diag(ELoc, diag::err_omp_required_access) |
| 7500 | << getOpenMPClauseName(OMPC_lastprivate) |
| 7501 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 7502 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7503 | continue; |
| 7504 | } |
| 7505 | } |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7506 | // OpenMP [2.14.3.5, Restrictions, C++, p.1,2] |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7507 | // A variable of class type (or array thereof) that appears in a |
| 7508 | // lastprivate clause requires an accessible, unambiguous default |
| 7509 | // constructor for the class type, unless the list item is also specified |
| 7510 | // in a firstprivate clause. |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7511 | // A variable of class type (or array thereof) that appears in a |
| 7512 | // lastprivate clause requires an accessible, unambiguous copy assignment |
| 7513 | // operator for the class type. |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7514 | Type = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7515 | auto *SrcVD = buildVarDecl(*this, DE->getLocStart(), |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 7516 | Type.getUnqualifiedType(), ".lastprivate.src", |
| 7517 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7518 | auto *PseudoSrcExpr = buildDeclRefExpr( |
| 7519 | *this, SrcVD, Type.getUnqualifiedType(), DE->getExprLoc()); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7520 | auto *DstVD = |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 7521 | buildVarDecl(*this, DE->getLocStart(), Type, ".lastprivate.dst", |
| 7522 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7523 | auto *PseudoDstExpr = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7524 | buildDeclRefExpr(*this, DstVD, Type, DE->getExprLoc()); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7525 | // For arrays generate assignment operation for single element and replace |
| 7526 | // it by the original array element in CodeGen. |
| 7527 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, DE->getExprLoc(), BO_Assign, |
| 7528 | PseudoDstExpr, PseudoSrcExpr); |
| 7529 | if (AssignmentOp.isInvalid()) |
| 7530 | continue; |
| 7531 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), DE->getExprLoc(), |
| 7532 | /*DiscardedValue=*/true); |
| 7533 | if (AssignmentOp.isInvalid()) |
| 7534 | continue; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7535 | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7536 | // OpenMP 4.5 [2.10.8, Distribute Construct, p.3] |
| 7537 | // A list item may appear in a firstprivate or lastprivate clause but not |
| 7538 | // both. |
| 7539 | if (CurrDir == OMPD_distribute) { |
| 7540 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
| 7541 | if (DVar.CKind == OMPC_firstprivate) { |
| 7542 | Diag(ELoc, diag::err_omp_firstprivate_and_lastprivate_in_distribute); |
| 7543 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 7544 | continue; |
| 7545 | } |
| 7546 | } |
| 7547 | |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7548 | if (TopDVar.CKind != OMPC_firstprivate) |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7549 | DSAStack->addDSA(VD, DE, OMPC_lastprivate); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7550 | Vars.push_back(DE); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7551 | SrcExprs.push_back(PseudoSrcExpr); |
| 7552 | DstExprs.push_back(PseudoDstExpr); |
| 7553 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7554 | } |
| 7555 | |
| 7556 | if (Vars.empty()) |
| 7557 | return nullptr; |
| 7558 | |
| 7559 | return OMPLastprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7560 | Vars, SrcExprs, DstExprs, AssignmentOps); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7561 | } |
| 7562 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7563 | OMPClause *Sema::ActOnOpenMPSharedClause(ArrayRef<Expr *> VarList, |
| 7564 | SourceLocation StartLoc, |
| 7565 | SourceLocation LParenLoc, |
| 7566 | SourceLocation EndLoc) { |
| 7567 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7568 | for (auto &RefExpr : VarList) { |
| 7569 | assert(RefExpr && "NULL expr in OpenMP shared clause."); |
| 7570 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7571 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7572 | Vars.push_back(RefExpr); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7573 | continue; |
| 7574 | } |
| 7575 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7576 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7577 | // OpenMP [2.1, C/C++] |
| 7578 | // A list item is a variable name. |
Alexey Bataev | d4dbdf5 | 2014-03-06 12:27:56 +0000 | [diff] [blame] | 7579 | // OpenMP [2.14.3.2, Restrictions, p.1] |
| 7580 | // A variable that is part of another variable (as an array or structure |
| 7581 | // element) cannot appear in a shared unless it is a static data member |
| 7582 | // of a C++ class. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7583 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7584 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7585 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr) |
| 7586 | << 0 << RefExpr->getSourceRange(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7587 | continue; |
| 7588 | } |
| 7589 | Decl *D = DE->getDecl(); |
| 7590 | VarDecl *VD = cast<VarDecl>(D); |
| 7591 | |
| 7592 | QualType Type = VD->getType(); |
| 7593 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 7594 | // It will be analyzed later. |
| 7595 | Vars.push_back(DE); |
| 7596 | continue; |
| 7597 | } |
| 7598 | |
| 7599 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 7600 | // in a Construct] |
| 7601 | // Variables with the predetermined data-sharing attributes may not be |
| 7602 | // listed in data-sharing attributes clauses, except for the cases |
| 7603 | // listed below. For these exceptions only, listing a predetermined |
| 7604 | // variable in a data-sharing attribute clause is allowed and overrides |
| 7605 | // the variable's predetermined data-sharing attributes. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7606 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7607 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared && |
| 7608 | DVar.RefExpr) { |
| 7609 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 7610 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 7611 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7612 | continue; |
| 7613 | } |
| 7614 | |
| 7615 | DSAStack->addDSA(VD, DE, OMPC_shared); |
| 7616 | Vars.push_back(DE); |
| 7617 | } |
| 7618 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7619 | if (Vars.empty()) |
| 7620 | return nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7621 | |
| 7622 | return OMPSharedClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars); |
| 7623 | } |
| 7624 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7625 | namespace { |
| 7626 | class DSARefChecker : public StmtVisitor<DSARefChecker, bool> { |
| 7627 | DSAStackTy *Stack; |
| 7628 | |
| 7629 | public: |
| 7630 | bool VisitDeclRefExpr(DeclRefExpr *E) { |
| 7631 | if (VarDecl *VD = dyn_cast<VarDecl>(E->getDecl())) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7632 | DSAStackTy::DSAVarData DVar = Stack->getTopDSA(VD, false); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7633 | if (DVar.CKind == OMPC_shared && !DVar.RefExpr) |
| 7634 | return false; |
| 7635 | if (DVar.CKind != OMPC_unknown) |
| 7636 | return true; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7637 | DSAStackTy::DSAVarData DVarPrivate = |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7638 | Stack->hasDSA(VD, isOpenMPPrivate, MatchesAlways(), false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7639 | if (DVarPrivate.CKind != OMPC_unknown) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7640 | return true; |
| 7641 | return false; |
| 7642 | } |
| 7643 | return false; |
| 7644 | } |
| 7645 | bool VisitStmt(Stmt *S) { |
| 7646 | for (auto Child : S->children()) { |
| 7647 | if (Child && Visit(Child)) |
| 7648 | return true; |
| 7649 | } |
| 7650 | return false; |
| 7651 | } |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 7652 | explicit DSARefChecker(DSAStackTy *S) : Stack(S) {} |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7653 | }; |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 7654 | } // namespace |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7655 | |
| 7656 | OMPClause *Sema::ActOnOpenMPReductionClause( |
| 7657 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, SourceLocation LParenLoc, |
| 7658 | SourceLocation ColonLoc, SourceLocation EndLoc, |
| 7659 | CXXScopeSpec &ReductionIdScopeSpec, |
| 7660 | const DeclarationNameInfo &ReductionId) { |
| 7661 | // TODO: Allow scope specification search when 'declare reduction' is |
| 7662 | // supported. |
| 7663 | assert(ReductionIdScopeSpec.isEmpty() && |
| 7664 | "No support for scoped reduction identifiers yet."); |
| 7665 | |
| 7666 | auto DN = ReductionId.getName(); |
| 7667 | auto OOK = DN.getCXXOverloadedOperator(); |
| 7668 | BinaryOperatorKind BOK = BO_Comma; |
| 7669 | |
| 7670 | // OpenMP [2.14.3.6, reduction clause] |
| 7671 | // C |
| 7672 | // reduction-identifier is either an identifier or one of the following |
| 7673 | // operators: +, -, *, &, |, ^, && and || |
| 7674 | // C++ |
| 7675 | // reduction-identifier is either an id-expression or one of the following |
| 7676 | // operators: +, -, *, &, |, ^, && and || |
| 7677 | // FIXME: Only 'min' and 'max' identifiers are supported for now. |
| 7678 | switch (OOK) { |
| 7679 | case OO_Plus: |
| 7680 | case OO_Minus: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7681 | BOK = BO_Add; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7682 | break; |
| 7683 | case OO_Star: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7684 | BOK = BO_Mul; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7685 | break; |
| 7686 | case OO_Amp: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7687 | BOK = BO_And; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7688 | break; |
| 7689 | case OO_Pipe: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7690 | BOK = BO_Or; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7691 | break; |
| 7692 | case OO_Caret: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7693 | BOK = BO_Xor; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7694 | break; |
| 7695 | case OO_AmpAmp: |
| 7696 | BOK = BO_LAnd; |
| 7697 | break; |
| 7698 | case OO_PipePipe: |
| 7699 | BOK = BO_LOr; |
| 7700 | break; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7701 | case OO_New: |
| 7702 | case OO_Delete: |
| 7703 | case OO_Array_New: |
| 7704 | case OO_Array_Delete: |
| 7705 | case OO_Slash: |
| 7706 | case OO_Percent: |
| 7707 | case OO_Tilde: |
| 7708 | case OO_Exclaim: |
| 7709 | case OO_Equal: |
| 7710 | case OO_Less: |
| 7711 | case OO_Greater: |
| 7712 | case OO_LessEqual: |
| 7713 | case OO_GreaterEqual: |
| 7714 | case OO_PlusEqual: |
| 7715 | case OO_MinusEqual: |
| 7716 | case OO_StarEqual: |
| 7717 | case OO_SlashEqual: |
| 7718 | case OO_PercentEqual: |
| 7719 | case OO_CaretEqual: |
| 7720 | case OO_AmpEqual: |
| 7721 | case OO_PipeEqual: |
| 7722 | case OO_LessLess: |
| 7723 | case OO_GreaterGreater: |
| 7724 | case OO_LessLessEqual: |
| 7725 | case OO_GreaterGreaterEqual: |
| 7726 | case OO_EqualEqual: |
| 7727 | case OO_ExclaimEqual: |
| 7728 | case OO_PlusPlus: |
| 7729 | case OO_MinusMinus: |
| 7730 | case OO_Comma: |
| 7731 | case OO_ArrowStar: |
| 7732 | case OO_Arrow: |
| 7733 | case OO_Call: |
| 7734 | case OO_Subscript: |
| 7735 | case OO_Conditional: |
Richard Smith | 9be594e | 2015-10-22 05:12:22 +0000 | [diff] [blame] | 7736 | case OO_Coawait: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7737 | case NUM_OVERLOADED_OPERATORS: |
| 7738 | llvm_unreachable("Unexpected reduction identifier"); |
| 7739 | case OO_None: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7740 | if (auto II = DN.getAsIdentifierInfo()) { |
| 7741 | if (II->isStr("max")) |
| 7742 | BOK = BO_GT; |
| 7743 | else if (II->isStr("min")) |
| 7744 | BOK = BO_LT; |
| 7745 | } |
| 7746 | break; |
| 7747 | } |
| 7748 | SourceRange ReductionIdRange; |
| 7749 | if (ReductionIdScopeSpec.isValid()) { |
| 7750 | ReductionIdRange.setBegin(ReductionIdScopeSpec.getBeginLoc()); |
| 7751 | } |
| 7752 | ReductionIdRange.setEnd(ReductionId.getEndLoc()); |
| 7753 | if (BOK == BO_Comma) { |
| 7754 | // Not allowed reduction identifier is found. |
| 7755 | Diag(ReductionId.getLocStart(), diag::err_omp_unknown_reduction_identifier) |
| 7756 | << ReductionIdRange; |
| 7757 | return nullptr; |
| 7758 | } |
| 7759 | |
| 7760 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7761 | SmallVector<Expr *, 8> Privates; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7762 | SmallVector<Expr *, 8> LHSs; |
| 7763 | SmallVector<Expr *, 8> RHSs; |
| 7764 | SmallVector<Expr *, 8> ReductionOps; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7765 | for (auto RefExpr : VarList) { |
| 7766 | assert(RefExpr && "nullptr expr in OpenMP reduction clause."); |
| 7767 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 7768 | // It will be analyzed later. |
| 7769 | Vars.push_back(RefExpr); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7770 | Privates.push_back(nullptr); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7771 | LHSs.push_back(nullptr); |
| 7772 | RHSs.push_back(nullptr); |
| 7773 | ReductionOps.push_back(nullptr); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7774 | continue; |
| 7775 | } |
| 7776 | |
| 7777 | if (RefExpr->isTypeDependent() || RefExpr->isValueDependent() || |
| 7778 | RefExpr->isInstantiationDependent() || |
| 7779 | RefExpr->containsUnexpandedParameterPack()) { |
| 7780 | // It will be analyzed later. |
| 7781 | Vars.push_back(RefExpr); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7782 | Privates.push_back(nullptr); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7783 | LHSs.push_back(nullptr); |
| 7784 | RHSs.push_back(nullptr); |
| 7785 | ReductionOps.push_back(nullptr); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7786 | continue; |
| 7787 | } |
| 7788 | |
| 7789 | auto ELoc = RefExpr->getExprLoc(); |
| 7790 | auto ERange = RefExpr->getSourceRange(); |
| 7791 | // OpenMP [2.1, C/C++] |
| 7792 | // A list item is a variable or array section, subject to the restrictions |
| 7793 | // specified in Section 2.4 on page 42 and in each of the sections |
| 7794 | // describing clauses and directives for which a list appears. |
| 7795 | // OpenMP [2.14.3.3, Restrictions, p.1] |
| 7796 | // A variable that is part of another variable (as an array or |
| 7797 | // structure element) cannot appear in a private clause. |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7798 | auto *DE = dyn_cast<DeclRefExpr>(RefExpr); |
| 7799 | auto *ASE = dyn_cast<ArraySubscriptExpr>(RefExpr); |
| 7800 | auto *OASE = dyn_cast<OMPArraySectionExpr>(RefExpr); |
| 7801 | if (!ASE && !OASE && (!DE || !isa<VarDecl>(DE->getDecl()))) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7802 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr_or_array_item) |
| 7803 | << 0 << ERange; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7804 | continue; |
| 7805 | } |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7806 | QualType Type; |
| 7807 | VarDecl *VD = nullptr; |
| 7808 | if (DE) { |
| 7809 | auto D = DE->getDecl(); |
| 7810 | VD = cast<VarDecl>(D); |
Alexey Bataev | 31300ed | 2016-02-04 11:27:03 +0000 | [diff] [blame] | 7811 | Type = Context.getBaseElementType(VD->getType().getNonReferenceType()); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7812 | } else if (ASE) { |
Alexey Bataev | 31300ed | 2016-02-04 11:27:03 +0000 | [diff] [blame] | 7813 | Type = ASE->getType().getNonReferenceType(); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7814 | auto *Base = ASE->getBase()->IgnoreParenImpCasts(); |
| 7815 | while (auto *TempASE = dyn_cast<ArraySubscriptExpr>(Base)) |
| 7816 | Base = TempASE->getBase()->IgnoreParenImpCasts(); |
| 7817 | DE = dyn_cast<DeclRefExpr>(Base); |
| 7818 | if (DE) |
| 7819 | VD = dyn_cast<VarDecl>(DE->getDecl()); |
| 7820 | if (!VD) { |
| 7821 | Diag(Base->getExprLoc(), diag::err_omp_expected_base_var_name) |
| 7822 | << 0 << Base->getSourceRange(); |
| 7823 | continue; |
| 7824 | } |
| 7825 | } else if (OASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7826 | auto BaseType = OMPArraySectionExpr::getBaseOriginalType(OASE->getBase()); |
| 7827 | if (auto *ATy = BaseType->getAsArrayTypeUnsafe()) |
| 7828 | Type = ATy->getElementType(); |
| 7829 | else |
| 7830 | Type = BaseType->getPointeeType(); |
Alexey Bataev | 31300ed | 2016-02-04 11:27:03 +0000 | [diff] [blame] | 7831 | Type = Type.getNonReferenceType(); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7832 | auto *Base = OASE->getBase()->IgnoreParenImpCasts(); |
| 7833 | while (auto *TempOASE = dyn_cast<OMPArraySectionExpr>(Base)) |
| 7834 | Base = TempOASE->getBase()->IgnoreParenImpCasts(); |
| 7835 | while (auto *TempASE = dyn_cast<ArraySubscriptExpr>(Base)) |
| 7836 | Base = TempASE->getBase()->IgnoreParenImpCasts(); |
| 7837 | DE = dyn_cast<DeclRefExpr>(Base); |
| 7838 | if (DE) |
| 7839 | VD = dyn_cast<VarDecl>(DE->getDecl()); |
| 7840 | if (!VD) { |
| 7841 | Diag(Base->getExprLoc(), diag::err_omp_expected_base_var_name) |
| 7842 | << 1 << Base->getSourceRange(); |
| 7843 | continue; |
| 7844 | } |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7845 | } |
| 7846 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7847 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 7848 | // A variable that appears in a private clause must not have an incomplete |
| 7849 | // type or a reference type. |
| 7850 | if (RequireCompleteType(ELoc, Type, |
| 7851 | diag::err_omp_reduction_incomplete_type)) |
| 7852 | continue; |
| 7853 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7854 | // A list item that appears in a reduction clause must not be |
| 7855 | // const-qualified. |
| 7856 | if (Type.getNonReferenceType().isConstant(Context)) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7857 | Diag(ELoc, diag::err_omp_const_reduction_list_item) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7858 | << getOpenMPClauseName(OMPC_reduction) << Type << ERange; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7859 | if (!ASE && !OASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7860 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 7861 | VarDecl::DeclarationOnly; |
| 7862 | Diag(VD->getLocation(), |
| 7863 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7864 | << VD; |
| 7865 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7866 | continue; |
| 7867 | } |
| 7868 | // OpenMP [2.9.3.6, Restrictions, C/C++, p.4] |
| 7869 | // If a list-item is a reference type then it must bind to the same object |
| 7870 | // for all threads of the team. |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7871 | if (!ASE && !OASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7872 | VarDecl *VDDef = VD->getDefinition(); |
Alexey Bataev | 31300ed | 2016-02-04 11:27:03 +0000 | [diff] [blame] | 7873 | if (VD->getType()->isReferenceType() && VDDef) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7874 | DSARefChecker Check(DSAStack); |
| 7875 | if (Check.Visit(VDDef->getInit())) { |
| 7876 | Diag(ELoc, diag::err_omp_reduction_ref_type_arg) << ERange; |
| 7877 | Diag(VDDef->getLocation(), diag::note_defined_here) << VDDef; |
| 7878 | continue; |
| 7879 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7880 | } |
| 7881 | } |
| 7882 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
| 7883 | // The type of a list item that appears in a reduction clause must be valid |
| 7884 | // for the reduction-identifier. For a max or min reduction in C, the type |
| 7885 | // of the list item must be an allowed arithmetic data type: char, int, |
| 7886 | // float, double, or _Bool, possibly modified with long, short, signed, or |
| 7887 | // unsigned. For a max or min reduction in C++, the type of the list item |
| 7888 | // must be an allowed arithmetic data type: char, wchar_t, int, float, |
| 7889 | // double, or bool, possibly modified with long, short, signed, or unsigned. |
| 7890 | if ((BOK == BO_GT || BOK == BO_LT) && |
| 7891 | !(Type->isScalarType() || |
| 7892 | (getLangOpts().CPlusPlus && Type->isArithmeticType()))) { |
| 7893 | Diag(ELoc, diag::err_omp_clause_not_arithmetic_type_arg) |
| 7894 | << getLangOpts().CPlusPlus; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7895 | if (!ASE && !OASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7896 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 7897 | VarDecl::DeclarationOnly; |
| 7898 | Diag(VD->getLocation(), |
| 7899 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7900 | << VD; |
| 7901 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7902 | continue; |
| 7903 | } |
| 7904 | if ((BOK == BO_OrAssign || BOK == BO_AndAssign || BOK == BO_XorAssign) && |
| 7905 | !getLangOpts().CPlusPlus && Type->isFloatingType()) { |
| 7906 | Diag(ELoc, diag::err_omp_clause_floating_type_arg); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7907 | if (!ASE && !OASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7908 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 7909 | VarDecl::DeclarationOnly; |
| 7910 | Diag(VD->getLocation(), |
| 7911 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7912 | << VD; |
| 7913 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7914 | continue; |
| 7915 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7916 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 7917 | // in a Construct] |
| 7918 | // Variables with the predetermined data-sharing attributes may not be |
| 7919 | // listed in data-sharing attributes clauses, except for the cases |
| 7920 | // listed below. For these exceptions only, listing a predetermined |
| 7921 | // variable in a data-sharing attribute clause is allowed and overrides |
| 7922 | // the variable's predetermined data-sharing attributes. |
| 7923 | // OpenMP [2.14.3.6, Restrictions, p.3] |
| 7924 | // Any number of reduction clauses can be specified on the directive, |
| 7925 | // but a list item can appear only once in the reduction clauses for that |
| 7926 | // directive. |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7927 | DSAStackTy::DSAVarData DVar; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7928 | DVar = DSAStack->getTopDSA(VD, false); |
| 7929 | if (DVar.CKind == OMPC_reduction) { |
| 7930 | Diag(ELoc, diag::err_omp_once_referenced) |
| 7931 | << getOpenMPClauseName(OMPC_reduction); |
| 7932 | if (DVar.RefExpr) { |
| 7933 | Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_referenced); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7934 | } |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7935 | } else if (DVar.CKind != OMPC_unknown) { |
| 7936 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 7937 | << getOpenMPClauseName(DVar.CKind) |
| 7938 | << getOpenMPClauseName(OMPC_reduction); |
| 7939 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 7940 | continue; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7941 | } |
| 7942 | |
| 7943 | // OpenMP [2.14.3.6, Restrictions, p.1] |
| 7944 | // A list item that appears in a reduction clause of a worksharing |
| 7945 | // construct must be shared in the parallel regions to which any of the |
| 7946 | // worksharing regions arising from the worksharing construct bind. |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7947 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
| 7948 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 7949 | !isOpenMPParallelDirective(CurrDir)) { |
| 7950 | DVar = DSAStack->getImplicitDSA(VD, true); |
| 7951 | if (DVar.CKind != OMPC_shared) { |
| 7952 | Diag(ELoc, diag::err_omp_required_access) |
| 7953 | << getOpenMPClauseName(OMPC_reduction) |
| 7954 | << getOpenMPClauseName(OMPC_shared); |
| 7955 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 7956 | continue; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7957 | } |
| 7958 | } |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7959 | |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7960 | Type = Type.getNonLValueExprType(Context).getUnqualifiedType(); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7961 | auto *LHSVD = buildVarDecl(*this, ELoc, Type, ".reduction.lhs", |
| 7962 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
| 7963 | auto *RHSVD = buildVarDecl(*this, ELoc, Type, VD->getName(), |
| 7964 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
| 7965 | auto PrivateTy = Type; |
Alexey Bataev | 1189bd0 | 2016-01-26 12:20:39 +0000 | [diff] [blame] | 7966 | if (OASE || |
| 7967 | (DE && VD->getType().getNonReferenceType()->isVariablyModifiedType())) { |
| 7968 | // For arays/array sections only: |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7969 | // Create pseudo array type for private copy. The size for this array will |
| 7970 | // be generated during codegen. |
| 7971 | // For array subscripts or single variables Private Ty is the same as Type |
| 7972 | // (type of the variable or single array element). |
| 7973 | PrivateTy = Context.getVariableArrayType( |
| 7974 | Type, new (Context) OpaqueValueExpr(SourceLocation(), |
| 7975 | Context.getSizeType(), VK_RValue), |
| 7976 | ArrayType::Normal, /*IndexTypeQuals=*/0, SourceRange()); |
Alexey Bataev | 1189bd0 | 2016-01-26 12:20:39 +0000 | [diff] [blame] | 7977 | } else if (DE && |
| 7978 | Context.getAsArrayType(VD->getType().getNonReferenceType())) |
| 7979 | PrivateTy = VD->getType().getNonReferenceType(); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7980 | // Private copy. |
| 7981 | auto *PrivateVD = buildVarDecl(*this, ELoc, PrivateTy, VD->getName(), |
| 7982 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7983 | // Add initializer for private variable. |
| 7984 | Expr *Init = nullptr; |
| 7985 | switch (BOK) { |
| 7986 | case BO_Add: |
| 7987 | case BO_Xor: |
| 7988 | case BO_Or: |
| 7989 | case BO_LOr: |
| 7990 | // '+', '-', '^', '|', '||' reduction ops - initializer is '0'. |
| 7991 | if (Type->isScalarType() || Type->isAnyComplexType()) { |
| 7992 | Init = ActOnIntegerConstant(ELoc, /*Val=*/0).get(); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7993 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7994 | break; |
| 7995 | case BO_Mul: |
| 7996 | case BO_LAnd: |
| 7997 | if (Type->isScalarType() || Type->isAnyComplexType()) { |
| 7998 | // '*' and '&&' reduction ops - initializer is '1'. |
| 7999 | Init = ActOnIntegerConstant(ELoc, /*Val=*/1).get(); |
| 8000 | } |
| 8001 | break; |
| 8002 | case BO_And: { |
| 8003 | // '&' reduction op - initializer is '~0'. |
| 8004 | QualType OrigType = Type; |
| 8005 | if (auto *ComplexTy = OrigType->getAs<ComplexType>()) { |
| 8006 | Type = ComplexTy->getElementType(); |
| 8007 | } |
| 8008 | if (Type->isRealFloatingType()) { |
| 8009 | llvm::APFloat InitValue = |
| 8010 | llvm::APFloat::getAllOnesValue(Context.getTypeSize(Type), |
| 8011 | /*isIEEE=*/true); |
| 8012 | Init = FloatingLiteral::Create(Context, InitValue, /*isexact=*/true, |
| 8013 | Type, ELoc); |
| 8014 | } else if (Type->isScalarType()) { |
| 8015 | auto Size = Context.getTypeSize(Type); |
| 8016 | QualType IntTy = Context.getIntTypeForBitwidth(Size, /*Signed=*/0); |
| 8017 | llvm::APInt InitValue = llvm::APInt::getAllOnesValue(Size); |
| 8018 | Init = IntegerLiteral::Create(Context, InitValue, IntTy, ELoc); |
| 8019 | } |
| 8020 | if (Init && OrigType->isAnyComplexType()) { |
| 8021 | // Init = 0xFFFF + 0xFFFFi; |
| 8022 | auto *Im = new (Context) ImaginaryLiteral(Init, OrigType); |
| 8023 | Init = CreateBuiltinBinOp(ELoc, BO_Add, Init, Im).get(); |
| 8024 | } |
| 8025 | Type = OrigType; |
| 8026 | break; |
| 8027 | } |
| 8028 | case BO_LT: |
| 8029 | case BO_GT: { |
| 8030 | // 'min' reduction op - initializer is 'Largest representable number in |
| 8031 | // the reduction list item type'. |
| 8032 | // 'max' reduction op - initializer is 'Least representable number in |
| 8033 | // the reduction list item type'. |
| 8034 | if (Type->isIntegerType() || Type->isPointerType()) { |
| 8035 | bool IsSigned = Type->hasSignedIntegerRepresentation(); |
| 8036 | auto Size = Context.getTypeSize(Type); |
| 8037 | QualType IntTy = |
| 8038 | Context.getIntTypeForBitwidth(Size, /*Signed=*/IsSigned); |
| 8039 | llvm::APInt InitValue = |
| 8040 | (BOK != BO_LT) |
| 8041 | ? IsSigned ? llvm::APInt::getSignedMinValue(Size) |
| 8042 | : llvm::APInt::getMinValue(Size) |
| 8043 | : IsSigned ? llvm::APInt::getSignedMaxValue(Size) |
| 8044 | : llvm::APInt::getMaxValue(Size); |
| 8045 | Init = IntegerLiteral::Create(Context, InitValue, IntTy, ELoc); |
| 8046 | if (Type->isPointerType()) { |
| 8047 | // Cast to pointer type. |
| 8048 | auto CastExpr = BuildCStyleCastExpr( |
| 8049 | SourceLocation(), Context.getTrivialTypeSourceInfo(Type, ELoc), |
| 8050 | SourceLocation(), Init); |
| 8051 | if (CastExpr.isInvalid()) |
| 8052 | continue; |
| 8053 | Init = CastExpr.get(); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8054 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8055 | } else if (Type->isRealFloatingType()) { |
| 8056 | llvm::APFloat InitValue = llvm::APFloat::getLargest( |
| 8057 | Context.getFloatTypeSemantics(Type), BOK != BO_LT); |
| 8058 | Init = FloatingLiteral::Create(Context, InitValue, /*isexact=*/true, |
| 8059 | Type, ELoc); |
| 8060 | } |
| 8061 | break; |
| 8062 | } |
| 8063 | case BO_PtrMemD: |
| 8064 | case BO_PtrMemI: |
| 8065 | case BO_MulAssign: |
| 8066 | case BO_Div: |
| 8067 | case BO_Rem: |
| 8068 | case BO_Sub: |
| 8069 | case BO_Shl: |
| 8070 | case BO_Shr: |
| 8071 | case BO_LE: |
| 8072 | case BO_GE: |
| 8073 | case BO_EQ: |
| 8074 | case BO_NE: |
| 8075 | case BO_AndAssign: |
| 8076 | case BO_XorAssign: |
| 8077 | case BO_OrAssign: |
| 8078 | case BO_Assign: |
| 8079 | case BO_AddAssign: |
| 8080 | case BO_SubAssign: |
| 8081 | case BO_DivAssign: |
| 8082 | case BO_RemAssign: |
| 8083 | case BO_ShlAssign: |
| 8084 | case BO_ShrAssign: |
| 8085 | case BO_Comma: |
| 8086 | llvm_unreachable("Unexpected reduction operation"); |
| 8087 | } |
| 8088 | if (Init) { |
| 8089 | AddInitializerToDecl(RHSVD, Init, /*DirectInit=*/false, |
| 8090 | /*TypeMayContainAuto=*/false); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8091 | } else |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8092 | ActOnUninitializedDecl(RHSVD, /*TypeMayContainAuto=*/false); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8093 | if (!RHSVD->hasInit()) { |
| 8094 | Diag(ELoc, diag::err_omp_reduction_id_not_compatible) << Type |
| 8095 | << ReductionIdRange; |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8096 | if (VD) { |
| 8097 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 8098 | VarDecl::DeclarationOnly; |
| 8099 | Diag(VD->getLocation(), |
| 8100 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 8101 | << VD; |
| 8102 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8103 | continue; |
| 8104 | } |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8105 | // Store initializer for single element in private copy. Will be used during |
| 8106 | // codegen. |
| 8107 | PrivateVD->setInit(RHSVD->getInit()); |
| 8108 | PrivateVD->setInitStyle(RHSVD->getInitStyle()); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 8109 | auto *LHSDRE = buildDeclRefExpr(*this, LHSVD, Type, ELoc); |
| 8110 | auto *RHSDRE = buildDeclRefExpr(*this, RHSVD, Type, ELoc); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8111 | auto *PrivateDRE = buildDeclRefExpr(*this, PrivateVD, PrivateTy, ELoc); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8112 | ExprResult ReductionOp = |
| 8113 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), BOK, |
| 8114 | LHSDRE, RHSDRE); |
| 8115 | if (ReductionOp.isUsable()) { |
Alexey Bataev | 69a4779 | 2015-05-07 03:54:03 +0000 | [diff] [blame] | 8116 | if (BOK != BO_LT && BOK != BO_GT) { |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8117 | ReductionOp = |
| 8118 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), |
| 8119 | BO_Assign, LHSDRE, ReductionOp.get()); |
| 8120 | } else { |
| 8121 | auto *ConditionalOp = new (Context) ConditionalOperator( |
| 8122 | ReductionOp.get(), SourceLocation(), LHSDRE, SourceLocation(), |
| 8123 | RHSDRE, Type, VK_LValue, OK_Ordinary); |
| 8124 | ReductionOp = |
| 8125 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), |
| 8126 | BO_Assign, LHSDRE, ConditionalOp); |
| 8127 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 8128 | ReductionOp = ActOnFinishFullExpr(ReductionOp.get()); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8129 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8130 | if (ReductionOp.isInvalid()) |
| 8131 | continue; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8132 | |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8133 | DSAStack->addDSA(VD, DE, OMPC_reduction); |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8134 | Vars.push_back(RefExpr); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8135 | Privates.push_back(PrivateDRE); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8136 | LHSs.push_back(LHSDRE); |
| 8137 | RHSs.push_back(RHSDRE); |
| 8138 | ReductionOps.push_back(ReductionOp.get()); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8139 | } |
| 8140 | |
| 8141 | if (Vars.empty()) |
| 8142 | return nullptr; |
| 8143 | |
| 8144 | return OMPReductionClause::Create( |
| 8145 | Context, StartLoc, LParenLoc, ColonLoc, EndLoc, Vars, |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8146 | ReductionIdScopeSpec.getWithLocInContext(Context), ReductionId, Privates, |
| 8147 | LHSs, RHSs, ReductionOps); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8148 | } |
| 8149 | |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 8150 | OMPClause *Sema::ActOnOpenMPLinearClause( |
| 8151 | ArrayRef<Expr *> VarList, Expr *Step, SourceLocation StartLoc, |
| 8152 | SourceLocation LParenLoc, OpenMPLinearClauseKind LinKind, |
| 8153 | SourceLocation LinLoc, SourceLocation ColonLoc, SourceLocation EndLoc) { |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8154 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8155 | SmallVector<Expr *, 8> Privates; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8156 | SmallVector<Expr *, 8> Inits; |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 8157 | if ((!LangOpts.CPlusPlus && LinKind != OMPC_LINEAR_val) || |
| 8158 | LinKind == OMPC_LINEAR_unknown) { |
| 8159 | Diag(LinLoc, diag::err_omp_wrong_linear_modifier) << LangOpts.CPlusPlus; |
| 8160 | LinKind = OMPC_LINEAR_val; |
| 8161 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8162 | for (auto &RefExpr : VarList) { |
| 8163 | assert(RefExpr && "NULL expr in OpenMP linear clause."); |
| 8164 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8165 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8166 | Vars.push_back(RefExpr); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8167 | Privates.push_back(nullptr); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8168 | Inits.push_back(nullptr); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8169 | continue; |
| 8170 | } |
| 8171 | |
| 8172 | // OpenMP [2.14.3.7, linear clause] |
| 8173 | // A list item that appears in a linear clause is subject to the private |
| 8174 | // clause semantics described in Section 2.14.3.3 on page 159 except as |
| 8175 | // noted. In addition, the value of the new list item on each iteration |
| 8176 | // of the associated loop(s) corresponds to the value of the original |
| 8177 | // list item before entering the construct plus the logical number of |
| 8178 | // the iteration times linear-step. |
| 8179 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8180 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8181 | // OpenMP [2.1, C/C++] |
| 8182 | // A list item is a variable name. |
| 8183 | // OpenMP [2.14.3.3, Restrictions, p.1] |
| 8184 | // A variable that is part of another variable (as an array or |
| 8185 | // structure element) cannot appear in a private clause. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8186 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8187 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8188 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr) |
| 8189 | << 0 << RefExpr->getSourceRange(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8190 | continue; |
| 8191 | } |
| 8192 | |
| 8193 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); |
| 8194 | |
| 8195 | // OpenMP [2.14.3.7, linear clause] |
| 8196 | // A list-item cannot appear in more than one linear clause. |
| 8197 | // A list-item that appears in a linear clause cannot appear in any |
| 8198 | // other data-sharing attribute clause. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 8199 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8200 | if (DVar.RefExpr) { |
| 8201 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 8202 | << getOpenMPClauseName(OMPC_linear); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 8203 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8204 | continue; |
| 8205 | } |
| 8206 | |
| 8207 | QualType QType = VD->getType(); |
| 8208 | if (QType->isDependentType() || QType->isInstantiationDependentType()) { |
| 8209 | // It will be analyzed later. |
| 8210 | Vars.push_back(DE); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8211 | Privates.push_back(nullptr); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8212 | Inits.push_back(nullptr); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8213 | continue; |
| 8214 | } |
| 8215 | |
| 8216 | // A variable must not have an incomplete type or a reference type. |
| 8217 | if (RequireCompleteType(ELoc, QType, |
| 8218 | diag::err_omp_linear_incomplete_type)) { |
| 8219 | continue; |
| 8220 | } |
Alexey Bataev | 1185e19 | 2015-08-20 12:15:57 +0000 | [diff] [blame] | 8221 | if ((LinKind == OMPC_LINEAR_uval || LinKind == OMPC_LINEAR_ref) && |
| 8222 | !QType->isReferenceType()) { |
| 8223 | Diag(ELoc, diag::err_omp_wrong_linear_modifier_non_reference) |
| 8224 | << QType << getOpenMPSimpleClauseTypeName(OMPC_linear, LinKind); |
| 8225 | continue; |
| 8226 | } |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8227 | QType = QType.getNonReferenceType(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8228 | |
| 8229 | // A list item must not be const-qualified. |
| 8230 | if (QType.isConstant(Context)) { |
| 8231 | Diag(ELoc, diag::err_omp_const_variable) |
| 8232 | << getOpenMPClauseName(OMPC_linear); |
| 8233 | bool IsDecl = |
| 8234 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 8235 | Diag(VD->getLocation(), |
| 8236 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 8237 | << VD; |
| 8238 | continue; |
| 8239 | } |
| 8240 | |
| 8241 | // A list item must be of integral or pointer type. |
| 8242 | QType = QType.getUnqualifiedType().getCanonicalType(); |
| 8243 | const Type *Ty = QType.getTypePtrOrNull(); |
| 8244 | if (!Ty || (!Ty->isDependentType() && !Ty->isIntegralType(Context) && |
| 8245 | !Ty->isPointerType())) { |
| 8246 | Diag(ELoc, diag::err_omp_linear_expected_int_or_ptr) << QType; |
| 8247 | bool IsDecl = |
| 8248 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 8249 | Diag(VD->getLocation(), |
| 8250 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 8251 | << VD; |
| 8252 | continue; |
| 8253 | } |
| 8254 | |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8255 | // Build private copy of original var. |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 8256 | auto *Private = buildVarDecl(*this, ELoc, QType, VD->getName(), |
| 8257 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8258 | auto *PrivateRef = buildDeclRefExpr( |
| 8259 | *this, Private, DE->getType().getUnqualifiedType(), DE->getExprLoc()); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8260 | // Build var to save initial value. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8261 | VarDecl *Init = buildVarDecl(*this, ELoc, QType, ".linear.start"); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 8262 | Expr *InitExpr; |
| 8263 | if (LinKind == OMPC_LINEAR_uval) |
| 8264 | InitExpr = VD->getInit(); |
| 8265 | else |
| 8266 | InitExpr = DE; |
| 8267 | AddInitializerToDecl(Init, DefaultLvalueConversion(InitExpr).get(), |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8268 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8269 | auto InitRef = buildDeclRefExpr( |
| 8270 | *this, Init, DE->getType().getUnqualifiedType(), DE->getExprLoc()); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8271 | DSAStack->addDSA(VD, DE, OMPC_linear); |
| 8272 | Vars.push_back(DE); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8273 | Privates.push_back(PrivateRef); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8274 | Inits.push_back(InitRef); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8275 | } |
| 8276 | |
| 8277 | if (Vars.empty()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 8278 | return nullptr; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8279 | |
| 8280 | Expr *StepExpr = Step; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8281 | Expr *CalcStepExpr = nullptr; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8282 | if (Step && !Step->isValueDependent() && !Step->isTypeDependent() && |
| 8283 | !Step->isInstantiationDependent() && |
| 8284 | !Step->containsUnexpandedParameterPack()) { |
| 8285 | SourceLocation StepLoc = Step->getLocStart(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 8286 | ExprResult Val = PerformOpenMPImplicitIntegerConversion(StepLoc, Step); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8287 | if (Val.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 8288 | return nullptr; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 8289 | StepExpr = Val.get(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8290 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8291 | // Build var to save the step value. |
| 8292 | VarDecl *SaveVar = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 8293 | buildVarDecl(*this, StepLoc, StepExpr->getType(), ".linear.step"); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8294 | ExprResult SaveRef = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 8295 | buildDeclRefExpr(*this, SaveVar, StepExpr->getType(), StepLoc); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8296 | ExprResult CalcStep = |
| 8297 | BuildBinOp(CurScope, StepLoc, BO_Assign, SaveRef.get(), StepExpr); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 8298 | CalcStep = ActOnFinishFullExpr(CalcStep.get()); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8299 | |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8300 | // Warn about zero linear step (it would be probably better specified as |
| 8301 | // making corresponding variables 'const'). |
| 8302 | llvm::APSInt Result; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8303 | bool IsConstant = StepExpr->isIntegerConstantExpr(Result, Context); |
| 8304 | if (IsConstant && !Result.isNegative() && !Result.isStrictlyPositive()) |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8305 | Diag(StepLoc, diag::warn_omp_linear_step_zero) << Vars[0] |
| 8306 | << (Vars.size() > 1); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8307 | if (!IsConstant && CalcStep.isUsable()) { |
| 8308 | // Calculate the step beforehand instead of doing this on each iteration. |
| 8309 | // (This is not used if the number of iterations may be kfold-ed). |
| 8310 | CalcStepExpr = CalcStep.get(); |
| 8311 | } |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8312 | } |
| 8313 | |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 8314 | return OMPLinearClause::Create(Context, StartLoc, LParenLoc, LinKind, LinLoc, |
| 8315 | ColonLoc, EndLoc, Vars, Privates, Inits, |
| 8316 | StepExpr, CalcStepExpr); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8317 | } |
| 8318 | |
| 8319 | static bool FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV, |
| 8320 | Expr *NumIterations, Sema &SemaRef, |
| 8321 | Scope *S) { |
| 8322 | // Walk the vars and build update/final expressions for the CodeGen. |
| 8323 | SmallVector<Expr *, 8> Updates; |
| 8324 | SmallVector<Expr *, 8> Finals; |
| 8325 | Expr *Step = Clause.getStep(); |
| 8326 | Expr *CalcStep = Clause.getCalcStep(); |
| 8327 | // OpenMP [2.14.3.7, linear clause] |
| 8328 | // If linear-step is not specified it is assumed to be 1. |
| 8329 | if (Step == nullptr) |
| 8330 | Step = SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get(); |
| 8331 | else if (CalcStep) |
| 8332 | Step = cast<BinaryOperator>(CalcStep)->getLHS(); |
| 8333 | bool HasErrors = false; |
| 8334 | auto CurInit = Clause.inits().begin(); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8335 | auto CurPrivate = Clause.privates().begin(); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 8336 | auto LinKind = Clause.getModifier(); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8337 | for (auto &RefExpr : Clause.varlists()) { |
| 8338 | Expr *InitExpr = *CurInit; |
| 8339 | |
| 8340 | // Build privatized reference to the current linear var. |
| 8341 | auto DE = cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 8342 | Expr *CapturedRef; |
| 8343 | if (LinKind == OMPC_LINEAR_uval) |
| 8344 | CapturedRef = cast<VarDecl>(DE->getDecl())->getInit(); |
| 8345 | else |
| 8346 | CapturedRef = |
| 8347 | buildDeclRefExpr(SemaRef, cast<VarDecl>(DE->getDecl()), |
| 8348 | DE->getType().getUnqualifiedType(), DE->getExprLoc(), |
| 8349 | /*RefersToCapture=*/true); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8350 | |
| 8351 | // Build update: Var = InitExpr + IV * Step |
| 8352 | ExprResult Update = |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8353 | BuildCounterUpdate(SemaRef, S, RefExpr->getExprLoc(), *CurPrivate, |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8354 | InitExpr, IV, Step, /* Subtract */ false); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 8355 | Update = SemaRef.ActOnFinishFullExpr(Update.get(), DE->getLocStart(), |
| 8356 | /*DiscardedValue=*/true); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8357 | |
| 8358 | // Build final: Var = InitExpr + NumIterations * Step |
| 8359 | ExprResult Final = |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8360 | BuildCounterUpdate(SemaRef, S, RefExpr->getExprLoc(), CapturedRef, |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 8361 | InitExpr, NumIterations, Step, /* Subtract */ false); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 8362 | Final = SemaRef.ActOnFinishFullExpr(Final.get(), DE->getLocStart(), |
| 8363 | /*DiscardedValue=*/true); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8364 | if (!Update.isUsable() || !Final.isUsable()) { |
| 8365 | Updates.push_back(nullptr); |
| 8366 | Finals.push_back(nullptr); |
| 8367 | HasErrors = true; |
| 8368 | } else { |
| 8369 | Updates.push_back(Update.get()); |
| 8370 | Finals.push_back(Final.get()); |
| 8371 | } |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8372 | ++CurInit, ++CurPrivate; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8373 | } |
| 8374 | Clause.setUpdates(Updates); |
| 8375 | Clause.setFinals(Finals); |
| 8376 | return HasErrors; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8377 | } |
| 8378 | |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 8379 | OMPClause *Sema::ActOnOpenMPAlignedClause( |
| 8380 | ArrayRef<Expr *> VarList, Expr *Alignment, SourceLocation StartLoc, |
| 8381 | SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc) { |
| 8382 | |
| 8383 | SmallVector<Expr *, 8> Vars; |
| 8384 | for (auto &RefExpr : VarList) { |
| 8385 | assert(RefExpr && "NULL expr in OpenMP aligned clause."); |
| 8386 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 8387 | // It will be analyzed later. |
| 8388 | Vars.push_back(RefExpr); |
| 8389 | continue; |
| 8390 | } |
| 8391 | |
| 8392 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 8393 | // OpenMP [2.1, C/C++] |
| 8394 | // A list item is a variable name. |
| 8395 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
| 8396 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8397 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr) |
| 8398 | << 0 << RefExpr->getSourceRange(); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 8399 | continue; |
| 8400 | } |
| 8401 | |
| 8402 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); |
| 8403 | |
| 8404 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 8405 | // The type of list items appearing in the aligned clause must be |
| 8406 | // array, pointer, reference to array, or reference to pointer. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8407 | QualType QType = VD->getType(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8408 | QType = QType.getNonReferenceType().getUnqualifiedType().getCanonicalType(); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 8409 | const Type *Ty = QType.getTypePtrOrNull(); |
| 8410 | if (!Ty || (!Ty->isDependentType() && !Ty->isArrayType() && |
| 8411 | !Ty->isPointerType())) { |
| 8412 | Diag(ELoc, diag::err_omp_aligned_expected_array_or_ptr) |
| 8413 | << QType << getLangOpts().CPlusPlus << RefExpr->getSourceRange(); |
| 8414 | bool IsDecl = |
| 8415 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 8416 | Diag(VD->getLocation(), |
| 8417 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 8418 | << VD; |
| 8419 | continue; |
| 8420 | } |
| 8421 | |
| 8422 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 8423 | // A list-item cannot appear in more than one aligned clause. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8424 | if (Expr *PrevRef = DSAStack->addUniqueAligned(VD, DE)) { |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 8425 | Diag(ELoc, diag::err_omp_aligned_twice) << RefExpr->getSourceRange(); |
| 8426 | Diag(PrevRef->getExprLoc(), diag::note_omp_explicit_dsa) |
| 8427 | << getOpenMPClauseName(OMPC_aligned); |
| 8428 | continue; |
| 8429 | } |
| 8430 | |
| 8431 | Vars.push_back(DE); |
| 8432 | } |
| 8433 | |
| 8434 | // OpenMP [2.8.1, simd construct, Description] |
| 8435 | // The parameter of the aligned clause, alignment, must be a constant |
| 8436 | // positive integer expression. |
| 8437 | // If no optional parameter is specified, implementation-defined default |
| 8438 | // alignments for SIMD instructions on the target platforms are assumed. |
| 8439 | if (Alignment != nullptr) { |
| 8440 | ExprResult AlignResult = |
| 8441 | VerifyPositiveIntegerConstantInClause(Alignment, OMPC_aligned); |
| 8442 | if (AlignResult.isInvalid()) |
| 8443 | return nullptr; |
| 8444 | Alignment = AlignResult.get(); |
| 8445 | } |
| 8446 | if (Vars.empty()) |
| 8447 | return nullptr; |
| 8448 | |
| 8449 | return OMPAlignedClause::Create(Context, StartLoc, LParenLoc, ColonLoc, |
| 8450 | EndLoc, Vars, Alignment); |
| 8451 | } |
| 8452 | |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8453 | OMPClause *Sema::ActOnOpenMPCopyinClause(ArrayRef<Expr *> VarList, |
| 8454 | SourceLocation StartLoc, |
| 8455 | SourceLocation LParenLoc, |
| 8456 | SourceLocation EndLoc) { |
| 8457 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 8458 | SmallVector<Expr *, 8> SrcExprs; |
| 8459 | SmallVector<Expr *, 8> DstExprs; |
| 8460 | SmallVector<Expr *, 8> AssignmentOps; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8461 | for (auto &RefExpr : VarList) { |
| 8462 | assert(RefExpr && "NULL expr in OpenMP copyin clause."); |
| 8463 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8464 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8465 | Vars.push_back(RefExpr); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 8466 | SrcExprs.push_back(nullptr); |
| 8467 | DstExprs.push_back(nullptr); |
| 8468 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8469 | continue; |
| 8470 | } |
| 8471 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8472 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8473 | // OpenMP [2.1, C/C++] |
| 8474 | // A list item is a variable name. |
| 8475 | // OpenMP [2.14.4.1, Restrictions, p.1] |
| 8476 | // A list item that appears in a copyin clause must be threadprivate. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8477 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8478 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8479 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr) |
| 8480 | << 0 << RefExpr->getSourceRange(); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8481 | continue; |
| 8482 | } |
| 8483 | |
| 8484 | Decl *D = DE->getDecl(); |
| 8485 | VarDecl *VD = cast<VarDecl>(D); |
| 8486 | |
| 8487 | QualType Type = VD->getType(); |
| 8488 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 8489 | // It will be analyzed later. |
| 8490 | Vars.push_back(DE); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 8491 | SrcExprs.push_back(nullptr); |
| 8492 | DstExprs.push_back(nullptr); |
| 8493 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8494 | continue; |
| 8495 | } |
| 8496 | |
| 8497 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.1] |
| 8498 | // A list item that appears in a copyin clause must be threadprivate. |
| 8499 | if (!DSAStack->isThreadPrivate(VD)) { |
| 8500 | Diag(ELoc, diag::err_omp_required_access) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8501 | << getOpenMPClauseName(OMPC_copyin) |
| 8502 | << getOpenMPDirectiveName(OMPD_threadprivate); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8503 | continue; |
| 8504 | } |
| 8505 | |
| 8506 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.2] |
| 8507 | // A variable of class type (or array thereof) that appears in a |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 8508 | // copyin clause requires an accessible, unambiguous copy assignment |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8509 | // operator for the class type. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8510 | auto ElemType = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 8511 | auto *SrcVD = |
| 8512 | buildVarDecl(*this, DE->getLocStart(), ElemType.getUnqualifiedType(), |
| 8513 | ".copyin.src", VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 8514 | auto *PseudoSrcExpr = buildDeclRefExpr( |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8515 | *this, SrcVD, ElemType.getUnqualifiedType(), DE->getExprLoc()); |
| 8516 | auto *DstVD = |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 8517 | buildVarDecl(*this, DE->getLocStart(), ElemType, ".copyin.dst", |
| 8518 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 8519 | auto *PseudoDstExpr = |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8520 | buildDeclRefExpr(*this, DstVD, ElemType, DE->getExprLoc()); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 8521 | // For arrays generate assignment operation for single element and replace |
| 8522 | // it by the original array element in CodeGen. |
| 8523 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, DE->getExprLoc(), BO_Assign, |
| 8524 | PseudoDstExpr, PseudoSrcExpr); |
| 8525 | if (AssignmentOp.isInvalid()) |
| 8526 | continue; |
| 8527 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), DE->getExprLoc(), |
| 8528 | /*DiscardedValue=*/true); |
| 8529 | if (AssignmentOp.isInvalid()) |
| 8530 | continue; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8531 | |
| 8532 | DSAStack->addDSA(VD, DE, OMPC_copyin); |
| 8533 | Vars.push_back(DE); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 8534 | SrcExprs.push_back(PseudoSrcExpr); |
| 8535 | DstExprs.push_back(PseudoDstExpr); |
| 8536 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8537 | } |
| 8538 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8539 | if (Vars.empty()) |
| 8540 | return nullptr; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8541 | |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 8542 | return OMPCopyinClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
| 8543 | SrcExprs, DstExprs, AssignmentOps); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8544 | } |
| 8545 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8546 | OMPClause *Sema::ActOnOpenMPCopyprivateClause(ArrayRef<Expr *> VarList, |
| 8547 | SourceLocation StartLoc, |
| 8548 | SourceLocation LParenLoc, |
| 8549 | SourceLocation EndLoc) { |
| 8550 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 8551 | SmallVector<Expr *, 8> SrcExprs; |
| 8552 | SmallVector<Expr *, 8> DstExprs; |
| 8553 | SmallVector<Expr *, 8> AssignmentOps; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8554 | for (auto &RefExpr : VarList) { |
| 8555 | assert(RefExpr && "NULL expr in OpenMP copyprivate clause."); |
| 8556 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 8557 | // It will be analyzed later. |
| 8558 | Vars.push_back(RefExpr); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 8559 | SrcExprs.push_back(nullptr); |
| 8560 | DstExprs.push_back(nullptr); |
| 8561 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8562 | continue; |
| 8563 | } |
| 8564 | |
| 8565 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 8566 | // OpenMP [2.1, C/C++] |
| 8567 | // A list item is a variable name. |
| 8568 | // OpenMP [2.14.4.1, Restrictions, p.1] |
| 8569 | // A list item that appears in a copyin clause must be threadprivate. |
| 8570 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
| 8571 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8572 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr) |
| 8573 | << 0 << RefExpr->getSourceRange(); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8574 | continue; |
| 8575 | } |
| 8576 | |
| 8577 | Decl *D = DE->getDecl(); |
| 8578 | VarDecl *VD = cast<VarDecl>(D); |
| 8579 | |
| 8580 | QualType Type = VD->getType(); |
| 8581 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 8582 | // It will be analyzed later. |
| 8583 | Vars.push_back(DE); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 8584 | SrcExprs.push_back(nullptr); |
| 8585 | DstExprs.push_back(nullptr); |
| 8586 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8587 | continue; |
| 8588 | } |
| 8589 | |
| 8590 | // OpenMP [2.14.4.2, Restrictions, p.2] |
| 8591 | // A list item that appears in a copyprivate clause may not appear in a |
| 8592 | // private or firstprivate clause on the single construct. |
| 8593 | if (!DSAStack->isThreadPrivate(VD)) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 8594 | auto DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 8595 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_copyprivate && |
| 8596 | DVar.RefExpr) { |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8597 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 8598 | << getOpenMPClauseName(DVar.CKind) |
| 8599 | << getOpenMPClauseName(OMPC_copyprivate); |
| 8600 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 8601 | continue; |
| 8602 | } |
| 8603 | |
| 8604 | // OpenMP [2.11.4.2, Restrictions, p.1] |
| 8605 | // All list items that appear in a copyprivate clause must be either |
| 8606 | // threadprivate or private in the enclosing context. |
| 8607 | if (DVar.CKind == OMPC_unknown) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 8608 | DVar = DSAStack->getImplicitDSA(VD, false); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8609 | if (DVar.CKind == OMPC_shared) { |
| 8610 | Diag(ELoc, diag::err_omp_required_access) |
| 8611 | << getOpenMPClauseName(OMPC_copyprivate) |
| 8612 | << "threadprivate or private in the enclosing context"; |
| 8613 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 8614 | continue; |
| 8615 | } |
| 8616 | } |
| 8617 | } |
| 8618 | |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 8619 | // Variably modified types are not supported. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 8620 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType()) { |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 8621 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8622 | << getOpenMPClauseName(OMPC_copyprivate) << Type |
| 8623 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 8624 | bool IsDecl = |
| 8625 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 8626 | Diag(VD->getLocation(), |
| 8627 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 8628 | << VD; |
| 8629 | continue; |
| 8630 | } |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8631 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8632 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.2] |
| 8633 | // A variable of class type (or array thereof) that appears in a |
| 8634 | // copyin clause requires an accessible, unambiguous copy assignment |
| 8635 | // operator for the class type. |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8636 | Type = Context.getBaseElementType(Type.getNonReferenceType()) |
| 8637 | .getUnqualifiedType(); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 8638 | auto *SrcVD = |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 8639 | buildVarDecl(*this, DE->getLocStart(), Type, ".copyprivate.src", |
| 8640 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 8641 | auto *PseudoSrcExpr = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 8642 | buildDeclRefExpr(*this, SrcVD, Type, DE->getExprLoc()); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 8643 | auto *DstVD = |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 8644 | buildVarDecl(*this, DE->getLocStart(), Type, ".copyprivate.dst", |
| 8645 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 8646 | auto *PseudoDstExpr = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 8647 | buildDeclRefExpr(*this, DstVD, Type, DE->getExprLoc()); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 8648 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, DE->getExprLoc(), BO_Assign, |
| 8649 | PseudoDstExpr, PseudoSrcExpr); |
| 8650 | if (AssignmentOp.isInvalid()) |
| 8651 | continue; |
| 8652 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), DE->getExprLoc(), |
| 8653 | /*DiscardedValue=*/true); |
| 8654 | if (AssignmentOp.isInvalid()) |
| 8655 | continue; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8656 | |
| 8657 | // No need to mark vars as copyprivate, they are already threadprivate or |
| 8658 | // implicitly private. |
| 8659 | Vars.push_back(DE); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 8660 | SrcExprs.push_back(PseudoSrcExpr); |
| 8661 | DstExprs.push_back(PseudoDstExpr); |
| 8662 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8663 | } |
| 8664 | |
| 8665 | if (Vars.empty()) |
| 8666 | return nullptr; |
| 8667 | |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 8668 | return OMPCopyprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| 8669 | Vars, SrcExprs, DstExprs, AssignmentOps); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8670 | } |
| 8671 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 8672 | OMPClause *Sema::ActOnOpenMPFlushClause(ArrayRef<Expr *> VarList, |
| 8673 | SourceLocation StartLoc, |
| 8674 | SourceLocation LParenLoc, |
| 8675 | SourceLocation EndLoc) { |
| 8676 | if (VarList.empty()) |
| 8677 | return nullptr; |
| 8678 | |
| 8679 | return OMPFlushClause::Create(Context, StartLoc, LParenLoc, EndLoc, VarList); |
| 8680 | } |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 8681 | |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8682 | OMPClause * |
| 8683 | Sema::ActOnOpenMPDependClause(OpenMPDependClauseKind DepKind, |
| 8684 | SourceLocation DepLoc, SourceLocation ColonLoc, |
| 8685 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
| 8686 | SourceLocation LParenLoc, SourceLocation EndLoc) { |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 8687 | if (DSAStack->getCurrentDirective() == OMPD_ordered && |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 8688 | DepKind != OMPC_DEPEND_source && DepKind != OMPC_DEPEND_sink) { |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 8689 | Diag(DepLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 8690 | << "'source' or 'sink'" << getOpenMPClauseName(OMPC_depend); |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 8691 | return nullptr; |
| 8692 | } |
| 8693 | if (DSAStack->getCurrentDirective() != OMPD_ordered && |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 8694 | (DepKind == OMPC_DEPEND_unknown || DepKind == OMPC_DEPEND_source || |
| 8695 | DepKind == OMPC_DEPEND_sink)) { |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 8696 | unsigned Except[] = {OMPC_DEPEND_source, OMPC_DEPEND_sink}; |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8697 | Diag(DepLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 8698 | << getListOfPossibleValues(OMPC_depend, /*First=*/0, |
| 8699 | /*Last=*/OMPC_DEPEND_unknown, Except) |
| 8700 | << getOpenMPClauseName(OMPC_depend); |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8701 | return nullptr; |
| 8702 | } |
| 8703 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 8704 | llvm::APSInt DepCounter(/*BitWidth=*/32); |
| 8705 | llvm::APSInt TotalDepCount(/*BitWidth=*/32); |
| 8706 | if (DepKind == OMPC_DEPEND_sink) { |
| 8707 | if (auto *OrderedCountExpr = DSAStack->getParentOrderedRegionParam()) { |
| 8708 | TotalDepCount = OrderedCountExpr->EvaluateKnownConstInt(Context); |
| 8709 | TotalDepCount.setIsUnsigned(/*Val=*/true); |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8710 | } |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8711 | } |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 8712 | if ((DepKind != OMPC_DEPEND_sink && DepKind != OMPC_DEPEND_source) || |
| 8713 | DSAStack->getParentOrderedRegionParam()) { |
| 8714 | for (auto &RefExpr : VarList) { |
| 8715 | assert(RefExpr && "NULL expr in OpenMP shared clause."); |
| 8716 | if (isa<DependentScopeDeclRefExpr>(RefExpr) || |
| 8717 | (DepKind == OMPC_DEPEND_sink && CurContext->isDependentContext())) { |
| 8718 | // It will be analyzed later. |
| 8719 | Vars.push_back(RefExpr); |
| 8720 | continue; |
| 8721 | } |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8722 | |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 8723 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 8724 | auto *SimpleExpr = RefExpr->IgnoreParenCasts(); |
| 8725 | if (DepKind == OMPC_DEPEND_sink) { |
| 8726 | if (DepCounter >= TotalDepCount) { |
| 8727 | Diag(ELoc, diag::err_omp_depend_sink_unexpected_expr); |
| 8728 | continue; |
| 8729 | } |
| 8730 | ++DepCounter; |
| 8731 | // OpenMP [2.13.9, Summary] |
| 8732 | // depend(dependence-type : vec), where dependence-type is: |
| 8733 | // 'sink' and where vec is the iteration vector, which has the form: |
| 8734 | // x1 [+- d1], x2 [+- d2 ], . . . , xn [+- dn] |
| 8735 | // where n is the value specified by the ordered clause in the loop |
| 8736 | // directive, xi denotes the loop iteration variable of the i-th nested |
| 8737 | // loop associated with the loop directive, and di is a constant |
| 8738 | // non-negative integer. |
| 8739 | SimpleExpr = SimpleExpr->IgnoreImplicit(); |
| 8740 | auto *DE = dyn_cast<DeclRefExpr>(SimpleExpr); |
| 8741 | if (!DE) { |
| 8742 | OverloadedOperatorKind OOK = OO_None; |
| 8743 | SourceLocation OOLoc; |
| 8744 | Expr *LHS, *RHS; |
| 8745 | if (auto *BO = dyn_cast<BinaryOperator>(SimpleExpr)) { |
| 8746 | OOK = BinaryOperator::getOverloadedOperator(BO->getOpcode()); |
| 8747 | OOLoc = BO->getOperatorLoc(); |
| 8748 | LHS = BO->getLHS()->IgnoreParenImpCasts(); |
| 8749 | RHS = BO->getRHS()->IgnoreParenImpCasts(); |
| 8750 | } else if (auto *OCE = dyn_cast<CXXOperatorCallExpr>(SimpleExpr)) { |
| 8751 | OOK = OCE->getOperator(); |
| 8752 | OOLoc = OCE->getOperatorLoc(); |
| 8753 | LHS = OCE->getArg(/*Arg=*/0)->IgnoreParenImpCasts(); |
| 8754 | RHS = OCE->getArg(/*Arg=*/1)->IgnoreParenImpCasts(); |
| 8755 | } else if (auto *MCE = dyn_cast<CXXMemberCallExpr>(SimpleExpr)) { |
| 8756 | OOK = MCE->getMethodDecl() |
| 8757 | ->getNameInfo() |
| 8758 | .getName() |
| 8759 | .getCXXOverloadedOperator(); |
| 8760 | OOLoc = MCE->getCallee()->getExprLoc(); |
| 8761 | LHS = MCE->getImplicitObjectArgument()->IgnoreParenImpCasts(); |
| 8762 | RHS = MCE->getArg(/*Arg=*/0)->IgnoreParenImpCasts(); |
| 8763 | } else { |
| 8764 | Diag(ELoc, diag::err_omp_depend_sink_wrong_expr); |
| 8765 | continue; |
| 8766 | } |
| 8767 | DE = dyn_cast<DeclRefExpr>(LHS); |
| 8768 | if (!DE) { |
| 8769 | Diag(LHS->getExprLoc(), |
| 8770 | diag::err_omp_depend_sink_expected_loop_iteration) |
| 8771 | << DSAStack->getParentLoopControlVariable( |
| 8772 | DepCounter.getZExtValue()); |
| 8773 | continue; |
| 8774 | } |
| 8775 | if (OOK != OO_Plus && OOK != OO_Minus) { |
| 8776 | Diag(OOLoc, diag::err_omp_depend_sink_expected_plus_minus); |
| 8777 | continue; |
| 8778 | } |
| 8779 | ExprResult Res = VerifyPositiveIntegerConstantInClause( |
| 8780 | RHS, OMPC_depend, /*StrictlyPositive=*/false); |
| 8781 | if (Res.isInvalid()) |
| 8782 | continue; |
| 8783 | } |
| 8784 | auto *VD = dyn_cast<VarDecl>(DE->getDecl()); |
| 8785 | if (!CurContext->isDependentContext() && |
| 8786 | DSAStack->getParentOrderedRegionParam() && |
| 8787 | (!VD || DepCounter != DSAStack->isParentLoopControlVariable(VD))) { |
| 8788 | Diag(DE->getExprLoc(), |
| 8789 | diag::err_omp_depend_sink_expected_loop_iteration) |
| 8790 | << DSAStack->getParentLoopControlVariable( |
| 8791 | DepCounter.getZExtValue()); |
| 8792 | continue; |
| 8793 | } |
| 8794 | } else { |
| 8795 | // OpenMP [2.11.1.1, Restrictions, p.3] |
| 8796 | // A variable that is part of another variable (such as a field of a |
| 8797 | // structure) but is not an array element or an array section cannot |
| 8798 | // appear in a depend clause. |
| 8799 | auto *DE = dyn_cast<DeclRefExpr>(SimpleExpr); |
| 8800 | auto *ASE = dyn_cast<ArraySubscriptExpr>(SimpleExpr); |
| 8801 | auto *OASE = dyn_cast<OMPArraySectionExpr>(SimpleExpr); |
| 8802 | if (!RefExpr->IgnoreParenImpCasts()->isLValue() || |
| 8803 | (!ASE && !DE && !OASE) || (DE && !isa<VarDecl>(DE->getDecl())) || |
Alexey Bataev | 31300ed | 2016-02-04 11:27:03 +0000 | [diff] [blame] | 8804 | (ASE && |
| 8805 | !ASE->getBase() |
| 8806 | ->getType() |
| 8807 | .getNonReferenceType() |
| 8808 | ->isPointerType() && |
| 8809 | !ASE->getBase()->getType().getNonReferenceType()->isArrayType())) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8810 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr_or_array_item) |
| 8811 | << 0 << RefExpr->getSourceRange(); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 8812 | continue; |
| 8813 | } |
| 8814 | } |
| 8815 | |
| 8816 | Vars.push_back(RefExpr->IgnoreParenImpCasts()); |
| 8817 | } |
| 8818 | |
| 8819 | if (!CurContext->isDependentContext() && DepKind == OMPC_DEPEND_sink && |
| 8820 | TotalDepCount > VarList.size() && |
| 8821 | DSAStack->getParentOrderedRegionParam()) { |
| 8822 | Diag(EndLoc, diag::err_omp_depend_sink_expected_loop_iteration) |
| 8823 | << DSAStack->getParentLoopControlVariable(VarList.size() + 1); |
| 8824 | } |
| 8825 | if (DepKind != OMPC_DEPEND_source && DepKind != OMPC_DEPEND_sink && |
| 8826 | Vars.empty()) |
| 8827 | return nullptr; |
| 8828 | } |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8829 | |
| 8830 | return OMPDependClause::Create(Context, StartLoc, LParenLoc, EndLoc, DepKind, |
| 8831 | DepLoc, ColonLoc, Vars); |
| 8832 | } |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 8833 | |
| 8834 | OMPClause *Sema::ActOnOpenMPDeviceClause(Expr *Device, SourceLocation StartLoc, |
| 8835 | SourceLocation LParenLoc, |
| 8836 | SourceLocation EndLoc) { |
| 8837 | Expr *ValExpr = Device; |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 8838 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 8839 | // OpenMP [2.9.1, Restrictions] |
| 8840 | // The device expression must evaluate to a non-negative integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 8841 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_device, |
| 8842 | /*StrictlyPositive=*/false)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 8843 | return nullptr; |
| 8844 | |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 8845 | return new (Context) OMPDeviceClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 8846 | } |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 8847 | |
| 8848 | static bool IsCXXRecordForMappable(Sema &SemaRef, SourceLocation Loc, |
| 8849 | DSAStackTy *Stack, CXXRecordDecl *RD) { |
| 8850 | if (!RD || RD->isInvalidDecl()) |
| 8851 | return true; |
| 8852 | |
Alexey Bataev | c9bd03d | 2015-12-17 06:55:08 +0000 | [diff] [blame] | 8853 | if (auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(RD)) |
| 8854 | if (auto *CTD = CTSD->getSpecializedTemplate()) |
| 8855 | RD = CTD->getTemplatedDecl(); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 8856 | auto QTy = SemaRef.Context.getRecordType(RD); |
| 8857 | if (RD->isDynamicClass()) { |
| 8858 | SemaRef.Diag(Loc, diag::err_omp_not_mappable_type) << QTy; |
| 8859 | SemaRef.Diag(RD->getLocation(), diag::note_omp_polymorphic_in_target); |
| 8860 | return false; |
| 8861 | } |
| 8862 | auto *DC = RD; |
| 8863 | bool IsCorrect = true; |
| 8864 | for (auto *I : DC->decls()) { |
| 8865 | if (I) { |
| 8866 | if (auto *MD = dyn_cast<CXXMethodDecl>(I)) { |
| 8867 | if (MD->isStatic()) { |
| 8868 | SemaRef.Diag(Loc, diag::err_omp_not_mappable_type) << QTy; |
| 8869 | SemaRef.Diag(MD->getLocation(), |
| 8870 | diag::note_omp_static_member_in_target); |
| 8871 | IsCorrect = false; |
| 8872 | } |
| 8873 | } else if (auto *VD = dyn_cast<VarDecl>(I)) { |
| 8874 | if (VD->isStaticDataMember()) { |
| 8875 | SemaRef.Diag(Loc, diag::err_omp_not_mappable_type) << QTy; |
| 8876 | SemaRef.Diag(VD->getLocation(), |
| 8877 | diag::note_omp_static_member_in_target); |
| 8878 | IsCorrect = false; |
| 8879 | } |
| 8880 | } |
| 8881 | } |
| 8882 | } |
| 8883 | |
| 8884 | for (auto &I : RD->bases()) { |
| 8885 | if (!IsCXXRecordForMappable(SemaRef, I.getLocStart(), Stack, |
| 8886 | I.getType()->getAsCXXRecordDecl())) |
| 8887 | IsCorrect = false; |
| 8888 | } |
| 8889 | return IsCorrect; |
| 8890 | } |
| 8891 | |
| 8892 | static bool CheckTypeMappable(SourceLocation SL, SourceRange SR, Sema &SemaRef, |
| 8893 | DSAStackTy *Stack, QualType QTy) { |
| 8894 | NamedDecl *ND; |
| 8895 | if (QTy->isIncompleteType(&ND)) { |
| 8896 | SemaRef.Diag(SL, diag::err_incomplete_type) << QTy << SR; |
| 8897 | return false; |
| 8898 | } else if (CXXRecordDecl *RD = dyn_cast_or_null<CXXRecordDecl>(ND)) { |
| 8899 | if (!RD->isInvalidDecl() && |
| 8900 | !IsCXXRecordForMappable(SemaRef, SL, Stack, RD)) |
| 8901 | return false; |
| 8902 | } |
| 8903 | return true; |
| 8904 | } |
| 8905 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 8906 | // Return the expression of the base of the map clause or null if it cannot |
| 8907 | // be determined and do all the necessary checks to see if the expression is |
| 8908 | // valid as a standalone map clause expression. |
| 8909 | static Expr *CheckMapClauseExpressionBase(Sema &SemaRef, Expr *E) { |
| 8910 | SourceLocation ELoc = E->getExprLoc(); |
| 8911 | SourceRange ERange = E->getSourceRange(); |
| 8912 | |
| 8913 | // The base of elements of list in a map clause have to be either: |
| 8914 | // - a reference to variable or field. |
| 8915 | // - a member expression. |
| 8916 | // - an array expression. |
| 8917 | // |
| 8918 | // E.g. if we have the expression 'r.S.Arr[:12]', we want to retrieve the |
| 8919 | // reference to 'r'. |
| 8920 | // |
| 8921 | // If we have: |
| 8922 | // |
| 8923 | // struct SS { |
| 8924 | // Bla S; |
| 8925 | // foo() { |
| 8926 | // #pragma omp target map (S.Arr[:12]); |
| 8927 | // } |
| 8928 | // } |
| 8929 | // |
| 8930 | // We want to retrieve the member expression 'this->S'; |
| 8931 | |
| 8932 | Expr *RelevantExpr = nullptr; |
| 8933 | |
| 8934 | // Flags to help capture some memory |
| 8935 | |
| 8936 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.2] |
| 8937 | // If a list item is an array section, it must specify contiguous storage. |
| 8938 | // |
| 8939 | // For this restriction it is sufficient that we make sure only references |
| 8940 | // to variables or fields and array expressions, and that no array sections |
| 8941 | // exist except in the rightmost expression. E.g. these would be invalid: |
| 8942 | // |
| 8943 | // r.ArrS[3:5].Arr[6:7] |
| 8944 | // |
| 8945 | // r.ArrS[3:5].x |
| 8946 | // |
| 8947 | // but these would be valid: |
| 8948 | // r.ArrS[3].Arr[6:7] |
| 8949 | // |
| 8950 | // r.ArrS[3].x |
| 8951 | |
| 8952 | bool IsRightMostExpression = true; |
| 8953 | |
| 8954 | while (!RelevantExpr) { |
| 8955 | auto AllowArraySection = IsRightMostExpression; |
| 8956 | IsRightMostExpression = false; |
| 8957 | |
| 8958 | E = E->IgnoreParenImpCasts(); |
| 8959 | |
| 8960 | if (auto *CurE = dyn_cast<DeclRefExpr>(E)) { |
| 8961 | if (!isa<VarDecl>(CurE->getDecl())) |
| 8962 | break; |
| 8963 | |
| 8964 | RelevantExpr = CurE; |
| 8965 | continue; |
| 8966 | } |
| 8967 | |
| 8968 | if (auto *CurE = dyn_cast<MemberExpr>(E)) { |
| 8969 | auto *BaseE = CurE->getBase()->IgnoreParenImpCasts(); |
| 8970 | |
| 8971 | if (isa<CXXThisExpr>(BaseE)) |
| 8972 | // We found a base expression: this->Val. |
| 8973 | RelevantExpr = CurE; |
| 8974 | else |
| 8975 | E = BaseE; |
| 8976 | |
| 8977 | if (!isa<FieldDecl>(CurE->getMemberDecl())) { |
| 8978 | SemaRef.Diag(ELoc, diag::err_omp_expected_access_to_data_field) |
| 8979 | << CurE->getSourceRange(); |
| 8980 | break; |
| 8981 | } |
| 8982 | |
| 8983 | auto *FD = cast<FieldDecl>(CurE->getMemberDecl()); |
| 8984 | |
| 8985 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C/C++, p.3] |
| 8986 | // A bit-field cannot appear in a map clause. |
| 8987 | // |
| 8988 | if (FD->isBitField()) { |
| 8989 | SemaRef.Diag(ELoc, diag::err_omp_bit_fields_forbidden_in_map_clause) |
| 8990 | << CurE->getSourceRange(); |
| 8991 | break; |
| 8992 | } |
| 8993 | |
| 8994 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] |
| 8995 | // If the type of a list item is a reference to a type T then the type |
| 8996 | // will be considered to be T for all purposes of this clause. |
| 8997 | QualType CurType = BaseE->getType(); |
| 8998 | if (CurType->isReferenceType()) |
| 8999 | CurType = CurType->getPointeeType(); |
| 9000 | |
| 9001 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C/C++, p.2] |
| 9002 | // A list item cannot be a variable that is a member of a structure with |
| 9003 | // a union type. |
| 9004 | // |
| 9005 | if (auto *RT = CurType->getAs<RecordType>()) |
| 9006 | if (RT->isUnionType()) { |
| 9007 | SemaRef.Diag(ELoc, diag::err_omp_union_type_not_allowed) |
| 9008 | << CurE->getSourceRange(); |
| 9009 | break; |
| 9010 | } |
| 9011 | |
| 9012 | continue; |
| 9013 | } |
| 9014 | |
| 9015 | if (auto *CurE = dyn_cast<ArraySubscriptExpr>(E)) { |
| 9016 | E = CurE->getBase()->IgnoreParenImpCasts(); |
| 9017 | |
| 9018 | if (!E->getType()->isAnyPointerType() && !E->getType()->isArrayType()) { |
| 9019 | SemaRef.Diag(ELoc, diag::err_omp_expected_base_var_name) |
| 9020 | << 0 << CurE->getSourceRange(); |
| 9021 | break; |
| 9022 | } |
| 9023 | continue; |
| 9024 | } |
| 9025 | |
| 9026 | if (auto *CurE = dyn_cast<OMPArraySectionExpr>(E)) { |
| 9027 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.7] |
| 9028 | // If a list item is an element of a structure, only the rightmost symbol |
| 9029 | // of the variable reference can be an array section. |
| 9030 | // |
| 9031 | if (!AllowArraySection) { |
| 9032 | SemaRef.Diag(ELoc, diag::err_omp_array_section_in_rightmost_expression) |
| 9033 | << CurE->getSourceRange(); |
| 9034 | break; |
| 9035 | } |
| 9036 | |
| 9037 | E = CurE->getBase()->IgnoreParenImpCasts(); |
| 9038 | |
| 9039 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] |
| 9040 | // If the type of a list item is a reference to a type T then the type |
| 9041 | // will be considered to be T for all purposes of this clause. |
| 9042 | QualType CurType = E->getType(); |
| 9043 | if (CurType->isReferenceType()) |
| 9044 | CurType = CurType->getPointeeType(); |
| 9045 | |
| 9046 | if (!CurType->isAnyPointerType() && !CurType->isArrayType()) { |
| 9047 | SemaRef.Diag(ELoc, diag::err_omp_expected_base_var_name) |
| 9048 | << 0 << CurE->getSourceRange(); |
| 9049 | break; |
| 9050 | } |
| 9051 | |
| 9052 | continue; |
| 9053 | } |
| 9054 | |
| 9055 | // If nothing else worked, this is not a valid map clause expression. |
| 9056 | SemaRef.Diag(ELoc, |
| 9057 | diag::err_omp_expected_named_var_member_or_array_expression) |
| 9058 | << ERange; |
| 9059 | break; |
| 9060 | } |
| 9061 | |
| 9062 | return RelevantExpr; |
| 9063 | } |
| 9064 | |
| 9065 | // Return true if expression E associated with value VD has conflicts with other |
| 9066 | // map information. |
| 9067 | static bool CheckMapConflicts(Sema &SemaRef, DSAStackTy *DSAS, ValueDecl *VD, |
| 9068 | Expr *E, bool CurrentRegionOnly) { |
| 9069 | assert(VD && E); |
| 9070 | |
| 9071 | // Types used to organize the components of a valid map clause. |
| 9072 | typedef std::pair<Expr *, ValueDecl *> MapExpressionComponent; |
| 9073 | typedef SmallVector<MapExpressionComponent, 4> MapExpressionComponents; |
| 9074 | |
| 9075 | // Helper to extract the components in the map clause expression E and store |
| 9076 | // them into MEC. This assumes that E is a valid map clause expression, i.e. |
| 9077 | // it has already passed the single clause checks. |
| 9078 | auto ExtractMapExpressionComponents = [](Expr *TE, |
| 9079 | MapExpressionComponents &MEC) { |
| 9080 | while (true) { |
| 9081 | TE = TE->IgnoreParenImpCasts(); |
| 9082 | |
| 9083 | if (auto *CurE = dyn_cast<DeclRefExpr>(TE)) { |
| 9084 | MEC.push_back( |
| 9085 | MapExpressionComponent(CurE, cast<VarDecl>(CurE->getDecl()))); |
| 9086 | break; |
| 9087 | } |
| 9088 | |
| 9089 | if (auto *CurE = dyn_cast<MemberExpr>(TE)) { |
| 9090 | auto *BaseE = CurE->getBase()->IgnoreParenImpCasts(); |
| 9091 | |
| 9092 | MEC.push_back(MapExpressionComponent( |
| 9093 | CurE, cast<FieldDecl>(CurE->getMemberDecl()))); |
| 9094 | if (isa<CXXThisExpr>(BaseE)) |
| 9095 | break; |
| 9096 | |
| 9097 | TE = BaseE; |
| 9098 | continue; |
| 9099 | } |
| 9100 | |
| 9101 | if (auto *CurE = dyn_cast<ArraySubscriptExpr>(TE)) { |
| 9102 | MEC.push_back(MapExpressionComponent(CurE, nullptr)); |
| 9103 | TE = CurE->getBase()->IgnoreParenImpCasts(); |
| 9104 | continue; |
| 9105 | } |
| 9106 | |
| 9107 | if (auto *CurE = dyn_cast<OMPArraySectionExpr>(TE)) { |
| 9108 | MEC.push_back(MapExpressionComponent(CurE, nullptr)); |
| 9109 | TE = CurE->getBase()->IgnoreParenImpCasts(); |
| 9110 | continue; |
| 9111 | } |
| 9112 | |
| 9113 | llvm_unreachable( |
| 9114 | "Expecting only valid map clause expressions at this point!"); |
| 9115 | } |
| 9116 | }; |
| 9117 | |
| 9118 | SourceLocation ELoc = E->getExprLoc(); |
| 9119 | SourceRange ERange = E->getSourceRange(); |
| 9120 | |
| 9121 | // In order to easily check the conflicts we need to match each component of |
| 9122 | // the expression under test with the components of the expressions that are |
| 9123 | // already in the stack. |
| 9124 | |
| 9125 | MapExpressionComponents CurComponents; |
| 9126 | ExtractMapExpressionComponents(E, CurComponents); |
| 9127 | |
| 9128 | assert(!CurComponents.empty() && "Map clause expression with no components!"); |
| 9129 | assert(CurComponents.back().second == VD && |
| 9130 | "Map clause expression with unexpected base!"); |
| 9131 | |
| 9132 | // Variables to help detecting enclosing problems in data environment nests. |
| 9133 | bool IsEnclosedByDataEnvironmentExpr = false; |
| 9134 | Expr *EnclosingExpr = nullptr; |
| 9135 | |
| 9136 | bool FoundError = |
| 9137 | DSAS->checkMapInfoForVar(VD, CurrentRegionOnly, [&](Expr *RE) -> bool { |
| 9138 | MapExpressionComponents StackComponents; |
| 9139 | ExtractMapExpressionComponents(RE, StackComponents); |
| 9140 | assert(!StackComponents.empty() && |
| 9141 | "Map clause expression with no components!"); |
| 9142 | assert(StackComponents.back().second == VD && |
| 9143 | "Map clause expression with unexpected base!"); |
| 9144 | |
| 9145 | // Expressions must start from the same base. Here we detect at which |
| 9146 | // point both expressions diverge from each other and see if we can |
| 9147 | // detect if the memory referred to both expressions is contiguous and |
| 9148 | // do not overlap. |
| 9149 | auto CI = CurComponents.rbegin(); |
| 9150 | auto CE = CurComponents.rend(); |
| 9151 | auto SI = StackComponents.rbegin(); |
| 9152 | auto SE = StackComponents.rend(); |
| 9153 | for (; CI != CE && SI != SE; ++CI, ++SI) { |
| 9154 | |
| 9155 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.3] |
| 9156 | // At most one list item can be an array item derived from a given |
| 9157 | // variable in map clauses of the same construct. |
| 9158 | if (CurrentRegionOnly && (isa<ArraySubscriptExpr>(CI->first) || |
| 9159 | isa<OMPArraySectionExpr>(CI->first)) && |
| 9160 | (isa<ArraySubscriptExpr>(SI->first) || |
| 9161 | isa<OMPArraySectionExpr>(SI->first))) { |
| 9162 | SemaRef.Diag(CI->first->getExprLoc(), |
| 9163 | diag::err_omp_multiple_array_items_in_map_clause) |
| 9164 | << CI->first->getSourceRange(); |
| 9165 | ; |
| 9166 | SemaRef.Diag(SI->first->getExprLoc(), diag::note_used_here) |
| 9167 | << SI->first->getSourceRange(); |
| 9168 | return true; |
| 9169 | } |
| 9170 | |
| 9171 | // Do both expressions have the same kind? |
| 9172 | if (CI->first->getStmtClass() != SI->first->getStmtClass()) |
| 9173 | break; |
| 9174 | |
| 9175 | // Are we dealing with different variables/fields? |
| 9176 | if (CI->second != SI->second) |
| 9177 | break; |
| 9178 | } |
| 9179 | |
| 9180 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.4] |
| 9181 | // List items of map clauses in the same construct must not share |
| 9182 | // original storage. |
| 9183 | // |
| 9184 | // If the expressions are exactly the same or one is a subset of the |
| 9185 | // other, it means they are sharing storage. |
| 9186 | if (CI == CE && SI == SE) { |
| 9187 | if (CurrentRegionOnly) { |
| 9188 | SemaRef.Diag(ELoc, diag::err_omp_map_shared_storage) << ERange; |
| 9189 | SemaRef.Diag(RE->getExprLoc(), diag::note_used_here) |
| 9190 | << RE->getSourceRange(); |
| 9191 | return true; |
| 9192 | } else { |
| 9193 | // If we find the same expression in the enclosing data environment, |
| 9194 | // that is legal. |
| 9195 | IsEnclosedByDataEnvironmentExpr = true; |
| 9196 | return false; |
| 9197 | } |
| 9198 | } |
| 9199 | |
| 9200 | QualType DerivedType = std::prev(CI)->first->getType(); |
| 9201 | SourceLocation DerivedLoc = std::prev(CI)->first->getExprLoc(); |
| 9202 | |
| 9203 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] |
| 9204 | // If the type of a list item is a reference to a type T then the type |
| 9205 | // will be considered to be T for all purposes of this clause. |
| 9206 | if (DerivedType->isReferenceType()) |
| 9207 | DerivedType = DerivedType->getPointeeType(); |
| 9208 | |
| 9209 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C/C++, p.1] |
| 9210 | // A variable for which the type is pointer and an array section |
| 9211 | // derived from that variable must not appear as list items of map |
| 9212 | // clauses of the same construct. |
| 9213 | // |
| 9214 | // Also, cover one of the cases in: |
| 9215 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.5] |
| 9216 | // If any part of the original storage of a list item has corresponding |
| 9217 | // storage in the device data environment, all of the original storage |
| 9218 | // must have corresponding storage in the device data environment. |
| 9219 | // |
| 9220 | if (DerivedType->isAnyPointerType()) { |
| 9221 | if (CI == CE || SI == SE) { |
| 9222 | SemaRef.Diag( |
| 9223 | DerivedLoc, |
| 9224 | diag::err_omp_pointer_mapped_along_with_derived_section) |
| 9225 | << DerivedLoc; |
| 9226 | } else { |
| 9227 | assert(CI != CE && SI != SE); |
| 9228 | SemaRef.Diag(DerivedLoc, diag::err_omp_same_pointer_derreferenced) |
| 9229 | << DerivedLoc; |
| 9230 | } |
| 9231 | SemaRef.Diag(RE->getExprLoc(), diag::note_used_here) |
| 9232 | << RE->getSourceRange(); |
| 9233 | return true; |
| 9234 | } |
| 9235 | |
| 9236 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.4] |
| 9237 | // List items of map clauses in the same construct must not share |
| 9238 | // original storage. |
| 9239 | // |
| 9240 | // An expression is a subset of the other. |
| 9241 | if (CurrentRegionOnly && (CI == CE || SI == SE)) { |
| 9242 | SemaRef.Diag(ELoc, diag::err_omp_map_shared_storage) << ERange; |
| 9243 | SemaRef.Diag(RE->getExprLoc(), diag::note_used_here) |
| 9244 | << RE->getSourceRange(); |
| 9245 | return true; |
| 9246 | } |
| 9247 | |
| 9248 | // The current expression uses the same base as other expression in the |
| 9249 | // data environment but does not contain it completelly. |
| 9250 | if (!CurrentRegionOnly && SI != SE) |
| 9251 | EnclosingExpr = RE; |
| 9252 | |
| 9253 | // The current expression is a subset of the expression in the data |
| 9254 | // environment. |
| 9255 | IsEnclosedByDataEnvironmentExpr |= |
| 9256 | (!CurrentRegionOnly && CI != CE && SI == SE); |
| 9257 | |
| 9258 | return false; |
| 9259 | }); |
| 9260 | |
| 9261 | if (CurrentRegionOnly) |
| 9262 | return FoundError; |
| 9263 | |
| 9264 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.5] |
| 9265 | // If any part of the original storage of a list item has corresponding |
| 9266 | // storage in the device data environment, all of the original storage must |
| 9267 | // have corresponding storage in the device data environment. |
| 9268 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.6] |
| 9269 | // If a list item is an element of a structure, and a different element of |
| 9270 | // the structure has a corresponding list item in the device data environment |
| 9271 | // prior to a task encountering the construct associated with the map clause, |
| 9272 | // then the list item must also have a correspnding list item in the device |
| 9273 | // data environment prior to the task encountering the construct. |
| 9274 | // |
| 9275 | if (EnclosingExpr && !IsEnclosedByDataEnvironmentExpr) { |
| 9276 | SemaRef.Diag(ELoc, |
| 9277 | diag::err_omp_original_storage_is_shared_and_does_not_contain) |
| 9278 | << ERange; |
| 9279 | SemaRef.Diag(EnclosingExpr->getExprLoc(), diag::note_used_here) |
| 9280 | << EnclosingExpr->getSourceRange(); |
| 9281 | return true; |
| 9282 | } |
| 9283 | |
| 9284 | return FoundError; |
| 9285 | } |
| 9286 | |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 9287 | OMPClause * |
| 9288 | Sema::ActOnOpenMPMapClause(OpenMPMapClauseKind MapTypeModifier, |
| 9289 | OpenMPMapClauseKind MapType, bool IsMapTypeImplicit, |
| 9290 | SourceLocation MapLoc, SourceLocation ColonLoc, |
| 9291 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
| 9292 | SourceLocation LParenLoc, SourceLocation EndLoc) { |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9293 | SmallVector<Expr *, 4> Vars; |
| 9294 | |
| 9295 | for (auto &RE : VarList) { |
| 9296 | assert(RE && "Null expr in omp map"); |
| 9297 | if (isa<DependentScopeDeclRefExpr>(RE)) { |
| 9298 | // It will be analyzed later. |
| 9299 | Vars.push_back(RE); |
| 9300 | continue; |
| 9301 | } |
| 9302 | SourceLocation ELoc = RE->getExprLoc(); |
| 9303 | |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9304 | auto *VE = RE->IgnoreParenLValueCasts(); |
| 9305 | |
| 9306 | if (VE->isValueDependent() || VE->isTypeDependent() || |
| 9307 | VE->isInstantiationDependent() || |
| 9308 | VE->containsUnexpandedParameterPack()) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9309 | // We can only analyze this information once the missing information is |
| 9310 | // resolved. |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9311 | Vars.push_back(RE); |
| 9312 | continue; |
| 9313 | } |
| 9314 | |
| 9315 | auto *SimpleExpr = RE->IgnoreParenCasts(); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9316 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9317 | if (!RE->IgnoreParenImpCasts()->isLValue()) { |
| 9318 | Diag(ELoc, diag::err_omp_expected_named_var_member_or_array_expression) |
| 9319 | << RE->getSourceRange(); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9320 | continue; |
| 9321 | } |
| 9322 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9323 | // Obtain the array or member expression bases if required. |
| 9324 | auto *BE = CheckMapClauseExpressionBase(*this, SimpleExpr); |
| 9325 | if (!BE) |
| 9326 | continue; |
| 9327 | |
| 9328 | // If the base is a reference to a variable, we rely on that variable for |
| 9329 | // the following checks. If it is a 'this' expression we rely on the field. |
| 9330 | ValueDecl *D = nullptr; |
| 9331 | if (auto *DRE = dyn_cast<DeclRefExpr>(BE)) { |
| 9332 | D = DRE->getDecl(); |
| 9333 | } else { |
| 9334 | auto *ME = cast<MemberExpr>(BE); |
| 9335 | assert(isa<CXXThisExpr>(ME->getBase()) && "Unexpected expression!"); |
| 9336 | D = ME->getMemberDecl(); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9337 | } |
| 9338 | assert(D && "Null decl on map clause."); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9339 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9340 | auto *VD = dyn_cast<VarDecl>(D); |
| 9341 | auto *FD = dyn_cast<FieldDecl>(D); |
| 9342 | |
| 9343 | assert((VD || FD) && "Only variables or fields are expected here!"); |
NAKAMURA Takumi | 6dcb814 | 2016-01-23 01:38:20 +0000 | [diff] [blame] | 9344 | (void)FD; |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9345 | |
| 9346 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.10] |
| 9347 | // threadprivate variables cannot appear in a map clause. |
| 9348 | if (VD && DSAStack->isThreadPrivate(VD)) { |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9349 | auto DVar = DSAStack->getTopDSA(VD, false); |
| 9350 | Diag(ELoc, diag::err_omp_threadprivate_in_map); |
| 9351 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 9352 | continue; |
| 9353 | } |
| 9354 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9355 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.9] |
| 9356 | // A list item cannot appear in both a map clause and a data-sharing |
| 9357 | // attribute clause on the same construct. |
| 9358 | // |
| 9359 | // TODO: Implement this check - it cannot currently be tested because of |
| 9360 | // missing implementation of the other data sharing clauses in target |
| 9361 | // directives. |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9362 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9363 | // Check conflicts with other map clause expressions. We check the conflicts |
| 9364 | // with the current construct separately from the enclosing data |
| 9365 | // environment, because the restrictions are different. |
| 9366 | if (CheckMapConflicts(*this, DSAStack, D, SimpleExpr, |
| 9367 | /*CurrentRegionOnly=*/true)) |
| 9368 | break; |
| 9369 | if (CheckMapConflicts(*this, DSAStack, D, SimpleExpr, |
| 9370 | /*CurrentRegionOnly=*/false)) |
| 9371 | break; |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9372 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9373 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] |
| 9374 | // If the type of a list item is a reference to a type T then the type will |
| 9375 | // be considered to be T for all purposes of this clause. |
| 9376 | QualType Type = D->getType(); |
| 9377 | if (Type->isReferenceType()) |
| 9378 | Type = Type->getPointeeType(); |
| 9379 | |
| 9380 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.9] |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9381 | // A list item must have a mappable type. |
| 9382 | if (!CheckTypeMappable(VE->getExprLoc(), VE->getSourceRange(), *this, |
| 9383 | DSAStack, Type)) |
| 9384 | continue; |
| 9385 | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 9386 | // target enter data |
| 9387 | // OpenMP [2.10.2, Restrictions, p. 99] |
| 9388 | // A map-type must be specified in all map clauses and must be either |
| 9389 | // to or alloc. |
| 9390 | OpenMPDirectiveKind DKind = DSAStack->getCurrentDirective(); |
| 9391 | if (DKind == OMPD_target_enter_data && |
| 9392 | !(MapType == OMPC_MAP_to || MapType == OMPC_MAP_alloc)) { |
| 9393 | Diag(StartLoc, diag::err_omp_invalid_map_type_for_directive) |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 9394 | << (IsMapTypeImplicit ? 1 : 0) |
| 9395 | << getOpenMPSimpleClauseTypeName(OMPC_map, MapType) |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 9396 | << getOpenMPDirectiveName(DKind); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9397 | continue; |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 9398 | } |
| 9399 | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 9400 | // target exit_data |
| 9401 | // OpenMP [2.10.3, Restrictions, p. 102] |
| 9402 | // A map-type must be specified in all map clauses and must be either |
| 9403 | // from, release, or delete. |
| 9404 | DKind = DSAStack->getCurrentDirective(); |
| 9405 | if (DKind == OMPD_target_exit_data && |
| 9406 | !(MapType == OMPC_MAP_from || MapType == OMPC_MAP_release || |
| 9407 | MapType == OMPC_MAP_delete)) { |
| 9408 | Diag(StartLoc, diag::err_omp_invalid_map_type_for_directive) |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 9409 | << (IsMapTypeImplicit ? 1 : 0) |
| 9410 | << getOpenMPSimpleClauseTypeName(OMPC_map, MapType) |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 9411 | << getOpenMPDirectiveName(DKind); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9412 | continue; |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 9413 | } |
| 9414 | |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9415 | Vars.push_back(RE); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9416 | DSAStack->addExprToVarMapInfo(D, RE); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9417 | } |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9418 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9419 | // We need to produce a map clause even if we don't have variables so that |
| 9420 | // other diagnostics related with non-existing map clauses are accurate. |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9421 | return OMPMapClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 9422 | MapTypeModifier, MapType, IsMapTypeImplicit, |
| 9423 | MapLoc); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9424 | } |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 9425 | |
| 9426 | OMPClause *Sema::ActOnOpenMPNumTeamsClause(Expr *NumTeams, |
| 9427 | SourceLocation StartLoc, |
| 9428 | SourceLocation LParenLoc, |
| 9429 | SourceLocation EndLoc) { |
| 9430 | Expr *ValExpr = NumTeams; |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 9431 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 9432 | // OpenMP [teams Constrcut, Restrictions] |
| 9433 | // The num_teams expression must evaluate to a positive integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 9434 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_num_teams, |
| 9435 | /*StrictlyPositive=*/true)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 9436 | return nullptr; |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 9437 | |
| 9438 | return new (Context) OMPNumTeamsClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 9439 | } |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 9440 | |
| 9441 | OMPClause *Sema::ActOnOpenMPThreadLimitClause(Expr *ThreadLimit, |
| 9442 | SourceLocation StartLoc, |
| 9443 | SourceLocation LParenLoc, |
| 9444 | SourceLocation EndLoc) { |
| 9445 | Expr *ValExpr = ThreadLimit; |
| 9446 | |
| 9447 | // OpenMP [teams Constrcut, Restrictions] |
| 9448 | // The thread_limit expression must evaluate to a positive integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 9449 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_thread_limit, |
| 9450 | /*StrictlyPositive=*/true)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 9451 | return nullptr; |
| 9452 | |
| 9453 | return new (Context) OMPThreadLimitClause(ValExpr, StartLoc, LParenLoc, |
| 9454 | EndLoc); |
| 9455 | } |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 9456 | |
| 9457 | OMPClause *Sema::ActOnOpenMPPriorityClause(Expr *Priority, |
| 9458 | SourceLocation StartLoc, |
| 9459 | SourceLocation LParenLoc, |
| 9460 | SourceLocation EndLoc) { |
| 9461 | Expr *ValExpr = Priority; |
| 9462 | |
| 9463 | // OpenMP [2.9.1, task Constrcut] |
| 9464 | // The priority-value is a non-negative numerical scalar expression. |
| 9465 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_priority, |
| 9466 | /*StrictlyPositive=*/false)) |
| 9467 | return nullptr; |
| 9468 | |
| 9469 | return new (Context) OMPPriorityClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 9470 | } |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 9471 | |
| 9472 | OMPClause *Sema::ActOnOpenMPGrainsizeClause(Expr *Grainsize, |
| 9473 | SourceLocation StartLoc, |
| 9474 | SourceLocation LParenLoc, |
| 9475 | SourceLocation EndLoc) { |
| 9476 | Expr *ValExpr = Grainsize; |
| 9477 | |
| 9478 | // OpenMP [2.9.2, taskloop Constrcut] |
| 9479 | // The parameter of the grainsize clause must be a positive integer |
| 9480 | // expression. |
| 9481 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_grainsize, |
| 9482 | /*StrictlyPositive=*/true)) |
| 9483 | return nullptr; |
| 9484 | |
| 9485 | return new (Context) OMPGrainsizeClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 9486 | } |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 9487 | |
| 9488 | OMPClause *Sema::ActOnOpenMPNumTasksClause(Expr *NumTasks, |
| 9489 | SourceLocation StartLoc, |
| 9490 | SourceLocation LParenLoc, |
| 9491 | SourceLocation EndLoc) { |
| 9492 | Expr *ValExpr = NumTasks; |
| 9493 | |
| 9494 | // OpenMP [2.9.2, taskloop Constrcut] |
| 9495 | // The parameter of the num_tasks clause must be a positive integer |
| 9496 | // expression. |
| 9497 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_num_tasks, |
| 9498 | /*StrictlyPositive=*/true)) |
| 9499 | return nullptr; |
| 9500 | |
| 9501 | return new (Context) OMPNumTasksClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 9502 | } |
| 9503 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 9504 | OMPClause *Sema::ActOnOpenMPHintClause(Expr *Hint, SourceLocation StartLoc, |
| 9505 | SourceLocation LParenLoc, |
| 9506 | SourceLocation EndLoc) { |
| 9507 | // OpenMP [2.13.2, critical construct, Description] |
| 9508 | // ... where hint-expression is an integer constant expression that evaluates |
| 9509 | // to a valid lock hint. |
| 9510 | ExprResult HintExpr = VerifyPositiveIntegerConstantInClause(Hint, OMPC_hint); |
| 9511 | if (HintExpr.isInvalid()) |
| 9512 | return nullptr; |
| 9513 | return new (Context) |
| 9514 | OMPHintClause(HintExpr.get(), StartLoc, LParenLoc, EndLoc); |
| 9515 | } |
| 9516 | |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 9517 | OMPClause *Sema::ActOnOpenMPDistScheduleClause( |
| 9518 | OpenMPDistScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, |
| 9519 | SourceLocation LParenLoc, SourceLocation KindLoc, SourceLocation CommaLoc, |
| 9520 | SourceLocation EndLoc) { |
| 9521 | if (Kind == OMPC_DIST_SCHEDULE_unknown) { |
| 9522 | std::string Values; |
| 9523 | Values += "'"; |
| 9524 | Values += getOpenMPSimpleClauseTypeName(OMPC_dist_schedule, 0); |
| 9525 | Values += "'"; |
| 9526 | Diag(KindLoc, diag::err_omp_unexpected_clause_value) |
| 9527 | << Values << getOpenMPClauseName(OMPC_dist_schedule); |
| 9528 | return nullptr; |
| 9529 | } |
| 9530 | Expr *ValExpr = ChunkSize; |
| 9531 | Expr *HelperValExpr = nullptr; |
| 9532 | if (ChunkSize) { |
| 9533 | if (!ChunkSize->isValueDependent() && !ChunkSize->isTypeDependent() && |
| 9534 | !ChunkSize->isInstantiationDependent() && |
| 9535 | !ChunkSize->containsUnexpandedParameterPack()) { |
| 9536 | SourceLocation ChunkSizeLoc = ChunkSize->getLocStart(); |
| 9537 | ExprResult Val = |
| 9538 | PerformOpenMPImplicitIntegerConversion(ChunkSizeLoc, ChunkSize); |
| 9539 | if (Val.isInvalid()) |
| 9540 | return nullptr; |
| 9541 | |
| 9542 | ValExpr = Val.get(); |
| 9543 | |
| 9544 | // OpenMP [2.7.1, Restrictions] |
| 9545 | // chunk_size must be a loop invariant integer expression with a positive |
| 9546 | // value. |
| 9547 | llvm::APSInt Result; |
| 9548 | if (ValExpr->isIntegerConstantExpr(Result, Context)) { |
| 9549 | if (Result.isSigned() && !Result.isStrictlyPositive()) { |
| 9550 | Diag(ChunkSizeLoc, diag::err_omp_negative_expression_in_clause) |
| 9551 | << "dist_schedule" << ChunkSize->getSourceRange(); |
| 9552 | return nullptr; |
| 9553 | } |
| 9554 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective())) { |
| 9555 | auto *ImpVar = buildVarDecl(*this, ChunkSize->getExprLoc(), |
| 9556 | ChunkSize->getType(), ".chunk."); |
| 9557 | auto *ImpVarRef = buildDeclRefExpr(*this, ImpVar, ChunkSize->getType(), |
| 9558 | ChunkSize->getExprLoc(), |
| 9559 | /*RefersToCapture=*/true); |
| 9560 | HelperValExpr = ImpVarRef; |
| 9561 | } |
| 9562 | } |
| 9563 | } |
| 9564 | |
| 9565 | return new (Context) |
| 9566 | OMPDistScheduleClause(StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc, |
| 9567 | Kind, ValExpr, HelperValExpr); |
| 9568 | } |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 9569 | |
| 9570 | OMPClause *Sema::ActOnOpenMPDefaultmapClause( |
| 9571 | OpenMPDefaultmapClauseModifier M, OpenMPDefaultmapClauseKind Kind, |
| 9572 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation MLoc, |
| 9573 | SourceLocation KindLoc, SourceLocation EndLoc) { |
| 9574 | // OpenMP 4.5 only supports 'defaultmap(tofrom: scalar)' |
| 9575 | if (M != OMPC_DEFAULTMAP_MODIFIER_tofrom || |
| 9576 | Kind != OMPC_DEFAULTMAP_scalar) { |
| 9577 | std::string Value; |
| 9578 | SourceLocation Loc; |
| 9579 | Value += "'"; |
| 9580 | if (M != OMPC_DEFAULTMAP_MODIFIER_tofrom) { |
| 9581 | Value += getOpenMPSimpleClauseTypeName(OMPC_defaultmap, |
| 9582 | OMPC_DEFAULTMAP_MODIFIER_tofrom); |
| 9583 | Loc = MLoc; |
| 9584 | } else { |
| 9585 | Value += getOpenMPSimpleClauseTypeName(OMPC_defaultmap, |
| 9586 | OMPC_DEFAULTMAP_scalar); |
| 9587 | Loc = KindLoc; |
| 9588 | } |
| 9589 | Value += "'"; |
| 9590 | Diag(Loc, diag::err_omp_unexpected_clause_value) |
| 9591 | << Value << getOpenMPClauseName(OMPC_defaultmap); |
| 9592 | return nullptr; |
| 9593 | } |
| 9594 | |
| 9595 | return new (Context) |
| 9596 | OMPDefaultmapClause(StartLoc, LParenLoc, MLoc, KindLoc, EndLoc, Kind, M); |
| 9597 | } |