Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1 | //===--- SemaOpenMP.cpp - Semantic Analysis for OpenMP constructs ---------===// |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | /// \file |
| 10 | /// \brief This file implements semantic analysis for OpenMP directives and |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 11 | /// clauses. |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 12 | /// |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 15 | #include "TreeTransform.h" |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 16 | #include "clang/AST/ASTContext.h" |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 17 | #include "clang/AST/ASTMutationListener.h" |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 18 | #include "clang/AST/CXXInheritance.h" |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 19 | #include "clang/AST/Decl.h" |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 20 | #include "clang/AST/DeclCXX.h" |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 21 | #include "clang/AST/DeclOpenMP.h" |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 22 | #include "clang/AST/StmtCXX.h" |
| 23 | #include "clang/AST/StmtOpenMP.h" |
| 24 | #include "clang/AST/StmtVisitor.h" |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 25 | #include "clang/AST/TypeOrdering.h" |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 26 | #include "clang/Basic/OpenMPKinds.h" |
Samuel Antao | f8b5012 | 2015-07-13 22:54:53 +0000 | [diff] [blame] | 27 | #include "clang/Basic/TargetInfo.h" |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 28 | #include "clang/Lex/Preprocessor.h" |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 29 | #include "clang/Sema/Initialization.h" |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 30 | #include "clang/Sema/Lookup.h" |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 31 | #include "clang/Sema/Scope.h" |
| 32 | #include "clang/Sema/ScopeInfo.h" |
Chandler Carruth | 5553d0d | 2014-01-07 11:51:46 +0000 | [diff] [blame] | 33 | #include "clang/Sema/SemaInternal.h" |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 34 | using namespace clang; |
| 35 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 36 | //===----------------------------------------------------------------------===// |
| 37 | // Stack of data-sharing attributes for variables |
| 38 | //===----------------------------------------------------------------------===// |
| 39 | |
| 40 | namespace { |
| 41 | /// \brief Default data sharing attributes, which can be applied to directive. |
| 42 | enum DefaultDataSharingAttributes { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 43 | DSA_unspecified = 0, /// \brief Data sharing attribute not specified. |
| 44 | DSA_none = 1 << 0, /// \brief Default data sharing attribute 'none'. |
| 45 | DSA_shared = 1 << 1 /// \brief Default data sharing attribute 'shared'. |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 46 | }; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 47 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 48 | /// \brief Stack for tracking declarations used in OpenMP directives and |
| 49 | /// clauses and their data-sharing attributes. |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 50 | class DSAStackTy final { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 51 | public: |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 52 | struct DSAVarData final { |
| 53 | OpenMPDirectiveKind DKind = OMPD_unknown; |
| 54 | OpenMPClauseKind CKind = OMPC_unknown; |
| 55 | Expr *RefExpr = nullptr; |
| 56 | DeclRefExpr *PrivateCopy = nullptr; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 57 | SourceLocation ImplicitDSALoc; |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 58 | DSAVarData() {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 59 | }; |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 60 | typedef llvm::SmallVector<std::pair<Expr *, OverloadedOperatorKind>, 4> |
| 61 | OperatorOffsetTy; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 62 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 63 | private: |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 64 | struct DSAInfo final { |
| 65 | OpenMPClauseKind Attributes = OMPC_unknown; |
| 66 | /// Pointer to a reference expression and a flag which shows that the |
| 67 | /// variable is marked as lastprivate(true) or not (false). |
| 68 | llvm::PointerIntPair<Expr *, 1, bool> RefExpr; |
| 69 | DeclRefExpr *PrivateCopy = nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 70 | }; |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 71 | typedef llvm::DenseMap<ValueDecl *, DSAInfo> DeclSAMapTy; |
| 72 | typedef llvm::DenseMap<ValueDecl *, Expr *> AlignedMapTy; |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 73 | typedef std::pair<unsigned, VarDecl *> LCDeclInfo; |
| 74 | typedef llvm::DenseMap<ValueDecl *, LCDeclInfo> LoopControlVariablesMapTy; |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 75 | typedef llvm::DenseMap< |
| 76 | ValueDecl *, OMPClauseMappableExprCommon::MappableExprComponentLists> |
| 77 | MappedExprComponentsTy; |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 78 | typedef llvm::StringMap<std::pair<OMPCriticalDirective *, llvm::APSInt>> |
| 79 | CriticalsWithHintsTy; |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 80 | typedef llvm::DenseMap<OMPDependClause *, OperatorOffsetTy> |
| 81 | DoacrossDependMapTy; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 82 | |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 83 | struct SharingMapTy final { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 84 | DeclSAMapTy SharingMap; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 85 | AlignedMapTy AlignedMap; |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 86 | MappedExprComponentsTy MappedExprComponents; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 87 | LoopControlVariablesMapTy LCVMap; |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 88 | DefaultDataSharingAttributes DefaultAttr = DSA_unspecified; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 89 | SourceLocation DefaultAttrLoc; |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 90 | OpenMPDirectiveKind Directive = OMPD_unknown; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 91 | DeclarationNameInfo DirectiveName; |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 92 | Scope *CurScope = nullptr; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 93 | SourceLocation ConstructLoc; |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 94 | /// Set of 'depend' clauses with 'sink|source' dependence kind. Required to |
| 95 | /// get the data (loop counters etc.) about enclosing loop-based construct. |
| 96 | /// This data is required during codegen. |
| 97 | DoacrossDependMapTy DoacrossDepends; |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 98 | /// \brief first argument (Expr *) contains optional argument of the |
| 99 | /// 'ordered' clause, the second one is true if the regions has 'ordered' |
| 100 | /// clause, false otherwise. |
| 101 | llvm::PointerIntPair<Expr *, 1, bool> OrderedRegion; |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 102 | bool NowaitRegion = false; |
| 103 | bool CancelRegion = false; |
| 104 | unsigned AssociatedLoops = 1; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 105 | SourceLocation InnerTeamsRegionLoc; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 106 | SharingMapTy(OpenMPDirectiveKind DKind, DeclarationNameInfo Name, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 107 | Scope *CurScope, SourceLocation Loc) |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 108 | : Directive(DKind), DirectiveName(Name), CurScope(CurScope), |
| 109 | ConstructLoc(Loc) {} |
| 110 | SharingMapTy() {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 111 | }; |
| 112 | |
Axel Naumann | 323862e | 2016-02-03 10:45:22 +0000 | [diff] [blame] | 113 | typedef SmallVector<SharingMapTy, 4> StackTy; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 114 | |
| 115 | /// \brief Stack of used declaration and their data-sharing attributes. |
| 116 | StackTy Stack; |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 117 | /// \brief true, if check for DSA must be from parent directive, false, if |
| 118 | /// from current directive. |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 119 | OpenMPClauseKind ClauseKindMode = OMPC_unknown; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 120 | Sema &SemaRef; |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 121 | bool ForceCapturing = false; |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 122 | CriticalsWithHintsTy Criticals; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 123 | |
| 124 | typedef SmallVector<SharingMapTy, 8>::reverse_iterator reverse_iterator; |
| 125 | |
Dmitry Polukhin | dc78bc82 | 2016-04-01 09:52:30 +0000 | [diff] [blame] | 126 | DSAVarData getDSA(StackTy::reverse_iterator& Iter, ValueDecl *D); |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 127 | |
| 128 | /// \brief Checks if the variable is a local for OpenMP region. |
| 129 | bool isOpenMPLocal(VarDecl *D, StackTy::reverse_iterator Iter); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 130 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 131 | public: |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 132 | explicit DSAStackTy(Sema &S) : Stack(1), SemaRef(S) {} |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 133 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 134 | bool isClauseParsingMode() const { return ClauseKindMode != OMPC_unknown; } |
| 135 | void setClauseParsingMode(OpenMPClauseKind K) { ClauseKindMode = K; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 136 | |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 137 | bool isForceVarCapturing() const { return ForceCapturing; } |
| 138 | void setForceVarCapturing(bool V) { ForceCapturing = V; } |
| 139 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 140 | void push(OpenMPDirectiveKind DKind, const DeclarationNameInfo &DirName, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 141 | Scope *CurScope, SourceLocation Loc) { |
| 142 | Stack.push_back(SharingMapTy(DKind, DirName, CurScope, Loc)); |
| 143 | Stack.back().DefaultAttrLoc = Loc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | void pop() { |
| 147 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty!"); |
| 148 | Stack.pop_back(); |
| 149 | } |
| 150 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 151 | void addCriticalWithHint(OMPCriticalDirective *D, llvm::APSInt Hint) { |
| 152 | Criticals[D->getDirectiveName().getAsString()] = std::make_pair(D, Hint); |
| 153 | } |
| 154 | const std::pair<OMPCriticalDirective *, llvm::APSInt> |
| 155 | getCriticalWithHint(const DeclarationNameInfo &Name) const { |
| 156 | auto I = Criticals.find(Name.getAsString()); |
| 157 | if (I != Criticals.end()) |
| 158 | return I->second; |
| 159 | return std::make_pair(nullptr, llvm::APSInt()); |
| 160 | } |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 161 | /// \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] | 162 | /// add it and return NULL; otherwise return previous occurrence's expression |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 163 | /// for diagnostics. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 164 | Expr *addUniqueAligned(ValueDecl *D, Expr *NewDE); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 165 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 166 | /// \brief Register specified variable as loop control variable. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 167 | void addLoopControlVariable(ValueDecl *D, VarDecl *Capture); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 168 | /// \brief Check if the specified variable is a loop control variable for |
| 169 | /// current region. |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 170 | /// \return The index of the loop control variable in the list of associated |
| 171 | /// for-loops (from outer to inner). |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 172 | LCDeclInfo isLoopControlVariable(ValueDecl *D); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 173 | /// \brief Check if the specified variable is a loop control variable for |
| 174 | /// parent region. |
| 175 | /// \return The index of the loop control variable in the list of associated |
| 176 | /// for-loops (from outer to inner). |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 177 | LCDeclInfo isParentLoopControlVariable(ValueDecl *D); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 178 | /// \brief Get the loop control variable for the I-th loop (or nullptr) in |
| 179 | /// parent directive. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 180 | ValueDecl *getParentLoopControlVariable(unsigned I); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 181 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 182 | /// \brief Adds explicit data sharing attribute to the specified declaration. |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 183 | void addDSA(ValueDecl *D, Expr *E, OpenMPClauseKind A, |
| 184 | DeclRefExpr *PrivateCopy = nullptr); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 185 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 186 | /// \brief Returns data sharing attributes from top of the stack for the |
| 187 | /// specified declaration. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 188 | DSAVarData getTopDSA(ValueDecl *D, bool FromParent); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 189 | /// \brief Returns data-sharing attributes for the specified declaration. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 190 | DSAVarData getImplicitDSA(ValueDecl *D, bool FromParent); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 191 | /// \brief Checks if the specified variables has data-sharing attributes which |
| 192 | /// match specified \a CPred predicate in any directive which matches \a DPred |
| 193 | /// predicate. |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 194 | DSAVarData hasDSA(ValueDecl *D, |
| 195 | const llvm::function_ref<bool(OpenMPClauseKind)> &CPred, |
| 196 | const llvm::function_ref<bool(OpenMPDirectiveKind)> &DPred, |
| 197 | bool FromParent); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 198 | /// \brief Checks if the specified variables has data-sharing attributes which |
| 199 | /// match specified \a CPred predicate in any innermost directive which |
| 200 | /// matches \a DPred predicate. |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 201 | DSAVarData |
| 202 | hasInnermostDSA(ValueDecl *D, |
| 203 | const llvm::function_ref<bool(OpenMPClauseKind)> &CPred, |
| 204 | const llvm::function_ref<bool(OpenMPDirectiveKind)> &DPred, |
| 205 | bool FromParent); |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 206 | /// \brief Checks if the specified variables has explicit data-sharing |
| 207 | /// attributes which match specified \a CPred predicate at the specified |
| 208 | /// OpenMP region. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 209 | bool hasExplicitDSA(ValueDecl *D, |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 210 | const llvm::function_ref<bool(OpenMPClauseKind)> &CPred, |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 211 | unsigned Level, bool NotLastprivate = false); |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 212 | |
| 213 | /// \brief Returns true if the directive at level \Level matches in the |
| 214 | /// specified \a DPred predicate. |
| 215 | bool hasExplicitDirective( |
| 216 | const llvm::function_ref<bool(OpenMPDirectiveKind)> &DPred, |
| 217 | unsigned Level); |
| 218 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 219 | /// \brief Finds a directive which matches specified \a DPred predicate. |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 220 | bool hasDirective(const llvm::function_ref<bool(OpenMPDirectiveKind, |
| 221 | const DeclarationNameInfo &, |
| 222 | SourceLocation)> &DPred, |
| 223 | bool FromParent); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 224 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 225 | /// \brief Returns currently analyzed directive. |
| 226 | OpenMPDirectiveKind getCurrentDirective() const { |
| 227 | return Stack.back().Directive; |
| 228 | } |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 229 | /// \brief Returns parent directive. |
| 230 | OpenMPDirectiveKind getParentDirective() const { |
| 231 | if (Stack.size() > 2) |
| 232 | return Stack[Stack.size() - 2].Directive; |
| 233 | return OMPD_unknown; |
| 234 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 235 | |
| 236 | /// \brief Set default data sharing attribute to none. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 237 | void setDefaultDSANone(SourceLocation Loc) { |
| 238 | Stack.back().DefaultAttr = DSA_none; |
| 239 | Stack.back().DefaultAttrLoc = Loc; |
| 240 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 241 | /// \brief Set default data sharing attribute to shared. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 242 | void setDefaultDSAShared(SourceLocation Loc) { |
| 243 | Stack.back().DefaultAttr = DSA_shared; |
| 244 | Stack.back().DefaultAttrLoc = Loc; |
| 245 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 246 | |
| 247 | DefaultDataSharingAttributes getDefaultDSA() const { |
| 248 | return Stack.back().DefaultAttr; |
| 249 | } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 250 | SourceLocation getDefaultDSALocation() const { |
| 251 | return Stack.back().DefaultAttrLoc; |
| 252 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 253 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 254 | /// \brief Checks if the specified variable is a threadprivate. |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 255 | bool isThreadPrivate(VarDecl *D) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 256 | DSAVarData DVar = getTopDSA(D, false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 257 | return isOpenMPThreadPrivate(DVar.CKind); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 258 | } |
| 259 | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 260 | /// \brief Marks current region as ordered (it has an 'ordered' clause). |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 261 | void setOrderedRegion(bool IsOrdered, Expr *Param) { |
| 262 | Stack.back().OrderedRegion.setInt(IsOrdered); |
| 263 | Stack.back().OrderedRegion.setPointer(Param); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 264 | } |
| 265 | /// \brief Returns true, if parent region is ordered (has associated |
| 266 | /// 'ordered' clause), false - otherwise. |
| 267 | bool isParentOrderedRegion() const { |
| 268 | if (Stack.size() > 2) |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 269 | return Stack[Stack.size() - 2].OrderedRegion.getInt(); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 270 | return false; |
| 271 | } |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 272 | /// \brief Returns optional parameter for the ordered region. |
| 273 | Expr *getParentOrderedRegionParam() const { |
| 274 | if (Stack.size() > 2) |
| 275 | return Stack[Stack.size() - 2].OrderedRegion.getPointer(); |
| 276 | return nullptr; |
| 277 | } |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 278 | /// \brief Marks current region as nowait (it has a 'nowait' clause). |
| 279 | void setNowaitRegion(bool IsNowait = true) { |
| 280 | Stack.back().NowaitRegion = IsNowait; |
| 281 | } |
| 282 | /// \brief Returns true, if parent region is nowait (has associated |
| 283 | /// 'nowait' clause), false - otherwise. |
| 284 | bool isParentNowaitRegion() const { |
| 285 | if (Stack.size() > 2) |
| 286 | return Stack[Stack.size() - 2].NowaitRegion; |
| 287 | return false; |
| 288 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 289 | /// \brief Marks parent region as cancel region. |
| 290 | void setParentCancelRegion(bool Cancel = true) { |
| 291 | if (Stack.size() > 2) |
| 292 | Stack[Stack.size() - 2].CancelRegion = |
| 293 | Stack[Stack.size() - 2].CancelRegion || Cancel; |
| 294 | } |
| 295 | /// \brief Return true if current region has inner cancel construct. |
| 296 | bool isCancelRegion() const { |
| 297 | return Stack.back().CancelRegion; |
| 298 | } |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 299 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 300 | /// \brief Set collapse value for the region. |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 301 | void setAssociatedLoops(unsigned Val) { Stack.back().AssociatedLoops = Val; } |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 302 | /// \brief Return collapse value for region. |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 303 | unsigned getAssociatedLoops() const { return Stack.back().AssociatedLoops; } |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 304 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 305 | /// \brief Marks current target region as one with closely nested teams |
| 306 | /// region. |
| 307 | void setParentTeamsRegionLoc(SourceLocation TeamsRegionLoc) { |
| 308 | if (Stack.size() > 2) |
| 309 | Stack[Stack.size() - 2].InnerTeamsRegionLoc = TeamsRegionLoc; |
| 310 | } |
| 311 | /// \brief Returns true, if current region has closely nested teams region. |
| 312 | bool hasInnerTeamsRegion() const { |
| 313 | return getInnerTeamsRegionLoc().isValid(); |
| 314 | } |
| 315 | /// \brief Returns location of the nested teams region (if any). |
| 316 | SourceLocation getInnerTeamsRegionLoc() const { |
| 317 | if (Stack.size() > 1) |
| 318 | return Stack.back().InnerTeamsRegionLoc; |
| 319 | return SourceLocation(); |
| 320 | } |
| 321 | |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 322 | Scope *getCurScope() const { return Stack.back().CurScope; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 323 | Scope *getCurScope() { return Stack.back().CurScope; } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 324 | SourceLocation getConstructLoc() { return Stack.back().ConstructLoc; } |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 325 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 326 | // Do the check specified in \a Check to all component lists and return true |
| 327 | // if any issue is found. |
| 328 | bool checkMappableExprComponentListsForDecl( |
| 329 | ValueDecl *VD, bool CurrentRegionOnly, |
| 330 | const llvm::function_ref<bool( |
| 331 | OMPClauseMappableExprCommon::MappableExprComponentListRef)> &Check) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 332 | auto SI = Stack.rbegin(); |
| 333 | auto SE = Stack.rend(); |
| 334 | |
| 335 | if (SI == SE) |
| 336 | return false; |
| 337 | |
| 338 | if (CurrentRegionOnly) { |
| 339 | SE = std::next(SI); |
| 340 | } else { |
| 341 | ++SI; |
| 342 | } |
| 343 | |
| 344 | for (; SI != SE; ++SI) { |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 345 | auto MI = SI->MappedExprComponents.find(VD); |
| 346 | if (MI != SI->MappedExprComponents.end()) |
| 347 | for (auto &L : MI->second) |
| 348 | if (Check(L)) |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 349 | return true; |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 350 | } |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 351 | return false; |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 352 | } |
| 353 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 354 | // Create a new mappable expression component list associated with a given |
| 355 | // declaration and initialize it with the provided list of components. |
| 356 | void addMappableExpressionComponents( |
| 357 | ValueDecl *VD, |
| 358 | OMPClauseMappableExprCommon::MappableExprComponentListRef Components) { |
| 359 | assert(Stack.size() > 1 && |
| 360 | "Not expecting to retrieve components from a empty stack!"); |
| 361 | auto &MEC = Stack.back().MappedExprComponents[VD]; |
| 362 | // Create new entry and append the new components there. |
| 363 | MEC.resize(MEC.size() + 1); |
| 364 | MEC.back().append(Components.begin(), Components.end()); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 365 | } |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 366 | |
| 367 | unsigned getNestingLevel() const { |
| 368 | assert(Stack.size() > 1); |
| 369 | return Stack.size() - 2; |
| 370 | } |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 371 | void addDoacrossDependClause(OMPDependClause *C, OperatorOffsetTy &OpsOffs) { |
| 372 | assert(Stack.size() > 2); |
| 373 | assert(isOpenMPWorksharingDirective(Stack[Stack.size() - 2].Directive)); |
| 374 | Stack[Stack.size() - 2].DoacrossDepends.insert({C, OpsOffs}); |
| 375 | } |
| 376 | llvm::iterator_range<DoacrossDependMapTy::const_iterator> |
| 377 | getDoacrossDependClauses() const { |
| 378 | assert(Stack.size() > 1); |
| 379 | if (isOpenMPWorksharingDirective(Stack[Stack.size() - 1].Directive)) { |
| 380 | auto &Ref = Stack[Stack.size() - 1].DoacrossDepends; |
| 381 | return llvm::make_range(Ref.begin(), Ref.end()); |
| 382 | } |
| 383 | return llvm::make_range(Stack[0].DoacrossDepends.end(), |
| 384 | Stack[0].DoacrossDepends.end()); |
| 385 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 386 | }; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 387 | bool isParallelOrTaskRegion(OpenMPDirectiveKind DKind) { |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 388 | return isOpenMPParallelDirective(DKind) || isOpenMPTaskingDirective(DKind) || |
| 389 | isOpenMPTeamsDirective(DKind) || DKind == OMPD_unknown; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 390 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 391 | } // namespace |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 392 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 393 | static ValueDecl *getCanonicalDecl(ValueDecl *D) { |
| 394 | auto *VD = dyn_cast<VarDecl>(D); |
| 395 | auto *FD = dyn_cast<FieldDecl>(D); |
| 396 | if (VD != nullptr) { |
| 397 | VD = VD->getCanonicalDecl(); |
| 398 | D = VD; |
| 399 | } else { |
| 400 | assert(FD); |
| 401 | FD = FD->getCanonicalDecl(); |
| 402 | D = FD; |
| 403 | } |
| 404 | return D; |
| 405 | } |
| 406 | |
Dmitry Polukhin | dc78bc82 | 2016-04-01 09:52:30 +0000 | [diff] [blame] | 407 | DSAStackTy::DSAVarData DSAStackTy::getDSA(StackTy::reverse_iterator& Iter, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 408 | ValueDecl *D) { |
| 409 | D = getCanonicalDecl(D); |
| 410 | auto *VD = dyn_cast<VarDecl>(D); |
| 411 | auto *FD = dyn_cast<FieldDecl>(D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 412 | DSAVarData DVar; |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 413 | if (Iter == std::prev(Stack.rend())) { |
Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 414 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 415 | // in a region but not in construct] |
| 416 | // File-scope or namespace-scope variables referenced in called routines |
| 417 | // in the region are shared unless they appear in a threadprivate |
| 418 | // directive. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 419 | if (VD && !VD->isFunctionOrMethodVarDecl() && !isa<ParmVarDecl>(D)) |
Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 420 | DVar.CKind = OMPC_shared; |
| 421 | |
| 422 | // OpenMP [2.9.1.2, Data-sharing Attribute Rules for Variables Referenced |
| 423 | // in a region but not in construct] |
| 424 | // Variables with static storage duration that are declared in called |
| 425 | // routines in the region are shared. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 426 | if (VD && VD->hasGlobalStorage()) |
| 427 | DVar.CKind = OMPC_shared; |
| 428 | |
| 429 | // Non-static data members are shared by default. |
| 430 | if (FD) |
Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 431 | DVar.CKind = OMPC_shared; |
| 432 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 433 | return DVar; |
| 434 | } |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 435 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 436 | DVar.DKind = Iter->Directive; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 437 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 438 | // in a Construct, C/C++, predetermined, p.1] |
| 439 | // Variables with automatic storage duration that are declared in a scope |
| 440 | // inside the construct are private. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 441 | if (VD && isOpenMPLocal(VD, Iter) && VD->isLocalVarDecl() && |
| 442 | (VD->getStorageClass() == SC_Auto || VD->getStorageClass() == SC_None)) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 443 | DVar.CKind = OMPC_private; |
| 444 | return DVar; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 445 | } |
| 446 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 447 | // Explicitly specified attributes and local variables with predetermined |
| 448 | // attributes. |
| 449 | if (Iter->SharingMap.count(D)) { |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 450 | DVar.RefExpr = Iter->SharingMap[D].RefExpr.getPointer(); |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 451 | DVar.PrivateCopy = Iter->SharingMap[D].PrivateCopy; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 452 | DVar.CKind = Iter->SharingMap[D].Attributes; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 453 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 454 | return DVar; |
| 455 | } |
| 456 | |
| 457 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 458 | // in a Construct, C/C++, implicitly determined, p.1] |
| 459 | // In a parallel or task construct, the data-sharing attributes of these |
| 460 | // variables are determined by the default clause, if present. |
| 461 | switch (Iter->DefaultAttr) { |
| 462 | case DSA_shared: |
| 463 | DVar.CKind = OMPC_shared; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 464 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 465 | return DVar; |
| 466 | case DSA_none: |
| 467 | return DVar; |
| 468 | case DSA_unspecified: |
| 469 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 470 | // in a Construct, implicitly determined, p.2] |
| 471 | // In a parallel construct, if no default clause is present, these |
| 472 | // variables are shared. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 473 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 474 | if (isOpenMPParallelDirective(DVar.DKind) || |
| 475 | isOpenMPTeamsDirective(DVar.DKind)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 476 | DVar.CKind = OMPC_shared; |
| 477 | return DVar; |
| 478 | } |
| 479 | |
| 480 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 481 | // in a Construct, implicitly determined, p.4] |
| 482 | // In a task construct, if no default clause is present, a variable that in |
| 483 | // the enclosing context is determined to be shared by all implicit tasks |
| 484 | // bound to the current team is shared. |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 485 | if (isOpenMPTaskingDirective(DVar.DKind)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 486 | DSAVarData DVarTemp; |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 487 | for (StackTy::reverse_iterator I = std::next(Iter), EE = Stack.rend(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 488 | I != EE; ++I) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 489 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 490 | // Referenced in a Construct, implicitly determined, p.6] |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 491 | // In a task construct, if no default clause is present, a variable |
| 492 | // whose data-sharing attribute is not determined by the rules above is |
| 493 | // firstprivate. |
| 494 | DVarTemp = getDSA(I, D); |
| 495 | if (DVarTemp.CKind != OMPC_shared) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 496 | DVar.RefExpr = nullptr; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 497 | DVar.CKind = OMPC_firstprivate; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 498 | return DVar; |
| 499 | } |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 500 | if (isParallelOrTaskRegion(I->Directive)) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 501 | break; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 502 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 503 | DVar.CKind = |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 504 | (DVarTemp.CKind == OMPC_unknown) ? OMPC_firstprivate : OMPC_shared; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 505 | return DVar; |
| 506 | } |
| 507 | } |
| 508 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 509 | // in a Construct, implicitly determined, p.3] |
| 510 | // For constructs other than task, if no default clause is present, these |
| 511 | // variables inherit their data-sharing attributes from the enclosing |
| 512 | // context. |
Dmitry Polukhin | dc78bc82 | 2016-04-01 09:52:30 +0000 | [diff] [blame] | 513 | return getDSA(++Iter, D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 514 | } |
| 515 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 516 | Expr *DSAStackTy::addUniqueAligned(ValueDecl *D, Expr *NewDE) { |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 517 | assert(Stack.size() > 1 && "Data sharing attributes stack is empty"); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 518 | D = getCanonicalDecl(D); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 519 | auto It = Stack.back().AlignedMap.find(D); |
| 520 | if (It == Stack.back().AlignedMap.end()) { |
| 521 | assert(NewDE && "Unexpected nullptr expr to be added into aligned map"); |
| 522 | Stack.back().AlignedMap[D] = NewDE; |
| 523 | return nullptr; |
| 524 | } else { |
| 525 | assert(It->second && "Unexpected nullptr expr in the aligned map"); |
| 526 | return It->second; |
| 527 | } |
| 528 | return nullptr; |
| 529 | } |
| 530 | |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 531 | void DSAStackTy::addLoopControlVariable(ValueDecl *D, VarDecl *Capture) { |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 532 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 533 | D = getCanonicalDecl(D); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 534 | Stack.back().LCVMap.insert( |
| 535 | std::make_pair(D, LCDeclInfo(Stack.back().LCVMap.size() + 1, Capture))); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 536 | } |
| 537 | |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 538 | DSAStackTy::LCDeclInfo DSAStackTy::isLoopControlVariable(ValueDecl *D) { |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 539 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 540 | D = getCanonicalDecl(D); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 541 | return Stack.back().LCVMap.count(D) > 0 ? Stack.back().LCVMap[D] |
| 542 | : LCDeclInfo(0, nullptr); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 543 | } |
| 544 | |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 545 | DSAStackTy::LCDeclInfo DSAStackTy::isParentLoopControlVariable(ValueDecl *D) { |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 546 | assert(Stack.size() > 2 && "Data-sharing attributes stack is empty"); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 547 | D = getCanonicalDecl(D); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 548 | return Stack[Stack.size() - 2].LCVMap.count(D) > 0 |
| 549 | ? Stack[Stack.size() - 2].LCVMap[D] |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 550 | : LCDeclInfo(0, nullptr); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 551 | } |
| 552 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 553 | ValueDecl *DSAStackTy::getParentLoopControlVariable(unsigned I) { |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 554 | assert(Stack.size() > 2 && "Data-sharing attributes stack is empty"); |
| 555 | if (Stack[Stack.size() - 2].LCVMap.size() < I) |
| 556 | return nullptr; |
| 557 | for (auto &Pair : Stack[Stack.size() - 2].LCVMap) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 558 | if (Pair.second.first == I) |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 559 | return Pair.first; |
| 560 | } |
| 561 | return nullptr; |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 562 | } |
| 563 | |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 564 | void DSAStackTy::addDSA(ValueDecl *D, Expr *E, OpenMPClauseKind A, |
| 565 | DeclRefExpr *PrivateCopy) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 566 | D = getCanonicalDecl(D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 567 | if (A == OMPC_threadprivate) { |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 568 | auto &Data = Stack[0].SharingMap[D]; |
| 569 | Data.Attributes = A; |
| 570 | Data.RefExpr.setPointer(E); |
| 571 | Data.PrivateCopy = nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 572 | } else { |
| 573 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 574 | auto &Data = Stack.back().SharingMap[D]; |
| 575 | assert(Data.Attributes == OMPC_unknown || (A == Data.Attributes) || |
| 576 | (A == OMPC_firstprivate && Data.Attributes == OMPC_lastprivate) || |
| 577 | (A == OMPC_lastprivate && Data.Attributes == OMPC_firstprivate) || |
| 578 | (isLoopControlVariable(D).first && A == OMPC_private)); |
| 579 | if (A == OMPC_lastprivate && Data.Attributes == OMPC_firstprivate) { |
| 580 | Data.RefExpr.setInt(/*IntVal=*/true); |
| 581 | return; |
| 582 | } |
| 583 | const bool IsLastprivate = |
| 584 | A == OMPC_lastprivate || Data.Attributes == OMPC_lastprivate; |
| 585 | Data.Attributes = A; |
| 586 | Data.RefExpr.setPointerAndInt(E, IsLastprivate); |
| 587 | Data.PrivateCopy = PrivateCopy; |
| 588 | if (PrivateCopy) { |
| 589 | auto &Data = Stack.back().SharingMap[PrivateCopy->getDecl()]; |
| 590 | Data.Attributes = A; |
| 591 | Data.RefExpr.setPointerAndInt(PrivateCopy, IsLastprivate); |
| 592 | Data.PrivateCopy = nullptr; |
| 593 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 594 | } |
| 595 | } |
| 596 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 597 | bool DSAStackTy::isOpenMPLocal(VarDecl *D, StackTy::reverse_iterator Iter) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 598 | D = D->getCanonicalDecl(); |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 599 | if (Stack.size() > 2) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 600 | reverse_iterator I = Iter, E = std::prev(Stack.rend()); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 601 | Scope *TopScope = nullptr; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 602 | while (I != E && !isParallelOrTaskRegion(I->Directive)) { |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 603 | ++I; |
| 604 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 605 | if (I == E) |
| 606 | return false; |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 607 | TopScope = I->CurScope ? I->CurScope->getParent() : nullptr; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 608 | Scope *CurScope = getCurScope(); |
| 609 | while (CurScope != TopScope && !CurScope->isDeclScope(D)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 610 | CurScope = CurScope->getParent(); |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 611 | } |
| 612 | return CurScope != TopScope; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 613 | } |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 614 | return false; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 615 | } |
| 616 | |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 617 | /// \brief Build a variable declaration for OpenMP loop iteration variable. |
| 618 | static VarDecl *buildVarDecl(Sema &SemaRef, SourceLocation Loc, QualType Type, |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 619 | StringRef Name, const AttrVec *Attrs = nullptr) { |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 620 | DeclContext *DC = SemaRef.CurContext; |
| 621 | IdentifierInfo *II = &SemaRef.PP.getIdentifierTable().get(Name); |
| 622 | TypeSourceInfo *TInfo = SemaRef.Context.getTrivialTypeSourceInfo(Type, Loc); |
| 623 | VarDecl *Decl = |
| 624 | VarDecl::Create(SemaRef.Context, DC, Loc, Loc, II, Type, TInfo, SC_None); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 625 | if (Attrs) { |
| 626 | for (specific_attr_iterator<AlignedAttr> I(Attrs->begin()), E(Attrs->end()); |
| 627 | I != E; ++I) |
| 628 | Decl->addAttr(*I); |
| 629 | } |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 630 | Decl->setImplicit(); |
| 631 | return Decl; |
| 632 | } |
| 633 | |
| 634 | static DeclRefExpr *buildDeclRefExpr(Sema &S, VarDecl *D, QualType Ty, |
| 635 | SourceLocation Loc, |
| 636 | bool RefersToCapture = false) { |
| 637 | D->setReferenced(); |
| 638 | D->markUsed(S.Context); |
| 639 | return DeclRefExpr::Create(S.getASTContext(), NestedNameSpecifierLoc(), |
| 640 | SourceLocation(), D, RefersToCapture, Loc, Ty, |
| 641 | VK_LValue); |
| 642 | } |
| 643 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 644 | DSAStackTy::DSAVarData DSAStackTy::getTopDSA(ValueDecl *D, bool FromParent) { |
| 645 | D = getCanonicalDecl(D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 646 | DSAVarData DVar; |
| 647 | |
| 648 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 649 | // in a Construct, C/C++, predetermined, p.1] |
| 650 | // Variables appearing in threadprivate directives are threadprivate. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 651 | auto *VD = dyn_cast<VarDecl>(D); |
| 652 | if ((VD && VD->getTLSKind() != VarDecl::TLS_None && |
| 653 | !(VD->hasAttr<OMPThreadPrivateDeclAttr>() && |
Samuel Antao | f8b5012 | 2015-07-13 22:54:53 +0000 | [diff] [blame] | 654 | SemaRef.getLangOpts().OpenMPUseTLS && |
| 655 | SemaRef.getASTContext().getTargetInfo().isTLSSupported())) || |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 656 | (VD && VD->getStorageClass() == SC_Register && |
| 657 | VD->hasAttr<AsmLabelAttr>() && !VD->isLocalVarDecl())) { |
| 658 | addDSA(D, buildDeclRefExpr(SemaRef, VD, D->getType().getNonReferenceType(), |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 659 | D->getLocation()), |
Alexey Bataev | f2453a0 | 2015-05-06 07:25:08 +0000 | [diff] [blame] | 660 | OMPC_threadprivate); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 661 | } |
| 662 | if (Stack[0].SharingMap.count(D)) { |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 663 | DVar.RefExpr = Stack[0].SharingMap[D].RefExpr.getPointer(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 664 | DVar.CKind = OMPC_threadprivate; |
| 665 | return DVar; |
| 666 | } |
| 667 | |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 668 | if (Stack.size() == 1) { |
| 669 | // Not in OpenMP execution region and top scope was already checked. |
| 670 | return DVar; |
| 671 | } |
| 672 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 673 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
Alexey Bataev | dffa93a | 2015-12-10 08:20:58 +0000 | [diff] [blame] | 674 | // in a Construct, C/C++, predetermined, p.4] |
| 675 | // Static data members are shared. |
| 676 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 677 | // in a Construct, C/C++, predetermined, p.7] |
| 678 | // Variables with static storage duration that are declared in a scope |
| 679 | // inside the construct are shared. |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 680 | auto &&MatchesAlways = [](OpenMPDirectiveKind) -> bool { return true; }; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 681 | if (VD && VD->isStaticDataMember()) { |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 682 | DSAVarData DVarTemp = hasDSA(D, isOpenMPPrivate, MatchesAlways, FromParent); |
Alexey Bataev | dffa93a | 2015-12-10 08:20:58 +0000 | [diff] [blame] | 683 | if (DVarTemp.CKind != OMPC_unknown && DVarTemp.RefExpr) |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 684 | return DVar; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 685 | |
Alexey Bataev | dffa93a | 2015-12-10 08:20:58 +0000 | [diff] [blame] | 686 | DVar.CKind = OMPC_shared; |
| 687 | return DVar; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 688 | } |
| 689 | |
| 690 | QualType Type = D->getType().getNonReferenceType().getCanonicalType(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 691 | bool IsConstant = Type.isConstant(SemaRef.getASTContext()); |
| 692 | Type = SemaRef.getASTContext().getBaseElementType(Type); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 693 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 694 | // in a Construct, C/C++, predetermined, p.6] |
| 695 | // Variables with const qualified type having no mutable member are |
| 696 | // shared. |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 697 | CXXRecordDecl *RD = |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 698 | SemaRef.getLangOpts().CPlusPlus ? Type->getAsCXXRecordDecl() : nullptr; |
Alexey Bataev | c9bd03d | 2015-12-17 06:55:08 +0000 | [diff] [blame] | 699 | if (auto *CTSD = dyn_cast_or_null<ClassTemplateSpecializationDecl>(RD)) |
| 700 | if (auto *CTD = CTSD->getSpecializedTemplate()) |
| 701 | RD = CTD->getTemplatedDecl(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 702 | if (IsConstant && |
Alexey Bataev | 4bcad7f | 2016-02-10 10:50:12 +0000 | [diff] [blame] | 703 | !(SemaRef.getLangOpts().CPlusPlus && RD && RD->hasDefinition() && |
| 704 | RD->hasMutableFields())) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 705 | // Variables with const-qualified type having no mutable member may be |
| 706 | // listed in a firstprivate clause, even if they are static data members. |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 707 | DSAVarData DVarTemp = hasDSA( |
| 708 | D, [](OpenMPClauseKind C) -> bool { return C == OMPC_firstprivate; }, |
| 709 | MatchesAlways, FromParent); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 710 | if (DVarTemp.CKind == OMPC_firstprivate && DVarTemp.RefExpr) |
| 711 | return DVar; |
| 712 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 713 | DVar.CKind = OMPC_shared; |
| 714 | return DVar; |
| 715 | } |
| 716 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 717 | // Explicitly specified attributes and local variables with predetermined |
| 718 | // attributes. |
Alexey Bataev | dffa93a | 2015-12-10 08:20:58 +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 | } |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 724 | auto I = std::prev(StartI); |
| 725 | if (I->SharingMap.count(D)) { |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 726 | DVar.RefExpr = I->SharingMap[D].RefExpr.getPointer(); |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 727 | DVar.PrivateCopy = I->SharingMap[D].PrivateCopy; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 728 | DVar.CKind = I->SharingMap[D].Attributes; |
| 729 | DVar.ImplicitDSALoc = I->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 730 | } |
| 731 | |
| 732 | return DVar; |
| 733 | } |
| 734 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 735 | DSAStackTy::DSAVarData DSAStackTy::getImplicitDSA(ValueDecl *D, |
| 736 | bool FromParent) { |
| 737 | D = getCanonicalDecl(D); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 738 | auto StartI = Stack.rbegin(); |
| 739 | auto EndI = std::prev(Stack.rend()); |
| 740 | if (FromParent && StartI != EndI) { |
| 741 | StartI = std::next(StartI); |
| 742 | } |
| 743 | return getDSA(StartI, D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 744 | } |
| 745 | |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 746 | DSAStackTy::DSAVarData |
| 747 | DSAStackTy::hasDSA(ValueDecl *D, |
| 748 | const llvm::function_ref<bool(OpenMPClauseKind)> &CPred, |
| 749 | const llvm::function_ref<bool(OpenMPDirectiveKind)> &DPred, |
| 750 | bool FromParent) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 751 | D = getCanonicalDecl(D); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 752 | auto StartI = std::next(Stack.rbegin()); |
Dmitry Polukhin | dc78bc82 | 2016-04-01 09:52:30 +0000 | [diff] [blame] | 753 | auto EndI = Stack.rend(); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 754 | if (FromParent && StartI != EndI) { |
| 755 | StartI = std::next(StartI); |
| 756 | } |
| 757 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
| 758 | if (!DPred(I->Directive) && !isParallelOrTaskRegion(I->Directive)) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 759 | continue; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 760 | DSAVarData DVar = getDSA(I, D); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 761 | if (CPred(DVar.CKind)) |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 762 | return DVar; |
| 763 | } |
| 764 | return DSAVarData(); |
| 765 | } |
| 766 | |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 767 | DSAStackTy::DSAVarData DSAStackTy::hasInnermostDSA( |
| 768 | ValueDecl *D, const llvm::function_ref<bool(OpenMPClauseKind)> &CPred, |
| 769 | const llvm::function_ref<bool(OpenMPDirectiveKind)> &DPred, |
| 770 | bool FromParent) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 771 | D = getCanonicalDecl(D); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 772 | auto StartI = std::next(Stack.rbegin()); |
Dmitry Polukhin | dc78bc82 | 2016-04-01 09:52:30 +0000 | [diff] [blame] | 773 | auto EndI = Stack.rend(); |
Alexey Bataev | e397812 | 2016-07-19 05:06:39 +0000 | [diff] [blame] | 774 | if (FromParent && StartI != EndI) |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 775 | StartI = std::next(StartI); |
Alexey Bataev | e397812 | 2016-07-19 05:06:39 +0000 | [diff] [blame] | 776 | if (StartI == EndI || !DPred(StartI->Directive)) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 777 | return DSAVarData(); |
Alexey Bataev | e397812 | 2016-07-19 05:06:39 +0000 | [diff] [blame] | 778 | DSAVarData DVar = getDSA(StartI, D); |
| 779 | return CPred(DVar.CKind) ? DVar : DSAVarData(); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 780 | } |
| 781 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 782 | bool DSAStackTy::hasExplicitDSA( |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 783 | ValueDecl *D, const llvm::function_ref<bool(OpenMPClauseKind)> &CPred, |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 784 | unsigned Level, bool NotLastprivate) { |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 785 | if (CPred(ClauseKindMode)) |
| 786 | return true; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 787 | D = getCanonicalDecl(D); |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 788 | auto StartI = std::next(Stack.begin()); |
| 789 | auto EndI = Stack.end(); |
NAKAMURA Takumi | 0332eda | 2015-06-23 10:01:20 +0000 | [diff] [blame] | 790 | if (std::distance(StartI, EndI) <= (int)Level) |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 791 | return false; |
| 792 | std::advance(StartI, Level); |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 793 | return (StartI->SharingMap.count(D) > 0) && |
| 794 | StartI->SharingMap[D].RefExpr.getPointer() && |
| 795 | CPred(StartI->SharingMap[D].Attributes) && |
| 796 | (!NotLastprivate || !StartI->SharingMap[D].RefExpr.getInt()); |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 797 | } |
| 798 | |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 799 | bool DSAStackTy::hasExplicitDirective( |
| 800 | const llvm::function_ref<bool(OpenMPDirectiveKind)> &DPred, |
| 801 | unsigned Level) { |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 802 | auto StartI = std::next(Stack.begin()); |
| 803 | auto EndI = Stack.end(); |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 804 | if (std::distance(StartI, EndI) <= (int)Level) |
| 805 | return false; |
| 806 | std::advance(StartI, Level); |
| 807 | return DPred(StartI->Directive); |
| 808 | } |
| 809 | |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 810 | bool DSAStackTy::hasDirective( |
| 811 | const llvm::function_ref<bool(OpenMPDirectiveKind, |
| 812 | const DeclarationNameInfo &, SourceLocation)> |
| 813 | &DPred, |
| 814 | bool FromParent) { |
Samuel Antao | f0d7975 | 2016-05-27 15:21:27 +0000 | [diff] [blame] | 815 | // We look only in the enclosing region. |
| 816 | if (Stack.size() < 2) |
| 817 | return false; |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 818 | auto StartI = std::next(Stack.rbegin()); |
| 819 | auto EndI = std::prev(Stack.rend()); |
| 820 | if (FromParent && StartI != EndI) { |
| 821 | StartI = std::next(StartI); |
| 822 | } |
| 823 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
| 824 | if (DPred(I->Directive, I->DirectiveName, I->ConstructLoc)) |
| 825 | return true; |
| 826 | } |
| 827 | return false; |
| 828 | } |
| 829 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 830 | void Sema::InitDataSharingAttributesStack() { |
| 831 | VarDataSharingAttributesStack = new DSAStackTy(*this); |
| 832 | } |
| 833 | |
| 834 | #define DSAStack static_cast<DSAStackTy *>(VarDataSharingAttributesStack) |
| 835 | |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 836 | bool Sema::IsOpenMPCapturedByRef(ValueDecl *D, unsigned Level) { |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 837 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| 838 | |
| 839 | auto &Ctx = getASTContext(); |
| 840 | bool IsByRef = true; |
| 841 | |
| 842 | // Find the directive that is associated with the provided scope. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 843 | auto Ty = D->getType(); |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 844 | |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 845 | if (DSAStack->hasExplicitDirective(isOpenMPTargetExecutionDirective, Level)) { |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 846 | // This table summarizes how a given variable should be passed to the device |
| 847 | // given its type and the clauses where it appears. This table is based on |
| 848 | // the description in OpenMP 4.5 [2.10.4, target Construct] and |
| 849 | // OpenMP 4.5 [2.15.5, Data-mapping Attribute Rules and Clauses]. |
| 850 | // |
| 851 | // ========================================================================= |
| 852 | // | type | defaultmap | pvt | first | is_device_ptr | map | res. | |
| 853 | // | |(tofrom:scalar)| | pvt | | | | |
| 854 | // ========================================================================= |
| 855 | // | scl | | | | - | | bycopy| |
| 856 | // | scl | | - | x | - | - | bycopy| |
| 857 | // | scl | | x | - | - | - | null | |
| 858 | // | scl | x | | | - | | byref | |
| 859 | // | scl | x | - | x | - | - | bycopy| |
| 860 | // | scl | x | x | - | - | - | null | |
| 861 | // | scl | | - | - | - | x | byref | |
| 862 | // | scl | x | - | - | - | x | byref | |
| 863 | // |
| 864 | // | agg | n.a. | | | - | | byref | |
| 865 | // | agg | n.a. | - | x | - | - | byref | |
| 866 | // | agg | n.a. | x | - | - | - | null | |
| 867 | // | agg | n.a. | - | - | - | x | byref | |
| 868 | // | agg | n.a. | - | - | - | x[] | byref | |
| 869 | // |
| 870 | // | ptr | n.a. | | | - | | bycopy| |
| 871 | // | ptr | n.a. | - | x | - | - | bycopy| |
| 872 | // | ptr | n.a. | x | - | - | - | null | |
| 873 | // | ptr | n.a. | - | - | - | x | byref | |
| 874 | // | ptr | n.a. | - | - | - | x[] | bycopy| |
| 875 | // | ptr | n.a. | - | - | x | | bycopy| |
| 876 | // | ptr | n.a. | - | - | x | x | bycopy| |
| 877 | // | ptr | n.a. | - | - | x | x[] | bycopy| |
| 878 | // ========================================================================= |
| 879 | // Legend: |
| 880 | // scl - scalar |
| 881 | // ptr - pointer |
| 882 | // agg - aggregate |
| 883 | // x - applies |
| 884 | // - - invalid in this combination |
| 885 | // [] - mapped with an array section |
| 886 | // byref - should be mapped by reference |
| 887 | // byval - should be mapped by value |
| 888 | // null - initialize a local variable to null on the device |
| 889 | // |
| 890 | // Observations: |
| 891 | // - All scalar declarations that show up in a map clause have to be passed |
| 892 | // by reference, because they may have been mapped in the enclosing data |
| 893 | // environment. |
| 894 | // - If the scalar value does not fit the size of uintptr, it has to be |
| 895 | // passed by reference, regardless the result in the table above. |
| 896 | // - For pointers mapped by value that have either an implicit map or an |
| 897 | // array section, the runtime library may pass the NULL value to the |
| 898 | // device instead of the value passed to it by the compiler. |
| 899 | |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 900 | |
| 901 | if (Ty->isReferenceType()) |
| 902 | Ty = Ty->castAs<ReferenceType>()->getPointeeType(); |
Samuel Antao | 86ace55 | 2016-04-27 22:40:57 +0000 | [diff] [blame] | 903 | |
| 904 | // Locate map clauses and see if the variable being captured is referred to |
| 905 | // in any of those clauses. Here we only care about variables, not fields, |
| 906 | // because fields are part of aggregates. |
| 907 | bool IsVariableUsedInMapClause = false; |
| 908 | bool IsVariableAssociatedWithSection = false; |
| 909 | |
| 910 | DSAStack->checkMappableExprComponentListsForDecl( |
| 911 | D, /*CurrentRegionOnly=*/true, |
| 912 | [&](OMPClauseMappableExprCommon::MappableExprComponentListRef |
| 913 | MapExprComponents) { |
| 914 | |
| 915 | auto EI = MapExprComponents.rbegin(); |
| 916 | auto EE = MapExprComponents.rend(); |
| 917 | |
| 918 | assert(EI != EE && "Invalid map expression!"); |
| 919 | |
| 920 | if (isa<DeclRefExpr>(EI->getAssociatedExpression())) |
| 921 | IsVariableUsedInMapClause |= EI->getAssociatedDeclaration() == D; |
| 922 | |
| 923 | ++EI; |
| 924 | if (EI == EE) |
| 925 | return false; |
| 926 | |
| 927 | if (isa<ArraySubscriptExpr>(EI->getAssociatedExpression()) || |
| 928 | isa<OMPArraySectionExpr>(EI->getAssociatedExpression()) || |
| 929 | isa<MemberExpr>(EI->getAssociatedExpression())) { |
| 930 | IsVariableAssociatedWithSection = true; |
| 931 | // There is nothing more we need to know about this variable. |
| 932 | return true; |
| 933 | } |
| 934 | |
| 935 | // Keep looking for more map info. |
| 936 | return false; |
| 937 | }); |
| 938 | |
| 939 | if (IsVariableUsedInMapClause) { |
| 940 | // If variable is identified in a map clause it is always captured by |
| 941 | // reference except if it is a pointer that is dereferenced somehow. |
| 942 | IsByRef = !(Ty->isPointerType() && IsVariableAssociatedWithSection); |
| 943 | } else { |
| 944 | // By default, all the data that has a scalar type is mapped by copy. |
| 945 | IsByRef = !Ty->isScalarType(); |
| 946 | } |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 947 | } |
| 948 | |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 949 | if (IsByRef && Ty.getNonReferenceType()->isScalarType()) { |
| 950 | IsByRef = !DSAStack->hasExplicitDSA( |
| 951 | D, [](OpenMPClauseKind K) -> bool { return K == OMPC_firstprivate; }, |
| 952 | Level, /*NotLastprivate=*/true); |
| 953 | } |
| 954 | |
Samuel Antao | 86ace55 | 2016-04-27 22:40:57 +0000 | [diff] [blame] | 955 | // When passing data by copy, we need to make sure it fits the uintptr size |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 956 | // and alignment, because the runtime library only deals with uintptr types. |
| 957 | // If it does not fit the uintptr size, we need to pass the data by reference |
| 958 | // instead. |
| 959 | if (!IsByRef && |
| 960 | (Ctx.getTypeSizeInChars(Ty) > |
| 961 | Ctx.getTypeSizeInChars(Ctx.getUIntPtrType()) || |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 962 | Ctx.getDeclAlign(D) > Ctx.getTypeAlignInChars(Ctx.getUIntPtrType()))) { |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 963 | IsByRef = true; |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 964 | } |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 965 | |
| 966 | return IsByRef; |
| 967 | } |
| 968 | |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 969 | unsigned Sema::getOpenMPNestingLevel() const { |
| 970 | assert(getLangOpts().OpenMP); |
| 971 | return DSAStack->getNestingLevel(); |
| 972 | } |
| 973 | |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 974 | VarDecl *Sema::IsOpenMPCapturedDecl(ValueDecl *D) { |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 975 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 976 | D = getCanonicalDecl(D); |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 977 | |
| 978 | // If we are attempting to capture a global variable in a directive with |
| 979 | // 'target' we return true so that this global is also mapped to the device. |
| 980 | // |
| 981 | // FIXME: If the declaration is enclosed in a 'declare target' directive, |
| 982 | // then it should not be captured. Therefore, an extra check has to be |
| 983 | // inserted here once support for 'declare target' is added. |
| 984 | // |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 985 | auto *VD = dyn_cast<VarDecl>(D); |
| 986 | if (VD && !VD->hasLocalStorage()) { |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 987 | if (DSAStack->getCurrentDirective() == OMPD_target && |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 988 | !DSAStack->isClauseParsingMode()) |
| 989 | return VD; |
Samuel Antao | f0d7975 | 2016-05-27 15:21:27 +0000 | [diff] [blame] | 990 | if (DSAStack->hasDirective( |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 991 | [](OpenMPDirectiveKind K, const DeclarationNameInfo &, |
| 992 | SourceLocation) -> bool { |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 993 | return isOpenMPTargetExecutionDirective(K); |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 994 | }, |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 995 | false)) |
| 996 | return VD; |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 997 | } |
| 998 | |
Alexey Bataev | 48977c3 | 2015-08-04 08:10:48 +0000 | [diff] [blame] | 999 | if (DSAStack->getCurrentDirective() != OMPD_unknown && |
| 1000 | (!DSAStack->isClauseParsingMode() || |
| 1001 | DSAStack->getParentDirective() != OMPD_unknown)) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 1002 | auto &&Info = DSAStack->isLoopControlVariable(D); |
| 1003 | if (Info.first || |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1004 | (VD && VD->hasLocalStorage() && |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 1005 | isParallelOrTaskRegion(DSAStack->getCurrentDirective())) || |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1006 | (VD && DSAStack->isForceVarCapturing())) |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 1007 | return VD ? VD : Info.second; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1008 | auto DVarPrivate = DSAStack->getTopDSA(D, DSAStack->isClauseParsingMode()); |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 1009 | if (DVarPrivate.CKind != OMPC_unknown && isOpenMPPrivate(DVarPrivate.CKind)) |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 1010 | return VD ? VD : cast<VarDecl>(DVarPrivate.PrivateCopy->getDecl()); |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 1011 | DVarPrivate = DSAStack->hasDSA( |
| 1012 | D, isOpenMPPrivate, [](OpenMPDirectiveKind) -> bool { return true; }, |
| 1013 | DSAStack->isClauseParsingMode()); |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 1014 | if (DVarPrivate.CKind != OMPC_unknown) |
| 1015 | return VD ? VD : cast<VarDecl>(DVarPrivate.PrivateCopy->getDecl()); |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 1016 | } |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 1017 | return nullptr; |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 1018 | } |
| 1019 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1020 | bool Sema::isOpenMPPrivateDecl(ValueDecl *D, unsigned Level) { |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 1021 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| 1022 | return DSAStack->hasExplicitDSA( |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1023 | D, [](OpenMPClauseKind K) -> bool { return K == OMPC_private; }, Level); |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 1024 | } |
| 1025 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1026 | bool Sema::isOpenMPTargetCapturedDecl(ValueDecl *D, unsigned Level) { |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 1027 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| 1028 | // Return true if the current level is no longer enclosed in a target region. |
| 1029 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1030 | auto *VD = dyn_cast<VarDecl>(D); |
| 1031 | return VD && !VD->hasLocalStorage() && |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 1032 | DSAStack->hasExplicitDirective(isOpenMPTargetExecutionDirective, |
| 1033 | Level); |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 1034 | } |
| 1035 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1036 | void Sema::DestroyDataSharingAttributesStack() { delete DSAStack; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1037 | |
| 1038 | void Sema::StartOpenMPDSABlock(OpenMPDirectiveKind DKind, |
| 1039 | const DeclarationNameInfo &DirName, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1040 | Scope *CurScope, SourceLocation Loc) { |
| 1041 | DSAStack->push(DKind, DirName, CurScope, Loc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1042 | PushExpressionEvaluationContext(PotentiallyEvaluated); |
| 1043 | } |
| 1044 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 1045 | void Sema::StartOpenMPClause(OpenMPClauseKind K) { |
| 1046 | DSAStack->setClauseParsingMode(K); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 1047 | } |
| 1048 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 1049 | void Sema::EndOpenMPClause() { |
| 1050 | DSAStack->setClauseParsingMode(/*K=*/OMPC_unknown); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 1051 | } |
| 1052 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1053 | void Sema::EndOpenMPDSABlock(Stmt *CurDirective) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1054 | // OpenMP [2.14.3.5, Restrictions, C/C++, p.1] |
| 1055 | // A variable of class type (or array thereof) that appears in a lastprivate |
| 1056 | // clause requires an accessible, unambiguous default constructor for the |
| 1057 | // class type, unless the list item is also specified in a firstprivate |
| 1058 | // clause. |
| 1059 | if (auto D = dyn_cast_or_null<OMPExecutableDirective>(CurDirective)) { |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1060 | for (auto *C : D->clauses()) { |
| 1061 | if (auto *Clause = dyn_cast<OMPLastprivateClause>(C)) { |
| 1062 | SmallVector<Expr *, 8> PrivateCopies; |
| 1063 | for (auto *DE : Clause->varlists()) { |
| 1064 | if (DE->isValueDependent() || DE->isTypeDependent()) { |
| 1065 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1066 | continue; |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1067 | } |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 1068 | auto *DRE = cast<DeclRefExpr>(DE->IgnoreParens()); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 1069 | VarDecl *VD = cast<VarDecl>(DRE->getDecl()); |
| 1070 | QualType Type = VD->getType().getNonReferenceType(); |
| 1071 | auto DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1072 | if (DVar.CKind == OMPC_lastprivate) { |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1073 | // Generate helper private variable and initialize it with the |
| 1074 | // default value. The address of the original variable is replaced |
| 1075 | // by the address of the new private variable in CodeGen. This new |
| 1076 | // variable is not added to IdResolver, so the code in the OpenMP |
| 1077 | // region uses original variable for proper diagnostics. |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 1078 | auto *VDPrivate = buildVarDecl( |
| 1079 | *this, DE->getExprLoc(), Type.getUnqualifiedType(), |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 1080 | VD->getName(), VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1081 | ActOnUninitializedDecl(VDPrivate, /*TypeMayContainAuto=*/false); |
| 1082 | if (VDPrivate->isInvalidDecl()) |
| 1083 | continue; |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 1084 | PrivateCopies.push_back(buildDeclRefExpr( |
| 1085 | *this, VDPrivate, DE->getType(), DE->getExprLoc())); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1086 | } else { |
| 1087 | // The variable is also a firstprivate, so initialization sequence |
| 1088 | // for private copy is generated already. |
| 1089 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1090 | } |
| 1091 | } |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1092 | // Set initializers to private copies if no errors were found. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1093 | if (PrivateCopies.size() == Clause->varlist_size()) |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1094 | Clause->setPrivateCopies(PrivateCopies); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1095 | } |
| 1096 | } |
| 1097 | } |
| 1098 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1099 | DSAStack->pop(); |
| 1100 | DiscardCleanupsInEvaluationContext(); |
| 1101 | PopExpressionEvaluationContext(); |
| 1102 | } |
| 1103 | |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 1104 | static bool FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV, |
| 1105 | Expr *NumIterations, Sema &SemaRef, |
| 1106 | Scope *S, DSAStackTy *Stack); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 1107 | |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1108 | namespace { |
| 1109 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1110 | class VarDeclFilterCCC : public CorrectionCandidateCallback { |
| 1111 | private: |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1112 | Sema &SemaRef; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1113 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1114 | public: |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1115 | explicit VarDeclFilterCCC(Sema &S) : SemaRef(S) {} |
Craig Topper | e14c0f8 | 2014-03-12 04:55:44 +0000 | [diff] [blame] | 1116 | bool ValidateCandidate(const TypoCorrection &Candidate) override { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1117 | NamedDecl *ND = Candidate.getCorrectionDecl(); |
| 1118 | if (VarDecl *VD = dyn_cast_or_null<VarDecl>(ND)) { |
| 1119 | return VD->hasGlobalStorage() && |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1120 | SemaRef.isDeclInScope(ND, SemaRef.getCurLexicalContext(), |
| 1121 | SemaRef.getCurScope()); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1122 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1123 | return false; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1124 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1125 | }; |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 1126 | |
| 1127 | class VarOrFuncDeclFilterCCC : public CorrectionCandidateCallback { |
| 1128 | private: |
| 1129 | Sema &SemaRef; |
| 1130 | |
| 1131 | public: |
| 1132 | explicit VarOrFuncDeclFilterCCC(Sema &S) : SemaRef(S) {} |
| 1133 | bool ValidateCandidate(const TypoCorrection &Candidate) override { |
| 1134 | NamedDecl *ND = Candidate.getCorrectionDecl(); |
| 1135 | if (isa<VarDecl>(ND) || isa<FunctionDecl>(ND)) { |
| 1136 | return SemaRef.isDeclInScope(ND, SemaRef.getCurLexicalContext(), |
| 1137 | SemaRef.getCurScope()); |
| 1138 | } |
| 1139 | return false; |
| 1140 | } |
| 1141 | }; |
| 1142 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1143 | } // namespace |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1144 | |
| 1145 | ExprResult Sema::ActOnOpenMPIdExpression(Scope *CurScope, |
| 1146 | CXXScopeSpec &ScopeSpec, |
| 1147 | const DeclarationNameInfo &Id) { |
| 1148 | LookupResult Lookup(*this, Id, LookupOrdinaryName); |
| 1149 | LookupParsedName(Lookup, CurScope, &ScopeSpec, true); |
| 1150 | |
| 1151 | if (Lookup.isAmbiguous()) |
| 1152 | return ExprError(); |
| 1153 | |
| 1154 | VarDecl *VD; |
| 1155 | if (!Lookup.isSingleResult()) { |
Kaelyn Takata | 89c881b | 2014-10-27 18:07:29 +0000 | [diff] [blame] | 1156 | if (TypoCorrection Corrected = CorrectTypo( |
| 1157 | Id, LookupOrdinaryName, CurScope, nullptr, |
| 1158 | llvm::make_unique<VarDeclFilterCCC>(*this), CTK_ErrorRecovery)) { |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 1159 | diagnoseTypo(Corrected, |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 1160 | PDiag(Lookup.empty() |
| 1161 | ? diag::err_undeclared_var_use_suggest |
| 1162 | : diag::err_omp_expected_var_arg_suggest) |
| 1163 | << Id.getName()); |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 1164 | VD = Corrected.getCorrectionDeclAs<VarDecl>(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1165 | } else { |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 1166 | Diag(Id.getLoc(), Lookup.empty() ? diag::err_undeclared_var_use |
| 1167 | : diag::err_omp_expected_var_arg) |
| 1168 | << Id.getName(); |
| 1169 | return ExprError(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1170 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1171 | } else { |
| 1172 | if (!(VD = Lookup.getAsSingle<VarDecl>())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1173 | Diag(Id.getLoc(), diag::err_omp_expected_var_arg) << Id.getName(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1174 | Diag(Lookup.getFoundDecl()->getLocation(), diag::note_declared_at); |
| 1175 | return ExprError(); |
| 1176 | } |
| 1177 | } |
| 1178 | Lookup.suppressDiagnostics(); |
| 1179 | |
| 1180 | // OpenMP [2.9.2, Syntax, C/C++] |
| 1181 | // Variables must be file-scope, namespace-scope, or static block-scope. |
| 1182 | if (!VD->hasGlobalStorage()) { |
| 1183 | Diag(Id.getLoc(), diag::err_omp_global_var_arg) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1184 | << getOpenMPDirectiveName(OMPD_threadprivate) << !VD->isStaticLocal(); |
| 1185 | bool IsDecl = |
| 1186 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1187 | Diag(VD->getLocation(), |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1188 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1189 | << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1190 | return ExprError(); |
| 1191 | } |
| 1192 | |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1193 | VarDecl *CanonicalVD = VD->getCanonicalDecl(); |
| 1194 | NamedDecl *ND = cast<NamedDecl>(CanonicalVD); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1195 | // OpenMP [2.9.2, Restrictions, C/C++, p.2] |
| 1196 | // A threadprivate directive for file-scope variables must appear outside |
| 1197 | // any definition or declaration. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1198 | if (CanonicalVD->getDeclContext()->isTranslationUnit() && |
| 1199 | !getCurLexicalContext()->isTranslationUnit()) { |
| 1200 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1201 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1202 | bool IsDecl = |
| 1203 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1204 | Diag(VD->getLocation(), |
| 1205 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1206 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1207 | return ExprError(); |
| 1208 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1209 | // OpenMP [2.9.2, Restrictions, C/C++, p.3] |
| 1210 | // A threadprivate directive for static class member variables must appear |
| 1211 | // in the class definition, in the same scope in which the member |
| 1212 | // variables are declared. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1213 | if (CanonicalVD->isStaticDataMember() && |
| 1214 | !CanonicalVD->getDeclContext()->Equals(getCurLexicalContext())) { |
| 1215 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1216 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1217 | bool IsDecl = |
| 1218 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1219 | Diag(VD->getLocation(), |
| 1220 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1221 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1222 | return ExprError(); |
| 1223 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1224 | // OpenMP [2.9.2, Restrictions, C/C++, p.4] |
| 1225 | // A threadprivate directive for namespace-scope variables must appear |
| 1226 | // outside any definition or declaration other than the namespace |
| 1227 | // definition itself. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1228 | if (CanonicalVD->getDeclContext()->isNamespace() && |
| 1229 | (!getCurLexicalContext()->isFileContext() || |
| 1230 | !getCurLexicalContext()->Encloses(CanonicalVD->getDeclContext()))) { |
| 1231 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1232 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1233 | bool IsDecl = |
| 1234 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1235 | Diag(VD->getLocation(), |
| 1236 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1237 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1238 | return ExprError(); |
| 1239 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1240 | // OpenMP [2.9.2, Restrictions, C/C++, p.6] |
| 1241 | // A threadprivate directive for static block-scope variables must appear |
| 1242 | // in the scope of the variable and not in a nested scope. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1243 | if (CanonicalVD->isStaticLocal() && CurScope && |
| 1244 | !isDeclInScope(ND, getCurLexicalContext(), CurScope)) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1245 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1246 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1247 | bool IsDecl = |
| 1248 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1249 | Diag(VD->getLocation(), |
| 1250 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1251 | << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1252 | return ExprError(); |
| 1253 | } |
| 1254 | |
| 1255 | // OpenMP [2.9.2, Restrictions, C/C++, p.2-6] |
| 1256 | // A threadprivate directive must lexically precede all references to any |
| 1257 | // of the variables in its list. |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 1258 | if (VD->isUsed() && !DSAStack->isThreadPrivate(VD)) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1259 | Diag(Id.getLoc(), diag::err_omp_var_used) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1260 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1261 | return ExprError(); |
| 1262 | } |
| 1263 | |
| 1264 | QualType ExprType = VD->getType().getNonReferenceType(); |
Alexey Bataev | 376b4a4 | 2016-02-09 09:41:09 +0000 | [diff] [blame] | 1265 | return DeclRefExpr::Create(Context, NestedNameSpecifierLoc(), |
| 1266 | SourceLocation(), VD, |
| 1267 | /*RefersToEnclosingVariableOrCapture=*/false, |
| 1268 | Id.getLoc(), ExprType, VK_LValue); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1269 | } |
| 1270 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1271 | Sema::DeclGroupPtrTy |
| 1272 | Sema::ActOnOpenMPThreadprivateDirective(SourceLocation Loc, |
| 1273 | ArrayRef<Expr *> VarList) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1274 | if (OMPThreadPrivateDecl *D = CheckOMPThreadPrivateDecl(Loc, VarList)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1275 | CurContext->addDecl(D); |
| 1276 | return DeclGroupPtrTy::make(DeclGroupRef(D)); |
| 1277 | } |
David Blaikie | 0403cb1 | 2016-01-15 23:43:25 +0000 | [diff] [blame] | 1278 | return nullptr; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1279 | } |
| 1280 | |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1281 | namespace { |
| 1282 | class LocalVarRefChecker : public ConstStmtVisitor<LocalVarRefChecker, bool> { |
| 1283 | Sema &SemaRef; |
| 1284 | |
| 1285 | public: |
| 1286 | bool VisitDeclRefExpr(const DeclRefExpr *E) { |
| 1287 | if (auto VD = dyn_cast<VarDecl>(E->getDecl())) { |
| 1288 | if (VD->hasLocalStorage()) { |
| 1289 | SemaRef.Diag(E->getLocStart(), |
| 1290 | diag::err_omp_local_var_in_threadprivate_init) |
| 1291 | << E->getSourceRange(); |
| 1292 | SemaRef.Diag(VD->getLocation(), diag::note_defined_here) |
| 1293 | << VD << VD->getSourceRange(); |
| 1294 | return true; |
| 1295 | } |
| 1296 | } |
| 1297 | return false; |
| 1298 | } |
| 1299 | bool VisitStmt(const Stmt *S) { |
| 1300 | for (auto Child : S->children()) { |
| 1301 | if (Child && Visit(Child)) |
| 1302 | return true; |
| 1303 | } |
| 1304 | return false; |
| 1305 | } |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 1306 | explicit LocalVarRefChecker(Sema &SemaRef) : SemaRef(SemaRef) {} |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1307 | }; |
| 1308 | } // namespace |
| 1309 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1310 | OMPThreadPrivateDecl * |
| 1311 | Sema::CheckOMPThreadPrivateDecl(SourceLocation Loc, ArrayRef<Expr *> VarList) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1312 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1313 | for (auto &RefExpr : VarList) { |
| 1314 | DeclRefExpr *DE = cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1315 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); |
| 1316 | SourceLocation ILoc = DE->getExprLoc(); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1317 | |
Alexey Bataev | 376b4a4 | 2016-02-09 09:41:09 +0000 | [diff] [blame] | 1318 | // Mark variable as used. |
| 1319 | VD->setReferenced(); |
| 1320 | VD->markUsed(Context); |
| 1321 | |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 1322 | QualType QType = VD->getType(); |
| 1323 | if (QType->isDependentType() || QType->isInstantiationDependentType()) { |
| 1324 | // It will be analyzed later. |
| 1325 | Vars.push_back(DE); |
| 1326 | continue; |
| 1327 | } |
| 1328 | |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1329 | // OpenMP [2.9.2, Restrictions, C/C++, p.10] |
| 1330 | // A threadprivate variable must not have an incomplete type. |
| 1331 | if (RequireCompleteType(ILoc, VD->getType(), |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1332 | diag::err_omp_threadprivate_incomplete_type)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1333 | continue; |
| 1334 | } |
| 1335 | |
| 1336 | // OpenMP [2.9.2, Restrictions, C/C++, p.10] |
| 1337 | // A threadprivate variable must not have a reference type. |
| 1338 | if (VD->getType()->isReferenceType()) { |
| 1339 | Diag(ILoc, diag::err_omp_ref_type_arg) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1340 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD->getType(); |
| 1341 | bool IsDecl = |
| 1342 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1343 | Diag(VD->getLocation(), |
| 1344 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1345 | << VD; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1346 | continue; |
| 1347 | } |
| 1348 | |
Samuel Antao | f8b5012 | 2015-07-13 22:54:53 +0000 | [diff] [blame] | 1349 | // Check if this is a TLS variable. If TLS is not being supported, produce |
| 1350 | // the corresponding diagnostic. |
| 1351 | if ((VD->getTLSKind() != VarDecl::TLS_None && |
| 1352 | !(VD->hasAttr<OMPThreadPrivateDeclAttr>() && |
| 1353 | getLangOpts().OpenMPUseTLS && |
| 1354 | getASTContext().getTargetInfo().isTLSSupported())) || |
Alexey Bataev | 1a8b3f1 | 2015-05-06 06:34:55 +0000 | [diff] [blame] | 1355 | (VD->getStorageClass() == SC_Register && VD->hasAttr<AsmLabelAttr>() && |
| 1356 | !VD->isLocalVarDecl())) { |
Alexey Bataev | 26a3924 | 2015-01-13 03:35:30 +0000 | [diff] [blame] | 1357 | Diag(ILoc, diag::err_omp_var_thread_local) |
| 1358 | << VD << ((VD->getTLSKind() != VarDecl::TLS_None) ? 0 : 1); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1359 | bool IsDecl = |
| 1360 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1361 | Diag(VD->getLocation(), |
| 1362 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1363 | << VD; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1364 | continue; |
| 1365 | } |
| 1366 | |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1367 | // Check if initial value of threadprivate variable reference variable with |
| 1368 | // local storage (it is not supported by runtime). |
| 1369 | if (auto Init = VD->getAnyInitializer()) { |
| 1370 | LocalVarRefChecker Checker(*this); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1371 | if (Checker.Visit(Init)) |
| 1372 | continue; |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1373 | } |
| 1374 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1375 | Vars.push_back(RefExpr); |
Alexey Bataev | d178ad4 | 2014-03-07 08:03:37 +0000 | [diff] [blame] | 1376 | DSAStack->addDSA(VD, DE, OMPC_threadprivate); |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 1377 | VD->addAttr(OMPThreadPrivateDeclAttr::CreateImplicit( |
| 1378 | Context, SourceRange(Loc, Loc))); |
| 1379 | if (auto *ML = Context.getASTMutationListener()) |
| 1380 | ML->DeclarationMarkedOpenMPThreadPrivate(VD); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1381 | } |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 1382 | OMPThreadPrivateDecl *D = nullptr; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 1383 | if (!Vars.empty()) { |
| 1384 | D = OMPThreadPrivateDecl::Create(Context, getCurLexicalContext(), Loc, |
| 1385 | Vars); |
| 1386 | D->setAccess(AS_public); |
| 1387 | } |
| 1388 | return D; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1389 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1390 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1391 | static void ReportOriginalDSA(Sema &SemaRef, DSAStackTy *Stack, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1392 | const ValueDecl *D, DSAStackTy::DSAVarData DVar, |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1393 | bool IsLoopIterVar = false) { |
| 1394 | if (DVar.RefExpr) { |
| 1395 | SemaRef.Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_explicit_dsa) |
| 1396 | << getOpenMPClauseName(DVar.CKind); |
| 1397 | return; |
| 1398 | } |
| 1399 | enum { |
| 1400 | PDSA_StaticMemberShared, |
| 1401 | PDSA_StaticLocalVarShared, |
| 1402 | PDSA_LoopIterVarPrivate, |
| 1403 | PDSA_LoopIterVarLinear, |
| 1404 | PDSA_LoopIterVarLastprivate, |
| 1405 | PDSA_ConstVarShared, |
| 1406 | PDSA_GlobalVarShared, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1407 | PDSA_TaskVarFirstprivate, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1408 | PDSA_LocalVarPrivate, |
| 1409 | PDSA_Implicit |
| 1410 | } Reason = PDSA_Implicit; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1411 | bool ReportHint = false; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1412 | auto ReportLoc = D->getLocation(); |
| 1413 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1414 | if (IsLoopIterVar) { |
| 1415 | if (DVar.CKind == OMPC_private) |
| 1416 | Reason = PDSA_LoopIterVarPrivate; |
| 1417 | else if (DVar.CKind == OMPC_lastprivate) |
| 1418 | Reason = PDSA_LoopIterVarLastprivate; |
| 1419 | else |
| 1420 | Reason = PDSA_LoopIterVarLinear; |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 1421 | } else if (isOpenMPTaskingDirective(DVar.DKind) && |
| 1422 | DVar.CKind == OMPC_firstprivate) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1423 | Reason = PDSA_TaskVarFirstprivate; |
| 1424 | ReportLoc = DVar.ImplicitDSALoc; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1425 | } else if (VD && VD->isStaticLocal()) |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1426 | Reason = PDSA_StaticLocalVarShared; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1427 | else if (VD && VD->isStaticDataMember()) |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1428 | Reason = PDSA_StaticMemberShared; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1429 | else if (VD && VD->isFileVarDecl()) |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1430 | Reason = PDSA_GlobalVarShared; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1431 | else if (D->getType().isConstant(SemaRef.getASTContext())) |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1432 | Reason = PDSA_ConstVarShared; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1433 | else if (VD && VD->isLocalVarDecl() && DVar.CKind == OMPC_private) { |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1434 | ReportHint = true; |
| 1435 | Reason = PDSA_LocalVarPrivate; |
| 1436 | } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1437 | if (Reason != PDSA_Implicit) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1438 | SemaRef.Diag(ReportLoc, diag::note_omp_predetermined_dsa) |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1439 | << Reason << ReportHint |
| 1440 | << getOpenMPDirectiveName(Stack->getCurrentDirective()); |
| 1441 | } else if (DVar.ImplicitDSALoc.isValid()) { |
| 1442 | SemaRef.Diag(DVar.ImplicitDSALoc, diag::note_omp_implicit_dsa) |
| 1443 | << getOpenMPClauseName(DVar.CKind); |
| 1444 | } |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1445 | } |
| 1446 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1447 | namespace { |
| 1448 | class DSAAttrChecker : public StmtVisitor<DSAAttrChecker, void> { |
| 1449 | DSAStackTy *Stack; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1450 | Sema &SemaRef; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1451 | bool ErrorFound; |
| 1452 | CapturedStmt *CS; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1453 | llvm::SmallVector<Expr *, 8> ImplicitFirstprivate; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1454 | llvm::DenseMap<ValueDecl *, Expr *> VarsWithInheritedDSA; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1455 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1456 | public: |
| 1457 | void VisitDeclRefExpr(DeclRefExpr *E) { |
Alexey Bataev | 07b79c2 | 2016-04-29 09:56:11 +0000 | [diff] [blame] | 1458 | if (E->isTypeDependent() || E->isValueDependent() || |
| 1459 | E->containsUnexpandedParameterPack() || E->isInstantiationDependent()) |
| 1460 | return; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1461 | if (auto *VD = dyn_cast<VarDecl>(E->getDecl())) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1462 | // Skip internally declared variables. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1463 | if (VD->isLocalVarDecl() && !CS->capturesVariable(VD)) |
| 1464 | return; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1465 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1466 | auto DVar = Stack->getTopDSA(VD, false); |
| 1467 | // Check if the variable has explicit DSA set and stop analysis if it so. |
| 1468 | if (DVar.RefExpr) return; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1469 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1470 | auto ELoc = E->getExprLoc(); |
| 1471 | auto DKind = Stack->getCurrentDirective(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1472 | // The default(none) clause requires that each variable that is referenced |
| 1473 | // in the construct, and does not have a predetermined data-sharing |
| 1474 | // attribute, must have its data-sharing attribute explicitly determined |
| 1475 | // by being listed in a data-sharing attribute clause. |
| 1476 | if (DVar.CKind == OMPC_unknown && Stack->getDefaultDSA() == DSA_none && |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1477 | isParallelOrTaskRegion(DKind) && |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1478 | VarsWithInheritedDSA.count(VD) == 0) { |
| 1479 | VarsWithInheritedDSA[VD] = E; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1480 | return; |
| 1481 | } |
| 1482 | |
| 1483 | // OpenMP [2.9.3.6, Restrictions, p.2] |
| 1484 | // A list item that appears in a reduction clause of the innermost |
| 1485 | // enclosing worksharing or parallel construct may not be accessed in an |
| 1486 | // explicit task. |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 1487 | DVar = Stack->hasInnermostDSA( |
| 1488 | VD, [](OpenMPClauseKind C) -> bool { return C == OMPC_reduction; }, |
| 1489 | [](OpenMPDirectiveKind K) -> bool { |
| 1490 | return isOpenMPParallelDirective(K) || |
| 1491 | isOpenMPWorksharingDirective(K) || isOpenMPTeamsDirective(K); |
| 1492 | }, |
| 1493 | false); |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 1494 | if (isOpenMPTaskingDirective(DKind) && DVar.CKind == OMPC_reduction) { |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1495 | ErrorFound = true; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1496 | SemaRef.Diag(ELoc, diag::err_omp_reduction_in_task); |
| 1497 | ReportOriginalDSA(SemaRef, Stack, VD, DVar); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1498 | return; |
| 1499 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1500 | |
| 1501 | // Define implicit data-sharing attributes for task. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1502 | DVar = Stack->getImplicitDSA(VD, false); |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 1503 | if (isOpenMPTaskingDirective(DKind) && DVar.CKind != OMPC_shared && |
| 1504 | !Stack->isLoopControlVariable(VD).first) |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1505 | ImplicitFirstprivate.push_back(E); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1506 | } |
| 1507 | } |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1508 | void VisitMemberExpr(MemberExpr *E) { |
Alexey Bataev | 07b79c2 | 2016-04-29 09:56:11 +0000 | [diff] [blame] | 1509 | if (E->isTypeDependent() || E->isValueDependent() || |
| 1510 | E->containsUnexpandedParameterPack() || E->isInstantiationDependent()) |
| 1511 | return; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1512 | if (isa<CXXThisExpr>(E->getBase()->IgnoreParens())) { |
| 1513 | if (auto *FD = dyn_cast<FieldDecl>(E->getMemberDecl())) { |
| 1514 | auto DVar = Stack->getTopDSA(FD, false); |
| 1515 | // Check if the variable has explicit DSA set and stop analysis if it |
| 1516 | // so. |
| 1517 | if (DVar.RefExpr) |
| 1518 | return; |
| 1519 | |
| 1520 | auto ELoc = E->getExprLoc(); |
| 1521 | auto DKind = Stack->getCurrentDirective(); |
| 1522 | // OpenMP [2.9.3.6, Restrictions, p.2] |
| 1523 | // A list item that appears in a reduction clause of the innermost |
| 1524 | // enclosing worksharing or parallel construct may not be accessed in |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 1525 | // an explicit task. |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 1526 | DVar = Stack->hasInnermostDSA( |
| 1527 | FD, [](OpenMPClauseKind C) -> bool { return C == OMPC_reduction; }, |
| 1528 | [](OpenMPDirectiveKind K) -> bool { |
| 1529 | return isOpenMPParallelDirective(K) || |
| 1530 | isOpenMPWorksharingDirective(K) || |
| 1531 | isOpenMPTeamsDirective(K); |
| 1532 | }, |
| 1533 | false); |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 1534 | if (isOpenMPTaskingDirective(DKind) && DVar.CKind == OMPC_reduction) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1535 | ErrorFound = true; |
| 1536 | SemaRef.Diag(ELoc, diag::err_omp_reduction_in_task); |
| 1537 | ReportOriginalDSA(SemaRef, Stack, FD, DVar); |
| 1538 | return; |
| 1539 | } |
| 1540 | |
| 1541 | // Define implicit data-sharing attributes for task. |
| 1542 | DVar = Stack->getImplicitDSA(FD, false); |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 1543 | if (isOpenMPTaskingDirective(DKind) && DVar.CKind != OMPC_shared && |
| 1544 | !Stack->isLoopControlVariable(FD).first) |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1545 | ImplicitFirstprivate.push_back(E); |
| 1546 | } |
| 1547 | } |
| 1548 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1549 | void VisitOMPExecutableDirective(OMPExecutableDirective *S) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1550 | for (auto *C : S->clauses()) { |
| 1551 | // Skip analysis of arguments of implicitly defined firstprivate clause |
| 1552 | // for task directives. |
| 1553 | if (C && (!isa<OMPFirstprivateClause>(C) || C->getLocStart().isValid())) |
| 1554 | for (auto *CC : C->children()) { |
| 1555 | if (CC) |
| 1556 | Visit(CC); |
| 1557 | } |
| 1558 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1559 | } |
| 1560 | void VisitStmt(Stmt *S) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1561 | for (auto *C : S->children()) { |
| 1562 | if (C && !isa<OMPExecutableDirective>(C)) |
| 1563 | Visit(C); |
| 1564 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1565 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1566 | |
| 1567 | bool isErrorFound() { return ErrorFound; } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1568 | ArrayRef<Expr *> getImplicitFirstprivate() { return ImplicitFirstprivate; } |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1569 | llvm::DenseMap<ValueDecl *, Expr *> &getVarsWithInheritedDSA() { |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1570 | return VarsWithInheritedDSA; |
| 1571 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1572 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1573 | DSAAttrChecker(DSAStackTy *S, Sema &SemaRef, CapturedStmt *CS) |
| 1574 | : Stack(S), SemaRef(SemaRef), ErrorFound(false), CS(CS) {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1575 | }; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1576 | } // namespace |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1577 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1578 | void Sema::ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, Scope *CurScope) { |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1579 | switch (DKind) { |
Kelvin Li | 70a12c5 | 2016-07-13 21:51:49 +0000 | [diff] [blame] | 1580 | case OMPD_parallel: |
| 1581 | case OMPD_parallel_for: |
| 1582 | case OMPD_parallel_for_simd: |
| 1583 | case OMPD_parallel_sections: |
| 1584 | case OMPD_teams: { |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1585 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1586 | QualType KmpInt32PtrTy = |
| 1587 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1588 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1589 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1590 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1591 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1592 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1593 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1594 | Params); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1595 | break; |
| 1596 | } |
Kelvin Li | 70a12c5 | 2016-07-13 21:51:49 +0000 | [diff] [blame] | 1597 | case OMPD_simd: |
| 1598 | case OMPD_for: |
| 1599 | case OMPD_for_simd: |
| 1600 | case OMPD_sections: |
| 1601 | case OMPD_section: |
| 1602 | case OMPD_single: |
| 1603 | case OMPD_master: |
| 1604 | case OMPD_critical: |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 1605 | case OMPD_taskgroup: |
| 1606 | case OMPD_distribute: |
Kelvin Li | 70a12c5 | 2016-07-13 21:51:49 +0000 | [diff] [blame] | 1607 | case OMPD_ordered: |
| 1608 | case OMPD_atomic: |
| 1609 | case OMPD_target_data: |
| 1610 | case OMPD_target: |
| 1611 | case OMPD_target_parallel: |
| 1612 | case OMPD_target_parallel_for: |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 1613 | case OMPD_target_parallel_for_simd: |
| 1614 | case OMPD_target_simd: { |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1615 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1616 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1617 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1618 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1619 | Params); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1620 | break; |
| 1621 | } |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1622 | case OMPD_task: { |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1623 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 3ae88e2 | 2015-05-22 08:56:35 +0000 | [diff] [blame] | 1624 | QualType Args[] = {Context.VoidPtrTy.withConst().withRestrict()}; |
| 1625 | FunctionProtoType::ExtProtoInfo EPI; |
| 1626 | EPI.Variadic = true; |
| 1627 | QualType CopyFnType = Context.getFunctionType(Context.VoidTy, Args, EPI); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1628 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1629 | std::make_pair(".global_tid.", KmpInt32Ty), |
Alexey Bataev | 48591dd | 2016-04-20 04:01:36 +0000 | [diff] [blame] | 1630 | std::make_pair(".part_id.", Context.getPointerType(KmpInt32Ty)), |
| 1631 | std::make_pair(".privates.", Context.VoidPtrTy.withConst()), |
| 1632 | std::make_pair(".copy_fn.", |
| 1633 | Context.getPointerType(CopyFnType).withConst()), |
| 1634 | std::make_pair(".task_t.", Context.VoidPtrTy.withConst()), |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1635 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1636 | }; |
| 1637 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1638 | Params); |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1639 | // Mark this captured region as inlined, because we don't use outlined |
| 1640 | // function directly. |
| 1641 | getCurCapturedRegion()->TheCapturedDecl->addAttr( |
| 1642 | AlwaysInlineAttr::CreateImplicit( |
| 1643 | Context, AlwaysInlineAttr::Keyword_forceinline, SourceRange())); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1644 | break; |
| 1645 | } |
Alexey Bataev | 1e73ef3 | 2016-04-28 12:14:51 +0000 | [diff] [blame] | 1646 | case OMPD_taskloop: |
| 1647 | case OMPD_taskloop_simd: { |
Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 1648 | QualType KmpInt32Ty = |
| 1649 | Context.getIntTypeForBitwidth(/*DestWidth=*/32, /*Signed=*/1); |
| 1650 | QualType KmpUInt64Ty = |
| 1651 | Context.getIntTypeForBitwidth(/*DestWidth=*/64, /*Signed=*/0); |
| 1652 | QualType KmpInt64Ty = |
| 1653 | Context.getIntTypeForBitwidth(/*DestWidth=*/64, /*Signed=*/1); |
| 1654 | QualType Args[] = {Context.VoidPtrTy.withConst().withRestrict()}; |
| 1655 | FunctionProtoType::ExtProtoInfo EPI; |
| 1656 | EPI.Variadic = true; |
| 1657 | QualType CopyFnType = Context.getFunctionType(Context.VoidTy, Args, EPI); |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1658 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 1659 | std::make_pair(".global_tid.", KmpInt32Ty), |
| 1660 | std::make_pair(".part_id.", Context.getPointerType(KmpInt32Ty)), |
| 1661 | std::make_pair(".privates.", |
| 1662 | Context.VoidPtrTy.withConst().withRestrict()), |
| 1663 | std::make_pair( |
| 1664 | ".copy_fn.", |
| 1665 | Context.getPointerType(CopyFnType).withConst().withRestrict()), |
| 1666 | std::make_pair(".task_t.", Context.VoidPtrTy.withConst()), |
| 1667 | std::make_pair(".lb.", KmpUInt64Ty), |
| 1668 | std::make_pair(".ub.", KmpUInt64Ty), std::make_pair(".st.", KmpInt64Ty), |
| 1669 | std::make_pair(".liter.", KmpInt32Ty), |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1670 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1671 | }; |
| 1672 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1673 | Params); |
Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 1674 | // Mark this captured region as inlined, because we don't use outlined |
| 1675 | // function directly. |
| 1676 | getCurCapturedRegion()->TheCapturedDecl->addAttr( |
| 1677 | AlwaysInlineAttr::CreateImplicit( |
| 1678 | Context, AlwaysInlineAttr::Keyword_forceinline, SourceRange())); |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1679 | break; |
| 1680 | } |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 1681 | case OMPD_distribute_parallel_for_simd: |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 1682 | case OMPD_distribute_simd: |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 1683 | case OMPD_distribute_parallel_for: { |
| 1684 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
| 1685 | QualType KmpInt32PtrTy = |
| 1686 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
| 1687 | Sema::CapturedParamNameType Params[] = { |
| 1688 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1689 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1690 | std::make_pair(".previous.lb.", Context.getSizeType()), |
| 1691 | std::make_pair(".previous.ub.", Context.getSizeType()), |
| 1692 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1693 | }; |
| 1694 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1695 | Params); |
| 1696 | break; |
| 1697 | } |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1698 | case OMPD_threadprivate: |
Alexey Bataev | ee9af45 | 2014-11-21 11:33:46 +0000 | [diff] [blame] | 1699 | case OMPD_taskyield: |
| 1700 | case OMPD_barrier: |
| 1701 | case OMPD_taskwait: |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1702 | case OMPD_cancellation_point: |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1703 | case OMPD_cancel: |
Alexey Bataev | ee9af45 | 2014-11-21 11:33:46 +0000 | [diff] [blame] | 1704 | case OMPD_flush: |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1705 | case OMPD_target_enter_data: |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1706 | case OMPD_target_exit_data: |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 1707 | case OMPD_declare_reduction: |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 1708 | case OMPD_declare_simd: |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 1709 | case OMPD_declare_target: |
| 1710 | case OMPD_end_declare_target: |
Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 1711 | case OMPD_target_update: |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1712 | llvm_unreachable("OpenMP Directive is not allowed"); |
| 1713 | case OMPD_unknown: |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1714 | llvm_unreachable("Unknown OpenMP directive"); |
| 1715 | } |
| 1716 | } |
| 1717 | |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1718 | static OMPCapturedExprDecl *buildCaptureDecl(Sema &S, IdentifierInfo *Id, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 1719 | Expr *CaptureExpr, bool WithInit, |
| 1720 | bool AsExpression) { |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 1721 | assert(CaptureExpr); |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 1722 | ASTContext &C = S.getASTContext(); |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 1723 | Expr *Init = AsExpression ? CaptureExpr : CaptureExpr->IgnoreImpCasts(); |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 1724 | QualType Ty = Init->getType(); |
| 1725 | if (CaptureExpr->getObjectKind() == OK_Ordinary && CaptureExpr->isGLValue()) { |
| 1726 | if (S.getLangOpts().CPlusPlus) |
| 1727 | Ty = C.getLValueReferenceType(Ty); |
| 1728 | else { |
| 1729 | Ty = C.getPointerType(Ty); |
| 1730 | ExprResult Res = |
| 1731 | S.CreateBuiltinUnaryOp(CaptureExpr->getExprLoc(), UO_AddrOf, Init); |
| 1732 | if (!Res.isUsable()) |
| 1733 | return nullptr; |
| 1734 | Init = Res.get(); |
| 1735 | } |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 1736 | WithInit = true; |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 1737 | } |
| 1738 | auto *CED = OMPCapturedExprDecl::Create(C, S.CurContext, Id, Ty); |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 1739 | if (!WithInit) |
| 1740 | CED->addAttr(OMPCaptureNoInitAttr::CreateImplicit(C, SourceRange())); |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 1741 | S.CurContext->addHiddenDecl(CED); |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 1742 | S.AddInitializerToDecl(CED, Init, /*DirectInit=*/false, |
| 1743 | /*TypeMayContainAuto=*/true); |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1744 | return CED; |
| 1745 | } |
| 1746 | |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 1747 | static DeclRefExpr *buildCapture(Sema &S, ValueDecl *D, Expr *CaptureExpr, |
| 1748 | bool WithInit) { |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 1749 | OMPCapturedExprDecl *CD; |
| 1750 | if (auto *VD = S.IsOpenMPCapturedDecl(D)) |
| 1751 | CD = cast<OMPCapturedExprDecl>(VD); |
| 1752 | else |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 1753 | CD = buildCaptureDecl(S, D->getIdentifier(), CaptureExpr, WithInit, |
| 1754 | /*AsExpression=*/false); |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1755 | return buildDeclRefExpr(S, CD, CD->getType().getNonReferenceType(), |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 1756 | CaptureExpr->getExprLoc()); |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1757 | } |
| 1758 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 1759 | static ExprResult buildCapture(Sema &S, Expr *CaptureExpr, DeclRefExpr *&Ref) { |
| 1760 | if (!Ref) { |
| 1761 | auto *CD = |
| 1762 | buildCaptureDecl(S, &S.getASTContext().Idents.get(".capture_expr."), |
| 1763 | CaptureExpr, /*WithInit=*/true, /*AsExpression=*/true); |
| 1764 | Ref = buildDeclRefExpr(S, CD, CD->getType().getNonReferenceType(), |
| 1765 | CaptureExpr->getExprLoc()); |
| 1766 | } |
| 1767 | ExprResult Res = Ref; |
| 1768 | if (!S.getLangOpts().CPlusPlus && |
| 1769 | CaptureExpr->getObjectKind() == OK_Ordinary && CaptureExpr->isGLValue() && |
| 1770 | Ref->getType()->isPointerType()) |
| 1771 | Res = S.CreateBuiltinUnaryOp(CaptureExpr->getExprLoc(), UO_Deref, Ref); |
| 1772 | if (!Res.isUsable()) |
| 1773 | return ExprError(); |
| 1774 | return CaptureExpr->isGLValue() ? Res : S.DefaultLvalueConversion(Res.get()); |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 1775 | } |
| 1776 | |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1777 | StmtResult Sema::ActOnOpenMPRegionEnd(StmtResult S, |
| 1778 | ArrayRef<OMPClause *> Clauses) { |
| 1779 | if (!S.isUsable()) { |
| 1780 | ActOnCapturedRegionError(); |
| 1781 | return StmtError(); |
| 1782 | } |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1783 | |
| 1784 | OMPOrderedClause *OC = nullptr; |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1785 | OMPScheduleClause *SC = nullptr; |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1786 | SmallVector<OMPLinearClause *, 4> LCs; |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1787 | // This is required for proper codegen. |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1788 | for (auto *Clause : Clauses) { |
Alexey Bataev | 16dc7b6 | 2015-05-20 03:46:04 +0000 | [diff] [blame] | 1789 | if (isOpenMPPrivate(Clause->getClauseKind()) || |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 1790 | Clause->getClauseKind() == OMPC_copyprivate || |
| 1791 | (getLangOpts().OpenMPUseTLS && |
| 1792 | getASTContext().getTargetInfo().isTLSSupported() && |
| 1793 | Clause->getClauseKind() == OMPC_copyin)) { |
| 1794 | DSAStack->setForceVarCapturing(Clause->getClauseKind() == OMPC_copyin); |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1795 | // Mark all variables in private list clauses as used in inner region. |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1796 | for (auto *VarRef : Clause->children()) { |
| 1797 | if (auto *E = cast_or_null<Expr>(VarRef)) { |
Alexey Bataev | 8bf6b3e | 2015-04-02 13:07:08 +0000 | [diff] [blame] | 1798 | MarkDeclarationsReferencedInExpr(E); |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1799 | } |
| 1800 | } |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 1801 | DSAStack->setForceVarCapturing(/*V=*/false); |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1802 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective())) { |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1803 | // Mark all variables in private list clauses as used in inner region. |
| 1804 | // Required for proper codegen of combined directives. |
| 1805 | // TODO: add processing for other clauses. |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1806 | if (auto *C = OMPClauseWithPreInit::get(Clause)) { |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 1807 | if (auto *DS = cast_or_null<DeclStmt>(C->getPreInitStmt())) { |
| 1808 | for (auto *D : DS->decls()) |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1809 | MarkVariableReferenced(D->getLocation(), cast<VarDecl>(D)); |
| 1810 | } |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 1811 | } |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 1812 | if (auto *C = OMPClauseWithPostUpdate::get(Clause)) { |
| 1813 | if (auto *E = C->getPostUpdateExpr()) |
| 1814 | MarkDeclarationsReferencedInExpr(E); |
| 1815 | } |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1816 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1817 | if (Clause->getClauseKind() == OMPC_schedule) |
| 1818 | SC = cast<OMPScheduleClause>(Clause); |
| 1819 | else if (Clause->getClauseKind() == OMPC_ordered) |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1820 | OC = cast<OMPOrderedClause>(Clause); |
| 1821 | else if (Clause->getClauseKind() == OMPC_linear) |
| 1822 | LCs.push_back(cast<OMPLinearClause>(Clause)); |
| 1823 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1824 | bool ErrorFound = false; |
| 1825 | // OpenMP, 2.7.1 Loop Construct, Restrictions |
| 1826 | // The nonmonotonic modifier cannot be specified if an ordered clause is |
| 1827 | // specified. |
| 1828 | if (SC && |
| 1829 | (SC->getFirstScheduleModifier() == OMPC_SCHEDULE_MODIFIER_nonmonotonic || |
| 1830 | SC->getSecondScheduleModifier() == |
| 1831 | OMPC_SCHEDULE_MODIFIER_nonmonotonic) && |
| 1832 | OC) { |
| 1833 | Diag(SC->getFirstScheduleModifier() == OMPC_SCHEDULE_MODIFIER_nonmonotonic |
| 1834 | ? SC->getFirstScheduleModifierLoc() |
| 1835 | : SC->getSecondScheduleModifierLoc(), |
| 1836 | diag::err_omp_schedule_nonmonotonic_ordered) |
| 1837 | << SourceRange(OC->getLocStart(), OC->getLocEnd()); |
| 1838 | ErrorFound = true; |
| 1839 | } |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1840 | if (!LCs.empty() && OC && OC->getNumForLoops()) { |
| 1841 | for (auto *C : LCs) { |
| 1842 | Diag(C->getLocStart(), diag::err_omp_linear_ordered) |
| 1843 | << SourceRange(OC->getLocStart(), OC->getLocEnd()); |
| 1844 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1845 | ErrorFound = true; |
| 1846 | } |
Alexey Bataev | 113438c | 2015-12-30 12:06:23 +0000 | [diff] [blame] | 1847 | if (isOpenMPWorksharingDirective(DSAStack->getCurrentDirective()) && |
| 1848 | isOpenMPSimdDirective(DSAStack->getCurrentDirective()) && OC && |
| 1849 | OC->getNumForLoops()) { |
| 1850 | Diag(OC->getLocStart(), diag::err_omp_ordered_simd) |
| 1851 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 1852 | ErrorFound = true; |
| 1853 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1854 | if (ErrorFound) { |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1855 | ActOnCapturedRegionError(); |
| 1856 | return StmtError(); |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1857 | } |
| 1858 | return ActOnCapturedRegionEnd(S.get()); |
| 1859 | } |
| 1860 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1861 | static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, |
| 1862 | OpenMPDirectiveKind CurrentRegion, |
| 1863 | const DeclarationNameInfo &CurrentName, |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1864 | OpenMPDirectiveKind CancelRegion, |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1865 | SourceLocation StartLoc) { |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1866 | // Allowed nesting of constructs |
| 1867 | // +------------------+-----------------+------------------------------------+ |
| 1868 | // | Parent directive | Child directive | Closely (!), No-Closely(+), Both(*)| |
| 1869 | // +------------------+-----------------+------------------------------------+ |
| 1870 | // | parallel | parallel | * | |
| 1871 | // | parallel | for | * | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1872 | // | parallel | for simd | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1873 | // | parallel | master | * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1874 | // | parallel | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1875 | // | parallel | simd | * | |
| 1876 | // | parallel | sections | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1877 | // | parallel | section | + | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1878 | // | parallel | single | * | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1879 | // | parallel | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1880 | // | parallel |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1881 | // | parallel |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1882 | // | parallel | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1883 | // | parallel | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1884 | // | parallel | barrier | * | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1885 | // | parallel | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1886 | // | parallel | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1887 | // | parallel | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1888 | // | parallel | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1889 | // | parallel | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1890 | // | parallel | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 1891 | // | parallel | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 1892 | // | parallel | target parallel | * | |
| 1893 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1894 | // | parallel | target enter | * | |
| 1895 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1896 | // | parallel | target exit | * | |
| 1897 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1898 | // | parallel | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1899 | // | parallel | cancellation | | |
| 1900 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1901 | // | parallel | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1902 | // | parallel | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1903 | // | parallel | taskloop simd | * | |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 1904 | // | parallel | distribute | + | |
| 1905 | // | parallel | distribute | + | |
| 1906 | // | | parallel for | | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 1907 | // | parallel | distribute | + | |
| 1908 | // | |parallel for simd| | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 1909 | // | parallel | distribute simd | + | |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 1910 | // | parallel | target simd | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1911 | // +------------------+-----------------+------------------------------------+ |
| 1912 | // | for | parallel | * | |
| 1913 | // | for | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1914 | // | for | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1915 | // | for | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1916 | // | for | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1917 | // | for | simd | * | |
| 1918 | // | for | sections | + | |
| 1919 | // | for | section | + | |
| 1920 | // | for | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1921 | // | for | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1922 | // | for |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1923 | // | for |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1924 | // | for | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1925 | // | for | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1926 | // | for | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1927 | // | for | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1928 | // | for | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1929 | // | for | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1930 | // | for | ordered | * (if construct is ordered) | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1931 | // | for | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1932 | // | for | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 1933 | // | for | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 1934 | // | for | target parallel | * | |
| 1935 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1936 | // | for | target enter | * | |
| 1937 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1938 | // | for | target exit | * | |
| 1939 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1940 | // | for | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1941 | // | for | cancellation | | |
| 1942 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1943 | // | for | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1944 | // | for | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1945 | // | for | taskloop simd | * | |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 1946 | // | for | distribute | + | |
| 1947 | // | for | distribute | + | |
| 1948 | // | | parallel for | | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 1949 | // | for | distribute | + | |
| 1950 | // | |parallel for simd| | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 1951 | // | for | distribute simd | + | |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 1952 | // | for | target parallel | + | |
| 1953 | // | | for simd | | |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 1954 | // | for | target simd | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1955 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1956 | // | master | parallel | * | |
| 1957 | // | master | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1958 | // | master | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1959 | // | master | master | * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1960 | // | master | critical | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1961 | // | master | simd | * | |
| 1962 | // | master | sections | + | |
| 1963 | // | master | section | + | |
| 1964 | // | master | single | + | |
| 1965 | // | master | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1966 | // | master |parallel for simd| * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1967 | // | master |parallel sections| * | |
| 1968 | // | master | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1969 | // | master | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1970 | // | master | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1971 | // | master | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1972 | // | master | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1973 | // | master | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1974 | // | master | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1975 | // | master | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1976 | // | master | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 1977 | // | master | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 1978 | // | master | target parallel | * | |
| 1979 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1980 | // | master | target enter | * | |
| 1981 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1982 | // | master | target exit | * | |
| 1983 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1984 | // | master | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1985 | // | master | cancellation | | |
| 1986 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1987 | // | master | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1988 | // | master | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1989 | // | master | taskloop simd | * | |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 1990 | // | master | distribute | + | |
| 1991 | // | master | distribute | + | |
| 1992 | // | | parallel for | | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 1993 | // | master | distribute | + | |
| 1994 | // | |parallel for simd| | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 1995 | // | master | distribute simd | + | |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 1996 | // | master | target parallel | + | |
| 1997 | // | | for simd | | |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 1998 | // | master | target simd | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1999 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2000 | // | critical | parallel | * | |
| 2001 | // | critical | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2002 | // | critical | for simd | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2003 | // | critical | master | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2004 | // | critical | critical | * (should have different names) | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2005 | // | critical | simd | * | |
| 2006 | // | critical | sections | + | |
| 2007 | // | critical | section | + | |
| 2008 | // | critical | single | + | |
| 2009 | // | critical | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2010 | // | critical |parallel for simd| * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2011 | // | critical |parallel sections| * | |
| 2012 | // | critical | task | * | |
| 2013 | // | critical | taskyield | * | |
| 2014 | // | critical | barrier | + | |
| 2015 | // | critical | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2016 | // | critical | taskgroup | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2017 | // | critical | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2018 | // | critical | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2019 | // | critical | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2020 | // | critical | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2021 | // | critical | target parallel | * | |
| 2022 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2023 | // | critical | target enter | * | |
| 2024 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2025 | // | critical | target exit | * | |
| 2026 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2027 | // | critical | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2028 | // | critical | cancellation | | |
| 2029 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2030 | // | critical | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2031 | // | critical | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2032 | // | critical | taskloop simd | * | |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 2033 | // | critical | distribute | + | |
| 2034 | // | critical | distribute | + | |
| 2035 | // | | parallel for | | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 2036 | // | critical | distribute | + | |
| 2037 | // | |parallel for simd| | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 2038 | // | critical | distribute simd | + | |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 2039 | // | critical | target parallel | + | |
| 2040 | // | | for simd | | |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 2041 | // | critical | target simd | * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2042 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2043 | // | simd | parallel | | |
| 2044 | // | simd | for | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2045 | // | simd | for simd | | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2046 | // | simd | master | | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2047 | // | simd | critical | | |
Alexey Bataev | 1f09221 | 2016-02-02 04:59:52 +0000 | [diff] [blame] | 2048 | // | simd | simd | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2049 | // | simd | sections | | |
| 2050 | // | simd | section | | |
| 2051 | // | simd | single | | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2052 | // | simd | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2053 | // | simd |parallel for simd| | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2054 | // | simd |parallel sections| | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2055 | // | simd | task | | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2056 | // | simd | taskyield | | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2057 | // | simd | barrier | | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2058 | // | simd | taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2059 | // | simd | taskgroup | | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2060 | // | simd | flush | | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2061 | // | simd | ordered | + (with simd clause) | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2062 | // | simd | atomic | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2063 | // | simd | target | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2064 | // | simd | target parallel | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2065 | // | simd | target parallel | | |
| 2066 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2067 | // | simd | target enter | | |
| 2068 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2069 | // | simd | target exit | | |
| 2070 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2071 | // | simd | teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2072 | // | simd | cancellation | | |
| 2073 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2074 | // | simd | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2075 | // | simd | taskloop | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2076 | // | simd | taskloop simd | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2077 | // | simd | distribute | | |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 2078 | // | simd | distribute | | |
| 2079 | // | | parallel for | | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 2080 | // | simd | distribute | | |
| 2081 | // | |parallel for simd| | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 2082 | // | simd | distribute simd | | |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 2083 | // | simd | target parallel | | |
| 2084 | // | | for simd | | |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 2085 | // | simd | target simd | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2086 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2087 | // | for simd | parallel | | |
| 2088 | // | for simd | for | | |
| 2089 | // | for simd | for simd | | |
| 2090 | // | for simd | master | | |
| 2091 | // | for simd | critical | | |
Alexey Bataev | 1f09221 | 2016-02-02 04:59:52 +0000 | [diff] [blame] | 2092 | // | for simd | simd | * | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2093 | // | for simd | sections | | |
| 2094 | // | for simd | section | | |
| 2095 | // | for simd | single | | |
| 2096 | // | for simd | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2097 | // | for simd |parallel for simd| | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2098 | // | for simd |parallel sections| | |
| 2099 | // | for simd | task | | |
| 2100 | // | for simd | taskyield | | |
| 2101 | // | for simd | barrier | | |
| 2102 | // | for simd | taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2103 | // | for simd | taskgroup | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2104 | // | for simd | flush | | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2105 | // | for simd | ordered | + (with simd clause) | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2106 | // | for simd | atomic | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2107 | // | for simd | target | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2108 | // | for simd | target parallel | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2109 | // | for simd | target parallel | | |
| 2110 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2111 | // | for simd | target enter | | |
| 2112 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2113 | // | for simd | target exit | | |
| 2114 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2115 | // | for simd | teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2116 | // | for simd | cancellation | | |
| 2117 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2118 | // | for simd | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2119 | // | for simd | taskloop | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2120 | // | for simd | taskloop simd | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2121 | // | for simd | distribute | | |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 2122 | // | for simd | distribute | | |
| 2123 | // | | parallel for | | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 2124 | // | for simd | distribute | | |
| 2125 | // | |parallel for simd| | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 2126 | // | for simd | distribute simd | | |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 2127 | // | for simd | target parallel | | |
| 2128 | // | | for simd | | |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 2129 | // | for simd | target simd | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2130 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2131 | // | parallel for simd| parallel | | |
| 2132 | // | parallel for simd| for | | |
| 2133 | // | parallel for simd| for simd | | |
| 2134 | // | parallel for simd| master | | |
| 2135 | // | parallel for simd| critical | | |
Alexey Bataev | 1f09221 | 2016-02-02 04:59:52 +0000 | [diff] [blame] | 2136 | // | parallel for simd| simd | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2137 | // | parallel for simd| sections | | |
| 2138 | // | parallel for simd| section | | |
| 2139 | // | parallel for simd| single | | |
| 2140 | // | parallel for simd| parallel for | | |
| 2141 | // | parallel for simd|parallel for simd| | |
| 2142 | // | parallel for simd|parallel sections| | |
| 2143 | // | parallel for simd| task | | |
| 2144 | // | parallel for simd| taskyield | | |
| 2145 | // | parallel for simd| barrier | | |
| 2146 | // | parallel for simd| taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2147 | // | parallel for simd| taskgroup | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2148 | // | parallel for simd| flush | | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2149 | // | parallel for simd| ordered | + (with simd clause) | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2150 | // | parallel for simd| atomic | | |
| 2151 | // | parallel for simd| target | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2152 | // | parallel for simd| target parallel | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2153 | // | parallel for simd| target parallel | | |
| 2154 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2155 | // | parallel for simd| target enter | | |
| 2156 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2157 | // | parallel for simd| target exit | | |
| 2158 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2159 | // | parallel for simd| teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2160 | // | parallel for simd| cancellation | | |
| 2161 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2162 | // | parallel for simd| cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2163 | // | parallel for simd| taskloop | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2164 | // | parallel for simd| taskloop simd | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2165 | // | parallel for simd| distribute | | |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 2166 | // | parallel for simd| distribute | | |
| 2167 | // | | parallel for | | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 2168 | // | parallel for simd| distribute | | |
| 2169 | // | |parallel for simd| | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 2170 | // | parallel for simd| distribute simd | | |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 2171 | // | | for simd | | |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 2172 | // | parallel for simd| target simd | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2173 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2174 | // | sections | parallel | * | |
| 2175 | // | sections | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2176 | // | sections | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2177 | // | sections | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2178 | // | sections | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2179 | // | sections | simd | * | |
| 2180 | // | sections | sections | + | |
| 2181 | // | sections | section | * | |
| 2182 | // | sections | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2183 | // | sections | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2184 | // | sections |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2185 | // | sections |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2186 | // | sections | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2187 | // | sections | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2188 | // | sections | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2189 | // | sections | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2190 | // | sections | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2191 | // | sections | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2192 | // | sections | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2193 | // | sections | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2194 | // | sections | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2195 | // | sections | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2196 | // | sections | target parallel | * | |
| 2197 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2198 | // | sections | target enter | * | |
| 2199 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2200 | // | sections | target exit | * | |
| 2201 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2202 | // | sections | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2203 | // | sections | cancellation | | |
| 2204 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2205 | // | sections | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2206 | // | sections | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2207 | // | sections | taskloop simd | * | |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 2208 | // | sections | distribute | + | |
| 2209 | // | sections | distribute | + | |
| 2210 | // | | parallel for | | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 2211 | // | sections | distribute | + | |
| 2212 | // | |parallel for simd| | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 2213 | // | sections | distribute simd | + | |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 2214 | // | sections | target parallel | + | |
| 2215 | // | | for simd | | |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 2216 | // | sections | target simd | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2217 | // +------------------+-----------------+------------------------------------+ |
| 2218 | // | section | parallel | * | |
| 2219 | // | section | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2220 | // | section | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2221 | // | section | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2222 | // | section | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2223 | // | section | simd | * | |
| 2224 | // | section | sections | + | |
| 2225 | // | section | section | + | |
| 2226 | // | section | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2227 | // | section | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2228 | // | section |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2229 | // | section |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2230 | // | section | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2231 | // | section | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2232 | // | section | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2233 | // | section | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2234 | // | section | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2235 | // | section | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2236 | // | section | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2237 | // | section | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2238 | // | section | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2239 | // | section | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2240 | // | section | target parallel | * | |
| 2241 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2242 | // | section | target enter | * | |
| 2243 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2244 | // | section | target exit | * | |
| 2245 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2246 | // | section | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2247 | // | section | cancellation | | |
| 2248 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2249 | // | section | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2250 | // | section | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2251 | // | section | taskloop simd | * | |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 2252 | // | section | distribute | + | |
| 2253 | // | section | distribute | + | |
| 2254 | // | | parallel for | | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 2255 | // | section | distribute | + | |
| 2256 | // | |parallel for simd| | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 2257 | // | section | distribute simd | + | |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 2258 | // | section | target parallel | + | |
| 2259 | // | | for simd | | |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 2260 | // | section | target simd | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2261 | // +------------------+-----------------+------------------------------------+ |
| 2262 | // | single | parallel | * | |
| 2263 | // | single | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2264 | // | single | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2265 | // | single | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2266 | // | single | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2267 | // | single | simd | * | |
| 2268 | // | single | sections | + | |
| 2269 | // | single | section | + | |
| 2270 | // | single | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2271 | // | single | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2272 | // | single |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2273 | // | single |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2274 | // | single | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2275 | // | single | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2276 | // | single | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2277 | // | single | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2278 | // | single | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2279 | // | single | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2280 | // | single | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2281 | // | single | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2282 | // | single | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2283 | // | single | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2284 | // | single | target parallel | * | |
| 2285 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2286 | // | single | target enter | * | |
| 2287 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2288 | // | single | target exit | * | |
| 2289 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2290 | // | single | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2291 | // | single | cancellation | | |
| 2292 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2293 | // | single | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2294 | // | single | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2295 | // | single | taskloop simd | * | |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 2296 | // | single | distribute | + | |
| 2297 | // | single | distribute | + | |
| 2298 | // | | parallel for | | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 2299 | // | single | distribute | + | |
| 2300 | // | |parallel for simd| | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 2301 | // | single | distribute simd | + | |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 2302 | // | single | target parallel | + | |
| 2303 | // | | for simd | | |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 2304 | // | single | target simd | * | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2305 | // +------------------+-----------------+------------------------------------+ |
| 2306 | // | parallel for | parallel | * | |
| 2307 | // | parallel for | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2308 | // | parallel for | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2309 | // | parallel for | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2310 | // | parallel for | critical | * | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2311 | // | parallel for | simd | * | |
| 2312 | // | parallel for | sections | + | |
| 2313 | // | parallel for | section | + | |
| 2314 | // | parallel for | single | + | |
| 2315 | // | parallel for | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2316 | // | parallel for |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2317 | // | parallel for |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2318 | // | parallel for | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2319 | // | parallel for | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2320 | // | parallel for | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2321 | // | parallel for | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2322 | // | parallel for | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2323 | // | parallel for | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2324 | // | parallel for | ordered | * (if construct is ordered) | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2325 | // | parallel for | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2326 | // | parallel for | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2327 | // | parallel for | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2328 | // | parallel for | target parallel | * | |
| 2329 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2330 | // | parallel for | target enter | * | |
| 2331 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2332 | // | parallel for | target exit | * | |
| 2333 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2334 | // | parallel for | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2335 | // | parallel for | cancellation | | |
| 2336 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2337 | // | parallel for | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2338 | // | parallel for | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2339 | // | parallel for | taskloop simd | * | |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 2340 | // | parallel for | distribute | + | |
| 2341 | // | parallel for | distribute | + | |
| 2342 | // | | parallel for | | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 2343 | // | parallel for | distribute | + | |
| 2344 | // | |parallel for simd| | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 2345 | // | parallel for | distribute simd | + | |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 2346 | // | parallel for | target parallel | + | |
| 2347 | // | | for simd | | |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 2348 | // | parallel for | target simd | * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2349 | // +------------------+-----------------+------------------------------------+ |
| 2350 | // | parallel sections| parallel | * | |
| 2351 | // | parallel sections| for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2352 | // | parallel sections| for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2353 | // | parallel sections| master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2354 | // | parallel sections| critical | + | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2355 | // | parallel sections| simd | * | |
| 2356 | // | parallel sections| sections | + | |
| 2357 | // | parallel sections| section | * | |
| 2358 | // | parallel sections| single | + | |
| 2359 | // | parallel sections| parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2360 | // | parallel sections|parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2361 | // | parallel sections|parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2362 | // | parallel sections| task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2363 | // | parallel sections| taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2364 | // | parallel sections| barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2365 | // | parallel sections| taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2366 | // | parallel sections| taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2367 | // | parallel sections| flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2368 | // | parallel sections| ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2369 | // | parallel sections| atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2370 | // | parallel sections| target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2371 | // | parallel sections| target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2372 | // | parallel sections| target parallel | * | |
| 2373 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2374 | // | parallel sections| target enter | * | |
| 2375 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2376 | // | parallel sections| target exit | * | |
| 2377 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2378 | // | parallel sections| teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2379 | // | parallel sections| cancellation | | |
| 2380 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2381 | // | parallel sections| cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2382 | // | parallel sections| taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2383 | // | parallel sections| taskloop simd | * | |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 2384 | // | parallel sections| distribute | + | |
| 2385 | // | parallel sections| distribute | + | |
| 2386 | // | | parallel for | | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 2387 | // | parallel sections| distribute | + | |
| 2388 | // | |parallel for simd| | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 2389 | // | parallel sections| distribute simd | + | |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 2390 | // | parallel sections| target parallel | + | |
| 2391 | // | | for simd | | |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 2392 | // | parallel sections| target simd | * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2393 | // +------------------+-----------------+------------------------------------+ |
| 2394 | // | task | parallel | * | |
| 2395 | // | task | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2396 | // | task | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2397 | // | task | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2398 | // | task | critical | * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2399 | // | task | simd | * | |
| 2400 | // | task | sections | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2401 | // | task | section | + | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2402 | // | task | single | + | |
| 2403 | // | task | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2404 | // | task |parallel for simd| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2405 | // | task |parallel sections| * | |
| 2406 | // | task | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2407 | // | task | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2408 | // | task | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2409 | // | task | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2410 | // | task | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2411 | // | task | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2412 | // | task | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2413 | // | task | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2414 | // | task | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2415 | // | task | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2416 | // | task | target parallel | * | |
| 2417 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2418 | // | task | target enter | * | |
| 2419 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2420 | // | task | target exit | * | |
| 2421 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2422 | // | task | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2423 | // | task | cancellation | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2424 | // | | point | ! | |
| 2425 | // | task | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2426 | // | task | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2427 | // | task | taskloop simd | * | |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 2428 | // | task | distribute | + | |
| 2429 | // | task | distribute | + | |
| 2430 | // | | parallel for | | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 2431 | // | task | distribute | + | |
| 2432 | // | |parallel for simd| | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 2433 | // | task | distribute simd | + | |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 2434 | // | task | target parallel | + | |
| 2435 | // | | for simd | | |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 2436 | // | task | target simd | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2437 | // +------------------+-----------------+------------------------------------+ |
| 2438 | // | ordered | parallel | * | |
| 2439 | // | ordered | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2440 | // | ordered | for simd | + | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2441 | // | ordered | master | * | |
| 2442 | // | ordered | critical | * | |
| 2443 | // | ordered | simd | * | |
| 2444 | // | ordered | sections | + | |
| 2445 | // | ordered | section | + | |
| 2446 | // | ordered | single | + | |
| 2447 | // | ordered | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2448 | // | ordered |parallel for simd| * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2449 | // | ordered |parallel sections| * | |
| 2450 | // | ordered | task | * | |
| 2451 | // | ordered | taskyield | * | |
| 2452 | // | ordered | barrier | + | |
| 2453 | // | ordered | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2454 | // | ordered | taskgroup | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2455 | // | ordered | flush | * | |
| 2456 | // | ordered | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2457 | // | ordered | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2458 | // | ordered | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2459 | // | ordered | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2460 | // | ordered | target parallel | * | |
| 2461 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2462 | // | ordered | target enter | * | |
| 2463 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2464 | // | ordered | target exit | * | |
| 2465 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2466 | // | ordered | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2467 | // | ordered | cancellation | | |
| 2468 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2469 | // | ordered | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2470 | // | ordered | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2471 | // | ordered | taskloop simd | * | |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 2472 | // | ordered | distribute | + | |
| 2473 | // | ordered | distribute | + | |
| 2474 | // | | parallel for | | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 2475 | // | ordered | distribute | + | |
| 2476 | // | |parallel for simd| | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 2477 | // | ordered | distribute simd | + | |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 2478 | // | ordered | target parallel | + | |
| 2479 | // | | for simd | | |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 2480 | // | ordered | target simd | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2481 | // +------------------+-----------------+------------------------------------+ |
| 2482 | // | atomic | parallel | | |
| 2483 | // | atomic | for | | |
| 2484 | // | atomic | for simd | | |
| 2485 | // | atomic | master | | |
| 2486 | // | atomic | critical | | |
| 2487 | // | atomic | simd | | |
| 2488 | // | atomic | sections | | |
| 2489 | // | atomic | section | | |
| 2490 | // | atomic | single | | |
| 2491 | // | atomic | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2492 | // | atomic |parallel for simd| | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2493 | // | atomic |parallel sections| | |
| 2494 | // | atomic | task | | |
| 2495 | // | atomic | taskyield | | |
| 2496 | // | atomic | barrier | | |
| 2497 | // | atomic | taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2498 | // | atomic | taskgroup | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2499 | // | atomic | flush | | |
| 2500 | // | atomic | ordered | | |
| 2501 | // | atomic | atomic | | |
| 2502 | // | atomic | target | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2503 | // | atomic | target parallel | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2504 | // | atomic | target parallel | | |
| 2505 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2506 | // | atomic | target enter | | |
| 2507 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2508 | // | atomic | target exit | | |
| 2509 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2510 | // | atomic | teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2511 | // | atomic | cancellation | | |
| 2512 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2513 | // | atomic | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2514 | // | atomic | taskloop | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2515 | // | atomic | taskloop simd | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2516 | // | atomic | distribute | | |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 2517 | // | atomic | distribute | | |
| 2518 | // | | parallel for | | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 2519 | // | atomic | distribute | | |
| 2520 | // | |parallel for simd| | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 2521 | // | atomic | distribute simd | | |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 2522 | // | atomic | target parallel | | |
| 2523 | // | | for simd | | |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 2524 | // | atomic | target simd | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2525 | // +------------------+-----------------+------------------------------------+ |
| 2526 | // | target | parallel | * | |
| 2527 | // | target | for | * | |
| 2528 | // | target | for simd | * | |
| 2529 | // | target | master | * | |
| 2530 | // | target | critical | * | |
| 2531 | // | target | simd | * | |
| 2532 | // | target | sections | * | |
| 2533 | // | target | section | * | |
| 2534 | // | target | single | * | |
| 2535 | // | target | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2536 | // | target |parallel for simd| * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2537 | // | target |parallel sections| * | |
| 2538 | // | target | task | * | |
| 2539 | // | target | taskyield | * | |
| 2540 | // | target | barrier | * | |
| 2541 | // | target | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2542 | // | target | taskgroup | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2543 | // | target | flush | * | |
| 2544 | // | target | ordered | * | |
| 2545 | // | target | atomic | * | |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2546 | // | target | target | | |
| 2547 | // | target | target parallel | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2548 | // | target | target parallel | | |
| 2549 | // | | for | | |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2550 | // | target | target enter | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2551 | // | | data | | |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2552 | // | target | target exit | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2553 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2554 | // | target | teams | * | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2555 | // | target | cancellation | | |
| 2556 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2557 | // | target | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2558 | // | target | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2559 | // | target | taskloop simd | * | |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 2560 | // | target | distribute | + | |
| 2561 | // | target | distribute | + | |
| 2562 | // | | parallel for | | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 2563 | // | target | distribute | + | |
| 2564 | // | |parallel for simd| | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 2565 | // | target | distribute simd | + | |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 2566 | // | target | target parallel | | |
| 2567 | // | | for simd | | |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 2568 | // | target | target simd | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2569 | // +------------------+-----------------+------------------------------------+ |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2570 | // | target parallel | parallel | * | |
| 2571 | // | target parallel | for | * | |
| 2572 | // | target parallel | for simd | * | |
| 2573 | // | target parallel | master | * | |
| 2574 | // | target parallel | critical | * | |
| 2575 | // | target parallel | simd | * | |
| 2576 | // | target parallel | sections | * | |
| 2577 | // | target parallel | section | * | |
| 2578 | // | target parallel | single | * | |
| 2579 | // | target parallel | parallel for | * | |
| 2580 | // | target parallel |parallel for simd| * | |
| 2581 | // | target parallel |parallel sections| * | |
| 2582 | // | target parallel | task | * | |
| 2583 | // | target parallel | taskyield | * | |
| 2584 | // | target parallel | barrier | * | |
| 2585 | // | target parallel | taskwait | * | |
| 2586 | // | target parallel | taskgroup | * | |
| 2587 | // | target parallel | flush | * | |
| 2588 | // | target parallel | ordered | * | |
| 2589 | // | target parallel | atomic | * | |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2590 | // | target parallel | target | | |
| 2591 | // | target parallel | target parallel | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2592 | // | target parallel | target parallel | | |
| 2593 | // | | for | | |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2594 | // | target parallel | target enter | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2595 | // | | data | | |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2596 | // | target parallel | target exit | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2597 | // | | data | | |
| 2598 | // | target parallel | teams | | |
| 2599 | // | target parallel | cancellation | | |
| 2600 | // | | point | ! | |
| 2601 | // | target parallel | cancel | ! | |
| 2602 | // | target parallel | taskloop | * | |
| 2603 | // | target parallel | taskloop simd | * | |
| 2604 | // | target parallel | distribute | | |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 2605 | // | target parallel | distribute | | |
| 2606 | // | | parallel for | | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 2607 | // | target parallel | distribute | | |
| 2608 | // | |parallel for simd| | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 2609 | // | target parallel | distribute simd | | |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 2610 | // | target parallel | target parallel | | |
| 2611 | // | | for simd | | |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 2612 | // | target parallel | target simd | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2613 | // +------------------+-----------------+------------------------------------+ |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2614 | // | target parallel | parallel | * | |
| 2615 | // | for | | | |
| 2616 | // | target parallel | for | * | |
| 2617 | // | for | | | |
| 2618 | // | target parallel | for simd | * | |
| 2619 | // | for | | | |
| 2620 | // | target parallel | master | * | |
| 2621 | // | for | | | |
| 2622 | // | target parallel | critical | * | |
| 2623 | // | for | | | |
| 2624 | // | target parallel | simd | * | |
| 2625 | // | for | | | |
| 2626 | // | target parallel | sections | * | |
| 2627 | // | for | | | |
| 2628 | // | target parallel | section | * | |
| 2629 | // | for | | | |
| 2630 | // | target parallel | single | * | |
| 2631 | // | for | | | |
| 2632 | // | target parallel | parallel for | * | |
| 2633 | // | for | | | |
| 2634 | // | target parallel |parallel for simd| * | |
| 2635 | // | for | | | |
| 2636 | // | target parallel |parallel sections| * | |
| 2637 | // | for | | | |
| 2638 | // | target parallel | task | * | |
| 2639 | // | for | | | |
| 2640 | // | target parallel | taskyield | * | |
| 2641 | // | for | | | |
| 2642 | // | target parallel | barrier | * | |
| 2643 | // | for | | | |
| 2644 | // | target parallel | taskwait | * | |
| 2645 | // | for | | | |
| 2646 | // | target parallel | taskgroup | * | |
| 2647 | // | for | | | |
| 2648 | // | target parallel | flush | * | |
| 2649 | // | for | | | |
| 2650 | // | target parallel | ordered | * | |
| 2651 | // | for | | | |
| 2652 | // | target parallel | atomic | * | |
| 2653 | // | for | | | |
| 2654 | // | target parallel | target | | |
| 2655 | // | for | | | |
| 2656 | // | target parallel | target parallel | | |
| 2657 | // | for | | | |
| 2658 | // | target parallel | target parallel | | |
| 2659 | // | for | for | | |
| 2660 | // | target parallel | target enter | | |
| 2661 | // | for | data | | |
| 2662 | // | target parallel | target exit | | |
| 2663 | // | for | data | | |
| 2664 | // | target parallel | teams | | |
| 2665 | // | for | | | |
| 2666 | // | target parallel | cancellation | | |
| 2667 | // | for | point | ! | |
| 2668 | // | target parallel | cancel | ! | |
| 2669 | // | for | | | |
| 2670 | // | target parallel | taskloop | * | |
| 2671 | // | for | | | |
| 2672 | // | target parallel | taskloop simd | * | |
| 2673 | // | for | | | |
| 2674 | // | target parallel | distribute | | |
| 2675 | // | for | | | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 2676 | // | target parallel | distribute | | |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 2677 | // | for | parallel for | | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 2678 | // | target parallel | distribute | | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 2679 | // | for |parallel for simd| | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 2680 | // | target parallel | distribute simd | | |
| 2681 | // | for | | | |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 2682 | // | target parallel | target parallel | | |
| 2683 | // | for | for simd | | |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 2684 | // | target parallel | target simd | | |
| 2685 | // | for | | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2686 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2687 | // | teams | parallel | * | |
| 2688 | // | teams | for | + | |
| 2689 | // | teams | for simd | + | |
| 2690 | // | teams | master | + | |
| 2691 | // | teams | critical | + | |
| 2692 | // | teams | simd | + | |
| 2693 | // | teams | sections | + | |
| 2694 | // | teams | section | + | |
| 2695 | // | teams | single | + | |
| 2696 | // | teams | parallel for | * | |
| 2697 | // | teams |parallel for simd| * | |
| 2698 | // | teams |parallel sections| * | |
| 2699 | // | teams | task | + | |
| 2700 | // | teams | taskyield | + | |
| 2701 | // | teams | barrier | + | |
| 2702 | // | teams | taskwait | + | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2703 | // | teams | taskgroup | + | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2704 | // | teams | flush | + | |
| 2705 | // | teams | ordered | + | |
| 2706 | // | teams | atomic | + | |
| 2707 | // | teams | target | + | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2708 | // | teams | target parallel | + | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2709 | // | teams | target parallel | + | |
| 2710 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2711 | // | teams | target enter | + | |
| 2712 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2713 | // | teams | target exit | + | |
| 2714 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2715 | // | teams | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2716 | // | teams | cancellation | | |
| 2717 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2718 | // | teams | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2719 | // | teams | taskloop | + | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2720 | // | teams | taskloop simd | + | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2721 | // | teams | distribute | ! | |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 2722 | // | teams | distribute | ! | |
| 2723 | // | | parallel for | | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 2724 | // | teams | distribute | ! | |
| 2725 | // | |parallel for simd| | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 2726 | // | teams | distribute simd | ! | |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 2727 | // | teams | target parallel | + | |
| 2728 | // | | for simd | | |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 2729 | // | teams | target simd | + | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2730 | // +------------------+-----------------+------------------------------------+ |
| 2731 | // | taskloop | parallel | * | |
| 2732 | // | taskloop | for | + | |
| 2733 | // | taskloop | for simd | + | |
| 2734 | // | taskloop | master | + | |
| 2735 | // | taskloop | critical | * | |
| 2736 | // | taskloop | simd | * | |
| 2737 | // | taskloop | sections | + | |
| 2738 | // | taskloop | section | + | |
| 2739 | // | taskloop | single | + | |
| 2740 | // | taskloop | parallel for | * | |
| 2741 | // | taskloop |parallel for simd| * | |
| 2742 | // | taskloop |parallel sections| * | |
| 2743 | // | taskloop | task | * | |
| 2744 | // | taskloop | taskyield | * | |
| 2745 | // | taskloop | barrier | + | |
| 2746 | // | taskloop | taskwait | * | |
| 2747 | // | taskloop | taskgroup | * | |
| 2748 | // | taskloop | flush | * | |
| 2749 | // | taskloop | ordered | + | |
| 2750 | // | taskloop | atomic | * | |
| 2751 | // | taskloop | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2752 | // | taskloop | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2753 | // | taskloop | target parallel | * | |
| 2754 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2755 | // | taskloop | target enter | * | |
| 2756 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2757 | // | taskloop | target exit | * | |
| 2758 | // | | data | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2759 | // | taskloop | teams | + | |
| 2760 | // | taskloop | cancellation | | |
| 2761 | // | | point | | |
| 2762 | // | taskloop | cancel | | |
| 2763 | // | taskloop | taskloop | * | |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 2764 | // | taskloop | distribute | + | |
| 2765 | // | taskloop | distribute | + | |
| 2766 | // | | parallel for | | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 2767 | // | taskloop | distribute | + | |
| 2768 | // | |parallel for simd| | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 2769 | // | taskloop | distribute simd | + | |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 2770 | // | taskloop | target parallel | * | |
| 2771 | // | | for simd | | |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 2772 | // | taskloop | target simd | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2773 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2774 | // | taskloop simd | parallel | | |
| 2775 | // | taskloop simd | for | | |
| 2776 | // | taskloop simd | for simd | | |
| 2777 | // | taskloop simd | master | | |
| 2778 | // | taskloop simd | critical | | |
Alexey Bataev | 1f09221 | 2016-02-02 04:59:52 +0000 | [diff] [blame] | 2779 | // | taskloop simd | simd | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2780 | // | taskloop simd | sections | | |
| 2781 | // | taskloop simd | section | | |
| 2782 | // | taskloop simd | single | | |
| 2783 | // | taskloop simd | parallel for | | |
| 2784 | // | taskloop simd |parallel for simd| | |
| 2785 | // | taskloop simd |parallel sections| | |
| 2786 | // | taskloop simd | task | | |
| 2787 | // | taskloop simd | taskyield | | |
| 2788 | // | taskloop simd | barrier | | |
| 2789 | // | taskloop simd | taskwait | | |
| 2790 | // | taskloop simd | taskgroup | | |
| 2791 | // | taskloop simd | flush | | |
| 2792 | // | taskloop simd | ordered | + (with simd clause) | |
| 2793 | // | taskloop simd | atomic | | |
| 2794 | // | taskloop simd | target | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2795 | // | taskloop simd | target parallel | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2796 | // | taskloop simd | target parallel | | |
| 2797 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2798 | // | taskloop simd | target enter | | |
| 2799 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2800 | // | taskloop simd | target exit | | |
| 2801 | // | | data | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2802 | // | taskloop simd | teams | | |
| 2803 | // | taskloop simd | cancellation | | |
| 2804 | // | | point | | |
| 2805 | // | taskloop simd | cancel | | |
| 2806 | // | taskloop simd | taskloop | | |
| 2807 | // | taskloop simd | taskloop simd | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2808 | // | taskloop simd | distribute | | |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 2809 | // | taskloop simd | distribute | | |
| 2810 | // | | parallel for | | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 2811 | // | taskloop simd | distribute | | |
| 2812 | // | |parallel for simd| | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 2813 | // | taskloop simd | distribute simd | | |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 2814 | // | taskloop simd | target parallel | | |
| 2815 | // | | for simd | | |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 2816 | // | taskloop simd | target simd | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2817 | // +------------------+-----------------+------------------------------------+ |
| 2818 | // | distribute | parallel | * | |
| 2819 | // | distribute | for | * | |
| 2820 | // | distribute | for simd | * | |
| 2821 | // | distribute | master | * | |
| 2822 | // | distribute | critical | * | |
| 2823 | // | distribute | simd | * | |
| 2824 | // | distribute | sections | * | |
| 2825 | // | distribute | section | * | |
| 2826 | // | distribute | single | * | |
| 2827 | // | distribute | parallel for | * | |
| 2828 | // | distribute |parallel for simd| * | |
| 2829 | // | distribute |parallel sections| * | |
| 2830 | // | distribute | task | * | |
| 2831 | // | distribute | taskyield | * | |
| 2832 | // | distribute | barrier | * | |
| 2833 | // | distribute | taskwait | * | |
| 2834 | // | distribute | taskgroup | * | |
| 2835 | // | distribute | flush | * | |
| 2836 | // | distribute | ordered | + | |
| 2837 | // | distribute | atomic | * | |
| 2838 | // | distribute | target | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2839 | // | distribute | target parallel | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2840 | // | distribute | target parallel | | |
| 2841 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2842 | // | distribute | target enter | | |
| 2843 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2844 | // | distribute | target exit | | |
| 2845 | // | | data | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2846 | // | distribute | teams | | |
| 2847 | // | distribute | cancellation | + | |
| 2848 | // | | point | | |
| 2849 | // | distribute | cancel | + | |
| 2850 | // | distribute | taskloop | * | |
| 2851 | // | distribute | taskloop simd | * | |
| 2852 | // | distribute | distribute | | |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 2853 | // | distribute | distribute | | |
| 2854 | // | | parallel for | | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 2855 | // | distribute | distribute | | |
| 2856 | // | |parallel for simd| | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 2857 | // | distribute | distribute simd | | |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 2858 | // | distribute | target parallel | | |
| 2859 | // | | for simd | | |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 2860 | // | distribute | target simd | | |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 2861 | // +------------------+-----------------+------------------------------------+ |
| 2862 | // | distribute | parallel | * | |
| 2863 | // | parallel for | | | |
| 2864 | // | distribute | for | * | |
| 2865 | // | parallel for | | | |
| 2866 | // | distribute | for simd | * | |
| 2867 | // | parallel for | | | |
| 2868 | // | distribute | master | * | |
| 2869 | // | parallel for | | | |
| 2870 | // | distribute | critical | * | |
| 2871 | // | parallel for | | | |
| 2872 | // | distribute | simd | * | |
| 2873 | // | parallel for | | | |
| 2874 | // | distribute | sections | * | |
| 2875 | // | parallel for | | | |
| 2876 | // | distribute | section | * | |
| 2877 | // | parallel for | | | |
| 2878 | // | distribute | single | * | |
| 2879 | // | parallel for | | | |
| 2880 | // | distribute | parallel for | * | |
| 2881 | // | parallel for | | | |
| 2882 | // | distribute |parallel for simd| * | |
| 2883 | // | parallel for | | | |
| 2884 | // | distribute |parallel sections| * | |
| 2885 | // | parallel for | | | |
| 2886 | // | distribute | task | * | |
| 2887 | // | parallel for | | | |
| 2888 | // | parallel for | | | |
| 2889 | // | distribute | taskyield | * | |
| 2890 | // | parallel for | | | |
| 2891 | // | distribute | barrier | * | |
| 2892 | // | parallel for | | | |
| 2893 | // | distribute | taskwait | * | |
| 2894 | // | parallel for | | | |
| 2895 | // | distribute | taskgroup | * | |
| 2896 | // | parallel for | | | |
| 2897 | // | distribute | flush | * | |
| 2898 | // | parallel for | | | |
| 2899 | // | distribute | ordered | + | |
| 2900 | // | parallel for | | | |
| 2901 | // | distribute | atomic | * | |
| 2902 | // | parallel for | | | |
| 2903 | // | distribute | target | | |
| 2904 | // | parallel for | | | |
| 2905 | // | distribute | target parallel | | |
| 2906 | // | parallel for | | | |
| 2907 | // | distribute | target parallel | | |
| 2908 | // | parallel for | for | | |
| 2909 | // | distribute | target enter | | |
| 2910 | // | parallel for | data | | |
| 2911 | // | distribute | target exit | | |
| 2912 | // | parallel for | data | | |
| 2913 | // | distribute | teams | | |
| 2914 | // | parallel for | | | |
| 2915 | // | distribute | cancellation | + | |
| 2916 | // | parallel for | point | | |
| 2917 | // | distribute | cancel | + | |
| 2918 | // | parallel for | | | |
| 2919 | // | distribute | taskloop | * | |
| 2920 | // | parallel for | | | |
| 2921 | // | distribute | taskloop simd | * | |
| 2922 | // | parallel for | | | |
| 2923 | // | distribute | distribute | | |
| 2924 | // | parallel for | | | |
| 2925 | // | distribute | distribute | | |
| 2926 | // | parallel for | parallel for | | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 2927 | // | distribute | distribute | | |
| 2928 | // | parallel for |parallel for simd| | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 2929 | // | distribute | distribute simd | | |
| 2930 | // | parallel for | | | |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 2931 | // | distribute | target parallel | | |
| 2932 | // | parallel for | for simd | | |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 2933 | // | distribute | target simd | | |
| 2934 | // | parallel for | | | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 2935 | // +------------------+-----------------+------------------------------------+ |
| 2936 | // | distribute | parallel | * | |
| 2937 | // | parallel for simd| | | |
| 2938 | // | distribute | for | * | |
| 2939 | // | parallel for simd| | | |
| 2940 | // | distribute | for simd | * | |
| 2941 | // | parallel for simd| | | |
| 2942 | // | distribute | master | * | |
| 2943 | // | parallel for simd| | | |
| 2944 | // | distribute | critical | * | |
| 2945 | // | parallel for simd| | | |
| 2946 | // | distribute | simd | * | |
| 2947 | // | parallel for simd| | | |
| 2948 | // | distribute | sections | * | |
| 2949 | // | parallel for simd| | | |
| 2950 | // | distribute | section | * | |
| 2951 | // | parallel for simd| | | |
| 2952 | // | distribute | single | * | |
| 2953 | // | parallel for simd| | | |
| 2954 | // | distribute | parallel for | * | |
| 2955 | // | parallel for simd| | | |
| 2956 | // | distribute |parallel for simd| * | |
| 2957 | // | parallel for simd| | | |
| 2958 | // | distribute |parallel sections| * | |
| 2959 | // | parallel for simd| | | |
| 2960 | // | distribute | task | * | |
| 2961 | // | parallel for simd| | | |
| 2962 | // | distribute | taskyield | * | |
| 2963 | // | parallel for simd| | | |
| 2964 | // | distribute | barrier | * | |
| 2965 | // | parallel for simd| | | |
| 2966 | // | distribute | taskwait | * | |
| 2967 | // | parallel for simd| | | |
| 2968 | // | distribute | taskgroup | * | |
| 2969 | // | parallel for simd| | | |
| 2970 | // | distribute | flush | * | |
| 2971 | // | parallel for simd| | | |
| 2972 | // | distribute | ordered | + | |
| 2973 | // | parallel for simd| | | |
| 2974 | // | distribute | atomic | * | |
| 2975 | // | parallel for simd| | | |
| 2976 | // | distribute | target | | |
| 2977 | // | parallel for simd| | | |
| 2978 | // | distribute | target parallel | | |
| 2979 | // | parallel for simd| | | |
| 2980 | // | distribute | target parallel | | |
| 2981 | // | parallel for simd| for | | |
| 2982 | // | distribute | target enter | | |
| 2983 | // | parallel for simd| data | | |
| 2984 | // | distribute | target exit | | |
| 2985 | // | parallel for simd| data | | |
| 2986 | // | distribute | teams | | |
| 2987 | // | parallel for simd| | | |
| 2988 | // | distribute | cancellation | + | |
| 2989 | // | parallel for simd| point | | |
| 2990 | // | distribute | cancel | + | |
| 2991 | // | parallel for simd| | | |
| 2992 | // | distribute | taskloop | * | |
| 2993 | // | parallel for simd| | | |
| 2994 | // | distribute | taskloop simd | * | |
| 2995 | // | parallel for simd| | | |
| 2996 | // | distribute | distribute | | |
| 2997 | // | parallel for simd| | | |
| 2998 | // | distribute | distribute | * | |
| 2999 | // | parallel for simd| parallel for | | |
| 3000 | // | distribute | distribute | * | |
| 3001 | // | parallel for simd|parallel for simd| | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 3002 | // | distribute | distribute simd | * | |
| 3003 | // | parallel for simd| | | |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 3004 | // | distribute | target parallel | | |
| 3005 | // | parallel for simd| for simd | | |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 3006 | // | distribute | target simd | | |
| 3007 | // | parallel for simd| | | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 3008 | // +------------------+-----------------+------------------------------------+ |
| 3009 | // | distribute simd | parallel | * | |
| 3010 | // | distribute simd | for | * | |
| 3011 | // | distribute simd | for simd | * | |
| 3012 | // | distribute simd | master | * | |
| 3013 | // | distribute simd | critical | * | |
| 3014 | // | distribute simd | simd | * | |
| 3015 | // | distribute simd | sections | * | |
| 3016 | // | distribute simd | section | * | |
| 3017 | // | distribute simd | single | * | |
| 3018 | // | distribute simd | parallel for | * | |
| 3019 | // | distribute simd |parallel for simd| * | |
| 3020 | // | distribute simd |parallel sections| * | |
| 3021 | // | distribute simd | task | * | |
| 3022 | // | distribute simd | taskyield | * | |
| 3023 | // | distribute simd | barrier | * | |
| 3024 | // | distribute simd | taskwait | * | |
| 3025 | // | distribute simd | taskgroup | * | |
| 3026 | // | distribute simd | flush | * | |
| 3027 | // | distribute simd | ordered | + | |
| 3028 | // | distribute simd | atomic | * | |
| 3029 | // | distribute simd | target | * | |
| 3030 | // | distribute simd | target parallel | * | |
| 3031 | // | distribute simd | target parallel | * | |
| 3032 | // | | for | | |
| 3033 | // | distribute simd | target enter | * | |
| 3034 | // | | data | | |
| 3035 | // | distribute simd | target exit | * | |
| 3036 | // | | data | | |
| 3037 | // | distribute simd | teams | * | |
| 3038 | // | distribute simd | cancellation | + | |
| 3039 | // | | point | | |
| 3040 | // | distribute simd | cancel | + | |
| 3041 | // | distribute simd | taskloop | * | |
| 3042 | // | distribute simd | taskloop simd | * | |
| 3043 | // | distribute simd | distribute | | |
| 3044 | // | distribute simd | distribute | * | |
| 3045 | // | | parallel for | | |
| 3046 | // | distribute simd | distribute | * | |
| 3047 | // | |parallel for simd| | |
| 3048 | // | distribute simd | distribute simd | * | |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 3049 | // | distribute simd | target parallel | * | |
| 3050 | // | | for simd | | |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 3051 | // | distribute simd | target simd | * | |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 3052 | // +------------------+-----------------+------------------------------------+ |
| 3053 | // | target parallel | parallel | * | |
| 3054 | // | for simd | | | |
| 3055 | // | target parallel | for | * | |
| 3056 | // | for simd | | | |
| 3057 | // | target parallel | for simd | * | |
| 3058 | // | for simd | | | |
| 3059 | // | target parallel | master | * | |
| 3060 | // | for simd | | | |
| 3061 | // | target parallel | critical | * | |
| 3062 | // | for simd | | | |
| 3063 | // | target parallel | simd | ! | |
| 3064 | // | for simd | | | |
| 3065 | // | target parallel | sections | * | |
| 3066 | // | for simd | | | |
| 3067 | // | target parallel | section | * | |
| 3068 | // | for simd | | | |
| 3069 | // | target parallel | single | * | |
| 3070 | // | for simd | | | |
| 3071 | // | target parallel | parallel for | * | |
| 3072 | // | for simd | | | |
| 3073 | // | target parallel |parallel for simd| * | |
| 3074 | // | for simd | | | |
| 3075 | // | target parallel |parallel sections| * | |
| 3076 | // | for simd | | | |
| 3077 | // | target parallel | task | * | |
| 3078 | // | for simd | | | |
| 3079 | // | target parallel | taskyield | * | |
| 3080 | // | for simd | | | |
| 3081 | // | target parallel | barrier | * | |
| 3082 | // | for simd | | | |
| 3083 | // | target parallel | taskwait | * | |
| 3084 | // | for simd | | | |
| 3085 | // | target parallel | taskgroup | * | |
| 3086 | // | for simd | | | |
| 3087 | // | target parallel | flush | * | |
| 3088 | // | for simd | | | |
| 3089 | // | target parallel | ordered | + (with simd clause) | |
| 3090 | // | for simd | | | |
| 3091 | // | target parallel | atomic | * | |
| 3092 | // | for simd | | | |
| 3093 | // | target parallel | target | * | |
| 3094 | // | for simd | | | |
| 3095 | // | target parallel | target parallel | * | |
| 3096 | // | for simd | | | |
| 3097 | // | target parallel | target parallel | * | |
| 3098 | // | for simd | for | | |
| 3099 | // | target parallel | target enter | * | |
| 3100 | // | for simd | data | | |
| 3101 | // | target parallel | target exit | * | |
| 3102 | // | for simd | data | | |
| 3103 | // | target parallel | teams | * | |
| 3104 | // | for simd | | | |
| 3105 | // | target parallel | cancellation | * | |
| 3106 | // | for simd | point | | |
| 3107 | // | target parallel | cancel | * | |
| 3108 | // | for simd | | | |
| 3109 | // | target parallel | taskloop | * | |
| 3110 | // | for simd | | | |
| 3111 | // | target parallel | taskloop simd | * | |
| 3112 | // | for simd | | | |
| 3113 | // | target parallel | distribute | * | |
| 3114 | // | for simd | | | |
| 3115 | // | target parallel | distribute | * | |
| 3116 | // | for simd | parallel for | | |
| 3117 | // | target parallel | distribute | * | |
| 3118 | // | for simd |parallel for simd| | |
| 3119 | // | target parallel | distribute simd | * | |
| 3120 | // | for simd | | | |
| 3121 | // | target parallel | target parallel | * | |
| 3122 | // | for simd | for simd | | |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 3123 | // | target parallel | target simd | * | |
| 3124 | // | for simd | | | |
| 3125 | // +------------------+-----------------+------------------------------------+ |
| 3126 | // | target simd | parallel | | |
| 3127 | // | target simd | for | | |
| 3128 | // | target simd | for simd | | |
| 3129 | // | target simd | master | | |
| 3130 | // | target simd | critical | | |
| 3131 | // | target simd | simd | | |
| 3132 | // | target simd | sections | | |
| 3133 | // | target simd | section | | |
| 3134 | // | target simd | single | | |
| 3135 | // | target simd | parallel for | | |
| 3136 | // | target simd |parallel for simd| | |
| 3137 | // | target simd |parallel sections| | |
| 3138 | // | target simd | task | | |
| 3139 | // | target simd | taskyield | | |
| 3140 | // | target simd | barrier | | |
| 3141 | // | target simd | taskwait | | |
| 3142 | // | target simd | taskgroup | | |
| 3143 | // | target simd | flush | | |
| 3144 | // | target simd | ordered | + (with simd clause) | |
| 3145 | // | target simd | atomic | | |
| 3146 | // | target simd | target | | |
| 3147 | // | target simd | target parallel | | |
| 3148 | // | target simd | target parallel | | |
| 3149 | // | | for | | |
| 3150 | // | target simd | target enter | | |
| 3151 | // | | data | | |
| 3152 | // | target simd | target exit | | |
| 3153 | // | | data | | |
| 3154 | // | target simd | teams | | |
| 3155 | // | target simd | cancellation | | |
| 3156 | // | | point | | |
| 3157 | // | target simd | cancel | | |
| 3158 | // | target simd | taskloop | | |
| 3159 | // | target simd | taskloop simd | | |
| 3160 | // | target simd | distribute | | |
| 3161 | // | target simd | distribute | | |
| 3162 | // | | parallel for | | |
| 3163 | // | target simd | distribute | | |
| 3164 | // | |parallel for simd| | |
| 3165 | // | target simd | distribute simd | | |
| 3166 | // | target simd | target parallel | | |
| 3167 | // | | for simd | | |
| 3168 | // | target simd | target simd | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 3169 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 3170 | if (Stack->getCurScope()) { |
| 3171 | auto ParentRegion = Stack->getParentDirective(); |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 3172 | auto OffendingRegion = ParentRegion; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 3173 | bool NestingProhibited = false; |
| 3174 | bool CloseNesting = true; |
Kelvin Li | 2b51f72 | 2016-07-26 04:32:50 +0000 | [diff] [blame] | 3175 | bool OrphanSeen = false; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 3176 | enum { |
| 3177 | NoRecommend, |
| 3178 | ShouldBeInParallelRegion, |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 3179 | ShouldBeInOrderedRegion, |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 3180 | ShouldBeInTargetRegion, |
| 3181 | ShouldBeInTeamsRegion |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 3182 | } Recommend = NoRecommend; |
Kelvin Li | fd8b574 | 2016-07-01 14:30:25 +0000 | [diff] [blame] | 3183 | if (isOpenMPSimdDirective(ParentRegion) && CurrentRegion != OMPD_ordered) { |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 3184 | // OpenMP [2.16, Nesting of Regions] |
| 3185 | // OpenMP constructs may not be nested inside a simd region. |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 3186 | // OpenMP [2.8.1,simd Construct, Restrictions] |
Kelvin Li | fd8b574 | 2016-07-01 14:30:25 +0000 | [diff] [blame] | 3187 | // An ordered construct with the simd clause is the only OpenMP |
| 3188 | // construct that can appear in the simd region. |
| 3189 | // Allowing a SIMD consruct nested in another SIMD construct is an |
| 3190 | // extension. The OpenMP 4.5 spec does not allow it. Issue a warning |
| 3191 | // message. |
| 3192 | SemaRef.Diag(StartLoc, (CurrentRegion != OMPD_simd) |
| 3193 | ? diag::err_omp_prohibited_region_simd |
| 3194 | : diag::warn_omp_nesting_simd); |
| 3195 | return CurrentRegion != OMPD_simd; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 3196 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 3197 | if (ParentRegion == OMPD_atomic) { |
| 3198 | // OpenMP [2.16, Nesting of Regions] |
| 3199 | // OpenMP constructs may not be nested inside an atomic region. |
| 3200 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region_atomic); |
| 3201 | return true; |
| 3202 | } |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 3203 | if (CurrentRegion == OMPD_section) { |
| 3204 | // OpenMP [2.7.2, sections Construct, Restrictions] |
| 3205 | // Orphaned section directives are prohibited. That is, the section |
| 3206 | // directives must appear within the sections construct and must not be |
| 3207 | // encountered elsewhere in the sections region. |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 3208 | if (ParentRegion != OMPD_sections && |
| 3209 | ParentRegion != OMPD_parallel_sections) { |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 3210 | SemaRef.Diag(StartLoc, diag::err_omp_orphaned_section_directive) |
| 3211 | << (ParentRegion != OMPD_unknown) |
| 3212 | << getOpenMPDirectiveName(ParentRegion); |
| 3213 | return true; |
| 3214 | } |
| 3215 | return false; |
| 3216 | } |
Kelvin Li | 2b51f72 | 2016-07-26 04:32:50 +0000 | [diff] [blame] | 3217 | // Allow some constructs (except teams) to be orphaned (they could be |
| 3218 | // used in functions, called from OpenMP regions with the required |
| 3219 | // preconditions). |
| 3220 | if (ParentRegion == OMPD_unknown && !isOpenMPTeamsDirective(CurrentRegion)) |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 3221 | return false; |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 3222 | if (CurrentRegion == OMPD_cancellation_point || |
| 3223 | CurrentRegion == OMPD_cancel) { |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 3224 | // OpenMP [2.16, Nesting of Regions] |
| 3225 | // A cancellation point construct for which construct-type-clause is |
| 3226 | // taskgroup must be nested inside a task construct. A cancellation |
| 3227 | // point construct for which construct-type-clause is not taskgroup must |
| 3228 | // be closely nested inside an OpenMP construct that matches the type |
| 3229 | // specified in construct-type-clause. |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 3230 | // A cancel construct for which construct-type-clause is taskgroup must be |
| 3231 | // nested inside a task construct. A cancel construct for which |
| 3232 | // construct-type-clause is not taskgroup must be closely nested inside an |
| 3233 | // OpenMP construct that matches the type specified in |
| 3234 | // construct-type-clause. |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 3235 | NestingProhibited = |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 3236 | !((CancelRegion == OMPD_parallel && |
| 3237 | (ParentRegion == OMPD_parallel || |
| 3238 | ParentRegion == OMPD_target_parallel)) || |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 3239 | (CancelRegion == OMPD_for && |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 3240 | (ParentRegion == OMPD_for || ParentRegion == OMPD_parallel_for || |
| 3241 | ParentRegion == OMPD_target_parallel_for)) || |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 3242 | (CancelRegion == OMPD_taskgroup && ParentRegion == OMPD_task) || |
| 3243 | (CancelRegion == OMPD_sections && |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 3244 | (ParentRegion == OMPD_section || ParentRegion == OMPD_sections || |
| 3245 | ParentRegion == OMPD_parallel_sections))); |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 3246 | } else if (CurrentRegion == OMPD_master) { |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 3247 | // OpenMP [2.16, Nesting of Regions] |
| 3248 | // A master region may not be closely nested inside a worksharing, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 3249 | // atomic, or explicit task region. |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 3250 | NestingProhibited = isOpenMPWorksharingDirective(ParentRegion) || |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 3251 | isOpenMPTaskingDirective(ParentRegion); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 3252 | } else if (CurrentRegion == OMPD_critical && CurrentName.getName()) { |
| 3253 | // OpenMP [2.16, Nesting of Regions] |
| 3254 | // A critical region may not be nested (closely or otherwise) inside a |
| 3255 | // critical region with the same name. Note that this restriction is not |
| 3256 | // sufficient to prevent deadlock. |
| 3257 | SourceLocation PreviousCriticalLoc; |
| 3258 | bool DeadLock = |
| 3259 | Stack->hasDirective([CurrentName, &PreviousCriticalLoc]( |
| 3260 | OpenMPDirectiveKind K, |
| 3261 | const DeclarationNameInfo &DNI, |
| 3262 | SourceLocation Loc) |
| 3263 | ->bool { |
| 3264 | if (K == OMPD_critical && |
| 3265 | DNI.getName() == CurrentName.getName()) { |
| 3266 | PreviousCriticalLoc = Loc; |
| 3267 | return true; |
| 3268 | } else |
| 3269 | return false; |
| 3270 | }, |
| 3271 | false /* skip top directive */); |
| 3272 | if (DeadLock) { |
| 3273 | SemaRef.Diag(StartLoc, |
| 3274 | diag::err_omp_prohibited_region_critical_same_name) |
| 3275 | << CurrentName.getName(); |
| 3276 | if (PreviousCriticalLoc.isValid()) |
| 3277 | SemaRef.Diag(PreviousCriticalLoc, |
| 3278 | diag::note_omp_previous_critical_region); |
| 3279 | return true; |
| 3280 | } |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 3281 | } else if (CurrentRegion == OMPD_barrier) { |
| 3282 | // OpenMP [2.16, Nesting of Regions] |
| 3283 | // A barrier region may not be closely nested inside a worksharing, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 3284 | // explicit task, critical, ordered, atomic, or master region. |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 3285 | NestingProhibited = isOpenMPWorksharingDirective(ParentRegion) || |
| 3286 | isOpenMPTaskingDirective(ParentRegion) || |
| 3287 | ParentRegion == OMPD_master || |
| 3288 | ParentRegion == OMPD_critical || |
| 3289 | ParentRegion == OMPD_ordered; |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 3290 | } else if (isOpenMPWorksharingDirective(CurrentRegion) && |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 3291 | !isOpenMPParallelDirective(CurrentRegion)) { |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 3292 | // OpenMP [2.16, Nesting of Regions] |
| 3293 | // A worksharing region may not be closely nested inside a worksharing, |
| 3294 | // explicit task, critical, ordered, atomic, or master region. |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 3295 | NestingProhibited = isOpenMPWorksharingDirective(ParentRegion) || |
| 3296 | isOpenMPTaskingDirective(ParentRegion) || |
| 3297 | ParentRegion == OMPD_master || |
| 3298 | ParentRegion == OMPD_critical || |
| 3299 | ParentRegion == OMPD_ordered; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 3300 | Recommend = ShouldBeInParallelRegion; |
| 3301 | } else if (CurrentRegion == OMPD_ordered) { |
| 3302 | // OpenMP [2.16, Nesting of Regions] |
| 3303 | // An ordered region may not be closely nested inside a critical, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 3304 | // atomic, or explicit task region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 3305 | // An ordered region must be closely nested inside a loop region (or |
| 3306 | // parallel loop region) with an ordered clause. |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 3307 | // OpenMP [2.8.1,simd Construct, Restrictions] |
| 3308 | // An ordered construct with the simd clause is the only OpenMP construct |
| 3309 | // that can appear in the simd region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 3310 | NestingProhibited = ParentRegion == OMPD_critical || |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 3311 | isOpenMPTaskingDirective(ParentRegion) || |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 3312 | !(isOpenMPSimdDirective(ParentRegion) || |
| 3313 | Stack->isParentOrderedRegion()); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 3314 | Recommend = ShouldBeInOrderedRegion; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 3315 | } else if (isOpenMPTeamsDirective(CurrentRegion)) { |
| 3316 | // OpenMP [2.16, Nesting of Regions] |
| 3317 | // If specified, a teams construct must be contained within a target |
| 3318 | // construct. |
| 3319 | NestingProhibited = ParentRegion != OMPD_target; |
Kelvin Li | 2b51f72 | 2016-07-26 04:32:50 +0000 | [diff] [blame] | 3320 | OrphanSeen = ParentRegion == OMPD_unknown; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 3321 | Recommend = ShouldBeInTargetRegion; |
| 3322 | Stack->setParentTeamsRegionLoc(Stack->getConstructLoc()); |
| 3323 | } |
| 3324 | if (!NestingProhibited && isOpenMPTeamsDirective(ParentRegion)) { |
| 3325 | // OpenMP [2.16, Nesting of Regions] |
| 3326 | // distribute, parallel, parallel sections, parallel workshare, and the |
| 3327 | // parallel loop and parallel loop SIMD constructs are the only OpenMP |
| 3328 | // constructs that can be closely nested in the teams region. |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 3329 | NestingProhibited = !isOpenMPParallelDirective(CurrentRegion) && |
| 3330 | !isOpenMPDistributeDirective(CurrentRegion); |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 3331 | Recommend = ShouldBeInParallelRegion; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 3332 | } |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 3333 | if (!NestingProhibited && isOpenMPDistributeDirective(CurrentRegion)) { |
| 3334 | // OpenMP 4.5 [2.17 Nesting of Regions] |
| 3335 | // The region associated with the distribute construct must be strictly |
| 3336 | // nested inside a teams region |
| 3337 | NestingProhibited = !isOpenMPTeamsDirective(ParentRegion); |
| 3338 | Recommend = ShouldBeInTeamsRegion; |
| 3339 | } |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 3340 | if (!NestingProhibited && |
| 3341 | (isOpenMPTargetExecutionDirective(CurrentRegion) || |
| 3342 | isOpenMPTargetDataManagementDirective(CurrentRegion))) { |
| 3343 | // OpenMP 4.5 [2.17 Nesting of Regions] |
| 3344 | // If a target, target update, target data, target enter data, or |
| 3345 | // target exit data construct is encountered during execution of a |
| 3346 | // target region, the behavior is unspecified. |
| 3347 | NestingProhibited = Stack->hasDirective( |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 3348 | [&OffendingRegion](OpenMPDirectiveKind K, const DeclarationNameInfo &, |
| 3349 | SourceLocation) -> bool { |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 3350 | if (isOpenMPTargetExecutionDirective(K)) { |
| 3351 | OffendingRegion = K; |
| 3352 | return true; |
| 3353 | } else |
| 3354 | return false; |
| 3355 | }, |
| 3356 | false /* don't skip top directive */); |
| 3357 | CloseNesting = false; |
| 3358 | } |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 3359 | if (NestingProhibited) { |
Kelvin Li | 2b51f72 | 2016-07-26 04:32:50 +0000 | [diff] [blame] | 3360 | if (OrphanSeen) { |
| 3361 | SemaRef.Diag(StartLoc, diag::err_omp_orphaned_device_directive) |
| 3362 | << getOpenMPDirectiveName(CurrentRegion) << Recommend; |
| 3363 | } else { |
| 3364 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region) |
| 3365 | << CloseNesting << getOpenMPDirectiveName(OffendingRegion) |
| 3366 | << Recommend << getOpenMPDirectiveName(CurrentRegion); |
| 3367 | } |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 3368 | return true; |
| 3369 | } |
| 3370 | } |
| 3371 | return false; |
| 3372 | } |
| 3373 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3374 | static bool checkIfClauses(Sema &S, OpenMPDirectiveKind Kind, |
| 3375 | ArrayRef<OMPClause *> Clauses, |
| 3376 | ArrayRef<OpenMPDirectiveKind> AllowedNameModifiers) { |
| 3377 | bool ErrorFound = false; |
| 3378 | unsigned NamedModifiersNumber = 0; |
| 3379 | SmallVector<const OMPIfClause *, OMPC_unknown + 1> FoundNameModifiers( |
| 3380 | OMPD_unknown + 1); |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 3381 | SmallVector<SourceLocation, 4> NameModifierLoc; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3382 | for (const auto *C : Clauses) { |
| 3383 | if (const auto *IC = dyn_cast_or_null<OMPIfClause>(C)) { |
| 3384 | // At most one if clause without a directive-name-modifier can appear on |
| 3385 | // the directive. |
| 3386 | OpenMPDirectiveKind CurNM = IC->getNameModifier(); |
| 3387 | if (FoundNameModifiers[CurNM]) { |
| 3388 | S.Diag(C->getLocStart(), diag::err_omp_more_one_clause) |
| 3389 | << getOpenMPDirectiveName(Kind) << getOpenMPClauseName(OMPC_if) |
| 3390 | << (CurNM != OMPD_unknown) << getOpenMPDirectiveName(CurNM); |
| 3391 | ErrorFound = true; |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 3392 | } else if (CurNM != OMPD_unknown) { |
| 3393 | NameModifierLoc.push_back(IC->getNameModifierLoc()); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3394 | ++NamedModifiersNumber; |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 3395 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3396 | FoundNameModifiers[CurNM] = IC; |
| 3397 | if (CurNM == OMPD_unknown) |
| 3398 | continue; |
| 3399 | // Check if the specified name modifier is allowed for the current |
| 3400 | // directive. |
| 3401 | // At most one if clause with the particular directive-name-modifier can |
| 3402 | // appear on the directive. |
| 3403 | bool MatchFound = false; |
| 3404 | for (auto NM : AllowedNameModifiers) { |
| 3405 | if (CurNM == NM) { |
| 3406 | MatchFound = true; |
| 3407 | break; |
| 3408 | } |
| 3409 | } |
| 3410 | if (!MatchFound) { |
| 3411 | S.Diag(IC->getNameModifierLoc(), |
| 3412 | diag::err_omp_wrong_if_directive_name_modifier) |
| 3413 | << getOpenMPDirectiveName(CurNM) << getOpenMPDirectiveName(Kind); |
| 3414 | ErrorFound = true; |
| 3415 | } |
| 3416 | } |
| 3417 | } |
| 3418 | // If any if clause on the directive includes a directive-name-modifier then |
| 3419 | // all if clauses on the directive must include a directive-name-modifier. |
| 3420 | if (FoundNameModifiers[OMPD_unknown] && NamedModifiersNumber > 0) { |
| 3421 | if (NamedModifiersNumber == AllowedNameModifiers.size()) { |
| 3422 | S.Diag(FoundNameModifiers[OMPD_unknown]->getLocStart(), |
| 3423 | diag::err_omp_no_more_if_clause); |
| 3424 | } else { |
| 3425 | std::string Values; |
| 3426 | std::string Sep(", "); |
| 3427 | unsigned AllowedCnt = 0; |
| 3428 | unsigned TotalAllowedNum = |
| 3429 | AllowedNameModifiers.size() - NamedModifiersNumber; |
| 3430 | for (unsigned Cnt = 0, End = AllowedNameModifiers.size(); Cnt < End; |
| 3431 | ++Cnt) { |
| 3432 | OpenMPDirectiveKind NM = AllowedNameModifiers[Cnt]; |
| 3433 | if (!FoundNameModifiers[NM]) { |
| 3434 | Values += "'"; |
| 3435 | Values += getOpenMPDirectiveName(NM); |
| 3436 | Values += "'"; |
| 3437 | if (AllowedCnt + 2 == TotalAllowedNum) |
| 3438 | Values += " or "; |
| 3439 | else if (AllowedCnt + 1 != TotalAllowedNum) |
| 3440 | Values += Sep; |
| 3441 | ++AllowedCnt; |
| 3442 | } |
| 3443 | } |
| 3444 | S.Diag(FoundNameModifiers[OMPD_unknown]->getCondition()->getLocStart(), |
| 3445 | diag::err_omp_unnamed_if_clause) |
| 3446 | << (TotalAllowedNum > 1) << Values; |
| 3447 | } |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 3448 | for (auto Loc : NameModifierLoc) { |
| 3449 | S.Diag(Loc, diag::note_omp_previous_named_if_clause); |
| 3450 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3451 | ErrorFound = true; |
| 3452 | } |
| 3453 | return ErrorFound; |
| 3454 | } |
| 3455 | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 3456 | StmtResult Sema::ActOnOpenMPExecutableDirective( |
| 3457 | OpenMPDirectiveKind Kind, const DeclarationNameInfo &DirName, |
| 3458 | OpenMPDirectiveKind CancelRegion, ArrayRef<OMPClause *> Clauses, |
| 3459 | Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3460 | StmtResult Res = StmtError(); |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 3461 | if (CheckNestingOfRegions(*this, DSAStack, Kind, DirName, CancelRegion, |
| 3462 | StartLoc)) |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 3463 | return StmtError(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 3464 | |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 3465 | llvm::SmallVector<OMPClause *, 8> ClausesWithImplicit; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 3466 | llvm::DenseMap<ValueDecl *, Expr *> VarsWithInheritedDSA; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 3467 | bool ErrorFound = false; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 3468 | ClausesWithImplicit.append(Clauses.begin(), Clauses.end()); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 3469 | if (AStmt) { |
| 3470 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 3471 | |
| 3472 | // Check default data sharing attributes for referenced variables. |
| 3473 | DSAAttrChecker DSAChecker(DSAStack, *this, cast<CapturedStmt>(AStmt)); |
| 3474 | DSAChecker.Visit(cast<CapturedStmt>(AStmt)->getCapturedStmt()); |
| 3475 | if (DSAChecker.isErrorFound()) |
| 3476 | return StmtError(); |
| 3477 | // Generate list of implicitly defined firstprivate variables. |
| 3478 | VarsWithInheritedDSA = DSAChecker.getVarsWithInheritedDSA(); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 3479 | |
| 3480 | if (!DSAChecker.getImplicitFirstprivate().empty()) { |
| 3481 | if (OMPClause *Implicit = ActOnOpenMPFirstprivateClause( |
| 3482 | DSAChecker.getImplicitFirstprivate(), SourceLocation(), |
| 3483 | SourceLocation(), SourceLocation())) { |
| 3484 | ClausesWithImplicit.push_back(Implicit); |
| 3485 | ErrorFound = cast<OMPFirstprivateClause>(Implicit)->varlist_size() != |
| 3486 | DSAChecker.getImplicitFirstprivate().size(); |
| 3487 | } else |
| 3488 | ErrorFound = true; |
| 3489 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 3490 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 3491 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3492 | llvm::SmallVector<OpenMPDirectiveKind, 4> AllowedNameModifiers; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3493 | switch (Kind) { |
| 3494 | case OMPD_parallel: |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 3495 | Res = ActOnOpenMPParallelDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3496 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3497 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3498 | break; |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 3499 | case OMPD_simd: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3500 | Res = ActOnOpenMPSimdDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc, |
| 3501 | VarsWithInheritedDSA); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 3502 | break; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3503 | case OMPD_for: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3504 | Res = ActOnOpenMPForDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc, |
| 3505 | VarsWithInheritedDSA); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3506 | break; |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 3507 | case OMPD_for_simd: |
| 3508 | Res = ActOnOpenMPForSimdDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3509 | EndLoc, VarsWithInheritedDSA); |
| 3510 | break; |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 3511 | case OMPD_sections: |
| 3512 | Res = ActOnOpenMPSectionsDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3513 | EndLoc); |
| 3514 | break; |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 3515 | case OMPD_section: |
| 3516 | assert(ClausesWithImplicit.empty() && |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 3517 | "No clauses are allowed for 'omp section' directive"); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 3518 | Res = ActOnOpenMPSectionDirective(AStmt, StartLoc, EndLoc); |
| 3519 | break; |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 3520 | case OMPD_single: |
| 3521 | Res = ActOnOpenMPSingleDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3522 | EndLoc); |
| 3523 | break; |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 3524 | case OMPD_master: |
| 3525 | assert(ClausesWithImplicit.empty() && |
| 3526 | "No clauses are allowed for 'omp master' directive"); |
| 3527 | Res = ActOnOpenMPMasterDirective(AStmt, StartLoc, EndLoc); |
| 3528 | break; |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 3529 | case OMPD_critical: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 3530 | Res = ActOnOpenMPCriticalDirective(DirName, ClausesWithImplicit, AStmt, |
| 3531 | StartLoc, EndLoc); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 3532 | break; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3533 | case OMPD_parallel_for: |
| 3534 | Res = ActOnOpenMPParallelForDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3535 | EndLoc, VarsWithInheritedDSA); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3536 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3537 | break; |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 3538 | case OMPD_parallel_for_simd: |
| 3539 | Res = ActOnOpenMPParallelForSimdDirective( |
| 3540 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3541 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 3542 | break; |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 3543 | case OMPD_parallel_sections: |
| 3544 | Res = ActOnOpenMPParallelSectionsDirective(ClausesWithImplicit, AStmt, |
| 3545 | StartLoc, EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3546 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 3547 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3548 | case OMPD_task: |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 3549 | Res = |
| 3550 | ActOnOpenMPTaskDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3551 | AllowedNameModifiers.push_back(OMPD_task); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 3552 | break; |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 3553 | case OMPD_taskyield: |
| 3554 | assert(ClausesWithImplicit.empty() && |
| 3555 | "No clauses are allowed for 'omp taskyield' directive"); |
| 3556 | assert(AStmt == nullptr && |
| 3557 | "No associated statement allowed for 'omp taskyield' directive"); |
| 3558 | Res = ActOnOpenMPTaskyieldDirective(StartLoc, EndLoc); |
| 3559 | break; |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 3560 | case OMPD_barrier: |
| 3561 | assert(ClausesWithImplicit.empty() && |
| 3562 | "No clauses are allowed for 'omp barrier' directive"); |
| 3563 | assert(AStmt == nullptr && |
| 3564 | "No associated statement allowed for 'omp barrier' directive"); |
| 3565 | Res = ActOnOpenMPBarrierDirective(StartLoc, EndLoc); |
| 3566 | break; |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 3567 | case OMPD_taskwait: |
| 3568 | assert(ClausesWithImplicit.empty() && |
| 3569 | "No clauses are allowed for 'omp taskwait' directive"); |
| 3570 | assert(AStmt == nullptr && |
| 3571 | "No associated statement allowed for 'omp taskwait' directive"); |
| 3572 | Res = ActOnOpenMPTaskwaitDirective(StartLoc, EndLoc); |
| 3573 | break; |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 3574 | case OMPD_taskgroup: |
| 3575 | assert(ClausesWithImplicit.empty() && |
| 3576 | "No clauses are allowed for 'omp taskgroup' directive"); |
| 3577 | Res = ActOnOpenMPTaskgroupDirective(AStmt, StartLoc, EndLoc); |
| 3578 | break; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 3579 | case OMPD_flush: |
| 3580 | assert(AStmt == nullptr && |
| 3581 | "No associated statement allowed for 'omp flush' directive"); |
| 3582 | Res = ActOnOpenMPFlushDirective(ClausesWithImplicit, StartLoc, EndLoc); |
| 3583 | break; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 3584 | case OMPD_ordered: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 3585 | Res = ActOnOpenMPOrderedDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3586 | EndLoc); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 3587 | break; |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 3588 | case OMPD_atomic: |
| 3589 | Res = ActOnOpenMPAtomicDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3590 | EndLoc); |
| 3591 | break; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 3592 | case OMPD_teams: |
| 3593 | Res = |
| 3594 | ActOnOpenMPTeamsDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); |
| 3595 | break; |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 3596 | case OMPD_target: |
| 3597 | Res = ActOnOpenMPTargetDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3598 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3599 | AllowedNameModifiers.push_back(OMPD_target); |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 3600 | break; |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 3601 | case OMPD_target_parallel: |
| 3602 | Res = ActOnOpenMPTargetParallelDirective(ClausesWithImplicit, AStmt, |
| 3603 | StartLoc, EndLoc); |
| 3604 | AllowedNameModifiers.push_back(OMPD_target); |
| 3605 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 3606 | break; |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 3607 | case OMPD_target_parallel_for: |
| 3608 | Res = ActOnOpenMPTargetParallelForDirective( |
| 3609 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 3610 | AllowedNameModifiers.push_back(OMPD_target); |
| 3611 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 3612 | break; |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 3613 | case OMPD_cancellation_point: |
| 3614 | assert(ClausesWithImplicit.empty() && |
| 3615 | "No clauses are allowed for 'omp cancellation point' directive"); |
| 3616 | assert(AStmt == nullptr && "No associated statement allowed for 'omp " |
| 3617 | "cancellation point' directive"); |
| 3618 | Res = ActOnOpenMPCancellationPointDirective(StartLoc, EndLoc, CancelRegion); |
| 3619 | break; |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 3620 | case OMPD_cancel: |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 3621 | assert(AStmt == nullptr && |
| 3622 | "No associated statement allowed for 'omp cancel' directive"); |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 3623 | Res = ActOnOpenMPCancelDirective(ClausesWithImplicit, StartLoc, EndLoc, |
| 3624 | CancelRegion); |
| 3625 | AllowedNameModifiers.push_back(OMPD_cancel); |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 3626 | break; |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 3627 | case OMPD_target_data: |
| 3628 | Res = ActOnOpenMPTargetDataDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3629 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3630 | AllowedNameModifiers.push_back(OMPD_target_data); |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 3631 | break; |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 3632 | case OMPD_target_enter_data: |
| 3633 | Res = ActOnOpenMPTargetEnterDataDirective(ClausesWithImplicit, StartLoc, |
| 3634 | EndLoc); |
| 3635 | AllowedNameModifiers.push_back(OMPD_target_enter_data); |
| 3636 | break; |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 3637 | case OMPD_target_exit_data: |
| 3638 | Res = ActOnOpenMPTargetExitDataDirective(ClausesWithImplicit, StartLoc, |
| 3639 | EndLoc); |
| 3640 | AllowedNameModifiers.push_back(OMPD_target_exit_data); |
| 3641 | break; |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 3642 | case OMPD_taskloop: |
| 3643 | Res = ActOnOpenMPTaskLoopDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3644 | EndLoc, VarsWithInheritedDSA); |
| 3645 | AllowedNameModifiers.push_back(OMPD_taskloop); |
| 3646 | break; |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 3647 | case OMPD_taskloop_simd: |
| 3648 | Res = ActOnOpenMPTaskLoopSimdDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3649 | EndLoc, VarsWithInheritedDSA); |
| 3650 | AllowedNameModifiers.push_back(OMPD_taskloop); |
| 3651 | break; |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 3652 | case OMPD_distribute: |
| 3653 | Res = ActOnOpenMPDistributeDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3654 | EndLoc, VarsWithInheritedDSA); |
| 3655 | break; |
Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 3656 | case OMPD_target_update: |
| 3657 | assert(!AStmt && "Statement is not allowed for target update"); |
| 3658 | Res = |
| 3659 | ActOnOpenMPTargetUpdateDirective(ClausesWithImplicit, StartLoc, EndLoc); |
| 3660 | AllowedNameModifiers.push_back(OMPD_target_update); |
| 3661 | break; |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 3662 | case OMPD_distribute_parallel_for: |
| 3663 | Res = ActOnOpenMPDistributeParallelForDirective( |
| 3664 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 3665 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 3666 | break; |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 3667 | case OMPD_distribute_parallel_for_simd: |
| 3668 | Res = ActOnOpenMPDistributeParallelForSimdDirective( |
| 3669 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 3670 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 3671 | break; |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 3672 | case OMPD_distribute_simd: |
| 3673 | Res = ActOnOpenMPDistributeSimdDirective( |
| 3674 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 3675 | break; |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 3676 | case OMPD_target_parallel_for_simd: |
| 3677 | Res = ActOnOpenMPTargetParallelForSimdDirective( |
| 3678 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 3679 | AllowedNameModifiers.push_back(OMPD_target); |
| 3680 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 3681 | break; |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 3682 | case OMPD_target_simd: |
| 3683 | Res = ActOnOpenMPTargetSimdDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3684 | EndLoc, VarsWithInheritedDSA); |
| 3685 | AllowedNameModifiers.push_back(OMPD_target); |
| 3686 | break; |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 3687 | case OMPD_declare_target: |
| 3688 | case OMPD_end_declare_target: |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 3689 | case OMPD_threadprivate: |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 3690 | case OMPD_declare_reduction: |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 3691 | case OMPD_declare_simd: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3692 | llvm_unreachable("OpenMP Directive is not allowed"); |
| 3693 | case OMPD_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3694 | llvm_unreachable("Unknown OpenMP directive"); |
| 3695 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 3696 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3697 | for (auto P : VarsWithInheritedDSA) { |
| 3698 | Diag(P.second->getExprLoc(), diag::err_omp_no_dsa_for_variable) |
| 3699 | << P.first << P.second->getSourceRange(); |
| 3700 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3701 | ErrorFound = !VarsWithInheritedDSA.empty() || ErrorFound; |
| 3702 | |
| 3703 | if (!AllowedNameModifiers.empty()) |
| 3704 | ErrorFound = checkIfClauses(*this, Kind, Clauses, AllowedNameModifiers) || |
| 3705 | ErrorFound; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3706 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 3707 | if (ErrorFound) |
| 3708 | return StmtError(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3709 | return Res; |
| 3710 | } |
| 3711 | |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 3712 | Sema::DeclGroupPtrTy Sema::ActOnOpenMPDeclareSimdDirective( |
| 3713 | DeclGroupPtrTy DG, OMPDeclareSimdDeclAttr::BranchStateTy BS, Expr *Simdlen, |
Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 3714 | ArrayRef<Expr *> Uniforms, ArrayRef<Expr *> Aligneds, |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 3715 | ArrayRef<Expr *> Alignments, ArrayRef<Expr *> Linears, |
| 3716 | ArrayRef<unsigned> LinModifiers, ArrayRef<Expr *> Steps, SourceRange SR) { |
Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 3717 | assert(Aligneds.size() == Alignments.size()); |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 3718 | assert(Linears.size() == LinModifiers.size()); |
| 3719 | assert(Linears.size() == Steps.size()); |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 3720 | if (!DG || DG.get().isNull()) |
| 3721 | return DeclGroupPtrTy(); |
| 3722 | |
| 3723 | if (!DG.get().isSingleDecl()) { |
Alexey Bataev | 20dfd77 | 2016-04-04 10:12:15 +0000 | [diff] [blame] | 3724 | Diag(SR.getBegin(), diag::err_omp_single_decl_in_declare_simd); |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 3725 | return DG; |
| 3726 | } |
| 3727 | auto *ADecl = DG.get().getSingleDecl(); |
| 3728 | if (auto *FTD = dyn_cast<FunctionTemplateDecl>(ADecl)) |
| 3729 | ADecl = FTD->getTemplatedDecl(); |
| 3730 | |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 3731 | auto *FD = dyn_cast<FunctionDecl>(ADecl); |
| 3732 | if (!FD) { |
| 3733 | Diag(ADecl->getLocation(), diag::err_omp_function_expected); |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 3734 | return DeclGroupPtrTy(); |
| 3735 | } |
| 3736 | |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 3737 | // OpenMP [2.8.2, declare simd construct, Description] |
| 3738 | // The parameter of the simdlen clause must be a constant positive integer |
| 3739 | // expression. |
| 3740 | ExprResult SL; |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 3741 | if (Simdlen) |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 3742 | SL = VerifyPositiveIntegerConstantInClause(Simdlen, OMPC_simdlen); |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 3743 | // OpenMP [2.8.2, declare simd construct, Description] |
| 3744 | // The special this pointer can be used as if was one of the arguments to the |
| 3745 | // function in any of the linear, aligned, or uniform clauses. |
| 3746 | // The uniform clause declares one or more arguments to have an invariant |
| 3747 | // value for all concurrent invocations of the function in the execution of a |
| 3748 | // single SIMD loop. |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 3749 | llvm::DenseMap<Decl *, Expr *> UniformedArgs; |
| 3750 | Expr *UniformedLinearThis = nullptr; |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 3751 | for (auto *E : Uniforms) { |
| 3752 | E = E->IgnoreParenImpCasts(); |
| 3753 | if (auto *DRE = dyn_cast<DeclRefExpr>(E)) |
| 3754 | if (auto *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl())) |
| 3755 | if (FD->getNumParams() > PVD->getFunctionScopeIndex() && |
| 3756 | FD->getParamDecl(PVD->getFunctionScopeIndex()) |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 3757 | ->getCanonicalDecl() == PVD->getCanonicalDecl()) { |
| 3758 | UniformedArgs.insert(std::make_pair(PVD->getCanonicalDecl(), E)); |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 3759 | continue; |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 3760 | } |
| 3761 | if (isa<CXXThisExpr>(E)) { |
| 3762 | UniformedLinearThis = E; |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 3763 | continue; |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 3764 | } |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 3765 | Diag(E->getExprLoc(), diag::err_omp_param_or_this_in_clause) |
| 3766 | << FD->getDeclName() << (isa<CXXMethodDecl>(ADecl) ? 1 : 0); |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 3767 | } |
Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 3768 | // OpenMP [2.8.2, declare simd construct, Description] |
| 3769 | // The aligned clause declares that the object to which each list item points |
| 3770 | // is aligned to the number of bytes expressed in the optional parameter of |
| 3771 | // the aligned clause. |
| 3772 | // The special this pointer can be used as if was one of the arguments to the |
| 3773 | // function in any of the linear, aligned, or uniform clauses. |
| 3774 | // The type of list items appearing in the aligned clause must be array, |
| 3775 | // pointer, reference to array, or reference to pointer. |
| 3776 | llvm::DenseMap<Decl *, Expr *> AlignedArgs; |
| 3777 | Expr *AlignedThis = nullptr; |
| 3778 | for (auto *E : Aligneds) { |
| 3779 | E = E->IgnoreParenImpCasts(); |
| 3780 | if (auto *DRE = dyn_cast<DeclRefExpr>(E)) |
| 3781 | if (auto *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl())) { |
| 3782 | auto *CanonPVD = PVD->getCanonicalDecl(); |
| 3783 | if (FD->getNumParams() > PVD->getFunctionScopeIndex() && |
| 3784 | FD->getParamDecl(PVD->getFunctionScopeIndex()) |
| 3785 | ->getCanonicalDecl() == CanonPVD) { |
| 3786 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 3787 | // A list-item cannot appear in more than one aligned clause. |
| 3788 | if (AlignedArgs.count(CanonPVD) > 0) { |
| 3789 | Diag(E->getExprLoc(), diag::err_omp_aligned_twice) |
| 3790 | << 1 << E->getSourceRange(); |
| 3791 | Diag(AlignedArgs[CanonPVD]->getExprLoc(), |
| 3792 | diag::note_omp_explicit_dsa) |
| 3793 | << getOpenMPClauseName(OMPC_aligned); |
| 3794 | continue; |
| 3795 | } |
| 3796 | AlignedArgs[CanonPVD] = E; |
| 3797 | QualType QTy = PVD->getType() |
| 3798 | .getNonReferenceType() |
| 3799 | .getUnqualifiedType() |
| 3800 | .getCanonicalType(); |
| 3801 | const Type *Ty = QTy.getTypePtrOrNull(); |
| 3802 | if (!Ty || (!Ty->isArrayType() && !Ty->isPointerType())) { |
| 3803 | Diag(E->getExprLoc(), diag::err_omp_aligned_expected_array_or_ptr) |
| 3804 | << QTy << getLangOpts().CPlusPlus << E->getSourceRange(); |
| 3805 | Diag(PVD->getLocation(), diag::note_previous_decl) << PVD; |
| 3806 | } |
| 3807 | continue; |
| 3808 | } |
| 3809 | } |
| 3810 | if (isa<CXXThisExpr>(E)) { |
| 3811 | if (AlignedThis) { |
| 3812 | Diag(E->getExprLoc(), diag::err_omp_aligned_twice) |
| 3813 | << 2 << E->getSourceRange(); |
| 3814 | Diag(AlignedThis->getExprLoc(), diag::note_omp_explicit_dsa) |
| 3815 | << getOpenMPClauseName(OMPC_aligned); |
| 3816 | } |
| 3817 | AlignedThis = E; |
| 3818 | continue; |
| 3819 | } |
| 3820 | Diag(E->getExprLoc(), diag::err_omp_param_or_this_in_clause) |
| 3821 | << FD->getDeclName() << (isa<CXXMethodDecl>(ADecl) ? 1 : 0); |
| 3822 | } |
| 3823 | // The optional parameter of the aligned clause, alignment, must be a constant |
| 3824 | // positive integer expression. If no optional parameter is specified, |
| 3825 | // implementation-defined default alignments for SIMD instructions on the |
| 3826 | // target platforms are assumed. |
| 3827 | SmallVector<Expr *, 4> NewAligns; |
| 3828 | for (auto *E : Alignments) { |
| 3829 | ExprResult Align; |
| 3830 | if (E) |
| 3831 | Align = VerifyPositiveIntegerConstantInClause(E, OMPC_aligned); |
| 3832 | NewAligns.push_back(Align.get()); |
| 3833 | } |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 3834 | // OpenMP [2.8.2, declare simd construct, Description] |
| 3835 | // The linear clause declares one or more list items to be private to a SIMD |
| 3836 | // lane and to have a linear relationship with respect to the iteration space |
| 3837 | // of a loop. |
| 3838 | // The special this pointer can be used as if was one of the arguments to the |
| 3839 | // function in any of the linear, aligned, or uniform clauses. |
| 3840 | // When a linear-step expression is specified in a linear clause it must be |
| 3841 | // either a constant integer expression or an integer-typed parameter that is |
| 3842 | // specified in a uniform clause on the directive. |
| 3843 | llvm::DenseMap<Decl *, Expr *> LinearArgs; |
| 3844 | const bool IsUniformedThis = UniformedLinearThis != nullptr; |
| 3845 | auto MI = LinModifiers.begin(); |
| 3846 | for (auto *E : Linears) { |
| 3847 | auto LinKind = static_cast<OpenMPLinearClauseKind>(*MI); |
| 3848 | ++MI; |
| 3849 | E = E->IgnoreParenImpCasts(); |
| 3850 | if (auto *DRE = dyn_cast<DeclRefExpr>(E)) |
| 3851 | if (auto *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl())) { |
| 3852 | auto *CanonPVD = PVD->getCanonicalDecl(); |
| 3853 | if (FD->getNumParams() > PVD->getFunctionScopeIndex() && |
| 3854 | FD->getParamDecl(PVD->getFunctionScopeIndex()) |
| 3855 | ->getCanonicalDecl() == CanonPVD) { |
| 3856 | // OpenMP [2.15.3.7, linear Clause, Restrictions] |
| 3857 | // A list-item cannot appear in more than one linear clause. |
| 3858 | if (LinearArgs.count(CanonPVD) > 0) { |
| 3859 | Diag(E->getExprLoc(), diag::err_omp_wrong_dsa) |
| 3860 | << getOpenMPClauseName(OMPC_linear) |
| 3861 | << getOpenMPClauseName(OMPC_linear) << E->getSourceRange(); |
| 3862 | Diag(LinearArgs[CanonPVD]->getExprLoc(), |
| 3863 | diag::note_omp_explicit_dsa) |
| 3864 | << getOpenMPClauseName(OMPC_linear); |
| 3865 | continue; |
| 3866 | } |
| 3867 | // Each argument can appear in at most one uniform or linear clause. |
| 3868 | if (UniformedArgs.count(CanonPVD) > 0) { |
| 3869 | Diag(E->getExprLoc(), diag::err_omp_wrong_dsa) |
| 3870 | << getOpenMPClauseName(OMPC_linear) |
| 3871 | << getOpenMPClauseName(OMPC_uniform) << E->getSourceRange(); |
| 3872 | Diag(UniformedArgs[CanonPVD]->getExprLoc(), |
| 3873 | diag::note_omp_explicit_dsa) |
| 3874 | << getOpenMPClauseName(OMPC_uniform); |
| 3875 | continue; |
| 3876 | } |
| 3877 | LinearArgs[CanonPVD] = E; |
| 3878 | if (E->isValueDependent() || E->isTypeDependent() || |
| 3879 | E->isInstantiationDependent() || |
| 3880 | E->containsUnexpandedParameterPack()) |
| 3881 | continue; |
| 3882 | (void)CheckOpenMPLinearDecl(CanonPVD, E->getExprLoc(), LinKind, |
| 3883 | PVD->getOriginalType()); |
| 3884 | continue; |
| 3885 | } |
| 3886 | } |
| 3887 | if (isa<CXXThisExpr>(E)) { |
| 3888 | if (UniformedLinearThis) { |
| 3889 | Diag(E->getExprLoc(), diag::err_omp_wrong_dsa) |
| 3890 | << getOpenMPClauseName(OMPC_linear) |
| 3891 | << getOpenMPClauseName(IsUniformedThis ? OMPC_uniform : OMPC_linear) |
| 3892 | << E->getSourceRange(); |
| 3893 | Diag(UniformedLinearThis->getExprLoc(), diag::note_omp_explicit_dsa) |
| 3894 | << getOpenMPClauseName(IsUniformedThis ? OMPC_uniform |
| 3895 | : OMPC_linear); |
| 3896 | continue; |
| 3897 | } |
| 3898 | UniformedLinearThis = E; |
| 3899 | if (E->isValueDependent() || E->isTypeDependent() || |
| 3900 | E->isInstantiationDependent() || E->containsUnexpandedParameterPack()) |
| 3901 | continue; |
| 3902 | (void)CheckOpenMPLinearDecl(/*D=*/nullptr, E->getExprLoc(), LinKind, |
| 3903 | E->getType()); |
| 3904 | continue; |
| 3905 | } |
| 3906 | Diag(E->getExprLoc(), diag::err_omp_param_or_this_in_clause) |
| 3907 | << FD->getDeclName() << (isa<CXXMethodDecl>(ADecl) ? 1 : 0); |
| 3908 | } |
| 3909 | Expr *Step = nullptr; |
| 3910 | Expr *NewStep = nullptr; |
| 3911 | SmallVector<Expr *, 4> NewSteps; |
| 3912 | for (auto *E : Steps) { |
| 3913 | // Skip the same step expression, it was checked already. |
| 3914 | if (Step == E || !E) { |
| 3915 | NewSteps.push_back(E ? NewStep : nullptr); |
| 3916 | continue; |
| 3917 | } |
| 3918 | Step = E; |
| 3919 | if (auto *DRE = dyn_cast<DeclRefExpr>(Step)) |
| 3920 | if (auto *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl())) { |
| 3921 | auto *CanonPVD = PVD->getCanonicalDecl(); |
| 3922 | if (UniformedArgs.count(CanonPVD) == 0) { |
| 3923 | Diag(Step->getExprLoc(), diag::err_omp_expected_uniform_param) |
| 3924 | << Step->getSourceRange(); |
| 3925 | } else if (E->isValueDependent() || E->isTypeDependent() || |
| 3926 | E->isInstantiationDependent() || |
| 3927 | E->containsUnexpandedParameterPack() || |
| 3928 | CanonPVD->getType()->hasIntegerRepresentation()) |
| 3929 | NewSteps.push_back(Step); |
| 3930 | else { |
| 3931 | Diag(Step->getExprLoc(), diag::err_omp_expected_int_param) |
| 3932 | << Step->getSourceRange(); |
| 3933 | } |
| 3934 | continue; |
| 3935 | } |
| 3936 | NewStep = Step; |
| 3937 | if (Step && !Step->isValueDependent() && !Step->isTypeDependent() && |
| 3938 | !Step->isInstantiationDependent() && |
| 3939 | !Step->containsUnexpandedParameterPack()) { |
| 3940 | NewStep = PerformOpenMPImplicitIntegerConversion(Step->getExprLoc(), Step) |
| 3941 | .get(); |
| 3942 | if (NewStep) |
| 3943 | NewStep = VerifyIntegerConstantExpression(NewStep).get(); |
| 3944 | } |
| 3945 | NewSteps.push_back(NewStep); |
| 3946 | } |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 3947 | auto *NewAttr = OMPDeclareSimdDeclAttr::CreateImplicit( |
| 3948 | Context, BS, SL.get(), const_cast<Expr **>(Uniforms.data()), |
Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 3949 | Uniforms.size(), const_cast<Expr **>(Aligneds.data()), Aligneds.size(), |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 3950 | const_cast<Expr **>(NewAligns.data()), NewAligns.size(), |
| 3951 | const_cast<Expr **>(Linears.data()), Linears.size(), |
| 3952 | const_cast<unsigned *>(LinModifiers.data()), LinModifiers.size(), |
| 3953 | NewSteps.data(), NewSteps.size(), SR); |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 3954 | ADecl->addAttr(NewAttr); |
| 3955 | return ConvertDeclToDeclGroup(ADecl); |
| 3956 | } |
| 3957 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3958 | StmtResult Sema::ActOnOpenMPParallelDirective(ArrayRef<OMPClause *> Clauses, |
| 3959 | Stmt *AStmt, |
| 3960 | SourceLocation StartLoc, |
| 3961 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3962 | if (!AStmt) |
| 3963 | return StmtError(); |
| 3964 | |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 3965 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 3966 | // 1.2.2 OpenMP Language Terminology |
| 3967 | // Structured block - An executable statement with a single entry at the |
| 3968 | // top and a single exit at the bottom. |
| 3969 | // The point of exit cannot be a branch out of the structured block. |
| 3970 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 3971 | CS->getCapturedDecl()->setNothrow(); |
| 3972 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3973 | getCurFunction()->setHasBranchProtectedScope(); |
| 3974 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 3975 | return OMPParallelDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 3976 | DSAStack->isCancelRegion()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3977 | } |
| 3978 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3979 | namespace { |
| 3980 | /// \brief Helper class for checking canonical form of the OpenMP loops and |
| 3981 | /// extracting iteration space of each loop in the loop nest, that will be used |
| 3982 | /// for IR generation. |
| 3983 | class OpenMPIterationSpaceChecker { |
| 3984 | /// \brief Reference to Sema. |
| 3985 | Sema &SemaRef; |
| 3986 | /// \brief A location for diagnostics (when there is no some better location). |
| 3987 | SourceLocation DefaultLoc; |
| 3988 | /// \brief A location for diagnostics (when increment is not compatible). |
| 3989 | SourceLocation ConditionLoc; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3990 | /// \brief A source location for referring to loop init later. |
| 3991 | SourceRange InitSrcRange; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3992 | /// \brief A source location for referring to condition later. |
| 3993 | SourceRange ConditionSrcRange; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3994 | /// \brief A source location for referring to increment later. |
| 3995 | SourceRange IncrementSrcRange; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3996 | /// \brief Loop variable. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3997 | ValueDecl *LCDecl = nullptr; |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3998 | /// \brief Reference to loop variable. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3999 | Expr *LCRef = nullptr; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4000 | /// \brief Lower bound (initializer for the var). |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4001 | Expr *LB = nullptr; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4002 | /// \brief Upper bound. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4003 | Expr *UB = nullptr; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4004 | /// \brief Loop step (increment). |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4005 | Expr *Step = nullptr; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4006 | /// \brief This flag is true when condition is one of: |
| 4007 | /// Var < UB |
| 4008 | /// Var <= UB |
| 4009 | /// UB > Var |
| 4010 | /// UB >= Var |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4011 | bool TestIsLessOp = false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4012 | /// \brief This flag is true when condition is strict ( < or > ). |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4013 | bool TestIsStrictOp = false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4014 | /// \brief This flag is true when step is subtracted on each iteration. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4015 | bool SubtractStep = false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4016 | |
| 4017 | public: |
| 4018 | OpenMPIterationSpaceChecker(Sema &SemaRef, SourceLocation DefaultLoc) |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4019 | : SemaRef(SemaRef), DefaultLoc(DefaultLoc), ConditionLoc(DefaultLoc) {} |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4020 | /// \brief Check init-expr for canonical loop form and save loop counter |
| 4021 | /// variable - #Var and its initialization value - #LB. |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 4022 | bool CheckInit(Stmt *S, bool EmitDiags = true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4023 | /// \brief Check test-expr for canonical form, save upper-bound (#UB), flags |
| 4024 | /// for less/greater and for strict/non-strict comparison. |
| 4025 | bool CheckCond(Expr *S); |
| 4026 | /// \brief Check incr-expr for canonical loop form and return true if it |
| 4027 | /// does not conform, otherwise save loop step (#Step). |
| 4028 | bool CheckInc(Expr *S); |
| 4029 | /// \brief Return the loop counter variable. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4030 | ValueDecl *GetLoopDecl() const { return LCDecl; } |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 4031 | /// \brief Return the reference expression to loop counter variable. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4032 | Expr *GetLoopDeclRefExpr() const { return LCRef; } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4033 | /// \brief Source range of the loop init. |
| 4034 | SourceRange GetInitSrcRange() const { return InitSrcRange; } |
| 4035 | /// \brief Source range of the loop condition. |
| 4036 | SourceRange GetConditionSrcRange() const { return ConditionSrcRange; } |
| 4037 | /// \brief Source range of the loop increment. |
| 4038 | SourceRange GetIncrementSrcRange() const { return IncrementSrcRange; } |
| 4039 | /// \brief True if the step should be subtracted. |
| 4040 | bool ShouldSubtractStep() const { return SubtractStep; } |
| 4041 | /// \brief Build the expression to calculate the number of iterations. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4042 | Expr * |
| 4043 | BuildNumIterations(Scope *S, const bool LimitedType, |
| 4044 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) const; |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 4045 | /// \brief Build the precondition expression for the loops. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4046 | Expr *BuildPreCond(Scope *S, Expr *Cond, |
| 4047 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) const; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4048 | /// \brief Build reference expression to the counter be used for codegen. |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 4049 | DeclRefExpr *BuildCounterVar(llvm::MapVector<Expr *, DeclRefExpr *> &Captures, |
| 4050 | DSAStackTy &DSA) const; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 4051 | /// \brief Build reference expression to the private counter be used for |
| 4052 | /// codegen. |
| 4053 | Expr *BuildPrivateCounterVar() const; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4054 | /// \brief Build initization of the counter be used for codegen. |
| 4055 | Expr *BuildCounterInit() const; |
| 4056 | /// \brief Build step of the counter be used for codegen. |
| 4057 | Expr *BuildCounterStep() const; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4058 | /// \brief Return true if any expression is dependent. |
| 4059 | bool Dependent() const; |
| 4060 | |
| 4061 | private: |
| 4062 | /// \brief Check the right-hand side of an assignment in the increment |
| 4063 | /// expression. |
| 4064 | bool CheckIncRHS(Expr *RHS); |
| 4065 | /// \brief Helper to set loop counter variable and its initializer. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4066 | bool SetLCDeclAndLB(ValueDecl *NewLCDecl, Expr *NewDeclRefExpr, Expr *NewLB); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4067 | /// \brief Helper to set upper bound. |
Craig Topper | e335f25 | 2015-10-04 04:53:55 +0000 | [diff] [blame] | 4068 | bool SetUB(Expr *NewUB, bool LessOp, bool StrictOp, SourceRange SR, |
Craig Topper | 9cd5e4f | 2015-09-21 01:23:32 +0000 | [diff] [blame] | 4069 | SourceLocation SL); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4070 | /// \brief Helper to set loop increment. |
| 4071 | bool SetStep(Expr *NewStep, bool Subtract); |
| 4072 | }; |
| 4073 | |
| 4074 | bool OpenMPIterationSpaceChecker::Dependent() const { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4075 | if (!LCDecl) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4076 | assert(!LB && !UB && !Step); |
| 4077 | return false; |
| 4078 | } |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4079 | return LCDecl->getType()->isDependentType() || |
| 4080 | (LB && LB->isValueDependent()) || (UB && UB->isValueDependent()) || |
| 4081 | (Step && Step->isValueDependent()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4082 | } |
| 4083 | |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4084 | static Expr *getExprAsWritten(Expr *E) { |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 4085 | if (auto *ExprTemp = dyn_cast<ExprWithCleanups>(E)) |
| 4086 | E = ExprTemp->getSubExpr(); |
| 4087 | |
| 4088 | if (auto *MTE = dyn_cast<MaterializeTemporaryExpr>(E)) |
| 4089 | E = MTE->GetTemporaryExpr(); |
| 4090 | |
| 4091 | while (auto *Binder = dyn_cast<CXXBindTemporaryExpr>(E)) |
| 4092 | E = Binder->getSubExpr(); |
| 4093 | |
| 4094 | if (auto *ICE = dyn_cast<ImplicitCastExpr>(E)) |
| 4095 | E = ICE->getSubExprAsWritten(); |
| 4096 | return E->IgnoreParens(); |
| 4097 | } |
| 4098 | |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4099 | bool OpenMPIterationSpaceChecker::SetLCDeclAndLB(ValueDecl *NewLCDecl, |
| 4100 | Expr *NewLCRefExpr, |
| 4101 | Expr *NewLB) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4102 | // State consistency checking to ensure correct usage. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4103 | assert(LCDecl == nullptr && LB == nullptr && LCRef == nullptr && |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 4104 | UB == nullptr && Step == nullptr && !TestIsLessOp && !TestIsStrictOp); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4105 | if (!NewLCDecl || !NewLB) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4106 | return true; |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4107 | LCDecl = getCanonicalDecl(NewLCDecl); |
| 4108 | LCRef = NewLCRefExpr; |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 4109 | if (auto *CE = dyn_cast_or_null<CXXConstructExpr>(NewLB)) |
| 4110 | if (const CXXConstructorDecl *Ctor = CE->getConstructor()) |
Alexey Bataev | 0d08a7f | 2015-07-16 04:19:43 +0000 | [diff] [blame] | 4111 | if ((Ctor->isCopyOrMoveConstructor() || |
| 4112 | Ctor->isConvertingConstructor(/*AllowExplicit=*/false)) && |
| 4113 | CE->getNumArgs() > 0 && CE->getArg(0) != nullptr) |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 4114 | NewLB = CE->getArg(0)->IgnoreParenImpCasts(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4115 | LB = NewLB; |
| 4116 | return false; |
| 4117 | } |
| 4118 | |
| 4119 | bool OpenMPIterationSpaceChecker::SetUB(Expr *NewUB, bool LessOp, bool StrictOp, |
Craig Topper | e335f25 | 2015-10-04 04:53:55 +0000 | [diff] [blame] | 4120 | SourceRange SR, SourceLocation SL) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4121 | // State consistency checking to ensure correct usage. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4122 | assert(LCDecl != nullptr && LB != nullptr && UB == nullptr && |
| 4123 | Step == nullptr && !TestIsLessOp && !TestIsStrictOp); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4124 | if (!NewUB) |
| 4125 | return true; |
| 4126 | UB = NewUB; |
| 4127 | TestIsLessOp = LessOp; |
| 4128 | TestIsStrictOp = StrictOp; |
| 4129 | ConditionSrcRange = SR; |
| 4130 | ConditionLoc = SL; |
| 4131 | return false; |
| 4132 | } |
| 4133 | |
| 4134 | bool OpenMPIterationSpaceChecker::SetStep(Expr *NewStep, bool Subtract) { |
| 4135 | // State consistency checking to ensure correct usage. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4136 | assert(LCDecl != nullptr && LB != nullptr && Step == nullptr); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4137 | if (!NewStep) |
| 4138 | return true; |
| 4139 | if (!NewStep->isValueDependent()) { |
| 4140 | // Check that the step is integer expression. |
| 4141 | SourceLocation StepLoc = NewStep->getLocStart(); |
| 4142 | ExprResult Val = |
| 4143 | SemaRef.PerformOpenMPImplicitIntegerConversion(StepLoc, NewStep); |
| 4144 | if (Val.isInvalid()) |
| 4145 | return true; |
| 4146 | NewStep = Val.get(); |
| 4147 | |
| 4148 | // OpenMP [2.6, Canonical Loop Form, Restrictions] |
| 4149 | // If test-expr is of form var relational-op b and relational-op is < or |
| 4150 | // <= then incr-expr must cause var to increase on each iteration of the |
| 4151 | // loop. If test-expr is of form var relational-op b and relational-op is |
| 4152 | // > or >= then incr-expr must cause var to decrease on each iteration of |
| 4153 | // the loop. |
| 4154 | // If test-expr is of form b relational-op var and relational-op is < or |
| 4155 | // <= then incr-expr must cause var to decrease on each iteration of the |
| 4156 | // loop. If test-expr is of form b relational-op var and relational-op is |
| 4157 | // > or >= then incr-expr must cause var to increase on each iteration of |
| 4158 | // the loop. |
| 4159 | llvm::APSInt Result; |
| 4160 | bool IsConstant = NewStep->isIntegerConstantExpr(Result, SemaRef.Context); |
| 4161 | bool IsUnsigned = !NewStep->getType()->hasSignedIntegerRepresentation(); |
| 4162 | bool IsConstNeg = |
| 4163 | IsConstant && Result.isSigned() && (Subtract != Result.isNegative()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4164 | bool IsConstPos = |
| 4165 | IsConstant && Result.isSigned() && (Subtract == Result.isNegative()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4166 | bool IsConstZero = IsConstant && !Result.getBoolValue(); |
| 4167 | if (UB && (IsConstZero || |
| 4168 | (TestIsLessOp ? (IsConstNeg || (IsUnsigned && Subtract)) |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4169 | : (IsConstPos || (IsUnsigned && !Subtract))))) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4170 | SemaRef.Diag(NewStep->getExprLoc(), |
| 4171 | diag::err_omp_loop_incr_not_compatible) |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4172 | << LCDecl << TestIsLessOp << NewStep->getSourceRange(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4173 | SemaRef.Diag(ConditionLoc, |
| 4174 | diag::note_omp_loop_cond_requres_compatible_incr) |
| 4175 | << TestIsLessOp << ConditionSrcRange; |
| 4176 | return true; |
| 4177 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4178 | if (TestIsLessOp == Subtract) { |
| 4179 | NewStep = SemaRef.CreateBuiltinUnaryOp(NewStep->getExprLoc(), UO_Minus, |
| 4180 | NewStep).get(); |
| 4181 | Subtract = !Subtract; |
| 4182 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4183 | } |
| 4184 | |
| 4185 | Step = NewStep; |
| 4186 | SubtractStep = Subtract; |
| 4187 | return false; |
| 4188 | } |
| 4189 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 4190 | bool OpenMPIterationSpaceChecker::CheckInit(Stmt *S, bool EmitDiags) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4191 | // Check init-expr for canonical loop form and save loop counter |
| 4192 | // variable - #Var and its initialization value - #LB. |
| 4193 | // OpenMP [2.6] Canonical loop form. init-expr may be one of the following: |
| 4194 | // var = lb |
| 4195 | // integer-type var = lb |
| 4196 | // random-access-iterator-type var = lb |
| 4197 | // pointer-type var = lb |
| 4198 | // |
| 4199 | if (!S) { |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 4200 | if (EmitDiags) { |
| 4201 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_init); |
| 4202 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4203 | return true; |
| 4204 | } |
Tim Shen | 4a05bb8 | 2016-06-21 20:29:17 +0000 | [diff] [blame] | 4205 | if (auto *ExprTemp = dyn_cast<ExprWithCleanups>(S)) |
| 4206 | if (!ExprTemp->cleanupsHaveSideEffects()) |
| 4207 | S = ExprTemp->getSubExpr(); |
| 4208 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4209 | InitSrcRange = S->getSourceRange(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4210 | if (Expr *E = dyn_cast<Expr>(S)) |
| 4211 | S = E->IgnoreParens(); |
| 4212 | if (auto BO = dyn_cast<BinaryOperator>(S)) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4213 | if (BO->getOpcode() == BO_Assign) { |
| 4214 | auto *LHS = BO->getLHS()->IgnoreParens(); |
| 4215 | if (auto *DRE = dyn_cast<DeclRefExpr>(LHS)) { |
| 4216 | if (auto *CED = dyn_cast<OMPCapturedExprDecl>(DRE->getDecl())) |
| 4217 | if (auto *ME = dyn_cast<MemberExpr>(getExprAsWritten(CED->getInit()))) |
| 4218 | return SetLCDeclAndLB(ME->getMemberDecl(), ME, BO->getRHS()); |
| 4219 | return SetLCDeclAndLB(DRE->getDecl(), DRE, BO->getRHS()); |
| 4220 | } |
| 4221 | if (auto *ME = dyn_cast<MemberExpr>(LHS)) { |
| 4222 | if (ME->isArrow() && |
| 4223 | isa<CXXThisExpr>(ME->getBase()->IgnoreParenImpCasts())) |
| 4224 | return SetLCDeclAndLB(ME->getMemberDecl(), ME, BO->getRHS()); |
| 4225 | } |
| 4226 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4227 | } else if (auto DS = dyn_cast<DeclStmt>(S)) { |
| 4228 | if (DS->isSingleDecl()) { |
| 4229 | if (auto Var = dyn_cast_or_null<VarDecl>(DS->getSingleDecl())) { |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 4230 | if (Var->hasInit() && !Var->getType()->isReferenceType()) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4231 | // Accept non-canonical init form here but emit ext. warning. |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 4232 | if (Var->getInitStyle() != VarDecl::CInit && EmitDiags) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4233 | SemaRef.Diag(S->getLocStart(), |
| 4234 | diag::ext_omp_loop_not_canonical_init) |
| 4235 | << S->getSourceRange(); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4236 | return SetLCDeclAndLB(Var, nullptr, Var->getInit()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4237 | } |
| 4238 | } |
| 4239 | } |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4240 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
| 4241 | if (CE->getOperator() == OO_Equal) { |
| 4242 | auto *LHS = CE->getArg(0); |
| 4243 | if (auto DRE = dyn_cast<DeclRefExpr>(LHS)) { |
| 4244 | if (auto *CED = dyn_cast<OMPCapturedExprDecl>(DRE->getDecl())) |
| 4245 | if (auto *ME = dyn_cast<MemberExpr>(getExprAsWritten(CED->getInit()))) |
| 4246 | return SetLCDeclAndLB(ME->getMemberDecl(), ME, BO->getRHS()); |
| 4247 | return SetLCDeclAndLB(DRE->getDecl(), DRE, CE->getArg(1)); |
| 4248 | } |
| 4249 | if (auto *ME = dyn_cast<MemberExpr>(LHS)) { |
| 4250 | if (ME->isArrow() && |
| 4251 | isa<CXXThisExpr>(ME->getBase()->IgnoreParenImpCasts())) |
| 4252 | return SetLCDeclAndLB(ME->getMemberDecl(), ME, BO->getRHS()); |
| 4253 | } |
| 4254 | } |
| 4255 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4256 | |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4257 | if (Dependent() || SemaRef.CurContext->isDependentContext()) |
| 4258 | return false; |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 4259 | if (EmitDiags) { |
| 4260 | SemaRef.Diag(S->getLocStart(), diag::err_omp_loop_not_canonical_init) |
| 4261 | << S->getSourceRange(); |
| 4262 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4263 | return true; |
| 4264 | } |
| 4265 | |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 4266 | /// \brief Ignore parenthesizes, implicit casts, copy constructor and return the |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4267 | /// variable (which may be the loop variable) if possible. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4268 | static const ValueDecl *GetInitLCDecl(Expr *E) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4269 | if (!E) |
Craig Topper | 4b56692 | 2014-06-09 02:04:02 +0000 | [diff] [blame] | 4270 | return nullptr; |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 4271 | E = getExprAsWritten(E); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4272 | if (auto *CE = dyn_cast_or_null<CXXConstructExpr>(E)) |
| 4273 | if (const CXXConstructorDecl *Ctor = CE->getConstructor()) |
Alexey Bataev | 0d08a7f | 2015-07-16 04:19:43 +0000 | [diff] [blame] | 4274 | if ((Ctor->isCopyOrMoveConstructor() || |
| 4275 | Ctor->isConvertingConstructor(/*AllowExplicit=*/false)) && |
| 4276 | CE->getNumArgs() > 0 && CE->getArg(0) != nullptr) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4277 | E = CE->getArg(0)->IgnoreParenImpCasts(); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4278 | if (auto *DRE = dyn_cast_or_null<DeclRefExpr>(E)) { |
| 4279 | if (auto *VD = dyn_cast<VarDecl>(DRE->getDecl())) { |
| 4280 | if (auto *CED = dyn_cast<OMPCapturedExprDecl>(VD)) |
| 4281 | if (auto *ME = dyn_cast<MemberExpr>(getExprAsWritten(CED->getInit()))) |
| 4282 | return getCanonicalDecl(ME->getMemberDecl()); |
| 4283 | return getCanonicalDecl(VD); |
| 4284 | } |
| 4285 | } |
| 4286 | if (auto *ME = dyn_cast_or_null<MemberExpr>(E)) |
| 4287 | if (ME->isArrow() && isa<CXXThisExpr>(ME->getBase()->IgnoreParenImpCasts())) |
| 4288 | return getCanonicalDecl(ME->getMemberDecl()); |
| 4289 | return nullptr; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4290 | } |
| 4291 | |
| 4292 | bool OpenMPIterationSpaceChecker::CheckCond(Expr *S) { |
| 4293 | // Check test-expr for canonical form, save upper-bound UB, flags for |
| 4294 | // less/greater and for strict/non-strict comparison. |
| 4295 | // OpenMP [2.6] Canonical loop form. Test-expr may be one of the following: |
| 4296 | // var relational-op b |
| 4297 | // b relational-op var |
| 4298 | // |
| 4299 | if (!S) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4300 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_cond) << LCDecl; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4301 | return true; |
| 4302 | } |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 4303 | S = getExprAsWritten(S); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4304 | SourceLocation CondLoc = S->getLocStart(); |
| 4305 | if (auto BO = dyn_cast<BinaryOperator>(S)) { |
| 4306 | if (BO->isRelationalOp()) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4307 | if (GetInitLCDecl(BO->getLHS()) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4308 | return SetUB(BO->getRHS(), |
| 4309 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_LE), |
| 4310 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_GT), |
| 4311 | BO->getSourceRange(), BO->getOperatorLoc()); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4312 | if (GetInitLCDecl(BO->getRHS()) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4313 | return SetUB(BO->getLHS(), |
| 4314 | (BO->getOpcode() == BO_GT || BO->getOpcode() == BO_GE), |
| 4315 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_GT), |
| 4316 | BO->getSourceRange(), BO->getOperatorLoc()); |
| 4317 | } |
| 4318 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
| 4319 | if (CE->getNumArgs() == 2) { |
| 4320 | auto Op = CE->getOperator(); |
| 4321 | switch (Op) { |
| 4322 | case OO_Greater: |
| 4323 | case OO_GreaterEqual: |
| 4324 | case OO_Less: |
| 4325 | case OO_LessEqual: |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4326 | if (GetInitLCDecl(CE->getArg(0)) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4327 | return SetUB(CE->getArg(1), Op == OO_Less || Op == OO_LessEqual, |
| 4328 | Op == OO_Less || Op == OO_Greater, CE->getSourceRange(), |
| 4329 | CE->getOperatorLoc()); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4330 | if (GetInitLCDecl(CE->getArg(1)) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4331 | return SetUB(CE->getArg(0), Op == OO_Greater || Op == OO_GreaterEqual, |
| 4332 | Op == OO_Less || Op == OO_Greater, CE->getSourceRange(), |
| 4333 | CE->getOperatorLoc()); |
| 4334 | break; |
| 4335 | default: |
| 4336 | break; |
| 4337 | } |
| 4338 | } |
| 4339 | } |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4340 | if (Dependent() || SemaRef.CurContext->isDependentContext()) |
| 4341 | return false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4342 | SemaRef.Diag(CondLoc, diag::err_omp_loop_not_canonical_cond) |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4343 | << S->getSourceRange() << LCDecl; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4344 | return true; |
| 4345 | } |
| 4346 | |
| 4347 | bool OpenMPIterationSpaceChecker::CheckIncRHS(Expr *RHS) { |
| 4348 | // RHS of canonical loop form increment can be: |
| 4349 | // var + incr |
| 4350 | // incr + var |
| 4351 | // var - incr |
| 4352 | // |
| 4353 | RHS = RHS->IgnoreParenImpCasts(); |
| 4354 | if (auto BO = dyn_cast<BinaryOperator>(RHS)) { |
| 4355 | if (BO->isAdditiveOp()) { |
| 4356 | bool IsAdd = BO->getOpcode() == BO_Add; |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4357 | if (GetInitLCDecl(BO->getLHS()) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4358 | return SetStep(BO->getRHS(), !IsAdd); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4359 | if (IsAdd && GetInitLCDecl(BO->getRHS()) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4360 | return SetStep(BO->getLHS(), false); |
| 4361 | } |
| 4362 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(RHS)) { |
| 4363 | bool IsAdd = CE->getOperator() == OO_Plus; |
| 4364 | if ((IsAdd || CE->getOperator() == OO_Minus) && CE->getNumArgs() == 2) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4365 | if (GetInitLCDecl(CE->getArg(0)) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4366 | return SetStep(CE->getArg(1), !IsAdd); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4367 | if (IsAdd && GetInitLCDecl(CE->getArg(1)) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4368 | return SetStep(CE->getArg(0), false); |
| 4369 | } |
| 4370 | } |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4371 | if (Dependent() || SemaRef.CurContext->isDependentContext()) |
| 4372 | return false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4373 | SemaRef.Diag(RHS->getLocStart(), diag::err_omp_loop_not_canonical_incr) |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4374 | << RHS->getSourceRange() << LCDecl; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4375 | return true; |
| 4376 | } |
| 4377 | |
| 4378 | bool OpenMPIterationSpaceChecker::CheckInc(Expr *S) { |
| 4379 | // Check incr-expr for canonical loop form and return true if it |
| 4380 | // does not conform. |
| 4381 | // OpenMP [2.6] Canonical loop form. Test-expr may be one of the following: |
| 4382 | // ++var |
| 4383 | // var++ |
| 4384 | // --var |
| 4385 | // var-- |
| 4386 | // var += incr |
| 4387 | // var -= incr |
| 4388 | // var = var + incr |
| 4389 | // var = incr + var |
| 4390 | // var = var - incr |
| 4391 | // |
| 4392 | if (!S) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4393 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_incr) << LCDecl; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4394 | return true; |
| 4395 | } |
Tim Shen | 4a05bb8 | 2016-06-21 20:29:17 +0000 | [diff] [blame] | 4396 | if (auto *ExprTemp = dyn_cast<ExprWithCleanups>(S)) |
| 4397 | if (!ExprTemp->cleanupsHaveSideEffects()) |
| 4398 | S = ExprTemp->getSubExpr(); |
| 4399 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4400 | IncrementSrcRange = S->getSourceRange(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4401 | S = S->IgnoreParens(); |
| 4402 | if (auto UO = dyn_cast<UnaryOperator>(S)) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4403 | if (UO->isIncrementDecrementOp() && |
| 4404 | GetInitLCDecl(UO->getSubExpr()) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4405 | return SetStep( |
| 4406 | SemaRef.ActOnIntegerConstant(UO->getLocStart(), |
| 4407 | (UO->isDecrementOp() ? -1 : 1)).get(), |
| 4408 | false); |
| 4409 | } else if (auto BO = dyn_cast<BinaryOperator>(S)) { |
| 4410 | switch (BO->getOpcode()) { |
| 4411 | case BO_AddAssign: |
| 4412 | case BO_SubAssign: |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4413 | if (GetInitLCDecl(BO->getLHS()) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4414 | return SetStep(BO->getRHS(), BO->getOpcode() == BO_SubAssign); |
| 4415 | break; |
| 4416 | case BO_Assign: |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4417 | if (GetInitLCDecl(BO->getLHS()) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4418 | return CheckIncRHS(BO->getRHS()); |
| 4419 | break; |
| 4420 | default: |
| 4421 | break; |
| 4422 | } |
| 4423 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
| 4424 | switch (CE->getOperator()) { |
| 4425 | case OO_PlusPlus: |
| 4426 | case OO_MinusMinus: |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4427 | if (GetInitLCDecl(CE->getArg(0)) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4428 | return SetStep( |
| 4429 | SemaRef.ActOnIntegerConstant( |
| 4430 | CE->getLocStart(), |
| 4431 | ((CE->getOperator() == OO_MinusMinus) ? -1 : 1)).get(), |
| 4432 | false); |
| 4433 | break; |
| 4434 | case OO_PlusEqual: |
| 4435 | case OO_MinusEqual: |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4436 | if (GetInitLCDecl(CE->getArg(0)) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4437 | return SetStep(CE->getArg(1), CE->getOperator() == OO_MinusEqual); |
| 4438 | break; |
| 4439 | case OO_Equal: |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4440 | if (GetInitLCDecl(CE->getArg(0)) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4441 | return CheckIncRHS(CE->getArg(1)); |
| 4442 | break; |
| 4443 | default: |
| 4444 | break; |
| 4445 | } |
| 4446 | } |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4447 | if (Dependent() || SemaRef.CurContext->isDependentContext()) |
| 4448 | return false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4449 | SemaRef.Diag(S->getLocStart(), diag::err_omp_loop_not_canonical_incr) |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4450 | << S->getSourceRange() << LCDecl; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4451 | return true; |
| 4452 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4453 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4454 | static ExprResult |
| 4455 | tryBuildCapture(Sema &SemaRef, Expr *Capture, |
| 4456 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) { |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 4457 | if (SemaRef.CurContext->isDependentContext()) |
| 4458 | return ExprResult(Capture); |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4459 | if (Capture->isEvaluatable(SemaRef.Context, Expr::SE_AllowSideEffects)) |
| 4460 | return SemaRef.PerformImplicitConversion( |
| 4461 | Capture->IgnoreImpCasts(), Capture->getType(), Sema::AA_Converting, |
| 4462 | /*AllowExplicit=*/true); |
| 4463 | auto I = Captures.find(Capture); |
| 4464 | if (I != Captures.end()) |
| 4465 | return buildCapture(SemaRef, Capture, I->second); |
| 4466 | DeclRefExpr *Ref = nullptr; |
| 4467 | ExprResult Res = buildCapture(SemaRef, Capture, Ref); |
| 4468 | Captures[Capture] = Ref; |
| 4469 | return Res; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4470 | } |
| 4471 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4472 | /// \brief Build the expression to calculate the number of iterations. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4473 | Expr *OpenMPIterationSpaceChecker::BuildNumIterations( |
| 4474 | Scope *S, const bool LimitedType, |
| 4475 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) const { |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4476 | ExprResult Diff; |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4477 | auto VarType = LCDecl->getType().getNonReferenceType(); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4478 | if (VarType->isIntegerType() || VarType->isPointerType() || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4479 | SemaRef.getLangOpts().CPlusPlus) { |
| 4480 | // Upper - Lower |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4481 | auto *UBExpr = TestIsLessOp ? UB : LB; |
| 4482 | auto *LBExpr = TestIsLessOp ? LB : UB; |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4483 | Expr *Upper = tryBuildCapture(SemaRef, UBExpr, Captures).get(); |
| 4484 | Expr *Lower = tryBuildCapture(SemaRef, LBExpr, Captures).get(); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4485 | if (!Upper || !Lower) |
| 4486 | return nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4487 | |
| 4488 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Sub, Upper, Lower); |
| 4489 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4490 | if (!Diff.isUsable() && VarType->getAsCXXRecordDecl()) { |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4491 | // BuildBinOp already emitted error, this one is to point user to upper |
| 4492 | // and lower bound, and to tell what is passed to 'operator-'. |
| 4493 | SemaRef.Diag(Upper->getLocStart(), diag::err_omp_loop_diff_cxx) |
| 4494 | << Upper->getSourceRange() << Lower->getSourceRange(); |
| 4495 | return nullptr; |
| 4496 | } |
| 4497 | } |
| 4498 | |
| 4499 | if (!Diff.isUsable()) |
| 4500 | return nullptr; |
| 4501 | |
| 4502 | // Upper - Lower [- 1] |
| 4503 | if (TestIsStrictOp) |
| 4504 | Diff = SemaRef.BuildBinOp( |
| 4505 | S, DefaultLoc, BO_Sub, Diff.get(), |
| 4506 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 4507 | if (!Diff.isUsable()) |
| 4508 | return nullptr; |
| 4509 | |
| 4510 | // Upper - Lower [- 1] + Step |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4511 | auto NewStep = tryBuildCapture(SemaRef, Step, Captures); |
| 4512 | if (!NewStep.isUsable()) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4513 | return nullptr; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4514 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Add, Diff.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4515 | if (!Diff.isUsable()) |
| 4516 | return nullptr; |
| 4517 | |
| 4518 | // Parentheses (for dumping/debugging purposes only). |
| 4519 | Diff = SemaRef.ActOnParenExpr(DefaultLoc, DefaultLoc, Diff.get()); |
| 4520 | if (!Diff.isUsable()) |
| 4521 | return nullptr; |
| 4522 | |
| 4523 | // (Upper - Lower [- 1] + Step) / Step |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4524 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Div, Diff.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4525 | if (!Diff.isUsable()) |
| 4526 | return nullptr; |
| 4527 | |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 4528 | // OpenMP runtime requires 32-bit or 64-bit loop variables. |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4529 | QualType Type = Diff.get()->getType(); |
| 4530 | auto &C = SemaRef.Context; |
| 4531 | bool UseVarType = VarType->hasIntegerRepresentation() && |
| 4532 | C.getTypeSize(Type) > C.getTypeSize(VarType); |
| 4533 | if (!Type->isIntegerType() || UseVarType) { |
| 4534 | unsigned NewSize = |
| 4535 | UseVarType ? C.getTypeSize(VarType) : C.getTypeSize(Type); |
| 4536 | bool IsSigned = UseVarType ? VarType->hasSignedIntegerRepresentation() |
| 4537 | : Type->hasSignedIntegerRepresentation(); |
| 4538 | Type = C.getIntTypeForBitwidth(NewSize, IsSigned); |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 4539 | if (!SemaRef.Context.hasSameType(Diff.get()->getType(), Type)) { |
| 4540 | Diff = SemaRef.PerformImplicitConversion( |
| 4541 | Diff.get(), Type, Sema::AA_Converting, /*AllowExplicit=*/true); |
| 4542 | if (!Diff.isUsable()) |
| 4543 | return nullptr; |
| 4544 | } |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4545 | } |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 4546 | if (LimitedType) { |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 4547 | unsigned NewSize = (C.getTypeSize(Type) > 32) ? 64 : 32; |
| 4548 | if (NewSize != C.getTypeSize(Type)) { |
| 4549 | if (NewSize < C.getTypeSize(Type)) { |
| 4550 | assert(NewSize == 64 && "incorrect loop var size"); |
| 4551 | SemaRef.Diag(DefaultLoc, diag::warn_omp_loop_64_bit_var) |
| 4552 | << InitSrcRange << ConditionSrcRange; |
| 4553 | } |
| 4554 | QualType NewType = C.getIntTypeForBitwidth( |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4555 | NewSize, Type->hasSignedIntegerRepresentation() || |
| 4556 | C.getTypeSize(Type) < NewSize); |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 4557 | if (!SemaRef.Context.hasSameType(Diff.get()->getType(), NewType)) { |
| 4558 | Diff = SemaRef.PerformImplicitConversion(Diff.get(), NewType, |
| 4559 | Sema::AA_Converting, true); |
| 4560 | if (!Diff.isUsable()) |
| 4561 | return nullptr; |
| 4562 | } |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 4563 | } |
| 4564 | } |
| 4565 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4566 | return Diff.get(); |
| 4567 | } |
| 4568 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4569 | Expr *OpenMPIterationSpaceChecker::BuildPreCond( |
| 4570 | Scope *S, Expr *Cond, |
| 4571 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) const { |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 4572 | // Try to build LB <op> UB, where <op> is <, >, <=, or >=. |
| 4573 | bool Suppress = SemaRef.getDiagnostics().getSuppressAllDiagnostics(); |
| 4574 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(/*Val=*/true); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4575 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4576 | auto NewLB = tryBuildCapture(SemaRef, LB, Captures); |
| 4577 | auto NewUB = tryBuildCapture(SemaRef, UB, Captures); |
| 4578 | if (!NewLB.isUsable() || !NewUB.isUsable()) |
| 4579 | return nullptr; |
| 4580 | |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 4581 | auto CondExpr = SemaRef.BuildBinOp( |
| 4582 | S, DefaultLoc, TestIsLessOp ? (TestIsStrictOp ? BO_LT : BO_LE) |
| 4583 | : (TestIsStrictOp ? BO_GT : BO_GE), |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4584 | NewLB.get(), NewUB.get()); |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 4585 | if (CondExpr.isUsable()) { |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4586 | if (!SemaRef.Context.hasSameUnqualifiedType(CondExpr.get()->getType(), |
| 4587 | SemaRef.Context.BoolTy)) |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 4588 | CondExpr = SemaRef.PerformImplicitConversion( |
| 4589 | CondExpr.get(), SemaRef.Context.BoolTy, /*Action=*/Sema::AA_Casting, |
| 4590 | /*AllowExplicit=*/true); |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 4591 | } |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 4592 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(Suppress); |
| 4593 | // Otherwise use original loop conditon and evaluate it in runtime. |
| 4594 | return CondExpr.isUsable() ? CondExpr.get() : Cond; |
| 4595 | } |
| 4596 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4597 | /// \brief Build reference expression to the counter be used for codegen. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4598 | DeclRefExpr *OpenMPIterationSpaceChecker::BuildCounterVar( |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 4599 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures, DSAStackTy &DSA) const { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4600 | auto *VD = dyn_cast<VarDecl>(LCDecl); |
| 4601 | if (!VD) { |
| 4602 | VD = SemaRef.IsOpenMPCapturedDecl(LCDecl); |
| 4603 | auto *Ref = buildDeclRefExpr( |
| 4604 | SemaRef, VD, VD->getType().getNonReferenceType(), DefaultLoc); |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 4605 | DSAStackTy::DSAVarData Data = DSA.getTopDSA(LCDecl, /*FromParent=*/false); |
| 4606 | // If the loop control decl is explicitly marked as private, do not mark it |
| 4607 | // as captured again. |
| 4608 | if (!isOpenMPPrivate(Data.CKind) || !Data.RefExpr) |
| 4609 | Captures.insert(std::make_pair(LCRef, Ref)); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4610 | return Ref; |
| 4611 | } |
| 4612 | return buildDeclRefExpr(SemaRef, VD, VD->getType().getNonReferenceType(), |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 4613 | DefaultLoc); |
| 4614 | } |
| 4615 | |
| 4616 | Expr *OpenMPIterationSpaceChecker::BuildPrivateCounterVar() const { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4617 | if (LCDecl && !LCDecl->isInvalidDecl()) { |
| 4618 | auto Type = LCDecl->getType().getNonReferenceType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 4619 | auto *PrivateVar = |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4620 | buildVarDecl(SemaRef, DefaultLoc, Type, LCDecl->getName(), |
| 4621 | LCDecl->hasAttrs() ? &LCDecl->getAttrs() : nullptr); |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 4622 | if (PrivateVar->isInvalidDecl()) |
| 4623 | return nullptr; |
| 4624 | return buildDeclRefExpr(SemaRef, PrivateVar, Type, DefaultLoc); |
| 4625 | } |
| 4626 | return nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4627 | } |
| 4628 | |
| 4629 | /// \brief Build initization of the counter be used for codegen. |
| 4630 | Expr *OpenMPIterationSpaceChecker::BuildCounterInit() const { return LB; } |
| 4631 | |
| 4632 | /// \brief Build step of the counter be used for codegen. |
| 4633 | Expr *OpenMPIterationSpaceChecker::BuildCounterStep() const { return Step; } |
| 4634 | |
| 4635 | /// \brief Iteration space of a single for loop. |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 4636 | struct LoopIterationSpace final { |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 4637 | /// \brief Condition of the loop. |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 4638 | Expr *PreCond = nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4639 | /// \brief This expression calculates the number of iterations in the loop. |
| 4640 | /// It is always possible to calculate it before starting the loop. |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 4641 | Expr *NumIterations = nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4642 | /// \brief The loop counter variable. |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 4643 | Expr *CounterVar = nullptr; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 4644 | /// \brief Private loop counter variable. |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 4645 | Expr *PrivateCounterVar = nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4646 | /// \brief This is initializer for the initial value of #CounterVar. |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 4647 | Expr *CounterInit = nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4648 | /// \brief This is step for the #CounterVar used to generate its update: |
| 4649 | /// #CounterVar = #CounterInit + #CounterStep * CurrentIteration. |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 4650 | Expr *CounterStep = nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4651 | /// \brief Should step be subtracted? |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 4652 | bool Subtract = false; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4653 | /// \brief Source range of the loop init. |
| 4654 | SourceRange InitSrcRange; |
| 4655 | /// \brief Source range of the loop condition. |
| 4656 | SourceRange CondSrcRange; |
| 4657 | /// \brief Source range of the loop increment. |
| 4658 | SourceRange IncSrcRange; |
| 4659 | }; |
| 4660 | |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 4661 | } // namespace |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4662 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 4663 | void Sema::ActOnOpenMPLoopInitialization(SourceLocation ForLoc, Stmt *Init) { |
| 4664 | assert(getLangOpts().OpenMP && "OpenMP is not active."); |
| 4665 | assert(Init && "Expected loop in canonical form."); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 4666 | unsigned AssociatedLoops = DSAStack->getAssociatedLoops(); |
| 4667 | if (AssociatedLoops > 0 && |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 4668 | isOpenMPLoopDirective(DSAStack->getCurrentDirective())) { |
| 4669 | OpenMPIterationSpaceChecker ISC(*this, ForLoc); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4670 | if (!ISC.CheckInit(Init, /*EmitDiags=*/false)) { |
| 4671 | if (auto *D = ISC.GetLoopDecl()) { |
| 4672 | auto *VD = dyn_cast<VarDecl>(D); |
| 4673 | if (!VD) { |
| 4674 | if (auto *Private = IsOpenMPCapturedDecl(D)) |
| 4675 | VD = Private; |
| 4676 | else { |
| 4677 | auto *Ref = buildCapture(*this, D, ISC.GetLoopDeclRefExpr(), |
| 4678 | /*WithInit=*/false); |
| 4679 | VD = cast<VarDecl>(Ref->getDecl()); |
| 4680 | } |
| 4681 | } |
| 4682 | DSAStack->addLoopControlVariable(D, VD); |
| 4683 | } |
| 4684 | } |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 4685 | DSAStack->setAssociatedLoops(AssociatedLoops - 1); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 4686 | } |
| 4687 | } |
| 4688 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4689 | /// \brief Called on a for stmt to check and extract its iteration space |
| 4690 | /// for further processing (such as collapsing). |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4691 | static bool CheckOpenMPIterationSpace( |
| 4692 | OpenMPDirectiveKind DKind, Stmt *S, Sema &SemaRef, DSAStackTy &DSA, |
| 4693 | unsigned CurrentNestedLoopCount, unsigned NestedLoopCount, |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4694 | Expr *CollapseLoopCountExpr, Expr *OrderedLoopCountExpr, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 4695 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4696 | LoopIterationSpace &ResultIterSpace, |
| 4697 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4698 | // OpenMP [2.6, Canonical Loop Form] |
| 4699 | // for (init-expr; test-expr; incr-expr) structured-block |
| 4700 | auto For = dyn_cast_or_null<ForStmt>(S); |
| 4701 | if (!For) { |
| 4702 | SemaRef.Diag(S->getLocStart(), diag::err_omp_not_for) |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4703 | << (CollapseLoopCountExpr != nullptr || OrderedLoopCountExpr != nullptr) |
| 4704 | << getOpenMPDirectiveName(DKind) << NestedLoopCount |
| 4705 | << (CurrentNestedLoopCount > 0) << CurrentNestedLoopCount; |
| 4706 | if (NestedLoopCount > 1) { |
| 4707 | if (CollapseLoopCountExpr && OrderedLoopCountExpr) |
| 4708 | SemaRef.Diag(DSA.getConstructLoc(), |
| 4709 | diag::note_omp_collapse_ordered_expr) |
| 4710 | << 2 << CollapseLoopCountExpr->getSourceRange() |
| 4711 | << OrderedLoopCountExpr->getSourceRange(); |
| 4712 | else if (CollapseLoopCountExpr) |
| 4713 | SemaRef.Diag(CollapseLoopCountExpr->getExprLoc(), |
| 4714 | diag::note_omp_collapse_ordered_expr) |
| 4715 | << 0 << CollapseLoopCountExpr->getSourceRange(); |
| 4716 | else |
| 4717 | SemaRef.Diag(OrderedLoopCountExpr->getExprLoc(), |
| 4718 | diag::note_omp_collapse_ordered_expr) |
| 4719 | << 1 << OrderedLoopCountExpr->getSourceRange(); |
| 4720 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4721 | return true; |
| 4722 | } |
| 4723 | assert(For->getBody()); |
| 4724 | |
| 4725 | OpenMPIterationSpaceChecker ISC(SemaRef, For->getForLoc()); |
| 4726 | |
| 4727 | // Check init. |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 4728 | auto Init = For->getInit(); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4729 | if (ISC.CheckInit(Init)) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4730 | return true; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4731 | |
| 4732 | bool HasErrors = false; |
| 4733 | |
| 4734 | // Check loop variable's type. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4735 | if (auto *LCDecl = ISC.GetLoopDecl()) { |
| 4736 | auto *LoopDeclRefExpr = ISC.GetLoopDeclRefExpr(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4737 | |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4738 | // OpenMP [2.6, Canonical Loop Form] |
| 4739 | // Var is one of the following: |
| 4740 | // A variable of signed or unsigned integer type. |
| 4741 | // For C++, a variable of a random access iterator type. |
| 4742 | // For C, a variable of a pointer type. |
| 4743 | auto VarType = LCDecl->getType().getNonReferenceType(); |
| 4744 | if (!VarType->isDependentType() && !VarType->isIntegerType() && |
| 4745 | !VarType->isPointerType() && |
| 4746 | !(SemaRef.getLangOpts().CPlusPlus && VarType->isOverloadableType())) { |
| 4747 | SemaRef.Diag(Init->getLocStart(), diag::err_omp_loop_variable_type) |
| 4748 | << SemaRef.getLangOpts().CPlusPlus; |
| 4749 | HasErrors = true; |
| 4750 | } |
| 4751 | |
| 4752 | // OpenMP, 2.14.1.1 Data-sharing Attribute Rules for Variables Referenced in |
| 4753 | // a Construct |
| 4754 | // The loop iteration variable(s) in the associated for-loop(s) of a for or |
| 4755 | // parallel for construct is (are) private. |
| 4756 | // The loop iteration variable in the associated for-loop of a simd |
| 4757 | // construct with just one associated for-loop is linear with a |
| 4758 | // constant-linear-step that is the increment of the associated for-loop. |
| 4759 | // Exclude loop var from the list of variables with implicitly defined data |
| 4760 | // sharing attributes. |
| 4761 | VarsWithImplicitDSA.erase(LCDecl); |
| 4762 | |
| 4763 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 4764 | // in a Construct, C/C++]. |
| 4765 | // The loop iteration variable in the associated for-loop of a simd |
| 4766 | // construct with just one associated for-loop may be listed in a linear |
| 4767 | // clause with a constant-linear-step that is the increment of the |
| 4768 | // associated for-loop. |
| 4769 | // The loop iteration variable(s) in the associated for-loop(s) of a for or |
| 4770 | // parallel for construct may be listed in a private or lastprivate clause. |
| 4771 | DSAStackTy::DSAVarData DVar = DSA.getTopDSA(LCDecl, false); |
| 4772 | // If LoopVarRefExpr is nullptr it means the corresponding loop variable is |
| 4773 | // declared in the loop and it is predetermined as a private. |
| 4774 | auto PredeterminedCKind = |
| 4775 | isOpenMPSimdDirective(DKind) |
| 4776 | ? ((NestedLoopCount == 1) ? OMPC_linear : OMPC_lastprivate) |
| 4777 | : OMPC_private; |
| 4778 | if (((isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown && |
| 4779 | DVar.CKind != PredeterminedCKind) || |
| 4780 | ((isOpenMPWorksharingDirective(DKind) || DKind == OMPD_taskloop || |
| 4781 | isOpenMPDistributeDirective(DKind)) && |
| 4782 | !isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown && |
| 4783 | DVar.CKind != OMPC_private && DVar.CKind != OMPC_lastprivate)) && |
| 4784 | (DVar.CKind != OMPC_private || DVar.RefExpr != nullptr)) { |
| 4785 | SemaRef.Diag(Init->getLocStart(), diag::err_omp_loop_var_dsa) |
| 4786 | << getOpenMPClauseName(DVar.CKind) << getOpenMPDirectiveName(DKind) |
| 4787 | << getOpenMPClauseName(PredeterminedCKind); |
| 4788 | if (DVar.RefExpr == nullptr) |
| 4789 | DVar.CKind = PredeterminedCKind; |
| 4790 | ReportOriginalDSA(SemaRef, &DSA, LCDecl, DVar, /*IsLoopIterVar=*/true); |
| 4791 | HasErrors = true; |
| 4792 | } else if (LoopDeclRefExpr != nullptr) { |
| 4793 | // Make the loop iteration variable private (for worksharing constructs), |
| 4794 | // linear (for simd directives with the only one associated loop) or |
| 4795 | // lastprivate (for simd directives with several collapsed or ordered |
| 4796 | // loops). |
| 4797 | if (DVar.CKind == OMPC_unknown) |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 4798 | DVar = DSA.hasDSA(LCDecl, isOpenMPPrivate, |
| 4799 | [](OpenMPDirectiveKind) -> bool { return true; }, |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4800 | /*FromParent=*/false); |
| 4801 | DSA.addDSA(LCDecl, LoopDeclRefExpr, PredeterminedCKind); |
| 4802 | } |
| 4803 | |
| 4804 | assert(isOpenMPLoopDirective(DKind) && "DSA for non-loop vars"); |
| 4805 | |
| 4806 | // Check test-expr. |
| 4807 | HasErrors |= ISC.CheckCond(For->getCond()); |
| 4808 | |
| 4809 | // Check incr-expr. |
| 4810 | HasErrors |= ISC.CheckInc(For->getInc()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4811 | } |
| 4812 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4813 | if (ISC.Dependent() || SemaRef.CurContext->isDependentContext() || HasErrors) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4814 | return HasErrors; |
| 4815 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4816 | // Build the loop's iteration space representation. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4817 | ResultIterSpace.PreCond = |
| 4818 | ISC.BuildPreCond(DSA.getCurScope(), For->getCond(), Captures); |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 4819 | ResultIterSpace.NumIterations = ISC.BuildNumIterations( |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4820 | DSA.getCurScope(), |
| 4821 | (isOpenMPWorksharingDirective(DKind) || |
| 4822 | isOpenMPTaskLoopDirective(DKind) || isOpenMPDistributeDirective(DKind)), |
| 4823 | Captures); |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 4824 | ResultIterSpace.CounterVar = ISC.BuildCounterVar(Captures, DSA); |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 4825 | ResultIterSpace.PrivateCounterVar = ISC.BuildPrivateCounterVar(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4826 | ResultIterSpace.CounterInit = ISC.BuildCounterInit(); |
| 4827 | ResultIterSpace.CounterStep = ISC.BuildCounterStep(); |
| 4828 | ResultIterSpace.InitSrcRange = ISC.GetInitSrcRange(); |
| 4829 | ResultIterSpace.CondSrcRange = ISC.GetConditionSrcRange(); |
| 4830 | ResultIterSpace.IncSrcRange = ISC.GetIncrementSrcRange(); |
| 4831 | ResultIterSpace.Subtract = ISC.ShouldSubtractStep(); |
| 4832 | |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 4833 | HasErrors |= (ResultIterSpace.PreCond == nullptr || |
| 4834 | ResultIterSpace.NumIterations == nullptr || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4835 | ResultIterSpace.CounterVar == nullptr || |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 4836 | ResultIterSpace.PrivateCounterVar == nullptr || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4837 | ResultIterSpace.CounterInit == nullptr || |
| 4838 | ResultIterSpace.CounterStep == nullptr); |
| 4839 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4840 | return HasErrors; |
| 4841 | } |
| 4842 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4843 | /// \brief Build 'VarRef = Start. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4844 | static ExprResult |
| 4845 | BuildCounterInit(Sema &SemaRef, Scope *S, SourceLocation Loc, ExprResult VarRef, |
| 4846 | ExprResult Start, |
| 4847 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) { |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4848 | // Build 'VarRef = Start. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4849 | auto NewStart = tryBuildCapture(SemaRef, Start.get(), Captures); |
| 4850 | if (!NewStart.isUsable()) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4851 | return ExprError(); |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 4852 | if (!SemaRef.Context.hasSameType(NewStart.get()->getType(), |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 4853 | VarRef.get()->getType())) { |
| 4854 | NewStart = SemaRef.PerformImplicitConversion( |
| 4855 | NewStart.get(), VarRef.get()->getType(), Sema::AA_Converting, |
| 4856 | /*AllowExplicit=*/true); |
| 4857 | if (!NewStart.isUsable()) |
| 4858 | return ExprError(); |
| 4859 | } |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4860 | |
| 4861 | auto Init = |
| 4862 | SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), NewStart.get()); |
| 4863 | return Init; |
| 4864 | } |
| 4865 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4866 | /// \brief Build 'VarRef = Start + Iter * Step'. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4867 | static ExprResult |
| 4868 | BuildCounterUpdate(Sema &SemaRef, Scope *S, SourceLocation Loc, |
| 4869 | ExprResult VarRef, ExprResult Start, ExprResult Iter, |
| 4870 | ExprResult Step, bool Subtract, |
| 4871 | llvm::MapVector<Expr *, DeclRefExpr *> *Captures = nullptr) { |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4872 | // Add parentheses (for debugging purposes only). |
| 4873 | Iter = SemaRef.ActOnParenExpr(Loc, Loc, Iter.get()); |
| 4874 | if (!VarRef.isUsable() || !Start.isUsable() || !Iter.isUsable() || |
| 4875 | !Step.isUsable()) |
| 4876 | return ExprError(); |
| 4877 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4878 | ExprResult NewStep = Step; |
| 4879 | if (Captures) |
| 4880 | NewStep = tryBuildCapture(SemaRef, Step.get(), *Captures); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4881 | if (NewStep.isInvalid()) |
| 4882 | return ExprError(); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4883 | ExprResult Update = |
| 4884 | SemaRef.BuildBinOp(S, Loc, BO_Mul, Iter.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4885 | if (!Update.isUsable()) |
| 4886 | return ExprError(); |
| 4887 | |
Alexey Bataev | c0214e0 | 2016-02-16 12:13:49 +0000 | [diff] [blame] | 4888 | // Try to build 'VarRef = Start, VarRef (+|-)= Iter * Step' or |
| 4889 | // 'VarRef = Start (+|-) Iter * Step'. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4890 | ExprResult NewStart = Start; |
| 4891 | if (Captures) |
| 4892 | NewStart = tryBuildCapture(SemaRef, Start.get(), *Captures); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4893 | if (NewStart.isInvalid()) |
| 4894 | return ExprError(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4895 | |
Alexey Bataev | c0214e0 | 2016-02-16 12:13:49 +0000 | [diff] [blame] | 4896 | // First attempt: try to build 'VarRef = Start, VarRef += Iter * Step'. |
| 4897 | ExprResult SavedUpdate = Update; |
| 4898 | ExprResult UpdateVal; |
| 4899 | if (VarRef.get()->getType()->isOverloadableType() || |
| 4900 | NewStart.get()->getType()->isOverloadableType() || |
| 4901 | Update.get()->getType()->isOverloadableType()) { |
| 4902 | bool Suppress = SemaRef.getDiagnostics().getSuppressAllDiagnostics(); |
| 4903 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(/*Val=*/true); |
| 4904 | Update = |
| 4905 | SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), NewStart.get()); |
| 4906 | if (Update.isUsable()) { |
| 4907 | UpdateVal = |
| 4908 | SemaRef.BuildBinOp(S, Loc, Subtract ? BO_SubAssign : BO_AddAssign, |
| 4909 | VarRef.get(), SavedUpdate.get()); |
| 4910 | if (UpdateVal.isUsable()) { |
| 4911 | Update = SemaRef.CreateBuiltinBinOp(Loc, BO_Comma, Update.get(), |
| 4912 | UpdateVal.get()); |
| 4913 | } |
| 4914 | } |
| 4915 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(Suppress); |
| 4916 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4917 | |
Alexey Bataev | c0214e0 | 2016-02-16 12:13:49 +0000 | [diff] [blame] | 4918 | // Second attempt: try to build 'VarRef = Start (+|-) Iter * Step'. |
| 4919 | if (!Update.isUsable() || !UpdateVal.isUsable()) { |
| 4920 | Update = SemaRef.BuildBinOp(S, Loc, Subtract ? BO_Sub : BO_Add, |
| 4921 | NewStart.get(), SavedUpdate.get()); |
| 4922 | if (!Update.isUsable()) |
| 4923 | return ExprError(); |
| 4924 | |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 4925 | if (!SemaRef.Context.hasSameType(Update.get()->getType(), |
| 4926 | VarRef.get()->getType())) { |
| 4927 | Update = SemaRef.PerformImplicitConversion( |
| 4928 | Update.get(), VarRef.get()->getType(), Sema::AA_Converting, true); |
| 4929 | if (!Update.isUsable()) |
| 4930 | return ExprError(); |
| 4931 | } |
Alexey Bataev | c0214e0 | 2016-02-16 12:13:49 +0000 | [diff] [blame] | 4932 | |
| 4933 | Update = SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), Update.get()); |
| 4934 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4935 | return Update; |
| 4936 | } |
| 4937 | |
| 4938 | /// \brief Convert integer expression \a E to make it have at least \a Bits |
| 4939 | /// bits. |
| 4940 | static ExprResult WidenIterationCount(unsigned Bits, Expr *E, |
| 4941 | Sema &SemaRef) { |
| 4942 | if (E == nullptr) |
| 4943 | return ExprError(); |
| 4944 | auto &C = SemaRef.Context; |
| 4945 | QualType OldType = E->getType(); |
| 4946 | unsigned HasBits = C.getTypeSize(OldType); |
| 4947 | if (HasBits >= Bits) |
| 4948 | return ExprResult(E); |
| 4949 | // OK to convert to signed, because new type has more bits than old. |
| 4950 | QualType NewType = C.getIntTypeForBitwidth(Bits, /* Signed */ true); |
| 4951 | return SemaRef.PerformImplicitConversion(E, NewType, Sema::AA_Converting, |
| 4952 | true); |
| 4953 | } |
| 4954 | |
| 4955 | /// \brief Check if the given expression \a E is a constant integer that fits |
| 4956 | /// into \a Bits bits. |
| 4957 | static bool FitsInto(unsigned Bits, bool Signed, Expr *E, Sema &SemaRef) { |
| 4958 | if (E == nullptr) |
| 4959 | return false; |
| 4960 | llvm::APSInt Result; |
| 4961 | if (E->isIntegerConstantExpr(Result, SemaRef.Context)) |
| 4962 | return Signed ? Result.isSignedIntN(Bits) : Result.isIntN(Bits); |
| 4963 | return false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4964 | } |
| 4965 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4966 | /// Build preinits statement for the given declarations. |
| 4967 | static Stmt *buildPreInits(ASTContext &Context, |
| 4968 | SmallVectorImpl<Decl *> &PreInits) { |
| 4969 | if (!PreInits.empty()) { |
| 4970 | return new (Context) DeclStmt( |
| 4971 | DeclGroupRef::Create(Context, PreInits.begin(), PreInits.size()), |
| 4972 | SourceLocation(), SourceLocation()); |
| 4973 | } |
| 4974 | return nullptr; |
| 4975 | } |
| 4976 | |
| 4977 | /// Build preinits statement for the given declarations. |
| 4978 | static Stmt *buildPreInits(ASTContext &Context, |
| 4979 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) { |
| 4980 | if (!Captures.empty()) { |
| 4981 | SmallVector<Decl *, 16> PreInits; |
| 4982 | for (auto &Pair : Captures) |
| 4983 | PreInits.push_back(Pair.second->getDecl()); |
| 4984 | return buildPreInits(Context, PreInits); |
| 4985 | } |
| 4986 | return nullptr; |
| 4987 | } |
| 4988 | |
| 4989 | /// Build postupdate expression for the given list of postupdates expressions. |
| 4990 | static Expr *buildPostUpdate(Sema &S, ArrayRef<Expr *> PostUpdates) { |
| 4991 | Expr *PostUpdate = nullptr; |
| 4992 | if (!PostUpdates.empty()) { |
| 4993 | for (auto *E : PostUpdates) { |
| 4994 | Expr *ConvE = S.BuildCStyleCastExpr( |
| 4995 | E->getExprLoc(), |
| 4996 | S.Context.getTrivialTypeSourceInfo(S.Context.VoidTy), |
| 4997 | E->getExprLoc(), E) |
| 4998 | .get(); |
| 4999 | PostUpdate = PostUpdate |
| 5000 | ? S.CreateBuiltinBinOp(ConvE->getExprLoc(), BO_Comma, |
| 5001 | PostUpdate, ConvE) |
| 5002 | .get() |
| 5003 | : ConvE; |
| 5004 | } |
| 5005 | } |
| 5006 | return PostUpdate; |
| 5007 | } |
| 5008 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5009 | /// \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] | 5010 | /// \return Returns 0 if one of the collapsed stmts is not canonical for loop, |
| 5011 | /// number of collapsed loops otherwise. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 5012 | static unsigned |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5013 | CheckOpenMPLoop(OpenMPDirectiveKind DKind, Expr *CollapseLoopCountExpr, |
| 5014 | Expr *OrderedLoopCountExpr, Stmt *AStmt, Sema &SemaRef, |
| 5015 | DSAStackTy &DSA, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 5016 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA, |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5017 | OMPLoopDirective::HelperExprs &Built) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 5018 | unsigned NestedLoopCount = 1; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5019 | if (CollapseLoopCountExpr) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 5020 | // Found 'collapse' clause - calculate collapse number. |
| 5021 | llvm::APSInt Result; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5022 | if (CollapseLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext())) |
Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 5023 | NestedLoopCount = Result.getLimitedValue(); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5024 | } |
| 5025 | if (OrderedLoopCountExpr) { |
| 5026 | // Found 'ordered' clause - calculate collapse number. |
| 5027 | llvm::APSInt Result; |
Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 5028 | if (OrderedLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext())) { |
| 5029 | if (Result.getLimitedValue() < NestedLoopCount) { |
| 5030 | SemaRef.Diag(OrderedLoopCountExpr->getExprLoc(), |
| 5031 | diag::err_omp_wrong_ordered_loop_count) |
| 5032 | << OrderedLoopCountExpr->getSourceRange(); |
| 5033 | SemaRef.Diag(CollapseLoopCountExpr->getExprLoc(), |
| 5034 | diag::note_collapse_loop_count) |
| 5035 | << CollapseLoopCountExpr->getSourceRange(); |
| 5036 | } |
| 5037 | NestedLoopCount = Result.getLimitedValue(); |
| 5038 | } |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 5039 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5040 | // This is helper routine for loop directives (e.g., 'for', 'simd', |
| 5041 | // 'for simd', etc.). |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 5042 | llvm::MapVector<Expr *, DeclRefExpr *> Captures; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5043 | SmallVector<LoopIterationSpace, 4> IterSpaces; |
| 5044 | IterSpaces.resize(NestedLoopCount); |
| 5045 | Stmt *CurStmt = AStmt->IgnoreContainers(/* IgnoreCaptured */ true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5046 | for (unsigned Cnt = 0; Cnt < NestedLoopCount; ++Cnt) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 5047 | if (CheckOpenMPIterationSpace(DKind, CurStmt, SemaRef, DSA, Cnt, |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5048 | NestedLoopCount, CollapseLoopCountExpr, |
| 5049 | OrderedLoopCountExpr, VarsWithImplicitDSA, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 5050 | IterSpaces[Cnt], Captures)) |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 5051 | return 0; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5052 | // 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] | 5053 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 5054 | // All loops associated with the construct must be perfectly nested; that |
| 5055 | // is, there must be no intervening code nor any OpenMP directive between |
| 5056 | // any two loops. |
| 5057 | CurStmt = cast<ForStmt>(CurStmt)->getBody()->IgnoreContainers(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5058 | } |
| 5059 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5060 | Built.clear(/* size */ NestedLoopCount); |
| 5061 | |
| 5062 | if (SemaRef.CurContext->isDependentContext()) |
| 5063 | return NestedLoopCount; |
| 5064 | |
| 5065 | // An example of what is generated for the following code: |
| 5066 | // |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5067 | // #pragma omp simd collapse(2) ordered(2) |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5068 | // for (i = 0; i < NI; ++i) |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5069 | // for (k = 0; k < NK; ++k) |
| 5070 | // for (j = J0; j < NJ; j+=2) { |
| 5071 | // <loop body> |
| 5072 | // } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5073 | // |
| 5074 | // We generate the code below. |
| 5075 | // Note: the loop body may be outlined in CodeGen. |
| 5076 | // Note: some counters may be C++ classes, operator- is used to find number of |
| 5077 | // iterations and operator+= to calculate counter value. |
| 5078 | // Note: decltype(NumIterations) must be integer type (in 'omp for', only i32 |
| 5079 | // or i64 is currently supported). |
| 5080 | // |
| 5081 | // #define NumIterations (NI * ((NJ - J0 - 1 + 2) / 2)) |
| 5082 | // for (int[32|64]_t IV = 0; IV < NumIterations; ++IV ) { |
| 5083 | // .local.i = IV / ((NJ - J0 - 1 + 2) / 2); |
| 5084 | // .local.j = J0 + (IV % ((NJ - J0 - 1 + 2) / 2)) * 2; |
| 5085 | // // similar updates for vars in clauses (e.g. 'linear') |
| 5086 | // <loop body (using local i and j)> |
| 5087 | // } |
| 5088 | // i = NI; // assign final values of counters |
| 5089 | // j = NJ; |
| 5090 | // |
| 5091 | |
| 5092 | // Last iteration number is (I1 * I2 * ... In) - 1, where I1, I2 ... In are |
| 5093 | // the iteration counts of the collapsed for loops. |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 5094 | // Precondition tests if there is at least one iteration (all conditions are |
| 5095 | // true). |
| 5096 | auto PreCond = ExprResult(IterSpaces[0].PreCond); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5097 | auto N0 = IterSpaces[0].NumIterations; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 5098 | ExprResult LastIteration32 = WidenIterationCount( |
| 5099 | 32 /* Bits */, SemaRef.PerformImplicitConversion( |
| 5100 | N0->IgnoreImpCasts(), N0->getType(), |
| 5101 | Sema::AA_Converting, /*AllowExplicit=*/true) |
| 5102 | .get(), |
| 5103 | SemaRef); |
| 5104 | ExprResult LastIteration64 = WidenIterationCount( |
| 5105 | 64 /* Bits */, SemaRef.PerformImplicitConversion( |
| 5106 | N0->IgnoreImpCasts(), N0->getType(), |
| 5107 | Sema::AA_Converting, /*AllowExplicit=*/true) |
| 5108 | .get(), |
| 5109 | SemaRef); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5110 | |
| 5111 | if (!LastIteration32.isUsable() || !LastIteration64.isUsable()) |
| 5112 | return NestedLoopCount; |
| 5113 | |
| 5114 | auto &C = SemaRef.Context; |
| 5115 | bool AllCountsNeedLessThan32Bits = C.getTypeSize(N0->getType()) < 32; |
| 5116 | |
| 5117 | Scope *CurScope = DSA.getCurScope(); |
| 5118 | for (unsigned Cnt = 1; Cnt < NestedLoopCount; ++Cnt) { |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 5119 | if (PreCond.isUsable()) { |
| 5120 | PreCond = SemaRef.BuildBinOp(CurScope, SourceLocation(), BO_LAnd, |
| 5121 | PreCond.get(), IterSpaces[Cnt].PreCond); |
| 5122 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5123 | auto N = IterSpaces[Cnt].NumIterations; |
| 5124 | AllCountsNeedLessThan32Bits &= C.getTypeSize(N->getType()) < 32; |
| 5125 | if (LastIteration32.isUsable()) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 5126 | LastIteration32 = SemaRef.BuildBinOp( |
| 5127 | CurScope, SourceLocation(), BO_Mul, LastIteration32.get(), |
| 5128 | SemaRef.PerformImplicitConversion(N->IgnoreImpCasts(), N->getType(), |
| 5129 | Sema::AA_Converting, |
| 5130 | /*AllowExplicit=*/true) |
| 5131 | .get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5132 | if (LastIteration64.isUsable()) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 5133 | LastIteration64 = SemaRef.BuildBinOp( |
| 5134 | CurScope, SourceLocation(), BO_Mul, LastIteration64.get(), |
| 5135 | SemaRef.PerformImplicitConversion(N->IgnoreImpCasts(), N->getType(), |
| 5136 | Sema::AA_Converting, |
| 5137 | /*AllowExplicit=*/true) |
| 5138 | .get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5139 | } |
| 5140 | |
| 5141 | // Choose either the 32-bit or 64-bit version. |
| 5142 | ExprResult LastIteration = LastIteration64; |
| 5143 | if (LastIteration32.isUsable() && |
| 5144 | C.getTypeSize(LastIteration32.get()->getType()) == 32 && |
| 5145 | (AllCountsNeedLessThan32Bits || NestedLoopCount == 1 || |
| 5146 | FitsInto( |
| 5147 | 32 /* Bits */, |
| 5148 | LastIteration32.get()->getType()->hasSignedIntegerRepresentation(), |
| 5149 | LastIteration64.get(), SemaRef))) |
| 5150 | LastIteration = LastIteration32; |
Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 5151 | QualType VType = LastIteration.get()->getType(); |
| 5152 | QualType RealVType = VType; |
| 5153 | QualType StrideVType = VType; |
| 5154 | if (isOpenMPTaskLoopDirective(DKind)) { |
| 5155 | VType = |
| 5156 | SemaRef.Context.getIntTypeForBitwidth(/*DestWidth=*/64, /*Signed=*/0); |
| 5157 | StrideVType = |
| 5158 | SemaRef.Context.getIntTypeForBitwidth(/*DestWidth=*/64, /*Signed=*/1); |
| 5159 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5160 | |
| 5161 | if (!LastIteration.isUsable()) |
| 5162 | return 0; |
| 5163 | |
| 5164 | // Save the number of iterations. |
| 5165 | ExprResult NumIterations = LastIteration; |
| 5166 | { |
| 5167 | LastIteration = SemaRef.BuildBinOp( |
| 5168 | CurScope, SourceLocation(), BO_Sub, LastIteration.get(), |
| 5169 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 5170 | if (!LastIteration.isUsable()) |
| 5171 | return 0; |
| 5172 | } |
| 5173 | |
| 5174 | // Calculate the last iteration number beforehand instead of doing this on |
| 5175 | // each iteration. Do not do this if the number of iterations may be kfold-ed. |
| 5176 | llvm::APSInt Result; |
| 5177 | bool IsConstant = |
| 5178 | LastIteration.get()->isIntegerConstantExpr(Result, SemaRef.Context); |
| 5179 | ExprResult CalcLastIteration; |
| 5180 | if (!IsConstant) { |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 5181 | ExprResult SaveRef = |
| 5182 | tryBuildCapture(SemaRef, LastIteration.get(), Captures); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5183 | LastIteration = SaveRef; |
| 5184 | |
| 5185 | // Prepare SaveRef + 1. |
| 5186 | NumIterations = SemaRef.BuildBinOp( |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 5187 | CurScope, SourceLocation(), BO_Add, SaveRef.get(), |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5188 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 5189 | if (!NumIterations.isUsable()) |
| 5190 | return 0; |
| 5191 | } |
| 5192 | |
| 5193 | SourceLocation InitLoc = IterSpaces[0].InitSrcRange.getBegin(); |
| 5194 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5195 | // Build variables passed into runtime, nesessary for worksharing directives. |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 5196 | ExprResult LB, UB, IL, ST, EUB, PrevLB, PrevUB; |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 5197 | if (isOpenMPWorksharingDirective(DKind) || isOpenMPTaskLoopDirective(DKind) || |
| 5198 | isOpenMPDistributeDirective(DKind)) { |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5199 | // Lower bound variable, initialized with zero. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 5200 | VarDecl *LBDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.lb"); |
| 5201 | LB = buildDeclRefExpr(SemaRef, LBDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5202 | SemaRef.AddInitializerToDecl( |
| 5203 | LBDecl, SemaRef.ActOnIntegerConstant(InitLoc, 0).get(), |
| 5204 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 5205 | |
| 5206 | // Upper bound variable, initialized with last iteration number. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 5207 | VarDecl *UBDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.ub"); |
| 5208 | UB = buildDeclRefExpr(SemaRef, UBDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5209 | SemaRef.AddInitializerToDecl(UBDecl, LastIteration.get(), |
| 5210 | /*DirectInit*/ false, |
| 5211 | /*TypeMayContainAuto*/ false); |
| 5212 | |
| 5213 | // A 32-bit variable-flag where runtime returns 1 for the last iteration. |
| 5214 | // This will be used to implement clause 'lastprivate'. |
| 5215 | QualType Int32Ty = SemaRef.Context.getIntTypeForBitwidth(32, true); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 5216 | VarDecl *ILDecl = buildVarDecl(SemaRef, InitLoc, Int32Ty, ".omp.is_last"); |
| 5217 | IL = buildDeclRefExpr(SemaRef, ILDecl, Int32Ty, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5218 | SemaRef.AddInitializerToDecl( |
| 5219 | ILDecl, SemaRef.ActOnIntegerConstant(InitLoc, 0).get(), |
| 5220 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 5221 | |
| 5222 | // Stride variable returned by runtime (we initialize it to 1 by default). |
Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 5223 | VarDecl *STDecl = |
| 5224 | buildVarDecl(SemaRef, InitLoc, StrideVType, ".omp.stride"); |
| 5225 | ST = buildDeclRefExpr(SemaRef, STDecl, StrideVType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5226 | SemaRef.AddInitializerToDecl( |
| 5227 | STDecl, SemaRef.ActOnIntegerConstant(InitLoc, 1).get(), |
| 5228 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 5229 | |
| 5230 | // Build expression: UB = min(UB, LastIteration) |
| 5231 | // It is nesessary for CodeGen of directives with static scheduling. |
| 5232 | ExprResult IsUBGreater = SemaRef.BuildBinOp(CurScope, InitLoc, BO_GT, |
| 5233 | UB.get(), LastIteration.get()); |
| 5234 | ExprResult CondOp = SemaRef.ActOnConditionalOp( |
| 5235 | InitLoc, InitLoc, IsUBGreater.get(), LastIteration.get(), UB.get()); |
| 5236 | EUB = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, UB.get(), |
| 5237 | CondOp.get()); |
| 5238 | EUB = SemaRef.ActOnFinishFullExpr(EUB.get()); |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 5239 | |
| 5240 | // If we have a combined directive that combines 'distribute', 'for' or |
| 5241 | // 'simd' we need to be able to access the bounds of the schedule of the |
| 5242 | // enclosing region. E.g. in 'distribute parallel for' the bounds obtained |
| 5243 | // by scheduling 'distribute' have to be passed to the schedule of 'for'. |
| 5244 | if (isOpenMPLoopBoundSharingDirective(DKind)) { |
| 5245 | auto *CD = cast<CapturedStmt>(AStmt)->getCapturedDecl(); |
| 5246 | |
| 5247 | // We expect to have at least 2 more parameters than the 'parallel' |
| 5248 | // directive does - the lower and upper bounds of the previous schedule. |
| 5249 | assert(CD->getNumParams() >= 4 && |
| 5250 | "Unexpected number of parameters in loop combined directive"); |
| 5251 | |
| 5252 | // Set the proper type for the bounds given what we learned from the |
| 5253 | // enclosed loops. |
| 5254 | auto *PrevLBDecl = CD->getParam(/*PrevLB=*/2); |
| 5255 | auto *PrevUBDecl = CD->getParam(/*PrevUB=*/3); |
| 5256 | |
| 5257 | // Previous lower and upper bounds are obtained from the region |
| 5258 | // parameters. |
| 5259 | PrevLB = |
| 5260 | buildDeclRefExpr(SemaRef, PrevLBDecl, PrevLBDecl->getType(), InitLoc); |
| 5261 | PrevUB = |
| 5262 | buildDeclRefExpr(SemaRef, PrevUBDecl, PrevUBDecl->getType(), InitLoc); |
| 5263 | } |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5264 | } |
| 5265 | |
| 5266 | // Build the iteration variable and its initialization before loop. |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5267 | ExprResult IV; |
| 5268 | ExprResult Init; |
| 5269 | { |
Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 5270 | VarDecl *IVDecl = buildVarDecl(SemaRef, InitLoc, RealVType, ".omp.iv"); |
| 5271 | IV = buildDeclRefExpr(SemaRef, IVDecl, RealVType, InitLoc); |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 5272 | Expr *RHS = (isOpenMPWorksharingDirective(DKind) || |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 5273 | isOpenMPTaskLoopDirective(DKind) || |
| 5274 | isOpenMPDistributeDirective(DKind)) |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5275 | ? LB.get() |
| 5276 | : SemaRef.ActOnIntegerConstant(SourceLocation(), 0).get(); |
| 5277 | Init = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, IV.get(), RHS); |
| 5278 | Init = SemaRef.ActOnFinishFullExpr(Init.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5279 | } |
| 5280 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5281 | // Loop condition (IV < NumIterations) or (IV <= UB) for worksharing loops. |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5282 | SourceLocation CondLoc; |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5283 | ExprResult Cond = |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 5284 | (isOpenMPWorksharingDirective(DKind) || |
| 5285 | isOpenMPTaskLoopDirective(DKind) || isOpenMPDistributeDirective(DKind)) |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5286 | ? SemaRef.BuildBinOp(CurScope, CondLoc, BO_LE, IV.get(), UB.get()) |
| 5287 | : SemaRef.BuildBinOp(CurScope, CondLoc, BO_LT, IV.get(), |
| 5288 | NumIterations.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5289 | |
| 5290 | // Loop increment (IV = IV + 1) |
| 5291 | SourceLocation IncLoc; |
| 5292 | ExprResult Inc = |
| 5293 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, IV.get(), |
| 5294 | SemaRef.ActOnIntegerConstant(IncLoc, 1).get()); |
| 5295 | if (!Inc.isUsable()) |
| 5296 | return 0; |
| 5297 | Inc = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, IV.get(), Inc.get()); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5298 | Inc = SemaRef.ActOnFinishFullExpr(Inc.get()); |
| 5299 | if (!Inc.isUsable()) |
| 5300 | return 0; |
| 5301 | |
| 5302 | // Increments for worksharing loops (LB = LB + ST; UB = UB + ST). |
| 5303 | // Used for directives with static scheduling. |
| 5304 | ExprResult NextLB, NextUB; |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 5305 | if (isOpenMPWorksharingDirective(DKind) || isOpenMPTaskLoopDirective(DKind) || |
| 5306 | isOpenMPDistributeDirective(DKind)) { |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5307 | // LB + ST |
| 5308 | NextLB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, LB.get(), ST.get()); |
| 5309 | if (!NextLB.isUsable()) |
| 5310 | return 0; |
| 5311 | // LB = LB + ST |
| 5312 | NextLB = |
| 5313 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, LB.get(), NextLB.get()); |
| 5314 | NextLB = SemaRef.ActOnFinishFullExpr(NextLB.get()); |
| 5315 | if (!NextLB.isUsable()) |
| 5316 | return 0; |
| 5317 | // UB + ST |
| 5318 | NextUB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, UB.get(), ST.get()); |
| 5319 | if (!NextUB.isUsable()) |
| 5320 | return 0; |
| 5321 | // UB = UB + ST |
| 5322 | NextUB = |
| 5323 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, UB.get(), NextUB.get()); |
| 5324 | NextUB = SemaRef.ActOnFinishFullExpr(NextUB.get()); |
| 5325 | if (!NextUB.isUsable()) |
| 5326 | return 0; |
| 5327 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5328 | |
| 5329 | // Build updates and final values of the loop counters. |
| 5330 | bool HasErrors = false; |
| 5331 | Built.Counters.resize(NestedLoopCount); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 5332 | Built.Inits.resize(NestedLoopCount); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5333 | Built.Updates.resize(NestedLoopCount); |
| 5334 | Built.Finals.resize(NestedLoopCount); |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 5335 | SmallVector<Expr *, 4> LoopMultipliers; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5336 | { |
| 5337 | ExprResult Div; |
| 5338 | // Go from inner nested loop to outer. |
| 5339 | for (int Cnt = NestedLoopCount - 1; Cnt >= 0; --Cnt) { |
| 5340 | LoopIterationSpace &IS = IterSpaces[Cnt]; |
| 5341 | SourceLocation UpdLoc = IS.IncSrcRange.getBegin(); |
| 5342 | // Build: Iter = (IV / Div) % IS.NumIters |
| 5343 | // where Div is product of previous iterations' IS.NumIters. |
| 5344 | ExprResult Iter; |
| 5345 | if (Div.isUsable()) { |
| 5346 | Iter = |
| 5347 | SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Div, IV.get(), Div.get()); |
| 5348 | } else { |
| 5349 | Iter = IV; |
| 5350 | assert((Cnt == (int)NestedLoopCount - 1) && |
| 5351 | "unusable div expected on first iteration only"); |
| 5352 | } |
| 5353 | |
| 5354 | if (Cnt != 0 && Iter.isUsable()) |
| 5355 | Iter = SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Rem, Iter.get(), |
| 5356 | IS.NumIterations); |
| 5357 | if (!Iter.isUsable()) { |
| 5358 | HasErrors = true; |
| 5359 | break; |
| 5360 | } |
| 5361 | |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 5362 | // Build update: IS.CounterVar(Private) = IS.Start + Iter * IS.Step |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 5363 | auto *VD = cast<VarDecl>(cast<DeclRefExpr>(IS.CounterVar)->getDecl()); |
| 5364 | auto *CounterVar = buildDeclRefExpr(SemaRef, VD, IS.CounterVar->getType(), |
| 5365 | IS.CounterVar->getExprLoc(), |
| 5366 | /*RefersToCapture=*/true); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 5367 | ExprResult Init = BuildCounterInit(SemaRef, CurScope, UpdLoc, CounterVar, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 5368 | IS.CounterInit, Captures); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 5369 | if (!Init.isUsable()) { |
| 5370 | HasErrors = true; |
| 5371 | break; |
| 5372 | } |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 5373 | ExprResult Update = BuildCounterUpdate( |
| 5374 | SemaRef, CurScope, UpdLoc, CounterVar, IS.CounterInit, Iter, |
| 5375 | IS.CounterStep, IS.Subtract, &Captures); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5376 | if (!Update.isUsable()) { |
| 5377 | HasErrors = true; |
| 5378 | break; |
| 5379 | } |
| 5380 | |
| 5381 | // Build final: IS.CounterVar = IS.Start + IS.NumIters * IS.Step |
| 5382 | ExprResult Final = BuildCounterUpdate( |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 5383 | SemaRef, CurScope, UpdLoc, CounterVar, IS.CounterInit, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 5384 | IS.NumIterations, IS.CounterStep, IS.Subtract, &Captures); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5385 | if (!Final.isUsable()) { |
| 5386 | HasErrors = true; |
| 5387 | break; |
| 5388 | } |
| 5389 | |
| 5390 | // Build Div for the next iteration: Div <- Div * IS.NumIters |
| 5391 | if (Cnt != 0) { |
| 5392 | if (Div.isUnset()) |
| 5393 | Div = IS.NumIterations; |
| 5394 | else |
| 5395 | Div = SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Mul, Div.get(), |
| 5396 | IS.NumIterations); |
| 5397 | |
| 5398 | // Add parentheses (for debugging purposes only). |
| 5399 | if (Div.isUsable()) |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 5400 | Div = tryBuildCapture(SemaRef, Div.get(), Captures); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5401 | if (!Div.isUsable()) { |
| 5402 | HasErrors = true; |
| 5403 | break; |
| 5404 | } |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 5405 | LoopMultipliers.push_back(Div.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5406 | } |
| 5407 | if (!Update.isUsable() || !Final.isUsable()) { |
| 5408 | HasErrors = true; |
| 5409 | break; |
| 5410 | } |
| 5411 | // Save results |
| 5412 | Built.Counters[Cnt] = IS.CounterVar; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 5413 | Built.PrivateCounters[Cnt] = IS.PrivateCounterVar; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 5414 | Built.Inits[Cnt] = Init.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5415 | Built.Updates[Cnt] = Update.get(); |
| 5416 | Built.Finals[Cnt] = Final.get(); |
| 5417 | } |
| 5418 | } |
| 5419 | |
| 5420 | if (HasErrors) |
| 5421 | return 0; |
| 5422 | |
| 5423 | // Save results |
| 5424 | Built.IterationVarRef = IV.get(); |
| 5425 | Built.LastIteration = LastIteration.get(); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 5426 | Built.NumIterations = NumIterations.get(); |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 5427 | Built.CalcLastIteration = |
| 5428 | SemaRef.ActOnFinishFullExpr(CalcLastIteration.get()).get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5429 | Built.PreCond = PreCond.get(); |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 5430 | Built.PreInits = buildPreInits(C, Captures); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5431 | Built.Cond = Cond.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5432 | Built.Init = Init.get(); |
| 5433 | Built.Inc = Inc.get(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5434 | Built.LB = LB.get(); |
| 5435 | Built.UB = UB.get(); |
| 5436 | Built.IL = IL.get(); |
| 5437 | Built.ST = ST.get(); |
| 5438 | Built.EUB = EUB.get(); |
| 5439 | Built.NLB = NextLB.get(); |
| 5440 | Built.NUB = NextUB.get(); |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 5441 | Built.PrevLB = PrevLB.get(); |
| 5442 | Built.PrevUB = PrevUB.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5443 | |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 5444 | Expr *CounterVal = SemaRef.DefaultLvalueConversion(IV.get()).get(); |
| 5445 | // Fill data for doacross depend clauses. |
| 5446 | for (auto Pair : DSA.getDoacrossDependClauses()) { |
| 5447 | if (Pair.first->getDependencyKind() == OMPC_DEPEND_source) |
| 5448 | Pair.first->setCounterValue(CounterVal); |
| 5449 | else { |
| 5450 | if (NestedLoopCount != Pair.second.size() || |
| 5451 | NestedLoopCount != LoopMultipliers.size() + 1) { |
| 5452 | // Erroneous case - clause has some problems. |
| 5453 | Pair.first->setCounterValue(CounterVal); |
| 5454 | continue; |
| 5455 | } |
| 5456 | assert(Pair.first->getDependencyKind() == OMPC_DEPEND_sink); |
| 5457 | auto I = Pair.second.rbegin(); |
| 5458 | auto IS = IterSpaces.rbegin(); |
| 5459 | auto ILM = LoopMultipliers.rbegin(); |
| 5460 | Expr *UpCounterVal = CounterVal; |
| 5461 | Expr *Multiplier = nullptr; |
| 5462 | for (int Cnt = NestedLoopCount - 1; Cnt >= 0; --Cnt) { |
| 5463 | if (I->first) { |
| 5464 | assert(IS->CounterStep); |
| 5465 | Expr *NormalizedOffset = |
| 5466 | SemaRef |
| 5467 | .BuildBinOp(CurScope, I->first->getExprLoc(), BO_Div, |
| 5468 | I->first, IS->CounterStep) |
| 5469 | .get(); |
| 5470 | if (Multiplier) { |
| 5471 | NormalizedOffset = |
| 5472 | SemaRef |
| 5473 | .BuildBinOp(CurScope, I->first->getExprLoc(), BO_Mul, |
| 5474 | NormalizedOffset, Multiplier) |
| 5475 | .get(); |
| 5476 | } |
| 5477 | assert(I->second == OO_Plus || I->second == OO_Minus); |
| 5478 | BinaryOperatorKind BOK = (I->second == OO_Plus) ? BO_Add : BO_Sub; |
| 5479 | UpCounterVal = |
| 5480 | SemaRef.BuildBinOp(CurScope, I->first->getExprLoc(), BOK, |
| 5481 | UpCounterVal, NormalizedOffset).get(); |
| 5482 | } |
| 5483 | Multiplier = *ILM; |
| 5484 | ++I; |
| 5485 | ++IS; |
| 5486 | ++ILM; |
| 5487 | } |
| 5488 | Pair.first->setCounterValue(UpCounterVal); |
| 5489 | } |
| 5490 | } |
| 5491 | |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 5492 | return NestedLoopCount; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5493 | } |
| 5494 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5495 | static Expr *getCollapseNumberExpr(ArrayRef<OMPClause *> Clauses) { |
Benjamin Kramer | fc600dc | 2015-08-30 15:12:28 +0000 | [diff] [blame] | 5496 | auto CollapseClauses = |
| 5497 | OMPExecutableDirective::getClausesOfKind<OMPCollapseClause>(Clauses); |
| 5498 | if (CollapseClauses.begin() != CollapseClauses.end()) |
| 5499 | return (*CollapseClauses.begin())->getNumForLoops(); |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 5500 | return nullptr; |
| 5501 | } |
| 5502 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5503 | static Expr *getOrderedNumberExpr(ArrayRef<OMPClause *> Clauses) { |
Benjamin Kramer | fc600dc | 2015-08-30 15:12:28 +0000 | [diff] [blame] | 5504 | auto OrderedClauses = |
| 5505 | OMPExecutableDirective::getClausesOfKind<OMPOrderedClause>(Clauses); |
| 5506 | if (OrderedClauses.begin() != OrderedClauses.end()) |
| 5507 | return (*OrderedClauses.begin())->getNumForLoops(); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5508 | return nullptr; |
| 5509 | } |
| 5510 | |
Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 5511 | static bool checkSimdlenSafelenSpecified(Sema &S, |
| 5512 | const ArrayRef<OMPClause *> Clauses) { |
| 5513 | OMPSafelenClause *Safelen = nullptr; |
| 5514 | OMPSimdlenClause *Simdlen = nullptr; |
| 5515 | |
| 5516 | for (auto *Clause : Clauses) { |
| 5517 | if (Clause->getClauseKind() == OMPC_safelen) |
| 5518 | Safelen = cast<OMPSafelenClause>(Clause); |
| 5519 | else if (Clause->getClauseKind() == OMPC_simdlen) |
| 5520 | Simdlen = cast<OMPSimdlenClause>(Clause); |
| 5521 | if (Safelen && Simdlen) |
| 5522 | break; |
| 5523 | } |
| 5524 | |
| 5525 | if (Simdlen && Safelen) { |
| 5526 | llvm::APSInt SimdlenRes, SafelenRes; |
| 5527 | auto SimdlenLength = Simdlen->getSimdlen(); |
| 5528 | auto SafelenLength = Safelen->getSafelen(); |
| 5529 | if (SimdlenLength->isValueDependent() || SimdlenLength->isTypeDependent() || |
| 5530 | SimdlenLength->isInstantiationDependent() || |
| 5531 | SimdlenLength->containsUnexpandedParameterPack()) |
| 5532 | return false; |
| 5533 | if (SafelenLength->isValueDependent() || SafelenLength->isTypeDependent() || |
| 5534 | SafelenLength->isInstantiationDependent() || |
| 5535 | SafelenLength->containsUnexpandedParameterPack()) |
| 5536 | return false; |
| 5537 | SimdlenLength->EvaluateAsInt(SimdlenRes, S.Context); |
| 5538 | SafelenLength->EvaluateAsInt(SafelenRes, S.Context); |
| 5539 | // OpenMP 4.5 [2.8.1, simd Construct, Restrictions] |
| 5540 | // If both simdlen and safelen clauses are specified, the value of the |
| 5541 | // simdlen parameter must be less than or equal to the value of the safelen |
| 5542 | // parameter. |
| 5543 | if (SimdlenRes > SafelenRes) { |
| 5544 | S.Diag(SimdlenLength->getExprLoc(), |
| 5545 | diag::err_omp_wrong_simdlen_safelen_values) |
| 5546 | << SimdlenLength->getSourceRange() << SafelenLength->getSourceRange(); |
| 5547 | return true; |
| 5548 | } |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 5549 | } |
| 5550 | return false; |
| 5551 | } |
| 5552 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 5553 | StmtResult Sema::ActOnOpenMPSimdDirective( |
| 5554 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 5555 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 5556 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5557 | if (!AStmt) |
| 5558 | return StmtError(); |
| 5559 | |
| 5560 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5561 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5562 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 5563 | // define the nested loops number. |
| 5564 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 5565 | OMPD_simd, getCollapseNumberExpr(Clauses), getOrderedNumberExpr(Clauses), |
| 5566 | AStmt, *this, *DSAStack, VarsWithImplicitDSA, B); |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 5567 | if (NestedLoopCount == 0) |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 5568 | return StmtError(); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 5569 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5570 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 5571 | "omp simd loop exprs were not built"); |
| 5572 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 5573 | if (!CurContext->isDependentContext()) { |
| 5574 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 5575 | for (auto C : Clauses) { |
| 5576 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 5577 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 5578 | B.NumIterations, *this, CurScope, |
| 5579 | DSAStack)) |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 5580 | return StmtError(); |
| 5581 | } |
| 5582 | } |
| 5583 | |
Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 5584 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 5585 | return StmtError(); |
| 5586 | |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 5587 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5588 | return OMPSimdDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| 5589 | Clauses, AStmt, B); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 5590 | } |
| 5591 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 5592 | StmtResult Sema::ActOnOpenMPForDirective( |
| 5593 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 5594 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 5595 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5596 | if (!AStmt) |
| 5597 | return StmtError(); |
| 5598 | |
| 5599 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5600 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5601 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 5602 | // define the nested loops number. |
| 5603 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 5604 | OMPD_for, getCollapseNumberExpr(Clauses), getOrderedNumberExpr(Clauses), |
| 5605 | AStmt, *this, *DSAStack, VarsWithImplicitDSA, B); |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 5606 | if (NestedLoopCount == 0) |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 5607 | return StmtError(); |
| 5608 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5609 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 5610 | "omp for loop exprs were not built"); |
| 5611 | |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 5612 | if (!CurContext->isDependentContext()) { |
| 5613 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 5614 | for (auto C : Clauses) { |
| 5615 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 5616 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 5617 | B.NumIterations, *this, CurScope, |
| 5618 | DSAStack)) |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 5619 | return StmtError(); |
| 5620 | } |
| 5621 | } |
| 5622 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 5623 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5624 | return OMPForDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 5625 | Clauses, AStmt, B, DSAStack->isCancelRegion()); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 5626 | } |
| 5627 | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 5628 | StmtResult Sema::ActOnOpenMPForSimdDirective( |
| 5629 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 5630 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 5631 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5632 | if (!AStmt) |
| 5633 | return StmtError(); |
| 5634 | |
| 5635 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5636 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5637 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 5638 | // define the nested loops number. |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 5639 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5640 | CheckOpenMPLoop(OMPD_for_simd, getCollapseNumberExpr(Clauses), |
| 5641 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 5642 | VarsWithImplicitDSA, B); |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 5643 | if (NestedLoopCount == 0) |
| 5644 | return StmtError(); |
| 5645 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5646 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 5647 | "omp for simd loop exprs were not built"); |
| 5648 | |
Alexey Bataev | 58e5bdb | 2015-06-18 04:45:29 +0000 | [diff] [blame] | 5649 | if (!CurContext->isDependentContext()) { |
| 5650 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 5651 | for (auto C : Clauses) { |
| 5652 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 5653 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 5654 | B.NumIterations, *this, CurScope, |
| 5655 | DSAStack)) |
Alexey Bataev | 58e5bdb | 2015-06-18 04:45:29 +0000 | [diff] [blame] | 5656 | return StmtError(); |
| 5657 | } |
| 5658 | } |
| 5659 | |
Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 5660 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 5661 | return StmtError(); |
| 5662 | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 5663 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5664 | return OMPForSimdDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| 5665 | Clauses, AStmt, B); |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 5666 | } |
| 5667 | |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 5668 | StmtResult Sema::ActOnOpenMPSectionsDirective(ArrayRef<OMPClause *> Clauses, |
| 5669 | Stmt *AStmt, |
| 5670 | SourceLocation StartLoc, |
| 5671 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5672 | if (!AStmt) |
| 5673 | return StmtError(); |
| 5674 | |
| 5675 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 5676 | auto BaseStmt = AStmt; |
| 5677 | while (CapturedStmt *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt)) |
| 5678 | BaseStmt = CS->getCapturedStmt(); |
| 5679 | if (auto C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) { |
| 5680 | auto S = C->children(); |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 5681 | if (S.begin() == S.end()) |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 5682 | return StmtError(); |
| 5683 | // All associated statements must be '#pragma omp section' except for |
| 5684 | // the first one. |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 5685 | for (Stmt *SectionStmt : llvm::make_range(std::next(S.begin()), S.end())) { |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 5686 | if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) { |
| 5687 | if (SectionStmt) |
| 5688 | Diag(SectionStmt->getLocStart(), |
| 5689 | diag::err_omp_sections_substmt_not_section); |
| 5690 | return StmtError(); |
| 5691 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 5692 | cast<OMPSectionDirective>(SectionStmt) |
| 5693 | ->setHasCancel(DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 5694 | } |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 5695 | } else { |
| 5696 | Diag(AStmt->getLocStart(), diag::err_omp_sections_not_compound_stmt); |
| 5697 | return StmtError(); |
| 5698 | } |
| 5699 | |
| 5700 | getCurFunction()->setHasBranchProtectedScope(); |
| 5701 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 5702 | return OMPSectionsDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 5703 | DSAStack->isCancelRegion()); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 5704 | } |
| 5705 | |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 5706 | StmtResult Sema::ActOnOpenMPSectionDirective(Stmt *AStmt, |
| 5707 | SourceLocation StartLoc, |
| 5708 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5709 | if (!AStmt) |
| 5710 | return StmtError(); |
| 5711 | |
| 5712 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 5713 | |
| 5714 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 5715 | DSAStack->setParentCancelRegion(DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 5716 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 5717 | return OMPSectionDirective::Create(Context, StartLoc, EndLoc, AStmt, |
| 5718 | DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 5719 | } |
| 5720 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 5721 | StmtResult Sema::ActOnOpenMPSingleDirective(ArrayRef<OMPClause *> Clauses, |
| 5722 | Stmt *AStmt, |
| 5723 | SourceLocation StartLoc, |
| 5724 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5725 | if (!AStmt) |
| 5726 | return StmtError(); |
| 5727 | |
| 5728 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 74a05c9 | 2014-07-15 02:55:09 +0000 | [diff] [blame] | 5729 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 5730 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | 74a05c9 | 2014-07-15 02:55:09 +0000 | [diff] [blame] | 5731 | |
Alexey Bataev | 3255bf3 | 2015-01-19 05:20:46 +0000 | [diff] [blame] | 5732 | // OpenMP [2.7.3, single Construct, Restrictions] |
| 5733 | // The copyprivate clause must not be used with the nowait clause. |
| 5734 | OMPClause *Nowait = nullptr; |
| 5735 | OMPClause *Copyprivate = nullptr; |
| 5736 | for (auto *Clause : Clauses) { |
| 5737 | if (Clause->getClauseKind() == OMPC_nowait) |
| 5738 | Nowait = Clause; |
| 5739 | else if (Clause->getClauseKind() == OMPC_copyprivate) |
| 5740 | Copyprivate = Clause; |
| 5741 | if (Copyprivate && Nowait) { |
| 5742 | Diag(Copyprivate->getLocStart(), |
| 5743 | diag::err_omp_single_copyprivate_with_nowait); |
| 5744 | Diag(Nowait->getLocStart(), diag::note_omp_nowait_clause_here); |
| 5745 | return StmtError(); |
| 5746 | } |
| 5747 | } |
| 5748 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 5749 | return OMPSingleDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 5750 | } |
| 5751 | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 5752 | StmtResult Sema::ActOnOpenMPMasterDirective(Stmt *AStmt, |
| 5753 | SourceLocation StartLoc, |
| 5754 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5755 | if (!AStmt) |
| 5756 | return StmtError(); |
| 5757 | |
| 5758 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 5759 | |
| 5760 | getCurFunction()->setHasBranchProtectedScope(); |
| 5761 | |
| 5762 | return OMPMasterDirective::Create(Context, StartLoc, EndLoc, AStmt); |
| 5763 | } |
| 5764 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 5765 | StmtResult Sema::ActOnOpenMPCriticalDirective( |
| 5766 | const DeclarationNameInfo &DirName, ArrayRef<OMPClause *> Clauses, |
| 5767 | Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5768 | if (!AStmt) |
| 5769 | return StmtError(); |
| 5770 | |
| 5771 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 5772 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 5773 | bool ErrorFound = false; |
| 5774 | llvm::APSInt Hint; |
| 5775 | SourceLocation HintLoc; |
| 5776 | bool DependentHint = false; |
| 5777 | for (auto *C : Clauses) { |
| 5778 | if (C->getClauseKind() == OMPC_hint) { |
| 5779 | if (!DirName.getName()) { |
| 5780 | Diag(C->getLocStart(), diag::err_omp_hint_clause_no_name); |
| 5781 | ErrorFound = true; |
| 5782 | } |
| 5783 | Expr *E = cast<OMPHintClause>(C)->getHint(); |
| 5784 | if (E->isTypeDependent() || E->isValueDependent() || |
| 5785 | E->isInstantiationDependent()) |
| 5786 | DependentHint = true; |
| 5787 | else { |
| 5788 | Hint = E->EvaluateKnownConstInt(Context); |
| 5789 | HintLoc = C->getLocStart(); |
| 5790 | } |
| 5791 | } |
| 5792 | } |
| 5793 | if (ErrorFound) |
| 5794 | return StmtError(); |
| 5795 | auto Pair = DSAStack->getCriticalWithHint(DirName); |
| 5796 | if (Pair.first && DirName.getName() && !DependentHint) { |
| 5797 | if (llvm::APSInt::compareValues(Hint, Pair.second) != 0) { |
| 5798 | Diag(StartLoc, diag::err_omp_critical_with_hint); |
| 5799 | if (HintLoc.isValid()) { |
| 5800 | Diag(HintLoc, diag::note_omp_critical_hint_here) |
| 5801 | << 0 << Hint.toString(/*Radix=*/10, /*Signed=*/false); |
| 5802 | } else |
| 5803 | Diag(StartLoc, diag::note_omp_critical_no_hint) << 0; |
| 5804 | if (auto *C = Pair.first->getSingleClause<OMPHintClause>()) { |
| 5805 | Diag(C->getLocStart(), diag::note_omp_critical_hint_here) |
| 5806 | << 1 |
| 5807 | << C->getHint()->EvaluateKnownConstInt(Context).toString( |
| 5808 | /*Radix=*/10, /*Signed=*/false); |
| 5809 | } else |
| 5810 | Diag(Pair.first->getLocStart(), diag::note_omp_critical_no_hint) << 1; |
| 5811 | } |
| 5812 | } |
| 5813 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 5814 | getCurFunction()->setHasBranchProtectedScope(); |
| 5815 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 5816 | auto *Dir = OMPCriticalDirective::Create(Context, DirName, StartLoc, EndLoc, |
| 5817 | Clauses, AStmt); |
| 5818 | if (!Pair.first && DirName.getName() && !DependentHint) |
| 5819 | DSAStack->addCriticalWithHint(Dir, Hint); |
| 5820 | return Dir; |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 5821 | } |
| 5822 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 5823 | StmtResult Sema::ActOnOpenMPParallelForDirective( |
| 5824 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 5825 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 5826 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5827 | if (!AStmt) |
| 5828 | return StmtError(); |
| 5829 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 5830 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 5831 | // 1.2.2 OpenMP Language Terminology |
| 5832 | // Structured block - An executable statement with a single entry at the |
| 5833 | // top and a single exit at the bottom. |
| 5834 | // The point of exit cannot be a branch out of the structured block. |
| 5835 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5836 | CS->getCapturedDecl()->setNothrow(); |
| 5837 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5838 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5839 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 5840 | // define the nested loops number. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 5841 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5842 | CheckOpenMPLoop(OMPD_parallel_for, getCollapseNumberExpr(Clauses), |
| 5843 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 5844 | VarsWithImplicitDSA, B); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 5845 | if (NestedLoopCount == 0) |
| 5846 | return StmtError(); |
| 5847 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5848 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 5849 | "omp parallel for loop exprs were not built"); |
| 5850 | |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 5851 | if (!CurContext->isDependentContext()) { |
| 5852 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 5853 | for (auto C : Clauses) { |
| 5854 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 5855 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 5856 | B.NumIterations, *this, CurScope, |
| 5857 | DSAStack)) |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 5858 | return StmtError(); |
| 5859 | } |
| 5860 | } |
| 5861 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 5862 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5863 | return OMPParallelForDirective::Create(Context, StartLoc, EndLoc, |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 5864 | NestedLoopCount, Clauses, AStmt, B, |
| 5865 | DSAStack->isCancelRegion()); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 5866 | } |
| 5867 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 5868 | StmtResult Sema::ActOnOpenMPParallelForSimdDirective( |
| 5869 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 5870 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 5871 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5872 | if (!AStmt) |
| 5873 | return StmtError(); |
| 5874 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 5875 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 5876 | // 1.2.2 OpenMP Language Terminology |
| 5877 | // Structured block - An executable statement with a single entry at the |
| 5878 | // top and a single exit at the bottom. |
| 5879 | // The point of exit cannot be a branch out of the structured block. |
| 5880 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5881 | CS->getCapturedDecl()->setNothrow(); |
| 5882 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5883 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5884 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 5885 | // define the nested loops number. |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 5886 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5887 | CheckOpenMPLoop(OMPD_parallel_for_simd, getCollapseNumberExpr(Clauses), |
| 5888 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 5889 | VarsWithImplicitDSA, B); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 5890 | if (NestedLoopCount == 0) |
| 5891 | return StmtError(); |
| 5892 | |
Alexey Bataev | 3b5b5c4 | 2015-06-18 10:10:12 +0000 | [diff] [blame] | 5893 | if (!CurContext->isDependentContext()) { |
| 5894 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 5895 | for (auto C : Clauses) { |
| 5896 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 5897 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 5898 | B.NumIterations, *this, CurScope, |
| 5899 | DSAStack)) |
Alexey Bataev | 3b5b5c4 | 2015-06-18 10:10:12 +0000 | [diff] [blame] | 5900 | return StmtError(); |
| 5901 | } |
| 5902 | } |
| 5903 | |
Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 5904 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 5905 | return StmtError(); |
| 5906 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 5907 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5908 | return OMPParallelForSimdDirective::Create( |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5909 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 5910 | } |
| 5911 | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 5912 | StmtResult |
| 5913 | Sema::ActOnOpenMPParallelSectionsDirective(ArrayRef<OMPClause *> Clauses, |
| 5914 | Stmt *AStmt, SourceLocation StartLoc, |
| 5915 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5916 | if (!AStmt) |
| 5917 | return StmtError(); |
| 5918 | |
| 5919 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 5920 | auto BaseStmt = AStmt; |
| 5921 | while (CapturedStmt *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt)) |
| 5922 | BaseStmt = CS->getCapturedStmt(); |
| 5923 | if (auto C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) { |
| 5924 | auto S = C->children(); |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 5925 | if (S.begin() == S.end()) |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 5926 | return StmtError(); |
| 5927 | // All associated statements must be '#pragma omp section' except for |
| 5928 | // the first one. |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 5929 | for (Stmt *SectionStmt : llvm::make_range(std::next(S.begin()), S.end())) { |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 5930 | if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) { |
| 5931 | if (SectionStmt) |
| 5932 | Diag(SectionStmt->getLocStart(), |
| 5933 | diag::err_omp_parallel_sections_substmt_not_section); |
| 5934 | return StmtError(); |
| 5935 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 5936 | cast<OMPSectionDirective>(SectionStmt) |
| 5937 | ->setHasCancel(DSAStack->isCancelRegion()); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 5938 | } |
| 5939 | } else { |
| 5940 | Diag(AStmt->getLocStart(), |
| 5941 | diag::err_omp_parallel_sections_not_compound_stmt); |
| 5942 | return StmtError(); |
| 5943 | } |
| 5944 | |
| 5945 | getCurFunction()->setHasBranchProtectedScope(); |
| 5946 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 5947 | return OMPParallelSectionsDirective::Create( |
| 5948 | Context, StartLoc, EndLoc, Clauses, AStmt, DSAStack->isCancelRegion()); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 5949 | } |
| 5950 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5951 | StmtResult Sema::ActOnOpenMPTaskDirective(ArrayRef<OMPClause *> Clauses, |
| 5952 | Stmt *AStmt, SourceLocation StartLoc, |
| 5953 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5954 | if (!AStmt) |
| 5955 | return StmtError(); |
| 5956 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5957 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 5958 | // 1.2.2 OpenMP Language Terminology |
| 5959 | // Structured block - An executable statement with a single entry at the |
| 5960 | // top and a single exit at the bottom. |
| 5961 | // The point of exit cannot be a branch out of the structured block. |
| 5962 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5963 | CS->getCapturedDecl()->setNothrow(); |
| 5964 | |
| 5965 | getCurFunction()->setHasBranchProtectedScope(); |
| 5966 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 5967 | return OMPTaskDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 5968 | DSAStack->isCancelRegion()); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5969 | } |
| 5970 | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 5971 | StmtResult Sema::ActOnOpenMPTaskyieldDirective(SourceLocation StartLoc, |
| 5972 | SourceLocation EndLoc) { |
| 5973 | return OMPTaskyieldDirective::Create(Context, StartLoc, EndLoc); |
| 5974 | } |
| 5975 | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 5976 | StmtResult Sema::ActOnOpenMPBarrierDirective(SourceLocation StartLoc, |
| 5977 | SourceLocation EndLoc) { |
| 5978 | return OMPBarrierDirective::Create(Context, StartLoc, EndLoc); |
| 5979 | } |
| 5980 | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 5981 | StmtResult Sema::ActOnOpenMPTaskwaitDirective(SourceLocation StartLoc, |
| 5982 | SourceLocation EndLoc) { |
| 5983 | return OMPTaskwaitDirective::Create(Context, StartLoc, EndLoc); |
| 5984 | } |
| 5985 | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 5986 | StmtResult Sema::ActOnOpenMPTaskgroupDirective(Stmt *AStmt, |
| 5987 | SourceLocation StartLoc, |
| 5988 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5989 | if (!AStmt) |
| 5990 | return StmtError(); |
| 5991 | |
| 5992 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 5993 | |
| 5994 | getCurFunction()->setHasBranchProtectedScope(); |
| 5995 | |
| 5996 | return OMPTaskgroupDirective::Create(Context, StartLoc, EndLoc, AStmt); |
| 5997 | } |
| 5998 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 5999 | StmtResult Sema::ActOnOpenMPFlushDirective(ArrayRef<OMPClause *> Clauses, |
| 6000 | SourceLocation StartLoc, |
| 6001 | SourceLocation EndLoc) { |
| 6002 | assert(Clauses.size() <= 1 && "Extra clauses in flush directive"); |
| 6003 | return OMPFlushDirective::Create(Context, StartLoc, EndLoc, Clauses); |
| 6004 | } |
| 6005 | |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6006 | StmtResult Sema::ActOnOpenMPOrderedDirective(ArrayRef<OMPClause *> Clauses, |
| 6007 | Stmt *AStmt, |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 6008 | SourceLocation StartLoc, |
| 6009 | SourceLocation EndLoc) { |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 6010 | OMPClause *DependFound = nullptr; |
| 6011 | OMPClause *DependSourceClause = nullptr; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 6012 | OMPClause *DependSinkClause = nullptr; |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 6013 | bool ErrorFound = false; |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6014 | OMPThreadsClause *TC = nullptr; |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6015 | OMPSIMDClause *SC = nullptr; |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 6016 | for (auto *C : Clauses) { |
| 6017 | if (auto *DC = dyn_cast<OMPDependClause>(C)) { |
| 6018 | DependFound = C; |
| 6019 | if (DC->getDependencyKind() == OMPC_DEPEND_source) { |
| 6020 | if (DependSourceClause) { |
| 6021 | Diag(C->getLocStart(), diag::err_omp_more_one_clause) |
| 6022 | << getOpenMPDirectiveName(OMPD_ordered) |
| 6023 | << getOpenMPClauseName(OMPC_depend) << 2; |
| 6024 | ErrorFound = true; |
| 6025 | } else |
| 6026 | DependSourceClause = C; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 6027 | if (DependSinkClause) { |
| 6028 | Diag(C->getLocStart(), diag::err_omp_depend_sink_source_not_allowed) |
| 6029 | << 0; |
| 6030 | ErrorFound = true; |
| 6031 | } |
| 6032 | } else if (DC->getDependencyKind() == OMPC_DEPEND_sink) { |
| 6033 | if (DependSourceClause) { |
| 6034 | Diag(C->getLocStart(), diag::err_omp_depend_sink_source_not_allowed) |
| 6035 | << 1; |
| 6036 | ErrorFound = true; |
| 6037 | } |
| 6038 | DependSinkClause = C; |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 6039 | } |
| 6040 | } else if (C->getClauseKind() == OMPC_threads) |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6041 | TC = cast<OMPThreadsClause>(C); |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6042 | else if (C->getClauseKind() == OMPC_simd) |
| 6043 | SC = cast<OMPSIMDClause>(C); |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6044 | } |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 6045 | if (!ErrorFound && !SC && |
| 6046 | isOpenMPSimdDirective(DSAStack->getParentDirective())) { |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6047 | // OpenMP [2.8.1,simd Construct, Restrictions] |
| 6048 | // An ordered construct with the simd clause is the only OpenMP construct |
| 6049 | // that can appear in the simd region. |
| 6050 | Diag(StartLoc, diag::err_omp_prohibited_region_simd); |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 6051 | ErrorFound = true; |
| 6052 | } else if (DependFound && (TC || SC)) { |
| 6053 | Diag(DependFound->getLocStart(), diag::err_omp_depend_clause_thread_simd) |
| 6054 | << getOpenMPClauseName(TC ? TC->getClauseKind() : SC->getClauseKind()); |
| 6055 | ErrorFound = true; |
| 6056 | } else if (DependFound && !DSAStack->getParentOrderedRegionParam()) { |
| 6057 | Diag(DependFound->getLocStart(), |
| 6058 | diag::err_omp_ordered_directive_without_param); |
| 6059 | ErrorFound = true; |
| 6060 | } else if (TC || Clauses.empty()) { |
| 6061 | if (auto *Param = DSAStack->getParentOrderedRegionParam()) { |
| 6062 | SourceLocation ErrLoc = TC ? TC->getLocStart() : StartLoc; |
| 6063 | Diag(ErrLoc, diag::err_omp_ordered_directive_with_param) |
| 6064 | << (TC != nullptr); |
| 6065 | Diag(Param->getLocStart(), diag::note_omp_ordered_param); |
| 6066 | ErrorFound = true; |
| 6067 | } |
| 6068 | } |
| 6069 | if ((!AStmt && !DependFound) || ErrorFound) |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6070 | return StmtError(); |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 6071 | |
| 6072 | if (AStmt) { |
| 6073 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 6074 | |
| 6075 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6076 | } |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6077 | |
| 6078 | return OMPOrderedDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 6079 | } |
| 6080 | |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6081 | namespace { |
| 6082 | /// \brief Helper class for checking expression in 'omp atomic [update]' |
| 6083 | /// construct. |
| 6084 | class OpenMPAtomicUpdateChecker { |
| 6085 | /// \brief Error results for atomic update expressions. |
| 6086 | enum ExprAnalysisErrorCode { |
| 6087 | /// \brief A statement is not an expression statement. |
| 6088 | NotAnExpression, |
| 6089 | /// \brief Expression is not builtin binary or unary operation. |
| 6090 | NotABinaryOrUnaryExpression, |
| 6091 | /// \brief Unary operation is not post-/pre- increment/decrement operation. |
| 6092 | NotAnUnaryIncDecExpression, |
| 6093 | /// \brief An expression is not of scalar type. |
| 6094 | NotAScalarType, |
| 6095 | /// \brief A binary operation is not an assignment operation. |
| 6096 | NotAnAssignmentOp, |
| 6097 | /// \brief RHS part of the binary operation is not a binary expression. |
| 6098 | NotABinaryExpression, |
| 6099 | /// \brief RHS part is not additive/multiplicative/shift/biwise binary |
| 6100 | /// expression. |
| 6101 | NotABinaryOperator, |
| 6102 | /// \brief RHS binary operation does not have reference to the updated LHS |
| 6103 | /// part. |
| 6104 | NotAnUpdateExpression, |
| 6105 | /// \brief No errors is found. |
| 6106 | NoError |
| 6107 | }; |
| 6108 | /// \brief Reference to Sema. |
| 6109 | Sema &SemaRef; |
| 6110 | /// \brief A location for note diagnostics (when error is found). |
| 6111 | SourceLocation NoteLoc; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6112 | /// \brief 'x' lvalue part of the source atomic expression. |
| 6113 | Expr *X; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6114 | /// \brief 'expr' rvalue part of the source atomic expression. |
| 6115 | Expr *E; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6116 | /// \brief Helper expression of the form |
| 6117 | /// 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or |
| 6118 | /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'. |
| 6119 | Expr *UpdateExpr; |
| 6120 | /// \brief Is 'x' a LHS in a RHS part of full update expression. It is |
| 6121 | /// important for non-associative operations. |
| 6122 | bool IsXLHSInRHSPart; |
| 6123 | BinaryOperatorKind Op; |
| 6124 | SourceLocation OpLoc; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6125 | /// \brief true if the source expression is a postfix unary operation, false |
| 6126 | /// if it is a prefix unary operation. |
| 6127 | bool IsPostfixUpdate; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6128 | |
| 6129 | public: |
| 6130 | OpenMPAtomicUpdateChecker(Sema &SemaRef) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6131 | : SemaRef(SemaRef), X(nullptr), E(nullptr), UpdateExpr(nullptr), |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6132 | IsXLHSInRHSPart(false), Op(BO_PtrMemD), IsPostfixUpdate(false) {} |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6133 | /// \brief Check specified statement that it is suitable for 'atomic update' |
| 6134 | /// constructs and extract 'x', 'expr' and Operation from the original |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6135 | /// expression. If DiagId and NoteId == 0, then only check is performed |
| 6136 | /// without error notification. |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6137 | /// \param DiagId Diagnostic which should be emitted if error is found. |
| 6138 | /// \param NoteId Diagnostic note for the main error message. |
| 6139 | /// \return true if statement is not an update expression, false otherwise. |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6140 | bool checkStatement(Stmt *S, unsigned DiagId = 0, unsigned NoteId = 0); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6141 | /// \brief Return the 'x' lvalue part of the source atomic expression. |
| 6142 | Expr *getX() const { return X; } |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6143 | /// \brief Return the 'expr' rvalue part of the source atomic expression. |
| 6144 | Expr *getExpr() const { return E; } |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6145 | /// \brief Return the update expression used in calculation of the updated |
| 6146 | /// value. Always has form 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or |
| 6147 | /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'. |
| 6148 | Expr *getUpdateExpr() const { return UpdateExpr; } |
| 6149 | /// \brief Return true if 'x' is LHS in RHS part of full update expression, |
| 6150 | /// false otherwise. |
| 6151 | bool isXLHSInRHSPart() const { return IsXLHSInRHSPart; } |
| 6152 | |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6153 | /// \brief true if the source expression is a postfix unary operation, false |
| 6154 | /// if it is a prefix unary operation. |
| 6155 | bool isPostfixUpdate() const { return IsPostfixUpdate; } |
| 6156 | |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6157 | private: |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6158 | bool checkBinaryOperation(BinaryOperator *AtomicBinOp, unsigned DiagId = 0, |
| 6159 | unsigned NoteId = 0); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6160 | }; |
| 6161 | } // namespace |
| 6162 | |
| 6163 | bool OpenMPAtomicUpdateChecker::checkBinaryOperation( |
| 6164 | BinaryOperator *AtomicBinOp, unsigned DiagId, unsigned NoteId) { |
| 6165 | ExprAnalysisErrorCode ErrorFound = NoError; |
| 6166 | SourceLocation ErrorLoc, NoteLoc; |
| 6167 | SourceRange ErrorRange, NoteRange; |
| 6168 | // Allowed constructs are: |
| 6169 | // x = x binop expr; |
| 6170 | // x = expr binop x; |
| 6171 | if (AtomicBinOp->getOpcode() == BO_Assign) { |
| 6172 | X = AtomicBinOp->getLHS(); |
| 6173 | if (auto *AtomicInnerBinOp = dyn_cast<BinaryOperator>( |
| 6174 | AtomicBinOp->getRHS()->IgnoreParenImpCasts())) { |
| 6175 | if (AtomicInnerBinOp->isMultiplicativeOp() || |
| 6176 | AtomicInnerBinOp->isAdditiveOp() || AtomicInnerBinOp->isShiftOp() || |
| 6177 | AtomicInnerBinOp->isBitwiseOp()) { |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6178 | Op = AtomicInnerBinOp->getOpcode(); |
| 6179 | OpLoc = AtomicInnerBinOp->getOperatorLoc(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6180 | auto *LHS = AtomicInnerBinOp->getLHS(); |
| 6181 | auto *RHS = AtomicInnerBinOp->getRHS(); |
| 6182 | llvm::FoldingSetNodeID XId, LHSId, RHSId; |
| 6183 | X->IgnoreParenImpCasts()->Profile(XId, SemaRef.getASTContext(), |
| 6184 | /*Canonical=*/true); |
| 6185 | LHS->IgnoreParenImpCasts()->Profile(LHSId, SemaRef.getASTContext(), |
| 6186 | /*Canonical=*/true); |
| 6187 | RHS->IgnoreParenImpCasts()->Profile(RHSId, SemaRef.getASTContext(), |
| 6188 | /*Canonical=*/true); |
| 6189 | if (XId == LHSId) { |
| 6190 | E = RHS; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6191 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6192 | } else if (XId == RHSId) { |
| 6193 | E = LHS; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6194 | IsXLHSInRHSPart = false; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6195 | } else { |
| 6196 | ErrorLoc = AtomicInnerBinOp->getExprLoc(); |
| 6197 | ErrorRange = AtomicInnerBinOp->getSourceRange(); |
| 6198 | NoteLoc = X->getExprLoc(); |
| 6199 | NoteRange = X->getSourceRange(); |
| 6200 | ErrorFound = NotAnUpdateExpression; |
| 6201 | } |
| 6202 | } else { |
| 6203 | ErrorLoc = AtomicInnerBinOp->getExprLoc(); |
| 6204 | ErrorRange = AtomicInnerBinOp->getSourceRange(); |
| 6205 | NoteLoc = AtomicInnerBinOp->getOperatorLoc(); |
| 6206 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 6207 | ErrorFound = NotABinaryOperator; |
| 6208 | } |
| 6209 | } else { |
| 6210 | NoteLoc = ErrorLoc = AtomicBinOp->getRHS()->getExprLoc(); |
| 6211 | NoteRange = ErrorRange = AtomicBinOp->getRHS()->getSourceRange(); |
| 6212 | ErrorFound = NotABinaryExpression; |
| 6213 | } |
| 6214 | } else { |
| 6215 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 6216 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 6217 | NoteLoc = AtomicBinOp->getOperatorLoc(); |
| 6218 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 6219 | ErrorFound = NotAnAssignmentOp; |
| 6220 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6221 | if (ErrorFound != NoError && DiagId != 0 && NoteId != 0) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6222 | SemaRef.Diag(ErrorLoc, DiagId) << ErrorRange; |
| 6223 | SemaRef.Diag(NoteLoc, NoteId) << ErrorFound << NoteRange; |
| 6224 | return true; |
| 6225 | } else if (SemaRef.CurContext->isDependentContext()) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6226 | E = X = UpdateExpr = nullptr; |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 6227 | return ErrorFound != NoError; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6228 | } |
| 6229 | |
| 6230 | bool OpenMPAtomicUpdateChecker::checkStatement(Stmt *S, unsigned DiagId, |
| 6231 | unsigned NoteId) { |
| 6232 | ExprAnalysisErrorCode ErrorFound = NoError; |
| 6233 | SourceLocation ErrorLoc, NoteLoc; |
| 6234 | SourceRange ErrorRange, NoteRange; |
| 6235 | // Allowed constructs are: |
| 6236 | // x++; |
| 6237 | // x--; |
| 6238 | // ++x; |
| 6239 | // --x; |
| 6240 | // x binop= expr; |
| 6241 | // x = x binop expr; |
| 6242 | // x = expr binop x; |
| 6243 | if (auto *AtomicBody = dyn_cast<Expr>(S)) { |
| 6244 | AtomicBody = AtomicBody->IgnoreParenImpCasts(); |
| 6245 | if (AtomicBody->getType()->isScalarType() || |
| 6246 | AtomicBody->isInstantiationDependent()) { |
| 6247 | if (auto *AtomicCompAssignOp = dyn_cast<CompoundAssignOperator>( |
| 6248 | AtomicBody->IgnoreParenImpCasts())) { |
| 6249 | // Check for Compound Assignment Operation |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6250 | Op = BinaryOperator::getOpForCompoundAssignment( |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6251 | AtomicCompAssignOp->getOpcode()); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6252 | OpLoc = AtomicCompAssignOp->getOperatorLoc(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6253 | E = AtomicCompAssignOp->getRHS(); |
Kelvin Li | 4f161cf | 2016-07-20 19:41:17 +0000 | [diff] [blame] | 6254 | X = AtomicCompAssignOp->getLHS()->IgnoreParens(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6255 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6256 | } else if (auto *AtomicBinOp = dyn_cast<BinaryOperator>( |
| 6257 | AtomicBody->IgnoreParenImpCasts())) { |
| 6258 | // Check for Binary Operation |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6259 | if(checkBinaryOperation(AtomicBinOp, DiagId, NoteId)) |
| 6260 | return true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6261 | } else if (auto *AtomicUnaryOp = |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6262 | dyn_cast<UnaryOperator>(AtomicBody->IgnoreParenImpCasts())) { |
| 6263 | // Check for Unary Operation |
| 6264 | if (AtomicUnaryOp->isIncrementDecrementOp()) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6265 | IsPostfixUpdate = AtomicUnaryOp->isPostfix(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6266 | Op = AtomicUnaryOp->isIncrementOp() ? BO_Add : BO_Sub; |
| 6267 | OpLoc = AtomicUnaryOp->getOperatorLoc(); |
Kelvin Li | 4f161cf | 2016-07-20 19:41:17 +0000 | [diff] [blame] | 6268 | X = AtomicUnaryOp->getSubExpr()->IgnoreParens(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6269 | E = SemaRef.ActOnIntegerConstant(OpLoc, /*uint64_t Val=*/1).get(); |
| 6270 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6271 | } else { |
| 6272 | ErrorFound = NotAnUnaryIncDecExpression; |
| 6273 | ErrorLoc = AtomicUnaryOp->getExprLoc(); |
| 6274 | ErrorRange = AtomicUnaryOp->getSourceRange(); |
| 6275 | NoteLoc = AtomicUnaryOp->getOperatorLoc(); |
| 6276 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 6277 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 6278 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6279 | ErrorFound = NotABinaryOrUnaryExpression; |
| 6280 | NoteLoc = ErrorLoc = AtomicBody->getExprLoc(); |
| 6281 | NoteRange = ErrorRange = AtomicBody->getSourceRange(); |
| 6282 | } |
| 6283 | } else { |
| 6284 | ErrorFound = NotAScalarType; |
| 6285 | NoteLoc = ErrorLoc = AtomicBody->getLocStart(); |
| 6286 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
| 6287 | } |
| 6288 | } else { |
| 6289 | ErrorFound = NotAnExpression; |
| 6290 | NoteLoc = ErrorLoc = S->getLocStart(); |
| 6291 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
| 6292 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6293 | if (ErrorFound != NoError && DiagId != 0 && NoteId != 0) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6294 | SemaRef.Diag(ErrorLoc, DiagId) << ErrorRange; |
| 6295 | SemaRef.Diag(NoteLoc, NoteId) << ErrorFound << NoteRange; |
| 6296 | return true; |
| 6297 | } else if (SemaRef.CurContext->isDependentContext()) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6298 | E = X = UpdateExpr = nullptr; |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 6299 | if (ErrorFound == NoError && E && X) { |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6300 | // Build an update expression of form 'OpaqueValueExpr(x) binop |
| 6301 | // OpaqueValueExpr(expr)' or 'OpaqueValueExpr(expr) binop |
| 6302 | // OpaqueValueExpr(x)' and then cast it to the type of the 'x' expression. |
| 6303 | auto *OVEX = new (SemaRef.getASTContext()) |
| 6304 | OpaqueValueExpr(X->getExprLoc(), X->getType(), VK_RValue); |
| 6305 | auto *OVEExpr = new (SemaRef.getASTContext()) |
| 6306 | OpaqueValueExpr(E->getExprLoc(), E->getType(), VK_RValue); |
| 6307 | auto Update = |
| 6308 | SemaRef.CreateBuiltinBinOp(OpLoc, Op, IsXLHSInRHSPart ? OVEX : OVEExpr, |
| 6309 | IsXLHSInRHSPart ? OVEExpr : OVEX); |
| 6310 | if (Update.isInvalid()) |
| 6311 | return true; |
| 6312 | Update = SemaRef.PerformImplicitConversion(Update.get(), X->getType(), |
| 6313 | Sema::AA_Casting); |
| 6314 | if (Update.isInvalid()) |
| 6315 | return true; |
| 6316 | UpdateExpr = Update.get(); |
| 6317 | } |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 6318 | return ErrorFound != NoError; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6319 | } |
| 6320 | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 6321 | StmtResult Sema::ActOnOpenMPAtomicDirective(ArrayRef<OMPClause *> Clauses, |
| 6322 | Stmt *AStmt, |
| 6323 | SourceLocation StartLoc, |
| 6324 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6325 | if (!AStmt) |
| 6326 | return StmtError(); |
| 6327 | |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6328 | auto CS = cast<CapturedStmt>(AStmt); |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 6329 | // 1.2.2 OpenMP Language Terminology |
| 6330 | // Structured block - An executable statement with a single entry at the |
| 6331 | // top and a single exit at the bottom. |
| 6332 | // The point of exit cannot be a branch out of the structured block. |
| 6333 | // longjmp() and throw() must not violate the entry/exit criteria. |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6334 | OpenMPClauseKind AtomicKind = OMPC_unknown; |
| 6335 | SourceLocation AtomicKindLoc; |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6336 | for (auto *C : Clauses) { |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6337 | if (C->getClauseKind() == OMPC_read || C->getClauseKind() == OMPC_write || |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6338 | C->getClauseKind() == OMPC_update || |
| 6339 | C->getClauseKind() == OMPC_capture) { |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6340 | if (AtomicKind != OMPC_unknown) { |
| 6341 | Diag(C->getLocStart(), diag::err_omp_atomic_several_clauses) |
| 6342 | << SourceRange(C->getLocStart(), C->getLocEnd()); |
| 6343 | Diag(AtomicKindLoc, diag::note_omp_atomic_previous_clause) |
| 6344 | << getOpenMPClauseName(AtomicKind); |
| 6345 | } else { |
| 6346 | AtomicKind = C->getClauseKind(); |
| 6347 | AtomicKindLoc = C->getLocStart(); |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6348 | } |
| 6349 | } |
| 6350 | } |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 6351 | |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6352 | auto Body = CS->getCapturedStmt(); |
Alexey Bataev | 10fec57 | 2015-03-11 04:48:56 +0000 | [diff] [blame] | 6353 | if (auto *EWC = dyn_cast<ExprWithCleanups>(Body)) |
| 6354 | Body = EWC->getSubExpr(); |
| 6355 | |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 6356 | Expr *X = nullptr; |
| 6357 | Expr *V = nullptr; |
| 6358 | Expr *E = nullptr; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6359 | Expr *UE = nullptr; |
| 6360 | bool IsXLHSInRHSPart = false; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6361 | bool IsPostfixUpdate = false; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 6362 | // OpenMP [2.12.6, atomic Construct] |
| 6363 | // In the next expressions: |
| 6364 | // * x and v (as applicable) are both l-value expressions with scalar type. |
| 6365 | // * During the execution of an atomic region, multiple syntactic |
| 6366 | // occurrences of x must designate the same storage location. |
| 6367 | // * Neither of v and expr (as applicable) may access the storage location |
| 6368 | // designated by x. |
| 6369 | // * Neither of x and expr (as applicable) may access the storage location |
| 6370 | // designated by v. |
| 6371 | // * expr is an expression with scalar type. |
| 6372 | // * binop is one of +, *, -, /, &, ^, |, <<, or >>. |
| 6373 | // * binop, binop=, ++, and -- are not overloaded operators. |
| 6374 | // * The expression x binop expr must be numerically equivalent to x binop |
| 6375 | // (expr). This requirement is satisfied if the operators in expr have |
| 6376 | // precedence greater than binop, or by using parentheses around expr or |
| 6377 | // subexpressions of expr. |
| 6378 | // * The expression expr binop x must be numerically equivalent to (expr) |
| 6379 | // binop x. This requirement is satisfied if the operators in expr have |
| 6380 | // precedence equal to or greater than binop, or by using parentheses around |
| 6381 | // expr or subexpressions of expr. |
| 6382 | // * For forms that allow multiple occurrences of x, the number of times |
| 6383 | // that x is evaluated is unspecified. |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6384 | if (AtomicKind == OMPC_read) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6385 | enum { |
| 6386 | NotAnExpression, |
| 6387 | NotAnAssignmentOp, |
| 6388 | NotAScalarType, |
| 6389 | NotAnLValue, |
| 6390 | NoError |
| 6391 | } ErrorFound = NoError; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 6392 | SourceLocation ErrorLoc, NoteLoc; |
| 6393 | SourceRange ErrorRange, NoteRange; |
| 6394 | // If clause is read: |
| 6395 | // v = x; |
| 6396 | if (auto AtomicBody = dyn_cast<Expr>(Body)) { |
| 6397 | auto AtomicBinOp = |
| 6398 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 6399 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
| 6400 | X = AtomicBinOp->getRHS()->IgnoreParenImpCasts(); |
| 6401 | V = AtomicBinOp->getLHS()->IgnoreParenImpCasts(); |
| 6402 | if ((X->isInstantiationDependent() || X->getType()->isScalarType()) && |
| 6403 | (V->isInstantiationDependent() || V->getType()->isScalarType())) { |
| 6404 | if (!X->isLValue() || !V->isLValue()) { |
| 6405 | auto NotLValueExpr = X->isLValue() ? V : X; |
| 6406 | ErrorFound = NotAnLValue; |
| 6407 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 6408 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 6409 | NoteLoc = NotLValueExpr->getExprLoc(); |
| 6410 | NoteRange = NotLValueExpr->getSourceRange(); |
| 6411 | } |
| 6412 | } else if (!X->isInstantiationDependent() || |
| 6413 | !V->isInstantiationDependent()) { |
| 6414 | auto NotScalarExpr = |
| 6415 | (X->isInstantiationDependent() || X->getType()->isScalarType()) |
| 6416 | ? V |
| 6417 | : X; |
| 6418 | ErrorFound = NotAScalarType; |
| 6419 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 6420 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 6421 | NoteLoc = NotScalarExpr->getExprLoc(); |
| 6422 | NoteRange = NotScalarExpr->getSourceRange(); |
| 6423 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 6424 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 6425 | ErrorFound = NotAnAssignmentOp; |
| 6426 | ErrorLoc = AtomicBody->getExprLoc(); |
| 6427 | ErrorRange = AtomicBody->getSourceRange(); |
| 6428 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 6429 | : AtomicBody->getExprLoc(); |
| 6430 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 6431 | : AtomicBody->getSourceRange(); |
| 6432 | } |
| 6433 | } else { |
| 6434 | ErrorFound = NotAnExpression; |
| 6435 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 6436 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6437 | } |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 6438 | if (ErrorFound != NoError) { |
| 6439 | Diag(ErrorLoc, diag::err_omp_atomic_read_not_expression_statement) |
| 6440 | << ErrorRange; |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 6441 | Diag(NoteLoc, diag::note_omp_atomic_read_write) << ErrorFound |
| 6442 | << NoteRange; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 6443 | return StmtError(); |
| 6444 | } else if (CurContext->isDependentContext()) |
| 6445 | V = X = nullptr; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6446 | } else if (AtomicKind == OMPC_write) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6447 | enum { |
| 6448 | NotAnExpression, |
| 6449 | NotAnAssignmentOp, |
| 6450 | NotAScalarType, |
| 6451 | NotAnLValue, |
| 6452 | NoError |
| 6453 | } ErrorFound = NoError; |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 6454 | SourceLocation ErrorLoc, NoteLoc; |
| 6455 | SourceRange ErrorRange, NoteRange; |
| 6456 | // If clause is write: |
| 6457 | // x = expr; |
| 6458 | if (auto AtomicBody = dyn_cast<Expr>(Body)) { |
| 6459 | auto AtomicBinOp = |
| 6460 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 6461 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
Alexey Bataev | b832926 | 2015-02-27 06:33:30 +0000 | [diff] [blame] | 6462 | X = AtomicBinOp->getLHS(); |
| 6463 | E = AtomicBinOp->getRHS(); |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 6464 | if ((X->isInstantiationDependent() || X->getType()->isScalarType()) && |
| 6465 | (E->isInstantiationDependent() || E->getType()->isScalarType())) { |
| 6466 | if (!X->isLValue()) { |
| 6467 | ErrorFound = NotAnLValue; |
| 6468 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 6469 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 6470 | NoteLoc = X->getExprLoc(); |
| 6471 | NoteRange = X->getSourceRange(); |
| 6472 | } |
| 6473 | } else if (!X->isInstantiationDependent() || |
| 6474 | !E->isInstantiationDependent()) { |
| 6475 | auto NotScalarExpr = |
| 6476 | (X->isInstantiationDependent() || X->getType()->isScalarType()) |
| 6477 | ? E |
| 6478 | : X; |
| 6479 | ErrorFound = NotAScalarType; |
| 6480 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 6481 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 6482 | NoteLoc = NotScalarExpr->getExprLoc(); |
| 6483 | NoteRange = NotScalarExpr->getSourceRange(); |
| 6484 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 6485 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 6486 | ErrorFound = NotAnAssignmentOp; |
| 6487 | ErrorLoc = AtomicBody->getExprLoc(); |
| 6488 | ErrorRange = AtomicBody->getSourceRange(); |
| 6489 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 6490 | : AtomicBody->getExprLoc(); |
| 6491 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 6492 | : AtomicBody->getSourceRange(); |
| 6493 | } |
| 6494 | } else { |
| 6495 | ErrorFound = NotAnExpression; |
| 6496 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 6497 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6498 | } |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 6499 | if (ErrorFound != NoError) { |
| 6500 | Diag(ErrorLoc, diag::err_omp_atomic_write_not_expression_statement) |
| 6501 | << ErrorRange; |
| 6502 | Diag(NoteLoc, diag::note_omp_atomic_read_write) << ErrorFound |
| 6503 | << NoteRange; |
| 6504 | return StmtError(); |
| 6505 | } else if (CurContext->isDependentContext()) |
| 6506 | E = X = nullptr; |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6507 | } else if (AtomicKind == OMPC_update || AtomicKind == OMPC_unknown) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6508 | // If clause is update: |
| 6509 | // x++; |
| 6510 | // x--; |
| 6511 | // ++x; |
| 6512 | // --x; |
| 6513 | // x binop= expr; |
| 6514 | // x = x binop expr; |
| 6515 | // x = expr binop x; |
| 6516 | OpenMPAtomicUpdateChecker Checker(*this); |
| 6517 | if (Checker.checkStatement( |
| 6518 | Body, (AtomicKind == OMPC_update) |
| 6519 | ? diag::err_omp_atomic_update_not_expression_statement |
| 6520 | : diag::err_omp_atomic_not_expression_statement, |
| 6521 | diag::note_omp_atomic_update)) |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6522 | return StmtError(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6523 | if (!CurContext->isDependentContext()) { |
| 6524 | E = Checker.getExpr(); |
| 6525 | X = Checker.getX(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6526 | UE = Checker.getUpdateExpr(); |
| 6527 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6528 | } |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6529 | } else if (AtomicKind == OMPC_capture) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6530 | enum { |
| 6531 | NotAnAssignmentOp, |
| 6532 | NotACompoundStatement, |
| 6533 | NotTwoSubstatements, |
| 6534 | NotASpecificExpression, |
| 6535 | NoError |
| 6536 | } ErrorFound = NoError; |
| 6537 | SourceLocation ErrorLoc, NoteLoc; |
| 6538 | SourceRange ErrorRange, NoteRange; |
| 6539 | if (auto *AtomicBody = dyn_cast<Expr>(Body)) { |
| 6540 | // If clause is a capture: |
| 6541 | // v = x++; |
| 6542 | // v = x--; |
| 6543 | // v = ++x; |
| 6544 | // v = --x; |
| 6545 | // v = x binop= expr; |
| 6546 | // v = x = x binop expr; |
| 6547 | // v = x = expr binop x; |
| 6548 | auto *AtomicBinOp = |
| 6549 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 6550 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
| 6551 | V = AtomicBinOp->getLHS(); |
| 6552 | Body = AtomicBinOp->getRHS()->IgnoreParenImpCasts(); |
| 6553 | OpenMPAtomicUpdateChecker Checker(*this); |
| 6554 | if (Checker.checkStatement( |
| 6555 | Body, diag::err_omp_atomic_capture_not_expression_statement, |
| 6556 | diag::note_omp_atomic_update)) |
| 6557 | return StmtError(); |
| 6558 | E = Checker.getExpr(); |
| 6559 | X = Checker.getX(); |
| 6560 | UE = Checker.getUpdateExpr(); |
| 6561 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
| 6562 | IsPostfixUpdate = Checker.isPostfixUpdate(); |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 6563 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6564 | ErrorLoc = AtomicBody->getExprLoc(); |
| 6565 | ErrorRange = AtomicBody->getSourceRange(); |
| 6566 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 6567 | : AtomicBody->getExprLoc(); |
| 6568 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 6569 | : AtomicBody->getSourceRange(); |
| 6570 | ErrorFound = NotAnAssignmentOp; |
| 6571 | } |
| 6572 | if (ErrorFound != NoError) { |
| 6573 | Diag(ErrorLoc, diag::err_omp_atomic_capture_not_expression_statement) |
| 6574 | << ErrorRange; |
| 6575 | Diag(NoteLoc, diag::note_omp_atomic_capture) << ErrorFound << NoteRange; |
| 6576 | return StmtError(); |
| 6577 | } else if (CurContext->isDependentContext()) { |
| 6578 | UE = V = E = X = nullptr; |
| 6579 | } |
| 6580 | } else { |
| 6581 | // If clause is a capture: |
| 6582 | // { v = x; x = expr; } |
| 6583 | // { v = x; x++; } |
| 6584 | // { v = x; x--; } |
| 6585 | // { v = x; ++x; } |
| 6586 | // { v = x; --x; } |
| 6587 | // { v = x; x binop= expr; } |
| 6588 | // { v = x; x = x binop expr; } |
| 6589 | // { v = x; x = expr binop x; } |
| 6590 | // { x++; v = x; } |
| 6591 | // { x--; v = x; } |
| 6592 | // { ++x; v = x; } |
| 6593 | // { --x; v = x; } |
| 6594 | // { x binop= expr; v = x; } |
| 6595 | // { x = x binop expr; v = x; } |
| 6596 | // { x = expr binop x; v = x; } |
| 6597 | if (auto *CS = dyn_cast<CompoundStmt>(Body)) { |
| 6598 | // Check that this is { expr1; expr2; } |
| 6599 | if (CS->size() == 2) { |
| 6600 | auto *First = CS->body_front(); |
| 6601 | auto *Second = CS->body_back(); |
| 6602 | if (auto *EWC = dyn_cast<ExprWithCleanups>(First)) |
| 6603 | First = EWC->getSubExpr()->IgnoreParenImpCasts(); |
| 6604 | if (auto *EWC = dyn_cast<ExprWithCleanups>(Second)) |
| 6605 | Second = EWC->getSubExpr()->IgnoreParenImpCasts(); |
| 6606 | // Need to find what subexpression is 'v' and what is 'x'. |
| 6607 | OpenMPAtomicUpdateChecker Checker(*this); |
| 6608 | bool IsUpdateExprFound = !Checker.checkStatement(Second); |
| 6609 | BinaryOperator *BinOp = nullptr; |
| 6610 | if (IsUpdateExprFound) { |
| 6611 | BinOp = dyn_cast<BinaryOperator>(First); |
| 6612 | IsUpdateExprFound = BinOp && BinOp->getOpcode() == BO_Assign; |
| 6613 | } |
| 6614 | if (IsUpdateExprFound && !CurContext->isDependentContext()) { |
| 6615 | // { v = x; x++; } |
| 6616 | // { v = x; x--; } |
| 6617 | // { v = x; ++x; } |
| 6618 | // { v = x; --x; } |
| 6619 | // { v = x; x binop= expr; } |
| 6620 | // { v = x; x = x binop expr; } |
| 6621 | // { v = x; x = expr binop x; } |
| 6622 | // Check that the first expression has form v = x. |
| 6623 | auto *PossibleX = BinOp->getRHS()->IgnoreParenImpCasts(); |
| 6624 | llvm::FoldingSetNodeID XId, PossibleXId; |
| 6625 | Checker.getX()->Profile(XId, Context, /*Canonical=*/true); |
| 6626 | PossibleX->Profile(PossibleXId, Context, /*Canonical=*/true); |
| 6627 | IsUpdateExprFound = XId == PossibleXId; |
| 6628 | if (IsUpdateExprFound) { |
| 6629 | V = BinOp->getLHS(); |
| 6630 | X = Checker.getX(); |
| 6631 | E = Checker.getExpr(); |
| 6632 | UE = Checker.getUpdateExpr(); |
| 6633 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 6634 | IsPostfixUpdate = true; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6635 | } |
| 6636 | } |
| 6637 | if (!IsUpdateExprFound) { |
| 6638 | IsUpdateExprFound = !Checker.checkStatement(First); |
| 6639 | BinOp = nullptr; |
| 6640 | if (IsUpdateExprFound) { |
| 6641 | BinOp = dyn_cast<BinaryOperator>(Second); |
| 6642 | IsUpdateExprFound = BinOp && BinOp->getOpcode() == BO_Assign; |
| 6643 | } |
| 6644 | if (IsUpdateExprFound && !CurContext->isDependentContext()) { |
| 6645 | // { x++; v = x; } |
| 6646 | // { x--; v = x; } |
| 6647 | // { ++x; v = x; } |
| 6648 | // { --x; v = x; } |
| 6649 | // { x binop= expr; v = x; } |
| 6650 | // { x = x binop expr; v = x; } |
| 6651 | // { x = expr binop x; v = x; } |
| 6652 | // Check that the second expression has form v = x. |
| 6653 | auto *PossibleX = BinOp->getRHS()->IgnoreParenImpCasts(); |
| 6654 | llvm::FoldingSetNodeID XId, PossibleXId; |
| 6655 | Checker.getX()->Profile(XId, Context, /*Canonical=*/true); |
| 6656 | PossibleX->Profile(PossibleXId, Context, /*Canonical=*/true); |
| 6657 | IsUpdateExprFound = XId == PossibleXId; |
| 6658 | if (IsUpdateExprFound) { |
| 6659 | V = BinOp->getLHS(); |
| 6660 | X = Checker.getX(); |
| 6661 | E = Checker.getExpr(); |
| 6662 | UE = Checker.getUpdateExpr(); |
| 6663 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 6664 | IsPostfixUpdate = false; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6665 | } |
| 6666 | } |
| 6667 | } |
| 6668 | if (!IsUpdateExprFound) { |
| 6669 | // { v = x; x = expr; } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 6670 | auto *FirstExpr = dyn_cast<Expr>(First); |
| 6671 | auto *SecondExpr = dyn_cast<Expr>(Second); |
| 6672 | if (!FirstExpr || !SecondExpr || |
| 6673 | !(FirstExpr->isInstantiationDependent() || |
| 6674 | SecondExpr->isInstantiationDependent())) { |
| 6675 | auto *FirstBinOp = dyn_cast<BinaryOperator>(First); |
| 6676 | if (!FirstBinOp || FirstBinOp->getOpcode() != BO_Assign) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6677 | ErrorFound = NotAnAssignmentOp; |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 6678 | NoteLoc = ErrorLoc = FirstBinOp ? FirstBinOp->getOperatorLoc() |
| 6679 | : First->getLocStart(); |
| 6680 | NoteRange = ErrorRange = FirstBinOp |
| 6681 | ? FirstBinOp->getSourceRange() |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6682 | : SourceRange(ErrorLoc, ErrorLoc); |
| 6683 | } else { |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 6684 | auto *SecondBinOp = dyn_cast<BinaryOperator>(Second); |
| 6685 | if (!SecondBinOp || SecondBinOp->getOpcode() != BO_Assign) { |
| 6686 | ErrorFound = NotAnAssignmentOp; |
| 6687 | NoteLoc = ErrorLoc = SecondBinOp |
| 6688 | ? SecondBinOp->getOperatorLoc() |
| 6689 | : Second->getLocStart(); |
| 6690 | NoteRange = ErrorRange = |
| 6691 | SecondBinOp ? SecondBinOp->getSourceRange() |
| 6692 | : SourceRange(ErrorLoc, ErrorLoc); |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6693 | } else { |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 6694 | auto *PossibleXRHSInFirst = |
| 6695 | FirstBinOp->getRHS()->IgnoreParenImpCasts(); |
| 6696 | auto *PossibleXLHSInSecond = |
| 6697 | SecondBinOp->getLHS()->IgnoreParenImpCasts(); |
| 6698 | llvm::FoldingSetNodeID X1Id, X2Id; |
| 6699 | PossibleXRHSInFirst->Profile(X1Id, Context, |
| 6700 | /*Canonical=*/true); |
| 6701 | PossibleXLHSInSecond->Profile(X2Id, Context, |
| 6702 | /*Canonical=*/true); |
| 6703 | IsUpdateExprFound = X1Id == X2Id; |
| 6704 | if (IsUpdateExprFound) { |
| 6705 | V = FirstBinOp->getLHS(); |
| 6706 | X = SecondBinOp->getLHS(); |
| 6707 | E = SecondBinOp->getRHS(); |
| 6708 | UE = nullptr; |
| 6709 | IsXLHSInRHSPart = false; |
| 6710 | IsPostfixUpdate = true; |
| 6711 | } else { |
| 6712 | ErrorFound = NotASpecificExpression; |
| 6713 | ErrorLoc = FirstBinOp->getExprLoc(); |
| 6714 | ErrorRange = FirstBinOp->getSourceRange(); |
| 6715 | NoteLoc = SecondBinOp->getLHS()->getExprLoc(); |
| 6716 | NoteRange = SecondBinOp->getRHS()->getSourceRange(); |
| 6717 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6718 | } |
| 6719 | } |
| 6720 | } |
| 6721 | } |
| 6722 | } else { |
| 6723 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 6724 | NoteRange = ErrorRange = |
| 6725 | SourceRange(Body->getLocStart(), Body->getLocStart()); |
| 6726 | ErrorFound = NotTwoSubstatements; |
| 6727 | } |
| 6728 | } else { |
| 6729 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 6730 | NoteRange = ErrorRange = |
| 6731 | SourceRange(Body->getLocStart(), Body->getLocStart()); |
| 6732 | ErrorFound = NotACompoundStatement; |
| 6733 | } |
| 6734 | if (ErrorFound != NoError) { |
| 6735 | Diag(ErrorLoc, diag::err_omp_atomic_capture_not_compound_statement) |
| 6736 | << ErrorRange; |
| 6737 | Diag(NoteLoc, diag::note_omp_atomic_capture) << ErrorFound << NoteRange; |
| 6738 | return StmtError(); |
| 6739 | } else if (CurContext->isDependentContext()) { |
| 6740 | UE = V = E = X = nullptr; |
| 6741 | } |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6742 | } |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6743 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 6744 | |
| 6745 | getCurFunction()->setHasBranchProtectedScope(); |
| 6746 | |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 6747 | return OMPAtomicDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6748 | X, V, E, UE, IsXLHSInRHSPart, |
| 6749 | IsPostfixUpdate); |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 6750 | } |
| 6751 | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 6752 | StmtResult Sema::ActOnOpenMPTargetDirective(ArrayRef<OMPClause *> Clauses, |
| 6753 | Stmt *AStmt, |
| 6754 | SourceLocation StartLoc, |
| 6755 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6756 | if (!AStmt) |
| 6757 | return StmtError(); |
| 6758 | |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 6759 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6760 | // 1.2.2 OpenMP Language Terminology |
| 6761 | // Structured block - An executable statement with a single entry at the |
| 6762 | // top and a single exit at the bottom. |
| 6763 | // The point of exit cannot be a branch out of the structured block. |
| 6764 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6765 | CS->getCapturedDecl()->setNothrow(); |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 6766 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 6767 | // OpenMP [2.16, Nesting of Regions] |
| 6768 | // If specified, a teams construct must be contained within a target |
| 6769 | // construct. That target construct must contain no statements or directives |
| 6770 | // outside of the teams construct. |
| 6771 | if (DSAStack->hasInnerTeamsRegion()) { |
| 6772 | auto S = AStmt->IgnoreContainers(/*IgnoreCaptured*/ true); |
| 6773 | bool OMPTeamsFound = true; |
| 6774 | if (auto *CS = dyn_cast<CompoundStmt>(S)) { |
| 6775 | auto I = CS->body_begin(); |
| 6776 | while (I != CS->body_end()) { |
| 6777 | auto OED = dyn_cast<OMPExecutableDirective>(*I); |
| 6778 | if (!OED || !isOpenMPTeamsDirective(OED->getDirectiveKind())) { |
| 6779 | OMPTeamsFound = false; |
| 6780 | break; |
| 6781 | } |
| 6782 | ++I; |
| 6783 | } |
| 6784 | assert(I != CS->body_end() && "Not found statement"); |
| 6785 | S = *I; |
Kelvin Li | 3834dce | 2016-06-27 19:15:43 +0000 | [diff] [blame] | 6786 | } else { |
| 6787 | auto *OED = dyn_cast<OMPExecutableDirective>(S); |
| 6788 | OMPTeamsFound = OED && isOpenMPTeamsDirective(OED->getDirectiveKind()); |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 6789 | } |
| 6790 | if (!OMPTeamsFound) { |
| 6791 | Diag(StartLoc, diag::err_omp_target_contains_not_only_teams); |
| 6792 | Diag(DSAStack->getInnerTeamsRegionLoc(), |
| 6793 | diag::note_omp_nested_teams_construct_here); |
| 6794 | Diag(S->getLocStart(), diag::note_omp_nested_statement_here) |
| 6795 | << isa<OMPExecutableDirective>(S); |
| 6796 | return StmtError(); |
| 6797 | } |
| 6798 | } |
| 6799 | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 6800 | getCurFunction()->setHasBranchProtectedScope(); |
| 6801 | |
| 6802 | return OMPTargetDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 6803 | } |
| 6804 | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 6805 | StmtResult |
| 6806 | Sema::ActOnOpenMPTargetParallelDirective(ArrayRef<OMPClause *> Clauses, |
| 6807 | Stmt *AStmt, SourceLocation StartLoc, |
| 6808 | SourceLocation EndLoc) { |
| 6809 | if (!AStmt) |
| 6810 | return StmtError(); |
| 6811 | |
| 6812 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6813 | // 1.2.2 OpenMP Language Terminology |
| 6814 | // Structured block - An executable statement with a single entry at the |
| 6815 | // top and a single exit at the bottom. |
| 6816 | // The point of exit cannot be a branch out of the structured block. |
| 6817 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6818 | CS->getCapturedDecl()->setNothrow(); |
| 6819 | |
| 6820 | getCurFunction()->setHasBranchProtectedScope(); |
| 6821 | |
| 6822 | return OMPTargetParallelDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 6823 | AStmt); |
| 6824 | } |
| 6825 | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 6826 | StmtResult Sema::ActOnOpenMPTargetParallelForDirective( |
| 6827 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6828 | SourceLocation EndLoc, |
| 6829 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 6830 | if (!AStmt) |
| 6831 | return StmtError(); |
| 6832 | |
| 6833 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6834 | // 1.2.2 OpenMP Language Terminology |
| 6835 | // Structured block - An executable statement with a single entry at the |
| 6836 | // top and a single exit at the bottom. |
| 6837 | // The point of exit cannot be a branch out of the structured block. |
| 6838 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6839 | CS->getCapturedDecl()->setNothrow(); |
| 6840 | |
| 6841 | OMPLoopDirective::HelperExprs B; |
| 6842 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 6843 | // define the nested loops number. |
| 6844 | unsigned NestedLoopCount = |
| 6845 | CheckOpenMPLoop(OMPD_target_parallel_for, getCollapseNumberExpr(Clauses), |
| 6846 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 6847 | VarsWithImplicitDSA, B); |
| 6848 | if (NestedLoopCount == 0) |
| 6849 | return StmtError(); |
| 6850 | |
| 6851 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6852 | "omp target parallel for loop exprs were not built"); |
| 6853 | |
| 6854 | if (!CurContext->isDependentContext()) { |
| 6855 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 6856 | for (auto C : Clauses) { |
| 6857 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 6858 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 6859 | B.NumIterations, *this, CurScope, |
| 6860 | DSAStack)) |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 6861 | return StmtError(); |
| 6862 | } |
| 6863 | } |
| 6864 | |
| 6865 | getCurFunction()->setHasBranchProtectedScope(); |
| 6866 | return OMPTargetParallelForDirective::Create(Context, StartLoc, EndLoc, |
| 6867 | NestedLoopCount, Clauses, AStmt, |
| 6868 | B, DSAStack->isCancelRegion()); |
| 6869 | } |
| 6870 | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 6871 | /// \brief Check for existence of a map clause in the list of clauses. |
| 6872 | static bool HasMapClause(ArrayRef<OMPClause *> Clauses) { |
| 6873 | for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end(); |
| 6874 | I != E; ++I) { |
| 6875 | if (*I != nullptr && (*I)->getClauseKind() == OMPC_map) { |
| 6876 | return true; |
| 6877 | } |
| 6878 | } |
| 6879 | |
| 6880 | return false; |
| 6881 | } |
| 6882 | |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 6883 | StmtResult Sema::ActOnOpenMPTargetDataDirective(ArrayRef<OMPClause *> Clauses, |
| 6884 | Stmt *AStmt, |
| 6885 | SourceLocation StartLoc, |
| 6886 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6887 | if (!AStmt) |
| 6888 | return StmtError(); |
| 6889 | |
| 6890 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 6891 | |
Arpith Chacko Jacob | 46a04bb | 2016-01-21 19:57:55 +0000 | [diff] [blame] | 6892 | // OpenMP [2.10.1, Restrictions, p. 97] |
| 6893 | // At least one map clause must appear on the directive. |
| 6894 | if (!HasMapClause(Clauses)) { |
| 6895 | Diag(StartLoc, diag::err_omp_no_map_for_directive) << |
| 6896 | getOpenMPDirectiveName(OMPD_target_data); |
| 6897 | return StmtError(); |
| 6898 | } |
| 6899 | |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 6900 | getCurFunction()->setHasBranchProtectedScope(); |
| 6901 | |
| 6902 | return OMPTargetDataDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 6903 | AStmt); |
| 6904 | } |
| 6905 | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 6906 | StmtResult |
| 6907 | Sema::ActOnOpenMPTargetEnterDataDirective(ArrayRef<OMPClause *> Clauses, |
| 6908 | SourceLocation StartLoc, |
| 6909 | SourceLocation EndLoc) { |
| 6910 | // OpenMP [2.10.2, Restrictions, p. 99] |
| 6911 | // At least one map clause must appear on the directive. |
| 6912 | if (!HasMapClause(Clauses)) { |
| 6913 | Diag(StartLoc, diag::err_omp_no_map_for_directive) |
| 6914 | << getOpenMPDirectiveName(OMPD_target_enter_data); |
| 6915 | return StmtError(); |
| 6916 | } |
| 6917 | |
| 6918 | return OMPTargetEnterDataDirective::Create(Context, StartLoc, EndLoc, |
| 6919 | Clauses); |
| 6920 | } |
| 6921 | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 6922 | StmtResult |
| 6923 | Sema::ActOnOpenMPTargetExitDataDirective(ArrayRef<OMPClause *> Clauses, |
| 6924 | SourceLocation StartLoc, |
| 6925 | SourceLocation EndLoc) { |
| 6926 | // OpenMP [2.10.3, Restrictions, p. 102] |
| 6927 | // At least one map clause must appear on the directive. |
| 6928 | if (!HasMapClause(Clauses)) { |
| 6929 | Diag(StartLoc, diag::err_omp_no_map_for_directive) |
| 6930 | << getOpenMPDirectiveName(OMPD_target_exit_data); |
| 6931 | return StmtError(); |
| 6932 | } |
| 6933 | |
| 6934 | return OMPTargetExitDataDirective::Create(Context, StartLoc, EndLoc, Clauses); |
| 6935 | } |
| 6936 | |
Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 6937 | StmtResult Sema::ActOnOpenMPTargetUpdateDirective(ArrayRef<OMPClause *> Clauses, |
| 6938 | SourceLocation StartLoc, |
| 6939 | SourceLocation EndLoc) { |
Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 6940 | bool seenMotionClause = false; |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 6941 | for (auto *C : Clauses) { |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 6942 | if (C->getClauseKind() == OMPC_to || C->getClauseKind() == OMPC_from) |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 6943 | seenMotionClause = true; |
| 6944 | } |
Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 6945 | if (!seenMotionClause) { |
| 6946 | Diag(StartLoc, diag::err_omp_at_least_one_motion_clause_required); |
| 6947 | return StmtError(); |
| 6948 | } |
| 6949 | return OMPTargetUpdateDirective::Create(Context, StartLoc, EndLoc, Clauses); |
| 6950 | } |
| 6951 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 6952 | StmtResult Sema::ActOnOpenMPTeamsDirective(ArrayRef<OMPClause *> Clauses, |
| 6953 | Stmt *AStmt, SourceLocation StartLoc, |
| 6954 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6955 | if (!AStmt) |
| 6956 | return StmtError(); |
| 6957 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 6958 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6959 | // 1.2.2 OpenMP Language Terminology |
| 6960 | // Structured block - An executable statement with a single entry at the |
| 6961 | // top and a single exit at the bottom. |
| 6962 | // The point of exit cannot be a branch out of the structured block. |
| 6963 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6964 | CS->getCapturedDecl()->setNothrow(); |
| 6965 | |
| 6966 | getCurFunction()->setHasBranchProtectedScope(); |
| 6967 | |
| 6968 | return OMPTeamsDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 6969 | } |
| 6970 | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 6971 | StmtResult |
| 6972 | Sema::ActOnOpenMPCancellationPointDirective(SourceLocation StartLoc, |
| 6973 | SourceLocation EndLoc, |
| 6974 | OpenMPDirectiveKind CancelRegion) { |
| 6975 | if (CancelRegion != OMPD_parallel && CancelRegion != OMPD_for && |
| 6976 | CancelRegion != OMPD_sections && CancelRegion != OMPD_taskgroup) { |
| 6977 | Diag(StartLoc, diag::err_omp_wrong_cancel_region) |
| 6978 | << getOpenMPDirectiveName(CancelRegion); |
| 6979 | return StmtError(); |
| 6980 | } |
| 6981 | if (DSAStack->isParentNowaitRegion()) { |
| 6982 | Diag(StartLoc, diag::err_omp_parent_cancel_region_nowait) << 0; |
| 6983 | return StmtError(); |
| 6984 | } |
| 6985 | if (DSAStack->isParentOrderedRegion()) { |
| 6986 | Diag(StartLoc, diag::err_omp_parent_cancel_region_ordered) << 0; |
| 6987 | return StmtError(); |
| 6988 | } |
| 6989 | return OMPCancellationPointDirective::Create(Context, StartLoc, EndLoc, |
| 6990 | CancelRegion); |
| 6991 | } |
| 6992 | |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 6993 | StmtResult Sema::ActOnOpenMPCancelDirective(ArrayRef<OMPClause *> Clauses, |
| 6994 | SourceLocation StartLoc, |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 6995 | SourceLocation EndLoc, |
| 6996 | OpenMPDirectiveKind CancelRegion) { |
| 6997 | if (CancelRegion != OMPD_parallel && CancelRegion != OMPD_for && |
| 6998 | CancelRegion != OMPD_sections && CancelRegion != OMPD_taskgroup) { |
| 6999 | Diag(StartLoc, diag::err_omp_wrong_cancel_region) |
| 7000 | << getOpenMPDirectiveName(CancelRegion); |
| 7001 | return StmtError(); |
| 7002 | } |
| 7003 | if (DSAStack->isParentNowaitRegion()) { |
| 7004 | Diag(StartLoc, diag::err_omp_parent_cancel_region_nowait) << 1; |
| 7005 | return StmtError(); |
| 7006 | } |
| 7007 | if (DSAStack->isParentOrderedRegion()) { |
| 7008 | Diag(StartLoc, diag::err_omp_parent_cancel_region_ordered) << 1; |
| 7009 | return StmtError(); |
| 7010 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 7011 | DSAStack->setParentCancelRegion(/*Cancel=*/true); |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 7012 | return OMPCancelDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 7013 | CancelRegion); |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 7014 | } |
| 7015 | |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 7016 | static bool checkGrainsizeNumTasksClauses(Sema &S, |
| 7017 | ArrayRef<OMPClause *> Clauses) { |
| 7018 | OMPClause *PrevClause = nullptr; |
| 7019 | bool ErrorFound = false; |
| 7020 | for (auto *C : Clauses) { |
| 7021 | if (C->getClauseKind() == OMPC_grainsize || |
| 7022 | C->getClauseKind() == OMPC_num_tasks) { |
| 7023 | if (!PrevClause) |
| 7024 | PrevClause = C; |
| 7025 | else if (PrevClause->getClauseKind() != C->getClauseKind()) { |
| 7026 | S.Diag(C->getLocStart(), |
| 7027 | diag::err_omp_grainsize_num_tasks_mutually_exclusive) |
| 7028 | << getOpenMPClauseName(C->getClauseKind()) |
| 7029 | << getOpenMPClauseName(PrevClause->getClauseKind()); |
| 7030 | S.Diag(PrevClause->getLocStart(), |
| 7031 | diag::note_omp_previous_grainsize_num_tasks) |
| 7032 | << getOpenMPClauseName(PrevClause->getClauseKind()); |
| 7033 | ErrorFound = true; |
| 7034 | } |
| 7035 | } |
| 7036 | } |
| 7037 | return ErrorFound; |
| 7038 | } |
| 7039 | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 7040 | StmtResult Sema::ActOnOpenMPTaskLoopDirective( |
| 7041 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 7042 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7043 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 7044 | if (!AStmt) |
| 7045 | return StmtError(); |
| 7046 | |
| 7047 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 7048 | OMPLoopDirective::HelperExprs B; |
| 7049 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 7050 | // define the nested loops number. |
| 7051 | unsigned NestedLoopCount = |
| 7052 | CheckOpenMPLoop(OMPD_taskloop, getCollapseNumberExpr(Clauses), |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 7053 | /*OrderedLoopCountExpr=*/nullptr, AStmt, *this, *DSAStack, |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 7054 | VarsWithImplicitDSA, B); |
| 7055 | if (NestedLoopCount == 0) |
| 7056 | return StmtError(); |
| 7057 | |
| 7058 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 7059 | "omp for loop exprs were not built"); |
| 7060 | |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 7061 | // OpenMP, [2.9.2 taskloop Construct, Restrictions] |
| 7062 | // The grainsize clause and num_tasks clause are mutually exclusive and may |
| 7063 | // not appear on the same taskloop directive. |
| 7064 | if (checkGrainsizeNumTasksClauses(*this, Clauses)) |
| 7065 | return StmtError(); |
| 7066 | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 7067 | getCurFunction()->setHasBranchProtectedScope(); |
| 7068 | return OMPTaskLoopDirective::Create(Context, StartLoc, EndLoc, |
| 7069 | NestedLoopCount, Clauses, AStmt, B); |
| 7070 | } |
| 7071 | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 7072 | StmtResult Sema::ActOnOpenMPTaskLoopSimdDirective( |
| 7073 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 7074 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7075 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 7076 | if (!AStmt) |
| 7077 | return StmtError(); |
| 7078 | |
| 7079 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 7080 | OMPLoopDirective::HelperExprs B; |
| 7081 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 7082 | // define the nested loops number. |
| 7083 | unsigned NestedLoopCount = |
| 7084 | CheckOpenMPLoop(OMPD_taskloop_simd, getCollapseNumberExpr(Clauses), |
| 7085 | /*OrderedLoopCountExpr=*/nullptr, AStmt, *this, *DSAStack, |
| 7086 | VarsWithImplicitDSA, B); |
| 7087 | if (NestedLoopCount == 0) |
| 7088 | return StmtError(); |
| 7089 | |
| 7090 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 7091 | "omp for loop exprs were not built"); |
| 7092 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 7093 | if (!CurContext->isDependentContext()) { |
| 7094 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 7095 | for (auto C : Clauses) { |
| 7096 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 7097 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 7098 | B.NumIterations, *this, CurScope, |
| 7099 | DSAStack)) |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 7100 | return StmtError(); |
| 7101 | } |
| 7102 | } |
| 7103 | |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 7104 | // OpenMP, [2.9.2 taskloop Construct, Restrictions] |
| 7105 | // The grainsize clause and num_tasks clause are mutually exclusive and may |
| 7106 | // not appear on the same taskloop directive. |
| 7107 | if (checkGrainsizeNumTasksClauses(*this, Clauses)) |
| 7108 | return StmtError(); |
| 7109 | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 7110 | getCurFunction()->setHasBranchProtectedScope(); |
| 7111 | return OMPTaskLoopSimdDirective::Create(Context, StartLoc, EndLoc, |
| 7112 | NestedLoopCount, Clauses, AStmt, B); |
| 7113 | } |
| 7114 | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7115 | StmtResult Sema::ActOnOpenMPDistributeDirective( |
| 7116 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 7117 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7118 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7119 | if (!AStmt) |
| 7120 | return StmtError(); |
| 7121 | |
| 7122 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 7123 | OMPLoopDirective::HelperExprs B; |
| 7124 | // In presence of clause 'collapse' with number of loops, it will |
| 7125 | // define the nested loops number. |
| 7126 | unsigned NestedLoopCount = |
| 7127 | CheckOpenMPLoop(OMPD_distribute, getCollapseNumberExpr(Clauses), |
| 7128 | nullptr /*ordered not a clause on distribute*/, AStmt, |
| 7129 | *this, *DSAStack, VarsWithImplicitDSA, B); |
| 7130 | if (NestedLoopCount == 0) |
| 7131 | return StmtError(); |
| 7132 | |
| 7133 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 7134 | "omp for loop exprs were not built"); |
| 7135 | |
| 7136 | getCurFunction()->setHasBranchProtectedScope(); |
| 7137 | return OMPDistributeDirective::Create(Context, StartLoc, EndLoc, |
| 7138 | NestedLoopCount, Clauses, AStmt, B); |
| 7139 | } |
| 7140 | |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 7141 | StmtResult Sema::ActOnOpenMPDistributeParallelForDirective( |
| 7142 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 7143 | SourceLocation EndLoc, |
| 7144 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 7145 | if (!AStmt) |
| 7146 | return StmtError(); |
| 7147 | |
| 7148 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 7149 | // 1.2.2 OpenMP Language Terminology |
| 7150 | // Structured block - An executable statement with a single entry at the |
| 7151 | // top and a single exit at the bottom. |
| 7152 | // The point of exit cannot be a branch out of the structured block. |
| 7153 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 7154 | CS->getCapturedDecl()->setNothrow(); |
| 7155 | |
| 7156 | OMPLoopDirective::HelperExprs B; |
| 7157 | // In presence of clause 'collapse' with number of loops, it will |
| 7158 | // define the nested loops number. |
| 7159 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 7160 | OMPD_distribute_parallel_for, getCollapseNumberExpr(Clauses), |
| 7161 | nullptr /*ordered not a clause on distribute*/, AStmt, *this, *DSAStack, |
| 7162 | VarsWithImplicitDSA, B); |
| 7163 | if (NestedLoopCount == 0) |
| 7164 | return StmtError(); |
| 7165 | |
| 7166 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 7167 | "omp for loop exprs were not built"); |
| 7168 | |
| 7169 | getCurFunction()->setHasBranchProtectedScope(); |
| 7170 | return OMPDistributeParallelForDirective::Create( |
| 7171 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 7172 | } |
| 7173 | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 7174 | StmtResult Sema::ActOnOpenMPDistributeParallelForSimdDirective( |
| 7175 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 7176 | SourceLocation EndLoc, |
| 7177 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 7178 | if (!AStmt) |
| 7179 | return StmtError(); |
| 7180 | |
| 7181 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 7182 | // 1.2.2 OpenMP Language Terminology |
| 7183 | // Structured block - An executable statement with a single entry at the |
| 7184 | // top and a single exit at the bottom. |
| 7185 | // The point of exit cannot be a branch out of the structured block. |
| 7186 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 7187 | CS->getCapturedDecl()->setNothrow(); |
| 7188 | |
| 7189 | OMPLoopDirective::HelperExprs B; |
| 7190 | // In presence of clause 'collapse' with number of loops, it will |
| 7191 | // define the nested loops number. |
| 7192 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 7193 | OMPD_distribute_parallel_for_simd, getCollapseNumberExpr(Clauses), |
| 7194 | nullptr /*ordered not a clause on distribute*/, AStmt, *this, *DSAStack, |
| 7195 | VarsWithImplicitDSA, B); |
| 7196 | if (NestedLoopCount == 0) |
| 7197 | return StmtError(); |
| 7198 | |
| 7199 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 7200 | "omp for loop exprs were not built"); |
| 7201 | |
Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 7202 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
| 7203 | return StmtError(); |
| 7204 | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 7205 | getCurFunction()->setHasBranchProtectedScope(); |
| 7206 | return OMPDistributeParallelForSimdDirective::Create( |
| 7207 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 7208 | } |
| 7209 | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 7210 | StmtResult Sema::ActOnOpenMPDistributeSimdDirective( |
| 7211 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 7212 | SourceLocation EndLoc, |
| 7213 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 7214 | if (!AStmt) |
| 7215 | return StmtError(); |
| 7216 | |
| 7217 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 7218 | // 1.2.2 OpenMP Language Terminology |
| 7219 | // Structured block - An executable statement with a single entry at the |
| 7220 | // top and a single exit at the bottom. |
| 7221 | // The point of exit cannot be a branch out of the structured block. |
| 7222 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 7223 | CS->getCapturedDecl()->setNothrow(); |
| 7224 | |
| 7225 | OMPLoopDirective::HelperExprs B; |
| 7226 | // In presence of clause 'collapse' with number of loops, it will |
| 7227 | // define the nested loops number. |
| 7228 | unsigned NestedLoopCount = |
| 7229 | CheckOpenMPLoop(OMPD_distribute_simd, getCollapseNumberExpr(Clauses), |
| 7230 | nullptr /*ordered not a clause on distribute*/, AStmt, |
| 7231 | *this, *DSAStack, VarsWithImplicitDSA, B); |
| 7232 | if (NestedLoopCount == 0) |
| 7233 | return StmtError(); |
| 7234 | |
| 7235 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 7236 | "omp for loop exprs were not built"); |
| 7237 | |
Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 7238 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
| 7239 | return StmtError(); |
| 7240 | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 7241 | getCurFunction()->setHasBranchProtectedScope(); |
| 7242 | return OMPDistributeSimdDirective::Create(Context, StartLoc, EndLoc, |
| 7243 | NestedLoopCount, Clauses, AStmt, B); |
| 7244 | } |
| 7245 | |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 7246 | StmtResult Sema::ActOnOpenMPTargetParallelForSimdDirective( |
| 7247 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 7248 | SourceLocation EndLoc, |
| 7249 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 7250 | if (!AStmt) |
| 7251 | return StmtError(); |
| 7252 | |
| 7253 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 7254 | // 1.2.2 OpenMP Language Terminology |
| 7255 | // Structured block - An executable statement with a single entry at the |
| 7256 | // top and a single exit at the bottom. |
| 7257 | // The point of exit cannot be a branch out of the structured block. |
| 7258 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 7259 | CS->getCapturedDecl()->setNothrow(); |
| 7260 | |
| 7261 | OMPLoopDirective::HelperExprs B; |
| 7262 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 7263 | // define the nested loops number. |
| 7264 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 7265 | OMPD_target_parallel_for_simd, getCollapseNumberExpr(Clauses), |
| 7266 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 7267 | VarsWithImplicitDSA, B); |
| 7268 | if (NestedLoopCount == 0) |
| 7269 | return StmtError(); |
| 7270 | |
| 7271 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 7272 | "omp target parallel for simd loop exprs were not built"); |
| 7273 | |
| 7274 | if (!CurContext->isDependentContext()) { |
| 7275 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 7276 | for (auto C : Clauses) { |
| 7277 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 7278 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 7279 | B.NumIterations, *this, CurScope, |
| 7280 | DSAStack)) |
| 7281 | return StmtError(); |
| 7282 | } |
| 7283 | } |
Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 7284 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 7285 | return StmtError(); |
| 7286 | |
| 7287 | getCurFunction()->setHasBranchProtectedScope(); |
| 7288 | return OMPTargetParallelForSimdDirective::Create( |
| 7289 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 7290 | } |
| 7291 | |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 7292 | StmtResult Sema::ActOnOpenMPTargetSimdDirective( |
| 7293 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 7294 | SourceLocation EndLoc, |
| 7295 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 7296 | if (!AStmt) |
| 7297 | return StmtError(); |
| 7298 | |
| 7299 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 7300 | // 1.2.2 OpenMP Language Terminology |
| 7301 | // Structured block - An executable statement with a single entry at the |
| 7302 | // top and a single exit at the bottom. |
| 7303 | // The point of exit cannot be a branch out of the structured block. |
| 7304 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 7305 | CS->getCapturedDecl()->setNothrow(); |
| 7306 | |
| 7307 | OMPLoopDirective::HelperExprs B; |
| 7308 | // In presence of clause 'collapse' with number of loops, it will define the |
| 7309 | // nested loops number. |
| 7310 | unsigned NestedLoopCount = |
| 7311 | CheckOpenMPLoop(OMPD_target_simd, getCollapseNumberExpr(Clauses), |
| 7312 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 7313 | VarsWithImplicitDSA, B); |
| 7314 | if (NestedLoopCount == 0) |
| 7315 | return StmtError(); |
| 7316 | |
| 7317 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 7318 | "omp target simd loop exprs were not built"); |
| 7319 | |
| 7320 | if (!CurContext->isDependentContext()) { |
| 7321 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 7322 | for (auto C : Clauses) { |
| 7323 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 7324 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 7325 | B.NumIterations, *this, CurScope, |
| 7326 | DSAStack)) |
| 7327 | return StmtError(); |
| 7328 | } |
| 7329 | } |
| 7330 | |
| 7331 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
| 7332 | return StmtError(); |
| 7333 | |
| 7334 | getCurFunction()->setHasBranchProtectedScope(); |
| 7335 | return OMPTargetSimdDirective::Create(Context, StartLoc, EndLoc, |
| 7336 | NestedLoopCount, Clauses, AStmt, B); |
| 7337 | } |
| 7338 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7339 | OMPClause *Sema::ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, Expr *Expr, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7340 | SourceLocation StartLoc, |
| 7341 | SourceLocation LParenLoc, |
| 7342 | SourceLocation EndLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 7343 | OMPClause *Res = nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7344 | switch (Kind) { |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 7345 | case OMPC_final: |
| 7346 | Res = ActOnOpenMPFinalClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 7347 | break; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7348 | case OMPC_num_threads: |
| 7349 | Res = ActOnOpenMPNumThreadsClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 7350 | break; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 7351 | case OMPC_safelen: |
| 7352 | Res = ActOnOpenMPSafelenClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 7353 | break; |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 7354 | case OMPC_simdlen: |
| 7355 | Res = ActOnOpenMPSimdlenClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 7356 | break; |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 7357 | case OMPC_collapse: |
| 7358 | Res = ActOnOpenMPCollapseClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 7359 | break; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 7360 | case OMPC_ordered: |
| 7361 | Res = ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Expr); |
| 7362 | break; |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 7363 | case OMPC_device: |
| 7364 | Res = ActOnOpenMPDeviceClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 7365 | break; |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 7366 | case OMPC_num_teams: |
| 7367 | Res = ActOnOpenMPNumTeamsClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 7368 | break; |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7369 | case OMPC_thread_limit: |
| 7370 | Res = ActOnOpenMPThreadLimitClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 7371 | break; |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 7372 | case OMPC_priority: |
| 7373 | Res = ActOnOpenMPPriorityClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 7374 | break; |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 7375 | case OMPC_grainsize: |
| 7376 | Res = ActOnOpenMPGrainsizeClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 7377 | break; |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 7378 | case OMPC_num_tasks: |
| 7379 | Res = ActOnOpenMPNumTasksClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 7380 | break; |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 7381 | case OMPC_hint: |
| 7382 | Res = ActOnOpenMPHintClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 7383 | break; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 7384 | case OMPC_if: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7385 | case OMPC_default: |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 7386 | case OMPC_proc_bind: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7387 | case OMPC_schedule: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7388 | case OMPC_private: |
| 7389 | case OMPC_firstprivate: |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7390 | case OMPC_lastprivate: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7391 | case OMPC_shared: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7392 | case OMPC_reduction: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7393 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 7394 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7395 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7396 | case OMPC_copyprivate: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 7397 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 7398 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 7399 | case OMPC_mergeable: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7400 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 7401 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 7402 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 7403 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 7404 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 7405 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 7406 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 7407 | case OMPC_depend: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 7408 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 7409 | case OMPC_simd: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 7410 | case OMPC_map: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 7411 | case OMPC_nogroup: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 7412 | case OMPC_dist_schedule: |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 7413 | case OMPC_defaultmap: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7414 | case OMPC_unknown: |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 7415 | case OMPC_uniform: |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 7416 | case OMPC_to: |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 7417 | case OMPC_from: |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 7418 | case OMPC_use_device_ptr: |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 7419 | case OMPC_is_device_ptr: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7420 | llvm_unreachable("Clause is not allowed."); |
| 7421 | } |
| 7422 | return Res; |
| 7423 | } |
| 7424 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 7425 | OMPClause *Sema::ActOnOpenMPIfClause(OpenMPDirectiveKind NameModifier, |
| 7426 | Expr *Condition, SourceLocation StartLoc, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7427 | SourceLocation LParenLoc, |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 7428 | SourceLocation NameModifierLoc, |
| 7429 | SourceLocation ColonLoc, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7430 | SourceLocation EndLoc) { |
| 7431 | Expr *ValExpr = Condition; |
| 7432 | if (!Condition->isValueDependent() && !Condition->isTypeDependent() && |
| 7433 | !Condition->isInstantiationDependent() && |
| 7434 | !Condition->containsUnexpandedParameterPack()) { |
Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 7435 | ExprResult Val = CheckBooleanCondition(StartLoc, Condition); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7436 | if (Val.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 7437 | return nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7438 | |
Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 7439 | ValExpr = MakeFullExpr(Val.get()).get(); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7440 | } |
| 7441 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 7442 | return new (Context) OMPIfClause(NameModifier, ValExpr, StartLoc, LParenLoc, |
| 7443 | NameModifierLoc, ColonLoc, EndLoc); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7444 | } |
| 7445 | |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 7446 | OMPClause *Sema::ActOnOpenMPFinalClause(Expr *Condition, |
| 7447 | SourceLocation StartLoc, |
| 7448 | SourceLocation LParenLoc, |
| 7449 | SourceLocation EndLoc) { |
| 7450 | Expr *ValExpr = Condition; |
| 7451 | if (!Condition->isValueDependent() && !Condition->isTypeDependent() && |
| 7452 | !Condition->isInstantiationDependent() && |
| 7453 | !Condition->containsUnexpandedParameterPack()) { |
Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 7454 | ExprResult Val = CheckBooleanCondition(StartLoc, Condition); |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 7455 | if (Val.isInvalid()) |
| 7456 | return nullptr; |
| 7457 | |
Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 7458 | ValExpr = MakeFullExpr(Val.get()).get(); |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 7459 | } |
| 7460 | |
| 7461 | return new (Context) OMPFinalClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 7462 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 7463 | ExprResult Sema::PerformOpenMPImplicitIntegerConversion(SourceLocation Loc, |
| 7464 | Expr *Op) { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7465 | if (!Op) |
| 7466 | return ExprError(); |
| 7467 | |
| 7468 | class IntConvertDiagnoser : public ICEConvertDiagnoser { |
| 7469 | public: |
| 7470 | IntConvertDiagnoser() |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7471 | : ICEConvertDiagnoser(/*AllowScopedEnumerations*/ false, false, true) {} |
Craig Topper | e14c0f8 | 2014-03-12 04:55:44 +0000 | [diff] [blame] | 7472 | SemaDiagnosticBuilder diagnoseNotInt(Sema &S, SourceLocation Loc, |
| 7473 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7474 | return S.Diag(Loc, diag::err_omp_not_integral) << T; |
| 7475 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7476 | SemaDiagnosticBuilder diagnoseIncomplete(Sema &S, SourceLocation Loc, |
| 7477 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7478 | return S.Diag(Loc, diag::err_omp_incomplete_type) << T; |
| 7479 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7480 | SemaDiagnosticBuilder diagnoseExplicitConv(Sema &S, SourceLocation Loc, |
| 7481 | QualType T, |
| 7482 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7483 | return S.Diag(Loc, diag::err_omp_explicit_conversion) << T << ConvTy; |
| 7484 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7485 | SemaDiagnosticBuilder noteExplicitConv(Sema &S, CXXConversionDecl *Conv, |
| 7486 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7487 | return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7488 | << ConvTy->isEnumeralType() << ConvTy; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7489 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7490 | SemaDiagnosticBuilder diagnoseAmbiguous(Sema &S, SourceLocation Loc, |
| 7491 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7492 | return S.Diag(Loc, diag::err_omp_ambiguous_conversion) << T; |
| 7493 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7494 | SemaDiagnosticBuilder noteAmbiguous(Sema &S, CXXConversionDecl *Conv, |
| 7495 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7496 | return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7497 | << ConvTy->isEnumeralType() << ConvTy; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7498 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7499 | SemaDiagnosticBuilder diagnoseConversion(Sema &, SourceLocation, QualType, |
| 7500 | QualType) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7501 | llvm_unreachable("conversion functions are permitted"); |
| 7502 | } |
| 7503 | } ConvertDiagnoser; |
| 7504 | return PerformContextualImplicitConversion(Loc, Op, ConvertDiagnoser); |
| 7505 | } |
| 7506 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7507 | static bool IsNonNegativeIntegerValue(Expr *&ValExpr, Sema &SemaRef, |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 7508 | OpenMPClauseKind CKind, |
| 7509 | bool StrictlyPositive) { |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7510 | if (!ValExpr->isTypeDependent() && !ValExpr->isValueDependent() && |
| 7511 | !ValExpr->isInstantiationDependent()) { |
| 7512 | SourceLocation Loc = ValExpr->getExprLoc(); |
| 7513 | ExprResult Value = |
| 7514 | SemaRef.PerformOpenMPImplicitIntegerConversion(Loc, ValExpr); |
| 7515 | if (Value.isInvalid()) |
| 7516 | return false; |
| 7517 | |
| 7518 | ValExpr = Value.get(); |
| 7519 | // The expression must evaluate to a non-negative integer value. |
| 7520 | llvm::APSInt Result; |
| 7521 | if (ValExpr->isIntegerConstantExpr(Result, SemaRef.Context) && |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 7522 | Result.isSigned() && |
| 7523 | !((!StrictlyPositive && Result.isNonNegative()) || |
| 7524 | (StrictlyPositive && Result.isStrictlyPositive()))) { |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7525 | SemaRef.Diag(Loc, diag::err_omp_negative_expression_in_clause) |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 7526 | << getOpenMPClauseName(CKind) << (StrictlyPositive ? 1 : 0) |
| 7527 | << ValExpr->getSourceRange(); |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7528 | return false; |
| 7529 | } |
| 7530 | } |
| 7531 | return true; |
| 7532 | } |
| 7533 | |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7534 | OMPClause *Sema::ActOnOpenMPNumThreadsClause(Expr *NumThreads, |
| 7535 | SourceLocation StartLoc, |
| 7536 | SourceLocation LParenLoc, |
| 7537 | SourceLocation EndLoc) { |
| 7538 | Expr *ValExpr = NumThreads; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7539 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7540 | // OpenMP [2.5, Restrictions] |
| 7541 | // The num_threads expression must evaluate to a positive integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 7542 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_num_threads, |
| 7543 | /*StrictlyPositive=*/true)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7544 | return nullptr; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7545 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7546 | return new (Context) |
| 7547 | OMPNumThreadsClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7548 | } |
| 7549 | |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 7550 | ExprResult Sema::VerifyPositiveIntegerConstantInClause(Expr *E, |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 7551 | OpenMPClauseKind CKind, |
| 7552 | bool StrictlyPositive) { |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 7553 | if (!E) |
| 7554 | return ExprError(); |
| 7555 | if (E->isValueDependent() || E->isTypeDependent() || |
| 7556 | E->isInstantiationDependent() || E->containsUnexpandedParameterPack()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7557 | return E; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 7558 | llvm::APSInt Result; |
| 7559 | ExprResult ICE = VerifyIntegerConstantExpression(E, &Result); |
| 7560 | if (ICE.isInvalid()) |
| 7561 | return ExprError(); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 7562 | if ((StrictlyPositive && !Result.isStrictlyPositive()) || |
| 7563 | (!StrictlyPositive && !Result.isNonNegative())) { |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 7564 | Diag(E->getExprLoc(), diag::err_omp_negative_expression_in_clause) |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 7565 | << getOpenMPClauseName(CKind) << (StrictlyPositive ? 1 : 0) |
| 7566 | << E->getSourceRange(); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 7567 | return ExprError(); |
| 7568 | } |
Alexander Musman | 09184fe | 2014-09-30 05:29:28 +0000 | [diff] [blame] | 7569 | if (CKind == OMPC_aligned && !Result.isPowerOf2()) { |
| 7570 | Diag(E->getExprLoc(), diag::warn_omp_alignment_not_power_of_two) |
| 7571 | << E->getSourceRange(); |
| 7572 | return ExprError(); |
| 7573 | } |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 7574 | if (CKind == OMPC_collapse && DSAStack->getAssociatedLoops() == 1) |
| 7575 | DSAStack->setAssociatedLoops(Result.getExtValue()); |
Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 7576 | else if (CKind == OMPC_ordered) |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 7577 | DSAStack->setAssociatedLoops(Result.getExtValue()); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 7578 | return ICE; |
| 7579 | } |
| 7580 | |
| 7581 | OMPClause *Sema::ActOnOpenMPSafelenClause(Expr *Len, SourceLocation StartLoc, |
| 7582 | SourceLocation LParenLoc, |
| 7583 | SourceLocation EndLoc) { |
| 7584 | // OpenMP [2.8.1, simd construct, Description] |
| 7585 | // The parameter of the safelen clause must be a constant |
| 7586 | // positive integer expression. |
| 7587 | ExprResult Safelen = VerifyPositiveIntegerConstantInClause(Len, OMPC_safelen); |
| 7588 | if (Safelen.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 7589 | return nullptr; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 7590 | return new (Context) |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 7591 | OMPSafelenClause(Safelen.get(), StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 7592 | } |
| 7593 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 7594 | OMPClause *Sema::ActOnOpenMPSimdlenClause(Expr *Len, SourceLocation StartLoc, |
| 7595 | SourceLocation LParenLoc, |
| 7596 | SourceLocation EndLoc) { |
| 7597 | // OpenMP [2.8.1, simd construct, Description] |
| 7598 | // The parameter of the simdlen clause must be a constant |
| 7599 | // positive integer expression. |
| 7600 | ExprResult Simdlen = VerifyPositiveIntegerConstantInClause(Len, OMPC_simdlen); |
| 7601 | if (Simdlen.isInvalid()) |
| 7602 | return nullptr; |
| 7603 | return new (Context) |
| 7604 | OMPSimdlenClause(Simdlen.get(), StartLoc, LParenLoc, EndLoc); |
| 7605 | } |
| 7606 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7607 | OMPClause *Sema::ActOnOpenMPCollapseClause(Expr *NumForLoops, |
| 7608 | SourceLocation StartLoc, |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 7609 | SourceLocation LParenLoc, |
| 7610 | SourceLocation EndLoc) { |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7611 | // OpenMP [2.7.1, loop construct, Description] |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 7612 | // OpenMP [2.8.1, simd construct, Description] |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7613 | // OpenMP [2.9.6, distribute construct, Description] |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 7614 | // The parameter of the collapse clause must be a constant |
| 7615 | // positive integer expression. |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7616 | ExprResult NumForLoopsResult = |
| 7617 | VerifyPositiveIntegerConstantInClause(NumForLoops, OMPC_collapse); |
| 7618 | if (NumForLoopsResult.isInvalid()) |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 7619 | return nullptr; |
| 7620 | return new (Context) |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7621 | OMPCollapseClause(NumForLoopsResult.get(), StartLoc, LParenLoc, EndLoc); |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 7622 | } |
| 7623 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 7624 | OMPClause *Sema::ActOnOpenMPOrderedClause(SourceLocation StartLoc, |
| 7625 | SourceLocation EndLoc, |
| 7626 | SourceLocation LParenLoc, |
| 7627 | Expr *NumForLoops) { |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 7628 | // OpenMP [2.7.1, loop construct, Description] |
| 7629 | // OpenMP [2.8.1, simd construct, Description] |
| 7630 | // OpenMP [2.9.6, distribute construct, Description] |
| 7631 | // The parameter of the ordered clause must be a constant |
| 7632 | // positive integer expression if any. |
| 7633 | if (NumForLoops && LParenLoc.isValid()) { |
| 7634 | ExprResult NumForLoopsResult = |
| 7635 | VerifyPositiveIntegerConstantInClause(NumForLoops, OMPC_ordered); |
| 7636 | if (NumForLoopsResult.isInvalid()) |
| 7637 | return nullptr; |
| 7638 | NumForLoops = NumForLoopsResult.get(); |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 7639 | } else |
| 7640 | NumForLoops = nullptr; |
| 7641 | DSAStack->setOrderedRegion(/*IsOrdered=*/true, NumForLoops); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 7642 | return new (Context) |
| 7643 | OMPOrderedClause(NumForLoops, StartLoc, LParenLoc, EndLoc); |
| 7644 | } |
| 7645 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7646 | OMPClause *Sema::ActOnOpenMPSimpleClause( |
| 7647 | OpenMPClauseKind Kind, unsigned Argument, SourceLocation ArgumentLoc, |
| 7648 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 7649 | OMPClause *Res = nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7650 | switch (Kind) { |
| 7651 | case OMPC_default: |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7652 | Res = |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7653 | ActOnOpenMPDefaultClause(static_cast<OpenMPDefaultClauseKind>(Argument), |
| 7654 | ArgumentLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7655 | break; |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 7656 | case OMPC_proc_bind: |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7657 | Res = ActOnOpenMPProcBindClause( |
| 7658 | static_cast<OpenMPProcBindClauseKind>(Argument), ArgumentLoc, StartLoc, |
| 7659 | LParenLoc, EndLoc); |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 7660 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7661 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 7662 | case OMPC_final: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7663 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 7664 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 7665 | case OMPC_simdlen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 7666 | case OMPC_collapse: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7667 | case OMPC_schedule: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7668 | case OMPC_private: |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7669 | case OMPC_firstprivate: |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7670 | case OMPC_lastprivate: |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7671 | case OMPC_shared: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7672 | case OMPC_reduction: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7673 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 7674 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7675 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7676 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7677 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 7678 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 7679 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 7680 | case OMPC_mergeable: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7681 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 7682 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 7683 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 7684 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 7685 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 7686 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 7687 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 7688 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 7689 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 7690 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 7691 | case OMPC_simd: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 7692 | case OMPC_map: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 7693 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7694 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 7695 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 7696 | case OMPC_grainsize: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 7697 | case OMPC_nogroup: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 7698 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 7699 | case OMPC_hint: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 7700 | case OMPC_dist_schedule: |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 7701 | case OMPC_defaultmap: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7702 | case OMPC_unknown: |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 7703 | case OMPC_uniform: |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 7704 | case OMPC_to: |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 7705 | case OMPC_from: |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 7706 | case OMPC_use_device_ptr: |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 7707 | case OMPC_is_device_ptr: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7708 | llvm_unreachable("Clause is not allowed."); |
| 7709 | } |
| 7710 | return Res; |
| 7711 | } |
| 7712 | |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7713 | static std::string |
| 7714 | getListOfPossibleValues(OpenMPClauseKind K, unsigned First, unsigned Last, |
| 7715 | ArrayRef<unsigned> Exclude = llvm::None) { |
| 7716 | std::string Values; |
| 7717 | unsigned Bound = Last >= 2 ? Last - 2 : 0; |
| 7718 | unsigned Skipped = Exclude.size(); |
| 7719 | auto S = Exclude.begin(), E = Exclude.end(); |
| 7720 | for (unsigned i = First; i < Last; ++i) { |
| 7721 | if (std::find(S, E, i) != E) { |
| 7722 | --Skipped; |
| 7723 | continue; |
| 7724 | } |
| 7725 | Values += "'"; |
| 7726 | Values += getOpenMPSimpleClauseTypeName(K, i); |
| 7727 | Values += "'"; |
| 7728 | if (i == Bound - Skipped) |
| 7729 | Values += " or "; |
| 7730 | else if (i != Bound + 1 - Skipped) |
| 7731 | Values += ", "; |
| 7732 | } |
| 7733 | return Values; |
| 7734 | } |
| 7735 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7736 | OMPClause *Sema::ActOnOpenMPDefaultClause(OpenMPDefaultClauseKind Kind, |
| 7737 | SourceLocation KindKwLoc, |
| 7738 | SourceLocation StartLoc, |
| 7739 | SourceLocation LParenLoc, |
| 7740 | SourceLocation EndLoc) { |
| 7741 | if (Kind == OMPC_DEFAULT_unknown) { |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 7742 | static_assert(OMPC_DEFAULT_unknown > 0, |
| 7743 | "OMPC_DEFAULT_unknown not greater than 0"); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7744 | Diag(KindKwLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7745 | << getListOfPossibleValues(OMPC_default, /*First=*/0, |
| 7746 | /*Last=*/OMPC_DEFAULT_unknown) |
| 7747 | << getOpenMPClauseName(OMPC_default); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 7748 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7749 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7750 | switch (Kind) { |
| 7751 | case OMPC_DEFAULT_none: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7752 | DSAStack->setDefaultDSANone(KindKwLoc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7753 | break; |
| 7754 | case OMPC_DEFAULT_shared: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7755 | DSAStack->setDefaultDSAShared(KindKwLoc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7756 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7757 | case OMPC_DEFAULT_unknown: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7758 | llvm_unreachable("Clause kind is not allowed."); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7759 | break; |
| 7760 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7761 | return new (Context) |
| 7762 | OMPDefaultClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7763 | } |
| 7764 | |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 7765 | OMPClause *Sema::ActOnOpenMPProcBindClause(OpenMPProcBindClauseKind Kind, |
| 7766 | SourceLocation KindKwLoc, |
| 7767 | SourceLocation StartLoc, |
| 7768 | SourceLocation LParenLoc, |
| 7769 | SourceLocation EndLoc) { |
| 7770 | if (Kind == OMPC_PROC_BIND_unknown) { |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 7771 | Diag(KindKwLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7772 | << getListOfPossibleValues(OMPC_proc_bind, /*First=*/0, |
| 7773 | /*Last=*/OMPC_PROC_BIND_unknown) |
| 7774 | << getOpenMPClauseName(OMPC_proc_bind); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 7775 | return nullptr; |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 7776 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7777 | return new (Context) |
| 7778 | OMPProcBindClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 7779 | } |
| 7780 | |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7781 | OMPClause *Sema::ActOnOpenMPSingleExprWithArgClause( |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7782 | OpenMPClauseKind Kind, ArrayRef<unsigned> Argument, Expr *Expr, |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7783 | SourceLocation StartLoc, SourceLocation LParenLoc, |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7784 | ArrayRef<SourceLocation> ArgumentLoc, SourceLocation DelimLoc, |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7785 | SourceLocation EndLoc) { |
| 7786 | OMPClause *Res = nullptr; |
| 7787 | switch (Kind) { |
| 7788 | case OMPC_schedule: |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7789 | enum { Modifier1, Modifier2, ScheduleKind, NumberOfElements }; |
| 7790 | assert(Argument.size() == NumberOfElements && |
| 7791 | ArgumentLoc.size() == NumberOfElements); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7792 | Res = ActOnOpenMPScheduleClause( |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7793 | static_cast<OpenMPScheduleClauseModifier>(Argument[Modifier1]), |
| 7794 | static_cast<OpenMPScheduleClauseModifier>(Argument[Modifier2]), |
| 7795 | static_cast<OpenMPScheduleClauseKind>(Argument[ScheduleKind]), Expr, |
| 7796 | StartLoc, LParenLoc, ArgumentLoc[Modifier1], ArgumentLoc[Modifier2], |
| 7797 | ArgumentLoc[ScheduleKind], DelimLoc, EndLoc); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7798 | break; |
| 7799 | case OMPC_if: |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7800 | assert(Argument.size() == 1 && ArgumentLoc.size() == 1); |
| 7801 | Res = ActOnOpenMPIfClause(static_cast<OpenMPDirectiveKind>(Argument.back()), |
| 7802 | Expr, StartLoc, LParenLoc, ArgumentLoc.back(), |
| 7803 | DelimLoc, EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 7804 | break; |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 7805 | case OMPC_dist_schedule: |
| 7806 | Res = ActOnOpenMPDistScheduleClause( |
| 7807 | static_cast<OpenMPDistScheduleClauseKind>(Argument.back()), Expr, |
| 7808 | StartLoc, LParenLoc, ArgumentLoc.back(), DelimLoc, EndLoc); |
| 7809 | break; |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 7810 | case OMPC_defaultmap: |
| 7811 | enum { Modifier, DefaultmapKind }; |
| 7812 | Res = ActOnOpenMPDefaultmapClause( |
| 7813 | static_cast<OpenMPDefaultmapClauseModifier>(Argument[Modifier]), |
| 7814 | static_cast<OpenMPDefaultmapClauseKind>(Argument[DefaultmapKind]), |
| 7815 | StartLoc, LParenLoc, ArgumentLoc[Modifier], |
| 7816 | ArgumentLoc[DefaultmapKind], EndLoc); |
| 7817 | break; |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 7818 | case OMPC_final: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7819 | case OMPC_num_threads: |
| 7820 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 7821 | case OMPC_simdlen: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7822 | case OMPC_collapse: |
| 7823 | case OMPC_default: |
| 7824 | case OMPC_proc_bind: |
| 7825 | case OMPC_private: |
| 7826 | case OMPC_firstprivate: |
| 7827 | case OMPC_lastprivate: |
| 7828 | case OMPC_shared: |
| 7829 | case OMPC_reduction: |
| 7830 | case OMPC_linear: |
| 7831 | case OMPC_aligned: |
| 7832 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7833 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7834 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 7835 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 7836 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 7837 | case OMPC_mergeable: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7838 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 7839 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 7840 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 7841 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 7842 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 7843 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 7844 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 7845 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 7846 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 7847 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 7848 | case OMPC_simd: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 7849 | case OMPC_map: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 7850 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7851 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 7852 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 7853 | case OMPC_grainsize: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 7854 | case OMPC_nogroup: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 7855 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 7856 | case OMPC_hint: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7857 | case OMPC_unknown: |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 7858 | case OMPC_uniform: |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 7859 | case OMPC_to: |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 7860 | case OMPC_from: |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 7861 | case OMPC_use_device_ptr: |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 7862 | case OMPC_is_device_ptr: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7863 | llvm_unreachable("Clause is not allowed."); |
| 7864 | } |
| 7865 | return Res; |
| 7866 | } |
| 7867 | |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7868 | static bool checkScheduleModifiers(Sema &S, OpenMPScheduleClauseModifier M1, |
| 7869 | OpenMPScheduleClauseModifier M2, |
| 7870 | SourceLocation M1Loc, SourceLocation M2Loc) { |
| 7871 | if (M1 == OMPC_SCHEDULE_MODIFIER_unknown && M1Loc.isValid()) { |
| 7872 | SmallVector<unsigned, 2> Excluded; |
| 7873 | if (M2 != OMPC_SCHEDULE_MODIFIER_unknown) |
| 7874 | Excluded.push_back(M2); |
| 7875 | if (M2 == OMPC_SCHEDULE_MODIFIER_nonmonotonic) |
| 7876 | Excluded.push_back(OMPC_SCHEDULE_MODIFIER_monotonic); |
| 7877 | if (M2 == OMPC_SCHEDULE_MODIFIER_monotonic) |
| 7878 | Excluded.push_back(OMPC_SCHEDULE_MODIFIER_nonmonotonic); |
| 7879 | S.Diag(M1Loc, diag::err_omp_unexpected_clause_value) |
| 7880 | << getListOfPossibleValues(OMPC_schedule, |
| 7881 | /*First=*/OMPC_SCHEDULE_MODIFIER_unknown + 1, |
| 7882 | /*Last=*/OMPC_SCHEDULE_MODIFIER_last, |
| 7883 | Excluded) |
| 7884 | << getOpenMPClauseName(OMPC_schedule); |
| 7885 | return true; |
| 7886 | } |
| 7887 | return false; |
| 7888 | } |
| 7889 | |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7890 | OMPClause *Sema::ActOnOpenMPScheduleClause( |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7891 | OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2, |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7892 | OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7893 | SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc, |
| 7894 | SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) { |
| 7895 | if (checkScheduleModifiers(*this, M1, M2, M1Loc, M2Loc) || |
| 7896 | checkScheduleModifiers(*this, M2, M1, M2Loc, M1Loc)) |
| 7897 | return nullptr; |
| 7898 | // OpenMP, 2.7.1, Loop Construct, Restrictions |
| 7899 | // Either the monotonic modifier or the nonmonotonic modifier can be specified |
| 7900 | // but not both. |
| 7901 | if ((M1 == M2 && M1 != OMPC_SCHEDULE_MODIFIER_unknown) || |
| 7902 | (M1 == OMPC_SCHEDULE_MODIFIER_monotonic && |
| 7903 | M2 == OMPC_SCHEDULE_MODIFIER_nonmonotonic) || |
| 7904 | (M1 == OMPC_SCHEDULE_MODIFIER_nonmonotonic && |
| 7905 | M2 == OMPC_SCHEDULE_MODIFIER_monotonic)) { |
| 7906 | Diag(M2Loc, diag::err_omp_unexpected_schedule_modifier) |
| 7907 | << getOpenMPSimpleClauseTypeName(OMPC_schedule, M2) |
| 7908 | << getOpenMPSimpleClauseTypeName(OMPC_schedule, M1); |
| 7909 | return nullptr; |
| 7910 | } |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7911 | if (Kind == OMPC_SCHEDULE_unknown) { |
| 7912 | std::string Values; |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7913 | if (M1Loc.isInvalid() && M2Loc.isInvalid()) { |
| 7914 | unsigned Exclude[] = {OMPC_SCHEDULE_unknown}; |
| 7915 | Values = getListOfPossibleValues(OMPC_schedule, /*First=*/0, |
| 7916 | /*Last=*/OMPC_SCHEDULE_MODIFIER_last, |
| 7917 | Exclude); |
| 7918 | } else { |
| 7919 | Values = getListOfPossibleValues(OMPC_schedule, /*First=*/0, |
| 7920 | /*Last=*/OMPC_SCHEDULE_unknown); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7921 | } |
| 7922 | Diag(KindLoc, diag::err_omp_unexpected_clause_value) |
| 7923 | << Values << getOpenMPClauseName(OMPC_schedule); |
| 7924 | return nullptr; |
| 7925 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7926 | // OpenMP, 2.7.1, Loop Construct, Restrictions |
| 7927 | // The nonmonotonic modifier can only be specified with schedule(dynamic) or |
| 7928 | // schedule(guided). |
| 7929 | if ((M1 == OMPC_SCHEDULE_MODIFIER_nonmonotonic || |
| 7930 | M2 == OMPC_SCHEDULE_MODIFIER_nonmonotonic) && |
| 7931 | Kind != OMPC_SCHEDULE_dynamic && Kind != OMPC_SCHEDULE_guided) { |
| 7932 | Diag(M1 == OMPC_SCHEDULE_MODIFIER_nonmonotonic ? M1Loc : M2Loc, |
| 7933 | diag::err_omp_schedule_nonmonotonic_static); |
| 7934 | return nullptr; |
| 7935 | } |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7936 | Expr *ValExpr = ChunkSize; |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 7937 | Stmt *HelperValStmt = nullptr; |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7938 | if (ChunkSize) { |
| 7939 | if (!ChunkSize->isValueDependent() && !ChunkSize->isTypeDependent() && |
| 7940 | !ChunkSize->isInstantiationDependent() && |
| 7941 | !ChunkSize->containsUnexpandedParameterPack()) { |
| 7942 | SourceLocation ChunkSizeLoc = ChunkSize->getLocStart(); |
| 7943 | ExprResult Val = |
| 7944 | PerformOpenMPImplicitIntegerConversion(ChunkSizeLoc, ChunkSize); |
| 7945 | if (Val.isInvalid()) |
| 7946 | return nullptr; |
| 7947 | |
| 7948 | ValExpr = Val.get(); |
| 7949 | |
| 7950 | // OpenMP [2.7.1, Restrictions] |
| 7951 | // chunk_size must be a loop invariant integer expression with a positive |
| 7952 | // value. |
| 7953 | llvm::APSInt Result; |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 7954 | if (ValExpr->isIntegerConstantExpr(Result, Context)) { |
| 7955 | if (Result.isSigned() && !Result.isStrictlyPositive()) { |
| 7956 | Diag(ChunkSizeLoc, diag::err_omp_negative_expression_in_clause) |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 7957 | << "schedule" << 1 << ChunkSize->getSourceRange(); |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 7958 | return nullptr; |
| 7959 | } |
Alexey Bataev | b46cdea | 2016-06-15 11:20:48 +0000 | [diff] [blame] | 7960 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective()) && |
| 7961 | !CurContext->isDependentContext()) { |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 7962 | llvm::MapVector<Expr *, DeclRefExpr *> Captures; |
| 7963 | ValExpr = tryBuildCapture(*this, ValExpr, Captures).get(); |
| 7964 | HelperValStmt = buildPreInits(Context, Captures); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7965 | } |
| 7966 | } |
| 7967 | } |
| 7968 | |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7969 | return new (Context) |
| 7970 | OMPScheduleClause(StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc, Kind, |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 7971 | ValExpr, HelperValStmt, M1, M1Loc, M2, M2Loc); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7972 | } |
| 7973 | |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7974 | OMPClause *Sema::ActOnOpenMPClause(OpenMPClauseKind Kind, |
| 7975 | SourceLocation StartLoc, |
| 7976 | SourceLocation EndLoc) { |
| 7977 | OMPClause *Res = nullptr; |
| 7978 | switch (Kind) { |
| 7979 | case OMPC_ordered: |
| 7980 | Res = ActOnOpenMPOrderedClause(StartLoc, EndLoc); |
| 7981 | break; |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 7982 | case OMPC_nowait: |
| 7983 | Res = ActOnOpenMPNowaitClause(StartLoc, EndLoc); |
| 7984 | break; |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 7985 | case OMPC_untied: |
| 7986 | Res = ActOnOpenMPUntiedClause(StartLoc, EndLoc); |
| 7987 | break; |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 7988 | case OMPC_mergeable: |
| 7989 | Res = ActOnOpenMPMergeableClause(StartLoc, EndLoc); |
| 7990 | break; |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 7991 | case OMPC_read: |
| 7992 | Res = ActOnOpenMPReadClause(StartLoc, EndLoc); |
| 7993 | break; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 7994 | case OMPC_write: |
| 7995 | Res = ActOnOpenMPWriteClause(StartLoc, EndLoc); |
| 7996 | break; |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 7997 | case OMPC_update: |
| 7998 | Res = ActOnOpenMPUpdateClause(StartLoc, EndLoc); |
| 7999 | break; |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 8000 | case OMPC_capture: |
| 8001 | Res = ActOnOpenMPCaptureClause(StartLoc, EndLoc); |
| 8002 | break; |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 8003 | case OMPC_seq_cst: |
| 8004 | Res = ActOnOpenMPSeqCstClause(StartLoc, EndLoc); |
| 8005 | break; |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 8006 | case OMPC_threads: |
| 8007 | Res = ActOnOpenMPThreadsClause(StartLoc, EndLoc); |
| 8008 | break; |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 8009 | case OMPC_simd: |
| 8010 | Res = ActOnOpenMPSIMDClause(StartLoc, EndLoc); |
| 8011 | break; |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 8012 | case OMPC_nogroup: |
| 8013 | Res = ActOnOpenMPNogroupClause(StartLoc, EndLoc); |
| 8014 | break; |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 8015 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 8016 | case OMPC_final: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 8017 | case OMPC_num_threads: |
| 8018 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 8019 | case OMPC_simdlen: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 8020 | case OMPC_collapse: |
| 8021 | case OMPC_schedule: |
| 8022 | case OMPC_private: |
| 8023 | case OMPC_firstprivate: |
| 8024 | case OMPC_lastprivate: |
| 8025 | case OMPC_shared: |
| 8026 | case OMPC_reduction: |
| 8027 | case OMPC_linear: |
| 8028 | case OMPC_aligned: |
| 8029 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8030 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 8031 | case OMPC_default: |
| 8032 | case OMPC_proc_bind: |
| 8033 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 8034 | case OMPC_flush: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8035 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 8036 | case OMPC_device: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 8037 | case OMPC_map: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 8038 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 8039 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 8040 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 8041 | case OMPC_grainsize: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 8042 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 8043 | case OMPC_hint: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 8044 | case OMPC_dist_schedule: |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 8045 | case OMPC_defaultmap: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 8046 | case OMPC_unknown: |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 8047 | case OMPC_uniform: |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 8048 | case OMPC_to: |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 8049 | case OMPC_from: |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 8050 | case OMPC_use_device_ptr: |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 8051 | case OMPC_is_device_ptr: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 8052 | llvm_unreachable("Clause is not allowed."); |
| 8053 | } |
| 8054 | return Res; |
| 8055 | } |
| 8056 | |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 8057 | OMPClause *Sema::ActOnOpenMPNowaitClause(SourceLocation StartLoc, |
| 8058 | SourceLocation EndLoc) { |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 8059 | DSAStack->setNowaitRegion(); |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 8060 | return new (Context) OMPNowaitClause(StartLoc, EndLoc); |
| 8061 | } |
| 8062 | |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 8063 | OMPClause *Sema::ActOnOpenMPUntiedClause(SourceLocation StartLoc, |
| 8064 | SourceLocation EndLoc) { |
| 8065 | return new (Context) OMPUntiedClause(StartLoc, EndLoc); |
| 8066 | } |
| 8067 | |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 8068 | OMPClause *Sema::ActOnOpenMPMergeableClause(SourceLocation StartLoc, |
| 8069 | SourceLocation EndLoc) { |
| 8070 | return new (Context) OMPMergeableClause(StartLoc, EndLoc); |
| 8071 | } |
| 8072 | |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 8073 | OMPClause *Sema::ActOnOpenMPReadClause(SourceLocation StartLoc, |
| 8074 | SourceLocation EndLoc) { |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 8075 | return new (Context) OMPReadClause(StartLoc, EndLoc); |
| 8076 | } |
| 8077 | |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 8078 | OMPClause *Sema::ActOnOpenMPWriteClause(SourceLocation StartLoc, |
| 8079 | SourceLocation EndLoc) { |
| 8080 | return new (Context) OMPWriteClause(StartLoc, EndLoc); |
| 8081 | } |
| 8082 | |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 8083 | OMPClause *Sema::ActOnOpenMPUpdateClause(SourceLocation StartLoc, |
| 8084 | SourceLocation EndLoc) { |
| 8085 | return new (Context) OMPUpdateClause(StartLoc, EndLoc); |
| 8086 | } |
| 8087 | |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 8088 | OMPClause *Sema::ActOnOpenMPCaptureClause(SourceLocation StartLoc, |
| 8089 | SourceLocation EndLoc) { |
| 8090 | return new (Context) OMPCaptureClause(StartLoc, EndLoc); |
| 8091 | } |
| 8092 | |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 8093 | OMPClause *Sema::ActOnOpenMPSeqCstClause(SourceLocation StartLoc, |
| 8094 | SourceLocation EndLoc) { |
| 8095 | return new (Context) OMPSeqCstClause(StartLoc, EndLoc); |
| 8096 | } |
| 8097 | |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 8098 | OMPClause *Sema::ActOnOpenMPThreadsClause(SourceLocation StartLoc, |
| 8099 | SourceLocation EndLoc) { |
| 8100 | return new (Context) OMPThreadsClause(StartLoc, EndLoc); |
| 8101 | } |
| 8102 | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 8103 | OMPClause *Sema::ActOnOpenMPSIMDClause(SourceLocation StartLoc, |
| 8104 | SourceLocation EndLoc) { |
| 8105 | return new (Context) OMPSIMDClause(StartLoc, EndLoc); |
| 8106 | } |
| 8107 | |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 8108 | OMPClause *Sema::ActOnOpenMPNogroupClause(SourceLocation StartLoc, |
| 8109 | SourceLocation EndLoc) { |
| 8110 | return new (Context) OMPNogroupClause(StartLoc, EndLoc); |
| 8111 | } |
| 8112 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8113 | OMPClause *Sema::ActOnOpenMPVarListClause( |
| 8114 | OpenMPClauseKind Kind, ArrayRef<Expr *> VarList, Expr *TailExpr, |
| 8115 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, |
| 8116 | SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8117 | const DeclarationNameInfo &ReductionId, OpenMPDependClauseKind DepKind, |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 8118 | OpenMPLinearClauseKind LinKind, OpenMPMapClauseKind MapTypeModifier, |
| 8119 | OpenMPMapClauseKind MapType, bool IsMapTypeImplicit, |
| 8120 | SourceLocation DepLinMapLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 8121 | OMPClause *Res = nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8122 | switch (Kind) { |
| 8123 | case OMPC_private: |
| 8124 | Res = ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 8125 | break; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8126 | case OMPC_firstprivate: |
| 8127 | Res = ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 8128 | break; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8129 | case OMPC_lastprivate: |
| 8130 | Res = ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 8131 | break; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8132 | case OMPC_shared: |
| 8133 | Res = ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 8134 | break; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8135 | case OMPC_reduction: |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 8136 | Res = ActOnOpenMPReductionClause(VarList, StartLoc, LParenLoc, ColonLoc, |
| 8137 | EndLoc, ReductionIdScopeSpec, ReductionId); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8138 | break; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8139 | case OMPC_linear: |
| 8140 | Res = ActOnOpenMPLinearClause(VarList, TailExpr, StartLoc, LParenLoc, |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 8141 | LinKind, DepLinMapLoc, ColonLoc, EndLoc); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8142 | break; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 8143 | case OMPC_aligned: |
| 8144 | Res = ActOnOpenMPAlignedClause(VarList, TailExpr, StartLoc, LParenLoc, |
| 8145 | ColonLoc, EndLoc); |
| 8146 | break; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8147 | case OMPC_copyin: |
| 8148 | Res = ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 8149 | break; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8150 | case OMPC_copyprivate: |
| 8151 | Res = ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 8152 | break; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 8153 | case OMPC_flush: |
| 8154 | Res = ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 8155 | break; |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8156 | case OMPC_depend: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 8157 | Res = ActOnOpenMPDependClause(DepKind, DepLinMapLoc, ColonLoc, VarList, |
| 8158 | StartLoc, LParenLoc, EndLoc); |
| 8159 | break; |
| 8160 | case OMPC_map: |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 8161 | Res = ActOnOpenMPMapClause(MapTypeModifier, MapType, IsMapTypeImplicit, |
| 8162 | DepLinMapLoc, ColonLoc, VarList, StartLoc, |
| 8163 | LParenLoc, EndLoc); |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8164 | break; |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 8165 | case OMPC_to: |
| 8166 | Res = ActOnOpenMPToClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 8167 | break; |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 8168 | case OMPC_from: |
| 8169 | Res = ActOnOpenMPFromClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 8170 | break; |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 8171 | case OMPC_use_device_ptr: |
| 8172 | Res = ActOnOpenMPUseDevicePtrClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 8173 | break; |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 8174 | case OMPC_is_device_ptr: |
| 8175 | Res = ActOnOpenMPIsDevicePtrClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 8176 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 8177 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 8178 | case OMPC_final: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 8179 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 8180 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 8181 | case OMPC_simdlen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 8182 | case OMPC_collapse: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8183 | case OMPC_default: |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 8184 | case OMPC_proc_bind: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 8185 | case OMPC_schedule: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 8186 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 8187 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 8188 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 8189 | case OMPC_mergeable: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8190 | case OMPC_threadprivate: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 8191 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 8192 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 8193 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 8194 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 8195 | case OMPC_seq_cst: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 8196 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 8197 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 8198 | case OMPC_simd: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 8199 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 8200 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 8201 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 8202 | case OMPC_grainsize: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 8203 | case OMPC_nogroup: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 8204 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 8205 | case OMPC_hint: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 8206 | case OMPC_dist_schedule: |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 8207 | case OMPC_defaultmap: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8208 | case OMPC_unknown: |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 8209 | case OMPC_uniform: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8210 | llvm_unreachable("Clause is not allowed."); |
| 8211 | } |
| 8212 | return Res; |
| 8213 | } |
| 8214 | |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 8215 | ExprResult Sema::getOpenMPCapturedExpr(VarDecl *Capture, ExprValueKind VK, |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 8216 | ExprObjectKind OK, SourceLocation Loc) { |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 8217 | ExprResult Res = BuildDeclRefExpr( |
| 8218 | Capture, Capture->getType().getNonReferenceType(), VK_LValue, Loc); |
| 8219 | if (!Res.isUsable()) |
| 8220 | return ExprError(); |
| 8221 | if (OK == OK_Ordinary && !getLangOpts().CPlusPlus) { |
| 8222 | Res = CreateBuiltinUnaryOp(Loc, UO_Deref, Res.get()); |
| 8223 | if (!Res.isUsable()) |
| 8224 | return ExprError(); |
| 8225 | } |
| 8226 | if (VK != VK_LValue && Res.get()->isGLValue()) { |
| 8227 | Res = DefaultLvalueConversion(Res.get()); |
| 8228 | if (!Res.isUsable()) |
| 8229 | return ExprError(); |
| 8230 | } |
| 8231 | return Res; |
| 8232 | } |
| 8233 | |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8234 | static std::pair<ValueDecl *, bool> |
| 8235 | getPrivateItem(Sema &S, Expr *&RefExpr, SourceLocation &ELoc, |
| 8236 | SourceRange &ERange, bool AllowArraySection = false) { |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8237 | if (RefExpr->isTypeDependent() || RefExpr->isValueDependent() || |
| 8238 | RefExpr->containsUnexpandedParameterPack()) |
| 8239 | return std::make_pair(nullptr, true); |
| 8240 | |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8241 | // OpenMP [3.1, C/C++] |
| 8242 | // A list item is a variable name. |
| 8243 | // OpenMP [2.9.3.3, Restrictions, p.1] |
| 8244 | // A variable that is part of another variable (as an array or |
| 8245 | // structure element) cannot appear in a private clause. |
| 8246 | RefExpr = RefExpr->IgnoreParens(); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8247 | enum { |
| 8248 | NoArrayExpr = -1, |
| 8249 | ArraySubscript = 0, |
| 8250 | OMPArraySection = 1 |
| 8251 | } IsArrayExpr = NoArrayExpr; |
| 8252 | if (AllowArraySection) { |
| 8253 | if (auto *ASE = dyn_cast_or_null<ArraySubscriptExpr>(RefExpr)) { |
| 8254 | auto *Base = ASE->getBase()->IgnoreParenImpCasts(); |
| 8255 | while (auto *TempASE = dyn_cast<ArraySubscriptExpr>(Base)) |
| 8256 | Base = TempASE->getBase()->IgnoreParenImpCasts(); |
| 8257 | RefExpr = Base; |
| 8258 | IsArrayExpr = ArraySubscript; |
| 8259 | } else if (auto *OASE = dyn_cast_or_null<OMPArraySectionExpr>(RefExpr)) { |
| 8260 | auto *Base = OASE->getBase()->IgnoreParenImpCasts(); |
| 8261 | while (auto *TempOASE = dyn_cast<OMPArraySectionExpr>(Base)) |
| 8262 | Base = TempOASE->getBase()->IgnoreParenImpCasts(); |
| 8263 | while (auto *TempASE = dyn_cast<ArraySubscriptExpr>(Base)) |
| 8264 | Base = TempASE->getBase()->IgnoreParenImpCasts(); |
| 8265 | RefExpr = Base; |
| 8266 | IsArrayExpr = OMPArraySection; |
| 8267 | } |
| 8268 | } |
| 8269 | ELoc = RefExpr->getExprLoc(); |
| 8270 | ERange = RefExpr->getSourceRange(); |
| 8271 | RefExpr = RefExpr->IgnoreParenImpCasts(); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8272 | auto *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr); |
| 8273 | auto *ME = dyn_cast_or_null<MemberExpr>(RefExpr); |
| 8274 | if ((!DE || !isa<VarDecl>(DE->getDecl())) && |
| 8275 | (S.getCurrentThisType().isNull() || !ME || |
| 8276 | !isa<CXXThisExpr>(ME->getBase()->IgnoreParenImpCasts()) || |
| 8277 | !isa<FieldDecl>(ME->getMemberDecl()))) { |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8278 | if (IsArrayExpr != NoArrayExpr) |
| 8279 | S.Diag(ELoc, diag::err_omp_expected_base_var_name) << IsArrayExpr |
| 8280 | << ERange; |
| 8281 | else { |
| 8282 | S.Diag(ELoc, |
| 8283 | AllowArraySection |
| 8284 | ? diag::err_omp_expected_var_name_member_expr_or_array_item |
| 8285 | : diag::err_omp_expected_var_name_member_expr) |
| 8286 | << (S.getCurrentThisType().isNull() ? 0 : 1) << ERange; |
| 8287 | } |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8288 | return std::make_pair(nullptr, false); |
| 8289 | } |
| 8290 | return std::make_pair(DE ? DE->getDecl() : ME->getMemberDecl(), false); |
| 8291 | } |
| 8292 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8293 | OMPClause *Sema::ActOnOpenMPPrivateClause(ArrayRef<Expr *> VarList, |
| 8294 | SourceLocation StartLoc, |
| 8295 | SourceLocation LParenLoc, |
| 8296 | SourceLocation EndLoc) { |
| 8297 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 8298 | SmallVector<Expr *, 8> PrivateCopies; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8299 | for (auto &RefExpr : VarList) { |
| 8300 | assert(RefExpr && "NULL expr in OpenMP private clause."); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8301 | SourceLocation ELoc; |
| 8302 | SourceRange ERange; |
| 8303 | Expr *SimpleRefExpr = RefExpr; |
| 8304 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8305 | if (Res.second) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8306 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8307 | Vars.push_back(RefExpr); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 8308 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8309 | } |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8310 | ValueDecl *D = Res.first; |
| 8311 | if (!D) |
| 8312 | continue; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8313 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8314 | QualType Type = D->getType(); |
| 8315 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8316 | |
| 8317 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 8318 | // A variable that appears in a private clause must not have an incomplete |
| 8319 | // type or a reference type. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8320 | if (RequireCompleteType(ELoc, Type, diag::err_omp_private_incomplete_type)) |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8321 | continue; |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8322 | Type = Type.getNonReferenceType(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8323 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8324 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 8325 | // in a Construct] |
| 8326 | // Variables with the predetermined data-sharing attributes may not be |
| 8327 | // listed in data-sharing attributes clauses, except for the cases |
| 8328 | // listed below. For these exceptions only, listing a predetermined |
| 8329 | // variable in a data-sharing attribute clause is allowed and overrides |
| 8330 | // the variable's predetermined data-sharing attributes. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8331 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8332 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_private) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8333 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 8334 | << getOpenMPClauseName(OMPC_private); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8335 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8336 | continue; |
| 8337 | } |
| 8338 | |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8339 | // Variably modified types are not supported for tasks. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 8340 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType() && |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 8341 | isOpenMPTaskingDirective(DSAStack->getCurrentDirective())) { |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8342 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
| 8343 | << getOpenMPClauseName(OMPC_private) << Type |
| 8344 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 8345 | bool IsDecl = |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8346 | !VD || |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8347 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8348 | Diag(D->getLocation(), |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8349 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8350 | << D; |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8351 | continue; |
| 8352 | } |
| 8353 | |
Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 8354 | // OpenMP 4.5 [2.15.5.1, Restrictions, p.3] |
| 8355 | // A list item cannot appear in both a map clause and a data-sharing |
| 8356 | // attribute clause on the same construct |
| 8357 | if (DSAStack->getCurrentDirective() == OMPD_target) { |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 8358 | if (DSAStack->checkMappableExprComponentListsForDecl( |
| 8359 | VD, /* CurrentRegionOnly = */ true, |
| 8360 | [&](OMPClauseMappableExprCommon::MappableExprComponentListRef) |
| 8361 | -> bool { return true; })) { |
Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 8362 | Diag(ELoc, diag::err_omp_variable_in_map_and_dsa) |
| 8363 | << getOpenMPClauseName(OMPC_private) |
| 8364 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 8365 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
| 8366 | continue; |
| 8367 | } |
| 8368 | } |
| 8369 | |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8370 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.1] |
| 8371 | // A variable of class type (or array thereof) that appears in a private |
| 8372 | // clause requires an accessible, unambiguous default constructor for the |
| 8373 | // class type. |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 8374 | // Generate helper private variable and initialize it with the default |
| 8375 | // value. The address of the original variable is replaced by the address of |
| 8376 | // the new private variable in CodeGen. This new variable is not added to |
| 8377 | // IdResolver, so the code in the OpenMP region uses original variable for |
| 8378 | // proper diagnostics. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8379 | Type = Type.getUnqualifiedType(); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8380 | auto VDPrivate = buildVarDecl(*this, ELoc, Type, D->getName(), |
| 8381 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 8382 | ActOnUninitializedDecl(VDPrivate, /*TypeMayContainAuto=*/false); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 8383 | if (VDPrivate->isInvalidDecl()) |
| 8384 | continue; |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8385 | auto VDPrivateRefExpr = buildDeclRefExpr( |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8386 | *this, VDPrivate, RefExpr->getType().getUnqualifiedType(), ELoc); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 8387 | |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 8388 | DeclRefExpr *Ref = nullptr; |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 8389 | if (!VD && !CurContext->isDependentContext()) |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 8390 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false); |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 8391 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_private, Ref); |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 8392 | Vars.push_back((VD || CurContext->isDependentContext()) |
| 8393 | ? RefExpr->IgnoreParens() |
| 8394 | : Ref); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 8395 | PrivateCopies.push_back(VDPrivateRefExpr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8396 | } |
| 8397 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8398 | if (Vars.empty()) |
| 8399 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8400 | |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 8401 | return OMPPrivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
| 8402 | PrivateCopies); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8403 | } |
| 8404 | |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 8405 | namespace { |
| 8406 | class DiagsUninitializedSeveretyRAII { |
| 8407 | private: |
| 8408 | DiagnosticsEngine &Diags; |
| 8409 | SourceLocation SavedLoc; |
| 8410 | bool IsIgnored; |
| 8411 | |
| 8412 | public: |
| 8413 | DiagsUninitializedSeveretyRAII(DiagnosticsEngine &Diags, SourceLocation Loc, |
| 8414 | bool IsIgnored) |
| 8415 | : Diags(Diags), SavedLoc(Loc), IsIgnored(IsIgnored) { |
| 8416 | if (!IsIgnored) { |
| 8417 | Diags.setSeverity(/*Diag*/ diag::warn_uninit_self_reference_in_init, |
| 8418 | /*Map*/ diag::Severity::Ignored, Loc); |
| 8419 | } |
| 8420 | } |
| 8421 | ~DiagsUninitializedSeveretyRAII() { |
| 8422 | if (!IsIgnored) |
| 8423 | Diags.popMappings(SavedLoc); |
| 8424 | } |
| 8425 | }; |
Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 8426 | } |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 8427 | |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8428 | OMPClause *Sema::ActOnOpenMPFirstprivateClause(ArrayRef<Expr *> VarList, |
| 8429 | SourceLocation StartLoc, |
| 8430 | SourceLocation LParenLoc, |
| 8431 | SourceLocation EndLoc) { |
| 8432 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 8433 | SmallVector<Expr *, 8> PrivateCopies; |
| 8434 | SmallVector<Expr *, 8> Inits; |
Alexey Bataev | 417089f | 2016-02-17 13:19:37 +0000 | [diff] [blame] | 8435 | SmallVector<Decl *, 4> ExprCaptures; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 8436 | bool IsImplicitClause = |
| 8437 | StartLoc.isInvalid() && LParenLoc.isInvalid() && EndLoc.isInvalid(); |
| 8438 | auto ImplicitClauseLoc = DSAStack->getConstructLoc(); |
| 8439 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8440 | for (auto &RefExpr : VarList) { |
| 8441 | assert(RefExpr && "NULL expr in OpenMP firstprivate clause."); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8442 | SourceLocation ELoc; |
| 8443 | SourceRange ERange; |
| 8444 | Expr *SimpleRefExpr = RefExpr; |
| 8445 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8446 | if (Res.second) { |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8447 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8448 | Vars.push_back(RefExpr); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 8449 | PrivateCopies.push_back(nullptr); |
| 8450 | Inits.push_back(nullptr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8451 | } |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8452 | ValueDecl *D = Res.first; |
| 8453 | if (!D) |
| 8454 | continue; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8455 | |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8456 | ELoc = IsImplicitClause ? ImplicitClauseLoc : ELoc; |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8457 | QualType Type = D->getType(); |
| 8458 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8459 | |
| 8460 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 8461 | // A variable that appears in a private clause must not have an incomplete |
| 8462 | // type or a reference type. |
| 8463 | if (RequireCompleteType(ELoc, Type, |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8464 | diag::err_omp_firstprivate_incomplete_type)) |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8465 | continue; |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8466 | Type = Type.getNonReferenceType(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8467 | |
| 8468 | // OpenMP [2.9.3.4, Restrictions, C/C++, p.1] |
| 8469 | // 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] | 8470 | // clause requires an accessible, unambiguous copy constructor for the |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8471 | // class type. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8472 | auto ElemType = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8473 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 8474 | // If an implicit firstprivate variable found it was checked already. |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8475 | DSAStackTy::DSAVarData TopDVar; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 8476 | if (!IsImplicitClause) { |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8477 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8478 | TopDVar = DVar; |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8479 | bool IsConstant = ElemType.isConstant(Context); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8480 | // OpenMP [2.4.13, Data-sharing Attribute Clauses] |
| 8481 | // A list item that specifies a given variable may not appear in more |
| 8482 | // than one clause on the same directive, except that a variable may be |
| 8483 | // specified in both firstprivate and lastprivate clauses. |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8484 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_firstprivate && |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 8485 | DVar.CKind != OMPC_lastprivate && DVar.RefExpr) { |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8486 | Diag(ELoc, diag::err_omp_wrong_dsa) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8487 | << getOpenMPClauseName(DVar.CKind) |
| 8488 | << getOpenMPClauseName(OMPC_firstprivate); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8489 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8490 | continue; |
| 8491 | } |
| 8492 | |
| 8493 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 8494 | // in a Construct] |
| 8495 | // Variables with the predetermined data-sharing attributes may not be |
| 8496 | // listed in data-sharing attributes clauses, except for the cases |
| 8497 | // listed below. For these exceptions only, listing a predetermined |
| 8498 | // variable in a data-sharing attribute clause is allowed and overrides |
| 8499 | // the variable's predetermined data-sharing attributes. |
| 8500 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 8501 | // in a Construct, C/C++, p.2] |
| 8502 | // Variables with const-qualified type having no mutable member may be |
| 8503 | // listed in a firstprivate clause, even if they are static data members. |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8504 | if (!(IsConstant || (VD && VD->isStaticDataMember())) && !DVar.RefExpr && |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8505 | DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared) { |
| 8506 | Diag(ELoc, diag::err_omp_wrong_dsa) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8507 | << getOpenMPClauseName(DVar.CKind) |
| 8508 | << getOpenMPClauseName(OMPC_firstprivate); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8509 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8510 | continue; |
| 8511 | } |
| 8512 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 8513 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8514 | // OpenMP [2.9.3.4, Restrictions, p.2] |
| 8515 | // A list item that is private within a parallel region must not appear |
| 8516 | // in a firstprivate clause on a worksharing construct if any of the |
| 8517 | // worksharing regions arising from the worksharing construct ever bind |
| 8518 | // to any of the parallel regions arising from the parallel construct. |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 8519 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 8520 | !isOpenMPParallelDirective(CurrDir)) { |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8521 | DVar = DSAStack->getImplicitDSA(D, true); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 8522 | if (DVar.CKind != OMPC_shared && |
| 8523 | (isOpenMPParallelDirective(DVar.DKind) || |
| 8524 | DVar.DKind == OMPD_unknown)) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 8525 | Diag(ELoc, diag::err_omp_required_access) |
| 8526 | << getOpenMPClauseName(OMPC_firstprivate) |
| 8527 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8528 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 8529 | continue; |
| 8530 | } |
| 8531 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8532 | // OpenMP [2.9.3.4, Restrictions, p.3] |
| 8533 | // A list item that appears in a reduction clause of a parallel construct |
| 8534 | // must not appear in a firstprivate clause on a worksharing or task |
| 8535 | // construct if any of the worksharing or task regions arising from the |
| 8536 | // worksharing or task construct ever bind to any of the parallel regions |
| 8537 | // arising from the parallel construct. |
| 8538 | // OpenMP [2.9.3.4, Restrictions, p.4] |
| 8539 | // A list item that appears in a reduction clause in worksharing |
| 8540 | // construct must not appear in a firstprivate clause in a task construct |
| 8541 | // encountered during execution of any of the worksharing regions arising |
| 8542 | // from the worksharing construct. |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 8543 | if (isOpenMPTaskingDirective(CurrDir)) { |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 8544 | DVar = DSAStack->hasInnermostDSA( |
| 8545 | D, [](OpenMPClauseKind C) -> bool { return C == OMPC_reduction; }, |
| 8546 | [](OpenMPDirectiveKind K) -> bool { |
| 8547 | return isOpenMPParallelDirective(K) || |
| 8548 | isOpenMPWorksharingDirective(K); |
| 8549 | }, |
| 8550 | false); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 8551 | if (DVar.CKind == OMPC_reduction && |
| 8552 | (isOpenMPParallelDirective(DVar.DKind) || |
| 8553 | isOpenMPWorksharingDirective(DVar.DKind))) { |
| 8554 | Diag(ELoc, diag::err_omp_parallel_reduction_in_task_firstprivate) |
| 8555 | << getOpenMPDirectiveName(DVar.DKind); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8556 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 8557 | continue; |
| 8558 | } |
| 8559 | } |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 8560 | |
| 8561 | // OpenMP 4.5 [2.15.3.4, Restrictions, p.3] |
| 8562 | // A list item that is private within a teams region must not appear in a |
| 8563 | // firstprivate clause on a distribute construct if any of the distribute |
| 8564 | // regions arising from the distribute construct ever bind to any of the |
| 8565 | // teams regions arising from the teams construct. |
| 8566 | // OpenMP 4.5 [2.15.3.4, Restrictions, p.3] |
| 8567 | // A list item that appears in a reduction clause of a teams construct |
| 8568 | // must not appear in a firstprivate clause on a distribute construct if |
| 8569 | // any of the distribute regions arising from the distribute construct |
| 8570 | // ever bind to any of the teams regions arising from the teams construct. |
| 8571 | // OpenMP 4.5 [2.10.8, Distribute Construct, p.3] |
| 8572 | // A list item may appear in a firstprivate or lastprivate clause but not |
| 8573 | // both. |
| 8574 | if (CurrDir == OMPD_distribute) { |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 8575 | DVar = DSAStack->hasInnermostDSA( |
| 8576 | D, [](OpenMPClauseKind C) -> bool { return C == OMPC_private; }, |
| 8577 | [](OpenMPDirectiveKind K) -> bool { |
| 8578 | return isOpenMPTeamsDirective(K); |
| 8579 | }, |
| 8580 | false); |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 8581 | if (DVar.CKind == OMPC_private && isOpenMPTeamsDirective(DVar.DKind)) { |
| 8582 | Diag(ELoc, diag::err_omp_firstprivate_distribute_private_teams); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8583 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 8584 | continue; |
| 8585 | } |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 8586 | DVar = DSAStack->hasInnermostDSA( |
| 8587 | D, [](OpenMPClauseKind C) -> bool { return C == OMPC_reduction; }, |
| 8588 | [](OpenMPDirectiveKind K) -> bool { |
| 8589 | return isOpenMPTeamsDirective(K); |
| 8590 | }, |
| 8591 | false); |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 8592 | if (DVar.CKind == OMPC_reduction && |
| 8593 | isOpenMPTeamsDirective(DVar.DKind)) { |
| 8594 | Diag(ELoc, diag::err_omp_firstprivate_distribute_in_teams_reduction); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8595 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 8596 | continue; |
| 8597 | } |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8598 | DVar = DSAStack->getTopDSA(D, false); |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 8599 | if (DVar.CKind == OMPC_lastprivate) { |
| 8600 | Diag(ELoc, diag::err_omp_firstprivate_and_lastprivate_in_distribute); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8601 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 8602 | continue; |
| 8603 | } |
| 8604 | } |
Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 8605 | // OpenMP 4.5 [2.15.5.1, Restrictions, p.3] |
| 8606 | // A list item cannot appear in both a map clause and a data-sharing |
| 8607 | // attribute clause on the same construct |
| 8608 | if (CurrDir == OMPD_target) { |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 8609 | if (DSAStack->checkMappableExprComponentListsForDecl( |
| 8610 | VD, /* CurrentRegionOnly = */ true, |
| 8611 | [&](OMPClauseMappableExprCommon::MappableExprComponentListRef) |
| 8612 | -> bool { return true; })) { |
Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 8613 | Diag(ELoc, diag::err_omp_variable_in_map_and_dsa) |
| 8614 | << getOpenMPClauseName(OMPC_firstprivate) |
| 8615 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 8616 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
| 8617 | continue; |
| 8618 | } |
| 8619 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8620 | } |
| 8621 | |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8622 | // Variably modified types are not supported for tasks. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 8623 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType() && |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 8624 | isOpenMPTaskingDirective(DSAStack->getCurrentDirective())) { |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8625 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
| 8626 | << getOpenMPClauseName(OMPC_firstprivate) << Type |
| 8627 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 8628 | bool IsDecl = |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8629 | !VD || |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8630 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8631 | Diag(D->getLocation(), |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8632 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8633 | << D; |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8634 | continue; |
| 8635 | } |
| 8636 | |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8637 | Type = Type.getUnqualifiedType(); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8638 | auto VDPrivate = buildVarDecl(*this, ELoc, Type, D->getName(), |
| 8639 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 8640 | // Generate helper private variable and initialize it with the value of the |
| 8641 | // original variable. The address of the original variable is replaced by |
| 8642 | // the address of the new private variable in the CodeGen. This new variable |
| 8643 | // is not added to IdResolver, so the code in the OpenMP region uses |
| 8644 | // original variable for proper diagnostics and variable capturing. |
| 8645 | Expr *VDInitRefExpr = nullptr; |
| 8646 | // For arrays generate initializer for single element and replace it by the |
| 8647 | // original array element in CodeGen. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8648 | if (Type->isArrayType()) { |
| 8649 | auto VDInit = |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8650 | buildVarDecl(*this, RefExpr->getExprLoc(), ElemType, D->getName()); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8651 | VDInitRefExpr = buildDeclRefExpr(*this, VDInit, ElemType, ELoc); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 8652 | auto Init = DefaultLvalueConversion(VDInitRefExpr).get(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8653 | ElemType = ElemType.getUnqualifiedType(); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8654 | auto *VDInitTemp = buildVarDecl(*this, RefExpr->getExprLoc(), ElemType, |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8655 | ".firstprivate.temp"); |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 8656 | InitializedEntity Entity = |
| 8657 | InitializedEntity::InitializeVariable(VDInitTemp); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 8658 | InitializationKind Kind = InitializationKind::CreateCopy(ELoc, ELoc); |
| 8659 | |
| 8660 | InitializationSequence InitSeq(*this, Entity, Kind, Init); |
| 8661 | ExprResult Result = InitSeq.Perform(*this, Entity, Kind, Init); |
| 8662 | if (Result.isInvalid()) |
| 8663 | VDPrivate->setInvalidDecl(); |
| 8664 | else |
| 8665 | VDPrivate->setInit(Result.getAs<Expr>()); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8666 | // Remove temp variable declaration. |
| 8667 | Context.Deallocate(VDInitTemp); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 8668 | } else { |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8669 | auto *VDInit = buildVarDecl(*this, RefExpr->getExprLoc(), Type, |
| 8670 | ".firstprivate.temp"); |
| 8671 | VDInitRefExpr = buildDeclRefExpr(*this, VDInit, RefExpr->getType(), |
| 8672 | RefExpr->getExprLoc()); |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 8673 | AddInitializerToDecl(VDPrivate, |
| 8674 | DefaultLvalueConversion(VDInitRefExpr).get(), |
| 8675 | /*DirectInit=*/false, /*TypeMayContainAuto=*/false); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 8676 | } |
| 8677 | if (VDPrivate->isInvalidDecl()) { |
| 8678 | if (IsImplicitClause) { |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8679 | Diag(RefExpr->getExprLoc(), |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 8680 | diag::note_omp_task_predetermined_firstprivate_here); |
| 8681 | } |
| 8682 | continue; |
| 8683 | } |
| 8684 | CurContext->addDecl(VDPrivate); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 8685 | auto VDPrivateRefExpr = buildDeclRefExpr( |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8686 | *this, VDPrivate, RefExpr->getType().getUnqualifiedType(), |
| 8687 | RefExpr->getExprLoc()); |
| 8688 | DeclRefExpr *Ref = nullptr; |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 8689 | if (!VD && !CurContext->isDependentContext()) { |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8690 | if (TopDVar.CKind == OMPC_lastprivate) |
| 8691 | Ref = TopDVar.PrivateCopy; |
| 8692 | else { |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 8693 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/true); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8694 | if (!IsOpenMPCapturedDecl(D)) |
| 8695 | ExprCaptures.push_back(Ref->getDecl()); |
| 8696 | } |
Alexey Bataev | 417089f | 2016-02-17 13:19:37 +0000 | [diff] [blame] | 8697 | } |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8698 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_firstprivate, Ref); |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 8699 | Vars.push_back((VD || CurContext->isDependentContext()) |
| 8700 | ? RefExpr->IgnoreParens() |
| 8701 | : Ref); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 8702 | PrivateCopies.push_back(VDPrivateRefExpr); |
| 8703 | Inits.push_back(VDInitRefExpr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8704 | } |
| 8705 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8706 | if (Vars.empty()) |
| 8707 | return nullptr; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8708 | |
| 8709 | return OMPFirstprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 8710 | Vars, PrivateCopies, Inits, |
| 8711 | buildPreInits(Context, ExprCaptures)); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8712 | } |
| 8713 | |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8714 | OMPClause *Sema::ActOnOpenMPLastprivateClause(ArrayRef<Expr *> VarList, |
| 8715 | SourceLocation StartLoc, |
| 8716 | SourceLocation LParenLoc, |
| 8717 | SourceLocation EndLoc) { |
| 8718 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 8719 | SmallVector<Expr *, 8> SrcExprs; |
| 8720 | SmallVector<Expr *, 8> DstExprs; |
| 8721 | SmallVector<Expr *, 8> AssignmentOps; |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8722 | SmallVector<Decl *, 4> ExprCaptures; |
| 8723 | SmallVector<Expr *, 4> ExprPostUpdates; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8724 | for (auto &RefExpr : VarList) { |
| 8725 | assert(RefExpr && "NULL expr in OpenMP lastprivate clause."); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8726 | SourceLocation ELoc; |
| 8727 | SourceRange ERange; |
| 8728 | Expr *SimpleRefExpr = RefExpr; |
| 8729 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8730 | if (Res.second) { |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8731 | // It will be analyzed later. |
| 8732 | Vars.push_back(RefExpr); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 8733 | SrcExprs.push_back(nullptr); |
| 8734 | DstExprs.push_back(nullptr); |
| 8735 | AssignmentOps.push_back(nullptr); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8736 | } |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8737 | ValueDecl *D = Res.first; |
| 8738 | if (!D) |
| 8739 | continue; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8740 | |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8741 | QualType Type = D->getType(); |
| 8742 | auto *VD = dyn_cast<VarDecl>(D); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8743 | |
| 8744 | // OpenMP [2.14.3.5, Restrictions, C/C++, p.2] |
| 8745 | // A variable that appears in a lastprivate clause must not have an |
| 8746 | // incomplete type or a reference type. |
| 8747 | if (RequireCompleteType(ELoc, Type, |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8748 | diag::err_omp_lastprivate_incomplete_type)) |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8749 | continue; |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8750 | Type = Type.getNonReferenceType(); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8751 | |
| 8752 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 8753 | // in a Construct] |
| 8754 | // Variables with the predetermined data-sharing attributes may not be |
| 8755 | // listed in data-sharing attributes clauses, except for the cases |
| 8756 | // listed below. |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8757 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8758 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_lastprivate && |
| 8759 | DVar.CKind != OMPC_firstprivate && |
| 8760 | (DVar.CKind != OMPC_private || DVar.RefExpr != nullptr)) { |
| 8761 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 8762 | << getOpenMPClauseName(DVar.CKind) |
| 8763 | << getOpenMPClauseName(OMPC_lastprivate); |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8764 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8765 | continue; |
| 8766 | } |
| 8767 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 8768 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
| 8769 | // OpenMP [2.14.3.5, Restrictions, p.2] |
| 8770 | // A list item that is private within a parallel region, or that appears in |
| 8771 | // the reduction clause of a parallel construct, must not appear in a |
| 8772 | // lastprivate clause on a worksharing construct if any of the corresponding |
| 8773 | // worksharing regions ever binds to any of the corresponding parallel |
| 8774 | // regions. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 8775 | DSAStackTy::DSAVarData TopDVar = DVar; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 8776 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 8777 | !isOpenMPParallelDirective(CurrDir)) { |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8778 | DVar = DSAStack->getImplicitDSA(D, true); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 8779 | if (DVar.CKind != OMPC_shared) { |
| 8780 | Diag(ELoc, diag::err_omp_required_access) |
| 8781 | << getOpenMPClauseName(OMPC_lastprivate) |
| 8782 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8783 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 8784 | continue; |
| 8785 | } |
| 8786 | } |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8787 | |
| 8788 | // OpenMP 4.5 [2.10.8, Distribute Construct, p.3] |
| 8789 | // A list item may appear in a firstprivate or lastprivate clause but not |
| 8790 | // both. |
| 8791 | if (CurrDir == OMPD_distribute) { |
| 8792 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
| 8793 | if (DVar.CKind == OMPC_firstprivate) { |
| 8794 | Diag(ELoc, diag::err_omp_firstprivate_and_lastprivate_in_distribute); |
| 8795 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
| 8796 | continue; |
| 8797 | } |
| 8798 | } |
| 8799 | |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8800 | // OpenMP [2.14.3.5, Restrictions, C++, p.1,2] |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 8801 | // A variable of class type (or array thereof) that appears in a |
| 8802 | // lastprivate clause requires an accessible, unambiguous default |
| 8803 | // constructor for the class type, unless the list item is also specified |
| 8804 | // in a firstprivate clause. |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8805 | // A variable of class type (or array thereof) that appears in a |
| 8806 | // lastprivate clause requires an accessible, unambiguous copy assignment |
| 8807 | // operator for the class type. |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 8808 | Type = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8809 | auto *SrcVD = buildVarDecl(*this, ERange.getBegin(), |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 8810 | Type.getUnqualifiedType(), ".lastprivate.src", |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8811 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 8812 | auto *PseudoSrcExpr = |
| 8813 | buildDeclRefExpr(*this, SrcVD, Type.getUnqualifiedType(), ELoc); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 8814 | auto *DstVD = |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8815 | buildVarDecl(*this, ERange.getBegin(), Type, ".lastprivate.dst", |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8816 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 8817 | auto *PseudoDstExpr = buildDeclRefExpr(*this, DstVD, Type, ELoc); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 8818 | // For arrays generate assignment operation for single element and replace |
| 8819 | // it by the original array element in CodeGen. |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8820 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, ELoc, BO_Assign, |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 8821 | PseudoDstExpr, PseudoSrcExpr); |
| 8822 | if (AssignmentOp.isInvalid()) |
| 8823 | continue; |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8824 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), ELoc, |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 8825 | /*DiscardedValue=*/true); |
| 8826 | if (AssignmentOp.isInvalid()) |
| 8827 | continue; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8828 | |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8829 | DeclRefExpr *Ref = nullptr; |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 8830 | if (!VD && !CurContext->isDependentContext()) { |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8831 | if (TopDVar.CKind == OMPC_firstprivate) |
| 8832 | Ref = TopDVar.PrivateCopy; |
| 8833 | else { |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 8834 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8835 | if (!IsOpenMPCapturedDecl(D)) |
| 8836 | ExprCaptures.push_back(Ref->getDecl()); |
| 8837 | } |
| 8838 | if (TopDVar.CKind == OMPC_firstprivate || |
| 8839 | (!IsOpenMPCapturedDecl(D) && |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8840 | Ref->getDecl()->hasAttr<OMPCaptureNoInitAttr>())) { |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8841 | ExprResult RefRes = DefaultLvalueConversion(Ref); |
| 8842 | if (!RefRes.isUsable()) |
| 8843 | continue; |
| 8844 | ExprResult PostUpdateRes = |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8845 | BuildBinOp(DSAStack->getCurScope(), ELoc, BO_Assign, SimpleRefExpr, |
| 8846 | RefRes.get()); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8847 | if (!PostUpdateRes.isUsable()) |
| 8848 | continue; |
Alexey Bataev | 78849fb | 2016-03-09 09:49:00 +0000 | [diff] [blame] | 8849 | ExprPostUpdates.push_back( |
| 8850 | IgnoredValueConversions(PostUpdateRes.get()).get()); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8851 | } |
| 8852 | } |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 8853 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_lastprivate, Ref); |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 8854 | Vars.push_back((VD || CurContext->isDependentContext()) |
| 8855 | ? RefExpr->IgnoreParens() |
| 8856 | : Ref); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 8857 | SrcExprs.push_back(PseudoSrcExpr); |
| 8858 | DstExprs.push_back(PseudoDstExpr); |
| 8859 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8860 | } |
| 8861 | |
| 8862 | if (Vars.empty()) |
| 8863 | return nullptr; |
| 8864 | |
| 8865 | return OMPLastprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8866 | Vars, SrcExprs, DstExprs, AssignmentOps, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 8867 | buildPreInits(Context, ExprCaptures), |
| 8868 | buildPostUpdate(*this, ExprPostUpdates)); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8869 | } |
| 8870 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8871 | OMPClause *Sema::ActOnOpenMPSharedClause(ArrayRef<Expr *> VarList, |
| 8872 | SourceLocation StartLoc, |
| 8873 | SourceLocation LParenLoc, |
| 8874 | SourceLocation EndLoc) { |
| 8875 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8876 | for (auto &RefExpr : VarList) { |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 8877 | assert(RefExpr && "NULL expr in OpenMP lastprivate clause."); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8878 | SourceLocation ELoc; |
| 8879 | SourceRange ERange; |
| 8880 | Expr *SimpleRefExpr = RefExpr; |
| 8881 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 8882 | if (Res.second) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8883 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8884 | Vars.push_back(RefExpr); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8885 | } |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 8886 | ValueDecl *D = Res.first; |
| 8887 | if (!D) |
| 8888 | continue; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8889 | |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 8890 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8891 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 8892 | // in a Construct] |
| 8893 | // Variables with the predetermined data-sharing attributes may not be |
| 8894 | // listed in data-sharing attributes clauses, except for the cases |
| 8895 | // listed below. For these exceptions only, listing a predetermined |
| 8896 | // variable in a data-sharing attribute clause is allowed and overrides |
| 8897 | // the variable's predetermined data-sharing attributes. |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 8898 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8899 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared && |
| 8900 | DVar.RefExpr) { |
| 8901 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 8902 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 8903 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8904 | continue; |
| 8905 | } |
| 8906 | |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 8907 | DeclRefExpr *Ref = nullptr; |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 8908 | if (!VD && IsOpenMPCapturedDecl(D) && !CurContext->isDependentContext()) |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 8909 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/true); |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 8910 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_shared, Ref); |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 8911 | Vars.push_back((VD || !Ref || CurContext->isDependentContext()) |
| 8912 | ? RefExpr->IgnoreParens() |
| 8913 | : Ref); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8914 | } |
| 8915 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8916 | if (Vars.empty()) |
| 8917 | return nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8918 | |
| 8919 | return OMPSharedClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars); |
| 8920 | } |
| 8921 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8922 | namespace { |
| 8923 | class DSARefChecker : public StmtVisitor<DSARefChecker, bool> { |
| 8924 | DSAStackTy *Stack; |
| 8925 | |
| 8926 | public: |
| 8927 | bool VisitDeclRefExpr(DeclRefExpr *E) { |
| 8928 | if (VarDecl *VD = dyn_cast<VarDecl>(E->getDecl())) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 8929 | DSAStackTy::DSAVarData DVar = Stack->getTopDSA(VD, false); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8930 | if (DVar.CKind == OMPC_shared && !DVar.RefExpr) |
| 8931 | return false; |
| 8932 | if (DVar.CKind != OMPC_unknown) |
| 8933 | return true; |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 8934 | DSAStackTy::DSAVarData DVarPrivate = Stack->hasDSA( |
| 8935 | VD, isOpenMPPrivate, [](OpenMPDirectiveKind) -> bool { return true; }, |
| 8936 | false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 8937 | if (DVarPrivate.CKind != OMPC_unknown) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8938 | return true; |
| 8939 | return false; |
| 8940 | } |
| 8941 | return false; |
| 8942 | } |
| 8943 | bool VisitStmt(Stmt *S) { |
| 8944 | for (auto Child : S->children()) { |
| 8945 | if (Child && Visit(Child)) |
| 8946 | return true; |
| 8947 | } |
| 8948 | return false; |
| 8949 | } |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 8950 | explicit DSARefChecker(DSAStackTy *S) : Stack(S) {} |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8951 | }; |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 8952 | } // namespace |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8953 | |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8954 | namespace { |
| 8955 | // Transform MemberExpression for specified FieldDecl of current class to |
| 8956 | // DeclRefExpr to specified OMPCapturedExprDecl. |
| 8957 | class TransformExprToCaptures : public TreeTransform<TransformExprToCaptures> { |
| 8958 | typedef TreeTransform<TransformExprToCaptures> BaseTransform; |
| 8959 | ValueDecl *Field; |
| 8960 | DeclRefExpr *CapturedExpr; |
| 8961 | |
| 8962 | public: |
| 8963 | TransformExprToCaptures(Sema &SemaRef, ValueDecl *FieldDecl) |
| 8964 | : BaseTransform(SemaRef), Field(FieldDecl), CapturedExpr(nullptr) {} |
| 8965 | |
| 8966 | ExprResult TransformMemberExpr(MemberExpr *E) { |
| 8967 | if (isa<CXXThisExpr>(E->getBase()->IgnoreParenImpCasts()) && |
| 8968 | E->getMemberDecl() == Field) { |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 8969 | CapturedExpr = buildCapture(SemaRef, Field, E, /*WithInit=*/false); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8970 | return CapturedExpr; |
| 8971 | } |
| 8972 | return BaseTransform::TransformMemberExpr(E); |
| 8973 | } |
| 8974 | DeclRefExpr *getCapturedExpr() { return CapturedExpr; } |
| 8975 | }; |
| 8976 | } // namespace |
| 8977 | |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8978 | template <typename T> |
| 8979 | static T filterLookupForUDR(SmallVectorImpl<UnresolvedSet<8>> &Lookups, |
| 8980 | const llvm::function_ref<T(ValueDecl *)> &Gen) { |
| 8981 | for (auto &Set : Lookups) { |
| 8982 | for (auto *D : Set) { |
| 8983 | if (auto Res = Gen(cast<ValueDecl>(D))) |
| 8984 | return Res; |
| 8985 | } |
| 8986 | } |
| 8987 | return T(); |
| 8988 | } |
| 8989 | |
| 8990 | static ExprResult |
| 8991 | buildDeclareReductionRef(Sema &SemaRef, SourceLocation Loc, SourceRange Range, |
| 8992 | Scope *S, CXXScopeSpec &ReductionIdScopeSpec, |
| 8993 | const DeclarationNameInfo &ReductionId, QualType Ty, |
| 8994 | CXXCastPath &BasePath, Expr *UnresolvedReduction) { |
| 8995 | if (ReductionIdScopeSpec.isInvalid()) |
| 8996 | return ExprError(); |
| 8997 | SmallVector<UnresolvedSet<8>, 4> Lookups; |
| 8998 | if (S) { |
| 8999 | LookupResult Lookup(SemaRef, ReductionId, Sema::LookupOMPReductionName); |
| 9000 | Lookup.suppressDiagnostics(); |
| 9001 | while (S && SemaRef.LookupParsedName(Lookup, S, &ReductionIdScopeSpec)) { |
| 9002 | auto *D = Lookup.getRepresentativeDecl(); |
| 9003 | do { |
| 9004 | S = S->getParent(); |
| 9005 | } while (S && !S->isDeclScope(D)); |
| 9006 | if (S) |
| 9007 | S = S->getParent(); |
| 9008 | Lookups.push_back(UnresolvedSet<8>()); |
| 9009 | Lookups.back().append(Lookup.begin(), Lookup.end()); |
| 9010 | Lookup.clear(); |
| 9011 | } |
| 9012 | } else if (auto *ULE = |
| 9013 | cast_or_null<UnresolvedLookupExpr>(UnresolvedReduction)) { |
| 9014 | Lookups.push_back(UnresolvedSet<8>()); |
| 9015 | Decl *PrevD = nullptr; |
| 9016 | for(auto *D : ULE->decls()) { |
| 9017 | if (D == PrevD) |
| 9018 | Lookups.push_back(UnresolvedSet<8>()); |
| 9019 | else if (auto *DRD = cast<OMPDeclareReductionDecl>(D)) |
| 9020 | Lookups.back().addDecl(DRD); |
| 9021 | PrevD = D; |
| 9022 | } |
| 9023 | } |
| 9024 | if (Ty->isDependentType() || Ty->isInstantiationDependentType() || |
| 9025 | Ty->containsUnexpandedParameterPack() || |
| 9026 | filterLookupForUDR<bool>(Lookups, [](ValueDecl *D) -> bool { |
| 9027 | return !D->isInvalidDecl() && |
| 9028 | (D->getType()->isDependentType() || |
| 9029 | D->getType()->isInstantiationDependentType() || |
| 9030 | D->getType()->containsUnexpandedParameterPack()); |
| 9031 | })) { |
| 9032 | UnresolvedSet<8> ResSet; |
| 9033 | for (auto &Set : Lookups) { |
| 9034 | ResSet.append(Set.begin(), Set.end()); |
| 9035 | // The last item marks the end of all declarations at the specified scope. |
| 9036 | ResSet.addDecl(Set[Set.size() - 1]); |
| 9037 | } |
| 9038 | return UnresolvedLookupExpr::Create( |
| 9039 | SemaRef.Context, /*NamingClass=*/nullptr, |
| 9040 | ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), ReductionId, |
| 9041 | /*ADL=*/true, /*Overloaded=*/true, ResSet.begin(), ResSet.end()); |
| 9042 | } |
| 9043 | if (auto *VD = filterLookupForUDR<ValueDecl *>( |
| 9044 | Lookups, [&SemaRef, Ty](ValueDecl *D) -> ValueDecl * { |
| 9045 | if (!D->isInvalidDecl() && |
| 9046 | SemaRef.Context.hasSameType(D->getType(), Ty)) |
| 9047 | return D; |
| 9048 | return nullptr; |
| 9049 | })) |
| 9050 | return SemaRef.BuildDeclRefExpr(VD, Ty, VK_LValue, Loc); |
| 9051 | if (auto *VD = filterLookupForUDR<ValueDecl *>( |
| 9052 | Lookups, [&SemaRef, Ty, Loc](ValueDecl *D) -> ValueDecl * { |
| 9053 | if (!D->isInvalidDecl() && |
| 9054 | SemaRef.IsDerivedFrom(Loc, Ty, D->getType()) && |
| 9055 | !Ty.isMoreQualifiedThan(D->getType())) |
| 9056 | return D; |
| 9057 | return nullptr; |
| 9058 | })) { |
| 9059 | CXXBasePaths Paths(/*FindAmbiguities=*/true, /*RecordPaths=*/true, |
| 9060 | /*DetectVirtual=*/false); |
| 9061 | if (SemaRef.IsDerivedFrom(Loc, Ty, VD->getType(), Paths)) { |
| 9062 | if (!Paths.isAmbiguous(SemaRef.Context.getCanonicalType( |
| 9063 | VD->getType().getUnqualifiedType()))) { |
| 9064 | if (SemaRef.CheckBaseClassAccess(Loc, VD->getType(), Ty, Paths.front(), |
| 9065 | /*DiagID=*/0) != |
| 9066 | Sema::AR_inaccessible) { |
| 9067 | SemaRef.BuildBasePathArray(Paths, BasePath); |
| 9068 | return SemaRef.BuildDeclRefExpr(VD, Ty, VK_LValue, Loc); |
| 9069 | } |
| 9070 | } |
| 9071 | } |
| 9072 | } |
| 9073 | if (ReductionIdScopeSpec.isSet()) { |
| 9074 | SemaRef.Diag(Loc, diag::err_omp_not_resolved_reduction_identifier) << Range; |
| 9075 | return ExprError(); |
| 9076 | } |
| 9077 | return ExprEmpty(); |
| 9078 | } |
| 9079 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9080 | OMPClause *Sema::ActOnOpenMPReductionClause( |
| 9081 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, SourceLocation LParenLoc, |
| 9082 | SourceLocation ColonLoc, SourceLocation EndLoc, |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9083 | CXXScopeSpec &ReductionIdScopeSpec, const DeclarationNameInfo &ReductionId, |
| 9084 | ArrayRef<Expr *> UnresolvedReductions) { |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9085 | auto DN = ReductionId.getName(); |
| 9086 | auto OOK = DN.getCXXOverloadedOperator(); |
| 9087 | BinaryOperatorKind BOK = BO_Comma; |
| 9088 | |
| 9089 | // OpenMP [2.14.3.6, reduction clause] |
| 9090 | // C |
| 9091 | // reduction-identifier is either an identifier or one of the following |
| 9092 | // operators: +, -, *, &, |, ^, && and || |
| 9093 | // C++ |
| 9094 | // reduction-identifier is either an id-expression or one of the following |
| 9095 | // operators: +, -, *, &, |, ^, && and || |
| 9096 | // FIXME: Only 'min' and 'max' identifiers are supported for now. |
| 9097 | switch (OOK) { |
| 9098 | case OO_Plus: |
| 9099 | case OO_Minus: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9100 | BOK = BO_Add; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9101 | break; |
| 9102 | case OO_Star: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9103 | BOK = BO_Mul; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9104 | break; |
| 9105 | case OO_Amp: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9106 | BOK = BO_And; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9107 | break; |
| 9108 | case OO_Pipe: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9109 | BOK = BO_Or; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9110 | break; |
| 9111 | case OO_Caret: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9112 | BOK = BO_Xor; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9113 | break; |
| 9114 | case OO_AmpAmp: |
| 9115 | BOK = BO_LAnd; |
| 9116 | break; |
| 9117 | case OO_PipePipe: |
| 9118 | BOK = BO_LOr; |
| 9119 | break; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9120 | case OO_New: |
| 9121 | case OO_Delete: |
| 9122 | case OO_Array_New: |
| 9123 | case OO_Array_Delete: |
| 9124 | case OO_Slash: |
| 9125 | case OO_Percent: |
| 9126 | case OO_Tilde: |
| 9127 | case OO_Exclaim: |
| 9128 | case OO_Equal: |
| 9129 | case OO_Less: |
| 9130 | case OO_Greater: |
| 9131 | case OO_LessEqual: |
| 9132 | case OO_GreaterEqual: |
| 9133 | case OO_PlusEqual: |
| 9134 | case OO_MinusEqual: |
| 9135 | case OO_StarEqual: |
| 9136 | case OO_SlashEqual: |
| 9137 | case OO_PercentEqual: |
| 9138 | case OO_CaretEqual: |
| 9139 | case OO_AmpEqual: |
| 9140 | case OO_PipeEqual: |
| 9141 | case OO_LessLess: |
| 9142 | case OO_GreaterGreater: |
| 9143 | case OO_LessLessEqual: |
| 9144 | case OO_GreaterGreaterEqual: |
| 9145 | case OO_EqualEqual: |
| 9146 | case OO_ExclaimEqual: |
| 9147 | case OO_PlusPlus: |
| 9148 | case OO_MinusMinus: |
| 9149 | case OO_Comma: |
| 9150 | case OO_ArrowStar: |
| 9151 | case OO_Arrow: |
| 9152 | case OO_Call: |
| 9153 | case OO_Subscript: |
| 9154 | case OO_Conditional: |
Richard Smith | 9be594e | 2015-10-22 05:12:22 +0000 | [diff] [blame] | 9155 | case OO_Coawait: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9156 | case NUM_OVERLOADED_OPERATORS: |
| 9157 | llvm_unreachable("Unexpected reduction identifier"); |
| 9158 | case OO_None: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9159 | if (auto II = DN.getAsIdentifierInfo()) { |
| 9160 | if (II->isStr("max")) |
| 9161 | BOK = BO_GT; |
| 9162 | else if (II->isStr("min")) |
| 9163 | BOK = BO_LT; |
| 9164 | } |
| 9165 | break; |
| 9166 | } |
| 9167 | SourceRange ReductionIdRange; |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9168 | if (ReductionIdScopeSpec.isValid()) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9169 | ReductionIdRange.setBegin(ReductionIdScopeSpec.getBeginLoc()); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9170 | ReductionIdRange.setEnd(ReductionId.getEndLoc()); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9171 | |
| 9172 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9173 | SmallVector<Expr *, 8> Privates; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9174 | SmallVector<Expr *, 8> LHSs; |
| 9175 | SmallVector<Expr *, 8> RHSs; |
| 9176 | SmallVector<Expr *, 8> ReductionOps; |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 9177 | SmallVector<Decl *, 4> ExprCaptures; |
| 9178 | SmallVector<Expr *, 4> ExprPostUpdates; |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9179 | auto IR = UnresolvedReductions.begin(), ER = UnresolvedReductions.end(); |
| 9180 | bool FirstIter = true; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9181 | for (auto RefExpr : VarList) { |
| 9182 | assert(RefExpr && "nullptr expr in OpenMP reduction clause."); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9183 | // OpenMP [2.1, C/C++] |
| 9184 | // A list item is a variable or array section, subject to the restrictions |
| 9185 | // specified in Section 2.4 on page 42 and in each of the sections |
| 9186 | // describing clauses and directives for which a list appears. |
| 9187 | // OpenMP [2.14.3.3, Restrictions, p.1] |
| 9188 | // A variable that is part of another variable (as an array or |
| 9189 | // structure element) cannot appear in a private clause. |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9190 | if (!FirstIter && IR != ER) |
| 9191 | ++IR; |
| 9192 | FirstIter = false; |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9193 | SourceLocation ELoc; |
| 9194 | SourceRange ERange; |
| 9195 | Expr *SimpleRefExpr = RefExpr; |
| 9196 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange, |
| 9197 | /*AllowArraySection=*/true); |
| 9198 | if (Res.second) { |
| 9199 | // It will be analyzed later. |
| 9200 | Vars.push_back(RefExpr); |
| 9201 | Privates.push_back(nullptr); |
| 9202 | LHSs.push_back(nullptr); |
| 9203 | RHSs.push_back(nullptr); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9204 | // Try to find 'declare reduction' corresponding construct before using |
| 9205 | // builtin/overloaded operators. |
| 9206 | QualType Type = Context.DependentTy; |
| 9207 | CXXCastPath BasePath; |
| 9208 | ExprResult DeclareReductionRef = buildDeclareReductionRef( |
| 9209 | *this, ELoc, ERange, DSAStack->getCurScope(), ReductionIdScopeSpec, |
| 9210 | ReductionId, Type, BasePath, IR == ER ? nullptr : *IR); |
| 9211 | if (CurContext->isDependentContext() && |
| 9212 | (DeclareReductionRef.isUnset() || |
| 9213 | isa<UnresolvedLookupExpr>(DeclareReductionRef.get()))) |
| 9214 | ReductionOps.push_back(DeclareReductionRef.get()); |
| 9215 | else |
| 9216 | ReductionOps.push_back(nullptr); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9217 | } |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9218 | ValueDecl *D = Res.first; |
| 9219 | if (!D) |
| 9220 | continue; |
| 9221 | |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 9222 | QualType Type; |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9223 | auto *ASE = dyn_cast<ArraySubscriptExpr>(RefExpr->IgnoreParens()); |
| 9224 | auto *OASE = dyn_cast<OMPArraySectionExpr>(RefExpr->IgnoreParens()); |
| 9225 | if (ASE) |
Alexey Bataev | 31300ed | 2016-02-04 11:27:03 +0000 | [diff] [blame] | 9226 | Type = ASE->getType().getNonReferenceType(); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9227 | else if (OASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 9228 | auto BaseType = OMPArraySectionExpr::getBaseOriginalType(OASE->getBase()); |
| 9229 | if (auto *ATy = BaseType->getAsArrayTypeUnsafe()) |
| 9230 | Type = ATy->getElementType(); |
| 9231 | else |
| 9232 | Type = BaseType->getPointeeType(); |
Alexey Bataev | 31300ed | 2016-02-04 11:27:03 +0000 | [diff] [blame] | 9233 | Type = Type.getNonReferenceType(); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9234 | } else |
| 9235 | Type = Context.getBaseElementType(D->getType().getNonReferenceType()); |
| 9236 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 9237 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9238 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 9239 | // A variable that appears in a private clause must not have an incomplete |
| 9240 | // type or a reference type. |
| 9241 | if (RequireCompleteType(ELoc, Type, |
| 9242 | diag::err_omp_reduction_incomplete_type)) |
| 9243 | continue; |
| 9244 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9245 | // A list item that appears in a reduction clause must not be |
| 9246 | // const-qualified. |
| 9247 | if (Type.getNonReferenceType().isConstant(Context)) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 9248 | Diag(ELoc, diag::err_omp_const_reduction_list_item) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9249 | << getOpenMPClauseName(OMPC_reduction) << Type << ERange; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9250 | if (!ASE && !OASE) { |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9251 | bool IsDecl = !VD || |
| 9252 | VD->isThisDeclarationADefinition(Context) == |
| 9253 | VarDecl::DeclarationOnly; |
| 9254 | Diag(D->getLocation(), |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 9255 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9256 | << D; |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 9257 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9258 | continue; |
| 9259 | } |
| 9260 | // OpenMP [2.9.3.6, Restrictions, C/C++, p.4] |
| 9261 | // If a list-item is a reference type then it must bind to the same object |
| 9262 | // for all threads of the team. |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9263 | if (!ASE && !OASE && VD) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 9264 | VarDecl *VDDef = VD->getDefinition(); |
Alexey Bataev | 31300ed | 2016-02-04 11:27:03 +0000 | [diff] [blame] | 9265 | if (VD->getType()->isReferenceType() && VDDef) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 9266 | DSARefChecker Check(DSAStack); |
| 9267 | if (Check.Visit(VDDef->getInit())) { |
| 9268 | Diag(ELoc, diag::err_omp_reduction_ref_type_arg) << ERange; |
| 9269 | Diag(VDDef->getLocation(), diag::note_defined_here) << VDDef; |
| 9270 | continue; |
| 9271 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9272 | } |
| 9273 | } |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9274 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9275 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 9276 | // in a Construct] |
| 9277 | // Variables with the predetermined data-sharing attributes may not be |
| 9278 | // listed in data-sharing attributes clauses, except for the cases |
| 9279 | // listed below. For these exceptions only, listing a predetermined |
| 9280 | // variable in a data-sharing attribute clause is allowed and overrides |
| 9281 | // the variable's predetermined data-sharing attributes. |
| 9282 | // OpenMP [2.14.3.6, Restrictions, p.3] |
| 9283 | // Any number of reduction clauses can be specified on the directive, |
| 9284 | // but a list item can appear only once in the reduction clauses for that |
| 9285 | // directive. |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 9286 | DSAStackTy::DSAVarData DVar; |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9287 | DVar = DSAStack->getTopDSA(D, false); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9288 | if (DVar.CKind == OMPC_reduction) { |
| 9289 | Diag(ELoc, diag::err_omp_once_referenced) |
| 9290 | << getOpenMPClauseName(OMPC_reduction); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9291 | if (DVar.RefExpr) |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9292 | Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_referenced); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9293 | } else if (DVar.CKind != OMPC_unknown) { |
| 9294 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 9295 | << getOpenMPClauseName(DVar.CKind) |
| 9296 | << getOpenMPClauseName(OMPC_reduction); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9297 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9298 | continue; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9299 | } |
| 9300 | |
| 9301 | // OpenMP [2.14.3.6, Restrictions, p.1] |
| 9302 | // A list item that appears in a reduction clause of a worksharing |
| 9303 | // construct must be shared in the parallel regions to which any of the |
| 9304 | // worksharing regions arising from the worksharing construct bind. |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9305 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
| 9306 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 9307 | !isOpenMPParallelDirective(CurrDir)) { |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9308 | DVar = DSAStack->getImplicitDSA(D, true); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9309 | if (DVar.CKind != OMPC_shared) { |
| 9310 | Diag(ELoc, diag::err_omp_required_access) |
| 9311 | << getOpenMPClauseName(OMPC_reduction) |
| 9312 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9313 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9314 | continue; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 9315 | } |
| 9316 | } |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9317 | |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9318 | // Try to find 'declare reduction' corresponding construct before using |
| 9319 | // builtin/overloaded operators. |
| 9320 | CXXCastPath BasePath; |
| 9321 | ExprResult DeclareReductionRef = buildDeclareReductionRef( |
| 9322 | *this, ELoc, ERange, DSAStack->getCurScope(), ReductionIdScopeSpec, |
| 9323 | ReductionId, Type, BasePath, IR == ER ? nullptr : *IR); |
| 9324 | if (DeclareReductionRef.isInvalid()) |
| 9325 | continue; |
| 9326 | if (CurContext->isDependentContext() && |
| 9327 | (DeclareReductionRef.isUnset() || |
| 9328 | isa<UnresolvedLookupExpr>(DeclareReductionRef.get()))) { |
| 9329 | Vars.push_back(RefExpr); |
| 9330 | Privates.push_back(nullptr); |
| 9331 | LHSs.push_back(nullptr); |
| 9332 | RHSs.push_back(nullptr); |
| 9333 | ReductionOps.push_back(DeclareReductionRef.get()); |
| 9334 | continue; |
| 9335 | } |
| 9336 | if (BOK == BO_Comma && DeclareReductionRef.isUnset()) { |
| 9337 | // Not allowed reduction identifier is found. |
| 9338 | Diag(ReductionId.getLocStart(), |
| 9339 | diag::err_omp_unknown_reduction_identifier) |
| 9340 | << Type << ReductionIdRange; |
| 9341 | continue; |
| 9342 | } |
| 9343 | |
| 9344 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
| 9345 | // The type of a list item that appears in a reduction clause must be valid |
| 9346 | // for the reduction-identifier. For a max or min reduction in C, the type |
| 9347 | // of the list item must be an allowed arithmetic data type: char, int, |
| 9348 | // float, double, or _Bool, possibly modified with long, short, signed, or |
| 9349 | // unsigned. For a max or min reduction in C++, the type of the list item |
| 9350 | // must be an allowed arithmetic data type: char, wchar_t, int, float, |
| 9351 | // double, or bool, possibly modified with long, short, signed, or unsigned. |
| 9352 | if (DeclareReductionRef.isUnset()) { |
| 9353 | if ((BOK == BO_GT || BOK == BO_LT) && |
| 9354 | !(Type->isScalarType() || |
| 9355 | (getLangOpts().CPlusPlus && Type->isArithmeticType()))) { |
| 9356 | Diag(ELoc, diag::err_omp_clause_not_arithmetic_type_arg) |
| 9357 | << getLangOpts().CPlusPlus; |
| 9358 | if (!ASE && !OASE) { |
| 9359 | bool IsDecl = !VD || |
| 9360 | VD->isThisDeclarationADefinition(Context) == |
| 9361 | VarDecl::DeclarationOnly; |
| 9362 | Diag(D->getLocation(), |
| 9363 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 9364 | << D; |
| 9365 | } |
| 9366 | continue; |
| 9367 | } |
| 9368 | if ((BOK == BO_OrAssign || BOK == BO_AndAssign || BOK == BO_XorAssign) && |
| 9369 | !getLangOpts().CPlusPlus && Type->isFloatingType()) { |
| 9370 | Diag(ELoc, diag::err_omp_clause_floating_type_arg); |
| 9371 | if (!ASE && !OASE) { |
| 9372 | bool IsDecl = !VD || |
| 9373 | VD->isThisDeclarationADefinition(Context) == |
| 9374 | VarDecl::DeclarationOnly; |
| 9375 | Diag(D->getLocation(), |
| 9376 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 9377 | << D; |
| 9378 | } |
| 9379 | continue; |
| 9380 | } |
| 9381 | } |
| 9382 | |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9383 | Type = Type.getNonLValueExprType(Context).getUnqualifiedType(); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9384 | auto *LHSVD = buildVarDecl(*this, ELoc, Type, ".reduction.lhs", |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9385 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 9386 | auto *RHSVD = buildVarDecl(*this, ELoc, Type, D->getName(), |
| 9387 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9388 | auto PrivateTy = Type; |
Alexey Bataev | 1189bd0 | 2016-01-26 12:20:39 +0000 | [diff] [blame] | 9389 | if (OASE || |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9390 | (!ASE && |
| 9391 | D->getType().getNonReferenceType()->isVariablyModifiedType())) { |
Alexey Bataev | 1189bd0 | 2016-01-26 12:20:39 +0000 | [diff] [blame] | 9392 | // For arays/array sections only: |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9393 | // Create pseudo array type for private copy. The size for this array will |
| 9394 | // be generated during codegen. |
| 9395 | // For array subscripts or single variables Private Ty is the same as Type |
| 9396 | // (type of the variable or single array element). |
| 9397 | PrivateTy = Context.getVariableArrayType( |
| 9398 | Type, new (Context) OpaqueValueExpr(SourceLocation(), |
| 9399 | Context.getSizeType(), VK_RValue), |
| 9400 | ArrayType::Normal, /*IndexTypeQuals=*/0, SourceRange()); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9401 | } else if (!ASE && !OASE && |
| 9402 | Context.getAsArrayType(D->getType().getNonReferenceType())) |
| 9403 | PrivateTy = D->getType().getNonReferenceType(); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9404 | // Private copy. |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9405 | auto *PrivateVD = buildVarDecl(*this, ELoc, PrivateTy, D->getName(), |
| 9406 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9407 | // Add initializer for private variable. |
| 9408 | Expr *Init = nullptr; |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9409 | auto *LHSDRE = buildDeclRefExpr(*this, LHSVD, Type, ELoc); |
| 9410 | auto *RHSDRE = buildDeclRefExpr(*this, RHSVD, Type, ELoc); |
| 9411 | if (DeclareReductionRef.isUsable()) { |
| 9412 | auto *DRDRef = DeclareReductionRef.getAs<DeclRefExpr>(); |
| 9413 | auto *DRD = cast<OMPDeclareReductionDecl>(DRDRef->getDecl()); |
| 9414 | if (DRD->getInitializer()) { |
| 9415 | Init = DRDRef; |
| 9416 | RHSVD->setInit(DRDRef); |
| 9417 | RHSVD->setInitStyle(VarDecl::CallInit); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9418 | } |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9419 | } else { |
| 9420 | switch (BOK) { |
| 9421 | case BO_Add: |
| 9422 | case BO_Xor: |
| 9423 | case BO_Or: |
| 9424 | case BO_LOr: |
| 9425 | // '+', '-', '^', '|', '||' reduction ops - initializer is '0'. |
| 9426 | if (Type->isScalarType() || Type->isAnyComplexType()) |
| 9427 | Init = ActOnIntegerConstant(ELoc, /*Val=*/0).get(); |
| 9428 | break; |
| 9429 | case BO_Mul: |
| 9430 | case BO_LAnd: |
| 9431 | if (Type->isScalarType() || Type->isAnyComplexType()) { |
| 9432 | // '*' and '&&' reduction ops - initializer is '1'. |
| 9433 | Init = ActOnIntegerConstant(ELoc, /*Val=*/1).get(); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9434 | } |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9435 | break; |
| 9436 | case BO_And: { |
| 9437 | // '&' reduction op - initializer is '~0'. |
| 9438 | QualType OrigType = Type; |
| 9439 | if (auto *ComplexTy = OrigType->getAs<ComplexType>()) |
| 9440 | Type = ComplexTy->getElementType(); |
| 9441 | if (Type->isRealFloatingType()) { |
| 9442 | llvm::APFloat InitValue = |
| 9443 | llvm::APFloat::getAllOnesValue(Context.getTypeSize(Type), |
| 9444 | /*isIEEE=*/true); |
| 9445 | Init = FloatingLiteral::Create(Context, InitValue, /*isexact=*/true, |
| 9446 | Type, ELoc); |
| 9447 | } else if (Type->isScalarType()) { |
| 9448 | auto Size = Context.getTypeSize(Type); |
| 9449 | QualType IntTy = Context.getIntTypeForBitwidth(Size, /*Signed=*/0); |
| 9450 | llvm::APInt InitValue = llvm::APInt::getAllOnesValue(Size); |
| 9451 | Init = IntegerLiteral::Create(Context, InitValue, IntTy, ELoc); |
| 9452 | } |
| 9453 | if (Init && OrigType->isAnyComplexType()) { |
| 9454 | // Init = 0xFFFF + 0xFFFFi; |
| 9455 | auto *Im = new (Context) ImaginaryLiteral(Init, OrigType); |
| 9456 | Init = CreateBuiltinBinOp(ELoc, BO_Add, Init, Im).get(); |
| 9457 | } |
| 9458 | Type = OrigType; |
| 9459 | break; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9460 | } |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9461 | case BO_LT: |
| 9462 | case BO_GT: { |
| 9463 | // 'min' reduction op - initializer is 'Largest representable number in |
| 9464 | // the reduction list item type'. |
| 9465 | // 'max' reduction op - initializer is 'Least representable number in |
| 9466 | // the reduction list item type'. |
| 9467 | if (Type->isIntegerType() || Type->isPointerType()) { |
| 9468 | bool IsSigned = Type->hasSignedIntegerRepresentation(); |
| 9469 | auto Size = Context.getTypeSize(Type); |
| 9470 | QualType IntTy = |
| 9471 | Context.getIntTypeForBitwidth(Size, /*Signed=*/IsSigned); |
| 9472 | llvm::APInt InitValue = |
| 9473 | (BOK != BO_LT) |
| 9474 | ? IsSigned ? llvm::APInt::getSignedMinValue(Size) |
| 9475 | : llvm::APInt::getMinValue(Size) |
| 9476 | : IsSigned ? llvm::APInt::getSignedMaxValue(Size) |
| 9477 | : llvm::APInt::getMaxValue(Size); |
| 9478 | Init = IntegerLiteral::Create(Context, InitValue, IntTy, ELoc); |
| 9479 | if (Type->isPointerType()) { |
| 9480 | // Cast to pointer type. |
| 9481 | auto CastExpr = BuildCStyleCastExpr( |
| 9482 | SourceLocation(), Context.getTrivialTypeSourceInfo(Type, ELoc), |
| 9483 | SourceLocation(), Init); |
| 9484 | if (CastExpr.isInvalid()) |
| 9485 | continue; |
| 9486 | Init = CastExpr.get(); |
| 9487 | } |
| 9488 | } else if (Type->isRealFloatingType()) { |
| 9489 | llvm::APFloat InitValue = llvm::APFloat::getLargest( |
| 9490 | Context.getFloatTypeSemantics(Type), BOK != BO_LT); |
| 9491 | Init = FloatingLiteral::Create(Context, InitValue, /*isexact=*/true, |
| 9492 | Type, ELoc); |
| 9493 | } |
| 9494 | break; |
| 9495 | } |
| 9496 | case BO_PtrMemD: |
| 9497 | case BO_PtrMemI: |
| 9498 | case BO_MulAssign: |
| 9499 | case BO_Div: |
| 9500 | case BO_Rem: |
| 9501 | case BO_Sub: |
| 9502 | case BO_Shl: |
| 9503 | case BO_Shr: |
| 9504 | case BO_LE: |
| 9505 | case BO_GE: |
| 9506 | case BO_EQ: |
| 9507 | case BO_NE: |
| 9508 | case BO_AndAssign: |
| 9509 | case BO_XorAssign: |
| 9510 | case BO_OrAssign: |
| 9511 | case BO_Assign: |
| 9512 | case BO_AddAssign: |
| 9513 | case BO_SubAssign: |
| 9514 | case BO_DivAssign: |
| 9515 | case BO_RemAssign: |
| 9516 | case BO_ShlAssign: |
| 9517 | case BO_ShrAssign: |
| 9518 | case BO_Comma: |
| 9519 | llvm_unreachable("Unexpected reduction operation"); |
| 9520 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9521 | } |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9522 | if (Init && DeclareReductionRef.isUnset()) { |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9523 | AddInitializerToDecl(RHSVD, Init, /*DirectInit=*/false, |
| 9524 | /*TypeMayContainAuto=*/false); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9525 | } else if (!Init) |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9526 | ActOnUninitializedDecl(RHSVD, /*TypeMayContainAuto=*/false); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9527 | if (RHSVD->isInvalidDecl()) |
| 9528 | continue; |
| 9529 | if (!RHSVD->hasInit() && DeclareReductionRef.isUnset()) { |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9530 | Diag(ELoc, diag::err_omp_reduction_id_not_compatible) << Type |
| 9531 | << ReductionIdRange; |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9532 | bool IsDecl = |
| 9533 | !VD || |
| 9534 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 9535 | Diag(D->getLocation(), |
| 9536 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 9537 | << D; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9538 | continue; |
| 9539 | } |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9540 | // Store initializer for single element in private copy. Will be used during |
| 9541 | // codegen. |
| 9542 | PrivateVD->setInit(RHSVD->getInit()); |
| 9543 | PrivateVD->setInitStyle(RHSVD->getInitStyle()); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9544 | auto *PrivateDRE = buildDeclRefExpr(*this, PrivateVD, PrivateTy, ELoc); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9545 | ExprResult ReductionOp; |
| 9546 | if (DeclareReductionRef.isUsable()) { |
| 9547 | QualType RedTy = DeclareReductionRef.get()->getType(); |
| 9548 | QualType PtrRedTy = Context.getPointerType(RedTy); |
| 9549 | ExprResult LHS = CreateBuiltinUnaryOp(ELoc, UO_AddrOf, LHSDRE); |
| 9550 | ExprResult RHS = CreateBuiltinUnaryOp(ELoc, UO_AddrOf, RHSDRE); |
| 9551 | if (!BasePath.empty()) { |
| 9552 | LHS = DefaultLvalueConversion(LHS.get()); |
| 9553 | RHS = DefaultLvalueConversion(RHS.get()); |
| 9554 | LHS = ImplicitCastExpr::Create(Context, PtrRedTy, |
| 9555 | CK_UncheckedDerivedToBase, LHS.get(), |
| 9556 | &BasePath, LHS.get()->getValueKind()); |
| 9557 | RHS = ImplicitCastExpr::Create(Context, PtrRedTy, |
| 9558 | CK_UncheckedDerivedToBase, RHS.get(), |
| 9559 | &BasePath, RHS.get()->getValueKind()); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9560 | } |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9561 | FunctionProtoType::ExtProtoInfo EPI; |
| 9562 | QualType Params[] = {PtrRedTy, PtrRedTy}; |
| 9563 | QualType FnTy = Context.getFunctionType(Context.VoidTy, Params, EPI); |
| 9564 | auto *OVE = new (Context) OpaqueValueExpr( |
| 9565 | ELoc, Context.getPointerType(FnTy), VK_RValue, OK_Ordinary, |
| 9566 | DefaultLvalueConversion(DeclareReductionRef.get()).get()); |
| 9567 | Expr *Args[] = {LHS.get(), RHS.get()}; |
| 9568 | ReductionOp = new (Context) |
| 9569 | CallExpr(Context, OVE, Args, Context.VoidTy, VK_RValue, ELoc); |
| 9570 | } else { |
| 9571 | ReductionOp = BuildBinOp(DSAStack->getCurScope(), |
| 9572 | ReductionId.getLocStart(), BOK, LHSDRE, RHSDRE); |
| 9573 | if (ReductionOp.isUsable()) { |
| 9574 | if (BOK != BO_LT && BOK != BO_GT) { |
| 9575 | ReductionOp = |
| 9576 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), |
| 9577 | BO_Assign, LHSDRE, ReductionOp.get()); |
| 9578 | } else { |
| 9579 | auto *ConditionalOp = new (Context) ConditionalOperator( |
| 9580 | ReductionOp.get(), SourceLocation(), LHSDRE, SourceLocation(), |
| 9581 | RHSDRE, Type, VK_LValue, OK_Ordinary); |
| 9582 | ReductionOp = |
| 9583 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), |
| 9584 | BO_Assign, LHSDRE, ConditionalOp); |
| 9585 | } |
| 9586 | ReductionOp = ActOnFinishFullExpr(ReductionOp.get()); |
| 9587 | } |
| 9588 | if (ReductionOp.isInvalid()) |
| 9589 | continue; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9590 | } |
| 9591 | |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9592 | DeclRefExpr *Ref = nullptr; |
| 9593 | Expr *VarsExpr = RefExpr->IgnoreParens(); |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 9594 | if (!VD && !CurContext->isDependentContext()) { |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9595 | if (ASE || OASE) { |
| 9596 | TransformExprToCaptures RebuildToCapture(*this, D); |
| 9597 | VarsExpr = |
| 9598 | RebuildToCapture.TransformExpr(RefExpr->IgnoreParens()).get(); |
| 9599 | Ref = RebuildToCapture.getCapturedExpr(); |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 9600 | } else { |
| 9601 | VarsExpr = Ref = |
| 9602 | buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false); |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 9603 | } |
| 9604 | if (!IsOpenMPCapturedDecl(D)) { |
| 9605 | ExprCaptures.push_back(Ref->getDecl()); |
| 9606 | if (Ref->getDecl()->hasAttr<OMPCaptureNoInitAttr>()) { |
| 9607 | ExprResult RefRes = DefaultLvalueConversion(Ref); |
| 9608 | if (!RefRes.isUsable()) |
| 9609 | continue; |
| 9610 | ExprResult PostUpdateRes = |
| 9611 | BuildBinOp(DSAStack->getCurScope(), ELoc, BO_Assign, |
| 9612 | SimpleRefExpr, RefRes.get()); |
| 9613 | if (!PostUpdateRes.isUsable()) |
| 9614 | continue; |
| 9615 | ExprPostUpdates.push_back( |
| 9616 | IgnoredValueConversions(PostUpdateRes.get()).get()); |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 9617 | } |
| 9618 | } |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9619 | } |
| 9620 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_reduction, Ref); |
| 9621 | Vars.push_back(VarsExpr); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9622 | Privates.push_back(PrivateDRE); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9623 | LHSs.push_back(LHSDRE); |
| 9624 | RHSs.push_back(RHSDRE); |
| 9625 | ReductionOps.push_back(ReductionOp.get()); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9626 | } |
| 9627 | |
| 9628 | if (Vars.empty()) |
| 9629 | return nullptr; |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 9630 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9631 | return OMPReductionClause::Create( |
| 9632 | Context, StartLoc, LParenLoc, ColonLoc, EndLoc, Vars, |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9633 | ReductionIdScopeSpec.getWithLocInContext(Context), ReductionId, Privates, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 9634 | LHSs, RHSs, ReductionOps, buildPreInits(Context, ExprCaptures), |
| 9635 | buildPostUpdate(*this, ExprPostUpdates)); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9636 | } |
| 9637 | |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 9638 | bool Sema::CheckOpenMPLinearModifier(OpenMPLinearClauseKind LinKind, |
| 9639 | SourceLocation LinLoc) { |
| 9640 | if ((!LangOpts.CPlusPlus && LinKind != OMPC_LINEAR_val) || |
| 9641 | LinKind == OMPC_LINEAR_unknown) { |
| 9642 | Diag(LinLoc, diag::err_omp_wrong_linear_modifier) << LangOpts.CPlusPlus; |
| 9643 | return true; |
| 9644 | } |
| 9645 | return false; |
| 9646 | } |
| 9647 | |
| 9648 | bool Sema::CheckOpenMPLinearDecl(ValueDecl *D, SourceLocation ELoc, |
| 9649 | OpenMPLinearClauseKind LinKind, |
| 9650 | QualType Type) { |
| 9651 | auto *VD = dyn_cast_or_null<VarDecl>(D); |
| 9652 | // A variable must not have an incomplete type or a reference type. |
| 9653 | if (RequireCompleteType(ELoc, Type, diag::err_omp_linear_incomplete_type)) |
| 9654 | return true; |
| 9655 | if ((LinKind == OMPC_LINEAR_uval || LinKind == OMPC_LINEAR_ref) && |
| 9656 | !Type->isReferenceType()) { |
| 9657 | Diag(ELoc, diag::err_omp_wrong_linear_modifier_non_reference) |
| 9658 | << Type << getOpenMPSimpleClauseTypeName(OMPC_linear, LinKind); |
| 9659 | return true; |
| 9660 | } |
| 9661 | Type = Type.getNonReferenceType(); |
| 9662 | |
| 9663 | // A list item must not be const-qualified. |
| 9664 | if (Type.isConstant(Context)) { |
| 9665 | Diag(ELoc, diag::err_omp_const_variable) |
| 9666 | << getOpenMPClauseName(OMPC_linear); |
| 9667 | if (D) { |
| 9668 | bool IsDecl = |
| 9669 | !VD || |
| 9670 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 9671 | Diag(D->getLocation(), |
| 9672 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 9673 | << D; |
| 9674 | } |
| 9675 | return true; |
| 9676 | } |
| 9677 | |
| 9678 | // A list item must be of integral or pointer type. |
| 9679 | Type = Type.getUnqualifiedType().getCanonicalType(); |
| 9680 | const auto *Ty = Type.getTypePtrOrNull(); |
| 9681 | if (!Ty || (!Ty->isDependentType() && !Ty->isIntegralType(Context) && |
| 9682 | !Ty->isPointerType())) { |
| 9683 | Diag(ELoc, diag::err_omp_linear_expected_int_or_ptr) << Type; |
| 9684 | if (D) { |
| 9685 | bool IsDecl = |
| 9686 | !VD || |
| 9687 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 9688 | Diag(D->getLocation(), |
| 9689 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 9690 | << D; |
| 9691 | } |
| 9692 | return true; |
| 9693 | } |
| 9694 | return false; |
| 9695 | } |
| 9696 | |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 9697 | OMPClause *Sema::ActOnOpenMPLinearClause( |
| 9698 | ArrayRef<Expr *> VarList, Expr *Step, SourceLocation StartLoc, |
| 9699 | SourceLocation LParenLoc, OpenMPLinearClauseKind LinKind, |
| 9700 | SourceLocation LinLoc, SourceLocation ColonLoc, SourceLocation EndLoc) { |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9701 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 9702 | SmallVector<Expr *, 8> Privates; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9703 | SmallVector<Expr *, 8> Inits; |
Alexey Bataev | 78849fb | 2016-03-09 09:49:00 +0000 | [diff] [blame] | 9704 | SmallVector<Decl *, 4> ExprCaptures; |
| 9705 | SmallVector<Expr *, 4> ExprPostUpdates; |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 9706 | if (CheckOpenMPLinearModifier(LinKind, LinLoc)) |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 9707 | LinKind = OMPC_LINEAR_val; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9708 | for (auto &RefExpr : VarList) { |
| 9709 | assert(RefExpr && "NULL expr in OpenMP linear clause."); |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 9710 | SourceLocation ELoc; |
| 9711 | SourceRange ERange; |
| 9712 | Expr *SimpleRefExpr = RefExpr; |
| 9713 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange, |
| 9714 | /*AllowArraySection=*/false); |
| 9715 | if (Res.second) { |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9716 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9717 | Vars.push_back(RefExpr); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 9718 | Privates.push_back(nullptr); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9719 | Inits.push_back(nullptr); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9720 | } |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 9721 | ValueDecl *D = Res.first; |
| 9722 | if (!D) |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9723 | continue; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9724 | |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 9725 | QualType Type = D->getType(); |
| 9726 | auto *VD = dyn_cast<VarDecl>(D); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9727 | |
| 9728 | // OpenMP [2.14.3.7, linear clause] |
| 9729 | // A list-item cannot appear in more than one linear clause. |
| 9730 | // A list-item that appears in a linear clause cannot appear in any |
| 9731 | // other data-sharing attribute clause. |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 9732 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9733 | if (DVar.RefExpr) { |
| 9734 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 9735 | << getOpenMPClauseName(OMPC_linear); |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 9736 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9737 | continue; |
| 9738 | } |
| 9739 | |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 9740 | if (CheckOpenMPLinearDecl(D, ELoc, LinKind, Type)) |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9741 | continue; |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 9742 | Type = Type.getNonReferenceType().getUnqualifiedType().getCanonicalType(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9743 | |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 9744 | // Build private copy of original var. |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 9745 | auto *Private = buildVarDecl(*this, ELoc, Type, D->getName(), |
| 9746 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 9747 | auto *PrivateRef = buildDeclRefExpr(*this, Private, Type, ELoc); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9748 | // Build var to save initial value. |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 9749 | VarDecl *Init = buildVarDecl(*this, ELoc, Type, ".linear.start"); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 9750 | Expr *InitExpr; |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 9751 | DeclRefExpr *Ref = nullptr; |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 9752 | if (!VD && !CurContext->isDependentContext()) { |
Alexey Bataev | 78849fb | 2016-03-09 09:49:00 +0000 | [diff] [blame] | 9753 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false); |
| 9754 | if (!IsOpenMPCapturedDecl(D)) { |
| 9755 | ExprCaptures.push_back(Ref->getDecl()); |
| 9756 | if (Ref->getDecl()->hasAttr<OMPCaptureNoInitAttr>()) { |
| 9757 | ExprResult RefRes = DefaultLvalueConversion(Ref); |
| 9758 | if (!RefRes.isUsable()) |
| 9759 | continue; |
| 9760 | ExprResult PostUpdateRes = |
| 9761 | BuildBinOp(DSAStack->getCurScope(), ELoc, BO_Assign, |
| 9762 | SimpleRefExpr, RefRes.get()); |
| 9763 | if (!PostUpdateRes.isUsable()) |
| 9764 | continue; |
| 9765 | ExprPostUpdates.push_back( |
| 9766 | IgnoredValueConversions(PostUpdateRes.get()).get()); |
| 9767 | } |
| 9768 | } |
| 9769 | } |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 9770 | if (LinKind == OMPC_LINEAR_uval) |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 9771 | InitExpr = VD ? VD->getInit() : SimpleRefExpr; |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 9772 | else |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 9773 | InitExpr = VD ? SimpleRefExpr : Ref; |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 9774 | AddInitializerToDecl(Init, DefaultLvalueConversion(InitExpr).get(), |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 9775 | /*DirectInit=*/false, /*TypeMayContainAuto=*/false); |
| 9776 | auto InitRef = buildDeclRefExpr(*this, Init, Type, ELoc); |
| 9777 | |
| 9778 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_linear, Ref); |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 9779 | Vars.push_back((VD || CurContext->isDependentContext()) |
| 9780 | ? RefExpr->IgnoreParens() |
| 9781 | : Ref); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 9782 | Privates.push_back(PrivateRef); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9783 | Inits.push_back(InitRef); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9784 | } |
| 9785 | |
| 9786 | if (Vars.empty()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 9787 | return nullptr; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9788 | |
| 9789 | Expr *StepExpr = Step; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9790 | Expr *CalcStepExpr = nullptr; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9791 | if (Step && !Step->isValueDependent() && !Step->isTypeDependent() && |
| 9792 | !Step->isInstantiationDependent() && |
| 9793 | !Step->containsUnexpandedParameterPack()) { |
| 9794 | SourceLocation StepLoc = Step->getLocStart(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 9795 | ExprResult Val = PerformOpenMPImplicitIntegerConversion(StepLoc, Step); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9796 | if (Val.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 9797 | return nullptr; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 9798 | StepExpr = Val.get(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9799 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9800 | // Build var to save the step value. |
| 9801 | VarDecl *SaveVar = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 9802 | buildVarDecl(*this, StepLoc, StepExpr->getType(), ".linear.step"); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9803 | ExprResult SaveRef = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 9804 | buildDeclRefExpr(*this, SaveVar, StepExpr->getType(), StepLoc); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9805 | ExprResult CalcStep = |
| 9806 | BuildBinOp(CurScope, StepLoc, BO_Assign, SaveRef.get(), StepExpr); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 9807 | CalcStep = ActOnFinishFullExpr(CalcStep.get()); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9808 | |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9809 | // Warn about zero linear step (it would be probably better specified as |
| 9810 | // making corresponding variables 'const'). |
| 9811 | llvm::APSInt Result; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9812 | bool IsConstant = StepExpr->isIntegerConstantExpr(Result, Context); |
| 9813 | if (IsConstant && !Result.isNegative() && !Result.isStrictlyPositive()) |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9814 | Diag(StepLoc, diag::warn_omp_linear_step_zero) << Vars[0] |
| 9815 | << (Vars.size() > 1); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9816 | if (!IsConstant && CalcStep.isUsable()) { |
| 9817 | // Calculate the step beforehand instead of doing this on each iteration. |
| 9818 | // (This is not used if the number of iterations may be kfold-ed). |
| 9819 | CalcStepExpr = CalcStep.get(); |
| 9820 | } |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9821 | } |
| 9822 | |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 9823 | return OMPLinearClause::Create(Context, StartLoc, LParenLoc, LinKind, LinLoc, |
| 9824 | ColonLoc, EndLoc, Vars, Privates, Inits, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 9825 | StepExpr, CalcStepExpr, |
| 9826 | buildPreInits(Context, ExprCaptures), |
| 9827 | buildPostUpdate(*this, ExprPostUpdates)); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9828 | } |
| 9829 | |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 9830 | static bool FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV, |
| 9831 | Expr *NumIterations, Sema &SemaRef, |
| 9832 | Scope *S, DSAStackTy *Stack) { |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9833 | // Walk the vars and build update/final expressions for the CodeGen. |
| 9834 | SmallVector<Expr *, 8> Updates; |
| 9835 | SmallVector<Expr *, 8> Finals; |
| 9836 | Expr *Step = Clause.getStep(); |
| 9837 | Expr *CalcStep = Clause.getCalcStep(); |
| 9838 | // OpenMP [2.14.3.7, linear clause] |
| 9839 | // If linear-step is not specified it is assumed to be 1. |
| 9840 | if (Step == nullptr) |
| 9841 | Step = SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get(); |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 9842 | else if (CalcStep) { |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9843 | Step = cast<BinaryOperator>(CalcStep)->getLHS(); |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 9844 | } |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9845 | bool HasErrors = false; |
| 9846 | auto CurInit = Clause.inits().begin(); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 9847 | auto CurPrivate = Clause.privates().begin(); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 9848 | auto LinKind = Clause.getModifier(); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9849 | for (auto &RefExpr : Clause.varlists()) { |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 9850 | SourceLocation ELoc; |
| 9851 | SourceRange ERange; |
| 9852 | Expr *SimpleRefExpr = RefExpr; |
| 9853 | auto Res = getPrivateItem(SemaRef, SimpleRefExpr, ELoc, ERange, |
| 9854 | /*AllowArraySection=*/false); |
| 9855 | ValueDecl *D = Res.first; |
| 9856 | if (Res.second || !D) { |
| 9857 | Updates.push_back(nullptr); |
| 9858 | Finals.push_back(nullptr); |
| 9859 | HasErrors = true; |
| 9860 | continue; |
| 9861 | } |
| 9862 | if (auto *CED = dyn_cast<OMPCapturedExprDecl>(D)) { |
| 9863 | D = cast<MemberExpr>(CED->getInit()->IgnoreParenImpCasts()) |
| 9864 | ->getMemberDecl(); |
| 9865 | } |
| 9866 | auto &&Info = Stack->isLoopControlVariable(D); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9867 | Expr *InitExpr = *CurInit; |
| 9868 | |
| 9869 | // Build privatized reference to the current linear var. |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 9870 | auto DE = cast<DeclRefExpr>(SimpleRefExpr); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 9871 | Expr *CapturedRef; |
| 9872 | if (LinKind == OMPC_LINEAR_uval) |
| 9873 | CapturedRef = cast<VarDecl>(DE->getDecl())->getInit(); |
| 9874 | else |
| 9875 | CapturedRef = |
| 9876 | buildDeclRefExpr(SemaRef, cast<VarDecl>(DE->getDecl()), |
| 9877 | DE->getType().getUnqualifiedType(), DE->getExprLoc(), |
| 9878 | /*RefersToCapture=*/true); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9879 | |
| 9880 | // Build update: Var = InitExpr + IV * Step |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 9881 | ExprResult Update; |
| 9882 | if (!Info.first) { |
| 9883 | Update = |
| 9884 | BuildCounterUpdate(SemaRef, S, RefExpr->getExprLoc(), *CurPrivate, |
| 9885 | InitExpr, IV, Step, /* Subtract */ false); |
| 9886 | } else |
| 9887 | Update = *CurPrivate; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 9888 | Update = SemaRef.ActOnFinishFullExpr(Update.get(), DE->getLocStart(), |
| 9889 | /*DiscardedValue=*/true); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9890 | |
| 9891 | // Build final: Var = InitExpr + NumIterations * Step |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 9892 | ExprResult Final; |
| 9893 | if (!Info.first) { |
| 9894 | Final = BuildCounterUpdate(SemaRef, S, RefExpr->getExprLoc(), CapturedRef, |
| 9895 | InitExpr, NumIterations, Step, |
| 9896 | /* Subtract */ false); |
| 9897 | } else |
| 9898 | Final = *CurPrivate; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 9899 | Final = SemaRef.ActOnFinishFullExpr(Final.get(), DE->getLocStart(), |
| 9900 | /*DiscardedValue=*/true); |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 9901 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9902 | if (!Update.isUsable() || !Final.isUsable()) { |
| 9903 | Updates.push_back(nullptr); |
| 9904 | Finals.push_back(nullptr); |
| 9905 | HasErrors = true; |
| 9906 | } else { |
| 9907 | Updates.push_back(Update.get()); |
| 9908 | Finals.push_back(Final.get()); |
| 9909 | } |
Richard Trieu | cc3949d | 2016-02-18 22:34:54 +0000 | [diff] [blame] | 9910 | ++CurInit; |
| 9911 | ++CurPrivate; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9912 | } |
| 9913 | Clause.setUpdates(Updates); |
| 9914 | Clause.setFinals(Finals); |
| 9915 | return HasErrors; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9916 | } |
| 9917 | |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9918 | OMPClause *Sema::ActOnOpenMPAlignedClause( |
| 9919 | ArrayRef<Expr *> VarList, Expr *Alignment, SourceLocation StartLoc, |
| 9920 | SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc) { |
| 9921 | |
| 9922 | SmallVector<Expr *, 8> Vars; |
| 9923 | for (auto &RefExpr : VarList) { |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 9924 | assert(RefExpr && "NULL expr in OpenMP linear clause."); |
| 9925 | SourceLocation ELoc; |
| 9926 | SourceRange ERange; |
| 9927 | Expr *SimpleRefExpr = RefExpr; |
| 9928 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange, |
| 9929 | /*AllowArraySection=*/false); |
| 9930 | if (Res.second) { |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9931 | // It will be analyzed later. |
| 9932 | Vars.push_back(RefExpr); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9933 | } |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 9934 | ValueDecl *D = Res.first; |
| 9935 | if (!D) |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9936 | continue; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9937 | |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 9938 | QualType QType = D->getType(); |
| 9939 | auto *VD = dyn_cast<VarDecl>(D); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9940 | |
| 9941 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 9942 | // The type of list items appearing in the aligned clause must be |
| 9943 | // array, pointer, reference to array, or reference to pointer. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 9944 | QType = QType.getNonReferenceType().getUnqualifiedType().getCanonicalType(); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9945 | const Type *Ty = QType.getTypePtrOrNull(); |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 9946 | if (!Ty || (!Ty->isArrayType() && !Ty->isPointerType())) { |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9947 | Diag(ELoc, diag::err_omp_aligned_expected_array_or_ptr) |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 9948 | << QType << getLangOpts().CPlusPlus << ERange; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9949 | bool IsDecl = |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 9950 | !VD || |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9951 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 9952 | Diag(D->getLocation(), |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9953 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 9954 | << D; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9955 | continue; |
| 9956 | } |
| 9957 | |
| 9958 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 9959 | // A list-item cannot appear in more than one aligned clause. |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 9960 | if (Expr *PrevRef = DSAStack->addUniqueAligned(D, SimpleRefExpr)) { |
Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 9961 | Diag(ELoc, diag::err_omp_aligned_twice) << 0 << ERange; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9962 | Diag(PrevRef->getExprLoc(), diag::note_omp_explicit_dsa) |
| 9963 | << getOpenMPClauseName(OMPC_aligned); |
| 9964 | continue; |
| 9965 | } |
| 9966 | |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 9967 | DeclRefExpr *Ref = nullptr; |
| 9968 | if (!VD && IsOpenMPCapturedDecl(D)) |
| 9969 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/true); |
| 9970 | Vars.push_back(DefaultFunctionArrayConversion( |
| 9971 | (VD || !Ref) ? RefExpr->IgnoreParens() : Ref) |
| 9972 | .get()); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9973 | } |
| 9974 | |
| 9975 | // OpenMP [2.8.1, simd construct, Description] |
| 9976 | // The parameter of the aligned clause, alignment, must be a constant |
| 9977 | // positive integer expression. |
| 9978 | // If no optional parameter is specified, implementation-defined default |
| 9979 | // alignments for SIMD instructions on the target platforms are assumed. |
| 9980 | if (Alignment != nullptr) { |
| 9981 | ExprResult AlignResult = |
| 9982 | VerifyPositiveIntegerConstantInClause(Alignment, OMPC_aligned); |
| 9983 | if (AlignResult.isInvalid()) |
| 9984 | return nullptr; |
| 9985 | Alignment = AlignResult.get(); |
| 9986 | } |
| 9987 | if (Vars.empty()) |
| 9988 | return nullptr; |
| 9989 | |
| 9990 | return OMPAlignedClause::Create(Context, StartLoc, LParenLoc, ColonLoc, |
| 9991 | EndLoc, Vars, Alignment); |
| 9992 | } |
| 9993 | |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9994 | OMPClause *Sema::ActOnOpenMPCopyinClause(ArrayRef<Expr *> VarList, |
| 9995 | SourceLocation StartLoc, |
| 9996 | SourceLocation LParenLoc, |
| 9997 | SourceLocation EndLoc) { |
| 9998 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 9999 | SmallVector<Expr *, 8> SrcExprs; |
| 10000 | SmallVector<Expr *, 8> DstExprs; |
| 10001 | SmallVector<Expr *, 8> AssignmentOps; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 10002 | for (auto &RefExpr : VarList) { |
| 10003 | assert(RefExpr && "NULL expr in OpenMP copyin clause."); |
| 10004 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 10005 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 10006 | Vars.push_back(RefExpr); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 10007 | SrcExprs.push_back(nullptr); |
| 10008 | DstExprs.push_back(nullptr); |
| 10009 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 10010 | continue; |
| 10011 | } |
| 10012 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 10013 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 10014 | // OpenMP [2.1, C/C++] |
| 10015 | // A list item is a variable name. |
| 10016 | // OpenMP [2.14.4.1, Restrictions, p.1] |
| 10017 | // A list item that appears in a copyin clause must be threadprivate. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 10018 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 10019 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 10020 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr) |
| 10021 | << 0 << RefExpr->getSourceRange(); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 10022 | continue; |
| 10023 | } |
| 10024 | |
| 10025 | Decl *D = DE->getDecl(); |
| 10026 | VarDecl *VD = cast<VarDecl>(D); |
| 10027 | |
| 10028 | QualType Type = VD->getType(); |
| 10029 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 10030 | // It will be analyzed later. |
| 10031 | Vars.push_back(DE); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 10032 | SrcExprs.push_back(nullptr); |
| 10033 | DstExprs.push_back(nullptr); |
| 10034 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 10035 | continue; |
| 10036 | } |
| 10037 | |
| 10038 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.1] |
| 10039 | // A list item that appears in a copyin clause must be threadprivate. |
| 10040 | if (!DSAStack->isThreadPrivate(VD)) { |
| 10041 | Diag(ELoc, diag::err_omp_required_access) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 10042 | << getOpenMPClauseName(OMPC_copyin) |
| 10043 | << getOpenMPDirectiveName(OMPD_threadprivate); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 10044 | continue; |
| 10045 | } |
| 10046 | |
| 10047 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.2] |
| 10048 | // A variable of class type (or array thereof) that appears in a |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 10049 | // copyin clause requires an accessible, unambiguous copy assignment |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 10050 | // operator for the class type. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 10051 | auto ElemType = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 10052 | auto *SrcVD = |
| 10053 | buildVarDecl(*this, DE->getLocStart(), ElemType.getUnqualifiedType(), |
| 10054 | ".copyin.src", VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 10055 | auto *PseudoSrcExpr = buildDeclRefExpr( |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 10056 | *this, SrcVD, ElemType.getUnqualifiedType(), DE->getExprLoc()); |
| 10057 | auto *DstVD = |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 10058 | buildVarDecl(*this, DE->getLocStart(), ElemType, ".copyin.dst", |
| 10059 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 10060 | auto *PseudoDstExpr = |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 10061 | buildDeclRefExpr(*this, DstVD, ElemType, DE->getExprLoc()); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 10062 | // For arrays generate assignment operation for single element and replace |
| 10063 | // it by the original array element in CodeGen. |
| 10064 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, DE->getExprLoc(), BO_Assign, |
| 10065 | PseudoDstExpr, PseudoSrcExpr); |
| 10066 | if (AssignmentOp.isInvalid()) |
| 10067 | continue; |
| 10068 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), DE->getExprLoc(), |
| 10069 | /*DiscardedValue=*/true); |
| 10070 | if (AssignmentOp.isInvalid()) |
| 10071 | continue; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 10072 | |
| 10073 | DSAStack->addDSA(VD, DE, OMPC_copyin); |
| 10074 | Vars.push_back(DE); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 10075 | SrcExprs.push_back(PseudoSrcExpr); |
| 10076 | DstExprs.push_back(PseudoDstExpr); |
| 10077 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 10078 | } |
| 10079 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 10080 | if (Vars.empty()) |
| 10081 | return nullptr; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 10082 | |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 10083 | return OMPCopyinClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
| 10084 | SrcExprs, DstExprs, AssignmentOps); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 10085 | } |
| 10086 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 10087 | OMPClause *Sema::ActOnOpenMPCopyprivateClause(ArrayRef<Expr *> VarList, |
| 10088 | SourceLocation StartLoc, |
| 10089 | SourceLocation LParenLoc, |
| 10090 | SourceLocation EndLoc) { |
| 10091 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 10092 | SmallVector<Expr *, 8> SrcExprs; |
| 10093 | SmallVector<Expr *, 8> DstExprs; |
| 10094 | SmallVector<Expr *, 8> AssignmentOps; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 10095 | for (auto &RefExpr : VarList) { |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 10096 | assert(RefExpr && "NULL expr in OpenMP linear clause."); |
| 10097 | SourceLocation ELoc; |
| 10098 | SourceRange ERange; |
| 10099 | Expr *SimpleRefExpr = RefExpr; |
| 10100 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange, |
| 10101 | /*AllowArraySection=*/false); |
| 10102 | if (Res.second) { |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 10103 | // It will be analyzed later. |
| 10104 | Vars.push_back(RefExpr); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 10105 | SrcExprs.push_back(nullptr); |
| 10106 | DstExprs.push_back(nullptr); |
| 10107 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 10108 | } |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 10109 | ValueDecl *D = Res.first; |
| 10110 | if (!D) |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 10111 | continue; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 10112 | |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 10113 | QualType Type = D->getType(); |
| 10114 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 10115 | |
| 10116 | // OpenMP [2.14.4.2, Restrictions, p.2] |
| 10117 | // A list item that appears in a copyprivate clause may not appear in a |
| 10118 | // private or firstprivate clause on the single construct. |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 10119 | if (!VD || !DSAStack->isThreadPrivate(VD)) { |
| 10120 | auto DVar = DSAStack->getTopDSA(D, false); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 10121 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_copyprivate && |
| 10122 | DVar.RefExpr) { |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 10123 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 10124 | << getOpenMPClauseName(DVar.CKind) |
| 10125 | << getOpenMPClauseName(OMPC_copyprivate); |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 10126 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 10127 | continue; |
| 10128 | } |
| 10129 | |
| 10130 | // OpenMP [2.11.4.2, Restrictions, p.1] |
| 10131 | // All list items that appear in a copyprivate clause must be either |
| 10132 | // threadprivate or private in the enclosing context. |
| 10133 | if (DVar.CKind == OMPC_unknown) { |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 10134 | DVar = DSAStack->getImplicitDSA(D, false); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 10135 | if (DVar.CKind == OMPC_shared) { |
| 10136 | Diag(ELoc, diag::err_omp_required_access) |
| 10137 | << getOpenMPClauseName(OMPC_copyprivate) |
| 10138 | << "threadprivate or private in the enclosing context"; |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 10139 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 10140 | continue; |
| 10141 | } |
| 10142 | } |
| 10143 | } |
| 10144 | |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 10145 | // Variably modified types are not supported. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 10146 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType()) { |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 10147 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 10148 | << getOpenMPClauseName(OMPC_copyprivate) << Type |
| 10149 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 10150 | bool IsDecl = |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 10151 | !VD || |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 10152 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 10153 | Diag(D->getLocation(), |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 10154 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 10155 | << D; |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 10156 | continue; |
| 10157 | } |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 10158 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 10159 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.2] |
| 10160 | // A variable of class type (or array thereof) that appears in a |
| 10161 | // copyin clause requires an accessible, unambiguous copy assignment |
| 10162 | // operator for the class type. |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 10163 | Type = Context.getBaseElementType(Type.getNonReferenceType()) |
| 10164 | .getUnqualifiedType(); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 10165 | auto *SrcVD = |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 10166 | buildVarDecl(*this, RefExpr->getLocStart(), Type, ".copyprivate.src", |
| 10167 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 10168 | auto *PseudoSrcExpr = buildDeclRefExpr(*this, SrcVD, Type, ELoc); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 10169 | auto *DstVD = |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 10170 | buildVarDecl(*this, RefExpr->getLocStart(), Type, ".copyprivate.dst", |
| 10171 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 10172 | auto *PseudoDstExpr = |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 10173 | buildDeclRefExpr(*this, DstVD, Type, ELoc); |
| 10174 | auto AssignmentOp = BuildBinOp(DSAStack->getCurScope(), ELoc, BO_Assign, |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 10175 | PseudoDstExpr, PseudoSrcExpr); |
| 10176 | if (AssignmentOp.isInvalid()) |
| 10177 | continue; |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 10178 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), ELoc, |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 10179 | /*DiscardedValue=*/true); |
| 10180 | if (AssignmentOp.isInvalid()) |
| 10181 | continue; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 10182 | |
| 10183 | // No need to mark vars as copyprivate, they are already threadprivate or |
| 10184 | // implicitly private. |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 10185 | assert(VD || IsOpenMPCapturedDecl(D)); |
| 10186 | Vars.push_back( |
| 10187 | VD ? RefExpr->IgnoreParens() |
| 10188 | : buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false)); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 10189 | SrcExprs.push_back(PseudoSrcExpr); |
| 10190 | DstExprs.push_back(PseudoDstExpr); |
| 10191 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 10192 | } |
| 10193 | |
| 10194 | if (Vars.empty()) |
| 10195 | return nullptr; |
| 10196 | |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 10197 | return OMPCopyprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| 10198 | Vars, SrcExprs, DstExprs, AssignmentOps); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 10199 | } |
| 10200 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 10201 | OMPClause *Sema::ActOnOpenMPFlushClause(ArrayRef<Expr *> VarList, |
| 10202 | SourceLocation StartLoc, |
| 10203 | SourceLocation LParenLoc, |
| 10204 | SourceLocation EndLoc) { |
| 10205 | if (VarList.empty()) |
| 10206 | return nullptr; |
| 10207 | |
| 10208 | return OMPFlushClause::Create(Context, StartLoc, LParenLoc, EndLoc, VarList); |
| 10209 | } |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 10210 | |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 10211 | OMPClause * |
| 10212 | Sema::ActOnOpenMPDependClause(OpenMPDependClauseKind DepKind, |
| 10213 | SourceLocation DepLoc, SourceLocation ColonLoc, |
| 10214 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
| 10215 | SourceLocation LParenLoc, SourceLocation EndLoc) { |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 10216 | if (DSAStack->getCurrentDirective() == OMPD_ordered && |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 10217 | DepKind != OMPC_DEPEND_source && DepKind != OMPC_DEPEND_sink) { |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 10218 | Diag(DepLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 10219 | << "'source' or 'sink'" << getOpenMPClauseName(OMPC_depend); |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 10220 | return nullptr; |
| 10221 | } |
| 10222 | if (DSAStack->getCurrentDirective() != OMPD_ordered && |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 10223 | (DepKind == OMPC_DEPEND_unknown || DepKind == OMPC_DEPEND_source || |
| 10224 | DepKind == OMPC_DEPEND_sink)) { |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 10225 | unsigned Except[] = {OMPC_DEPEND_source, OMPC_DEPEND_sink}; |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 10226 | Diag(DepLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 10227 | << getListOfPossibleValues(OMPC_depend, /*First=*/0, |
| 10228 | /*Last=*/OMPC_DEPEND_unknown, Except) |
| 10229 | << getOpenMPClauseName(OMPC_depend); |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 10230 | return nullptr; |
| 10231 | } |
| 10232 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 10233 | DSAStackTy::OperatorOffsetTy OpsOffs; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 10234 | llvm::APSInt DepCounter(/*BitWidth=*/32); |
| 10235 | llvm::APSInt TotalDepCount(/*BitWidth=*/32); |
| 10236 | if (DepKind == OMPC_DEPEND_sink) { |
| 10237 | if (auto *OrderedCountExpr = DSAStack->getParentOrderedRegionParam()) { |
| 10238 | TotalDepCount = OrderedCountExpr->EvaluateKnownConstInt(Context); |
| 10239 | TotalDepCount.setIsUnsigned(/*Val=*/true); |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 10240 | } |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 10241 | } |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 10242 | if ((DepKind != OMPC_DEPEND_sink && DepKind != OMPC_DEPEND_source) || |
| 10243 | DSAStack->getParentOrderedRegionParam()) { |
| 10244 | for (auto &RefExpr : VarList) { |
| 10245 | assert(RefExpr && "NULL expr in OpenMP shared clause."); |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 10246 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 10247 | // It will be analyzed later. |
| 10248 | Vars.push_back(RefExpr); |
| 10249 | continue; |
| 10250 | } |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 10251 | |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 10252 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 10253 | auto *SimpleExpr = RefExpr->IgnoreParenCasts(); |
| 10254 | if (DepKind == OMPC_DEPEND_sink) { |
| 10255 | if (DepCounter >= TotalDepCount) { |
| 10256 | Diag(ELoc, diag::err_omp_depend_sink_unexpected_expr); |
| 10257 | continue; |
| 10258 | } |
| 10259 | ++DepCounter; |
| 10260 | // OpenMP [2.13.9, Summary] |
| 10261 | // depend(dependence-type : vec), where dependence-type is: |
| 10262 | // 'sink' and where vec is the iteration vector, which has the form: |
| 10263 | // x1 [+- d1], x2 [+- d2 ], . . . , xn [+- dn] |
| 10264 | // where n is the value specified by the ordered clause in the loop |
| 10265 | // directive, xi denotes the loop iteration variable of the i-th nested |
| 10266 | // loop associated with the loop directive, and di is a constant |
| 10267 | // non-negative integer. |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 10268 | if (CurContext->isDependentContext()) { |
| 10269 | // It will be analyzed later. |
| 10270 | Vars.push_back(RefExpr); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 10271 | continue; |
| 10272 | } |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 10273 | SimpleExpr = SimpleExpr->IgnoreImplicit(); |
| 10274 | OverloadedOperatorKind OOK = OO_None; |
| 10275 | SourceLocation OOLoc; |
| 10276 | Expr *LHS = SimpleExpr; |
| 10277 | Expr *RHS = nullptr; |
| 10278 | if (auto *BO = dyn_cast<BinaryOperator>(SimpleExpr)) { |
| 10279 | OOK = BinaryOperator::getOverloadedOperator(BO->getOpcode()); |
| 10280 | OOLoc = BO->getOperatorLoc(); |
| 10281 | LHS = BO->getLHS()->IgnoreParenImpCasts(); |
| 10282 | RHS = BO->getRHS()->IgnoreParenImpCasts(); |
| 10283 | } else if (auto *OCE = dyn_cast<CXXOperatorCallExpr>(SimpleExpr)) { |
| 10284 | OOK = OCE->getOperator(); |
| 10285 | OOLoc = OCE->getOperatorLoc(); |
| 10286 | LHS = OCE->getArg(/*Arg=*/0)->IgnoreParenImpCasts(); |
| 10287 | RHS = OCE->getArg(/*Arg=*/1)->IgnoreParenImpCasts(); |
| 10288 | } else if (auto *MCE = dyn_cast<CXXMemberCallExpr>(SimpleExpr)) { |
| 10289 | OOK = MCE->getMethodDecl() |
| 10290 | ->getNameInfo() |
| 10291 | .getName() |
| 10292 | .getCXXOverloadedOperator(); |
| 10293 | OOLoc = MCE->getCallee()->getExprLoc(); |
| 10294 | LHS = MCE->getImplicitObjectArgument()->IgnoreParenImpCasts(); |
| 10295 | RHS = MCE->getArg(/*Arg=*/0)->IgnoreParenImpCasts(); |
| 10296 | } |
| 10297 | SourceLocation ELoc; |
| 10298 | SourceRange ERange; |
| 10299 | auto Res = getPrivateItem(*this, LHS, ELoc, ERange, |
| 10300 | /*AllowArraySection=*/false); |
| 10301 | if (Res.second) { |
| 10302 | // It will be analyzed later. |
| 10303 | Vars.push_back(RefExpr); |
| 10304 | } |
| 10305 | ValueDecl *D = Res.first; |
| 10306 | if (!D) |
| 10307 | continue; |
| 10308 | |
| 10309 | if (OOK != OO_Plus && OOK != OO_Minus && (RHS || OOK != OO_None)) { |
| 10310 | Diag(OOLoc, diag::err_omp_depend_sink_expected_plus_minus); |
| 10311 | continue; |
| 10312 | } |
| 10313 | if (RHS) { |
| 10314 | ExprResult RHSRes = VerifyPositiveIntegerConstantInClause( |
| 10315 | RHS, OMPC_depend, /*StrictlyPositive=*/false); |
| 10316 | if (RHSRes.isInvalid()) |
| 10317 | continue; |
| 10318 | } |
| 10319 | if (!CurContext->isDependentContext() && |
| 10320 | DSAStack->getParentOrderedRegionParam() && |
| 10321 | DepCounter != DSAStack->isParentLoopControlVariable(D).first) { |
| 10322 | Diag(ELoc, diag::err_omp_depend_sink_expected_loop_iteration) |
| 10323 | << DSAStack->getParentLoopControlVariable( |
| 10324 | DepCounter.getZExtValue()); |
| 10325 | continue; |
| 10326 | } |
| 10327 | OpsOffs.push_back({RHS, OOK}); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 10328 | } else { |
| 10329 | // OpenMP [2.11.1.1, Restrictions, p.3] |
| 10330 | // A variable that is part of another variable (such as a field of a |
| 10331 | // structure) but is not an array element or an array section cannot |
| 10332 | // appear in a depend clause. |
| 10333 | auto *DE = dyn_cast<DeclRefExpr>(SimpleExpr); |
| 10334 | auto *ASE = dyn_cast<ArraySubscriptExpr>(SimpleExpr); |
| 10335 | auto *OASE = dyn_cast<OMPArraySectionExpr>(SimpleExpr); |
| 10336 | if (!RefExpr->IgnoreParenImpCasts()->isLValue() || |
| 10337 | (!ASE && !DE && !OASE) || (DE && !isa<VarDecl>(DE->getDecl())) || |
Alexey Bataev | 31300ed | 2016-02-04 11:27:03 +0000 | [diff] [blame] | 10338 | (ASE && |
| 10339 | !ASE->getBase() |
| 10340 | ->getType() |
| 10341 | .getNonReferenceType() |
| 10342 | ->isPointerType() && |
| 10343 | !ASE->getBase()->getType().getNonReferenceType()->isArrayType())) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 10344 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr_or_array_item) |
| 10345 | << 0 << RefExpr->getSourceRange(); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 10346 | continue; |
| 10347 | } |
| 10348 | } |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 10349 | Vars.push_back(RefExpr->IgnoreParenImpCasts()); |
| 10350 | } |
| 10351 | |
| 10352 | if (!CurContext->isDependentContext() && DepKind == OMPC_DEPEND_sink && |
| 10353 | TotalDepCount > VarList.size() && |
| 10354 | DSAStack->getParentOrderedRegionParam()) { |
| 10355 | Diag(EndLoc, diag::err_omp_depend_sink_expected_loop_iteration) |
| 10356 | << DSAStack->getParentLoopControlVariable(VarList.size() + 1); |
| 10357 | } |
| 10358 | if (DepKind != OMPC_DEPEND_source && DepKind != OMPC_DEPEND_sink && |
| 10359 | Vars.empty()) |
| 10360 | return nullptr; |
| 10361 | } |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 10362 | auto *C = OMPDependClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| 10363 | DepKind, DepLoc, ColonLoc, Vars); |
| 10364 | if (DepKind == OMPC_DEPEND_sink || DepKind == OMPC_DEPEND_source) |
| 10365 | DSAStack->addDoacrossDependClause(C, OpsOffs); |
| 10366 | return C; |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 10367 | } |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 10368 | |
| 10369 | OMPClause *Sema::ActOnOpenMPDeviceClause(Expr *Device, SourceLocation StartLoc, |
| 10370 | SourceLocation LParenLoc, |
| 10371 | SourceLocation EndLoc) { |
| 10372 | Expr *ValExpr = Device; |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 10373 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 10374 | // OpenMP [2.9.1, Restrictions] |
| 10375 | // The device expression must evaluate to a non-negative integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 10376 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_device, |
| 10377 | /*StrictlyPositive=*/false)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 10378 | return nullptr; |
| 10379 | |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 10380 | return new (Context) OMPDeviceClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 10381 | } |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10382 | |
| 10383 | static bool IsCXXRecordForMappable(Sema &SemaRef, SourceLocation Loc, |
| 10384 | DSAStackTy *Stack, CXXRecordDecl *RD) { |
| 10385 | if (!RD || RD->isInvalidDecl()) |
| 10386 | return true; |
| 10387 | |
Alexey Bataev | c9bd03d | 2015-12-17 06:55:08 +0000 | [diff] [blame] | 10388 | if (auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(RD)) |
| 10389 | if (auto *CTD = CTSD->getSpecializedTemplate()) |
| 10390 | RD = CTD->getTemplatedDecl(); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10391 | auto QTy = SemaRef.Context.getRecordType(RD); |
| 10392 | if (RD->isDynamicClass()) { |
| 10393 | SemaRef.Diag(Loc, diag::err_omp_not_mappable_type) << QTy; |
| 10394 | SemaRef.Diag(RD->getLocation(), diag::note_omp_polymorphic_in_target); |
| 10395 | return false; |
| 10396 | } |
| 10397 | auto *DC = RD; |
| 10398 | bool IsCorrect = true; |
| 10399 | for (auto *I : DC->decls()) { |
| 10400 | if (I) { |
| 10401 | if (auto *MD = dyn_cast<CXXMethodDecl>(I)) { |
| 10402 | if (MD->isStatic()) { |
| 10403 | SemaRef.Diag(Loc, diag::err_omp_not_mappable_type) << QTy; |
| 10404 | SemaRef.Diag(MD->getLocation(), |
| 10405 | diag::note_omp_static_member_in_target); |
| 10406 | IsCorrect = false; |
| 10407 | } |
| 10408 | } else if (auto *VD = dyn_cast<VarDecl>(I)) { |
| 10409 | if (VD->isStaticDataMember()) { |
| 10410 | SemaRef.Diag(Loc, diag::err_omp_not_mappable_type) << QTy; |
| 10411 | SemaRef.Diag(VD->getLocation(), |
| 10412 | diag::note_omp_static_member_in_target); |
| 10413 | IsCorrect = false; |
| 10414 | } |
| 10415 | } |
| 10416 | } |
| 10417 | } |
| 10418 | |
| 10419 | for (auto &I : RD->bases()) { |
| 10420 | if (!IsCXXRecordForMappable(SemaRef, I.getLocStart(), Stack, |
| 10421 | I.getType()->getAsCXXRecordDecl())) |
| 10422 | IsCorrect = false; |
| 10423 | } |
| 10424 | return IsCorrect; |
| 10425 | } |
| 10426 | |
| 10427 | static bool CheckTypeMappable(SourceLocation SL, SourceRange SR, Sema &SemaRef, |
| 10428 | DSAStackTy *Stack, QualType QTy) { |
| 10429 | NamedDecl *ND; |
| 10430 | if (QTy->isIncompleteType(&ND)) { |
| 10431 | SemaRef.Diag(SL, diag::err_incomplete_type) << QTy << SR; |
| 10432 | return false; |
| 10433 | } else if (CXXRecordDecl *RD = dyn_cast_or_null<CXXRecordDecl>(ND)) { |
| 10434 | if (!RD->isInvalidDecl() && |
| 10435 | !IsCXXRecordForMappable(SemaRef, SL, Stack, RD)) |
| 10436 | return false; |
| 10437 | } |
| 10438 | return true; |
| 10439 | } |
| 10440 | |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 10441 | /// \brief Return true if it can be proven that the provided array expression |
| 10442 | /// (array section or array subscript) does NOT specify the whole size of the |
| 10443 | /// array whose base type is \a BaseQTy. |
| 10444 | static bool CheckArrayExpressionDoesNotReferToWholeSize(Sema &SemaRef, |
| 10445 | const Expr *E, |
| 10446 | QualType BaseQTy) { |
| 10447 | auto *OASE = dyn_cast<OMPArraySectionExpr>(E); |
| 10448 | |
| 10449 | // If this is an array subscript, it refers to the whole size if the size of |
| 10450 | // the dimension is constant and equals 1. Also, an array section assumes the |
| 10451 | // format of an array subscript if no colon is used. |
| 10452 | if (isa<ArraySubscriptExpr>(E) || (OASE && OASE->getColonLoc().isInvalid())) { |
| 10453 | if (auto *ATy = dyn_cast<ConstantArrayType>(BaseQTy.getTypePtr())) |
| 10454 | return ATy->getSize().getSExtValue() != 1; |
| 10455 | // Size can't be evaluated statically. |
| 10456 | return false; |
| 10457 | } |
| 10458 | |
| 10459 | assert(OASE && "Expecting array section if not an array subscript."); |
| 10460 | auto *LowerBound = OASE->getLowerBound(); |
| 10461 | auto *Length = OASE->getLength(); |
| 10462 | |
| 10463 | // If there is a lower bound that does not evaluates to zero, we are not |
| 10464 | // convering the whole dimension. |
| 10465 | if (LowerBound) { |
| 10466 | llvm::APSInt ConstLowerBound; |
| 10467 | if (!LowerBound->EvaluateAsInt(ConstLowerBound, SemaRef.getASTContext())) |
| 10468 | return false; // Can't get the integer value as a constant. |
| 10469 | if (ConstLowerBound.getSExtValue()) |
| 10470 | return true; |
| 10471 | } |
| 10472 | |
| 10473 | // If we don't have a length we covering the whole dimension. |
| 10474 | if (!Length) |
| 10475 | return false; |
| 10476 | |
| 10477 | // If the base is a pointer, we don't have a way to get the size of the |
| 10478 | // pointee. |
| 10479 | if (BaseQTy->isPointerType()) |
| 10480 | return false; |
| 10481 | |
| 10482 | // We can only check if the length is the same as the size of the dimension |
| 10483 | // if we have a constant array. |
| 10484 | auto *CATy = dyn_cast<ConstantArrayType>(BaseQTy.getTypePtr()); |
| 10485 | if (!CATy) |
| 10486 | return false; |
| 10487 | |
| 10488 | llvm::APSInt ConstLength; |
| 10489 | if (!Length->EvaluateAsInt(ConstLength, SemaRef.getASTContext())) |
| 10490 | return false; // Can't get the integer value as a constant. |
| 10491 | |
| 10492 | return CATy->getSize().getSExtValue() != ConstLength.getSExtValue(); |
| 10493 | } |
| 10494 | |
| 10495 | // Return true if it can be proven that the provided array expression (array |
| 10496 | // section or array subscript) does NOT specify a single element of the array |
| 10497 | // whose base type is \a BaseQTy. |
| 10498 | static bool CheckArrayExpressionDoesNotReferToUnitySize(Sema &SemaRef, |
| 10499 | const Expr *E, |
| 10500 | QualType BaseQTy) { |
| 10501 | auto *OASE = dyn_cast<OMPArraySectionExpr>(E); |
| 10502 | |
| 10503 | // An array subscript always refer to a single element. Also, an array section |
| 10504 | // assumes the format of an array subscript if no colon is used. |
| 10505 | if (isa<ArraySubscriptExpr>(E) || (OASE && OASE->getColonLoc().isInvalid())) |
| 10506 | return false; |
| 10507 | |
| 10508 | assert(OASE && "Expecting array section if not an array subscript."); |
| 10509 | auto *Length = OASE->getLength(); |
| 10510 | |
| 10511 | // If we don't have a length we have to check if the array has unitary size |
| 10512 | // for this dimension. Also, we should always expect a length if the base type |
| 10513 | // is pointer. |
| 10514 | if (!Length) { |
| 10515 | if (auto *ATy = dyn_cast<ConstantArrayType>(BaseQTy.getTypePtr())) |
| 10516 | return ATy->getSize().getSExtValue() != 1; |
| 10517 | // We cannot assume anything. |
| 10518 | return false; |
| 10519 | } |
| 10520 | |
| 10521 | // Check if the length evaluates to 1. |
| 10522 | llvm::APSInt ConstLength; |
| 10523 | if (!Length->EvaluateAsInt(ConstLength, SemaRef.getASTContext())) |
| 10524 | return false; // Can't get the integer value as a constant. |
| 10525 | |
| 10526 | return ConstLength.getSExtValue() != 1; |
| 10527 | } |
| 10528 | |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10529 | // Return the expression of the base of the mappable expression or null if it |
| 10530 | // cannot be determined and do all the necessary checks to see if the expression |
| 10531 | // is valid as a standalone mappable expression. In the process, record all the |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10532 | // components of the expression. |
| 10533 | static Expr *CheckMapClauseExpressionBase( |
| 10534 | Sema &SemaRef, Expr *E, |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10535 | OMPClauseMappableExprCommon::MappableExprComponentList &CurComponents, |
| 10536 | OpenMPClauseKind CKind) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10537 | SourceLocation ELoc = E->getExprLoc(); |
| 10538 | SourceRange ERange = E->getSourceRange(); |
| 10539 | |
| 10540 | // The base of elements of list in a map clause have to be either: |
| 10541 | // - a reference to variable or field. |
| 10542 | // - a member expression. |
| 10543 | // - an array expression. |
| 10544 | // |
| 10545 | // E.g. if we have the expression 'r.S.Arr[:12]', we want to retrieve the |
| 10546 | // reference to 'r'. |
| 10547 | // |
| 10548 | // If we have: |
| 10549 | // |
| 10550 | // struct SS { |
| 10551 | // Bla S; |
| 10552 | // foo() { |
| 10553 | // #pragma omp target map (S.Arr[:12]); |
| 10554 | // } |
| 10555 | // } |
| 10556 | // |
| 10557 | // We want to retrieve the member expression 'this->S'; |
| 10558 | |
| 10559 | Expr *RelevantExpr = nullptr; |
| 10560 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10561 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.2] |
| 10562 | // If a list item is an array section, it must specify contiguous storage. |
| 10563 | // |
| 10564 | // For this restriction it is sufficient that we make sure only references |
| 10565 | // to variables or fields and array expressions, and that no array sections |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 10566 | // exist except in the rightmost expression (unless they cover the whole |
| 10567 | // dimension of the array). E.g. these would be invalid: |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10568 | // |
| 10569 | // r.ArrS[3:5].Arr[6:7] |
| 10570 | // |
| 10571 | // r.ArrS[3:5].x |
| 10572 | // |
| 10573 | // but these would be valid: |
| 10574 | // r.ArrS[3].Arr[6:7] |
| 10575 | // |
| 10576 | // r.ArrS[3].x |
| 10577 | |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 10578 | bool AllowUnitySizeArraySection = true; |
| 10579 | bool AllowWholeSizeArraySection = true; |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10580 | |
Dmitry Polukhin | 644a925 | 2016-03-11 07:58:34 +0000 | [diff] [blame] | 10581 | while (!RelevantExpr) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10582 | E = E->IgnoreParenImpCasts(); |
| 10583 | |
| 10584 | if (auto *CurE = dyn_cast<DeclRefExpr>(E)) { |
| 10585 | if (!isa<VarDecl>(CurE->getDecl())) |
| 10586 | break; |
| 10587 | |
| 10588 | RelevantExpr = CurE; |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 10589 | |
| 10590 | // If we got a reference to a declaration, we should not expect any array |
| 10591 | // section before that. |
| 10592 | AllowUnitySizeArraySection = false; |
| 10593 | AllowWholeSizeArraySection = false; |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10594 | |
| 10595 | // Record the component. |
| 10596 | CurComponents.push_back(OMPClauseMappableExprCommon::MappableComponent( |
| 10597 | CurE, CurE->getDecl())); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10598 | continue; |
| 10599 | } |
| 10600 | |
| 10601 | if (auto *CurE = dyn_cast<MemberExpr>(E)) { |
| 10602 | auto *BaseE = CurE->getBase()->IgnoreParenImpCasts(); |
| 10603 | |
| 10604 | if (isa<CXXThisExpr>(BaseE)) |
| 10605 | // We found a base expression: this->Val. |
| 10606 | RelevantExpr = CurE; |
| 10607 | else |
| 10608 | E = BaseE; |
| 10609 | |
| 10610 | if (!isa<FieldDecl>(CurE->getMemberDecl())) { |
| 10611 | SemaRef.Diag(ELoc, diag::err_omp_expected_access_to_data_field) |
| 10612 | << CurE->getSourceRange(); |
| 10613 | break; |
| 10614 | } |
| 10615 | |
| 10616 | auto *FD = cast<FieldDecl>(CurE->getMemberDecl()); |
| 10617 | |
| 10618 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C/C++, p.3] |
| 10619 | // A bit-field cannot appear in a map clause. |
| 10620 | // |
| 10621 | if (FD->isBitField()) { |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10622 | SemaRef.Diag(ELoc, diag::err_omp_bit_fields_forbidden_in_clause) |
| 10623 | << CurE->getSourceRange() << getOpenMPClauseName(CKind); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10624 | break; |
| 10625 | } |
| 10626 | |
| 10627 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] |
| 10628 | // If the type of a list item is a reference to a type T then the type |
| 10629 | // will be considered to be T for all purposes of this clause. |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 10630 | QualType CurType = BaseE->getType().getNonReferenceType(); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10631 | |
| 10632 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C/C++, p.2] |
| 10633 | // A list item cannot be a variable that is a member of a structure with |
| 10634 | // a union type. |
| 10635 | // |
| 10636 | if (auto *RT = CurType->getAs<RecordType>()) |
| 10637 | if (RT->isUnionType()) { |
| 10638 | SemaRef.Diag(ELoc, diag::err_omp_union_type_not_allowed) |
| 10639 | << CurE->getSourceRange(); |
| 10640 | break; |
| 10641 | } |
| 10642 | |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 10643 | // If we got a member expression, we should not expect any array section |
| 10644 | // before that: |
| 10645 | // |
| 10646 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.7] |
| 10647 | // If a list item is an element of a structure, only the rightmost symbol |
| 10648 | // of the variable reference can be an array section. |
| 10649 | // |
| 10650 | AllowUnitySizeArraySection = false; |
| 10651 | AllowWholeSizeArraySection = false; |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10652 | |
| 10653 | // Record the component. |
| 10654 | CurComponents.push_back( |
| 10655 | OMPClauseMappableExprCommon::MappableComponent(CurE, FD)); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10656 | continue; |
| 10657 | } |
| 10658 | |
| 10659 | if (auto *CurE = dyn_cast<ArraySubscriptExpr>(E)) { |
| 10660 | E = CurE->getBase()->IgnoreParenImpCasts(); |
| 10661 | |
| 10662 | if (!E->getType()->isAnyPointerType() && !E->getType()->isArrayType()) { |
| 10663 | SemaRef.Diag(ELoc, diag::err_omp_expected_base_var_name) |
| 10664 | << 0 << CurE->getSourceRange(); |
| 10665 | break; |
| 10666 | } |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 10667 | |
| 10668 | // If we got an array subscript that express the whole dimension we |
| 10669 | // can have any array expressions before. If it only expressing part of |
| 10670 | // the dimension, we can only have unitary-size array expressions. |
| 10671 | if (CheckArrayExpressionDoesNotReferToWholeSize(SemaRef, CurE, |
| 10672 | E->getType())) |
| 10673 | AllowWholeSizeArraySection = false; |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10674 | |
| 10675 | // Record the component - we don't have any declaration associated. |
| 10676 | CurComponents.push_back( |
| 10677 | OMPClauseMappableExprCommon::MappableComponent(CurE, nullptr)); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10678 | continue; |
| 10679 | } |
| 10680 | |
| 10681 | if (auto *CurE = dyn_cast<OMPArraySectionExpr>(E)) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10682 | E = CurE->getBase()->IgnoreParenImpCasts(); |
| 10683 | |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 10684 | auto CurType = |
| 10685 | OMPArraySectionExpr::getBaseOriginalType(E).getCanonicalType(); |
| 10686 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10687 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] |
| 10688 | // If the type of a list item is a reference to a type T then the type |
| 10689 | // will be considered to be T for all purposes of this clause. |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10690 | if (CurType->isReferenceType()) |
| 10691 | CurType = CurType->getPointeeType(); |
| 10692 | |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 10693 | bool IsPointer = CurType->isAnyPointerType(); |
| 10694 | |
| 10695 | if (!IsPointer && !CurType->isArrayType()) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10696 | SemaRef.Diag(ELoc, diag::err_omp_expected_base_var_name) |
| 10697 | << 0 << CurE->getSourceRange(); |
| 10698 | break; |
| 10699 | } |
| 10700 | |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 10701 | bool NotWhole = |
| 10702 | CheckArrayExpressionDoesNotReferToWholeSize(SemaRef, CurE, CurType); |
| 10703 | bool NotUnity = |
| 10704 | CheckArrayExpressionDoesNotReferToUnitySize(SemaRef, CurE, CurType); |
| 10705 | |
Samuel Antao | dab51bb | 2016-07-18 23:22:11 +0000 | [diff] [blame] | 10706 | if (AllowWholeSizeArraySection) { |
| 10707 | // Any array section is currently allowed. Allowing a whole size array |
| 10708 | // section implies allowing a unity array section as well. |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 10709 | // |
| 10710 | // If this array section refers to the whole dimension we can still |
| 10711 | // accept other array sections before this one, except if the base is a |
| 10712 | // pointer. Otherwise, only unitary sections are accepted. |
| 10713 | if (NotWhole || IsPointer) |
| 10714 | AllowWholeSizeArraySection = false; |
Samuel Antao | dab51bb | 2016-07-18 23:22:11 +0000 | [diff] [blame] | 10715 | } else if (AllowUnitySizeArraySection && NotUnity) { |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 10716 | // A unity or whole array section is not allowed and that is not |
| 10717 | // compatible with the properties of the current array section. |
| 10718 | SemaRef.Diag( |
| 10719 | ELoc, diag::err_array_section_does_not_specify_contiguous_storage) |
| 10720 | << CurE->getSourceRange(); |
| 10721 | break; |
| 10722 | } |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10723 | |
| 10724 | // Record the component - we don't have any declaration associated. |
| 10725 | CurComponents.push_back( |
| 10726 | OMPClauseMappableExprCommon::MappableComponent(CurE, nullptr)); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10727 | continue; |
| 10728 | } |
| 10729 | |
| 10730 | // If nothing else worked, this is not a valid map clause expression. |
| 10731 | SemaRef.Diag(ELoc, |
| 10732 | diag::err_omp_expected_named_var_member_or_array_expression) |
| 10733 | << ERange; |
| 10734 | break; |
| 10735 | } |
| 10736 | |
| 10737 | return RelevantExpr; |
| 10738 | } |
| 10739 | |
| 10740 | // Return true if expression E associated with value VD has conflicts with other |
| 10741 | // map information. |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10742 | static bool CheckMapConflicts( |
| 10743 | Sema &SemaRef, DSAStackTy *DSAS, ValueDecl *VD, Expr *E, |
| 10744 | bool CurrentRegionOnly, |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10745 | OMPClauseMappableExprCommon::MappableExprComponentListRef CurComponents, |
| 10746 | OpenMPClauseKind CKind) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10747 | assert(VD && E); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10748 | SourceLocation ELoc = E->getExprLoc(); |
| 10749 | SourceRange ERange = E->getSourceRange(); |
| 10750 | |
| 10751 | // In order to easily check the conflicts we need to match each component of |
| 10752 | // the expression under test with the components of the expressions that are |
| 10753 | // already in the stack. |
| 10754 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10755 | assert(!CurComponents.empty() && "Map clause expression with no components!"); |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10756 | assert(CurComponents.back().getAssociatedDeclaration() == VD && |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10757 | "Map clause expression with unexpected base!"); |
| 10758 | |
| 10759 | // Variables to help detecting enclosing problems in data environment nests. |
| 10760 | bool IsEnclosedByDataEnvironmentExpr = false; |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10761 | const Expr *EnclosingExpr = nullptr; |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10762 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10763 | bool FoundError = DSAS->checkMappableExprComponentListsForDecl( |
| 10764 | VD, CurrentRegionOnly, |
| 10765 | [&](OMPClauseMappableExprCommon::MappableExprComponentListRef |
| 10766 | StackComponents) -> bool { |
| 10767 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10768 | assert(!StackComponents.empty() && |
| 10769 | "Map clause expression with no components!"); |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10770 | assert(StackComponents.back().getAssociatedDeclaration() == VD && |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10771 | "Map clause expression with unexpected base!"); |
| 10772 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10773 | // The whole expression in the stack. |
| 10774 | auto *RE = StackComponents.front().getAssociatedExpression(); |
| 10775 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10776 | // Expressions must start from the same base. Here we detect at which |
| 10777 | // point both expressions diverge from each other and see if we can |
| 10778 | // detect if the memory referred to both expressions is contiguous and |
| 10779 | // do not overlap. |
| 10780 | auto CI = CurComponents.rbegin(); |
| 10781 | auto CE = CurComponents.rend(); |
| 10782 | auto SI = StackComponents.rbegin(); |
| 10783 | auto SE = StackComponents.rend(); |
| 10784 | for (; CI != CE && SI != SE; ++CI, ++SI) { |
| 10785 | |
| 10786 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.3] |
| 10787 | // At most one list item can be an array item derived from a given |
| 10788 | // variable in map clauses of the same construct. |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10789 | if (CurrentRegionOnly && |
| 10790 | (isa<ArraySubscriptExpr>(CI->getAssociatedExpression()) || |
| 10791 | isa<OMPArraySectionExpr>(CI->getAssociatedExpression())) && |
| 10792 | (isa<ArraySubscriptExpr>(SI->getAssociatedExpression()) || |
| 10793 | isa<OMPArraySectionExpr>(SI->getAssociatedExpression()))) { |
| 10794 | SemaRef.Diag(CI->getAssociatedExpression()->getExprLoc(), |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10795 | diag::err_omp_multiple_array_items_in_map_clause) |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10796 | << CI->getAssociatedExpression()->getSourceRange(); |
| 10797 | SemaRef.Diag(SI->getAssociatedExpression()->getExprLoc(), |
| 10798 | diag::note_used_here) |
| 10799 | << SI->getAssociatedExpression()->getSourceRange(); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10800 | return true; |
| 10801 | } |
| 10802 | |
| 10803 | // Do both expressions have the same kind? |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10804 | if (CI->getAssociatedExpression()->getStmtClass() != |
| 10805 | SI->getAssociatedExpression()->getStmtClass()) |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10806 | break; |
| 10807 | |
| 10808 | // Are we dealing with different variables/fields? |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10809 | if (CI->getAssociatedDeclaration() != SI->getAssociatedDeclaration()) |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10810 | break; |
| 10811 | } |
Kelvin Li | 9f645ae | 2016-07-18 22:49:16 +0000 | [diff] [blame] | 10812 | // Check if the extra components of the expressions in the enclosing |
| 10813 | // data environment are redundant for the current base declaration. |
| 10814 | // If they are, the maps completely overlap, which is legal. |
| 10815 | for (; SI != SE; ++SI) { |
| 10816 | QualType Type; |
| 10817 | if (auto *ASE = |
| 10818 | dyn_cast<ArraySubscriptExpr>(SI->getAssociatedExpression())) { |
| 10819 | Type = ASE->getBase()->IgnoreParenImpCasts()->getType(); |
| 10820 | } else if (auto *OASE = |
| 10821 | dyn_cast<OMPArraySectionExpr>(SI->getAssociatedExpression())) { |
| 10822 | auto *E = OASE->getBase()->IgnoreParenImpCasts(); |
| 10823 | Type = |
| 10824 | OMPArraySectionExpr::getBaseOriginalType(E).getCanonicalType(); |
| 10825 | } |
| 10826 | if (Type.isNull() || Type->isAnyPointerType() || |
| 10827 | CheckArrayExpressionDoesNotReferToWholeSize( |
| 10828 | SemaRef, SI->getAssociatedExpression(), Type)) |
| 10829 | break; |
| 10830 | } |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10831 | |
| 10832 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.4] |
| 10833 | // List items of map clauses in the same construct must not share |
| 10834 | // original storage. |
| 10835 | // |
| 10836 | // If the expressions are exactly the same or one is a subset of the |
| 10837 | // other, it means they are sharing storage. |
| 10838 | if (CI == CE && SI == SE) { |
| 10839 | if (CurrentRegionOnly) { |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10840 | if (CKind == OMPC_map) |
| 10841 | SemaRef.Diag(ELoc, diag::err_omp_map_shared_storage) << ERange; |
| 10842 | else { |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 10843 | assert(CKind == OMPC_to || CKind == OMPC_from); |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10844 | SemaRef.Diag(ELoc, diag::err_omp_once_referenced_in_target_update) |
| 10845 | << ERange; |
| 10846 | } |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10847 | SemaRef.Diag(RE->getExprLoc(), diag::note_used_here) |
| 10848 | << RE->getSourceRange(); |
| 10849 | return true; |
| 10850 | } else { |
| 10851 | // If we find the same expression in the enclosing data environment, |
| 10852 | // that is legal. |
| 10853 | IsEnclosedByDataEnvironmentExpr = true; |
| 10854 | return false; |
| 10855 | } |
| 10856 | } |
| 10857 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10858 | QualType DerivedType = |
| 10859 | std::prev(CI)->getAssociatedDeclaration()->getType(); |
| 10860 | SourceLocation DerivedLoc = |
| 10861 | std::prev(CI)->getAssociatedExpression()->getExprLoc(); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10862 | |
| 10863 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] |
| 10864 | // If the type of a list item is a reference to a type T then the type |
| 10865 | // will be considered to be T for all purposes of this clause. |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10866 | DerivedType = DerivedType.getNonReferenceType(); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10867 | |
| 10868 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C/C++, p.1] |
| 10869 | // A variable for which the type is pointer and an array section |
| 10870 | // derived from that variable must not appear as list items of map |
| 10871 | // clauses of the same construct. |
| 10872 | // |
| 10873 | // Also, cover one of the cases in: |
| 10874 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.5] |
| 10875 | // If any part of the original storage of a list item has corresponding |
| 10876 | // storage in the device data environment, all of the original storage |
| 10877 | // must have corresponding storage in the device data environment. |
| 10878 | // |
| 10879 | if (DerivedType->isAnyPointerType()) { |
| 10880 | if (CI == CE || SI == SE) { |
| 10881 | SemaRef.Diag( |
| 10882 | DerivedLoc, |
| 10883 | diag::err_omp_pointer_mapped_along_with_derived_section) |
| 10884 | << DerivedLoc; |
| 10885 | } else { |
| 10886 | assert(CI != CE && SI != SE); |
| 10887 | SemaRef.Diag(DerivedLoc, diag::err_omp_same_pointer_derreferenced) |
| 10888 | << DerivedLoc; |
| 10889 | } |
| 10890 | SemaRef.Diag(RE->getExprLoc(), diag::note_used_here) |
| 10891 | << RE->getSourceRange(); |
| 10892 | return true; |
| 10893 | } |
| 10894 | |
| 10895 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.4] |
| 10896 | // List items of map clauses in the same construct must not share |
| 10897 | // original storage. |
| 10898 | // |
| 10899 | // An expression is a subset of the other. |
| 10900 | if (CurrentRegionOnly && (CI == CE || SI == SE)) { |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10901 | if (CKind == OMPC_map) |
| 10902 | SemaRef.Diag(ELoc, diag::err_omp_map_shared_storage) << ERange; |
| 10903 | else { |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 10904 | assert(CKind == OMPC_to || CKind == OMPC_from); |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10905 | SemaRef.Diag(ELoc, diag::err_omp_once_referenced_in_target_update) |
| 10906 | << ERange; |
| 10907 | } |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10908 | SemaRef.Diag(RE->getExprLoc(), diag::note_used_here) |
| 10909 | << RE->getSourceRange(); |
| 10910 | return true; |
| 10911 | } |
| 10912 | |
| 10913 | // The current expression uses the same base as other expression in the |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10914 | // data environment but does not contain it completely. |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10915 | if (!CurrentRegionOnly && SI != SE) |
| 10916 | EnclosingExpr = RE; |
| 10917 | |
| 10918 | // The current expression is a subset of the expression in the data |
| 10919 | // environment. |
| 10920 | IsEnclosedByDataEnvironmentExpr |= |
| 10921 | (!CurrentRegionOnly && CI != CE && SI == SE); |
| 10922 | |
| 10923 | return false; |
| 10924 | }); |
| 10925 | |
| 10926 | if (CurrentRegionOnly) |
| 10927 | return FoundError; |
| 10928 | |
| 10929 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.5] |
| 10930 | // If any part of the original storage of a list item has corresponding |
| 10931 | // storage in the device data environment, all of the original storage must |
| 10932 | // have corresponding storage in the device data environment. |
| 10933 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.6] |
| 10934 | // If a list item is an element of a structure, and a different element of |
| 10935 | // the structure has a corresponding list item in the device data environment |
| 10936 | // prior to a task encountering the construct associated with the map clause, |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10937 | // then the list item must also have a corresponding list item in the device |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10938 | // data environment prior to the task encountering the construct. |
| 10939 | // |
| 10940 | if (EnclosingExpr && !IsEnclosedByDataEnvironmentExpr) { |
| 10941 | SemaRef.Diag(ELoc, |
| 10942 | diag::err_omp_original_storage_is_shared_and_does_not_contain) |
| 10943 | << ERange; |
| 10944 | SemaRef.Diag(EnclosingExpr->getExprLoc(), diag::note_used_here) |
| 10945 | << EnclosingExpr->getSourceRange(); |
| 10946 | return true; |
| 10947 | } |
| 10948 | |
| 10949 | return FoundError; |
| 10950 | } |
| 10951 | |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10952 | namespace { |
| 10953 | // Utility struct that gathers all the related lists associated with a mappable |
| 10954 | // expression. |
| 10955 | struct MappableVarListInfo final { |
| 10956 | // The list of expressions. |
| 10957 | ArrayRef<Expr *> VarList; |
| 10958 | // The list of processed expressions. |
| 10959 | SmallVector<Expr *, 16> ProcessedVarList; |
| 10960 | // The mappble components for each expression. |
| 10961 | OMPClauseMappableExprCommon::MappableExprComponentLists VarComponents; |
| 10962 | // The base declaration of the variable. |
| 10963 | SmallVector<ValueDecl *, 16> VarBaseDeclarations; |
| 10964 | |
| 10965 | MappableVarListInfo(ArrayRef<Expr *> VarList) : VarList(VarList) { |
| 10966 | // We have a list of components and base declarations for each entry in the |
| 10967 | // variable list. |
| 10968 | VarComponents.reserve(VarList.size()); |
| 10969 | VarBaseDeclarations.reserve(VarList.size()); |
| 10970 | } |
| 10971 | }; |
| 10972 | } |
| 10973 | |
| 10974 | // Check the validity of the provided variable list for the provided clause kind |
| 10975 | // \a CKind. In the check process the valid expressions, and mappable expression |
| 10976 | // components and variables are extracted and used to fill \a Vars, |
| 10977 | // \a ClauseComponents, and \a ClauseBaseDeclarations. \a MapType and |
| 10978 | // \a IsMapTypeImplicit are expected to be valid if the clause kind is 'map'. |
| 10979 | static void |
| 10980 | checkMappableExpressionList(Sema &SemaRef, DSAStackTy *DSAS, |
| 10981 | OpenMPClauseKind CKind, MappableVarListInfo &MVLI, |
| 10982 | SourceLocation StartLoc, |
| 10983 | OpenMPMapClauseKind MapType = OMPC_MAP_unknown, |
| 10984 | bool IsMapTypeImplicit = false) { |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 10985 | // We only expect mappable expressions in 'to', 'from', and 'map' clauses. |
| 10986 | assert((CKind == OMPC_map || CKind == OMPC_to || CKind == OMPC_from) && |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10987 | "Unexpected clause kind with mappable expressions!"); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10988 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10989 | // Keep track of the mappable components and base declarations in this clause. |
| 10990 | // Each entry in the list is going to have a list of components associated. We |
| 10991 | // record each set of the components so that we can build the clause later on. |
| 10992 | // In the end we should have the same amount of declarations and component |
| 10993 | // lists. |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10994 | |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10995 | for (auto &RE : MVLI.VarList) { |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 10996 | assert(RE && "Null expr in omp to/from/map clause"); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10997 | SourceLocation ELoc = RE->getExprLoc(); |
| 10998 | |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10999 | auto *VE = RE->IgnoreParenLValueCasts(); |
| 11000 | |
| 11001 | if (VE->isValueDependent() || VE->isTypeDependent() || |
| 11002 | VE->isInstantiationDependent() || |
| 11003 | VE->containsUnexpandedParameterPack()) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 11004 | // We can only analyze this information once the missing information is |
| 11005 | // resolved. |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 11006 | MVLI.ProcessedVarList.push_back(RE); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 11007 | continue; |
| 11008 | } |
| 11009 | |
| 11010 | auto *SimpleExpr = RE->IgnoreParenCasts(); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 11011 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 11012 | if (!RE->IgnoreParenImpCasts()->isLValue()) { |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 11013 | SemaRef.Diag(ELoc, |
| 11014 | diag::err_omp_expected_named_var_member_or_array_expression) |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 11015 | << RE->getSourceRange(); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 11016 | continue; |
| 11017 | } |
| 11018 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 11019 | OMPClauseMappableExprCommon::MappableExprComponentList CurComponents; |
| 11020 | ValueDecl *CurDeclaration = nullptr; |
| 11021 | |
| 11022 | // Obtain the array or member expression bases if required. Also, fill the |
| 11023 | // components array with all the components identified in the process. |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 11024 | auto *BE = |
| 11025 | CheckMapClauseExpressionBase(SemaRef, SimpleExpr, CurComponents, CKind); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 11026 | if (!BE) |
| 11027 | continue; |
| 11028 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 11029 | assert(!CurComponents.empty() && |
| 11030 | "Invalid mappable expression information."); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 11031 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 11032 | // For the following checks, we rely on the base declaration which is |
| 11033 | // expected to be associated with the last component. The declaration is |
| 11034 | // expected to be a variable or a field (if 'this' is being mapped). |
| 11035 | CurDeclaration = CurComponents.back().getAssociatedDeclaration(); |
| 11036 | assert(CurDeclaration && "Null decl on map clause."); |
| 11037 | assert( |
| 11038 | CurDeclaration->isCanonicalDecl() && |
| 11039 | "Expecting components to have associated only canonical declarations."); |
| 11040 | |
| 11041 | auto *VD = dyn_cast<VarDecl>(CurDeclaration); |
| 11042 | auto *FD = dyn_cast<FieldDecl>(CurDeclaration); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 11043 | |
| 11044 | assert((VD || FD) && "Only variables or fields are expected here!"); |
NAKAMURA Takumi | 6dcb814 | 2016-01-23 01:38:20 +0000 | [diff] [blame] | 11045 | (void)FD; |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 11046 | |
| 11047 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.10] |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 11048 | // threadprivate variables cannot appear in a map clause. |
| 11049 | // OpenMP 4.5 [2.10.5, target update Construct] |
| 11050 | // threadprivate variables cannot appear in a from clause. |
| 11051 | if (VD && DSAS->isThreadPrivate(VD)) { |
| 11052 | auto DVar = DSAS->getTopDSA(VD, false); |
| 11053 | SemaRef.Diag(ELoc, diag::err_omp_threadprivate_in_clause) |
| 11054 | << getOpenMPClauseName(CKind); |
| 11055 | ReportOriginalDSA(SemaRef, DSAS, VD, DVar); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 11056 | continue; |
| 11057 | } |
| 11058 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 11059 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.9] |
| 11060 | // A list item cannot appear in both a map clause and a data-sharing |
| 11061 | // attribute clause on the same construct. |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 11062 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 11063 | // Check conflicts with other map clause expressions. We check the conflicts |
| 11064 | // with the current construct separately from the enclosing data |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 11065 | // environment, because the restrictions are different. We only have to |
| 11066 | // check conflicts across regions for the map clauses. |
| 11067 | if (CheckMapConflicts(SemaRef, DSAS, CurDeclaration, SimpleExpr, |
| 11068 | /*CurrentRegionOnly=*/true, CurComponents, CKind)) |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 11069 | break; |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 11070 | if (CKind == OMPC_map && |
| 11071 | CheckMapConflicts(SemaRef, DSAS, CurDeclaration, SimpleExpr, |
| 11072 | /*CurrentRegionOnly=*/false, CurComponents, CKind)) |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 11073 | break; |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 11074 | |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 11075 | // OpenMP 4.5 [2.10.5, target update Construct] |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 11076 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] |
| 11077 | // If the type of a list item is a reference to a type T then the type will |
| 11078 | // be considered to be T for all purposes of this clause. |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 11079 | QualType Type = CurDeclaration->getType().getNonReferenceType(); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 11080 | |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 11081 | // OpenMP 4.5 [2.10.5, target update Construct, Restrictions, p.4] |
| 11082 | // A list item in a to or from clause must have a mappable type. |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 11083 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.9] |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 11084 | // A list item must have a mappable type. |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 11085 | if (!CheckTypeMappable(VE->getExprLoc(), VE->getSourceRange(), SemaRef, |
| 11086 | DSAS, Type)) |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 11087 | continue; |
| 11088 | |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 11089 | if (CKind == OMPC_map) { |
| 11090 | // target enter data |
| 11091 | // OpenMP [2.10.2, Restrictions, p. 99] |
| 11092 | // A map-type must be specified in all map clauses and must be either |
| 11093 | // to or alloc. |
| 11094 | OpenMPDirectiveKind DKind = DSAS->getCurrentDirective(); |
| 11095 | if (DKind == OMPD_target_enter_data && |
| 11096 | !(MapType == OMPC_MAP_to || MapType == OMPC_MAP_alloc)) { |
| 11097 | SemaRef.Diag(StartLoc, diag::err_omp_invalid_map_type_for_directive) |
| 11098 | << (IsMapTypeImplicit ? 1 : 0) |
| 11099 | << getOpenMPSimpleClauseTypeName(OMPC_map, MapType) |
| 11100 | << getOpenMPDirectiveName(DKind); |
Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 11101 | continue; |
| 11102 | } |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 11103 | |
| 11104 | // target exit_data |
| 11105 | // OpenMP [2.10.3, Restrictions, p. 102] |
| 11106 | // A map-type must be specified in all map clauses and must be either |
| 11107 | // from, release, or delete. |
| 11108 | if (DKind == OMPD_target_exit_data && |
| 11109 | !(MapType == OMPC_MAP_from || MapType == OMPC_MAP_release || |
| 11110 | MapType == OMPC_MAP_delete)) { |
| 11111 | SemaRef.Diag(StartLoc, diag::err_omp_invalid_map_type_for_directive) |
| 11112 | << (IsMapTypeImplicit ? 1 : 0) |
| 11113 | << getOpenMPSimpleClauseTypeName(OMPC_map, MapType) |
| 11114 | << getOpenMPDirectiveName(DKind); |
| 11115 | continue; |
| 11116 | } |
| 11117 | |
| 11118 | // OpenMP 4.5 [2.15.5.1, Restrictions, p.3] |
| 11119 | // A list item cannot appear in both a map clause and a data-sharing |
| 11120 | // attribute clause on the same construct |
| 11121 | if (DKind == OMPD_target && VD) { |
| 11122 | auto DVar = DSAS->getTopDSA(VD, false); |
| 11123 | if (isOpenMPPrivate(DVar.CKind)) { |
| 11124 | SemaRef.Diag(ELoc, diag::err_omp_variable_in_map_and_dsa) |
| 11125 | << getOpenMPClauseName(DVar.CKind) |
| 11126 | << getOpenMPDirectiveName(DSAS->getCurrentDirective()); |
| 11127 | ReportOriginalDSA(SemaRef, DSAS, CurDeclaration, DVar); |
| 11128 | continue; |
| 11129 | } |
| 11130 | } |
Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 11131 | } |
| 11132 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 11133 | // Save the current expression. |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 11134 | MVLI.ProcessedVarList.push_back(RE); |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 11135 | |
| 11136 | // Store the components in the stack so that they can be used to check |
| 11137 | // against other clauses later on. |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 11138 | DSAS->addMappableExpressionComponents(CurDeclaration, CurComponents); |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 11139 | |
| 11140 | // Save the components and declaration to create the clause. For purposes of |
| 11141 | // the clause creation, any component list that has has base 'this' uses |
Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 11142 | // null as base declaration. |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 11143 | MVLI.VarComponents.resize(MVLI.VarComponents.size() + 1); |
| 11144 | MVLI.VarComponents.back().append(CurComponents.begin(), |
| 11145 | CurComponents.end()); |
| 11146 | MVLI.VarBaseDeclarations.push_back(isa<MemberExpr>(BE) ? nullptr |
| 11147 | : CurDeclaration); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 11148 | } |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 11149 | } |
| 11150 | |
| 11151 | OMPClause * |
| 11152 | Sema::ActOnOpenMPMapClause(OpenMPMapClauseKind MapTypeModifier, |
| 11153 | OpenMPMapClauseKind MapType, bool IsMapTypeImplicit, |
| 11154 | SourceLocation MapLoc, SourceLocation ColonLoc, |
| 11155 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
| 11156 | SourceLocation LParenLoc, SourceLocation EndLoc) { |
| 11157 | MappableVarListInfo MVLI(VarList); |
| 11158 | checkMappableExpressionList(*this, DSAStack, OMPC_map, MVLI, StartLoc, |
| 11159 | MapType, IsMapTypeImplicit); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 11160 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 11161 | // We need to produce a map clause even if we don't have variables so that |
| 11162 | // other diagnostics related with non-existing map clauses are accurate. |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 11163 | return OMPMapClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| 11164 | MVLI.ProcessedVarList, MVLI.VarBaseDeclarations, |
| 11165 | MVLI.VarComponents, MapTypeModifier, MapType, |
| 11166 | IsMapTypeImplicit, MapLoc); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 11167 | } |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 11168 | |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 11169 | QualType Sema::ActOnOpenMPDeclareReductionType(SourceLocation TyLoc, |
| 11170 | TypeResult ParsedType) { |
| 11171 | assert(ParsedType.isUsable()); |
| 11172 | |
| 11173 | QualType ReductionType = GetTypeFromParser(ParsedType.get()); |
| 11174 | if (ReductionType.isNull()) |
| 11175 | return QualType(); |
| 11176 | |
| 11177 | // [OpenMP 4.0], 2.15 declare reduction Directive, Restrictions, C\C++ |
| 11178 | // A type name in a declare reduction directive cannot be a function type, an |
| 11179 | // array type, a reference type, or a type qualified with const, volatile or |
| 11180 | // restrict. |
| 11181 | if (ReductionType.hasQualifiers()) { |
| 11182 | Diag(TyLoc, diag::err_omp_reduction_wrong_type) << 0; |
| 11183 | return QualType(); |
| 11184 | } |
| 11185 | |
| 11186 | if (ReductionType->isFunctionType()) { |
| 11187 | Diag(TyLoc, diag::err_omp_reduction_wrong_type) << 1; |
| 11188 | return QualType(); |
| 11189 | } |
| 11190 | if (ReductionType->isReferenceType()) { |
| 11191 | Diag(TyLoc, diag::err_omp_reduction_wrong_type) << 2; |
| 11192 | return QualType(); |
| 11193 | } |
| 11194 | if (ReductionType->isArrayType()) { |
| 11195 | Diag(TyLoc, diag::err_omp_reduction_wrong_type) << 3; |
| 11196 | return QualType(); |
| 11197 | } |
| 11198 | return ReductionType; |
| 11199 | } |
| 11200 | |
| 11201 | Sema::DeclGroupPtrTy Sema::ActOnOpenMPDeclareReductionDirectiveStart( |
| 11202 | Scope *S, DeclContext *DC, DeclarationName Name, |
| 11203 | ArrayRef<std::pair<QualType, SourceLocation>> ReductionTypes, |
| 11204 | AccessSpecifier AS, Decl *PrevDeclInScope) { |
| 11205 | SmallVector<Decl *, 8> Decls; |
| 11206 | Decls.reserve(ReductionTypes.size()); |
| 11207 | |
| 11208 | LookupResult Lookup(*this, Name, SourceLocation(), LookupOMPReductionName, |
| 11209 | ForRedeclaration); |
| 11210 | // [OpenMP 4.0], 2.15 declare reduction Directive, Restrictions |
| 11211 | // A reduction-identifier may not be re-declared in the current scope for the |
| 11212 | // same type or for a type that is compatible according to the base language |
| 11213 | // rules. |
| 11214 | llvm::DenseMap<QualType, SourceLocation> PreviousRedeclTypes; |
| 11215 | OMPDeclareReductionDecl *PrevDRD = nullptr; |
| 11216 | bool InCompoundScope = true; |
| 11217 | if (S != nullptr) { |
| 11218 | // Find previous declaration with the same name not referenced in other |
| 11219 | // declarations. |
| 11220 | FunctionScopeInfo *ParentFn = getEnclosingFunction(); |
| 11221 | InCompoundScope = |
| 11222 | (ParentFn != nullptr) && !ParentFn->CompoundScopes.empty(); |
| 11223 | LookupName(Lookup, S); |
| 11224 | FilterLookupForScope(Lookup, DC, S, /*ConsiderLinkage=*/false, |
| 11225 | /*AllowInlineNamespace=*/false); |
| 11226 | llvm::DenseMap<OMPDeclareReductionDecl *, bool> UsedAsPrevious; |
| 11227 | auto Filter = Lookup.makeFilter(); |
| 11228 | while (Filter.hasNext()) { |
| 11229 | auto *PrevDecl = cast<OMPDeclareReductionDecl>(Filter.next()); |
| 11230 | if (InCompoundScope) { |
| 11231 | auto I = UsedAsPrevious.find(PrevDecl); |
| 11232 | if (I == UsedAsPrevious.end()) |
| 11233 | UsedAsPrevious[PrevDecl] = false; |
| 11234 | if (auto *D = PrevDecl->getPrevDeclInScope()) |
| 11235 | UsedAsPrevious[D] = true; |
| 11236 | } |
| 11237 | PreviousRedeclTypes[PrevDecl->getType().getCanonicalType()] = |
| 11238 | PrevDecl->getLocation(); |
| 11239 | } |
| 11240 | Filter.done(); |
| 11241 | if (InCompoundScope) { |
| 11242 | for (auto &PrevData : UsedAsPrevious) { |
| 11243 | if (!PrevData.second) { |
| 11244 | PrevDRD = PrevData.first; |
| 11245 | break; |
| 11246 | } |
| 11247 | } |
| 11248 | } |
| 11249 | } else if (PrevDeclInScope != nullptr) { |
| 11250 | auto *PrevDRDInScope = PrevDRD = |
| 11251 | cast<OMPDeclareReductionDecl>(PrevDeclInScope); |
| 11252 | do { |
| 11253 | PreviousRedeclTypes[PrevDRDInScope->getType().getCanonicalType()] = |
| 11254 | PrevDRDInScope->getLocation(); |
| 11255 | PrevDRDInScope = PrevDRDInScope->getPrevDeclInScope(); |
| 11256 | } while (PrevDRDInScope != nullptr); |
| 11257 | } |
| 11258 | for (auto &TyData : ReductionTypes) { |
| 11259 | auto I = PreviousRedeclTypes.find(TyData.first.getCanonicalType()); |
| 11260 | bool Invalid = false; |
| 11261 | if (I != PreviousRedeclTypes.end()) { |
| 11262 | Diag(TyData.second, diag::err_omp_declare_reduction_redefinition) |
| 11263 | << TyData.first; |
| 11264 | Diag(I->second, diag::note_previous_definition); |
| 11265 | Invalid = true; |
| 11266 | } |
| 11267 | PreviousRedeclTypes[TyData.first.getCanonicalType()] = TyData.second; |
| 11268 | auto *DRD = OMPDeclareReductionDecl::Create(Context, DC, TyData.second, |
| 11269 | Name, TyData.first, PrevDRD); |
| 11270 | DC->addDecl(DRD); |
| 11271 | DRD->setAccess(AS); |
| 11272 | Decls.push_back(DRD); |
| 11273 | if (Invalid) |
| 11274 | DRD->setInvalidDecl(); |
| 11275 | else |
| 11276 | PrevDRD = DRD; |
| 11277 | } |
| 11278 | |
| 11279 | return DeclGroupPtrTy::make( |
| 11280 | DeclGroupRef::Create(Context, Decls.begin(), Decls.size())); |
| 11281 | } |
| 11282 | |
| 11283 | void Sema::ActOnOpenMPDeclareReductionCombinerStart(Scope *S, Decl *D) { |
| 11284 | auto *DRD = cast<OMPDeclareReductionDecl>(D); |
| 11285 | |
| 11286 | // Enter new function scope. |
| 11287 | PushFunctionScope(); |
| 11288 | getCurFunction()->setHasBranchProtectedScope(); |
| 11289 | getCurFunction()->setHasOMPDeclareReductionCombiner(); |
| 11290 | |
| 11291 | if (S != nullptr) |
| 11292 | PushDeclContext(S, DRD); |
| 11293 | else |
| 11294 | CurContext = DRD; |
| 11295 | |
| 11296 | PushExpressionEvaluationContext(PotentiallyEvaluated); |
| 11297 | |
| 11298 | QualType ReductionType = DRD->getType(); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 11299 | // Create 'T* omp_parm;T omp_in;'. All references to 'omp_in' will |
| 11300 | // be replaced by '*omp_parm' during codegen. This required because 'omp_in' |
| 11301 | // uses semantics of argument handles by value, but it should be passed by |
| 11302 | // reference. C lang does not support references, so pass all parameters as |
| 11303 | // pointers. |
| 11304 | // Create 'T omp_in;' variable. |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 11305 | auto *OmpInParm = |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 11306 | buildVarDecl(*this, D->getLocation(), ReductionType, "omp_in"); |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 11307 | // Create 'T* omp_parm;T omp_out;'. All references to 'omp_out' will |
| 11308 | // be replaced by '*omp_parm' during codegen. This required because 'omp_out' |
| 11309 | // uses semantics of argument handles by value, but it should be passed by |
| 11310 | // reference. C lang does not support references, so pass all parameters as |
| 11311 | // pointers. |
| 11312 | // Create 'T omp_out;' variable. |
| 11313 | auto *OmpOutParm = |
| 11314 | buildVarDecl(*this, D->getLocation(), ReductionType, "omp_out"); |
| 11315 | if (S != nullptr) { |
| 11316 | PushOnScopeChains(OmpInParm, S); |
| 11317 | PushOnScopeChains(OmpOutParm, S); |
| 11318 | } else { |
| 11319 | DRD->addDecl(OmpInParm); |
| 11320 | DRD->addDecl(OmpOutParm); |
| 11321 | } |
| 11322 | } |
| 11323 | |
| 11324 | void Sema::ActOnOpenMPDeclareReductionCombinerEnd(Decl *D, Expr *Combiner) { |
| 11325 | auto *DRD = cast<OMPDeclareReductionDecl>(D); |
| 11326 | DiscardCleanupsInEvaluationContext(); |
| 11327 | PopExpressionEvaluationContext(); |
| 11328 | |
| 11329 | PopDeclContext(); |
| 11330 | PopFunctionScopeInfo(); |
| 11331 | |
| 11332 | if (Combiner != nullptr) |
| 11333 | DRD->setCombiner(Combiner); |
| 11334 | else |
| 11335 | DRD->setInvalidDecl(); |
| 11336 | } |
| 11337 | |
| 11338 | void Sema::ActOnOpenMPDeclareReductionInitializerStart(Scope *S, Decl *D) { |
| 11339 | auto *DRD = cast<OMPDeclareReductionDecl>(D); |
| 11340 | |
| 11341 | // Enter new function scope. |
| 11342 | PushFunctionScope(); |
| 11343 | getCurFunction()->setHasBranchProtectedScope(); |
| 11344 | |
| 11345 | if (S != nullptr) |
| 11346 | PushDeclContext(S, DRD); |
| 11347 | else |
| 11348 | CurContext = DRD; |
| 11349 | |
| 11350 | PushExpressionEvaluationContext(PotentiallyEvaluated); |
| 11351 | |
| 11352 | QualType ReductionType = DRD->getType(); |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 11353 | // Create 'T* omp_parm;T omp_priv;'. All references to 'omp_priv' will |
| 11354 | // be replaced by '*omp_parm' during codegen. This required because 'omp_priv' |
| 11355 | // uses semantics of argument handles by value, but it should be passed by |
| 11356 | // reference. C lang does not support references, so pass all parameters as |
| 11357 | // pointers. |
| 11358 | // Create 'T omp_priv;' variable. |
| 11359 | auto *OmpPrivParm = |
| 11360 | buildVarDecl(*this, D->getLocation(), ReductionType, "omp_priv"); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 11361 | // Create 'T* omp_parm;T omp_orig;'. All references to 'omp_orig' will |
| 11362 | // be replaced by '*omp_parm' during codegen. This required because 'omp_orig' |
| 11363 | // uses semantics of argument handles by value, but it should be passed by |
| 11364 | // reference. C lang does not support references, so pass all parameters as |
| 11365 | // pointers. |
| 11366 | // Create 'T omp_orig;' variable. |
| 11367 | auto *OmpOrigParm = |
| 11368 | buildVarDecl(*this, D->getLocation(), ReductionType, "omp_orig"); |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 11369 | if (S != nullptr) { |
| 11370 | PushOnScopeChains(OmpPrivParm, S); |
| 11371 | PushOnScopeChains(OmpOrigParm, S); |
| 11372 | } else { |
| 11373 | DRD->addDecl(OmpPrivParm); |
| 11374 | DRD->addDecl(OmpOrigParm); |
| 11375 | } |
| 11376 | } |
| 11377 | |
| 11378 | void Sema::ActOnOpenMPDeclareReductionInitializerEnd(Decl *D, |
| 11379 | Expr *Initializer) { |
| 11380 | auto *DRD = cast<OMPDeclareReductionDecl>(D); |
| 11381 | DiscardCleanupsInEvaluationContext(); |
| 11382 | PopExpressionEvaluationContext(); |
| 11383 | |
| 11384 | PopDeclContext(); |
| 11385 | PopFunctionScopeInfo(); |
| 11386 | |
| 11387 | if (Initializer != nullptr) |
| 11388 | DRD->setInitializer(Initializer); |
| 11389 | else |
| 11390 | DRD->setInvalidDecl(); |
| 11391 | } |
| 11392 | |
| 11393 | Sema::DeclGroupPtrTy Sema::ActOnOpenMPDeclareReductionDirectiveEnd( |
| 11394 | Scope *S, DeclGroupPtrTy DeclReductions, bool IsValid) { |
| 11395 | for (auto *D : DeclReductions.get()) { |
| 11396 | if (IsValid) { |
| 11397 | auto *DRD = cast<OMPDeclareReductionDecl>(D); |
| 11398 | if (S != nullptr) |
| 11399 | PushOnScopeChains(DRD, S, /*AddToContext=*/false); |
| 11400 | } else |
| 11401 | D->setInvalidDecl(); |
| 11402 | } |
| 11403 | return DeclReductions; |
| 11404 | } |
| 11405 | |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 11406 | OMPClause *Sema::ActOnOpenMPNumTeamsClause(Expr *NumTeams, |
| 11407 | SourceLocation StartLoc, |
| 11408 | SourceLocation LParenLoc, |
| 11409 | SourceLocation EndLoc) { |
| 11410 | Expr *ValExpr = NumTeams; |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 11411 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 11412 | // OpenMP [teams Constrcut, Restrictions] |
| 11413 | // The num_teams expression must evaluate to a positive integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 11414 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_num_teams, |
| 11415 | /*StrictlyPositive=*/true)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 11416 | return nullptr; |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 11417 | |
| 11418 | return new (Context) OMPNumTeamsClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 11419 | } |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 11420 | |
| 11421 | OMPClause *Sema::ActOnOpenMPThreadLimitClause(Expr *ThreadLimit, |
| 11422 | SourceLocation StartLoc, |
| 11423 | SourceLocation LParenLoc, |
| 11424 | SourceLocation EndLoc) { |
| 11425 | Expr *ValExpr = ThreadLimit; |
| 11426 | |
| 11427 | // OpenMP [teams Constrcut, Restrictions] |
| 11428 | // The thread_limit expression must evaluate to a positive integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 11429 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_thread_limit, |
| 11430 | /*StrictlyPositive=*/true)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 11431 | return nullptr; |
| 11432 | |
| 11433 | return new (Context) OMPThreadLimitClause(ValExpr, StartLoc, LParenLoc, |
| 11434 | EndLoc); |
| 11435 | } |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 11436 | |
| 11437 | OMPClause *Sema::ActOnOpenMPPriorityClause(Expr *Priority, |
| 11438 | SourceLocation StartLoc, |
| 11439 | SourceLocation LParenLoc, |
| 11440 | SourceLocation EndLoc) { |
| 11441 | Expr *ValExpr = Priority; |
| 11442 | |
| 11443 | // OpenMP [2.9.1, task Constrcut] |
| 11444 | // The priority-value is a non-negative numerical scalar expression. |
| 11445 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_priority, |
| 11446 | /*StrictlyPositive=*/false)) |
| 11447 | return nullptr; |
| 11448 | |
| 11449 | return new (Context) OMPPriorityClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 11450 | } |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 11451 | |
| 11452 | OMPClause *Sema::ActOnOpenMPGrainsizeClause(Expr *Grainsize, |
| 11453 | SourceLocation StartLoc, |
| 11454 | SourceLocation LParenLoc, |
| 11455 | SourceLocation EndLoc) { |
| 11456 | Expr *ValExpr = Grainsize; |
| 11457 | |
| 11458 | // OpenMP [2.9.2, taskloop Constrcut] |
| 11459 | // The parameter of the grainsize clause must be a positive integer |
| 11460 | // expression. |
| 11461 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_grainsize, |
| 11462 | /*StrictlyPositive=*/true)) |
| 11463 | return nullptr; |
| 11464 | |
| 11465 | return new (Context) OMPGrainsizeClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 11466 | } |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 11467 | |
| 11468 | OMPClause *Sema::ActOnOpenMPNumTasksClause(Expr *NumTasks, |
| 11469 | SourceLocation StartLoc, |
| 11470 | SourceLocation LParenLoc, |
| 11471 | SourceLocation EndLoc) { |
| 11472 | Expr *ValExpr = NumTasks; |
| 11473 | |
| 11474 | // OpenMP [2.9.2, taskloop Constrcut] |
| 11475 | // The parameter of the num_tasks clause must be a positive integer |
| 11476 | // expression. |
| 11477 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_num_tasks, |
| 11478 | /*StrictlyPositive=*/true)) |
| 11479 | return nullptr; |
| 11480 | |
| 11481 | return new (Context) OMPNumTasksClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 11482 | } |
| 11483 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 11484 | OMPClause *Sema::ActOnOpenMPHintClause(Expr *Hint, SourceLocation StartLoc, |
| 11485 | SourceLocation LParenLoc, |
| 11486 | SourceLocation EndLoc) { |
| 11487 | // OpenMP [2.13.2, critical construct, Description] |
| 11488 | // ... where hint-expression is an integer constant expression that evaluates |
| 11489 | // to a valid lock hint. |
| 11490 | ExprResult HintExpr = VerifyPositiveIntegerConstantInClause(Hint, OMPC_hint); |
| 11491 | if (HintExpr.isInvalid()) |
| 11492 | return nullptr; |
| 11493 | return new (Context) |
| 11494 | OMPHintClause(HintExpr.get(), StartLoc, LParenLoc, EndLoc); |
| 11495 | } |
| 11496 | |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 11497 | OMPClause *Sema::ActOnOpenMPDistScheduleClause( |
| 11498 | OpenMPDistScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, |
| 11499 | SourceLocation LParenLoc, SourceLocation KindLoc, SourceLocation CommaLoc, |
| 11500 | SourceLocation EndLoc) { |
| 11501 | if (Kind == OMPC_DIST_SCHEDULE_unknown) { |
| 11502 | std::string Values; |
| 11503 | Values += "'"; |
| 11504 | Values += getOpenMPSimpleClauseTypeName(OMPC_dist_schedule, 0); |
| 11505 | Values += "'"; |
| 11506 | Diag(KindLoc, diag::err_omp_unexpected_clause_value) |
| 11507 | << Values << getOpenMPClauseName(OMPC_dist_schedule); |
| 11508 | return nullptr; |
| 11509 | } |
| 11510 | Expr *ValExpr = ChunkSize; |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 11511 | Stmt *HelperValStmt = nullptr; |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 11512 | if (ChunkSize) { |
| 11513 | if (!ChunkSize->isValueDependent() && !ChunkSize->isTypeDependent() && |
| 11514 | !ChunkSize->isInstantiationDependent() && |
| 11515 | !ChunkSize->containsUnexpandedParameterPack()) { |
| 11516 | SourceLocation ChunkSizeLoc = ChunkSize->getLocStart(); |
| 11517 | ExprResult Val = |
| 11518 | PerformOpenMPImplicitIntegerConversion(ChunkSizeLoc, ChunkSize); |
| 11519 | if (Val.isInvalid()) |
| 11520 | return nullptr; |
| 11521 | |
| 11522 | ValExpr = Val.get(); |
| 11523 | |
| 11524 | // OpenMP [2.7.1, Restrictions] |
| 11525 | // chunk_size must be a loop invariant integer expression with a positive |
| 11526 | // value. |
| 11527 | llvm::APSInt Result; |
| 11528 | if (ValExpr->isIntegerConstantExpr(Result, Context)) { |
| 11529 | if (Result.isSigned() && !Result.isStrictlyPositive()) { |
| 11530 | Diag(ChunkSizeLoc, diag::err_omp_negative_expression_in_clause) |
| 11531 | << "dist_schedule" << ChunkSize->getSourceRange(); |
| 11532 | return nullptr; |
| 11533 | } |
Alexey Bataev | b46cdea | 2016-06-15 11:20:48 +0000 | [diff] [blame] | 11534 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective()) && |
| 11535 | !CurContext->isDependentContext()) { |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 11536 | llvm::MapVector<Expr *, DeclRefExpr *> Captures; |
| 11537 | ValExpr = tryBuildCapture(*this, ValExpr, Captures).get(); |
| 11538 | HelperValStmt = buildPreInits(Context, Captures); |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 11539 | } |
| 11540 | } |
| 11541 | } |
| 11542 | |
| 11543 | return new (Context) |
| 11544 | OMPDistScheduleClause(StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc, |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 11545 | Kind, ValExpr, HelperValStmt); |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 11546 | } |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 11547 | |
| 11548 | OMPClause *Sema::ActOnOpenMPDefaultmapClause( |
| 11549 | OpenMPDefaultmapClauseModifier M, OpenMPDefaultmapClauseKind Kind, |
| 11550 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation MLoc, |
| 11551 | SourceLocation KindLoc, SourceLocation EndLoc) { |
| 11552 | // OpenMP 4.5 only supports 'defaultmap(tofrom: scalar)' |
| 11553 | if (M != OMPC_DEFAULTMAP_MODIFIER_tofrom || |
| 11554 | Kind != OMPC_DEFAULTMAP_scalar) { |
| 11555 | std::string Value; |
| 11556 | SourceLocation Loc; |
| 11557 | Value += "'"; |
| 11558 | if (M != OMPC_DEFAULTMAP_MODIFIER_tofrom) { |
| 11559 | Value += getOpenMPSimpleClauseTypeName(OMPC_defaultmap, |
| 11560 | OMPC_DEFAULTMAP_MODIFIER_tofrom); |
| 11561 | Loc = MLoc; |
| 11562 | } else { |
| 11563 | Value += getOpenMPSimpleClauseTypeName(OMPC_defaultmap, |
| 11564 | OMPC_DEFAULTMAP_scalar); |
| 11565 | Loc = KindLoc; |
| 11566 | } |
| 11567 | Value += "'"; |
| 11568 | Diag(Loc, diag::err_omp_unexpected_clause_value) |
| 11569 | << Value << getOpenMPClauseName(OMPC_defaultmap); |
| 11570 | return nullptr; |
| 11571 | } |
| 11572 | |
| 11573 | return new (Context) |
| 11574 | OMPDefaultmapClause(StartLoc, LParenLoc, MLoc, KindLoc, EndLoc, Kind, M); |
| 11575 | } |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 11576 | |
| 11577 | bool Sema::ActOnStartOpenMPDeclareTargetDirective(SourceLocation Loc) { |
| 11578 | DeclContext *CurLexicalContext = getCurLexicalContext(); |
| 11579 | if (!CurLexicalContext->isFileContext() && |
| 11580 | !CurLexicalContext->isExternCContext() && |
| 11581 | !CurLexicalContext->isExternCXXContext()) { |
| 11582 | Diag(Loc, diag::err_omp_region_not_file_context); |
| 11583 | return false; |
| 11584 | } |
| 11585 | if (IsInOpenMPDeclareTargetContext) { |
| 11586 | Diag(Loc, diag::err_omp_enclosed_declare_target); |
| 11587 | return false; |
| 11588 | } |
| 11589 | |
| 11590 | IsInOpenMPDeclareTargetContext = true; |
| 11591 | return true; |
| 11592 | } |
| 11593 | |
| 11594 | void Sema::ActOnFinishOpenMPDeclareTargetDirective() { |
| 11595 | assert(IsInOpenMPDeclareTargetContext && |
| 11596 | "Unexpected ActOnFinishOpenMPDeclareTargetDirective"); |
| 11597 | |
| 11598 | IsInOpenMPDeclareTargetContext = false; |
| 11599 | } |
| 11600 | |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 11601 | void |
| 11602 | Sema::ActOnOpenMPDeclareTargetName(Scope *CurScope, CXXScopeSpec &ScopeSpec, |
| 11603 | const DeclarationNameInfo &Id, |
| 11604 | OMPDeclareTargetDeclAttr::MapTypeTy MT, |
| 11605 | NamedDeclSetType &SameDirectiveDecls) { |
| 11606 | LookupResult Lookup(*this, Id, LookupOrdinaryName); |
| 11607 | LookupParsedName(Lookup, CurScope, &ScopeSpec, true); |
| 11608 | |
| 11609 | if (Lookup.isAmbiguous()) |
| 11610 | return; |
| 11611 | Lookup.suppressDiagnostics(); |
| 11612 | |
| 11613 | if (!Lookup.isSingleResult()) { |
| 11614 | if (TypoCorrection Corrected = |
| 11615 | CorrectTypo(Id, LookupOrdinaryName, CurScope, nullptr, |
| 11616 | llvm::make_unique<VarOrFuncDeclFilterCCC>(*this), |
| 11617 | CTK_ErrorRecovery)) { |
| 11618 | diagnoseTypo(Corrected, PDiag(diag::err_undeclared_var_use_suggest) |
| 11619 | << Id.getName()); |
| 11620 | checkDeclIsAllowedInOpenMPTarget(nullptr, Corrected.getCorrectionDecl()); |
| 11621 | return; |
| 11622 | } |
| 11623 | |
| 11624 | Diag(Id.getLoc(), diag::err_undeclared_var_use) << Id.getName(); |
| 11625 | return; |
| 11626 | } |
| 11627 | |
| 11628 | NamedDecl *ND = Lookup.getAsSingle<NamedDecl>(); |
| 11629 | if (isa<VarDecl>(ND) || isa<FunctionDecl>(ND)) { |
| 11630 | if (!SameDirectiveDecls.insert(cast<NamedDecl>(ND->getCanonicalDecl()))) |
| 11631 | Diag(Id.getLoc(), diag::err_omp_declare_target_multiple) << Id.getName(); |
| 11632 | |
| 11633 | if (!ND->hasAttr<OMPDeclareTargetDeclAttr>()) { |
| 11634 | Attr *A = OMPDeclareTargetDeclAttr::CreateImplicit(Context, MT); |
| 11635 | ND->addAttr(A); |
| 11636 | if (ASTMutationListener *ML = Context.getASTMutationListener()) |
| 11637 | ML->DeclarationMarkedOpenMPDeclareTarget(ND, A); |
| 11638 | checkDeclIsAllowedInOpenMPTarget(nullptr, ND); |
| 11639 | } else if (ND->getAttr<OMPDeclareTargetDeclAttr>()->getMapType() != MT) { |
| 11640 | Diag(Id.getLoc(), diag::err_omp_declare_target_to_and_link) |
| 11641 | << Id.getName(); |
| 11642 | } |
| 11643 | } else |
| 11644 | Diag(Id.getLoc(), diag::err_omp_invalid_target_decl) << Id.getName(); |
| 11645 | } |
| 11646 | |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 11647 | static void checkDeclInTargetContext(SourceLocation SL, SourceRange SR, |
| 11648 | Sema &SemaRef, Decl *D) { |
| 11649 | if (!D) |
| 11650 | return; |
| 11651 | Decl *LD = nullptr; |
| 11652 | if (isa<TagDecl>(D)) { |
| 11653 | LD = cast<TagDecl>(D)->getDefinition(); |
| 11654 | } else if (isa<VarDecl>(D)) { |
| 11655 | LD = cast<VarDecl>(D)->getDefinition(); |
| 11656 | |
| 11657 | // If this is an implicit variable that is legal and we do not need to do |
| 11658 | // anything. |
| 11659 | if (cast<VarDecl>(D)->isImplicit()) { |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 11660 | Attr *A = OMPDeclareTargetDeclAttr::CreateImplicit( |
| 11661 | SemaRef.Context, OMPDeclareTargetDeclAttr::MT_To); |
| 11662 | D->addAttr(A); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 11663 | if (ASTMutationListener *ML = SemaRef.Context.getASTMutationListener()) |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 11664 | ML->DeclarationMarkedOpenMPDeclareTarget(D, A); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 11665 | return; |
| 11666 | } |
| 11667 | |
| 11668 | } else if (isa<FunctionDecl>(D)) { |
| 11669 | const FunctionDecl *FD = nullptr; |
| 11670 | if (cast<FunctionDecl>(D)->hasBody(FD)) |
| 11671 | LD = const_cast<FunctionDecl *>(FD); |
| 11672 | |
| 11673 | // If the definition is associated with the current declaration in the |
| 11674 | // target region (it can be e.g. a lambda) that is legal and we do not need |
| 11675 | // to do anything else. |
| 11676 | if (LD == D) { |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 11677 | Attr *A = OMPDeclareTargetDeclAttr::CreateImplicit( |
| 11678 | SemaRef.Context, OMPDeclareTargetDeclAttr::MT_To); |
| 11679 | D->addAttr(A); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 11680 | if (ASTMutationListener *ML = SemaRef.Context.getASTMutationListener()) |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 11681 | ML->DeclarationMarkedOpenMPDeclareTarget(D, A); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 11682 | return; |
| 11683 | } |
| 11684 | } |
| 11685 | if (!LD) |
| 11686 | LD = D; |
| 11687 | if (LD && !LD->hasAttr<OMPDeclareTargetDeclAttr>() && |
| 11688 | (isa<VarDecl>(LD) || isa<FunctionDecl>(LD))) { |
| 11689 | // Outlined declaration is not declared target. |
| 11690 | if (LD->isOutOfLine()) { |
| 11691 | SemaRef.Diag(LD->getLocation(), diag::warn_omp_not_in_target_context); |
| 11692 | SemaRef.Diag(SL, diag::note_used_here) << SR; |
| 11693 | } else { |
| 11694 | DeclContext *DC = LD->getDeclContext(); |
| 11695 | while (DC) { |
| 11696 | if (isa<FunctionDecl>(DC) && |
| 11697 | cast<FunctionDecl>(DC)->hasAttr<OMPDeclareTargetDeclAttr>()) |
| 11698 | break; |
| 11699 | DC = DC->getParent(); |
| 11700 | } |
| 11701 | if (DC) |
| 11702 | return; |
| 11703 | |
| 11704 | // Is not declared in target context. |
| 11705 | SemaRef.Diag(LD->getLocation(), diag::warn_omp_not_in_target_context); |
| 11706 | SemaRef.Diag(SL, diag::note_used_here) << SR; |
| 11707 | } |
| 11708 | // Mark decl as declared target to prevent further diagnostic. |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 11709 | Attr *A = OMPDeclareTargetDeclAttr::CreateImplicit( |
| 11710 | SemaRef.Context, OMPDeclareTargetDeclAttr::MT_To); |
| 11711 | D->addAttr(A); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 11712 | if (ASTMutationListener *ML = SemaRef.Context.getASTMutationListener()) |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 11713 | ML->DeclarationMarkedOpenMPDeclareTarget(D, A); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 11714 | } |
| 11715 | } |
| 11716 | |
| 11717 | static bool checkValueDeclInTarget(SourceLocation SL, SourceRange SR, |
| 11718 | Sema &SemaRef, DSAStackTy *Stack, |
| 11719 | ValueDecl *VD) { |
| 11720 | if (VD->hasAttr<OMPDeclareTargetDeclAttr>()) |
| 11721 | return true; |
| 11722 | if (!CheckTypeMappable(SL, SR, SemaRef, Stack, VD->getType())) |
| 11723 | return false; |
| 11724 | return true; |
| 11725 | } |
| 11726 | |
| 11727 | void Sema::checkDeclIsAllowedInOpenMPTarget(Expr *E, Decl *D) { |
| 11728 | if (!D || D->isInvalidDecl()) |
| 11729 | return; |
| 11730 | SourceRange SR = E ? E->getSourceRange() : D->getSourceRange(); |
| 11731 | SourceLocation SL = E ? E->getLocStart() : D->getLocation(); |
| 11732 | // 2.10.6: threadprivate variable cannot appear in a declare target directive. |
| 11733 | if (VarDecl *VD = dyn_cast<VarDecl>(D)) { |
| 11734 | if (DSAStack->isThreadPrivate(VD)) { |
| 11735 | Diag(SL, diag::err_omp_threadprivate_in_target); |
| 11736 | ReportOriginalDSA(*this, DSAStack, VD, DSAStack->getTopDSA(VD, false)); |
| 11737 | return; |
| 11738 | } |
| 11739 | } |
| 11740 | if (ValueDecl *VD = dyn_cast<ValueDecl>(D)) { |
| 11741 | // Problem if any with var declared with incomplete type will be reported |
| 11742 | // as normal, so no need to check it here. |
| 11743 | if ((E || !VD->getType()->isIncompleteType()) && |
| 11744 | !checkValueDeclInTarget(SL, SR, *this, DSAStack, VD)) { |
| 11745 | // Mark decl as declared target to prevent further diagnostic. |
| 11746 | if (isa<VarDecl>(VD) || isa<FunctionDecl>(VD)) { |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 11747 | Attr *A = OMPDeclareTargetDeclAttr::CreateImplicit( |
| 11748 | Context, OMPDeclareTargetDeclAttr::MT_To); |
| 11749 | VD->addAttr(A); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 11750 | if (ASTMutationListener *ML = Context.getASTMutationListener()) |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 11751 | ML->DeclarationMarkedOpenMPDeclareTarget(VD, A); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 11752 | } |
| 11753 | return; |
| 11754 | } |
| 11755 | } |
| 11756 | if (!E) { |
| 11757 | // Checking declaration inside declare target region. |
| 11758 | if (!D->hasAttr<OMPDeclareTargetDeclAttr>() && |
| 11759 | (isa<VarDecl>(D) || isa<FunctionDecl>(D))) { |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 11760 | Attr *A = OMPDeclareTargetDeclAttr::CreateImplicit( |
| 11761 | Context, OMPDeclareTargetDeclAttr::MT_To); |
| 11762 | D->addAttr(A); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 11763 | if (ASTMutationListener *ML = Context.getASTMutationListener()) |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 11764 | ML->DeclarationMarkedOpenMPDeclareTarget(D, A); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 11765 | } |
| 11766 | return; |
| 11767 | } |
| 11768 | checkDeclInTargetContext(E->getExprLoc(), E->getSourceRange(), *this, D); |
| 11769 | } |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 11770 | |
| 11771 | OMPClause *Sema::ActOnOpenMPToClause(ArrayRef<Expr *> VarList, |
| 11772 | SourceLocation StartLoc, |
| 11773 | SourceLocation LParenLoc, |
| 11774 | SourceLocation EndLoc) { |
| 11775 | MappableVarListInfo MVLI(VarList); |
| 11776 | checkMappableExpressionList(*this, DSAStack, OMPC_to, MVLI, StartLoc); |
| 11777 | if (MVLI.ProcessedVarList.empty()) |
| 11778 | return nullptr; |
| 11779 | |
| 11780 | return OMPToClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| 11781 | MVLI.ProcessedVarList, MVLI.VarBaseDeclarations, |
| 11782 | MVLI.VarComponents); |
| 11783 | } |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 11784 | |
| 11785 | OMPClause *Sema::ActOnOpenMPFromClause(ArrayRef<Expr *> VarList, |
| 11786 | SourceLocation StartLoc, |
| 11787 | SourceLocation LParenLoc, |
| 11788 | SourceLocation EndLoc) { |
| 11789 | MappableVarListInfo MVLI(VarList); |
| 11790 | checkMappableExpressionList(*this, DSAStack, OMPC_from, MVLI, StartLoc); |
| 11791 | if (MVLI.ProcessedVarList.empty()) |
| 11792 | return nullptr; |
| 11793 | |
| 11794 | return OMPFromClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| 11795 | MVLI.ProcessedVarList, MVLI.VarBaseDeclarations, |
| 11796 | MVLI.VarComponents); |
| 11797 | } |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 11798 | |
| 11799 | OMPClause *Sema::ActOnOpenMPUseDevicePtrClause(ArrayRef<Expr *> VarList, |
| 11800 | SourceLocation StartLoc, |
| 11801 | SourceLocation LParenLoc, |
| 11802 | SourceLocation EndLoc) { |
Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame^] | 11803 | MappableVarListInfo MVLI(VarList); |
| 11804 | SmallVector<Expr *, 8> PrivateCopies; |
| 11805 | SmallVector<Expr *, 8> Inits; |
| 11806 | |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 11807 | for (auto &RefExpr : VarList) { |
| 11808 | assert(RefExpr && "NULL expr in OpenMP use_device_ptr clause."); |
| 11809 | SourceLocation ELoc; |
| 11810 | SourceRange ERange; |
| 11811 | Expr *SimpleRefExpr = RefExpr; |
| 11812 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
| 11813 | if (Res.second) { |
| 11814 | // It will be analyzed later. |
Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame^] | 11815 | MVLI.ProcessedVarList.push_back(RefExpr); |
| 11816 | PrivateCopies.push_back(nullptr); |
| 11817 | Inits.push_back(nullptr); |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 11818 | } |
| 11819 | ValueDecl *D = Res.first; |
| 11820 | if (!D) |
| 11821 | continue; |
| 11822 | |
| 11823 | QualType Type = D->getType(); |
Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame^] | 11824 | Type = Type.getNonReferenceType().getUnqualifiedType(); |
| 11825 | |
| 11826 | auto *VD = dyn_cast<VarDecl>(D); |
| 11827 | |
| 11828 | // Item should be a pointer or reference to pointer. |
| 11829 | if (!Type->isPointerType()) { |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 11830 | Diag(ELoc, diag::err_omp_usedeviceptr_not_a_pointer) |
| 11831 | << 0 << RefExpr->getSourceRange(); |
| 11832 | continue; |
| 11833 | } |
Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame^] | 11834 | |
| 11835 | // Build the private variable and the expression that refers to it. |
| 11836 | auto VDPrivate = buildVarDecl(*this, ELoc, Type, D->getName(), |
| 11837 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 11838 | if (VDPrivate->isInvalidDecl()) |
| 11839 | continue; |
| 11840 | |
| 11841 | CurContext->addDecl(VDPrivate); |
| 11842 | auto VDPrivateRefExpr = buildDeclRefExpr( |
| 11843 | *this, VDPrivate, RefExpr->getType().getUnqualifiedType(), ELoc); |
| 11844 | |
| 11845 | // Add temporary variable to initialize the private copy of the pointer. |
| 11846 | auto *VDInit = |
| 11847 | buildVarDecl(*this, RefExpr->getExprLoc(), Type, ".devptr.temp"); |
| 11848 | auto *VDInitRefExpr = buildDeclRefExpr(*this, VDInit, RefExpr->getType(), |
| 11849 | RefExpr->getExprLoc()); |
| 11850 | AddInitializerToDecl(VDPrivate, |
| 11851 | DefaultLvalueConversion(VDInitRefExpr).get(), |
| 11852 | /*DirectInit=*/false, /*TypeMayContainAuto=*/false); |
| 11853 | |
| 11854 | // If required, build a capture to implement the privatization initialized |
| 11855 | // with the current list item value. |
| 11856 | DeclRefExpr *Ref = nullptr; |
| 11857 | if (!VD) |
| 11858 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/true); |
| 11859 | MVLI.ProcessedVarList.push_back(VD ? RefExpr->IgnoreParens() : Ref); |
| 11860 | PrivateCopies.push_back(VDPrivateRefExpr); |
| 11861 | Inits.push_back(VDInitRefExpr); |
| 11862 | |
| 11863 | // We need to add a data sharing attribute for this variable to make sure it |
| 11864 | // is correctly captured. A variable that shows up in a use_device_ptr has |
| 11865 | // similar properties of a first private variable. |
| 11866 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_firstprivate, Ref); |
| 11867 | |
| 11868 | // Create a mappable component for the list item. List items in this clause |
| 11869 | // only need a component. |
| 11870 | MVLI.VarBaseDeclarations.push_back(D); |
| 11871 | MVLI.VarComponents.resize(MVLI.VarComponents.size() + 1); |
| 11872 | MVLI.VarComponents.back().push_back( |
| 11873 | OMPClauseMappableExprCommon::MappableComponent(SimpleRefExpr, D)); |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 11874 | } |
| 11875 | |
Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame^] | 11876 | if (MVLI.ProcessedVarList.empty()) |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 11877 | return nullptr; |
| 11878 | |
Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame^] | 11879 | return OMPUseDevicePtrClause::Create( |
| 11880 | Context, StartLoc, LParenLoc, EndLoc, MVLI.ProcessedVarList, |
| 11881 | PrivateCopies, Inits, MVLI.VarBaseDeclarations, MVLI.VarComponents); |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 11882 | } |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 11883 | |
| 11884 | OMPClause *Sema::ActOnOpenMPIsDevicePtrClause(ArrayRef<Expr *> VarList, |
| 11885 | SourceLocation StartLoc, |
| 11886 | SourceLocation LParenLoc, |
| 11887 | SourceLocation EndLoc) { |
| 11888 | SmallVector<Expr *, 8> Vars; |
| 11889 | for (auto &RefExpr : VarList) { |
| 11890 | assert(RefExpr && "NULL expr in OpenMP use_device_ptr clause."); |
| 11891 | SourceLocation ELoc; |
| 11892 | SourceRange ERange; |
| 11893 | Expr *SimpleRefExpr = RefExpr; |
| 11894 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
| 11895 | if (Res.second) { |
| 11896 | // It will be analyzed later. |
| 11897 | Vars.push_back(RefExpr); |
| 11898 | } |
| 11899 | ValueDecl *D = Res.first; |
| 11900 | if (!D) |
| 11901 | continue; |
| 11902 | |
| 11903 | QualType Type = D->getType(); |
| 11904 | // item should be a pointer or array or reference to pointer or array |
| 11905 | if (!Type.getNonReferenceType()->isPointerType() && |
| 11906 | !Type.getNonReferenceType()->isArrayType()) { |
| 11907 | Diag(ELoc, diag::err_omp_argument_type_isdeviceptr) |
| 11908 | << 0 << RefExpr->getSourceRange(); |
| 11909 | continue; |
| 11910 | } |
| 11911 | Vars.push_back(RefExpr->IgnoreParens()); |
| 11912 | } |
| 11913 | |
| 11914 | if (Vars.empty()) |
| 11915 | return nullptr; |
| 11916 | |
| 11917 | return OMPIsDevicePtrClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| 11918 | Vars); |
| 11919 | } |